uart4_send_data(buf,len);
}
-static char * response_data = NULL;
-static int response_len = 0;
-/*
-data: the data is received http context data
-len: the length of http context data
-num: the http response header "Content-Length" value
-cbdata: user private data
-*/
-static void response_cb(char * data, int len, int num, void *cbdata)
-{
- char * temp;
- char *private_data=(char *)cbdata;
-
- //FR8012HAQ_LOG("[http_client_test]Get private_data %s\n", private_data);
-
- FR8012HAQ_LOG("[http_client_test]Get data %d\n", len);
-
- temp = (void*)malloc(response_len + len);
- if (!temp) {
- FR8012HAQ_LOG("[http_client_test]Malloc failed...\n");
- return;
- }
- memset(temp, 0, response_len + len);
- if (response_data) {
- memcpy(temp, response_data, response_len);
- free(response_data);
- }
- memcpy(&temp[response_len], data, len);
- response_data = temp;
- response_len += len;
-}
-http_client * fr8012haq_client = NULL;
-static void * fr8012haq_http_post_json_timer = NULL;
-void fr8012haq_http_post_json_cb(unsigned int p)
-{
- if(fr8012haq_client!=NULL)
- http_client_stop(fr8012haq_client);
- uos_timer_stop(fr8012haq_http_post_json_timer);
-
-}
-int fr8012haq_http_post_json(char *url,char *token,char *post_data,char *read_buf,unsigned int read_buf_max,unsigned int timeout)
-{
- int response_code= 0;
- int ret = 0;
- struct http_client_list * header = NULL;
- if (fr8012haq_client != NULL)
- return -2;
- if(fr8012haq_http_post_json_timer == NULL )
- uos_timer_create(&fr8012haq_http_post_json_timer);
-
- uos_timer_start(fr8012haq_http_post_json_timer, MS_TO_TICKS(timeout), MS_TO_TICKS(timeout), fr8012haq_http_post_json_cb, NULL);
-
- fr8012haq_client = http_client_init();
- http_client_setopt(fr8012haq_client, HTTPCLIENT_OPT_URL, url); /*set URL:support http/https and ip4/ip6*/
- http_client_setopt(fr8012haq_client, HTTPCLIENT_OPT_HTTP1_0, 0); /*"0" is HTTP 1.1, "1" is HTTP 1.0*/
- http_client_setopt(fr8012haq_client, HTTPCLIENT_OPT_RESPONSECB, response_cb); /*response callback*/
- //http_client_setopt(fr8012haq_client, HTTPCLIENT_OPT_RESPONSECB_DATA, private_data); /*set user private data,*/
- http_client_setopt(fr8012haq_client, HTTPCLIENT_OPT_METHOD, HTTPCLIENT_REQUEST_POST); /*set method,support GET/POST/PUT*/
- http_client_setopt(fr8012haq_client, HTTPCLIENT_OPT_POSTDATA, post_data); /*post data is http context*/
- http_client_setopt(fr8012haq_client, HTTPCLIENT_OPT_POSTLENGTH, strlen(post_data)); /*http context length*/
- header = http_client_list_append(header, "Content-Type: application/json\r\n");
- header = http_client_list_append(header, "Accept: */*\r\n");
- if(token)
- {
- char * token_buf = malloc(strlen(token)+100);
- if(!token_buf)
- {
- ret = -1;
- goto EXIT;
-
- }
- memset(token_buf,0,strlen(token)+100);
- snprintf(token_buf,strlen(token)+100,"token: %s\r\n",token_buf);
- header = http_client_list_append(header, token_buf);
- free(token_buf);
- }
-
-
- http_client_setopt(fr8012haq_client, HTTPCLIENT_OPT_HTTPHEADER, header);
- http_client_getinfo(fr8012haq_client, HTTPCLIENT_GETINFO_TCP_STATE, &response_code);
- if(response_code != HTTP_TCP_ESTABLISHED){
- FR8012HAQ_LOG("fr8012haq_http_post_json:http tcp not connecting\n");
- ret = -1;
- goto EXIT;
- }
- response_code=http_client_perform(fr8012haq_client); /*execute http send and recv*/
- if(response_code != HTTP_CLIENT_OK){
- FR8012HAQ_LOG("[http_client_test]http perform have some wrong[%d]\n",response_code);
- ret = -1;
- goto EXIT;
- }
- http_client_getinfo(fr8012haq_client, HTTPCLIENT_GETINFO_RESPONSE_CODE, &response_code);
- if (response_code != 200 && response_code != 204) {
- FR8012HAQ_LOG("[http_client_test]response is not 'HTTP OK'(%d)\n", response_code);
- }
- int read_buf_len = 0;
- if(response_len>=read_buf_max)
- read_buf_len = read_buf_max-1;
- else
- read_buf_len = response_len;
- memcpy(read_buf,response_data,read_buf_len);
- read_buf[read_buf_len] = 0;
- FR8012HAQ_LOG("fr8012haq_http_post_json:Get total data len:%d\n", response_len);
- FR8012HAQ_LOG("fr8012haq_http_post_json:response_data %s\n",read_buf);
- uos_timer_stop(fr8012haq_http_post_json_timer);//获取数据成功,关闭定时器
-EXIT:
- if (header) {
- http_client_list_destroy(header);
- header = NULL;
- }
- if(fr8012haq_client)
- {
- http_client_shutdown(fr8012haq_client);
- fr8012haq_client = NULL;
- }
- if (response_data)
- free(response_data);
- response_data = NULL;
- response_len = 0;
- return ret;
-}
-static void fr8012haq_task_callback(VOID * argv)
-{
- //sensor_task_send_message(FR8012HAQ_ID,SENSOR_MSG_PROCESS_DATA);
- //mfp_config(uart4_pin_mfp_cfgs);
- int response_code,trynum=0;
- struct http_client * client = NULL;
- struct http_client_list * header = NULL;
-
- //char data[500]= {0};
- int len = 0;
- //uart4_debug();
- //char post_data[] ="{\"app_key\": \"5d3ef21f0cbf966505c3d5137740be77\",\"name\": \"RH303\",\"firm\": \"魔方\",\"mac\": \"DA:19:72:F3:0A:89\",\"model\": \"T11\",\"sensor\": {\"model\": \"VP60\",\"fs\": 81},\"sinklib_version\": \"v0.3.0.072522\",\"request_code\":\"6+m78fFJkFKu1mzhhL4jKRJTEhJMwvSJFlJhWIgRC8wfyB0HFw8JMURNQ6c3MP/U\"}" ;
- //char post_data[] ="{\"app_key\": \"5d3ef21f0cbf966505c3d5137740be77\",\"phone\": \"18100000001\",\"passwd\": \
- \"abc123\",\"name\": \"张三\",\"gender\": 1,\"birthday\": \"2002-06-01\",\"height\": 166,\"weight\": 56,\
- \"description\": \"1111\"}";
- //char url[] = "http://test.aicaring.com/api/v0/sinklib/activation";
- //char url[] = "http://test.aicaring.com/api/v0/entrance/user/login";
- char *read_buff = (void*)malloc(2000);
- if(!read_buff)
- return ;
- while(1)
- {
-
- UOS_SleepMs(5000);
-
- //fr8012haq_http_post_json(url,NULL,post_data,read_buff,2000,10000);
-
- // FR8012HAQ_LOG("fr8012haq_task_callback1!!!!\n");
- // client = http_client_init();
- // http_client_setopt(client, HTTPCLIENT_OPT_URL, "http://test.aicaring.com/api/v0/sinklib/activation"); /*set URL:support http/https and ip4/ip6*/
- // http_client_setopt(client, HTTPCLIENT_OPT_HTTP1_0, 0); /*"0" is HTTP 1.1, "1" is HTTP 1.0*/
-
- // http_client_setopt(client, HTTPCLIENT_OPT_RESPONSECB, response_cb); /*response callback*/
- // //http_client_setopt(client, HTTPCLIENT_OPT_RESPONSECB_DATA, private_data); /*set user private data,*/
- // http_client_setopt(client, HTTPCLIENT_OPT_METHOD, HTTPCLIENT_REQUEST_POST); /*set method,support GET/POST/PUT*/
- // http_client_setopt(client, HTTPCLIENT_OPT_POSTDATA, post_data); /*post data is http context*/
- // http_client_setopt(client, HTTPCLIENT_OPT_POSTLENGTH, strlen(post_data)); /*http context length*/
- // //http_client_setopt(client, HTTPCLIENT_OPT_AUTH_TYPE, HTTP_AUTH_TYPE_BASE); /*auth type support base and digest*/
- // // http_client_setopt(client, HTTPCLIENT_OPT_AUTH_USERNAME, "admin"); /*username*/
- // // http_client_setopt(client, HTTPCLIENT_OPT_AUTH_PASSWORD, "admin"); /*password*/
-
- // // Add private HTTP header
- // header = http_client_list_append(header, "Content-Type: application/json\r\n");
- // header = http_client_list_append(header, "Accept: */*\r\n");
- // FR8012HAQ_LOG("fr8012haq_task_callback2!!!!\n");
- // /*set http private header,our http stack already support Referer/Host/Authorization/User-Agent/Connection/cookie/Content-Length,
- // this header is other http header,ex: Content-Type..., we call it private header,*/
- // http_client_setopt(client, HTTPCLIENT_OPT_HTTPHEADER, header);
- // FR8012HAQ_LOG("fr8012haq_task_callback3!!!!\n");
- // http_client_getinfo(client, HTTPCLIENT_GETINFO_TCP_STATE, &response_code);
- // FR8012HAQ_LOG("fr8012haq_task_callback4!!!!\n");
- // FR8012HAQ_LOG("[http_client_test]Get tcp state %d\n", response_code);
-
- // if(response_code != HTTP_TCP_ESTABLISHED){
- // FR8012HAQ_LOG("[http_client_test]http tcp not connecting\n");
- // http_client_shutdown(client); /*release http resources*/
- // //client = http_client_init();
- // continue;
- // }
-
- // response_code=http_client_perform(client); /*execute http send and recv*/
- // if(response_code != HTTP_CLIENT_OK){
- // FR8012HAQ_LOG("[http_client_test]http perform have some wrong[%d]\n",response_code);
- // http_client_shutdown(client); /*release http resources*/
- // //client = http_client_init();
- // continue;
- // }
- // FR8012HAQ_LOG("fr8012haq_task_callback5!!!!\n");
- // http_client_getinfo(client, HTTPCLIENT_GETINFO_RESPONSE_CODE, &response_code);
- // if (response_code != 200 && response_code != 204) {
- // FR8012HAQ_LOG("[http_client_test]response is not 'HTTP OK'(%d)\n", response_code);
- // }
- // FR8012HAQ_LOG("fr8012haq_task_callback6!!!!\n");
- // FR8012HAQ_LOG("[http_client_test]Get total data %d\n", response_len);
- // FR8012HAQ_LOG("[http_client_test]response_data %s\n",response_data);
- // UOS_SleepMs(500);
- // if (response_data) free(response_data);
- // response_data = NULL;
- // response_len = 0;
-
- // //FR8012HAQ_LOG("[http_client_test]free(response_data)\n");
- // // Free private HTTP header
- // if (header) {
- // http_client_list_destroy(header);
- // header = NULL;
- // }
- // //FR8012HAQ_LOG("[http_client_test]http_client_list_destroy(header)\n");
- // http_client_shutdown(client); /*release http resources*/
- // FR8012HAQ_LOG("fr8012haq_task_callback7!!!!\n");
- // //FR8012HAQ_LOG("[http_client_test]http_client_shutdown(client)\n");
- UOS_SleepMs(2000);
- //fr8012haq_write_data("UART4:1111!!!!!!!\n",sizeof("UART4:1111!!!!!!!\n"));
- // len =uart4_recv_data(data,sizeof(data),64);
- // if(len)
- // FR8012HAQ_LOG("UART4:len:%d str:%s\n",len,data);
- //fr8012haq_write_data("UART4:1111!!!!!!!\n",sizeof("UART4:1111!!!!!!!\n"));
- }
-}
static void fr8012haq_hisr_callback(void)
{
sensor_task_send_message(FR8012HAQ_ID,SENSOR_MSG_PROCESS_DATA);
//FR8012HAQ_LOG("fr8012haq_timerout_cb\n");
OS_Activate_HISR(&fr8012haq_hisr_ref);
}
-void fr8012haq_timer_cfg(bool en)
+void fr8012haq_timer_cfg(bool en)
{
//FR8012HAQ_LOG("fr8012haq_timer_cfg :%d!!!!!!\n\n",en);
if(fr8012haq_timer == NULL )
uos_timer_create(&fr8012haq_timer);
//fr8012haq_timer = Helios_Timer_init( (void* )fr8012haq_timerout_cb, NULL);
- if(FR8012HAQ_result_get_wear_status() == 0)//如果是未佩戴,统一3秒
+ if(FR8012HAQ_run_mode == WEAR_MODE)//如果是未佩戴,统一3秒
{
- uos_timer_start(fr8012haq_timer, MS_TO_TICKS(3000), MS_TO_TICKS(3000), fr8012haq_timerout_cb, NULL);
+ uos_timer_start(fr8012haq_timer, MS_TO_TICKS(5000), MS_TO_TICKS(5000), fr8012haq_timerout_cb, NULL);
}
else if(FR8012HAQ_run_mode == BP_MODE)//血压500MS
{
case YYL_MODE:
/* code */
fr8012haq_write_data("{\"cmd\":\"2\",\"get_data\":\"yyl\"}\n",sizeof("{\"cmd\":\"2\",\"get_data\":\"yyl\"}\n"));
- UOS_SleepMs(30);
+ UOS_SleepMs(50);
break;
case TEMP_MODE:
/* code */
default:
break;
}
- UOS_SleepMs(20);
-
+ //UOS_SleepMs(20);
+ gps_ui_delay_us(1400*10);
//FR8012HAQ_LOG("fr8012haq_process_data2:%d!!!!\n",FR8012HAQ_run_mode);
// float tmp = 0x3FE2E147;
// FR8012HAQ_LOG("float:%f\n",tmp);
- fr8012haq_parse_returned_data(150);
+ fr8012haq_parse_returned_data(50);
//fr8012haq_write_data("{\"cmd\":\"0\"}",sizeof("{\"cmd\":\"0\"}"));//保活用
// gpio_enable_edge_detect(GPIO32, EDGE_FLAG_RISE);
// fr8012haq_sleep_resume();
hal_fr8012haq_int_init();
FR8012HAQ_LOG("Fr8012haq_Init4!!!!\n\n");
FR8012HAQ_restart();
- uart4_debug();
+ //uart4_debug();
UOS_SleepMs(5);
HA_lib_init();
// while(1)