예제 #1
0
/*========================================================================
    Routine    Description:
        iot_atcmd_exec_ver -- get FW version

    Arguments:
    Return Value: 0 is success,  -1 is out of memory
    Note:
========================================================================*/
int16 iot_atcmd_exec_ver(puchar pCmdBuf)
{
    size_t  len=0 , len2 =0;

    /* the response header format is:  "AT#CmdType=" */
    iot_atcmd_resp_header((int8 *)pCmdBuf, &len, AT_CMD_PREFIX, AT_CMD_VER);

    /*AT command Version*/
    len2 = strlen(FW_VERISON_CUST);
    memcpy(pCmdBuf + len, FW_VERISON_CUST, len2);
    len += len2;

    len2 = strlen("\n");
    if ( (len + len2 + 3) >= AT_CMD_MAX_LEN) {
        /*pCmdBuf is mallocated on    iot_atcmd_hdlr(),
           but here it's start after "AT#"
           thus it's length is     (AT_CMD_MAX_LEN-3); */
        return -1;
    }
    memcpy(pCmdBuf + len, "\n", len2);
    len += len2;

    //len += 1;
    //*(pCmdBuf+len) = '\n';

    iot_uart_output((puchar)pCmdBuf, (int16)len);
    return 0;
}
예제 #2
0
void handle_tcp_srv_app1(void)
{
    static struct timer user_timer; //create a timer;
    static bool app_init = FALSE;

    if (uip_newdata()) {
        printf_high("Server RX [%d] bytes\n", uip_datalen());
        iot_uart_output(uip_appdata, uip_datalen());
    }

    if (uip_poll()) {
        /* below codes shows how to send data to client  */
        if ((app_init == FALSE) || timer_expired(&user_timer)) {
            printf_high("TCP SERVER APP1 uip_poll_timer_expired\n");
            uip_send("hello,this is tcp srv...", 24);
            timer_set(&user_timer, 5*CLOCK_SECOND);
            app_init = TRUE;
        }
    }
}
예제 #3
0
void handle_tcp_app(void)
{
    /*
    * The uip_conn structure has a field called "appstate" that holds
    * the application state of the connection. We make a pointer to
    * this to access it easier.
    */
    struct iot_tcp_app_state *s = &(uip_conn->appstate);
    u16_t lport = HTONS(uip_conn->lport);

    if (uip_aborted() || uip_timedout() || uip_closed()) {
        switch (lport) {
            case 7682: //IoT as clent.
                cli_fd = -1;
        }
        printf("fd %d uip_aborted.%d\n", uip_conn->fd, HTONS(uip_conn->lport));
#if ENABLE_DATAPARSING_SEQUENCE_MGMT
        IoT_cp_app_connection_closed(uip_conn->fd);
#endif
        s->state = IOT_APP_S_CLOSED;
        s->buf = NULL;
        s->len = 0;
        uip_abort();
    }

    if (uip_connected()) {
        u8_t raddr[16];
        u8_t logon_msg[16] = "userlogon:";

        sprintf((char *)raddr, "%d.%d.%d.%d",
                uip_ipaddr1(uip_conn->ripaddr), uip_ipaddr2(uip_conn->ripaddr),
                uip_ipaddr3(uip_conn->ripaddr), uip_ipaddr4(uip_conn->ripaddr));

        printf_high("Connected fd:%d,lp:%d,ra:%s,rp:%d\n",
                    uip_conn->fd, HTONS(uip_conn->lport), raddr, HTONS(uip_conn->rport));

#if ENABLE_DATAPARSING_SEQUENCE_MGMT
        IoT_cp_app_connection_connected(uip_conn->fd
#if (NO_USED_CODE_REMOVE==0)
                                        ,HTONS(uip_conn->lport),
                                        raddr,
                                        HTONS(uip_conn->rport)
#endif
                                       );
#endif

        s->state = IOT_APP_S_CONNECTED;
        switch (lport) {
            case 7682:
                memcpy(logon_msg+10, gCurrentAddress, 6);
                uip_send(logon_msg, 16);
                break;
        }
    }

    if (uip_acked()) {
        printf("uip_acked.\n");
        s->state = IOT_APP_S_DATA_ACKED;
        s->buf = NULL;
        s->len = 0;
    }

    if (uip_newdata()) {
        printf("RX fd : %d\n", uip_conn->fd);
        if (lport == IoTpAd.ComCfg.Local_TCP_Srv_Port || lport==7682) {
#if ENABLE_DATAPARSING_SEQUENCE_MGMT
            iot_app_proc_pkt(uip_conn->fd, uip_appdata,uip_datalen());
#else
            iot_app_proc_pkt(uip_appdata,uip_datalen());
#endif
#if CFG_SUPPORT_TCPIP_ROBUST_TEST
        } else if (lport==7684) {
            uip_send(uip_appdata, uip_datalen());
#endif
        } else {
#if ATCMD_TCPIP_SUPPORT
            iot_uart_output(uip_appdata, (int16)uip_datalen());
#endif
        }
    }

    /* check if we have data to xmit for this connection.*/
    if (uip_poll()) {
#if ATCMD_TCPIP_SUPPORT
        if (s->state == IOT_APP_S_CLOSED) {
            uip_close();
        } else if (s->len > 0) {
            uip_send(s->buf, s->len);
            s->state = IOT_APP_S_DATA_SEND;
        }
#endif
    }
}