Пример #1
0
/****************************************************************
        FunctionName        :   GAgent_CloudTick.
        Description         :   GAgent Send cloud heartbeat to cloud
                                when mqttstatus is MQTT_STATUS_RUNNING

        Add by Alex.lin     --2015-03-10
****************************************************************/
void GAgent_CloudTick( pgcontext pgc )
{
    uint32 cTime=0,dTime=0;

    if( pgc->rtinfo.waninfo.mqttstatus != MQTT_STATUS_RUNNING )
        return;
    
    cTime = GAgent_GetDevTime_MS();
    dTime = abs(cTime - pgc->rtinfo.waninfo.send2MqttLastTime );
    
    if( dTime < CLOUD_HEARTBEAT )
        return ;
    
    if(pgc->rtinfo.waninfo.cloudPingTime > 2 )
    {
        ERRORCODE
        pgc->rtinfo.waninfo.cloudPingTime=0;
        GAgent_SetCloudServerStatus( pgc,MQTT_STATUS_START );
        GAgent_SetWiFiStatus( pgc,WIFI_CLOUD_STATUS,1 );
    }
    else
    {
        MQTT_HeartbeatTime();
        pgc->rtinfo.waninfo.cloudPingTime++;
        GAgent_Printf(GAGENT_INFO,"GAgent MQTT Ping ...");
    }
    pgc->rtinfo.waninfo.send2MqttLastTime = GAgent_GetDevTime_MS();

}
void make_rand(int8* data)
{
    int i;
    srand(GAgent_GetDevTime_MS());
    memset(data,0,10);
	
    for(i=0;i<10;i++)
    {
        data[i] = 65+rand()%(90-65);
    }
    data[10] = '\0';
    GAgent_Printf(GAGENT_INFO,"passcode:%s",data );
}
/****************************************************************
FunctionName    :   GAgentFindTestApHost.
Description     :   find the test ap host,like:GIZWITS_TEST_*
NetHostList_str :   GAgent wifi scan result .
return          :   1-GIZWITS_TEST_1
                    2-GIZWITS_TEST_2
                    fail :0.
Add by Alex.lin         --2015-05-06
****************************************************************/
uint8 GAgentFindTestApHost( NetHostList_str *pAplist )
{
    int8 i=0,apNum=0,ret=0;


    if( pAplist->ApNum <= 0 )
        return 0;
    for( i=0;i<pAplist->ApNum;i++ )
    {
        if( 0==memcmp(pAplist->ApList[i].ssid,GAGENT_TEST_AP1,strlen(GAGENT_TEST_AP1)) )
        {
            apNum=1;
        }
        if( 0==memcmp(pAplist->ApList[i].ssid,GAGENT_TEST_AP2,strlen(GAGENT_TEST_AP2)) )
        {
            /* 两个热点都能找到 */
            if( 1==apNum)
              apNum=3;
            else
              apNum=2;
        }
    }
    switch( apNum )
    {
        /* only the GIZWITS_TEST_1 */
        case 1:
            ret=1;
        break;
        /* only the GIZWITS_TEST_2 */
        case 2:
            ret=2;
        break;
        /* both of the test ap */
        case 3:
           srand(GAgent_GetDevTime_MS());
           ret = rand()%100;
           ret = (ret%2)+1; 
        break;
        default:
        ret =0;
        break;
    }
    return ret;
}
Пример #4
0
/****************************************************************
FunctionName    :   GAgent_LocalDataWriteP0
Description     :   send p0 to local io and add 0x55 after 0xff
                    auto.
cmd             :   MCU_CTRL_CMD or WIFI_STATUS2MCU
return          :   0-ok other -error
Add by Alex.lin     --2015-04-07
****************************************************************/
int32 GAgent_LocalDataWriteP0( pgcontext pgc,int32 fd,ppacket pTxBuf,uint8 cmd )
{
    int8 ret =0;
    uint16 datalen = 0;
    uint16 flag = 0;
    uint16 sendLen = 0;
    /* head(0xffff)| len(2B) | cmd(1B) | sn(1B) | flag(2B) |  payload(xB) | checksum(1B) */
    pTxBuf->phead = pTxBuf->ppayload - 8;
    pTxBuf->phead[0] = MCU_HDR_FF;
    pTxBuf->phead[1] = MCU_HDR_FF;
    datalen = pTxBuf->pend - pTxBuf->ppayload + 5;    //p0 + cmd + sn + flag + checksum
    *(uint16 *)(pTxBuf->phead + 2) = htons(datalen);
    pTxBuf->phead[4] = cmd;
    pTxBuf->phead[5] = GAgent_NewSN();
    *(uint16 *)(pTxBuf->phead + 6) = htons(flag);
    *( pTxBuf->pend )  = GAgent_SetCheckSum(pTxBuf->phead, (pTxBuf->pend)-(pTxBuf->phead) );
    pTxBuf->pend += 1;  /* add 1 Byte of checksum */

    sendLen = (pTxBuf->pend) - (pTxBuf->phead);
    sendLen = Local_DataAdapter( (pTxBuf->phead)+2,( (pTxBuf->pend) ) - ( (pTxBuf->phead)+2 ) );
    Local_SendData( fd, pTxBuf->phead,sendLen );

    if(GAgent_CheckAck( fd,pgc,pTxBuf->phead,sendLen,pLocalAckbuf,GAgent_GetDevTime_MS())==0)
    {
        GAgent_Printf( GAGENT_INFO,"%s %d GAgent_CheckAck OK",__FUNCTION__,__LINE__ );
        ret =0;  
    }
    else
    {
        GAgent_Printf( GAGENT_INFO,"%s %d GAgent_CheckAck Fail",__FUNCTION__,__LINE__ );
        ret=1;
    }
    resetPacket( pLocalAckbuf );
    
    return ret;
}
Пример #5
0
/****************************************************************
        FunctionName        :   Cloud_M2MDataHandle.
        Description         :   Receive cloud business data .
        xpg                 :   global context.
        Rxbuf                :   global buf struct.
        buflen              :   receive max len.
        return              :   >0 have business data,and need to 
                                   handle.
                                other,no business data.
        Add by Alex.lin     --2015-03-10
****************************************************************/
int32 Cloud_M2MDataHandle(  pgcontext pgc,ppacket pbuf /*, ppacket poutBuf*/, uint32 buflen)
{
    uint32 dTime=0,ret=0,dataLen=0;
    uint32 packetLen=0;
    pgcontext pGlobalVar=NULL;
    pgconfig pConfigData=NULL;
    int8 *username=NULL;
    int8 *password=NULL;
    uint8* pMqttBuf=NULL;
    fd_set readfd;
    int32 mqtt_fd=0;
    uint16 mqttstatus=0;
    uint8 mqttpackType=0;
    
    pConfigData = &(pgc->gc);
    pGlobalVar = pgc;
    pMqttBuf = pbuf->phead;
    
    mqttstatus = pGlobalVar->rtinfo.waninfo.mqttstatus;
    mqtt_fd = pGlobalVar->rtinfo.waninfo.m2m_socketid;
    readfd  = pGlobalVar->rtinfo.readfd;
    username = pConfigData->DID;
    password = pConfigData->wifipasscode;
    
    if( strlen(pConfigData->m2m_ip)==0 )
    {
        //GAgent_Printf( GAGENT_INFO,"M2M IP =0 IP TIME 1 %d 2%d ",pgc->rtinfo.waninfo.RefreshIPLastTime,pgc->rtinfo.waninfo.RefreshIPTime);
        return 0;
    }
    if( MQTT_STATUS_START==mqttstatus )
    {
        GAgent_Printf(GAGENT_INFO,"Req to connect m2m !");
        GAgent_Printf(GAGENT_INFO,"username: %s password: %s",username,password);

        Cloud_ReqConnect( pgc,username,password );
        GAgent_SetCloudServerStatus( pgc,MQTT_STATUS_RES_LOGIN );
        GAgent_Printf(GAGENT_INFO," MQTT_STATUS_START ");
        pgc->rtinfo.waninfo.send2MqttLastTime = GAgent_GetDevTime_MS();
        return 0;
    }
    dTime = abs( GAgent_GetDevTime_MS()-pGlobalVar->rtinfo.waninfo.send2MqttLastTime );
    if( FD_ISSET( mqtt_fd,&readfd )||( mqttstatus!=MQTT_STATUS_RUNNING && dTime>GAGENT_MQTT_TIMEOUT))
    {
        if( FD_ISSET( mqtt_fd,&readfd ) )
        {
          GAgent_Printf(GAGENT_DEBUG,"Data form M2M!!!");
          resetPacket( pbuf );
          packetLen = MQTT_readPacket(mqtt_fd,pbuf,GAGENT_BUF_LEN );
          if( packetLen==-1 ) 
          {
              mqtt_fd=-1;
              pGlobalVar->rtinfo.waninfo.m2m_socketid=-1;
              GAgent_SetCloudServerStatus( pgc,MQTT_STATUS_START );
              GAgent_Printf(GAGENT_DEBUG,"MQTT fd was closed!!");
              GAgent_Printf(GAGENT_DEBUG,"GAgent go to MQTT_STATUS_START");
              return -1;
          }
          else if(packetLen>0)
          {
            mqttpackType = MQTTParseMessageType( pMqttBuf );
            GAgent_Printf( GAGENT_DEBUG,"MQTT message type %d",mqttpackType );
          }
          else
          {
            return -1;
          }
        }

        /*create mqtt connect to m2m.*/
        if( MQTT_STATUS_RUNNING!=mqttstatus &&
            (MQTT_MSG_CONNACK==mqttpackType||MQTT_MSG_SUBACK==mqttpackType||dTime>GAGENT_MQTT_TIMEOUT))
        {
            switch( mqttstatus)
            {
                case MQTT_STATUS_RES_LOGIN:
                    
                     ret = Cloud_ResConnect( pMqttBuf );
                     if( ret!=0 )
                     {
                         GAgent_Printf(GAGENT_DEBUG," MQTT_STATUS_REQ_LOGIN Fail ");
                         if( dTime > GAGENT_MQTT_TIMEOUT )
                         {
                            GAgent_Printf(GAGENT_DEBUG,"MQTT req connetc m2m again!");
                            Cloud_ReqConnect( pgc,username,password );
                         }
                     }
                     else
                     {
                         GAgent_Printf(GAGENT_DEBUG,"GAgent do req connect m2m OK !");
                         GAgent_Printf(GAGENT_DEBUG,"Go to MQTT_STATUS_REQ_LOGINTOPIC1. ");
                         Cloud_ReqSubTopic( pgc,MQTT_STATUS_REQ_LOGINTOPIC1 );
                         GAgent_SetCloudServerStatus( pgc,MQTT_STATUS_RES_LOGINTOPIC1 );
                     }
                     break;
                case MQTT_STATUS_RES_LOGINTOPIC1:
                     ret = Cloud_ResSubTopic(pMqttBuf,pgc->rtinfo.waninfo.mqttMsgsubid );
                     if( 0!=ret )
                     {
                        GAgent_Printf(GAGENT_DEBUG," MQTT_STATUS_RES_LOGINTOPIC1 Fail ");
                        if( dTime > GAGENT_MQTT_TIMEOUT )
                        {
                            GAgent_Printf( GAGENT_DEBUG,"GAgent req sub LOGINTOPIC1 again ");
                            Cloud_ReqSubTopic( pgc,MQTT_STATUS_REQ_LOGINTOPIC1 );
                        }
                     }
                     else
                     {
                        GAgent_Printf(GAGENT_DEBUG,"Go to MQTT_STATUS_RES_LOGINTOPIC2. ");
                        Cloud_ReqSubTopic( pgc,MQTT_STATUS_REQ_LOGINTOPIC2 );
                        GAgent_SetCloudServerStatus( pgc,MQTT_STATUS_RES_LOGINTOPIC2 );
                     }
                     break;
                case MQTT_STATUS_RES_LOGINTOPIC2:
                     ret = Cloud_ResSubTopic(pMqttBuf,pgc->rtinfo.waninfo.mqttMsgsubid );
                     if( 0 != ret )
                     {
                        GAgent_Printf(GAGENT_DEBUG," MQTT_STATUS_RES_LOGINTOPIC2 Fail ");
                        if( dTime > GAGENT_MQTT_TIMEOUT )
                        {
                            GAgent_Printf( GAGENT_INFO,"GAgent req sub LOGINTOPIC2 again.");
                            Cloud_ReqSubTopic( pgc,MQTT_STATUS_REQ_LOGINTOPIC2 );
                        }
                     }
                     else
                     {
                        GAgent_Printf(GAGENT_DEBUG," Go to MQTT_STATUS_RES_LOGINTOPIC3. ");
                        Cloud_ReqSubTopic( pgc,MQTT_STATUS_REQ_LOGINTOPIC3 );
                        GAgent_SetCloudServerStatus( pgc,MQTT_STATUS_RES_LOGINTOPIC3 );
                     }
                     break;
                case MQTT_STATUS_RES_LOGINTOPIC3:
                      ret = Cloud_ResSubTopic(pMqttBuf,pgc->rtinfo.waninfo.mqttMsgsubid );
                     if( ret != 0 )
                     {
                        GAgent_Printf(GAGENT_DEBUG," MQTT_STATUS_RES_LOGINTOPIC3 Fail ");
                        if( dTime > GAGENT_MQTT_TIMEOUT )
                        {
                            GAgent_Printf(GAGENT_DEBUG,"GAgent req sub LOGINTOPIC3 again." );
                            Cloud_ReqSubTopic( pgc,MQTT_STATUS_REQ_LOGINTOPIC3 );
                        }
                     }
                     else
                     {
                        GAgent_Printf(GAGENT_CRITICAL,"GAgent Cloud Working...");
                        GAgent_SetCloudServerStatus( pgc,MQTT_STATUS_RUNNING );
                        GAgent_SetWiFiStatus( pgc,WIFI_CLOUD_STATUS,0 );
                     }
                      break;
                default:
                     break;
            }
            pgc->rtinfo.waninfo.send2MqttLastTime = GAgent_GetDevTime_MS();  
        }
        else if( packetLen>0 && ( mqttstatus == MQTT_STATUS_RUNNING ) )
        {
            int varlen=0,p0datalen=0;
            switch( mqttpackType )
            {
                case MQTT_MSG_PINGRESP:
                    pgc->rtinfo.waninfo.cloudPingTime=0;
                    GAgent_Printf(GAGENT_INFO,"GAgent MQTT Pong ... \r\n");
                break;
                case MQTT_MSG_PUBLISH:
                    dataLen = Mqtt_DispatchPublishPacket( pgc,pMqttBuf,packetLen );
                    if( dataLen>0 )
                    {
                        pbuf->type = SetPacketType( pbuf->type,CLOUD_DATA_IN,1 );
                        ParsePacket(  pbuf );
                        GAgent_Printf(GAGENT_INFO,"%s %d type : %04X len :%d",__FUNCTION__,__LINE__,pbuf->type,dataLen );
                    }
                break;
                default:
                    GAgent_Printf(GAGENT_WARNING," data form m2m but msg type is %d",mqttpackType );
                break;
            }
        }
    }
    return dataLen;
}
Пример #6
0
/****************************************************************
*
*   function    :   gagent do cloud config.
*   cloudstatus :   gagent cloud status.
*   return      :   0 successful other fail.
*   Add by Alex.lin --2015-02-28
****************************************************************/
uint32 Cloud_ConfigDataHandle( pgcontext pgc /*int32 cloudstatus*/ )
{
  int32 dTime=0;
  int32 ret =0;
  int32 respondCode=0;
  int32 cloudstatus = 0;
  pgcontext pGlobalVar=NULL;
  pgconfig pConfigData=NULL;

  uint16 GAgentStatus = 0;
  uint8 cloudConfiRxbuf[1024]={0};
  int8 *pDeviceID=NULL;

  fd_set readfd;
  int32 http_fd;

  pConfigData = &(pgc->gc);
  pGlobalVar = pgc;
  cloudstatus = pgc->rtinfo.waninfo.CloudStatus;
  GAgentStatus = pgc->rtinfo.GAgentStatus;

  if( (GAgentStatus&WIFI_STATION_STATUS)!= WIFI_STATION_STATUS)
    return 1 ;
  if( strlen( pgc->gc.GServer_ip)>IP_LEN || strlen( pgc->gc.GServer_ip)<7 )
  {
    GAgent_Printf( GAGENT_WARNING,"GServer IP is NULL!!");
    return 1;
  }
  if( cloudstatus== CLOUD_CONFIG_OK )
  {
      if( pGlobalVar->rtinfo.waninfo.http_socketid >0 )
      {
        GAgent_Printf( GAGENT_CRITICAL,"http config ok ,and close the socket.");
        close( pGlobalVar->rtinfo.waninfo.http_socketid );
        pGlobalVar->rtinfo.waninfo.http_socketid=-1;
      }
      return 1;
  }
  pDeviceID = pConfigData->DID;
  http_fd = pGlobalVar->rtinfo.waninfo.http_socketid;
  readfd  = pGlobalVar->rtinfo.readfd;
  
  if( CLOUD_INIT == cloudstatus )
  {
        GAgent_Printf( GAGENT_INFO,"%s %d",__FUNCTION__,__LINE__ );
        if( strlen(pDeviceID)==22 )/*had did*/
        {
            GAgent_Printf( GAGENT_INFO,"Had did !!!!" );
            ret = Cloud_ReqGetFid( pgc,OTATYPE_WIFI );
            GAgent_SetCloudConfigStatus( pgc,CLOUD_RES_GET_TARGET_FID);
        }
        else
        {
            GAgent_Printf( GAGENT_INFO,"Need to get did!!!" );
            GAgent_SetDeviceID( pgc,NULL );//clean did.
            ret = Cloud_ReqRegister( pgc );
            GAgent_SetCloudConfigStatus( pgc,CLOUD_RES_GET_DID );
        }
        return 0;
  }

  dTime = abs( GAgent_GetDevTime_MS()- pGlobalVar->rtinfo.waninfo.send2HttpLastTime );

  if( FD_ISSET( http_fd,&readfd )||( (cloudstatus<CLOUD_CONFIG_OK) && (dTime>GAGENT_HTTP_TIMEOUT)) )
  {
   GAgent_Printf(GAGENT_DEBUG,"HTTP Data from Gserver!%d", 2);
   ret = Cloud_ReadGServerConfigData( pgc,pGlobalVar->rtinfo.waninfo.http_socketid,cloudConfiRxbuf,1024 );
   respondCode = Http_Response_Code( cloudConfiRxbuf );
      
   GAgent_Printf(GAGENT_INFO,"http read ret:%d cloudStatus : %d",ret,cloudstatus );
   GAgent_Printf(GAGENT_INFO,"http response code : %d",respondCode );
   switch( cloudstatus )
   {
        case CLOUD_RES_GET_DID:
             ret = Cloud_ResRegister( cloudConfiRxbuf,ret,pDeviceID,respondCode );
             if( (RET_SUCCESS != ret) )/* can't got the did */
             {
                if(dTime>GAGENT_HTTP_TIMEOUT)
                {
                   GAgent_Printf(GAGENT_ERROR,"res register fail: %s %d",__FUNCTION__,__LINE__ );
                   GAgent_Printf(GAGENT_ERROR,"go to req register Device id again.");
                   ret = Cloud_ReqRegister( pgc );
                }
             }
             else
             {
                GAgent_SetDeviceID( pgc,pDeviceID );
                GAgent_DevGetConfigData( &(pgc->gc) );
                GAgent_Printf( GAGENT_DEBUG,"Register got did :%s len=%d",pgc->gc.DID,strlen(pgc->gc.DID) );
                 
                ret = Cloud_ReqGetFid( pgc,OTATYPE_WIFI );
                GAgent_SetCloudConfigStatus( pgc,CLOUD_RES_GET_TARGET_FID ); 
             }
             break;
        case CLOUD_RES_GET_TARGET_FID:
        {
            /*
              获取OTA信息错误进入provision 成功则进行OTA.
            */
             int8 download_url[256]={0};
             ret = Cloud_ResGetFid( download_url ,pGlobalVar->rtinfo.waninfo.firmwarever ,cloudConfiRxbuf,respondCode );
             if( RET_SUCCESS != ret )
             {
                 GAgent_Printf( GAGENT_WARNING,"GAgent get OTA info fail! go to provison! ");
                 ret = Cloud_ReqProvision( pgc );
                 GAgent_SetCloudConfigStatus( pgc,CLOUD_RES_PROVISION );
                 break;
             }
             else
             {
				ret = Cloud_isNeedOTA( NULL );
				if( 0==ret )
				{
					GAgent_Cloud_OTAByUrl( http_fd,download_url );
				}
                GAgent_Printf(GAGENT_INFO," CLOUD_RES_GET_TARGET_FID OK!!");
                GAgent_Printf(GAGENT_INFO,"url:%s",download_url);
                /* go to provision */
                ret = Cloud_ReqProvision( pgc );
                GAgent_SetCloudConfigStatus( pgc,CLOUD_RES_PROVISION );
             }
             
             break;
        }
        case CLOUD_RES_PROVISION:
             pGlobalVar->rtinfo.waninfo.Cloud3Flag = Http_Get3rdCloudInfo( pConfigData->cloud3info.cloud3Name,pConfigData->cloud3info.jdinfo.product_uuid ,
                                                            cloudConfiRxbuf );
             /* have 3rd cloud info need save to falsh */
             if( pGlobalVar->rtinfo.waninfo.Cloud3Flag == 1 )
             {
                GAgent_Printf(GAGENT_INFO,"3rd cloud name:%s",pConfigData->cloud3info.cloud3Name );
                GAgent_Printf(GAGENT_INFO,"3re cloud UUID: %s",pConfigData->cloud3info.jdinfo.product_uuid);
                GAgent_DevSaveConfigData( pConfigData );
             }
             ret = Cloud_ResProvision( pGlobalVar->minfo.m2m_SERVER , &pGlobalVar->minfo.m2m_Port,cloudConfiRxbuf,respondCode);
             if( ret!=0 )
             {
                
                if(dTime>GAGENT_HTTP_TIMEOUT)
                {
                   GAgent_Printf(GAGENT_WARNING,"Provision res fail ret=%d.", ret );
                   GAgent_Printf(GAGENT_WARNING,"go to provision again.");
                   ret = Cloud_ReqProvision( pgc );
                }
             }
             else
             {
                GAgent_Printf(GAGENT_INFO,"Provision OK!");
                GAgent_Printf(GAGENT_INFO,"M2M host:%s port:%d",pGlobalVar->minfo.m2m_SERVER,pGlobalVar->minfo.m2m_Port);
                GAgent_Printf(GAGENT_INFO,"GAgent go to login M2M !");
                GAgent_SetCloudConfigStatus( pgc,CLOUD_CONFIG_OK );
                //login to m2m.
                GAgent_SetCloudServerStatus( pgc,MQTT_STATUS_START );
                if( 1==GAgent_IsNeedDisableDID( pgc ) )
                {
                    GAgent_Printf(GAGENT_INFO,"Need to Disable Device ID!");
                    ret = Cloud_ReqDisable( pgc );
                    GAgent_SetCloudConfigStatus( pgc,CLOUD_RES_DISABLE_DID );
                    break;
                }
              }
             break;
        case CLOUD_RES_DISABLE_DID:
             ret = Cloud_ResDisable( respondCode );
             if(ret!=0)
             {
                 if(dTime>GAGENT_HTTP_TIMEOUT)
                 {
                    GAgent_Printf(GAGENT_WARNING,"Disable Device ID Fail.");
                 }
                 else
                 {
                    GAgent_SetCloudConfigStatus ( pgc,CLOUD_CONFIG_OK );
                 }
             }
             else
             {
                GAgent_Printf(GAGENT_INFO,"Disable Device ID OK!");
                GAgent_SetOldDeviceID( pgc,NULL,NULL,0 );
                GAgent_SetCloudConfigStatus ( pgc,CLOUD_CONFIG_OK );
             }
              
             break;
        case CLOUD_RES_POST_JD_INFO:
             ret = Cloud_JD_Post_ResFeed_Key( pgc,respondCode );
             if( ret!=0 )
             {
                 GAgent_Printf( GAGENT_WARNING," Post JD info respond fail!" );
                 if( dTime>GAGENT_HTTP_TIMEOUT )
                 {
                    GAgent_Printf( GAGENT_WARNING," Post JD info again");
                    ret = Cloud_JD_Post_ReqFeed_Key( pgc );
                 }
             }
             else
             {
                GAgent_SetCloudConfigStatus( pgc,CLOUD_CONFIG_OK );
             }
             break;
    }
        pGlobalVar->rtinfo.waninfo.send2HttpLastTime = GAgent_GetDevTime_MS();   
  }
}
Пример #7
0
/****************************************************************
FunctionName  :     GAgent_LocalGetInfo
Description   :     get localinfo like pk.
return        :     return 
Add by Alex.lin         --2015-04-18
****************************************************************/
void Local_GetInfo( pgcontext pgc )
{
    uint8 i=0;
    int32 pos=0;
    int8 length =0;
    uint16 *pTime=NULL;
    uint16 *pplength=NULL;
    uint8 get_Mcu_InfoBuf[9]=
    {
        0xff,0xff,0x00,0x05,0x01,0x01,0x00,0x00,0x07
    }; 
    //memset(&mcuAttrData[0],0,sizeof(mcuAttrData) );
    GAgent_DevLED_Green(0);
    get_Mcu_InfoBuf[8]  = GAgent_SetCheckSum( get_Mcu_InfoBuf, 8);
    Local_SendData( pgc->rtinfo.local.uart_fd,get_Mcu_InfoBuf, 9 );

    for( i=0;i<20;i++ )
    {
        if(GAgent_CheckAck( pgc->rtinfo.local.uart_fd,pgc,get_Mcu_InfoBuf,9,pgc->rtinfo.Rxbuf,GAgent_GetDevTime_MS())==0)
        {
            uint8 * Rxbuf=NULL;
            Rxbuf = pgc->rtinfo.Rxbuf->phead;

            pplength = (u16*)&((pgc->rtinfo.Rxbuf->phead +2)[0]);
            length = ntohs(*pplength);
            
            pos+=8;
            memcpy( pgc->mcu.protocol_ver, Rxbuf+pos, MCU_PROTOCOLVER_LEN );
            pgc->mcu.protocol_ver[MCU_PROTOCOLVER_LEN] = '\0';
            pos += MCU_PROTOCOLVER_LEN;

            memcpy( pgc->mcu.p0_ver,Rxbuf+pos, MCU_P0VER_LEN);
            pgc->mcu.p0_ver[MCU_P0VER_LEN] = '\0';
            pos+=MCU_P0VER_LEN;

            memcpy( pgc->mcu.hard_ver,Rxbuf+pos,MCU_HARDVER_LEN);
            pgc->mcu.hard_ver[MCU_HARDVER_LEN] = '\0';
            pos+=MCU_HARDVER_LEN;

            memcpy( pgc->mcu.soft_ver,Rxbuf+pos,MCU_SOFTVER_LEN);
            pgc->mcu.soft_ver[MCU_SOFTVER_LEN] = '\0';
            pos+=MCU_SOFTVER_LEN;

            memcpy( pgc->mcu.product_key,Rxbuf+pos,PK_LEN);
            pgc->mcu.product_key[PK_LEN] = '\0';
            pos+=PK_LEN;

            pTime = (u16*)&Rxbuf[pos];
            pgc->mcu.passcodeEnableTime = ntohs(*pTime);
            pos+=2;


            if( length >= (pos+MCU_MCUATTR_LEN+1 - MCU_P0_LEN - MCU_CMD_LEN) ) //pos+8+1:pos + mcu_attr(8B)+checksum(1B)
            {
                memcpy( pgc->mcu.mcu_attr,Rxbuf+pos, MCU_MCUATTR_LEN);
            }
            else
            {
                memset( pgc->mcu.mcu_attr, 0, MCU_MCUATTR_LEN);
            }

            GAgent_Printf( GAGENT_INFO,"GAgent get local info ok.");
            GAgent_Printf( GAGENT_INFO,"MCU Protocol Vertion:%s.",pgc->mcu.protocol_ver);
            GAgent_Printf( GAGENT_INFO,"MCU P0 Vertion:%s.",pgc->mcu.p0_ver);
            GAgent_Printf( GAGENT_INFO,"MCU Hard Vertion:%s.",pgc->mcu.hard_ver);
            GAgent_Printf( GAGENT_INFO,"MCU Soft Vertion:%s.",pgc->mcu.soft_ver);
            GAgent_Printf( GAGENT_INFO,"MCU old product_key:%s.",pgc->gc.old_productkey);
            GAgent_Printf( GAGENT_INFO,"MCU product_key:%s.",pgc->mcu.product_key);
            GAgent_Printf( GAGENT_INFO,"MCU passcodeEnableTime:%d s.\r\n",pgc->mcu.passcodeEnableTime);
            for( i=0;i<MCU_MCUATTR_LEN;i++ )
            {
                GAgent_Printf( GAGENT_INFO,"MCU mcu_attr[%d]= 0x%x.",i, (uint32)pgc->mcu.mcu_attr[i]);
            }
            
            if( strcmp( (int8 *)pgc->mcu.product_key,pgc->gc.old_productkey )!=0 )
            {
                GAgent_UpdateInfo( pgc,pgc->mcu.product_key );
                GAgent_Printf( GAGENT_INFO,"2 MCU old product_key:%s.",pgc->gc.old_productkey);
            }
            break;
        }
    }
    if( 20==i )
    {
    
        GAgent_Printf( GAGENT_INFO," GAgent get local info fail ... ");
        GAgent_Printf( GAGENT_INFO," Please check your local data,and restart GAgent again !!");
        GAgent_DevReset();
    }
}