qxwz_application.c 3.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170
  1. #include <rtthread.h>
  2. #include <string.h>
  3. #include <stdarg.h>
  4. #include <stdio.h>
  5. #include <rtdbg.h>
  6. #include <board.h>
  7. #include "qxwz_types.h"
  8. #include "qxwz_sdk.h"
  9. #include "qxwz_api.h"
  10. #include <drv_lcd.h>
  11. #define SAMPLE_UART_NAME "uart3"
  12. static int report_flag = 0;
  13. static char* file = "/qxwz_report.txt";
  14. static rt_mutex_t dynamic_mutex = RT_NULL;
  15. static struct rt_semaphore net_ready;
  16. static const qxwz_usr_config_t s_config;
  17. static char s_gga[256] = {0};
  18. static int report_flag;
  19. static int stopflag;
  20. static void report_gga(char *gga, qxwz_u32_t len);
  21. static void print2lcd(char* input_buf);
  22. static void receive_iprtcm(qxwz_void_t *rtcm, qxwz_u32_t len, qxwz_data_type_e type)
  23. {
  24. static unsigned int rtcmcouter = 0;
  25. write_to_uart(rtcm,len);
  26. rtcmcouter++;
  27. if(rtcmcouter >300){
  28. stopflag = 1;
  29. }
  30. }
  31. static void receive_status(qxwz_s32_t status)
  32. {
  33. rt_kprintf("got rtcm status=%d\n",status);
  34. if(1007 == status)
  35. {
  36. report_flag =1;
  37. start_uart(SAMPLE_UART_NAME,file,report_gga,print2lcd);
  38. }
  39. }
  40. static void report_gga(char *gga, qxwz_u32_t len)
  41. {
  42. rt_mutex_take(dynamic_mutex, RT_WAITING_FOREVER);
  43. memcpy(s_gga,gga,len);
  44. rt_mutex_release(dynamic_mutex);
  45. }
  46. qxwz_data_response_t data_res = {
  47. receive_iprtcm,
  48. NULL
  49. };
  50. qxwz_status_response_t status_res = {
  51. receive_status
  52. };
  53. static const qxwz_usr_config_t s_config = {
  54. "",
  55. "",
  56. "",
  57. ""
  58. };
  59. static void print2lcd(char* input_buf)
  60. {
  61. int i = 0;
  62. char* p_for =NULL;
  63. char* p_tmp =NULL;
  64. char* p_lati =NULL;
  65. char* p_long =NULL;
  66. char* p_loc_accu =NULL;
  67. char buf[10];
  68. char outbuf[100];
  69. lcd_clear(WHITE);
  70. lcd_set_color(WHITE, BLACK);
  71. lcd_show_string(10, 69, 16, input_buf);
  72. p_lati = strstr(strstr(input_buf,",")+1,",")+1;
  73. p_tmp = strstr(p_lati,",");
  74. memset(buf,0,10);
  75. p_for = p_lati;
  76. for(i = 0;i<p_tmp-p_lati;i++){
  77. buf[i] =*p_for;
  78. p_for++;
  79. }
  80. memset(outbuf,0,100);
  81. sprintf(outbuf,"latitude:%s",buf);
  82. lcd_show_string(10, 69+16+8+16+24, 16, outbuf);
  83. p_long = strstr(p_lati,"N,")+2;
  84. p_tmp = strstr(p_long,",");
  85. memset(buf,0,10);
  86. p_for = p_long;
  87. for(i = 0;i<p_tmp-p_long;i++){
  88. buf[i] =*p_for;
  89. p_for++;
  90. }
  91. memset(outbuf,0,100);
  92. sprintf(outbuf,"longitude:%s",buf);
  93. lcd_show_string(10, 69+8+16+16+24+24, 16, outbuf);
  94. p_loc_accu = strstr(p_long,"E,")+2;
  95. p_tmp = strstr(p_loc_accu,",");
  96. memset(buf,0,10);
  97. p_for = p_loc_accu;
  98. for(i = 0;i<p_tmp-p_loc_accu;i++){
  99. buf[i] =*p_for;
  100. p_for++;
  101. }
  102. memset(outbuf,0,100);
  103. sprintf(outbuf,"qx_loca_accuracy:%s",buf);
  104. lcd_show_string(10, 69+8+16+16+24+24+24, 16, outbuf);
  105. }
  106. int qxwz_application(void)
  107. {
  108. int result = RT_EOK;
  109. /* 初始化文件系统 */
  110. /* 初始化网络连接功能 */
  111. // The sdk current time
  112. dynamic_mutex = rt_mutex_create("dmutex", RT_IPC_FLAG_FIFO);
  113. if (dynamic_mutex == RT_NULL)
  114. {
  115. rt_kprintf("create dynamic mutex failed.\n");
  116. return -1;
  117. }
  118. static int s_current_time = 0;
  119. qxwz_s32_t ret = 0;
  120. s_current_time = time(NULL);
  121. qxwz_setting(&s_config,QXWZ_FALSE);
  122. ret = qxwz_start(&data_res,&status_res);
  123. if(0 != ret)
  124. return 0;
  125. int j = 0;
  126. while(1){
  127. if(stopflag){
  128. stop_uart();
  129. qxwz_stop();
  130. }
  131. ret = qxwz_tick(s_current_time);
  132. if(ret == 0)
  133. {
  134. break;
  135. }
  136. rt_thread_mdelay(1000);
  137. s_current_time += 1;
  138. if((report_flag)&&(j>5)){
  139. rt_mutex_take(dynamic_mutex, RT_WAITING_FOREVER);
  140. qxwz_send_data(s_gga, strlen(s_gga), UDATA_GGA);
  141. rt_mutex_release(dynamic_mutex);
  142. j = 0;
  143. }
  144. j++;
  145. }
  146. qxwz_release();
  147. return 0;
  148. }