alipay_iot_sdk_demo.c 30 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988
  1. #include <stdio.h>
  2. #include <string.h>
  3. #include <stdlib.h>
  4. #include "ql_api_osi.h"
  5. #include "ql_api_common.h"
  6. #include "ql_fs.h"
  7. #include "ql_api_datacall.h"
  8. #include "ql_log.h"
  9. #include "ql_api_osi.h"
  10. #include "alipay_iot_sdk_include/ant_kal.h"
  11. #include "alipay_iot_sdk_include/alipay_iot_sdk.h"
  12. #include "alipay_iot_sdk_include/alipay_iot_coll_biz.h"
  13. #include "alipay_iot_sdk_include/alipay_iot_kal.h"
  14. #include "alipay_iot_sdk_include/alipay_iot_sdk.h"
  15. #include "alipay_iot_sdk_include/alipay_iot_coll_biz.h"
  16. #include "alipay_iot_sdk_include/alipay_iot_signer.h"
  17. #include "alipay_iot_sdk_include/alipay_iot_cmd.h"
  18. #include "alipay_iot_sdk_include/alipay_iot_ota.h"
  19. #include "alipay_iot_sdk_include/alipay_iot_news.h"
  20. #include "alipay_iot_sdk_include/alipay_iot_network.h"
  21. #include "alipay_iot_sdk_include/alipay_iot_distribution.h"
  22. //本 alipay SDK ,只需要打开此三个宏即可
  23. #define __ALIPAY_IOT_IOTDID__
  24. #define __ALIPAY_IOT_BIZSIGN__
  25. #define __ALIPAY_IOT_MDAP__
  26. #define QL_ALIPAY_IOT_LOG_LEVEL QL_LOG_LEVEL_INFO
  27. #define QL_ALI_IOT_APP_LOG(msg, ...) QL_LOG(QL_ALIPAY_IOT_LOG_LEVEL, "QL_ALI_IOT_APP_LOG", msg, ##__VA_ARGS__)
  28. #define QL_ALI_IOT_TIMER_NUM_MAX 20
  29. #define QL_ALI_IOT_LOCAL_MSG_SDK_START 999
  30. #define QL_ALI_IOT_LOCAL_MSG_TIMER_EXPIRED 998
  31. #define QL_ALI_IOT_ANT_PDP_CID 1
  32. #define QL_ALI_IOT_SDK_OPEN_EVENT_ID 30001
  33. /*hardware supplier NO. quectel硬件供应商编号*/
  34. #define QL_ALI_IOT_APP_MAN_SUPPLIER_ID "201901220900654009"
  35. #define QL_ALI_IOT_SDK_QUEUE_L1_SIZE 10
  36. #define QL_ALI_IOT_SDK_QUEUE_L2_SIZE 10 /*FLASH空间大小 (6+6)*4 =48K*/
  37. #define QL_ALI_IOT_SDK__EVN_VALUE_MAX 5
  38. #define QL_ALI_IOT_APP_TASK_PRIORITY 20
  39. #define QL_ALI_IOT_SDK_TASK_PRIORITY 25
  40. typedef enum{
  41. QL_ALI_IOT_SDK_IDLE = 0,
  42. QL_ALI_IOT_SDK_RUN,
  43. QL_ALI_IOT_SDK_SHUT,
  44. }ql_ali_iot_sdk_state_e;
  45. typedef enum{
  46. QL_ALI_IOT_SIGN_MODE_RECV_QRCODE = 1,/*用户被扫*/
  47. QL_ALI_IOT_SIGN_MODE_FACE,/*用户人脸*/
  48. QL_ALI_IOT_SIGN_MODE_QRCODE,/*用户主扫*/
  49. QL_ALI_IOT_SIGN_MODE_DELEGATE,/*第三方代扣*/
  50. }ql_ali_iot_sign_mode_e;
  51. typedef enum{
  52. QL_ALI_IOT_RESULT_REBOOT = -2,
  53. QL_ALI_IOT_RESULT_FAIL= -1,
  54. QL_ALI_IOT_RESULT_OK= 0,
  55. QL_ALI_IOT_RESULT_PARAM_ERR,//1
  56. QL_ALI_IOT_RESULT_UNINIT,
  57. QL_ALI_IOT_RESULT_CACHE_ERR,
  58. QL_ALI_IOT_RESULT_MEM_ERR,
  59. QL_ALI_IOT_RESULT_NETBUSY_ERR,//5
  60. QL_ALI_IOT_RESULT_CACHE_FULL,
  61. QL_ALI_IOT_RESULT_DATABK_ERR,
  62. QL_ALI_IOT_RESULT_ERR,
  63. QL_ALI_IOT_RESULT_RSV1_ERR,
  64. QL_ALI_IOT_RESULT_NETWORK_ERR = 10,
  65. QL_ALI_IOT_RESULT_CODE_MAX,
  66. }ql_ali_iot_app_result_code_e;
  67. typedef struct
  68. {
  69. int mode;
  70. char need_sign_data[128];
  71. char amount[32];
  72. }ql_ali_iot_app_paysign_str;
  73. typedef struct
  74. {
  75. int broadcast_count;
  76. int scan_count;
  77. char *data;
  78. }ql_ali_iot_app_payact_str;
  79. typedef struct
  80. {
  81. int human_verify;
  82. char *data;
  83. }ql_ali_iot_app_payinfo_str;
  84. typedef struct
  85. {
  86. char business_no[BUSINESS_NO_MAX_LEN+1];
  87. char qr_code[QRCODE_MAX_LEN+1];
  88. int amount;
  89. int time_consuming;
  90. int trade_result;
  91. unsigned int timestamp;
  92. int result;
  93. int max_record_num;
  94. }ql_ali_iot_app_payrep_str;
  95. /*save parameter, 需要掉电保存的参数*/
  96. typedef struct
  97. {
  98. int rsv1;
  99. alipay_sdk_profile_info_struct profile_info_st;
  100. char terminal_id[SDK_DEVICE_SN_MAX_LEN+1]; //SN 设备的序列号sn
  101. }ql_ali_iot_app_save_info_str;
  102. typedef struct
  103. {
  104. //char business_no[64+1];
  105. char account_iccid[ICCID_MAX_LEN+1]; //流量账户信息/SIM卡的ICCID
  106. char imei[SDK_DEVICE_IMEI_MAX_LEN+1]; //IMEI
  107. char sn[SDK_DEVICE_SN_MAX_LEN+1]; //SN
  108. char clear_sdk_cache;//clear cache flag
  109. int running;/*sdk run flag*/
  110. ql_ali_iot_app_save_info_str app_save_info;
  111. }ql_ali_iot_app_ctx_str;
  112. static int g_ql_ali_iot_sdk_task_id = 0;
  113. static int g_ql_ali_iot_app_server_task_id = 0;
  114. static ant_timer g_ql_ali_iot_app_time_arry[QL_ALI_IOT_TIMER_NUM_MAX] = {0};
  115. static ql_ali_iot_app_ctx_str ql_ali_iot_app_ctx = {0};
  116. static ql_task_t ql_ali_iot_app_task_id = NULL;
  117. static int ql_ali_iot_task_send_message(int target_id, int src_id, int msg_id, void *data)
  118. {
  119. ant_msg msg = {0};
  120. msg.message = ANT_EVENT_IOT_SDK_EVENT;
  121. msg.param1 = (ant_ptr)msg_id;
  122. msg.param2 = (ant_ptr)data;
  123. msg.src_task_id = target_id;
  124. QL_ALI_IOT_APP_LOG("target_id: %d,src_id: %d,msg_id: %d,data: %p,msg: %p",target_id,src_id,msg_id,data,&msg);
  125. if (1 != ant_event_send_msg(target_id, &msg))
  126. {
  127. QL_ALI_IOT_APP_LOG("app task send message fail!");
  128. return -1;
  129. }
  130. return 1;
  131. }
  132. static int ql_ali_iot_task_recevie_message(int *src_id, int *msg_id, void **data)
  133. {
  134. ant_msg msg = {0};
  135. if (1 != ant_event_recv_msg(&msg))
  136. {
  137. QL_ALI_IOT_APP_LOG("Demo task recv message fail!");
  138. return -1;
  139. }
  140. QL_ALI_IOT_APP_LOG("src_id: %d,message: %d,msg_id: %d,data: %p,msg: %p", msg.src_task_id,msg.message,(int)msg.param1,(void *)msg.param2);
  141. if(msg.message == ANT_EVENT_IOT_SDK_EVENT)
  142. {
  143. *src_id = msg.src_task_id;
  144. *msg_id = (int)msg.param1;
  145. *data = (void *)msg.param2;
  146. QL_ALI_IOT_APP_LOG("app task send message success!");
  147. return 1;
  148. }
  149. else
  150. {
  151. QL_ALI_IOT_APP_LOG("fail: message %d : %d",msg.message,ANT_EVENT_IOT_SDK_EVENT);
  152. return -1;
  153. }
  154. }
  155. void ql_ali_iot_sdk_manage_init(int iot_sdk_tid)
  156. {
  157. static int my_count = 0;
  158. QL_ALI_IOT_APP_LOG("tid %d, count %d",iot_sdk_tid,my_count++);
  159. ql_ali_iot_task_send_message(iot_sdk_tid,(int)-1,MSG_ID_ALIPAY_SDK_INIT_REQ,NULL);
  160. }
  161. void ql_ali_iot_sdk_manage_nw_init(int iot_sdk_tid)
  162. {
  163. QL_ALI_IOT_APP_LOG("iot_sdk_tid: %d",iot_sdk_tid);
  164. ql_ali_iot_task_send_message(iot_sdk_tid,(int)-1,MSG_ID_ALIPAY_SDK_NW_INIT_REQ,NULL);
  165. }
  166. static int ql_ali_iot_sdk_open_notify(int result)
  167. {
  168. ql_event_t event = {0};
  169. event.id = QL_ALI_IOT_SDK_OPEN_EVENT_ID;
  170. event.param1 = (uint32)result;
  171. ql_rtos_event_send(ql_ali_iot_app_task_id, &event);
  172. QL_ALI_IOT_APP_LOG("ql ali iot sdk open %d",result);
  173. return 0;
  174. }
  175. void ql_ali_iot_sdk_manage_sdk_close(int iot_sdk_tid)
  176. {
  177. QL_ALI_IOT_APP_LOG("iot_sdk_tid: %d",iot_sdk_tid);
  178. ql_ali_iot_task_send_message(iot_sdk_tid,(int)-1,MSG_ID_ALIPAY_SDK_CLOSE_IND,NULL);
  179. }
  180. void ql_ali_iot_stop_timer(int16_t id)
  181. {
  182. if(g_ql_ali_iot_app_time_arry[id] != NULL)
  183. {
  184. ant_timer_stop(g_ql_ali_iot_app_time_arry[id]);
  185. }
  186. }
  187. void ql_ali_iot_start_timer(int16_t id, int32_t time, callback_on_timer callback_function)
  188. {
  189. char timer_name[20] = {0};
  190. int temp = id;
  191. QL_ALI_IOT_APP_LOG("%d",id);
  192. if(g_ql_ali_iot_app_time_arry[id] != NULL)
  193. {
  194. ant_timer_destroy(g_ql_ali_iot_app_time_arry[id]);
  195. g_ql_ali_iot_app_time_arry[id] = NULL;
  196. }
  197. QL_ALI_IOT_APP_LOG("%d",g_ql_ali_iot_app_time_arry[id]);
  198. if(g_ql_ali_iot_app_time_arry[id] == NULL)
  199. {
  200. alipay_iot_snprintf(timer_name, sizeof(timer_name), "%d", id);
  201. g_ql_ali_iot_app_time_arry[id] = ant_timer_create(timer_name);
  202. }
  203. QL_ALI_IOT_APP_LOG("%d %p ",g_ql_ali_iot_app_time_arry[id],id);
  204. if(g_ql_ali_iot_app_time_arry[id] != NULL)
  205. {
  206. ant_timer_start(g_ql_ali_iot_app_time_arry[id], callback_function,(void*)temp, time, 0);
  207. }
  208. }
  209. void ql_ali_iot_sdk_close_cnf(void* msg)
  210. {
  211. /*目前SDK 是不会执行的*/
  212. if(msg != NULL)
  213. {
  214. alipay_sdk_close_cnf_struct *rsp = (alipay_sdk_close_cnf_struct*)msg;
  215. if(rsp != NULL)
  216. {
  217. QL_ALI_IOT_APP_LOG("got result %d",rsp->result);
  218. alipay_sdk_close_cnf_struct_destory(rsp);
  219. ql_ali_iot_app_ctx.running = QL_ALI_IOT_SDK_SHUT;
  220. g_ql_ali_iot_sdk_task_id = 0;
  221. }
  222. }
  223. }
  224. void ql_ali_iot_reset_sdk_sta(void)
  225. {
  226. ql_ali_iot_app_ctx.running = QL_ALI_IOT_SDK_IDLE;
  227. }
  228. void ql_ali_iot_waiting_sdk_udpate_time_expirey(int result)
  229. {
  230. QL_ALI_IOT_APP_LOG("result :%d",result);
  231. /*report err URC*/
  232. ql_ali_iot_sdk_open_notify(result);
  233. /*clear alipay state*/
  234. ql_ali_iot_reset_sdk_sta();
  235. }
  236. static void ql_ali_iot_iot_timer_expired_in_task(void *id)
  237. {
  238. int temp = (int)id;
  239. QL_ALI_IOT_APP_LOG("timer %p, expired id :%d",id,temp);
  240. switch(temp)
  241. {
  242. case 5:
  243. ql_ali_iot_sdk_manage_sdk_close(g_ql_ali_iot_sdk_task_id);
  244. break;
  245. case 9:
  246. ql_ali_iot_waiting_sdk_udpate_time_expirey(-1);
  247. break;
  248. default:
  249. break;
  250. }
  251. }
  252. static void ql_ali_iot_timer_expired(void *id)
  253. {
  254. QL_ALI_IOT_APP_LOG("id:%p",id);
  255. ql_ali_iot_task_send_message(g_ql_ali_iot_app_server_task_id, -1, QL_ALI_IOT_LOCAL_MSG_TIMER_EXPIRED,id);
  256. }
  257. void ql_ali_iot_sdk_event_notify(void *msg)
  258. {
  259. alipay_sdk_event_notify_struct *notify=(alipay_sdk_event_notify_struct*)msg;
  260. if(notify ==NULL)
  261. {
  262. QL_ALI_IOT_APP_LOG("param null");
  263. return;
  264. }
  265. QL_ALI_IOT_APP_LOG("event_id=%d",notify->event_id);
  266. alipay_sdk_event_notify_struct_destory(notify);
  267. }
  268. void ql_ali_iot_sdk_nw_init_rsp(void* msg)
  269. {
  270. if(msg != NULL)
  271. {
  272. alipay_sdk_nw_init_rsp_struct *rsp = (alipay_sdk_nw_init_rsp_struct*)msg;
  273. if(rsp != NULL)
  274. {
  275. QL_ALI_IOT_APP_LOG("got result %d",rsp->result);
  276. ql_ali_iot_stop_timer(9);
  277. /*report URC*/
  278. if(rsp->result != 0)
  279. {
  280. /*clear alipay state*/
  281. ql_ali_iot_reset_sdk_sta();
  282. }
  283. ql_ali_iot_sdk_open_notify(rsp->result);
  284. alipay_sdk_nw_init_rsp_struct_destory(rsp);
  285. }
  286. }
  287. }
  288. //SDK通知更新了系统时间
  289. void ql_ali_iot_sdk_sys_time_update_ind(void* msg)
  290. {
  291. char tmp_buf[64]={0};
  292. if(msg != NULL)
  293. {
  294. alipay_sdk_sys_time_update_ind_struct *update_ind = (alipay_sdk_sys_time_update_ind_struct*)msg;
  295. if(update_ind != NULL)
  296. {
  297. QL_ALI_IOT_APP_LOG("cache=%d, got result %d",ql_ali_iot_app_ctx.clear_sdk_cache, update_ind->result);
  298. //如果需要清理SDK的所有缓存,只能在这里进行。
  299. //if(TRUE == ql_ali_iot_app_ctx.clear_sdk_cache){
  300. // alipay_iot_clear_sdk_cache();//del cache file
  301. //}
  302. /*update SIM iccid*/
  303. if(0 == ant_gprs_get_iccid(tmp_buf, 64)){
  304. strcpy(ql_ali_iot_app_ctx.account_iccid, tmp_buf);
  305. }
  306. QL_ALI_IOT_APP_LOG("account_iccid= %s",ql_ali_iot_app_ctx.account_iccid);
  307. //获取时间成功,初始化SDK
  308. if(update_ind->result == 0)
  309. {
  310. ql_ali_iot_sdk_manage_init(g_ql_ali_iot_sdk_task_id);
  311. }
  312. alipay_sdk_sys_time_update_ind_struct_destory(update_ind);
  313. }
  314. //此时不等初始化sdk完成,已经可以进行数据存储不发送, 后续可以优化定时器启动和关闭位置逻辑
  315. //ql_ali_iot_stop_timer(9);
  316. }
  317. }
  318. void ql_ali_iot_sdk_init_rsp(void* msg)
  319. {
  320. QL_ALI_IOT_APP_LOG("msg=%p",msg);
  321. if(msg != NULL)
  322. {
  323. alipay_sdk_init_rsp_struct *rsp = (alipay_sdk_init_rsp_struct*)msg;
  324. //IOT_LOG_INFO(LOG_TAG,"%s, rsp=%p", __func__, rsp);
  325. if(rsp != NULL)
  326. {
  327. QL_ALI_IOT_APP_LOG("rsp=%p result = %d",rsp,rsp->result);
  328. if(rsp->result != 0)/*激活成功*/
  329. {
  330. //初始化成功后,才可以初始化应用网络
  331. ql_ali_iot_sdk_manage_nw_init(g_ql_ali_iot_sdk_task_id);
  332. }
  333. else{
  334. ql_ali_iot_stop_timer(9);
  335. ql_ali_iot_sdk_open_notify(rsp->result);
  336. /*clear alipay state*/
  337. ql_ali_iot_reset_sdk_sta();
  338. }
  339. alipay_sdk_init_rsp_struct_destory(rsp);
  340. }
  341. }
  342. }
  343. int ql_ali_iot_sdk_create(int priority)//创建sdk+查状态和动作
  344. {
  345. int32_t ret = 0;
  346. static int exec_mark=0;
  347. ql_ali_iot_app_save_info_str iot_save;
  348. ant_memset(&iot_save, 0, sizeof(ql_ali_iot_app_save_info_str));
  349. ant_strncpy(iot_save.profile_info_st.module_supplier_no,"200",SDK_SUPPLIER_NO_MAX_LEN + 1);
  350. ant_strncpy(iot_save.profile_info_st.device_supplier_no,"200",SDK_DEVICE_SUPPLIER_NO_MAX_LEN + 1);
  351. ant_strncpy(iot_save.profile_info_st.merchant_user_id,"200",SDK_MERCHANT_USER_ID_MAX_LEN + 1);
  352. ant_strncpy(iot_save.profile_info_st.item_id,"2018121906963192",SDK_ITEM_ID_MAX_LEN + 1);
  353. ant_strncpy(iot_save.profile_info_st.product_key,"PAY_BOX",SDK_PRODUCT_KEY_MAX_LEN + 1);
  354. ant_strncpy(iot_save.terminal_id,"D1Q21A834011533",SDK_DEVICE_SN_MAX_LEN + 1);
  355. iot_save.profile_info_st.env = 5;
  356. //memcpy(ql_ali_iot_app_ctx.app_save_info.terminal_id,iot_save.terminal_id,SDK_DEVICE_SN_MAX_LEN);
  357. ant_memcpy(iot_save.profile_info_st.module_supplier_no, QL_ALI_IOT_APP_MAN_SUPPLIER_ID, strlen(QL_ALI_IOT_APP_MAN_SUPPLIER_ID));
  358. ant_memcpy(&ql_ali_iot_app_ctx.app_save_info,&iot_save,sizeof(ql_ali_iot_app_save_info_str));
  359. QL_ALI_IOT_APP_LOG("ret:%d, env=%d, sn=%s, msn=%s",ret,iot_save.profile_info_st.env,
  360. iot_save.terminal_id, iot_save.profile_info_st.module_supplier_no);
  361. if (!(exec_mark & 0x01))
  362. {
  363. ret = alipay_iot_sdk_set_profile(&iot_save.profile_info_st);
  364. QL_ALI_IOT_APP_LOG("ret:%d", ret);
  365. if(0 != ret)
  366. {
  367. return ret;
  368. }
  369. exec_mark |=0x01;
  370. }
  371. if (!(exec_mark & 0x02)){
  372. ret = alipay_iot_coll_cache_open(DATA_QUEUE_TYPE_MDAP,QL_ALI_IOT_SDK_QUEUE_L1_SIZE,QL_ALI_IOT_SDK_QUEUE_L2_SIZE);
  373. if(0 != ret) return ret;
  374. exec_mark |=0x02;
  375. }
  376. QL_ALI_IOT_APP_LOG("mark=%x, ret:%d",exec_mark,ret);
  377. if(0 == ret)
  378. {
  379. QL_ALI_IOT_APP_LOG("alipay_iot_start...");
  380. g_ql_ali_iot_sdk_task_id = alipay_iot_start(priority,ALIPAY_SDK_MODE_NORMAL);
  381. QL_ALI_IOT_APP_LOG("alipay_iot_start end");
  382. ret = (g_ql_ali_iot_sdk_task_id > 0) ? 0:-1;
  383. }
  384. QL_ALI_IOT_APP_LOG("ret:%d, g_ql_ali_iot_sdk_task_id=%d",ret,g_ql_ali_iot_sdk_task_id);
  385. return ret;
  386. }
  387. void ql_ali_iot_sdk_create_and_run(void)
  388. {
  389. int ret = 0;
  390. QL_ALI_IOT_APP_LOG("");
  391. ret = ql_ali_iot_sdk_create(QL_ALI_IOT_SDK_TASK_PRIORITY);//sdk创建
  392. //设置定时器,防止sdk的时间接口无响应
  393. QL_ALI_IOT_APP_LOG("ret=%d",ret);
  394. if(0 == ret)
  395. {
  396. ql_ali_iot_start_timer(9, 15000, ql_ali_iot_timer_expired);
  397. }
  398. else
  399. {
  400. ql_ali_iot_sdk_open_notify(QL_ALI_IOT_RESULT_FAIL);
  401. /*clear alipay state*/
  402. ql_ali_iot_reset_sdk_sta();
  403. }
  404. }
  405. void ql_ali_iot_sdk_thread(void* para)
  406. {
  407. int srcID = 0;
  408. int msgID = 0;
  409. void * data = NULL;
  410. do
  411. {
  412. QL_ALI_IOT_APP_LOG("msg rt<<");
  413. int rt = ql_ali_iot_task_recevie_message(&srcID, &msgID, &data);
  414. QL_ALI_IOT_APP_LOG("msg rt= %d",rt);
  415. if (rt < 0)
  416. {
  417. continue;
  418. }
  419. QL_ALI_IOT_APP_LOG("got msgID= %d",msgID);
  420. switch(msgID)
  421. {
  422. case QL_ALI_IOT_LOCAL_MSG_SDK_START:/*999*/
  423. ql_ali_iot_sdk_create_and_run();
  424. break;
  425. case QL_ALI_IOT_LOCAL_MSG_TIMER_EXPIRED:/*998 Timeout process*/
  426. ql_ali_iot_iot_timer_expired_in_task(data);
  427. break;
  428. case MSG_ID_ALIPAY_SYS_TIME_UPDATE_IND:/*310* Update time*/
  429. ql_ali_iot_sdk_sys_time_update_ind(data);
  430. break;
  431. case MSG_ID_ALIPAY_SDK_INIT_RSP:/*302 Activated success*/
  432. ql_ali_iot_sdk_init_rsp(data);
  433. break;
  434. case MSG_ID_ALIPAY_SDK_NW_INIT_RSP:/*304 Network communication initialization completed*/
  435. ql_ali_iot_sdk_nw_init_rsp(data);
  436. break;
  437. case MSG_ID_ALIPAY_SDK_EVENT_NOTIFY_IND:/*311*/
  438. ql_ali_iot_sdk_event_notify(data);
  439. break;
  440. case MSG_ID_ALIPAY_SDK_CLOSE_CNF:
  441. ql_ali_iot_sdk_close_cnf(data);
  442. break;
  443. break;
  444. }
  445. QL_ALI_IOT_APP_LOG("got msgID %d exit.",msgID);
  446. }while(1);
  447. }
  448. int ql_ali_iot_start_sdk(void)
  449. {
  450. int ret =0;
  451. QL_ALI_IOT_APP_LOG( "");
  452. //系统适配层初始化动作,不同系统不同
  453. ret = ant_task_create(ql_ali_iot_sdk_thread,"ali_app", 32*1024, sizeof(ant_msg), 20, NULL,QL_ALI_IOT_APP_TASK_PRIORITY);
  454. //注意stack不足可能导致崩溃
  455. QL_ALI_IOT_APP_LOG("demo_task_id %d", ret);
  456. if(ret > 0)
  457. {
  458. g_ql_ali_iot_app_server_task_id = ret;
  459. ant_task_sleep_ms(500);
  460. QL_ALI_IOT_APP_LOG("alipay app start send msg ....");
  461. ql_ali_iot_task_send_message(g_ql_ali_iot_app_server_task_id, -1, QL_ALI_IOT_LOCAL_MSG_SDK_START, NULL);
  462. QL_ALI_IOT_APP_LOG("alipay app start send msg end");
  463. ret = 0;
  464. }
  465. else
  466. {
  467. ret = -1;
  468. QL_ALI_IOT_APP_LOG("task fail.");
  469. }
  470. return ret;
  471. }
  472. int ql_ali_iot_get_ver(char *version, char* build_time, int size)
  473. {
  474. int32_t ret = 0;
  475. snprintf(version, size, "\"%s\"", ant_system_version_get());
  476. snprintf(build_time, size, "\"%s\"", ant_build_date_time());
  477. QL_ALI_IOT_APP_LOG("version=%s, build_time=%s\n", version, build_time);
  478. return ret;
  479. }
  480. int ql_ali_iot_start_open()
  481. {
  482. int32_t ret = 0;
  483. if(ant_gprs_get_network_status() != NETWORK_REGISTRED)
  484. {
  485. return QL_ALI_IOT_RESULT_NETWORK_ERR;
  486. }
  487. if(QL_ALI_IOT_SDK_RUN == ql_ali_iot_app_ctx.running)
  488. {
  489. return 0;
  490. }
  491. if(QL_ALI_IOT_SDK_SHUT == ql_ali_iot_app_ctx.running)
  492. {
  493. return QL_ALI_IOT_RESULT_REBOOT;/*Need to power off and restart operation*/
  494. }
  495. ql_ali_iot_app_ctx.running = QL_ALI_IOT_SDK_RUN;
  496. ret = ql_ali_iot_start_sdk();
  497. if(ret != 0)
  498. {
  499. ql_ali_iot_app_ctx.running = QL_ALI_IOT_SDK_IDLE;
  500. ret = -1;
  501. }
  502. return ret;
  503. }
  504. /*AT+ALIPAYSHUT*/
  505. int ql_ali_iot_close_shut(void *arg)
  506. {
  507. int32_t ret = 0;
  508. QL_ALI_IOT_APP_LOG("");
  509. if((QL_ALI_IOT_SDK_RUN == ql_ali_iot_app_ctx.running)||(g_ql_ali_iot_sdk_task_id > 0))
  510. {
  511. ql_ali_iot_app_ctx.running = QL_ALI_IOT_SDK_SHUT;
  512. ql_ali_iot_sdk_manage_sdk_close(g_ql_ali_iot_sdk_task_id);
  513. //g_ql_ali_iot_sdk_task_id = 0;/*alipay SDK maybe destroyed task*/
  514. /*
  515. *目前alipay SDK 该接口是空的, 执行后上层需屏蔽不可再操作AT
  516. *At present, the SHUT interface of Alipay SDK is empty.
  517. *After execution, the upper layer needs to be shielded and cannot be operated AT.
  518. */
  519. }
  520. return ret;
  521. }
  522. ql_ali_iot_app_result_code_e ql_ali_iot_app_get_did(char *did,int size)
  523. {
  524. int32_t ret = QL_ALI_IOT_RESULT_OK;
  525. char *biztid=NULL;
  526. if(did == NULL || size < 64)
  527. {
  528. QL_ALI_IOT_APP_LOG("did param null!");
  529. return QL_ALI_IOT_RESULT_PARAM_ERR;
  530. }
  531. biztid = alipay_iot_get_biztid();//alipay_iot_get_biztid()必须在sdk create出来之后调用
  532. QL_ALI_IOT_APP_LOG("biztid after sdk init. %s",biztid == NULL ? "null" : biztid);
  533. if(biztid != NULL)
  534. {
  535. ant_memset(did,0,size);
  536. ant_memcpy(did,biztid,strlen(biztid));
  537. }
  538. else
  539. {
  540. ret = QL_ALI_IOT_RESULT_FAIL;
  541. }
  542. alipay_iot_free_biztid(biztid);
  543. biztid = NULL;
  544. return ret;
  545. }
  546. int ql_ali_iot_app_set_sign(ql_ali_iot_app_paysign_str *paysign,char *result,int* len_result)
  547. {
  548. int32_t ret = ALIPAY_IOT_SIGN_RV_UNKNOWN;
  549. //注意可能出现内存超出的情况; 假定输入长度是X(X包含金额amount长度、qr_code长度),最终长度应该是512+X
  550. if(NULL == paysign || len_result == NULL || result == NULL)
  551. {
  552. return ALIPAY_IOT_SIGN_RV_PARAM_ERROR;
  553. }
  554. int buf_len = *len_result;
  555. memset(result, 0, *len_result);
  556. QL_ALI_IOT_APP_LOG("mode=%d,amount=%s,need_sign_data=%s",paysign->mode,paysign->amount,paysign->need_sign_data);
  557. switch(paysign->mode)
  558. {
  559. case QL_ALI_IOT_SIGN_MODE_RECV_QRCODE:/*1 用户被扫(反扫)*/
  560. ret = alipay_iot_sign_qrcode(paysign->need_sign_data, paysign->amount, result, len_result);
  561. break;
  562. case QL_ALI_IOT_SIGN_MODE_FACE:/*2 用户人脸*/
  563. ret = alipay_iot_sign_face_token(paysign->need_sign_data, paysign->amount, result, len_result);
  564. break;
  565. case QL_ALI_IOT_SIGN_MODE_QRCODE:/*3 用户主扫*/
  566. ret = alipay_iot_sign_recv_qrcode(paysign->need_sign_data, paysign->amount, result, len_result);
  567. break;
  568. case QL_ALI_IOT_SIGN_MODE_DELEGATE:/*4 第三方代扣*/
  569. ret = alipay_iot_sign_delegated(paysign->need_sign_data, paysign->amount, result, len_result);
  570. break;
  571. default:
  572. ret = ALIPAY_IOT_SIGN_RV_PARAM_ERROR;
  573. break;
  574. }
  575. ant_assert(*len_result < buf_len);/*Data overflow*/
  576. QL_ALI_IOT_APP_LOG("ret %d, buf_len %d; len_result %d",ret,buf_len,*len_result);
  577. QL_ALI_IOT_APP_LOG("result %s",result);
  578. return ret;
  579. }
  580. alipay_iot_biz_result_code_t ql_ali_iot_app_set_info(ql_ali_iot_app_payinfo_str *payinfo)
  581. {
  582. char iccid_buf[ICCID_MAX_LEN+1]={0};
  583. int32_t ret = alipay_iot_biz_result_succ;
  584. if(ant_gprs_get_network_status() != NETWORK_REGISTRED)
  585. {
  586. QL_ALI_IOT_APP_LOG("ali iot app payinfo network not activate!");
  587. return alipay_iot_biz_result_para_err;
  588. }
  589. if(NULL == payinfo)
  590. {
  591. QL_ALI_IOT_APP_LOG("payinfo param null!");
  592. return alipay_iot_biz_result_para_err;
  593. }
  594. alipay_iot_production_info_struct pd_info = {0};
  595. pd_info.human_verify = payinfo->human_verify;
  596. ant_system_get_device_info(ANT_DEVICE_ICCID, iccid_buf, ICCID_MAX_LEN);
  597. snprintf(pd_info.account_flow, ICCID_MAX_LEN+1, "%s",iccid_buf);
  598. ret = snprintf(pd_info.iccid, ICCID_MAX_LEN+1, "%s", iccid_buf);
  599. if(ret < 0)
  600. {
  601. QL_ALI_IOT_APP_LOG("ret:%d", ret);
  602. }
  603. ret = alipay_iot_coll_production_info_send(&pd_info);
  604. QL_ALI_IOT_APP_LOG("ret %d, account_flow=%s, iccid=%s",ret,pd_info.account_flow, pd_info.iccid);
  605. return ret;
  606. }
  607. alipay_iot_biz_result_code_t ql_ali_iot_app_set_rep(ql_ali_iot_app_payrep_str *payrep)
  608. {
  609. alipay_iot_biz_result_code_t ret = alipay_iot_biz_result_para_err;
  610. alipay_iot_transaction_data_struct pd_rep = {0};
  611. if(ant_gprs_get_network_status() != NETWORK_REGISTRED)
  612. {
  613. QL_ALI_IOT_APP_LOG("ali iot app payrep network not activate!");
  614. return alipay_iot_biz_result_para_err;
  615. }
  616. if(NULL == payrep)
  617. {
  618. QL_ALI_IOT_APP_LOG("payrep param null!");
  619. return alipay_iot_biz_result_para_err;
  620. }
  621. pd_rep.amount = payrep->amount;
  622. pd_rep.timestamp = payrep->timestamp;
  623. pd_rep.time_consuming = payrep->time_consuming;
  624. pd_rep.fail_reason = payrep->trade_result;
  625. snprintf(pd_rep.business_no, sizeof(pd_rep.business_no), "%s", payrep->business_no);
  626. snprintf(pd_rep.qr_code, sizeof(pd_rep.qr_code), "%s", payrep->qr_code);
  627. ret = alipay_iot_coll_transaction_data_send_rt(&pd_rep);
  628. QL_ALI_IOT_APP_LOG("ret %d, amount=%d, business_no=%s, qr_code=%s",ret,pd_rep.amount,pd_rep.business_no,pd_rep.qr_code);
  629. return ret;
  630. }
  631. ql_ali_iot_app_result_code_e ql_ali_iot_app_get_utc(UINT32 *seconds)
  632. {
  633. if(NULL == seconds)
  634. {
  635. QL_ALI_IOT_APP_LOG("seconds param null!");
  636. return QL_ALI_IOT_RESULT_PARAM_ERR;
  637. }
  638. *seconds = ant_get_utc_seconds();
  639. QL_ALI_IOT_APP_LOG("utc_seconds=%lu",*seconds);
  640. return QL_ALI_IOT_RESULT_OK;
  641. }
  642. /*
  643. alipay iot sdk 获取 sdk 的版本以及 编译的时间
  644. */
  645. void ql_ali_iot_app_get_sdk_ver_buildtime(char *version, char* build_time, int size)
  646. {
  647. snprintf(version, size, "\"%s\"", ant_system_version_get());
  648. snprintf(build_time, size, "\"%s\"", ant_build_date_time());
  649. QL_ALI_IOT_APP_LOG("ali iot sdk ver=%s,build_time=%s!", version, build_time);
  650. }
  651. alipay_iot_biz_result_code_t ql_ali_iot_app_set_act( ql_ali_iot_app_payact_str *payact)
  652. {
  653. int32_t ret = alipay_iot_biz_result_succ;
  654. alipay_iot_action_data_struct action = {0};
  655. if(ant_gprs_get_network_status() != NETWORK_REGISTRED)
  656. {
  657. QL_ALI_IOT_APP_LOG("ali iot app payact network not activate!");
  658. return alipay_iot_biz_result_para_err;
  659. }
  660. if(NULL == payact )
  661. {
  662. QL_ALI_IOT_APP_LOG("payact param null!");
  663. return alipay_iot_biz_result_para_err;
  664. }
  665. action.brocast_count = payact->broadcast_count;
  666. action.scan_count = payact->scan_count;
  667. ret = alipay_iot_coll_action_data_send(&action);
  668. QL_ALI_IOT_APP_LOG("ret=%d,brocast_count=%d, scan_count=%d",ret,action.brocast_count, action.scan_count);
  669. return ret;
  670. }
  671. int ql_ali_iot_app_net_register(uint8_t nSim,int profile_idx)
  672. {
  673. int ret = 0;
  674. ql_data_call_info_s info ={0};
  675. for (int i = 0; i < 10; i++)
  676. {
  677. ret = ql_network_register_wait(nSim, 120);
  678. if (0 == ret)
  679. {
  680. break;
  681. }
  682. ql_rtos_task_sleep_s(1);
  683. }
  684. if (0 != ret)
  685. {
  686. QL_ALI_IOT_APP_LOG("network register failure!");
  687. return -1;
  688. }
  689. ret = ql_set_data_call_asyn_mode(nSim, profile_idx, 0);
  690. QL_ALI_IOT_APP_LOG("network datacall asyn mode ret = %d",ret);
  691. ql_start_data_call(nSim, profile_idx, QL_PDP_TYPE_IP, "uninet", NULL, NULL, 0);
  692. QL_ALI_IOT_APP_LOG("network datacall result ret = %d",ret);
  693. if (0 != ret)
  694. {
  695. QL_ALI_IOT_APP_LOG("data call failure!");
  696. }
  697. ret = ql_get_data_call_info(nSim, profile_idx, &info);
  698. if (0 != ret)
  699. {
  700. ql_stop_data_call(nSim, profile_idx);
  701. return -1;
  702. }
  703. QL_ALI_IOT_APP_LOG("ql_get_data_call_info ret: 0x%x", ret);
  704. QL_ALI_IOT_APP_LOG("info.profile_idx: %d, info.ip_version: %d", info.profile_idx, info.ip_version);
  705. QL_ALI_IOT_APP_LOG("info->v4.state: %d, info.v6.state: %d", info.v4.state, info.v6.state);
  706. if(info.v4.state)
  707. {
  708. QL_ALI_IOT_APP_LOG("info.v4.addr.ip: %s", ip4addr_ntoa(&(info.v4.addr.ip)));
  709. QL_ALI_IOT_APP_LOG("info.v4.addr.pri_dns: %s", ip4addr_ntoa(&(info.v4.addr.pri_dns)));
  710. QL_ALI_IOT_APP_LOG("info.v4.addr.sec_dns: %s", ip4addr_ntoa(&(info.v4.addr.sec_dns)));
  711. }
  712. if(info.v6.state)
  713. {
  714. QL_ALI_IOT_APP_LOG("info.v6.addr.ip: %s", ip6addr_ntoa(&(info.v6.addr.ip)));
  715. QL_ALI_IOT_APP_LOG("info.v6.addr.pri_dns: %s", ip6addr_ntoa(&(info.v6.addr.pri_dns)));
  716. QL_ALI_IOT_APP_LOG("info.v6.addr.sec_dns: %s", ip6addr_ntoa(&(info.v6.addr.sec_dns)));
  717. }
  718. return ret;
  719. }
  720. static void ql_ali_iot_app_task_id_fxn(void * arg)
  721. {
  722. int ret = 0;
  723. ql_event_t event = {0};
  724. QL_ALI_IOT_APP_LOG("=========>>>> ql ali iot sdk demo begin!");
  725. ql_rtos_task_sleep_s(10);
  726. ql_ali_iot_app_net_register(0,1);
  727. ret = ql_ali_iot_start_open();
  728. QL_ALI_IOT_APP_LOG("=========>>>> ali iot app open: %d!",ret);
  729. if(ret != 0)
  730. {
  731. goto EXIT;
  732. }
  733. QL_ALI_IOT_APP_LOG("=========>>>> wait ali iot sdk open...!");
  734. ql_event_try_wait(&event);
  735. if(event.id == QL_ALI_IOT_SDK_OPEN_EVENT_ID)
  736. {
  737. if(event.param1 != 0)
  738. {
  739. QL_ALI_IOT_APP_LOG("=========>>>> ali iot sdk open fail %d!",event.param1);
  740. goto EXIT;
  741. }
  742. else
  743. {
  744. UINT32 seconds = 0;
  745. int temp_buf_size = 64;
  746. ql_ali_iot_app_result_code_e app_err = QL_ALI_IOT_RESULT_OK;
  747. ALIPAY_IOT_SIGN_RET iot_sign_ret = ALIPAY_IOT_SIGN_RV_OK;
  748. alipay_iot_biz_result_code_t result_code = alipay_iot_biz_result_succ;
  749. QL_ALI_IOT_APP_LOG("=========>>>> ali iot sdk open success...!");
  750. char* temp_buf_1 = ant_malloc(temp_buf_size+1);
  751. char* temp_buf_2 = ant_malloc(temp_buf_size+1);
  752. if(temp_buf_1 == NULL || temp_buf_2 == NULL)
  753. {
  754. QL_ALI_IOT_APP_LOG("=========>>>> ali iot sdk demo malloc fail!");
  755. goto EXIT;
  756. }
  757. ant_memset(temp_buf_1,0,temp_buf_size);
  758. ant_memset(temp_buf_2,0,temp_buf_size);
  759. ql_ali_iot_app_payinfo_str payinfo = {0};
  760. ql_ali_iot_app_paysign_str paysign = {0};
  761. ql_ali_iot_app_payrep_str payrep = {0};
  762. ql_ali_iot_app_payact_str payact = {0};
  763. ql_ali_iot_app_get_sdk_ver_buildtime(temp_buf_1,temp_buf_2,temp_buf_size);
  764. QL_ALI_IOT_APP_LOG("=========>>>> ali iot sdk demo build version: %s;build time: %s",temp_buf_1,temp_buf_2);
  765. ql_rtos_task_sleep_s(3);
  766. ant_memset(temp_buf_1,0,temp_buf_size);
  767. app_err = ql_ali_iot_app_get_did(temp_buf_1,temp_buf_size);
  768. QL_ALI_IOT_APP_LOG("=========>>>> ali iot sdk demo get biztid ret :%d;biztid: %s",app_err,temp_buf_1);
  769. ql_rtos_task_sleep_s(5);
  770. paysign.mode = 4;
  771. ant_memcpy(paysign.need_sign_data, "1234567890", strlen("1234567890"));
  772. ant_memcpy(paysign.amount, "10.25",strlen("10.25"));
  773. ant_memset(temp_buf_1,0,temp_buf_size);
  774. QL_ALI_IOT_APP_LOG("paysign.mode: %d",paysign.mode);
  775. QL_ALI_IOT_APP_LOG("paysign.need_sign_data :%s",paysign.need_sign_data);
  776. QL_ALI_IOT_APP_LOG("paysign.amount :%s",paysign.amount);
  777. int result_length = sizeof(ql_ali_iot_app_paysign_str)+1000;
  778. char* result = ant_malloc(result_length);
  779. iot_sign_ret = ql_ali_iot_app_set_sign(&paysign,result,&result_length);
  780. QL_ALI_IOT_APP_LOG("=========>>>> ali iot sdk demo set sign ret :%d;result length :%d;result: %s",iot_sign_ret,result_length,result);
  781. ql_rtos_task_sleep_s(5);
  782. ant_free(result);
  783. payinfo.human_verify = 1;
  784. QL_ALI_IOT_APP_LOG("payinfo.human_verify :%d",payinfo.human_verify);
  785. result_code = ql_ali_iot_app_set_info(&payinfo);
  786. QL_ALI_IOT_APP_LOG("=========>>>> ali iot sdk demo set payinfo result_code :%d",result_code);
  787. ql_rtos_task_sleep_s(3);
  788. memcpy(payrep.business_no, "698888", strlen("698888"));
  789. memcpy(payrep.qr_code, "95765",strlen("95765"));
  790. payrep.amount = 1678;
  791. payrep.time_consuming = 8;
  792. payrep.trade_result = 5;
  793. payrep.timestamp = 55555;
  794. QL_ALI_IOT_APP_LOG("payrep.business_no :%s",payrep.business_no);
  795. QL_ALI_IOT_APP_LOG("payrep.qr_code :%s",payrep.qr_code);
  796. QL_ALI_IOT_APP_LOG("payrep.amount :%d",payrep.amount);
  797. QL_ALI_IOT_APP_LOG("payrep.time_consuming :%d",payrep.time_consuming);
  798. QL_ALI_IOT_APP_LOG("payrep.trade_result :%d",payrep.trade_result);
  799. QL_ALI_IOT_APP_LOG("payrep.timestamp :%lu",payrep.timestamp);
  800. ant_memset(temp_buf_1,0,temp_buf_size);
  801. result_code = ql_ali_iot_app_set_rep(&payrep);
  802. QL_ALI_IOT_APP_LOG("=========>>>> ali iot sdk demo set rep result_code :%d",result_code);
  803. ql_rtos_task_sleep_s(3);
  804. ql_ali_iot_app_get_utc(&seconds);
  805. QL_ALI_IOT_APP_LOG("=========>>>> ali iot sdk demo get utc seconds :%d",seconds);
  806. ql_rtos_task_sleep_s(3);
  807. payact.broadcast_count = 1;
  808. payact.scan_count = 1;
  809. QL_ALI_IOT_APP_LOG("payact.broadcast_count :%d",payact.broadcast_count);
  810. QL_ALI_IOT_APP_LOG("payact.scan_count :%d",payact.scan_count);
  811. result_code = ql_ali_iot_app_set_act(&payact);
  812. QL_ALI_IOT_APP_LOG("=========>>>> ali iot sdk demo set act result_code :%d",result_code);
  813. ql_rtos_task_sleep_s(10);
  814. ant_free(temp_buf_1);
  815. ant_free(temp_buf_2);
  816. }
  817. }
  818. EXIT:
  819. ql_rtos_task_delete(ql_ali_iot_app_task_id);
  820. ql_rtos_task_sleep_s(10);
  821. QL_ALI_IOT_APP_LOG("=========>>>>ali iot sdk demo END!");
  822. }
  823. void ql_alipay_iot_sdk_app_init(void)
  824. {
  825. int ret = 0;
  826. char tmp_buf[64]={0};
  827. ant_network_init();
  828. ant_iot_kv_init();
  829. ant_gprs_init();
  830. QlOSStatus err = QL_OSI_SUCCESS;
  831. QL_ALI_IOT_APP_LOG("========>>>>ql ali iot sdk demo begin!");
  832. memset(&ql_ali_iot_app_ctx, 0, sizeof(ql_ali_iot_app_ctx_str));
  833. ql_ali_iot_app_ctx.running = QL_ALI_IOT_SDK_IDLE;
  834. ql_ali_iot_app_ctx.clear_sdk_cache = FALSE;
  835. ret = ant_timer_init();
  836. if(0 != ret)
  837. {
  838. QL_ALI_IOT_APP_LOG("ant timer init fail!");
  839. ql_ali_iot_app_ctx.running = QL_ALI_IOT_SDK_SHUT;
  840. return ;
  841. }
  842. memset(tmp_buf, 0, 64);
  843. ret = ant_gprs_get_imsi(tmp_buf, 64);
  844. if(0 == ret)
  845. {
  846. strcpy(ql_ali_iot_app_ctx.imei, tmp_buf);
  847. }
  848. memset(tmp_buf, 0, 64);
  849. ret = ant_gprs_get_sn(tmp_buf, 64);
  850. if(0 == ret)
  851. {
  852. strcpy(ql_ali_iot_app_ctx.sn, tmp_buf);
  853. }
  854. err = ql_rtos_task_create(&ql_ali_iot_app_task_id, 64*1024, QL_ALI_IOT_APP_TASK_PRIORITY-2, "QALIAPP", ql_ali_iot_app_task_id_fxn, NULL, 5);
  855. if(err != QL_OSI_SUCCESS)
  856. {
  857. QL_ALI_IOT_APP_LOG("ali iot app task: %d!",err);
  858. return ;
  859. }
  860. QL_ALI_IOT_APP_LOG("ali iot app task ret: %d!", err);
  861. }