@@ -26,17 +26,17 | |||||
26 | // TODO Auto-generated destructor stub |
|
26 | // TODO Auto-generated destructor stub | |
27 | } |
|
27 | } | |
28 |
|
28 | |||
29 | virtual void nmeaCode::code_init() { |
|
|||
30 |
|
29 | |||
31 | } |
|
30 | bool nmeaCode::nmea_code_set(const char* cd) { | |
32 | virtual int nmeaCode::code_gen(char *buff, int buff_sz) { |
|
31 | size_t sz = strlen(cd); | |
33 | return 0; |
|
32 | codebuff = new char[sz]; | |
|
33 | strcpy(codebuff, cd); | |||
|
34 | return true; | |||
34 | } |
|
35 | } | |
35 |
|
36 | |||
36 | virtual int nmeaCode::code_parse(const char *buff, int buff_sz) { |
|
37 | bool nmeaCode::nmea_code_get(char* cd) { | |
37 |
return |
|
38 | return true; | |
38 | } |
|
39 | } | |
39 |
|
||||
40 |
|
40 | |||
41 | //////////////////////////////////////////////////////////////////////////////////////// |
|
41 | //////////////////////////////////////////////////////////////////////////////////////// | |
42 |
|
42 |
@@ -15,14 +15,11 | |||||
15 | nmeaCode(char* name=nullptr); |
|
15 | nmeaCode(char* name=nullptr); | |
16 | virtual ~nmeaCode(); |
|
16 | virtual ~nmeaCode(); | |
17 |
|
17 | |||
18 | virtual void code_init(void); |
|
18 | bool nmea_code_set(const char* cd); | |
19 | virtual int code_gen(char *buff, int buff_sz);// TODO para generator |
|
19 | bool nmea_code_get(char* cd); | |
20 | virtual int code_parse(const char *buff, int buff_sz);// TODO para parser |
|
|||
21 |
|
||||
22 |
|
||||
23 |
|
||||
24 |
|
20 | |||
25 | private: |
|
21 | private: | |
|
22 | size_t size; | |||
26 | const char codename[8]; |
|
23 | const char codename[8]; | |
27 | const int type; |
|
24 | const int type; | |
28 | char *codebuff; |
|
25 | char *codebuff; |
@@ -20,7 +20,7 | |||||
20 | } |
|
20 | } | |
21 |
|
21 | |||
22 |
|
22 | |||
23 |
virtual int nmeaGenerator:: |
|
23 | virtual int nmeaGenerator::nmea_gen_info2code(const nmeaInfo *info, nmeaCode* code) | |
24 | { |
|
24 | { | |
25 | return 1; |
|
25 | return 1; | |
26 | } |
|
26 | } | |
@@ -34,7 +34,7 | |||||
34 | { |
|
34 | { | |
35 | int RetVal = 1; int smask = info->smask; |
|
35 | int RetVal = 1; int smask = info->smask; | |
36 |
|
36 | |||
37 |
info-> |
|
37 | info->nmea_info_init_INFO(); | |
38 | info->smask = smask; |
|
38 | info->smask = smask; | |
39 |
|
39 | |||
40 | info->lat = NMEA_DEF_LAT; |
|
40 | info->lat = NMEA_DEF_LAT; | |
@@ -184,7 +184,7 | |||||
184 |
|
184 | |||
185 | while(code) |
|
185 | while(code) | |
186 | { |
|
186 | { | |
187 |
|
|
187 | nmea_gen_info2code(info, code) | |
188 | gen_count += code->code_gen(buff + gen_count, buff_sz - gen_count); |
|
188 | gen_count += code->code_gen(buff + gen_count, buff_sz - gen_count); | |
189 | code += 1; |
|
189 | code += 1; | |
190 | if(buff_sz - gen_count <= 0) |
|
190 | if(buff_sz - gen_count <= 0) |
@@ -40,7 +40,7 | |||||
40 | virtual ~nmeaGenerator(); |
|
40 | virtual ~nmeaGenerator(); | |
41 |
|
41 | |||
42 |
|
42 | |||
43 |
virtual int |
|
43 | virtual int nmea_gen_info2code(const nmeaInfo *info, nmeaCode* code); | |
44 |
|
44 | |||
45 | int nmea_gen_init(nmeaInfo *info); |
|
45 | int nmea_gen_init(nmeaInfo *info); | |
46 | int nmea_gen_loop(nmeaInfo *info); |
|
46 | int nmea_gen_loop(nmeaInfo *info); |
@@ -17,15 +17,15 | |||||
17 | // TODO Auto-generated destructor stub |
|
17 | // TODO Auto-generated destructor stub | |
18 | } |
|
18 | } | |
19 |
|
19 | |||
20 |
void nmeaInfo:: |
|
20 | void nmeaInfo::nmea_info_init_INFO() | |
21 | { |
|
21 | { | |
22 |
|
22 | |||
23 |
|
|
23 | nmea_info_time_now(); | |
24 | sig = NMEA_SIG_BAD; |
|
24 | sig = NMEA_SIG_BAD; | |
25 | fix = NMEA_FIX_BAD; |
|
25 | fix = NMEA_FIX_BAD; | |
26 | } |
|
26 | } | |
27 |
|
27 | |||
28 |
static void nmeaInfo:: |
|
28 | static void nmeaInfo::nmea_info_time_now() { | |
29 | time_t lt; |
|
29 | time_t lt; | |
30 | struct tm *tt; |
|
30 | struct tm *tt; | |
31 |
|
31 | |||
@@ -44,7 +44,7 | |||||
44 | /** |
|
44 | /** | |
45 | * \brief Convert position from INFO to radians position |
|
45 | * \brief Convert position from INFO to radians position | |
46 | */ |
|
46 | */ | |
47 |
void nmeaInfo:: |
|
47 | void nmeaInfo::nmea_info_info2pos(nmeaPOS *pos) { | |
48 | pos->lat = code_ndeg2radian(lat); |
|
48 | pos->lat = code_ndeg2radian(lat); | |
49 | pos->lon = code_ndeg2radian(lon); |
|
49 | pos->lon = code_ndeg2radian(lon); | |
50 | } |
|
50 | } | |
@@ -52,7 +52,7 | |||||
52 | /** |
|
52 | /** | |
53 | * \brief Convert radians position to INFOs position |
|
53 | * \brief Convert radians position to INFOs position | |
54 | */ |
|
54 | */ | |
55 |
void nmeaInfo:: |
|
55 | void nmeaInfo::nmea_info_pos2info(const nmeaPOS *pos) { | |
56 | lat = code_radian2ndeg(pos->lat); |
|
56 | lat = code_radian2ndeg(pos->lat); | |
57 | lon = code_radian2ndeg(pos->lon); |
|
57 | lon = code_radian2ndeg(pos->lon); | |
58 | } |
|
58 | } | |
@@ -116,7 +116,7 | |||||
116 |
|
116 | |||
117 | int nmeaInfo::nmea_igen_static_loop() |
|
117 | int nmeaInfo::nmea_igen_static_loop() | |
118 | { |
|
118 | { | |
119 |
|
|
119 | nmea_info_time_now(); | |
120 | return 1; |
|
120 | return 1; | |
121 | }; |
|
121 | }; | |
122 |
|
122 | |||
@@ -173,7 +173,7 | |||||
173 | double deg = 360 / (count?count:1); |
|
173 | double deg = 360 / (count?count:1); | |
174 | double srt = (count?(satinfo.sat[0].azimuth):0) + 5; |
|
174 | double srt = (count?(satinfo.sat[0].azimuth):0) + 5; | |
175 |
|
175 | |||
176 |
|
|
176 | nmea_info_time_now(); | |
177 |
|
177 | |||
178 | for(it = 0; it < count; ++it) |
|
178 | for(it = 0; it < count; ++it) | |
179 | { |
|
179 | { | |
@@ -247,9 +247,9 | |||||
247 | if(speed < 1) |
|
247 | if(speed < 1) | |
248 | speed = 1; |
|
248 | speed = 1; | |
249 |
|
249 | |||
250 |
|
|
250 | nmea_info_info2pos(&crd); | |
251 | code_move_horz(&crd, &crd, direction, speed / 3600); |
|
251 | code_move_horz(&crd, &crd, direction, speed / 3600); | |
252 |
|
|
252 | nmea_info_pos2info(&crd); | |
253 |
|
253 | |||
254 | declination = direction; |
|
254 | declination = direction; | |
255 |
|
255 |
@@ -47,22 +47,22 | |||||
47 | public: |
|
47 | public: | |
48 | nmeaInfo(); |
|
48 | nmeaInfo(); | |
49 | virtual ~nmeaInfo(); |
|
49 | virtual ~nmeaInfo(); | |
50 |
void |
|
50 | void nmea_info_init_INFO(); | |
51 |
static void |
|
51 | static void nmea_info_time_now(); | |
52 |
void |
|
52 | void nmea_info_info2pos(nmeaPOS *pos); | |
53 |
void |
|
53 | void nmea_info_pos2info(const nmeaPOS *pos); | |
54 |
|
54 | |||
55 |
int nmea_i |
|
55 | int nmea_info_noise_init(); | |
56 |
int nmea_i |
|
56 | int nmea_info_noise_loop(); | |
57 |
int nmea_i |
|
57 | int nmea_info_noise_reset(); | |
58 |
int nmea_i |
|
58 | int nmea_info_static_loop(); | |
59 |
int nmea_i |
|
59 | int nmea_info_static_reset(); | |
60 |
int nmea_i |
|
60 | int nmea_info_static_init(); | |
61 |
int nmea_i |
|
61 | int nmea_info_rotate_loop(); | |
62 |
int nmea_i |
|
62 | int nmea_info_rotate_reset(); | |
63 |
int nmea_i |
|
63 | int nmea_info_rotate_init(); | |
64 |
int nmea_i |
|
64 | int nmea_info_pos_rmove_init(); | |
65 |
int nmea_i |
|
65 | int nmea_info_pos_rmove_loop(); | |
66 |
|
66 | |||
67 | private: |
|
67 | private: | |
68 | int smask; /**< Mask specifying types of packages from which data have been obtained */ |
|
68 | int smask; /**< Mask specifying types of packages from which data have been obtained */ | |
@@ -78,6 +78,14 | |||||
78 | double speed; /**< Speed over the ground in kilometers/hour */ |
|
78 | double speed; /**< Speed over the ground in kilometers/hour */ | |
79 | double direction; /**< Track angle in degrees True */ |
|
79 | double direction; /**< Track angle in degrees True */ | |
80 | double declination; /**< Magnetic variation degrees (Easterly var. subtracts from true course) */ |
|
80 | double declination; /**< Magnetic variation degrees (Easterly var. subtracts from true course) */ | |
|
81 | char ns; | |||
|
82 | char ew; | |||
|
83 | double satinuse; | |||
|
84 | char elv_units; | |||
|
85 | double diff; | |||
|
86 | char diff_units; | |||
|
87 | double dgps_age; | |||
|
88 | double dgps_sid; | |||
81 | nmeaSATINFO satinfo; /**< Satellites information */ |
|
89 | nmeaSATINFO satinfo; /**< Satellites information */ | |
82 | }; |
|
90 | }; | |
83 |
|
91 |
@@ -31,7 +31,7 | |||||
31 | int nmea_parser_buff_clear(void); |
|
31 | int nmea_parser_buff_clear(void); | |
32 | int nmea_parser_queue_clear(void); |
|
32 | int nmea_parser_queue_clear(void); | |
33 |
|
33 | |||
34 |
virtual void code |
|
34 | virtual void nmea_parser_code2info(nmeaCode* code, nmeaInfo* info); | |
35 |
|
35 | |||
36 | private: |
|
36 | private: | |
37 | void *top_node; |
|
37 | void *top_node; | |
@@ -43,4 +43,78 | |||||
43 | int nmea_parser_real_push(const char *buff, int buff_sz); |
|
43 | int nmea_parser_real_push(const char *buff, int buff_sz); | |
44 | }; |
|
44 | }; | |
45 |
|
45 | |||
|
46 | ||||
|
47 | class nmeaGPALMParser:nmeaParser { | |||
|
48 | void nmea_parser_code2info(nmeaCode* code, nmeaInfo* info); | |||
|
49 | }; | |||
|
50 | ||||
|
51 | //codigos NMEA que se pueden enviar al receptor GPS GARMIN | |||
|
52 | class nmeaPGRMIParser:nmeaParser { | |||
|
53 | void nmea_parser_code2info(nmeaCode* code, nmeaInfo* info); | |||
|
54 | }; | |||
|
55 | ||||
|
56 | class nmeaPGRMCParser:nmeaParser { | |||
|
57 | void nmea_parser_code2info(nmeaCode* code, nmeaInfo* info); | |||
|
58 | }; | |||
|
59 | ||||
|
60 | class nmeaPGRMC1Parser:nmeaParser { | |||
|
61 | void nmea_parser_code2info(nmeaCode* code, nmeaInfo* info); | |||
|
62 | }; | |||
|
63 | ||||
|
64 | class nmeaPGRMOParser:nmeaParser { | |||
|
65 | void nmea_parser_code2info(nmeaCode* code, nmeaInfo* info); | |||
|
66 | }; | |||
|
67 | ||||
|
68 | ||||
|
69 | //Codigos NMEA que puede transmitir el receptor GNSS | |||
|
70 | ||||
|
71 | class nmeaGPGGAParser:nmeaParser { | |||
|
72 | void nmea_parser_code2info(nmeaCode* code, nmeaInfo* info); | |||
|
73 | }; | |||
|
74 | ||||
|
75 | class nmeaGPGSAParser:nmeaParser { | |||
|
76 | void nmea_parser_code2info(nmeaCode* code, nmeaInfo* info); | |||
|
77 | }; | |||
|
78 | ||||
|
79 | class nmeaGPGSVParser:nmeaParser { | |||
|
80 | void nmea_parser_code2info(nmeaCode* code, nmeaInfo* info); | |||
|
81 | }; | |||
|
82 | ||||
|
83 | class nmeaGPRMCParser:nmeaParser { | |||
|
84 | void nmea_parser_code2info(nmeaCode* code, nmeaInfo* info); | |||
|
85 | }; | |||
|
86 | ||||
|
87 | class nmeaGPVTGParser:nmeaParser { | |||
|
88 | void nmea_parser_code2info(nmeaCode* code, nmeaInfo* info); | |||
|
89 | }; | |||
|
90 | ||||
|
91 | class nmeaGPGLLParser:nmeaParser { | |||
|
92 | void nmea_parser_code2info(nmeaCode* code, nmeaInfo* info); | |||
|
93 | }; | |||
|
94 | ||||
|
95 | //codigos de propiedad de GARMIN | |||
|
96 | class nmeaPGRMEParser:nmeaParser { | |||
|
97 | void nmea_parser_code2info(nmeaCode* code, nmeaInfo* info); | |||
|
98 | }; | |||
|
99 | ||||
|
100 | class nmeaPGRMFParser:nmeaParser { | |||
|
101 | void nmea_parser_code2info(nmeaCode* code, nmeaInfo* info); | |||
|
102 | }; | |||
|
103 | ||||
|
104 | class nmeaPGRMMParser:nmeaParser { | |||
|
105 | void nmea_parser_code2info(nmeaCode* code, nmeaInfo* info); | |||
|
106 | }; | |||
|
107 | ||||
|
108 | class nmeaPGRMTParser:nmeaParser { | |||
|
109 | void nmea_parser_code2info(nmeaCode* code, nmeaInfo* info); | |||
|
110 | }; | |||
|
111 | ||||
|
112 | class nmeaPGRMVParser:nmeaParser { | |||
|
113 | void nmea_parser_code2info(nmeaCode* code, nmeaInfo* info); | |||
|
114 | }; | |||
|
115 | ||||
|
116 | class nmeaPGRMBParser:nmeaParser { | |||
|
117 | void nmea_parser_code2info(nmeaCode* code, nmeaInfo* info); | |||
|
118 | }; | |||
|
119 | ||||
46 | #endif /* NMEALIB_NMEALIB___NMEAPARSER_H_ */ |
|
120 | #endif /* NMEALIB_NMEALIB___NMEAPARSER_H_ */ |
@@ -13,7 +13,7 | |||||
13 | * \fn code_degree2radian |
|
13 | * \fn code_degree2radian | |
14 | * \brief Convert degree to radian |
|
14 | * \brief Convert degree to radian | |
15 | */ |
|
15 | */ | |
16 |
double |
|
16 | double nmea_utils_degree2radian(double val) { | |
17 | return (val * code_PI180); |
|
17 | return (val * code_PI180); | |
18 | } |
|
18 | } | |
19 |
|
19 | |||
@@ -21,14 +21,14 | |||||
21 | * \fn code_radian2degree |
|
21 | * \fn code_radian2degree | |
22 | * \brief Convert radian to degree |
|
22 | * \brief Convert radian to degree | |
23 | */ |
|
23 | */ | |
24 |
double |
|
24 | double nmea_utils_radian2degree(double val) { | |
25 | return (val / code_PI180); |
|
25 | return (val / code_PI180); | |
26 | } |
|
26 | } | |
27 |
|
27 | |||
28 | /** |
|
28 | /** | |
29 | * \brief Convert NDEG (NMEA degree) to fractional degree |
|
29 | * \brief Convert NDEG (NMEA degree) to fractional degree | |
30 | */ |
|
30 | */ | |
31 |
double |
|
31 | double nmea_utils_ndeg2degree(double val) { | |
32 | double deg = ((int)(val / 100)); |
|
32 | double deg = ((int)(val / 100)); | |
33 | val = deg + (val - deg * 100) / 60; |
|
33 | val = deg + (val - deg * 100) / 60; | |
34 | return val; |
|
34 | return val; | |
@@ -37,7 +37,7 | |||||
37 | /** |
|
37 | /** | |
38 | * \brief Convert fractional degree to NDEG (NMEA degree) |
|
38 | * \brief Convert fractional degree to NDEG (NMEA degree) | |
39 | */ |
|
39 | */ | |
40 |
double |
|
40 | double nmea_utils_degree2ndeg(double val) { | |
41 | double int_part; |
|
41 | double int_part; | |
42 | double fra_part; |
|
42 | double fra_part; | |
43 | fra_part = modf(val, &int_part); |
|
43 | fra_part = modf(val, &int_part); | |
@@ -50,29 +50,29 | |||||
50 | * \brief Convert NDEG (NMEA degree) to radian |
|
50 | * \brief Convert NDEG (NMEA degree) to radian | |
51 | */ |
|
51 | */ | |
52 | double code_ndeg2radian(double val) { |
|
52 | double code_ndeg2radian(double val) { | |
53 |
return |
|
53 | return nmea_utils_degree2radian(nmea_utils_ndeg2degree(val)); | |
54 | } |
|
54 | } | |
55 |
|
55 | |||
56 | /** |
|
56 | /** | |
57 | * \fn code_radian2ndeg |
|
57 | * \fn code_radian2ndeg | |
58 | * \brief Convert radian to NDEG (NMEA degree) |
|
58 | * \brief Convert radian to NDEG (NMEA degree) | |
59 | */ |
|
59 | */ | |
60 |
double |
|
60 | double nmea_utils_radian2ndeg(double val) { | |
61 |
return |
|
61 | return nmea_utils_degree2ndeg(nmea_utils_radian2degree(val)); | |
62 | } |
|
62 | } | |
63 |
|
63 | |||
64 | /** |
|
64 | /** | |
65 | * \brief Calculate PDOP (Position Dilution Of Precision) factor |
|
65 | * \brief Calculate PDOP (Position Dilution Of Precision) factor | |
66 | */ |
|
66 | */ | |
67 |
double |
|
67 | double nmea_utils_calc_pdop(double hdop, double vdop) { | |
68 | return sqrt(pow(hdop, 2) + pow(vdop, 2)); |
|
68 | return sqrt(pow(hdop, 2) + pow(vdop, 2)); | |
69 | } |
|
69 | } | |
70 |
|
70 | |||
71 |
double |
|
71 | double nmea_utils_dop2meters(double dop) { | |
72 | return (dop * code_DOP_FACTOR); |
|
72 | return (dop * code_DOP_FACTOR); | |
73 | } |
|
73 | } | |
74 |
|
74 | |||
75 |
double |
|
75 | double nmea_utils_meters2dop(double meters) { | |
76 | return (meters / code_DOP_FACTOR); |
|
76 | return (meters / code_DOP_FACTOR); | |
77 | } |
|
77 | } | |
78 |
|
78 | |||
@@ -80,7 +80,7 | |||||
80 | * \brief Calculate distance between two points |
|
80 | * \brief Calculate distance between two points | |
81 | * \return Distance in meters |
|
81 | * \return Distance in meters | |
82 | */ |
|
82 | */ | |
83 |
double |
|
83 | double nmea_utils_distance( | |
84 | const nmeaPOS *from_pos, /**< From position in radians */ |
|
84 | const nmeaPOS *from_pos, /**< From position in radians */ | |
85 | const nmeaPOS *to_pos /**< To position in radians */ |
|
85 | const nmeaPOS *to_pos /**< To position in radians */ | |
86 | ) |
|
86 | ) | |
@@ -99,7 +99,7 | |||||
99 | * http://www.ngs.noaa.gov/PUBS_LIB/inverse.pdf |
|
99 | * http://www.ngs.noaa.gov/PUBS_LIB/inverse.pdf | |
100 | * \return Distance in meters |
|
100 | * \return Distance in meters | |
101 | */ |
|
101 | */ | |
102 |
double |
|
102 | double nmea_utils_distance_ellipsoid( | |
103 | const nmeaPOS *from_pos, /**< From position in radians */ |
|
103 | const nmeaPOS *from_pos, /**< From position in radians */ | |
104 | const nmeaPOS *to_pos, /**< To position in radians */ |
|
104 | const nmeaPOS *to_pos, /**< To position in radians */ | |
105 | double *from_azimuth, /**< (O) azimuth at "from" position in radians */ |
|
105 | double *from_azimuth, /**< (O) azimuth at "from" position in radians */ | |
@@ -214,7 +214,7 | |||||
214 | /** |
|
214 | /** | |
215 | * \brief Horizontal move of point position |
|
215 | * \brief Horizontal move of point position | |
216 | */ |
|
216 | */ | |
217 |
int |
|
217 | int nmea_utils_move_horz( | |
218 | const nmeaPOS *start_pos, /**< Start position in radians */ |
|
218 | const nmeaPOS *start_pos, /**< Start position in radians */ | |
219 | nmeaPOS *end_pos, /**< Result position in radians */ |
|
219 | nmeaPOS *end_pos, /**< Result position in radians */ | |
220 | double azimuth, /**< Azimuth (degree) [0, 359] */ |
|
220 | double azimuth, /**< Azimuth (degree) [0, 359] */ | |
@@ -225,7 +225,7 | |||||
225 | int RetVal = 1; |
|
225 | int RetVal = 1; | |
226 |
|
226 | |||
227 | distance /= code_EARTHRADIUS_KM; /* Angular distance covered on earth's surface */ |
|
227 | distance /= code_EARTHRADIUS_KM; /* Angular distance covered on earth's surface */ | |
228 |
azimuth = |
|
228 | azimuth = nmea_utils_degree2radian(azimuth); | |
229 |
|
229 | |||
230 | end_pos->lat = asin( |
|
230 | end_pos->lat = asin( | |
231 | sin(p1.lat) * cos(distance) + cos(p1.lat) * sin(distance) * cos(azimuth)); |
|
231 | sin(p1.lat) * cos(distance) + cos(p1.lat) * sin(distance) * cos(azimuth)); | |
@@ -247,7 +247,7 | |||||
247 | * The algorithm is described here: |
|
247 | * The algorithm is described here: | |
248 | * http://www.ngs.noaa.gov/PUBS_LIB/inverse.pdf |
|
248 | * http://www.ngs.noaa.gov/PUBS_LIB/inverse.pdf | |
249 | */ |
|
249 | */ | |
250 |
int |
|
250 | int nmea_utils_move_horz_ellipsoid( | |
251 | const nmeaPOS *start_pos, /**< Start position in radians */ |
|
251 | const nmeaPOS *start_pos, /**< Start position in radians */ | |
252 | nmeaPOS *end_pos, /**< (O) Result position in radians */ |
|
252 | nmeaPOS *end_pos, /**< (O) Result position in radians */ | |
253 | double azimuth, /**< Azimuth in radians */ |
|
253 | double azimuth, /**< Azimuth in radians */ | |
@@ -358,7 +358,7 | |||||
358 | /** |
|
358 | /** | |
359 | * \brief Calculate control sum of binary buffer |
|
359 | * \brief Calculate control sum of binary buffer | |
360 | */ |
|
360 | */ | |
361 |
int |
|
361 | int nmea_utils_calc_crc(const char *buff, int buff_sz) | |
362 | { |
|
362 | { | |
363 | int chsum = 0, |
|
363 | int chsum = 0, | |
364 | it; |
|
364 | it; | |
@@ -372,7 +372,7 | |||||
372 | /** |
|
372 | /** | |
373 | * \brief Convert string to number |
|
373 | * \brief Convert string to number | |
374 | */ |
|
374 | */ | |
375 |
int |
|
375 | int nmea_utils_atoi(const char *str, int str_sz, int radix) | |
376 | { |
|
376 | { | |
377 | char *tmp_ptr; |
|
377 | char *tmp_ptr; | |
378 | char buff[NMEA_CONVSTR_BUF]; |
|
378 | char buff[NMEA_CONVSTR_BUF]; | |
@@ -391,7 +391,7 | |||||
391 | /** |
|
391 | /** | |
392 | * \brief Convert string to fraction number |
|
392 | * \brief Convert string to fraction number | |
393 | */ |
|
393 | */ | |
394 |
double |
|
394 | double nmea_utils_atof(const char *str, int str_sz) | |
395 | { |
|
395 | { | |
396 | char *tmp_ptr; |
|
396 | char *tmp_ptr; | |
397 | char buff[NMEA_CONVSTR_BUF]; |
|
397 | char buff[NMEA_CONVSTR_BUF]; | |
@@ -410,7 +410,7 | |||||
410 | /** |
|
410 | /** | |
411 | * \brief Formating string (like standart printf) with CRC tail (*CRC) |
|
411 | * \brief Formating string (like standart printf) with CRC tail (*CRC) | |
412 | */ |
|
412 | */ | |
413 |
int |
|
413 | int nmea_utils_printf(char *buff, int buff_sz, const char *format, ...) | |
414 | { |
|
414 | { | |
415 | int retval, add = 0; |
|
415 | int retval, add = 0; | |
416 | va_list arg_ptr; |
|
416 | va_list arg_ptr; | |
@@ -426,7 +426,7 | |||||
426 | { |
|
426 | { | |
427 | add = NMEA_POSIX(snprintf)( |
|
427 | add = NMEA_POSIX(snprintf)( | |
428 | buff + retval, buff_sz - retval, "*%02x\r\n", |
|
428 | buff + retval, buff_sz - retval, "*%02x\r\n", | |
429 |
|
|
429 | nmea_utils_calc_crc(buff + 1, retval - 1)); | |
430 | } |
|
430 | } | |
431 |
|
431 | |||
432 | retval += add; |
|
432 | retval += add; | |
@@ -445,7 +445,7 | |||||
445 | /** |
|
445 | /** | |
446 | * \brief Analyse string (specificate for NMEA sentences) |
|
446 | * \brief Analyse string (specificate for NMEA sentences) | |
447 | */ |
|
447 | */ | |
448 |
int |
|
448 | int nmea_utils_scanf(const char *buff, int buff_sz, const char *format, ...) | |
449 | { |
|
449 | { | |
450 | const char *beg_tok; |
|
450 | const char *beg_tok; | |
451 | const char *end_buf = buff + buff_sz; |
|
451 | const char *end_buf = buff + buff_sz; | |
@@ -481,7 +481,7 | |||||
481 | { |
|
481 | { | |
482 | tok_type = NMEA_TOKS_TYPE; |
|
482 | tok_type = NMEA_TOKS_TYPE; | |
483 | if(format > beg_fmt) |
|
483 | if(format > beg_fmt) | |
484 |
width = |
|
484 | width = nmea_utils_atoi(beg_fmt, (int)(format - beg_fmt), 10); | |
485 | } |
|
485 | } | |
486 | case NMEA_TOKS_TYPE: |
|
486 | case NMEA_TOKS_TYPE: | |
487 | beg_tok = buff; |
|
487 | beg_tok = buff; | |
@@ -534,7 +534,7 | |||||
534 | case 'E': |
|
534 | case 'E': | |
535 | parg_target = (void *)va_arg(arg_ptr, double *); |
|
535 | parg_target = (void *)va_arg(arg_ptr, double *); | |
536 | if(width && 0 != (parg_target)) |
|
536 | if(width && 0 != (parg_target)) | |
537 |
*((double *)parg_target) = |
|
537 | *((double *)parg_target) = nmea_utils_atof(beg_tok, width); | |
538 | break; |
|
538 | break; | |
539 | }; |
|
539 | }; | |
540 |
|
540 | |||
@@ -549,20 +549,20 | |||||
549 | { |
|
549 | { | |
550 | case 'd': |
|
550 | case 'd': | |
551 | case 'i': |
|
551 | case 'i': | |
552 |
snum = |
|
552 | snum = nmea_utils_atoi(beg_tok, width, 10); | |
553 | memcpy(parg_target, &snum, sizeof(int)); |
|
553 | memcpy(parg_target, &snum, sizeof(int)); | |
554 | break; |
|
554 | break; | |
555 | case 'u': |
|
555 | case 'u': | |
556 |
unum = |
|
556 | unum = nmea_utils_atoi(beg_tok, width, 10); | |
557 | memcpy(parg_target, &unum, sizeof(unsigned int)); |
|
557 | memcpy(parg_target, &unum, sizeof(unsigned int)); | |
558 | break; |
|
558 | break; | |
559 | case 'x': |
|
559 | case 'x': | |
560 | case 'X': |
|
560 | case 'X': | |
561 |
unum = |
|
561 | unum = nmea_utils_atoi(beg_tok, width, 16); | |
562 | memcpy(parg_target, &unum, sizeof(unsigned int)); |
|
562 | memcpy(parg_target, &unum, sizeof(unsigned int)); | |
563 | break; |
|
563 | break; | |
564 | case 'o': |
|
564 | case 'o': | |
565 |
unum = |
|
565 | unum = nmea_utils_atoi(beg_tok, width, 8); | |
566 | memcpy(parg_target, &unum, sizeof(unsigned int)); |
|
566 | memcpy(parg_target, &unum, sizeof(unsigned int)); | |
567 | break; |
|
567 | break; | |
568 | default: |
|
568 | default: | |
@@ -581,7 +581,7 | |||||
581 | } |
|
581 | } | |
582 |
|
582 | |||
583 |
|
583 | |||
584 |
double nmea |
|
584 | double nmea_utils_random(double min, double max) | |
585 | { |
|
585 | { | |
586 | static double rand_max = RAND_MAX; |
|
586 | static double rand_max = RAND_MAX; | |
587 | double rand_val = rand(); |
|
587 | double rand_val = rand(); |
@@ -10,29 +10,29 | |||||
10 |
|
10 | |||
11 | #include "nmea_defs.h" |
|
11 | #include "nmea_defs.h" | |
12 |
|
12 | |||
13 |
double |
|
13 | double nmea_utils_degree2radian(double val); | |
14 |
double |
|
14 | double nmea_utils_radian2degree(double val); | |
15 |
double |
|
15 | double nmea_utils_ndeg2degree(double val); | |
16 |
double |
|
16 | double nmea_utils_degree2ndeg(double val); | |
17 |
double |
|
17 | double nmea_utils_ndeg2radian(double val); | |
18 |
double |
|
18 | double nmea_utils_radian2ndeg(double val); | |
19 |
double |
|
19 | double nmea_utils_calc_pdop(double hdop, double vdop); | |
20 |
double |
|
20 | double nmea_utils_dop2meters(double dop); | |
21 |
double |
|
21 | double nmea_utils_meters2dop(double meters); | |
22 |
double |
|
22 | double nmea_utils_distance(const nmeaPOS *from_pos, const nmeaPOS *to_pos); | |
23 |
double |
|
23 | double nmea_utils_distance_ellipsoid(const nmeaPOS *from_pos, const nmeaPOS *to_pos, | |
24 | double *from_azimuth, double *to_azimuth); |
|
24 | double *from_azimuth, double *to_azimuth); | |
25 |
int |
|
25 | int nmea_utils_move_horz(const nmeaPOS *start_pos, nmeaPOS *end_pos, | |
26 | double azimuth, double distance); |
|
26 | double azimuth, double distance); | |
27 |
int |
|
27 | int nmea_utils_move_horz_ellipsoid(const nmeaPOS *start_pos, nmeaPOS *end_pos, | |
28 | double azimuth, double distance, double *end_azimuth ); |
|
28 | double azimuth, double distance, double *end_azimuth ); | |
29 |
|
29 | |||
30 |
int |
|
30 | int nmea_utils_calc_crc(const char *buff, int buff_sz); | |
31 |
int |
|
31 | int nmea_utils_atoi(const char *str, int str_sz, int radix); | |
32 |
double |
|
32 | double nmea_utils_atof(const char *str, int str_sz); | |
33 |
int |
|
33 | int nmea_utils_printf(char *buff, int buff_sz, const char *format, ...); | |
34 |
int |
|
34 | int nmea_utils_scanf(const char *buff, int buff_sz, const char *format, ...); | |
35 |
|
35 | |||
36 | double nmea_random(double min, double max); |
|
36 | double nmea_utils_random(double min, double max); | |
37 |
|
37 | |||
38 | #endif /* NMEALIB___UTILS_H_ */ |
|
38 | #endif /* NMEALIB___UTILS_H_ */ |
General Comments 0
You need to be logged in to leave comments.
Login now