Пример #1
0
void GetWifiHotspots( int tcpclient,u8* buf, int bufferlen )
{
    varc Uart_varatt;
    u16 TempVarLen;
    int i;
    int totalLen;
    u8 *WifiHotspots_Ack;
    if(g_WifihotspotsLen == 0)
    {
        return;
    }
    WifiHotspots_Ack  = (u8*)malloc(1024);
    if(WifiHotspots_Ack == NULL)
    {
        return;
    }
    //varlen = flag(1b)+cmd(2b)+g_WifihotspotsLen
    TempVarLen = 1+2+g_WifihotspotsLen;    
    Uart_varatt=Tran2varc(TempVarLen);
    totalLen=4+TempVarLen+Uart_varatt.varcbty;

    WifiHotspots_Ack[0]= 0x00;
    WifiHotspots_Ack[1]= 0x00;
    WifiHotspots_Ack[2]= 0x00;
    WifiHotspots_Ack[3]= 0x03;
    //varlen
    for(i=0;i<Uart_varatt.varcbty;i++)
	{
		WifiHotspots_Ack[4+i] = Uart_varatt.var[i];
	}
    //flag
    WifiHotspots_Ack[4+Uart_varatt.varcbty]=0x00;
    //cmd
    WifiHotspots_Ack[4+Uart_varatt.varcbty+1]= 0x00;
    WifiHotspots_Ack[4+Uart_varatt.varcbty+2]= 0x0D;
    //wifiHotspots
    memcpy( &WifiHotspots_Ack[4+Uart_varatt.varcbty+3],g_Wifihotspots,g_WifihotspotsLen);    
    GAgent_Printf(GAGENT_INFO,"g_WifihotspotsLen:%d",g_WifihotspotsLen);
    send(tcpclient,WifiHotspots_Ack,totalLen,0);
    
    free(WifiHotspots_Ack);
}
Пример #2
0
/****************************************************************
        FunctionName    :   GAgent_Lan_SendTcpData
        Description     :   send buf data to TCP client.
        return          :   void
        Add by Will.zhou     --2015-03-17
****************************************************************/
void GAgent_Lan_SendTcpData(pgcontext pgc,ppacket pTxBuf)
{
    varc sendvarc;
    uint32 dataLen;
    int i;
    int offset = 0;

        /* protocol(4B) | varlen(xB) | flag(1B) | cmd(2B) | p0(xB)  */
    dataLen = pTxBuf->pend - pTxBuf->ppayload + LAN_PROTOCOL_CMD_LEN + LAN_PROTOCOL_FLAG_LEN;
    sendvarc = Tran2varc(dataLen);
    pTxBuf->phead = pTxBuf->ppayload - sendvarc.varcbty - 
            LAN_PROTOCOL_HEAD_LEN - LAN_PROTOCOL_CMD_LEN - LAN_PROTOCOL_FLAG_LEN;

    offset = 0;
    /* protocol */
    *(uint32 *)pTxBuf->phead = htonl(GAGENT_PROTOCOL_VERSION);
    offset += LAN_PROTOCOL_HEAD_LEN;
    /* varLen */
    for(i=0;i<sendvarc.varcbty;i++)
    {
        pTxBuf->phead[offset] = sendvarc.var[i];
        offset++;
    }
    /* flag */
    pTxBuf->phead[offset] = 0x00;
    offset += 1;
    /* cmd */
    *(uint16 *)(pTxBuf->phead + offset) = htons(0x0091);
    offset += LAN_PROTOCOL_CMD_LEN;

    for(i = 0; i < LAN_TCPCLIENT_MAX; i++)
    {
        if(pgc->ls.tcpClient[i].fd > 0 && 
            LAN_CLIENT_LOGIN_SUCCESS == pgc->ls.tcpClient[i].isLogin)
        {
            send(pgc->ls.tcpClient[i].fd, pTxBuf->phead, pTxBuf->pend - pTxBuf->phead, 0);
        }
    }
        
}
Пример #3
0
void GetWifiVersion( int nSocket,unsigned char *pData,int datalength )
{
    u8 WifiVersion[100];
    int i;
    u16 tempVarLen=0;
    varc temp_varatt;
    tempVarLen = 9+g_busiProtocolVerLen;
    //protocolver
    WifiVersion[0]=0x00;
    WifiVersion[1]=0x00;
    WifiVersion[2]=0x00;
    WifiVersion[3]=0x03;
    temp_varatt=Tran2varc(tempVarLen);
    //varLen
    for(i=0;i<temp_varatt.varcbty;i++)
	{
		WifiVersion[4+i] = temp_varatt.var[i];
	}    
    //flag
    WifiVersion[4+temp_varatt.varcbty]=0x00;
    //cmd 
    WifiVersion[4+temp_varatt.varcbty+1]=0x00;
    WifiVersion[4+temp_varatt.varcbty+2]=0x0b;
    //genProtocolVer
    WifiVersion[4+temp_varatt.varcbty+3]=0x00;
    WifiVersion[4+temp_varatt.varcbty+4]=0x00;
    WifiVersion[4+temp_varatt.varcbty+5]=0x00;
    WifiVersion[4+temp_varatt.varcbty+6]=0x03;
    //busiProtocolVerLen
    WifiVersion[4+temp_varatt.varcbty+7]=g_busiProtocolVerLen/255;
    WifiVersion[4+temp_varatt.varcbty+8]=g_busiProtocolVerLen%255;
    //busiProtocolVerLen
    memcpy( &WifiVersion[4+temp_varatt.varcbty+9],g_busiProtocolVer,g_busiProtocolVerLen );
    GAgent_Printf(GAGENT_INFO,"In GetWifiVersion sendLen:%d",tempVarLen+temp_varatt.varcbty+4);
    send( nSocket,WifiVersion,tempVarLen+temp_varatt.varcbty+4,0 );
}
Пример #4
0
/*************************************************
*       FUNCTION :	send mcu cmd to cloud 
*       uartbuf	 :	uart receive buf 
*
*************************************************/
void MCU_SendPacket2Cloud( u8* uartbuf,int uartbufLen )
{
    u8 *SendPack=NULL;
    int SendPackLen=0;
    u8 *ClientId=NULL;
    int ClientIdLen=0;
    int UartP0Len=0;    
    u8 McuSendTopic[200]={0};
    
    short VarLen=0;
    varc SendVarc;
    int i;
    
    ClientIdLen = uartbuf[8]*256+uartbuf[9];
    ClientId = (u8*)malloc( ClientIdLen );
    if( ClientId==NULL )
    {
        return;
    }
    
    //protocolVer(4B)+len(2B)+cmd(2B)+phoneClientIdLen(2B)+phoneClientId+p0
    UartP0Len = uartbufLen-10-ClientIdLen;
    
    
    memset(ClientId,0,ClientIdLen);
    memcpy(ClientId,uartbuf+10,ClientIdLen);    
    
    memcpy( McuSendTopic,"dev2app/",strlen("dev2app/"));
    memcpy( McuSendTopic+strlen("dev2app/"),g_Xpg_GlobalVar.DID,strlen(g_Xpg_GlobalVar.DID));
    McuSendTopic[strlen("dev2app/")+strlen(g_Xpg_GlobalVar.DID)]='/';
    memcpy( McuSendTopic+strlen("dev2app/")+strlen(g_Xpg_GlobalVar.DID)+1,ClientId,ClientIdLen);
    
    //protocolVer(4B)+varLen(1~4B)+flag(1B)+cmd(2B)+P0
    VarLen=1+2+UartP0Len;
    SendVarc = Tran2varc(VarLen);
    SendPackLen = 4+SendVarc.varcbty+1+2+UartP0Len;
    
    SendPack = (u8*)malloc(SendPackLen);
    if( SendPack==NULL ) 
    {
        free(ClientId);
        return ;
    }
    
    //protocolVer
    SendPack[0] = 0x00;
    SendPack[1] = 0x00;
    SendPack[2] = 0x00;
    SendPack[3] = 0x03;
    //varLen
    for(i=0;i<SendVarc.varcbty;i++)
	{
		SendPack[4+i] = SendVarc.var[i];
	}
     //flag   
    SendPack[4+SendVarc.varcbty] = 0x00;
    //CMD
    SendPack[4+SendVarc.varcbty+1]=0x00;
    SendPack[4+SendVarc.varcbty+2]=0x91;
    //p0
    memcpy( (SendPack+4+SendVarc.varcbty+3),uartbuf+10+ClientIdLen,UartP0Len);
    GAgent_Printf(GAGENT_INFO,"MCU data to Topic: %s",McuSendTopic);  
        
    PubMsg( &g_stMQTTBroker,McuSendTopic,SendPack,SendPackLen,0);
        
    free( SendPack );
    free( ClientId );
    
    return;
}
Пример #5
0
/********************************************************************
        Function        :   MQTT_SenData.
        Description     :   send buf data to m2m.
        szDID           :   Device ID.
        buf             :   need to send data pointer.
        buflen          :   buf length .
        return          :   0-ok 
                            other fail.
        Add by Alex.lin     --2015-03-17
********************************************************************/
int32 MQTT_SenData( pgcontext pgc, int8 *szDID, ppacket pbuf,/*uint8 *buf,*/ int32 buflen )
{
    uint8 *sendpack=NULL;
    int32 i=0,sendpacklen=0,headlen=0;
    int16 varlen=0;
    volatile varc sendvarc;
    int8 msgtopic[64]= {0};
    int32 didlen=0;
    uint16 cmd = pgc->rtinfo.stChannelAttrs.cloudClient.cmd;
    int32 sn = pgc->rtinfo.stChannelAttrs.cloudClient.sn;
    int8 *clienid = pgc->rtinfo.stChannelAttrs.cloudClient.phoneClientId;
    uint8 pos = 0;
    int32 clienIdLen;
    
    didlen = strlen(szDID);
    if(didlen!=22)
        return -1;
    
    memcpy( msgtopic,"dev2app/",strlen("dev2app/"));
    pos += strlen("dev2app/");
    memcpy( msgtopic+strlen("dev2app/"),szDID,didlen );
    pos += didlen;
    if(0x0094 == cmd)
    {
        clienIdLen = strlen( (const int8 *)clienid);
        if(clienIdLen > 0)
        {
            msgtopic[pos] = '/';
            pos++;
            memcpy( msgtopic+pos,clienid,clienIdLen );
            pos+=clienIdLen;
        }
    }
    msgtopic[pos] = '\0';
    
    //protocolVer(4B)+varLen(1~4B)+flag(1B)+cmd(2B)+P0
    varlen = 1+2+buflen;
    if(0x0093 == cmd || 0x0094 == cmd)
    {
        varlen += sizeof(sn);
    }
    sendvarc=Tran2varc(varlen);
    sendpacklen = 4+sendvarc.varcbty+varlen;
    headlen = sendpacklen-buflen;
    
    sendpack = ( (pbuf->ppayload)-headlen );
    //protocolVer
    sendpack[0] = 0x00;
    sendpack[1] = 0x00;
    sendpack[2] = 0x00;
    sendpack[3] = 0x03;
    //varLen
    for(i=0;i<sendvarc.varcbty;i++)
    {
        sendpack[4+i] = sendvarc.var[i];
    }
     //flag   
    sendpack[4+sendvarc.varcbty] = 0x00;
    //CMD
    *(uint16 *)&sendpack[4+sendvarc.varcbty+1] = htons(cmd);
    if(0x0093 == cmd || 0x0094 == cmd)
    {
        *(int32 *)&sendpack[4+sendvarc.varcbty+1 + 2] = htonl(sn);
    }

    GAgent_Printf(GAGENT_DEBUG,"------SEND TO Cloud ------\r\n");
    for(i=0;i<sendpacklen;i++)
        GAgent_Printf(GAGENT_DUMP," %02X",sendpack[i] );
    
    PubMsg( &g_stMQTTBroker,msgtopic,(int8 *)sendpack,sendpacklen,0 );

    return 0;
}
Пример #6
0
void Lan_sendTcpData(pgcontext pgc, int32 fd, uint16 cmd, int32 sn, ppacket pTxBuf)
{
    varc sendvarc;
    uint32 dataLen;
    int i;
    int offset = 0;

        /* protocol(4B) | varlen(xB) | flag(1B) | cmd(2B) | p0(xB)  */
    dataLen = pTxBuf->pend - pTxBuf->ppayload + LAN_PROTOCOL_CMD_LEN + LAN_PROTOCOL_FLAG_LEN;
    /* while cmd == 0x93/94,sn follow with cmd */
    if(GAGENT_LAN_CMD_CTL_93 == cmd || GAGENT_LAN_CMD_CTLACK_94 == cmd)
    {
        dataLen += LAN_PROTOCOL_SN_LEN;
    }
    sendvarc = Tran2varc(dataLen);
    pTxBuf->phead = pTxBuf->ppayload - sendvarc.varcbty - 
            LAN_PROTOCOL_HEAD_LEN - LAN_PROTOCOL_CMD_LEN - LAN_PROTOCOL_FLAG_LEN;
    
    /* while cmd == 0x93/94,sn follow with cmd */
    if(GAGENT_LAN_CMD_CTL_93 == cmd || GAGENT_LAN_CMD_CTLACK_94 == cmd)
    {
        pTxBuf->phead -= LAN_PROTOCOL_SN_LEN;
    }
    offset = 0;
    /* protocol */
    *(uint32 *)pTxBuf->phead = htonl(GAGENT_PROTOCOL_VERSION);
    offset += LAN_PROTOCOL_HEAD_LEN;
    /* varLen */
    for(i=0;i<sendvarc.varcbty;i++)
    {
        pTxBuf->phead[offset] = sendvarc.var[i];
        offset++;
    }
    /* flag */
    pTxBuf->phead[offset] = 0x00;
    offset += 1;

    /* cmd */
    *(uint16 *)(pTxBuf->phead + offset) = htons(cmd);
    offset += LAN_PROTOCOL_CMD_LEN;
    switch(cmd)
    {
        case GAGENT_LAN_CMD_CTL_93:
            sn = 0;
            *(int32 *)(pTxBuf->phead + offset) = htonl(sn);
            offset += LAN_PROTOCOL_SN_LEN;
            fd = -1;
            break;
        case GAGENT_LAN_CMD_CTLACK_94:
            *(int32 *)(pTxBuf->phead + offset) = htonl(sn);
            offset += LAN_PROTOCOL_SN_LEN;
            break;
        case GAGENT_LAN_CMD_TRANSMIT_91:
            break;
        default:
            /* not support ,return directly */
            return ;
            break;
    }

    if(fd >= 0)
    {
        send(fd, pTxBuf->phead, pTxBuf->pend - pTxBuf->phead, 0);
    }
    else
    {
        Lan_Upload_AllApp(pgc, pTxBuf);
    }
    
    return ;
}