// File: /workspace/github_c_makefile_star2_O2/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 %r13
pushq %r12
pushq %rbx
subq $0x148, %rsp            # imm = 0x148
movq %rsi, %rbx
movq %rdi, %r14
movaps 0x5484(%rip), %xmm0     # 0x7820
leaq 0x20(%rsp), %r15
movaps %xmm0, 0x10(%r15)
movaps 0x5463(%rip), %xmm0     # 0x7810
movaps %xmm0, (%r15)
xorps %xmm0, %xmm0
movq %rsp, %r12
movaps %xmm0, 0x10(%r12)
movaps %xmm0, (%r12)
movl 0x4c(%rsi), %edx
leaq 0x4d0e(%rip), %rsi      # 0x70da
movq %r12, %rdi
xorl %eax, %eax
callq 0x1100
movq %r15, %rdi
movq %r12, %rsi
callq 0x10f0
cmpb $0x0, 0x61(%r14)
leaq 0x57c5(%rip), %rax      # 0x7bb2
leaq 0x593e(%rip), %rdx      # 0x7d32
cmoveq %rax, %rdx
leaq 0x40(%rsp), %rcx
movq %r14, %rdi
movq %r15, %rsi
movl $0x249f0, %r8d          # imm = 0x249F0
callq 0x12d0
movl %eax, %ebp
testl %eax, %eax
jne 0x253b
xorps %xmm0, %xmm0
movaps %xmm0, 0x10(%rsp)
movaps %xmm0, (%rsp)
leaq 0x4ca2(%rip), %rsi      # 0x70cd
leaq 0x40(%rsp), %rdi
callq 0x1110
testq %rax, %rax
je 0x252b
leaq 0x40(%rsp), %r12
pushq $0x20
popq %rsi
pushq $0x2c
popq %r15
movq %rsp, %r14
movq %r12, %rdi
movl %r15d, %edx
movq %r14, %rcx
xorl %r8d, %r8d
callq 0x1694
movq %r14, %rdi
callq 0x10e0
movl %eax, 0x4c(%rbx)
pushq $0x22
popq %r13
movq %r12, %rdi
movl %r13d, %esi
movl %r13d, %edx
movq %r14, %rcx
xorl %r8d, %r8d
callq 0x1694
leaq 0x5c(%rbx), %rcx
pushq $0x2
popq %r8
movq %rax, %rdi
movl %r13d, %esi
movl %r13d, %edx
callq 0x1694
leaq 0x18(%rbx), %r12
leaq 0x10(%rbx), %rcx
andq $0x0, 0x10(%rbx)
movq %rax, %rdi
movl %r15d, %esi
movl %r15d, %edx
xorl %r8d, %r8d
callq 0x1694
movq %rax, %rdi
movl %r15d, %esi
movl %r15d, %edx
movq %r12, %rcx
xorl %r8d, %r8d
callq 0x1694
movq %rax, %rdi
movl %r15d, %esi
movl %r15d, %edx
movq %r14, %rcx
xorl %r8d, %r8d
callq 0x1694
movq %rax, %r12
movq %r14, %rdi
callq 0x10e0
movl %eax, 0x54(%rbx)
movq %r12, %rdi
movl %r15d, %esi
movl %r15d, %edx
xorl %ecx, %ecx
xorl %r8d, %r8d
callq 0x1694
xorps %xmm0, %xmm0
movaps %xmm0, (%r14)
movaps %xmm0, 0x10(%r14)
movq %rax, %rdi
movl %r15d, %esi
movl %r15d, %edx
movq %r14, %rcx
xorl %r8d, %r8d
callq 0x1694
movq %r14, %rdi
callq 0x10e0
movl %eax, 0x58(%rbx)
jmp 0x253b
xorps %xmm0, %xmm0
movups %xmm0, 0x10(%rbx)
movups %xmm0, 0x54(%rbx)
andq $0x0, 0x64(%rbx)
movl %ebp, %eax
addq $0x148, %rsp            # imm = 0x148
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq