static int32_t cat1_tcp_server_close( uint8_t conn_id )
{
+#if 1
+ char cmd[20];
+ sprintf( cmd, "AT+QICLOSE=%d",conn_id );
+ cat1_at_send_no_reply( cmd, strlen(cmd), true );
+ return 0;
+#else
char cmd[20];
atcmd_config_t at_cfg;
char resp_buf[20];
//连接TCP服务器
//AT+CIPSTART="TCP","192.168.3.116",8080 //protocol, server IP and port
at_cfg.reply_prefix = NULL;
- at_cfg.reply_success_postfix="OK"; //"+QIOPEN:conn_id,err\r\n";
+ at_cfg.reply_success_postfix="OK\r\n"; //"+QIOPEN:conn_id,err\r\n";
at_cfg.reply_fail_postfix ="ERROR"; //"ERROR CLOSED";
sprintf( cmd, "AT+QICLOSE=%d",conn_id );
memset( resp_buf, 0, sizeof(resp_buf) );
}else{
return -1;
}
+#endif
}
cat1_tcp_rx_buf[cat1_tcp_rx_n] = 0;
#if 1
{ extern int32_t iot_cmd_parse( uint32_t link, char *cmd );
- int32_t act = iot_cmd_parse( 0, (char *)cat1_tcp_rx_buf );
+ int32_t act = iot_cmd_parse( 2, (char *)cat1_tcp_rx_buf );
if( act == 1 || act == 2 ){
//char * s = lock_resp_str();
if( len <= sizeof(ota_rx_buf ) ){
int n =cat1_at_read( (char*)(ota_rx_buf), len );
ota_rx_n = len;
- debug_printf( " ota recv data %d bytes, rd:%d, wifi buf:%d[%d..%d]\n", len, n, rx_buf_wr-rx_buf_rd, rx_buf_rd, rx_buf_wr );
+ debug_printf( "cat1 - ota recv data %d bytes, rd:%d, wifi buf:%d[%d..%d]\n", len, n, rx_buf_wr-rx_buf_rd, rx_buf_rd, rx_buf_wr );
ota_handle_http_resp_data( ota_rx_buf, ota_rx_n );
}
}
atcmd_config_t at_cfg;
int32_t ret = 0;
- at_cfg.reply_prefix = ">";
- at_cfg.reply_success_postfix="SEND";
+if(conn_id==4) debug_printf( "cat1 ota req:[%s]\n", data);
+
+ at_cfg.reply_prefix = NULL; //">";
+ at_cfg.reply_success_postfix="SEND OK\r\n";
at_cfg.reply_fail_postfix = "ERROR";
sprintf( cmd, "AT+QISEND=%d,%d", conn_id, sz );
resp_buf[0] = 0;
g_dev.cat1_connected = 1 ;
}
+static void cat1_ota_closed_cb(void *arg, char *rspinfo, int rsplen)
+{
+ if( ota_link_connected )
+ ota_link_connected = 0 ;
+}
+
void user_cat1_task( void* unused )
{
uint32_t rpt_secs = 0;
cat1_at_register_callback("+QIURC: \"recv\"", NULL, NULL, 0, tcp_rx_data_handle, NULL);
//+QIURC: "closed",<connectID>
cat1_at_register_callback( "+QIURC: \"closed\",3", NULL, NULL, 0, cat1_tcp_closed_cb, NULL );
+ cat1_at_register_callback( "+QIURC: \"closed\",4", NULL, NULL, 0, cat1_ota_closed_cb, NULL );
while( 1 ){
if( cat1_connect() != 0 ){
if( cat1_tcp_server_connect( CONN_ID_OTA, host, port ) == 0 ){
ota_link_connected = 1;
}else{
- osDelay(1000);
cat1_tcp_server_close( CONN_ID_OTA );
+ osDelay(2000);
continue;
}
}
#define OTA_LINK_WIFI 0
#define OTA_LINK_ETH 1
+#define OTA_LINK_CAT1 2
#define OTA_FW_HEAD_FLAG 0xAA01
int32_t ota_start( uint32_t link, char * url, char *ver )
{
- if( link != OTA_LINK_WIFI && link != OTA_LINK_ETH ){
+ if( link != OTA_LINK_WIFI && link != OTA_LINK_ETH && link != OTA_LINK_CAT1 ){
return -1;
}
//return 0;
}
+int32_t cat1_ota_start( char * url, char *ver )
+{
+ return ota_start( OTA_LINK_CAT1, url, ver );
+ //return 0;
+}
+
int32_t ota_handle_http_resp( uint8_t *rx_data, uint32_t rx_sz )
{
//http_resp_flag = 1;
//tcp connect fail, ota fail
return ret;
}
+ }else if( g_ota.link == OTA_LINK_CAT1 ){
+ ret = cat1_ota_requst( g_ota.host, g_ota.port, http_req );
+ if(ret < 0){
+ //tcp connect fail, ota fail
+ return ret;
+ }
}else{
return -1;
}