// File: /workspace/github_cpp_makefile_star2_O1/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 0x3530b(%rip), %rdi     # 0x3ac40
movl $0xc, %esi
callq 0x152b0
leaq 0x35312(%rip), %rdi     # 0x3ac58
movl $0x800, %esi            # imm = 0x800
callq 0x152b0
movzbl 0x339ad(%rip), %eax     # 0x39304
leal 0x1(%rax), %ecx
shll $0x8, %eax
addl %r14d, %eax
leaq 0xe(%rsp), %rsi
movw %ax, (%rsi)
movb %cl, 0x33996(%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 0x3529c(%rip), %rdi     # 0x3ac40
movq 0x3529d(%rip), %rdx     # 0x3ac48
subq %rdi, %rdx
callq 0x21f0
cmpb $0x1, 0x3446b(%rip)     # 0x39e25
jne 0x59ca
leaq 0x2b161(%rip), %rdi     # 0x30b24
xorl %eax, %eax
callq 0x2040
leaq 0x2b157(%rip), %rdi     # 0x30b28
movl %ebp, %esi
movl %ebx, %edx
xorl %eax, %eax
callq 0x2040
cmpb $0x0, 0x35369(%rip)     # 0x3ad4c
jne 0x5a64
movl 0x3535d(%rip), %edi     # 0x3ad48
testl %edi, %edi
jle 0x5a4d
movq 0x3524a(%rip), %rsi     # 0x3ac40
movl 0x3524c(%rip), %edx     # 0x3ac48
subl %esi, %edx
callq 0x20a84
cltq
movq %rax, 0x35214(%rip)     # 0x3ac20
cmpb $0x1, 0x34412(%rip)     # 0x39e25
jne 0x5a23
leaq 0x2b118(%rip), %rdi     # 0x30b34
xorl %eax, %eax
callq 0x2040
movl 0x3531f(%rip), %edi     # 0x3ad48
movq 0x35228(%rip), %rsi     # 0x3ac58
movl 0x3522a(%rip), %edx     # 0x3ac60
subl %esi, %edx
callq 0x20adc
cltq
movq %rax, 0x351da(%rip)     # 0x3ac20
movb $0x1, 0x352ff(%rip)     # 0x3ad4c
cmpb $0x1, 0x343d1(%rip)     # 0x39e25
jne 0x5a64
leaq 0x2b0dc(%rip), %rdi     # 0x30b39
xorl %eax, %eax
callq 0x2040
movq 0x351b5(%rip), %rsi     # 0x3ac20
leaq 0x2b0a9(%rip), %rdi     # 0x30b1b
xorl %eax, %eax
callq 0x2040
movq 0x351a0(%rip), %rax     # 0x3ac20
addq $0xe0, %rsp
popq %rbx
popq %r14
popq %rbp
retq