// File: /workspace/github_c_makefile_star2_O3/connycommy[P]atCmdDevice/src/cellularModem/cellModem.c
// Function: cellModem_SocketGetServStatus
cmError_t cellModem_SocketGetServStatus(cmData_t *obj, socketData_t *config){  
    cmError_t retVal;
    char bufferRecv[256];
    char cmd[32]="AT+QISTATE=1,";
    char *ptr = NULL;
    char  buffer[32] ={0};

    sprintf(buffer,"%d\r",config->connectId);
    ptr  = strcat(cmd,buffer);
    retVal = cmSendCmd(obj,cmd , (0 == cellModem_GetatvFormat(obj) ) ? CELLMODEM_CMD_GENERAL_RESPONSE_ATV0 :CELLMODEM_CMD_GENERAL_RESPONSE  ,bufferRecv ,150000); //150 sg
    
    if(CM_OK == retVal){
        ptr = NULL;
        memset(buffer,0,sizeof(buffer));
        if( (ptr = strstr(bufferRecv,"+QISTATE:")) != NULL ){
            if(config != NULL){
                ptr = extractBetween(bufferRecv,' ',',',buffer,0);
                config->connectId = (int)atoi(buffer);
                ptr = extractBetween(bufferRecv,'"','"',buffer,0); // service type
                ptr = extractBetween(ptr,'"','"',config->ipAddres,2);

                if((config->remPort != NULL) || (config->locPort != NULL)){
                    memset((void*)config->remPort,0,sizeof(config->remPort));
                    memset((void*)config->remPort,0,sizeof(config->locPort));
                    ptr = extractBetween(ptr,',',',',config->remPort,0);
                    ptr = extractBetween(ptr,',',',',config->locPort,0); //printf("remPort: %s\n",config->remPort);
                }else{
                    //move pointer
                    ptr = extractBetween(ptr,',',',',NULL,0);
                    ptr = extractBetween(ptr,',',',',NULL,0);
                }
                
                ptr = extractBetween(ptr,',',',',buffer,0);//
                config->state = (int)atoi(buffer); //0: initial 1: opening 2:connected 3:listening 4 : closing
                ptr = extractBetween(ptr,',',',',NULL,0);//
                memset(buffer,0,sizeof(buffer));
                ptr = extractBetween(ptr,',',',',buffer,0);//
                config->serverId = (int)atoi(buffer);
            }
        }else{
            memset((void*)config->remPort,0,sizeof(config->remPort));
            memset((void*)config->locPort,0,sizeof(config->locPort));
            memset((void*)config->ipAddres,0,sizeof(config->ipAddres));
            config->state = 0;
            config->serverId = 0;
        }
    }
    return retVal;
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r12
pushq %rbx
subq $0x140, %rsp            # imm = 0x140
movq %rsi, %rbx
movq %rdi, %r14
movaps 0x53fe(%rip), %xmm0     # 0x7840
leaq 0x20(%rsp), %r15
movaps %xmm0, 0x10(%r15)
movaps 0x53dd(%rip), %xmm0     # 0x7830
movaps %xmm0, (%r15)
xorps %xmm0, %xmm0
movq %rsp, %r12
movaps %xmm0, 0x10(%r12)
movaps %xmm0, (%r12)
movl 0x4c(%rsi), %edx
leaq 0x4cb0(%rip), %rsi      # 0x7122
movq %r12, %rdi
xorl %eax, %eax
callq 0x1100
movq %r15, %rdi
movq %r12, %rsi
callq 0x10f0
cmpb $0x0, 0x61(%r14)
leaq 0x573f(%rip), %rax      # 0x7bd2
leaq 0x58b8(%rip), %rdx      # 0x7d52
cmoveq %rax, %rdx
leaq 0x40(%rsp), %rcx
movq %r14, %rdi
movq %r15, %rsi
movl $0x249f0, %r8d          # imm = 0x249F0
callq 0x12cc
movl %eax, %ebp
testl %eax, %eax
jne 0x2601
xorps %xmm0, %xmm0
movaps %xmm0, 0x10(%rsp)
movaps %xmm0, (%rsp)
leaq 0x4c44(%rip), %rsi      # 0x7115
leaq 0x40(%rsp), %rdi
callq 0x1110
testq %rax, %rax
je 0x25ee
leaq 0x40(%rsp), %r15
movq %rsp, %r14
movq %r15, %rdi
movl $0x20, %esi
movl $0x2c, %edx
movq %r14, %rcx
xorl %r8d, %r8d
callq 0x16cc
movq %r14, %rdi
callq 0x10e0
movl %eax, 0x4c(%rbx)
movq %r15, %rdi
movl $0x22, %esi
movl $0x22, %edx
movq %r14, %rcx
xorl %r8d, %r8d
callq 0x16cc
leaq 0x5c(%rbx), %rcx
movq %rax, %rdi
movl $0x22, %esi
movl $0x22, %edx
movl $0x2, %r8d
callq 0x16cc
leaq 0x18(%rbx), %r15
leaq 0x10(%rbx), %rcx
movq $0x0, 0x10(%rbx)
movq %rax, %rdi
movl $0x2c, %esi
movl $0x2c, %edx
xorl %r8d, %r8d
callq 0x16cc
movq %rax, %rdi
movl $0x2c, %esi
movl $0x2c, %edx
movq %r15, %rcx
xorl %r8d, %r8d
callq 0x16cc
movq %rax, %rdi
movl $0x2c, %esi
movl $0x2c, %edx
movq %r14, %rcx
xorl %r8d, %r8d
callq 0x16cc
movq %rax, %r15
movq %r14, %rdi
callq 0x10e0
movl %eax, 0x54(%rbx)
movq %r15, %rdi
movl $0x2c, %esi
movl $0x2c, %edx
xorl %ecx, %ecx
xorl %r8d, %r8d
callq 0x16cc
xorps %xmm0, %xmm0
movaps %xmm0, (%r14)
movaps %xmm0, 0x10(%r14)
movq %rax, %rdi
movl $0x2c, %esi
movl $0x2c, %edx
movq %r14, %rcx
xorl %r8d, %r8d
callq 0x16cc
movq %r14, %rdi
callq 0x10e0
movl %eax, 0x58(%rbx)
jmp 0x2601
xorps %xmm0, %xmm0
movups %xmm0, 0x10(%rbx)
movups %xmm0, 0x54(%rbx)
movq $0x0, 0x64(%rbx)
movl %ebp, %eax
addq $0x140, %rsp            # imm = 0x140
popq %rbx
popq %r12
popq %r14
popq %r15
popq %rbp
retq