Демонстрационная прошивка отладочного комплекта МТС NB-IoT
gnss_support.c
См. документацию.
1 #include "gnss_support.h"
2 
9 static volatile uint8_t gnss_data_buffer[GNSS_DATA_BUFFER_SIZE];
10 static volatile uint16_t buf_index=0;
11 static volatile uint8_t GNSS_location_stored=0;
12 static volatile uint8_t GNSS_location_found=0;
13 #define LOC_ID_LENGTH 6
14 const uint8_t location_identifier[] = {"$GNGLL"};
15 static volatile uint8_t id_index=0;
16 
17 void USART2_IRQHandler(void)
18 {
19  volatile uint8_t tmp;
20  volatile uint32_t SR_content;
21 
22  //Clearing every possible interrupt flag. Some are cleared by writing them to zero, and some by specific read sequence.
23  SR_content = USART2->SR;
24  tmp = USART2->DR;
25  USART2->SR = 0;
26 
27  if (!GNSS_location_stored)
28  {
29  if (SR_content & USART_SR_ORE)
30  {
31  //Reset search because overrun has occurred
32  buf_index=0;
33  id_index=0;
34  }
35 
36  gnss_data_buffer[buf_index] = tmp;
37  if (buf_index<(GNSS_DATA_BUFFER_SIZE-1)) //Reserving space to terminate a string with a null character
38  {
39  buf_index++;
40  }
41 
42  if ((tmp==location_identifier[id_index]) && (GNSS_location_found==0))
43  {
44  id_index++;
45 
46  if (id_index>=LOC_ID_LENGTH)
47  {
48  id_index=0;
49  GNSS_location_found=1;
50  }
51  }
52  else
53  {
54  id_index=0;
55 
56  if (GNSS_location_found==0)
57  {
58  buf_index=0; //To not save data that we do not want
59  }
60  }
61 
62  if (GNSS_location_found)
63  {
64  if ((gnss_data_buffer[buf_index-1]=='\n') && (gnss_data_buffer[buf_index-2]=='\r'))
65  {
66  //End of GNSS string, data ready
67  //Terminate the string and do not include CR-LF
68  gnss_data_buffer[buf_index-2]=0;
69  //Reset the FSM
70  GNSS_location_found=0;
71  buf_index=0;
72  id_index=0;
73  //Signal that the location data are ready
74  GNSS_location_stored=1;
75  }
76  }
77  }
78 }
79 
80 uint8_t GNSS_ReadLocationData(uint8_t *str_out,uint16_t max_length)
81 {
82  uint16_t k;
83 
84  if (GNSS_location_stored)
85  {
86  k=0;
87  if (str_out!=NULL)
88  {
89  while ((gnss_data_buffer[k]!=0) && (k<(max_length-1)))
90  {
91  str_out[k] = gnss_data_buffer[k];
92  k++;
93  }
94 
95  str_out[k]=0;
96  }
97 
98  GNSS_location_stored=0;
99 
100  return 1;
101  }
102  else
103  {
104  return 0;
105  }
106 }
GNSS_ReadLocationData
uint8_t GNSS_ReadLocationData(uint8_t *str_out, uint16_t max_length)
Прочесть данные о местоположении, полученные от GNSS-приемника
Definition: gnss_support.c:80
gnss_support.h