main.c 3.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127
  1. #define USR_PLATFORM_QL_ASR1606 0
  2. #define PLATFORM_TYPE USR_PLATFORM_QL_ASR1606
  3. #include "w_poc.h"
  4. #if(USR_PLATFORM_QL_ASR1606==USR_PLATFORM_QL_ASR1606)
  5. #include "ql_application.h"
  6. #include "ql_uart.h"
  7. #include "ql_rtos.h"
  8. char quec_uart=0;
  9. void quec_usbcdc_callback(QL_UART_PORT_NUMBER_E port, void *para)
  10. {
  11. }
  12. void hlog_init(void){
  13. if(0!=ql_uart_open(QL_USB_CDC_PORT, QL_UART_BAUD_115200, QL_FC_NONE)) return;
  14. ql_uart_register_cb(QL_USB_CDC_PORT, quec_usbcdc_callback); //use callback to read uart data
  15. quec_uart=1;
  16. }
  17. void hlog_show(char *msg){
  18. if(quec_uart==0) return;
  19. ql_uart_write(QL_USB_CDC_PORT, msg, strlen(msg));
  20. }
  21. char msgCmp(char *msg, char *target){
  22. char *p1=target, *p2=msg;
  23. while(*p1 != 0){
  24. if(*p1 != *p2) return 0;
  25. p1++;p2++;
  26. }
  27. return 1;
  28. }
  29. #define wlog_app(...) OEM_sys_log_print("WAPP","info", ##__VA_ARGS__)
  30. #define MSG_METHOD 0 //0 AT命令方式 1 API调用方式
  31. unsigned char loginStatus=0;
  32. void wpoc_msg_rx_at(char *msg){
  33. const char *marker="+WPTT:";
  34. if(!msgCmp(msg, marker)) return;
  35. wlog_app("%s", msg);
  36. msg+=strlen(marker);
  37. if(msgCmp(msg, "LOGIN=")){
  38. if(msg[6]=='0') loginStatus=0;
  39. else if(msg[6]=='1') loginStatus=1;
  40. }
  41. }
  42. void wpoc_msg_rx_event(WPOC_EVENT_RX event, unsigned char *data, int datalen){
  43. WPOC_LOGINACK_DEF *uinfo;
  44. switch(event){
  45. case WPOC_RX_EVENT_LOGIN:
  46. uinfo=(WPOC_LOGINACK_DEF *)data;
  47. wlog_app("login done");
  48. wlog_app("uid:%08x,name:%s", uinfo->user_id, uinfo->user_name);
  49. wlog_app("group:%08x,unum:%d,name:%s", uinfo->be_group_id, uinfo->user_num_in_group, uinfo->be_group_name);
  50. loginStatus=1;
  51. break;
  52. case WPOC_RX_EVENT_LINEOFF:
  53. wlog_app("line off");
  54. loginStatus=0;
  55. break;
  56. case WPOC_RX_EVENT_TIMES:
  57. wlog_app("time ack:%s", (char *)data);
  58. break;
  59. default:wlog_app("unhandle event:%d", event);break;
  60. }
  61. }
  62. WPOC_MSG_RX_DEF msg_rx_fun={
  63. #if MSG_METHOD==0
  64. .wpoc_msg_rx_at_fun=wpoc_msg_rx_at,
  65. .wpoc_msg_rx_event_fun=NULL
  66. #else
  67. .wpoc_msg_rx_at_fun=NULL,
  68. .wpoc_msg_rx_event_fun=wpoc_msg_rx_event
  69. #endif
  70. };
  71. static int test_task(void *param){
  72. unsigned int psn=241200001;
  73. int ret;
  74. int tick=0;
  75. WPOC_REQ_GROUP_DEF groupQuery={
  76. .startIndex=0,
  77. .totalNum=-1
  78. };
  79. ql_rtos_task_sleep_ms(10000);
  80. ql_set_auto_connect(1, TRUE);
  81. ql_start_data_call(1, 0, NULL, NULL, NULL, 0);
  82. hlog_init();
  83. wpoc_param_set(WPOC_MSG_RX_FUN, &msg_rx_fun);
  84. wpoc_param_set(WPOC_PARAM_ACCOUNT_PSN, &psn);
  85. wpoc_param_set(WPOC_PARAM_ACCOUNT_PASS, "123456");
  86. wpoc_param_set(WPOC_PARAM_DNS, "106.12.172.105");
  87. wpoc_param_set(WPOC_PARAM_PLATFORM, "EC600M");
  88. wpoc_param_set(WPOC_PARAM_GROUPNUMS, 100);
  89. wpoc_param_set(WPOC_PARAM_USERNUMS, 100);
  90. ret=wpoc_init(hlog_show);
  91. for(;;){
  92. ql_rtos_task_sleep_ms(1000);
  93. if(loginStatus==0) continue;
  94. //查询时间
  95. if(++tick<30) continue;
  96. tick=0;
  97. if(tick==5){
  98. #if MSG_METHOD==0
  99. wpoc_msg_at_tx("AT+WPTT:GROUPS=0,-1\r\n");
  100. #else
  101. wpoc_msg_event_tx(WPOC_TX_EVENT_REQGOUPS, &groupQuery, sizeof(WPOC_REQ_GROUP_DEF));
  102. #endif
  103. }else if(tick==30){
  104. #if MSG_METHOD==0
  105. wpoc_msg_at_tx("AT+WPTT:REQTIME\r\n");
  106. #else
  107. wpoc_msg_event_tx(WPOC_TX_EVENT_REQTIME, NULL, NULL);
  108. #endif
  109. }
  110. }
  111. return 0;
  112. }
  113. static int platform_entry(void *param){
  114. ql_task_t thisTask;
  115. return ql_rtos_task_create(&thisTask, 16*1024, 100,"test_task", test_task, NULL, 0);
  116. }
  117. application_init(platform_entry, "platform_entry", 64,1);
  118. #endif