// File: /workspace/github_cpp_makefile_star2_O3/Eba-M[P]E3DC-Control/RscpExampleMain.cpp
// Function: iModbusTCP_Get(int, int, int)
long iModbusTCP_Get(int reg,int val,int tac) //val anzahl register lesen
{
    send.resize(12);
    receive.resize(2048);

    Modbus_send Msend;
    Modbus_receive Mreceive;

    Msend.Tid = (tn*256+tac);
    tn++;
    Msend.Pid = 0;
    Msend.Mlen = 6*256;
    Msend.Dev = 1;  // Devadr. 1 oder 255
    Msend.Fcd = 3; // Funktioncode
    //            Msend.Fcd = 6; // Funktioncode
    Msend.Reg = reg*256;  // Adresse Register // Aussentemperatur
    Msend.Count = (val%256)*256; // Inhalt    int size = send.size();
    Msend.Count = Msend.Count + val/256; // Inhalt    int size = send.size();

    memcpy(&send[0],&Msend,send.size());
    if (e3dc_config.debug)
        printf("BRQ");
    printf(" Get %i %i ",reg, val);

/*
    if (isocket > 0)
    {
        iLength = SocketRecvData(isocket,&receive[0],receive.size());
        if (iLength < 0)
        {
            SocketClose(isocket);
            isocket = -1;
        }
    }

    if (isocket<0)
    {
        sprintf(server_ip,e3dc_config.heizung_ip);
        if (e3dc_config.debug)
            printf("BSC");

        isocket = SocketConnect(server_ip, 502);
        if (e3dc_config.debug)
            printf("ASC");

    }
*/
    if (brequest) 
    {
        printf(" len %i ",iLength);
        return iLength;
    }
if (isocket > 0)
 {
     iLength = SocketSendData(isocket,&send[0],send.size());
     if (e3dc_config.debug)
         printf("BRCV");
     iLength = SocketRecvData(isocket,&receive[0],receive.size());
         brequest = true;
 }
        if (e3dc_config.debug)
        printf("ARCV");
    printf(" len %i ",iLength);
    return iLength;
}

// Assembly:
pushq %rbp
pushq %r14
pushq %rbx
subq $0xe0, %rsp
movl %edx, %r14d
movl %esi, %ebx
movl %edi, %ebp
leaq 0x3531a(%rip), %rdi     # 0x3ac40
movl $0xc, %esi
callq 0x151b2
leaq 0x35321(%rip), %rdi     # 0x3ac58
movl $0x800, %esi            # imm = 0x800
callq 0x151b2
movzbl 0x339bc(%rip), %eax     # 0x39304
leal 0x1(%rax), %ecx
shll $0x8, %eax
addl %r14d, %eax
leaq 0xe(%rsp), %rsi
movw %ax, (%rsi)
movb %cl, 0x339a5(%rip)      # 0x39304
movl $0x6000000, 0x2(%rsi)   # imm = 0x6000000
movw $0x301, 0x6(%rsi)       # imm = 0x301
movl %ebp, %eax
shll $0x8, %eax
movw %ax, 0x8(%rsi)
movl %ebx, %eax
shll $0x8, %eax
leal 0xff(%rbx), %ecx
testl %ebx, %ebx
cmovnsl %ebx, %ecx
shrl $0x8, %ecx
addl %eax, %ecx
movw %cx, 0xa(%rsi)
movq 0x352ab(%rip), %rdi     # 0x3ac40
movq 0x352ac(%rip), %rdx     # 0x3ac48
subq %rdi, %rdx
callq 0x21f0
cmpb $0x1, 0x3447a(%rip)     # 0x39e25
jne 0x59bb
leaq 0x2b174(%rip), %rdi     # 0x30b28
xorl %eax, %eax
callq 0x2040
leaq 0x2b16a(%rip), %rdi     # 0x30b2c
movl %ebp, %esi
movl %ebx, %edx
xorl %eax, %eax
callq 0x2040
cmpb $0x0, 0x35378(%rip)     # 0x3ad4c
jne 0x5a55
movl 0x3536c(%rip), %edi     # 0x3ad48
testl %edi, %edi
jle 0x5a3e
movq 0x35259(%rip), %rsi     # 0x3ac40
movl 0x3525b(%rip), %edx     # 0x3ac48
subl %esi, %edx
callq 0x20921
cltq
movq %rax, 0x35223(%rip)     # 0x3ac20
cmpb $0x1, 0x34421(%rip)     # 0x39e25
jne 0x5a14
leaq 0x2b12b(%rip), %rdi     # 0x30b38
xorl %eax, %eax
callq 0x2040
movl 0x3532e(%rip), %edi     # 0x3ad48
movq 0x35237(%rip), %rsi     # 0x3ac58
movl 0x35239(%rip), %edx     # 0x3ac60
subl %esi, %edx
callq 0x2096d
cltq
movq %rax, 0x351e9(%rip)     # 0x3ac20
movb $0x1, 0x3530e(%rip)     # 0x3ad4c
cmpb $0x1, 0x343e0(%rip)     # 0x39e25
jne 0x5a55
leaq 0x2b0ef(%rip), %rdi     # 0x30b3d
xorl %eax, %eax
callq 0x2040
movq 0x351c4(%rip), %rsi     # 0x3ac20
leaq 0x2b0bc(%rip), %rdi     # 0x30b1f
xorl %eax, %eax
callq 0x2040
movq 0x351af(%rip), %rax     # 0x3ac20
addq $0xe0, %rsp
popq %rbx
popq %r14
popq %rbp
retq