Exemplo n.º 1
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();
    }
}
void GAgentSetLedStatus( uint16 gagentWiFiStatus )
{
    static uint8  Router_Connect_flag = 0;
    static uint32 Router_Connect_count = 0;
    static uint8  Airlink_flag = 0;
    static uint32 Airlink_count = 0;
    static uint8  Cloud_Connect_flag = 0;
    static uint32 Cloud_Connect_count = 0;

    switch( gagentWiFiStatus&0x35 )
    {
        case WIFI_MODE_AP: 
            GAgent_DevLED_Red( 1 );
            GAgent_DevLED_Green( 0 ); 
            break;
        case WIFI_MODE_ONBOARDING:
            if( (gagentWiFiStatus&WIFI_MODE_AP) == 0 )
            {
                Airlink_count++;
                if( Airlink_count%4 == 0)
                {
                    Airlink_flag = !Airlink_flag;
                    Airlink_count = 0;
                }
                GAgent_DevLED_Red( 0 );
                GAgent_DevLED_Green( Airlink_flag ); 
            }
            else
            {
                GAgent_DevLED_Red( 1 );
                GAgent_DevLED_Green( 0 ); 
            }
            break;
        case WIFI_STATION_CONNECTED:          
            GAgent_DevLED_Red( 1 );
            GAgent_DevLED_Green( 1 );      
            break;
        case ( WIFI_CLOUD_CONNECTED | WIFI_STATION_CONNECTED ):               
            if( Cloud_Connect_count < ONE_MINUTE*10 )
            {
                Cloud_Connect_count++;
                if( Cloud_Connect_count%4 == 0)
                {
                    Cloud_Connect_flag = !Cloud_Connect_flag;           
                }
                GAgent_DevLED_Red( Cloud_Connect_flag );
                GAgent_DevLED_Green( !Cloud_Connect_flag );
            }
            else
            {
                GAgent_DevLED_Red( 0 );
                GAgent_DevLED_Green( 0 );  
            }
            break;
        default: //don't connect router           
            Router_Connect_count++;            
            if( Router_Connect_count%4 == 0)
            {
                Router_Connect_flag = !Router_Connect_flag;
                Router_Connect_count = 0;
            }
            GAgent_DevLED_Red( 1 );
            GAgent_DevLED_Green( Router_Connect_flag );
            break;
    }
   
}