// File: /workspace/github_cpp_makefile_star2_O2/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 0x32ad8(%rip), %rdi     # 0x37c60
pushq $0xc
popq %rsi
callq 0x12422
leaq 0x32ae1(%rip), %rdi     # 0x37c78
movl $0x800, %esi            # imm = 0x800
callq 0x12422
movzbl 0x3117c(%rip), %eax     # 0x36324
leal 0x1(%rax), %ecx
shll $0x8, %eax
addl %r14d, %eax
leaq 0xe(%rsp), %rsi
movw %ax, (%rsi)
movb %cl, 0x31165(%rip)      # 0x36324
movl $0x6000000, 0x2(%rsi)   # imm = 0x6000000
movw $0x301, 0x6(%rsi)       # imm = 0x301
movl %ebp, %eax
shll $0x8, %eax
movw %ax, 0x8(%rsi)
movl %ebx, %ecx
shll $0x8, %ecx
movl $0x100, %edi            # imm = 0x100
movl %ebx, %eax
cltd
idivl %edi
addl %ecx, %eax
movw %ax, 0xa(%rsi)
movq 0x32a6f(%rip), %rdi     # 0x37c60
movq 0x32a70(%rip), %rdx     # 0x37c68
subq %rdi, %rdx
callq 0x21f0
cmpb $0x1, 0x31c3e(%rip)     # 0x36e45
jne 0x5217
leaq 0x26848(%rip), %rdi     # 0x2ba58
xorl %eax, %eax
callq 0x2040
leaq 0x2683e(%rip), %rdi     # 0x2ba5c
movl %ebp, %esi
movl %ebx, %edx
xorl %eax, %eax
callq 0x2040
cmpb $0x0, 0x32b3c(%rip)     # 0x37d6c
jne 0x52b1
movl 0x32b30(%rip), %edi     # 0x37d68
testl %edi, %edi
jle 0x529a
movq 0x32a1d(%rip), %rsi     # 0x37c60
movl 0x32a1f(%rip), %edx     # 0x37c68
subl %esi, %edx
callq 0x1d70b
cltq
movq %rax, 0x329e7(%rip)     # 0x37c40
cmpb $0x1, 0x31be5(%rip)     # 0x36e45
jne 0x5270
leaq 0x267ff(%rip), %rdi     # 0x2ba68
xorl %eax, %eax
callq 0x2040
movl 0x32af2(%rip), %edi     # 0x37d68
movq 0x329fb(%rip), %rsi     # 0x37c78
movl 0x329fd(%rip), %edx     # 0x37c80
subl %esi, %edx
callq 0x1d758
cltq
movq %rax, 0x329ad(%rip)     # 0x37c40
movb $0x1, 0x32ad2(%rip)     # 0x37d6c
cmpb $0x1, 0x31ba4(%rip)     # 0x36e45
jne 0x52b1
leaq 0x267c3(%rip), %rdi     # 0x2ba6d
xorl %eax, %eax
callq 0x2040
movq 0x32988(%rip), %rsi     # 0x37c40
leaq 0x26790(%rip), %rdi     # 0x2ba4f
xorl %eax, %eax
callq 0x2040
movq 0x32973(%rip), %rax     # 0x37c40
addq $0xe0, %rsp
popq %rbx
popq %r14
popq %rbp
retq