Rev 780 | Go to most recent revision | Only display areas with differences | Ignore whitespace | Details | Blame | Last modification | View Log | RSS feed
Rev 780 | Rev 792 | ||
---|---|---|---|
1 | /*#######################################################################################*/ |
1 | /*#######################################################################################*/ |
2 | /* !!! THIS IS NOT FREE SOFTWARE !!! */ |
2 | /* !!! THIS IS NOT FREE SOFTWARE !!! */ |
3 | /*#######################################################################################*/ |
3 | /*#######################################################################################*/ |
4 | // ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ |
4 | // ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ |
5 | // + www.MikroKopter.com |
5 | // + www.MikroKopter.com |
6 | // ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ |
6 | // ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ |
7 | // + Software Nutzungsbedingungen (english version: see below) |
7 | // + Software Nutzungsbedingungen (english version: see below) |
8 | // + der Fa. HiSystems GmbH, Flachsmeerstrasse 2, 26802 Moormerland - nachfolgend Lizenzgeber genannt - |
8 | // + der Fa. HiSystems GmbH, Flachsmeerstrasse 2, 26802 Moormerland - nachfolgend Lizenzgeber genannt - |
9 | // + Der Lizenzgeber räumt dem Kunden ein nicht-ausschließliches, zeitlich und räumlich* unbeschränktes Recht ein, die im den |
9 | // + Der Lizenzgeber räumt dem Kunden ein nicht-ausschließliches, zeitlich und räumlich* unbeschränktes Recht ein, die im den |
10 | // + Mikrocontroller verwendete Firmware für die Hardware Flight-Ctrl, Navi-Ctrl, BL-Ctrl, MK3Mag & PC-Programm MikroKopter-Tool |
10 | // + Mikrocontroller verwendete Firmware für die Hardware Flight-Ctrl, Navi-Ctrl, BL-Ctrl, MK3Mag & PC-Programm MikroKopter-Tool |
11 | // + - nachfolgend Software genannt - nur für private Zwecke zu nutzen. |
11 | // + - nachfolgend Software genannt - nur für private Zwecke zu nutzen. |
12 | // + Der Einsatz dieser Software ist nur auf oder mit Produkten des Lizenzgebers zulässig. |
12 | // + Der Einsatz dieser Software ist nur auf oder mit Produkten des Lizenzgebers zulässig. |
13 | // ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ |
13 | // ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ |
14 | // + Die vom Lizenzgeber gelieferte Software ist urheberrechtlich geschützt. Alle Rechte an der Software sowie an sonstigen im |
14 | // + Die vom Lizenzgeber gelieferte Software ist urheberrechtlich geschützt. Alle Rechte an der Software sowie an sonstigen im |
15 | // + Rahmen der Vertragsanbahnung und Vertragsdurchführung überlassenen Unterlagen stehen im Verhältnis der Vertragspartner ausschließlich dem Lizenzgeber zu. |
15 | // + Rahmen der Vertragsanbahnung und Vertragsdurchführung überlassenen Unterlagen stehen im Verhältnis der Vertragspartner ausschließlich dem Lizenzgeber zu. |
16 | // + Die in der Software enthaltenen Copyright-Vermerke, Markenzeichen, andere Rechtsvorbehalte, Seriennummern sowie |
16 | // + Die in der Software enthaltenen Copyright-Vermerke, Markenzeichen, andere Rechtsvorbehalte, Seriennummern sowie |
17 | // + sonstige der Programmidentifikation dienenden Merkmale dürfen vom Kunden nicht verändert oder unkenntlich gemacht werden. |
17 | // + sonstige der Programmidentifikation dienenden Merkmale dürfen vom Kunden nicht verändert oder unkenntlich gemacht werden. |
18 | // + Der Kunde trifft angemessene Vorkehrungen für den sicheren Einsatz der Software. Er wird die Software gründlich auf deren |
18 | // + Der Kunde trifft angemessene Vorkehrungen für den sicheren Einsatz der Software. Er wird die Software gründlich auf deren |
19 | // + Verwendbarkeit zu dem von ihm beabsichtigten Zweck testen, bevor er diese operativ einsetzt. |
19 | // + Verwendbarkeit zu dem von ihm beabsichtigten Zweck testen, bevor er diese operativ einsetzt. |
20 | // + Die Haftung des Lizenzgebers wird - soweit gesetzlich zulässig - begrenzt in Höhe des typischen und vorhersehbaren |
20 | // + Die Haftung des Lizenzgebers wird - soweit gesetzlich zulässig - begrenzt in Höhe des typischen und vorhersehbaren |
21 | // + Schadens. Die gesetzliche Haftung bei Personenschäden und nach dem Produkthaftungsgesetz bleibt unberührt. Dem Lizenzgeber steht jedoch der Einwand |
21 | // + Schadens. Die gesetzliche Haftung bei Personenschäden und nach dem Produkthaftungsgesetz bleibt unberührt. Dem Lizenzgeber steht jedoch der Einwand |
22 | // + des Mitverschuldens offen. |
22 | // + des Mitverschuldens offen. |
23 | // + Der Kunde trifft angemessene Vorkehrungen für den Fall, dass die Software ganz oder teilweise nicht ordnungsgemäß arbeitet. |
23 | // + Der Kunde trifft angemessene Vorkehrungen für den Fall, dass die Software ganz oder teilweise nicht ordnungsgemäß arbeitet. |
24 | // + Er wird die Software gründlich auf deren Verwendbarkeit zu dem von ihm beabsichtigten Zweck testen, bevor er diese operativ einsetzt. |
24 | // + Er wird die Software gründlich auf deren Verwendbarkeit zu dem von ihm beabsichtigten Zweck testen, bevor er diese operativ einsetzt. |
25 | // + Der Kunde wird er seine Daten vor Einsatz der Software nach dem Stand der Technik sichern. |
25 | // + Der Kunde wird er seine Daten vor Einsatz der Software nach dem Stand der Technik sichern. |
26 | // + Der Kunde ist darüber unterrichtet, dass der Lizenzgeber seine Daten im zur Vertragsdurchführung erforderlichen Umfang |
26 | // + Der Kunde ist darüber unterrichtet, dass der Lizenzgeber seine Daten im zur Vertragsdurchführung erforderlichen Umfang |
27 | // + und auf Grundlage der Datenschutzvorschriften erhebt, speichert, verarbeitet und, sofern notwendig, an Dritte übermittelt. |
27 | // + und auf Grundlage der Datenschutzvorschriften erhebt, speichert, verarbeitet und, sofern notwendig, an Dritte übermittelt. |
28 | // + *) Die räumliche Nutzung bezieht sich nur auf den Einsatzort, nicht auf die Reichweite der programmierten Software. |
28 | // + *) Die räumliche Nutzung bezieht sich nur auf den Einsatzort, nicht auf die Reichweite der programmierten Software. |
29 | // + #### ENDE DER NUTZUNGSBEDINGUNGEN ####' |
29 | // + #### ENDE DER NUTZUNGSBEDINGUNGEN ####' |
30 | // + Hinweis: Informationen über erweiterte Nutzungsrechte (wie z.B. Nutzung für nicht-private Zwecke) sind auf Anfrage per Email an info(@)hisystems.de verfügbar. |
30 | // + Hinweis: Informationen über erweiterte Nutzungsrechte (wie z.B. Nutzung für nicht-private Zwecke) sind auf Anfrage per Email an info(@)hisystems.de verfügbar. |
31 | // ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ |
31 | // ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ |
32 | // + Software LICENSING TERMS |
32 | // + Software LICENSING TERMS |
33 | // ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ |
33 | // ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ |
34 | // + of HiSystems GmbH, Flachsmeerstrasse 2, 26802 Moormerland, Germany - the Licensor - |
34 | // + of HiSystems GmbH, Flachsmeerstrasse 2, 26802 Moormerland, Germany - the Licensor - |
35 | // + The Licensor grants the customer a non-exclusive license to use the microcontroller firmware of the Flight-Ctrl, Navi-Ctrl, BL-Ctrl, and MK3Mag hardware |
35 | // + The Licensor grants the customer a non-exclusive license to use the microcontroller firmware of the Flight-Ctrl, Navi-Ctrl, BL-Ctrl, and MK3Mag hardware |
36 | // + (the Software) exclusively for private purposes. The License is unrestricted with respect to time and territory*. |
36 | // + (the Software) exclusively for private purposes. The License is unrestricted with respect to time and territory*. |
37 | // + The Software may only be used with the Licensor's products. |
37 | // + The Software may only be used with the Licensor's products. |
38 | // + The Software provided by the Licensor is protected by copyright. With respect to the relationship between the parties to this |
38 | // + The Software provided by the Licensor is protected by copyright. With respect to the relationship between the parties to this |
39 | // + agreement, all rights pertaining to the Software and other documents provided during the preparation and execution of this |
39 | // + agreement, all rights pertaining to the Software and other documents provided during the preparation and execution of this |
40 | // + agreement shall be the property of the Licensor. |
40 | // + agreement shall be the property of the Licensor. |
41 | // + The information contained in the Software copyright notices, trademarks, other legal reservations, serial numbers and other |
41 | // + The information contained in the Software copyright notices, trademarks, other legal reservations, serial numbers and other |
42 | // + features that can be used to identify the program may not be altered or defaced by the customer. |
42 | // + features that can be used to identify the program may not be altered or defaced by the customer. |
43 | // + The customer shall be responsible for taking reasonable precautions |
43 | // + The customer shall be responsible for taking reasonable precautions |
44 | // + for the safe use of the Software. The customer shall test the Software thoroughly regarding its suitability for the |
44 | // + for the safe use of the Software. The customer shall test the Software thoroughly regarding its suitability for the |
45 | // + intended purpose before implementing it for actual operation. The Licensor's liability shall be limited to the extent of typical and |
45 | // + intended purpose before implementing it for actual operation. The Licensor's liability shall be limited to the extent of typical and |
46 | // + foreseeable damage to the extent permitted by law, notwithstanding statutory liability for bodily injury and product |
46 | // + foreseeable damage to the extent permitted by law, notwithstanding statutory liability for bodily injury and product |
47 | // + liability. However, the Licensor shall be entitled to the defense of contributory negligence. |
47 | // + liability. However, the Licensor shall be entitled to the defense of contributory negligence. |
48 | // + The customer will take adequate precautions in the case, that the software is not working properly. The customer will test |
48 | // + The customer will take adequate precautions in the case, that the software is not working properly. The customer will test |
49 | // + the software for his purpose before any operational usage. The customer will backup his data before using the software. |
49 | // + the software for his purpose before any operational usage. The customer will backup his data before using the software. |
50 | // + The customer understands that the Licensor collects, stores and processes, and, where required, forwards, customer data |
50 | // + The customer understands that the Licensor collects, stores and processes, and, where required, forwards, customer data |
51 | // + to third parties to the extent necessary for executing the agreement, subject to applicable data protection and privacy regulations. |
51 | // + to third parties to the extent necessary for executing the agreement, subject to applicable data protection and privacy regulations. |
52 | // + *) The territory aspect only refers to the place where the Software is used, not its programmed range. |
52 | // + *) The territory aspect only refers to the place where the Software is used, not its programmed range. |
53 | // + #### END OF LICENSING TERMS #### |
53 | // + #### END OF LICENSING TERMS #### |
54 | // + Note: For information on license extensions (e.g. commercial use), please contact us at info(@)hisystems.de. |
54 | // + Note: For information on license extensions (e.g. commercial use), please contact us at info(@)hisystems.de. |
55 | // ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ |
55 | // ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ |
56 | #include <string.h> |
56 | #include <string.h> |
57 | #include "91x_lib.h" |
57 | #include "91x_lib.h" |
58 | #include "uart0.h" |
58 | #include "uart0.h" |
59 | #include "uart1.h" |
59 | #include "uart1.h" |
60 | #include "ubx.h" |
60 | #include "ubx.h" |
61 | #include "main.h" |
61 | #include "main.h" |
62 | #include "led.h" |
62 | #include "led.h" |
63 | #include "timer1.h" |
63 | #include "timer1.h" |
64 | #include "GPS.h" |
64 | #include "GPS.h" |
65 | 65 | ||
66 | // ------------------------------------------------------------------------------------------------ |
66 | // ------------------------------------------------------------------------------------------------ |
67 | // defines |
67 | // defines |
68 | 68 | ||
69 | #define DAYS_FROM_JAN01YEAR0001_TO_JAN6_1980 722819 // the year 0 does not exist! |
69 | #define DAYS_FROM_JAN01YEAR0001_TO_JAN6_1980 722819 // the year 0 does not exist! |
70 | #define DAYS_PER_YEAR 365 |
70 | #define DAYS_PER_YEAR 365 |
71 | #define DAYS_PER_LEAPYEAR 366 |
71 | #define DAYS_PER_LEAPYEAR 366 |
72 | #define DAYS_PER_4YEARS 1461 //((3 * DAYS_PER_YEAR) + DAYS_PER_LEAPYEAR) // years dividable by 4 are leap years |
72 | #define DAYS_PER_4YEARS 1461 //((3 * DAYS_PER_YEAR) + DAYS_PER_LEAPYEAR) // years dividable by 4 are leap years |
73 | #define DAYS_PER_100YEARS 36524 //((25 * DAYS_PER_4YEARS) - 1) // years dividable by 100 are no leap years |
73 | #define DAYS_PER_100YEARS 36524 //((25 * DAYS_PER_4YEARS) - 1) // years dividable by 100 are no leap years |
74 | #define DAYS_PER_400YEARS 146097 //((4 * DAYS_PER_100YEARS) + 1L) // but years dividable by 400 are leap years |
74 | #define DAYS_PER_400YEARS 146097 //((4 * DAYS_PER_100YEARS) + 1L) // but years dividable by 400 are leap years |
75 | #define SECONDS_PER_MINUTE 60 |
75 | #define SECONDS_PER_MINUTE 60 |
76 | #define MINUTES_PER_HOUR 60 |
76 | #define MINUTES_PER_HOUR 60 |
77 | #define HOURS_PER_DAY 24 |
77 | #define HOURS_PER_DAY 24 |
78 | #define DAYS_PER_WEEK 7 |
78 | #define DAYS_PER_WEEK 7 |
79 | #define SECONDS_PER_HOUR 3600 //(SECONDS_PER_MINUTE * MINUTES_PER_HOUR) |
79 | #define SECONDS_PER_HOUR 3600 //(SECONDS_PER_MINUTE * MINUTES_PER_HOUR) |
80 | #define SECONDS_PER_DAY 86400 //(SECONDS_PER_HOUR * HOURS_PER_DAY) |
80 | #define SECONDS_PER_DAY 86400 //(SECONDS_PER_HOUR * HOURS_PER_DAY) |
81 | #define SECONDS_PER_WEEK 604800 //(SECONDS_PER_DAY * DAYS_PER_WEEK) |
81 | #define SECONDS_PER_WEEK 604800 //(SECONDS_PER_DAY * DAYS_PER_WEEK) |
82 | 82 | ||
83 | // days per month in normal and leap years |
83 | // days per month in normal and leap years |
84 | const u32 Leap[ 13 ] = { 0, 31, 60, 91, 121, 152, 182, 213, 244, 274, 305, 335, 366 }; |
84 | const u32 Leap[ 13 ] = { 0, 31, 60, 91, 121, 152, 182, 213, 244, 274, 305, 335, 366 }; |
85 | const u32 Normal[ 13 ] = { 0, 31, 59, 90, 120, 151, 181, 212, 243, 273, 304, 334, 365 }; |
85 | const u32 Normal[ 13 ] = { 0, 31, 59, 90, 120, 151, 181, 212, 243, 273, 304, 334, 365 }; |
86 | 86 | ||
87 | #define LEAP_SECONDS_FROM_1980 16 |
87 | #define LEAP_SECONDS_FROM_1980 16 |
88 | 88 | ||
89 | // message sync bytes |
89 | // message sync bytes |
90 | #define UBX_SYNC1_CHAR 0xB5 |
90 | #define UBX_SYNC1_CHAR 0xB5 |
91 | #define UBX_SYNC2_CHAR 0x62 |
91 | #define UBX_SYNC2_CHAR 0x62 |
92 | // protocoll identifiers |
92 | // protocoll identifiers |
93 | // navigation class |
93 | // navigation class |
94 | #define UBX_CLASS_NAV 0x01 |
94 | #define UBX_CLASS_NAV 0x01 |
95 | #define UBX_CLASS_MON 0x0A |
95 | #define UBX_CLASS_MON 0x0A |
96 | 96 | ||
97 | #define UBX_ID_POSLLH 0x02 |
97 | #define UBX_ID_POSLLH 0x02 |
98 | #define UBX_ID_SOL 0x06 |
98 | #define UBX_ID_SOL 0x06 |
99 | #define UBX_ID_VELNED 0x12 |
99 | #define UBX_ID_VELNED 0x12 |
100 | 100 | ||
101 | #define UBX_ID_MON_VER 0x04 |
101 | #define UBX_ID_MON_VER 0x04 |
102 | 102 | ||
103 | // ------------------------------------------------------------------------------------------------ |
103 | // ------------------------------------------------------------------------------------------------ |
104 | // typedefs |
104 | // typedefs |
105 | 105 | ||
106 | 106 | ||
107 | // ubx parser state |
107 | // ubx parser state |
108 | typedef enum |
108 | typedef enum |
109 | { |
109 | { |
110 | UBXSTATE_IDLE, |
110 | UBXSTATE_IDLE, |
111 | UBXSTATE_SYNC1, |
111 | UBXSTATE_SYNC1, |
112 | UBXSTATE_SYNC2, |
112 | UBXSTATE_SYNC2, |
113 | UBXSTATE_CLASS, |
113 | UBXSTATE_CLASS, |
114 | UBXSTATE_LEN1, |
114 | UBXSTATE_LEN1, |
115 | UBXSTATE_LEN2, |
115 | UBXSTATE_LEN2, |
116 | UBXSTATE_DATA, |
116 | UBXSTATE_DATA, |
117 | UBXSTATE_CKA, |
117 | UBXSTATE_CKA, |
118 | UBXSTATE_CKB |
118 | UBXSTATE_CKB |
119 | } ubxState_t; |
119 | } ubxState_t; |
120 | 120 | ||
121 | typedef struct |
121 | typedef struct |
122 | { |
122 | { |
123 | u32 itow; // ms GPS Millisecond Time of Week |
123 | u32 itow; // ms GPS Millisecond Time of Week |
124 | s32 frac; // ns remainder of rounded ms above |
124 | s32 frac; // ns remainder of rounded ms above |
125 | s16 week; // GPS week |
125 | s16 week; // GPS week |
126 | u8 GPSfix; // GPSfix Type, range 0..6 |
126 | u8 GPSfix; // GPSfix Type, range 0..6 |
127 | u8 Flags; // Navigation Status Flags |
127 | u8 Flags; // Navigation Status Flags |
128 | s32 ECEF_X; // cm ECEF X coordinate |
128 | s32 ECEF_X; // cm ECEF X coordinate |
129 | s32 ECEF_Y; // cm ECEF Y coordinate |
129 | s32 ECEF_Y; // cm ECEF Y coordinate |
130 | s32 ECEF_Z; // cm ECEF Z coordinate |
130 | s32 ECEF_Z; // cm ECEF Z coordinate |
131 | u32 PAcc; // cm 3D Position Accuracy Estimate |
131 | u32 PAcc; // cm 3D Position Accuracy Estimate |
132 | s32 ECEFVX; // cm/s ECEF X velocity |
132 | s32 ECEFVX; // cm/s ECEF X velocity |
133 | s32 ECEFVY; // cm/s ECEF Y velocity |
133 | s32 ECEFVY; // cm/s ECEF Y velocity |
134 | s32 ECEFVZ; // cm/s ECEF Z velocity |
134 | s32 ECEFVZ; // cm/s ECEF Z velocity |
135 | u32 SAcc; // cm/s Speed Accuracy Estimate |
135 | u32 SAcc; // cm/s Speed Accuracy Estimate |
136 | u16 PDOP; // 0.01 Position DOP |
136 | u16 PDOP; // 0.01 Position DOP |
137 | u8 res1; // reserved |
137 | u8 res1; // reserved |
138 | u8 numSV; // Number of SVs used in navigation solution |
138 | u8 numSV; // Number of SVs used in navigation solution |
139 | u32 res2; // reserved |
139 | u32 res2; // reserved |
140 | u8 Status; // invalid/newdata/processed |
140 | u8 Status; // invalid/newdata/processed |
141 | } __attribute__((packed)) ubx_nav_sol_t; |
141 | } __attribute__((packed)) ubx_nav_sol_t; |
142 | 142 | ||
143 | 143 | ||
144 | typedef struct |
144 | typedef struct |
145 | { |
145 | { |
146 | u32 itow; // ms GPS Millisecond Time of Week |
146 | u32 itow; // ms GPS Millisecond Time of Week |
147 | s32 VEL_N; // cm/s NED north velocity |
147 | s32 VEL_N; // cm/s NED north velocity |
148 | s32 VEL_E; // cm/s NED east velocity |
148 | s32 VEL_E; // cm/s NED east velocity |
149 | s32 VEL_D; // cm/s NED down velocity |
149 | s32 VEL_D; // cm/s NED down velocity |
150 | u32 Speed; // cm/s Speed (3-D) |
150 | u32 Speed; // cm/s Speed (3-D) |
151 | u32 GSpeed; // cm/s Ground Speed (2-D) |
151 | u32 GSpeed; // cm/s Ground Speed (2-D) |
152 | s32 Heading; // 1e-05 deg Heading 2-D |
152 | s32 Heading; // 1e-05 deg Heading 2-D |
153 | u32 SAcc; // cm/s Speed Accuracy Estimate |
153 | u32 SAcc; // cm/s Speed Accuracy Estimate |
154 | u32 CAcc; // deg Course / Heading Accuracy Estimate |
154 | u32 CAcc; // deg Course / Heading Accuracy Estimate |
155 | u8 Status; // invalid/newdata/processed |
155 | u8 Status; // invalid/newdata/processed |
156 | } __attribute__((packed)) ubx_nav_velned_t; |
156 | } __attribute__((packed)) ubx_nav_velned_t; |
157 | 157 | ||
158 | typedef struct |
158 | typedef struct |
159 | { |
159 | { |
160 | u32 itow; // ms GPS Millisecond Time of Week |
160 | u32 itow; // ms GPS Millisecond Time of Week |
161 | s32 LON; // 1e-07 deg Longitude |
161 | s32 LON; // 1e-07 deg Longitude |
162 | s32 LAT; // 1e-07 deg Latitude |
162 | s32 LAT; // 1e-07 deg Latitude |
163 | s32 HEIGHT; // mm Height above Ellipsoid |
163 | s32 HEIGHT; // mm Height above Ellipsoid |
164 | s32 HMSL; // mm Height above mean sea level |
164 | s32 HMSL; // mm Height above mean sea level |
165 | u32 Hacc; // mm Horizontal Accuracy Estimate |
165 | u32 Hacc; // mm Horizontal Accuracy Estimate |
166 | u32 Vacc; // mm Vertical Accuracy Estimate |
166 | u32 Vacc; // mm Vertical Accuracy Estimate |
167 | u8 Status; // invalid/newdata/processed |
167 | u8 Status; // invalid/newdata/processed |
168 | } __attribute__((packed)) ubx_nav_posllh_t; |
168 | } __attribute__((packed)) ubx_nav_posllh_t; |
169 | 169 | ||
170 | //------------------------------------------------------------------------------------ |
170 | //------------------------------------------------------------------------------------ |
171 | // global variables |
171 | // global variables |
172 | 172 | ||
173 | // local buffers for the incomming ubx messages |
173 | // local buffers for the incomming ubx messages |
174 | ubx_nav_sol_t UbxSol = {0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, INVALID}; |
174 | ubx_nav_sol_t UbxSol = {0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, INVALID}; |
175 | ubx_nav_posllh_t UbxPosLlh = {0,0,0,0,0,0,0, INVALID}; |
175 | ubx_nav_posllh_t UbxPosLlh = {0,0,0,0,0,0,0, INVALID}; |
176 | ubx_nav_velned_t UbxVelNed = {0,0,0,0,0,0,0,0,0, INVALID}; |
176 | ubx_nav_velned_t UbxVelNed = {0,0,0,0,0,0,0,0,0, INVALID}; |
177 | ubxmsg_t UbxMsg; |
177 | ubxmsg_t UbxMsg; |
178 | 178 | ||
179 | // shared buffer |
179 | // shared buffer |
180 | gps_data_t GPSData = {200,{0,0,0,INVALID},0,0,0,0,0,0,0, INVALID}; |
180 | gps_data_t GPSData = {200,{0,0,0,INVALID},0,0,0,0,0,0,0, INVALID}; |
181 | DateTime_t GPSDateTime = {0,0,0,0,0,0,0, INVALID}; |
181 | DateTime_t GPSDateTime = {0,0,0,0,0,0,0, INVALID}; |
182 | 182 | ||
183 | #define UBX_TIMEOUT 500 // 500 ms |
183 | #define UBX_TIMEOUT 500 // 500 ms |
184 | u32 UBX_Timeout = 0; |
184 | u32 UBX_Timeout = 0; |
185 | 185 | ||
186 | //------------------------------------------------------------------------------------ |
186 | //------------------------------------------------------------------------------------ |
187 | // functions |
187 | // functions |
188 | 188 | ||
189 | u8 IsLeapYear(u16 year) |
189 | u8 IsLeapYear(u16 year) |
190 | { |
190 | { |
191 | if((year%400 == 0) || ( (year%4 == 0) && (year%100 != 0) ) ) return 1; |
191 | if((year%400 == 0) || ( (year%4 == 0) && (year%100 != 0) ) ) return 1; |
192 | else return 0; |
192 | else return 0; |
193 | } |
193 | } |
194 | /********************************************************/ |
194 | /********************************************************/ |
195 | /* Calculates the UTC Time from the GPS week and tow */ |
195 | /* Calculates the UTC Time from the GPS week and tow */ |
196 | /********************************************************/ |
196 | /********************************************************/ |
197 | void SetGPSTime(DateTime_t * pTimeStruct) |
197 | void SetGPSTime(DateTime_t * pTimeStruct) |
198 | { |
198 | { |
199 | u32 Days, Seconds, Week; |
199 | u32 Days, Seconds, Week; |
200 | u16 YearPart; |
200 | u16 YearPart; |
201 | u32 * MonthDayTab = 0; |
201 | u32 * MonthDayTab = 0; |
202 | u8 i; |
202 | u8 i; |
203 | 203 | ||
204 | 204 | ||
205 | // if GPS data show valid time data |
205 | // if GPS data show valid time data |
206 | if((UbxSol.Status != INVALID) && (UbxSol.Flags & FLAG_WKNSET) && (UbxSol.Flags & FLAG_TOWSET) ) |
206 | if((UbxSol.Status != INVALID) && (UbxSol.Flags & FLAG_WKNSET) && (UbxSol.Flags & FLAG_TOWSET) ) |
207 | { |
207 | { |
208 | Seconds = UbxSol.itow / 1000L; |
208 | Seconds = UbxSol.itow / 1000L; |
209 | Week = (u32)UbxSol.week; |
209 | Week = (u32)UbxSol.week; |
210 | // correct leap seconds since 1980 |
210 | // correct leap seconds since 1980 |
211 | if(Seconds < LEAP_SECONDS_FROM_1980) |
211 | if(Seconds < LEAP_SECONDS_FROM_1980) |
212 | { |
212 | { |
213 | Week--; |
213 | Week--; |
214 | Seconds = SECONDS_PER_WEEK - LEAP_SECONDS_FROM_1980 + Seconds; |
214 | Seconds = SECONDS_PER_WEEK - LEAP_SECONDS_FROM_1980 + Seconds; |
215 | } |
215 | } |
216 | else Seconds -= LEAP_SECONDS_FROM_1980; |
216 | else Seconds -= LEAP_SECONDS_FROM_1980; |
217 | 217 | ||
218 | Days = DAYS_FROM_JAN01YEAR0001_TO_JAN6_1980; |
218 | Days = DAYS_FROM_JAN01YEAR0001_TO_JAN6_1980; |
219 | Days += (Week * DAYS_PER_WEEK); |
219 | Days += (Week * DAYS_PER_WEEK); |
220 | Days += Seconds / SECONDS_PER_DAY; // seperate days from GPS seconds of week |
220 | Days += Seconds / SECONDS_PER_DAY; // seperate days from GPS seconds of week |
221 | 221 | ||
222 | pTimeStruct->Year = 1; |
222 | pTimeStruct->Year = 1; |
223 | YearPart = (u16)(Days / DAYS_PER_400YEARS); |
223 | YearPart = (u16)(Days / DAYS_PER_400YEARS); |
224 | pTimeStruct->Year += YearPart * 400; |
224 | pTimeStruct->Year += YearPart * 400; |
225 | Days = Days % DAYS_PER_400YEARS; |
225 | Days = Days % DAYS_PER_400YEARS; |
226 | YearPart = (u16)(Days / DAYS_PER_100YEARS); |
226 | YearPart = (u16)(Days / DAYS_PER_100YEARS); |
227 | pTimeStruct->Year += YearPart * 100; |
227 | pTimeStruct->Year += YearPart * 100; |
228 | Days = Days % DAYS_PER_100YEARS; |
228 | Days = Days % DAYS_PER_100YEARS; |
229 | YearPart = (u16)(Days / DAYS_PER_4YEARS); |
229 | YearPart = (u16)(Days / DAYS_PER_4YEARS); |
230 | pTimeStruct->Year += YearPart * 4; |
230 | pTimeStruct->Year += YearPart * 4; |
231 | Days = Days % DAYS_PER_4YEARS; |
231 | Days = Days % DAYS_PER_4YEARS; |
232 | if(Days < (3* DAYS_PER_YEAR)) YearPart = (u16)(Days / DAYS_PER_YEAR); |
232 | if(Days < (3* DAYS_PER_YEAR)) YearPart = (u16)(Days / DAYS_PER_YEAR); |
233 | else YearPart = 3; |
233 | else YearPart = 3; |
234 | pTimeStruct->Year += YearPart; |
234 | pTimeStruct->Year += YearPart; |
235 | // calculate remaining days of year |
235 | // calculate remaining days of year |
236 | Days -= (u32)(YearPart * DAYS_PER_YEAR); |
236 | Days -= (u32)(YearPart * DAYS_PER_YEAR); |
237 | Days += 1; |
237 | Days += 1; |
238 | // check if current year is a leap year |
238 | // check if current year is a leap year |
239 | if(IsLeapYear(pTimeStruct->Year)) MonthDayTab = (u32*)Leap; |
239 | if(IsLeapYear(pTimeStruct->Year)) MonthDayTab = (u32*)Leap; |
240 | else MonthDayTab = (u32*)Normal; |
240 | else MonthDayTab = (u32*)Normal; |
241 | // seperate month and day from days of year |
241 | // seperate month and day from days of year |
242 | for ( i = 0; i < 12; i++ ) |
242 | for ( i = 0; i < 12; i++ ) |
243 | { |
243 | { |
244 | if ( (MonthDayTab[i]< Days) && (Days <= MonthDayTab[i+1]) ) |
244 | if ( (MonthDayTab[i]< Days) && (Days <= MonthDayTab[i+1]) ) |
245 | { |
245 | { |
246 | pTimeStruct->Month = i+1; |
246 | pTimeStruct->Month = i+1; |
247 | pTimeStruct->Day = Days - MonthDayTab[i]; |
247 | pTimeStruct->Day = Days - MonthDayTab[i]; |
248 | i = 12; |
248 | i = 12; |
249 | } |
249 | } |
250 | } |
250 | } |
251 | Seconds = Seconds % SECONDS_PER_DAY; // remaining seconds of current day |
251 | Seconds = Seconds % SECONDS_PER_DAY; // remaining seconds of current day |
252 | pTimeStruct->Hour = (u8)(Seconds / SECONDS_PER_HOUR); |
252 | pTimeStruct->Hour = (u8)(Seconds / SECONDS_PER_HOUR); |
253 | Seconds = Seconds % SECONDS_PER_HOUR; // remaining seconds of current hour |
253 | Seconds = Seconds % SECONDS_PER_HOUR; // remaining seconds of current hour |
254 | pTimeStruct->Min = (u8)(Seconds / SECONDS_PER_MINUTE); |
254 | pTimeStruct->Min = (u8)(Seconds / SECONDS_PER_MINUTE); |
255 | Seconds = Seconds % SECONDS_PER_MINUTE; // remaining seconds of current minute |
255 | Seconds = Seconds % SECONDS_PER_MINUTE; // remaining seconds of current minute |
256 | pTimeStruct->Sec = (u8)(Seconds); |
256 | pTimeStruct->Sec = (u8)(Seconds); |
257 | pTimeStruct->mSec = (u16)(UbxSol.itow % 1000L); |
257 | pTimeStruct->mSec = (u16)(UbxSol.itow % 1000L); |
258 | pTimeStruct->Valid = 1; |
258 | pTimeStruct->Valid = 1; |
259 | } |
259 | } |
260 | else |
260 | else |
261 | { |
261 | { |
262 | pTimeStruct->Valid = 0; |
262 | pTimeStruct->Valid = 0; |
263 | } |
263 | } |
264 | } |
264 | } |
265 | 265 | ||
266 | 266 | ||
267 | 267 | ||
268 | /********************************************************/ |
268 | /********************************************************/ |
269 | /* Initialize UBX Parser */ |
269 | /* Initialize UBX Parser */ |
270 | /********************************************************/ |
270 | /********************************************************/ |
271 | void UBX_Init(void) |
271 | void UBX_Init(void) |
272 | { |
272 | { |
273 | // mark msg buffers invalid |
273 | // mark msg buffers invalid |
274 | UbxSol.Status = INVALID; |
274 | UbxSol.Status = INVALID; |
275 | UbxPosLlh.Status = INVALID; |
275 | UbxPosLlh.Status = INVALID; |
276 | UbxVelNed.Status = INVALID; |
276 | UbxVelNed.Status = INVALID; |
277 | UbxMsg.Status = INVALID; |
277 | UbxMsg.Status = INVALID; |
278 | GPSData.Status = INVALID; |
278 | GPSData.Status = INVALID; |
279 | 279 | ||
280 | UBX_Timeout = SetDelay(2 * UBX_Timeout); |
280 | UBX_Timeout = SetDelay(2 * UBX_Timeout); |
281 | } |
281 | } |
282 | 282 | ||
283 | /********************************************************/ |
283 | /********************************************************/ |
284 | /* Upate GPS data stcructure */ |
284 | /* Upate GPS data stcructure */ |
285 | /********************************************************/ |
285 | /********************************************************/ |
286 | void Update_GPSData(void) |
286 | void Update_GPSData(void) |
287 | { |
287 | { |
288 | static u32 last_itow = 0; |
288 | static u32 last_itow = 0; |
289 | static u32 milliseconds = 0; |
289 | static u32 milliseconds = 0; |
290 | 290 | ||
291 | // if a new set of ubx messages was collected |
291 | // if a new set of ubx messages was collected |
292 | if((UbxSol.Status == NEWDATA) && (UbxPosLlh.Status == NEWDATA) && (UbxVelNed.Status == NEWDATA)) |
292 | if((UbxSol.Status == NEWDATA) && (UbxPosLlh.Status == NEWDATA) && (UbxVelNed.Status == NEWDATA)) |
293 | { // and the itow is equal (same time base) |
293 | { // and the itow is equal (same time base) |
294 | UART_VersionInfo.Flags |= NC_VERSION_FLAG_GPS_PRESENT; |
294 | UART_VersionInfo.Flags |= NC_VERSION_FLAG_GPS_PRESENT; |
295 | if((UbxSol.itow == UbxPosLlh.itow) && (UbxPosLlh.itow == UbxVelNed.itow)) |
295 | if((UbxSol.itow == UbxPosLlh.itow) && (UbxPosLlh.itow == UbxVelNed.itow)) |
296 | { |
296 | { |
297 | UBX_Timeout = SetDelay(UBX_TIMEOUT); |
297 | UBX_Timeout = SetDelay(UBX_TIMEOUT); |
298 | DebugOut.Analog[9]++; |
298 | DebugOut.Analog[9]++; |
299 | // update GPS data only if the status is INVALID or PROCESSED |
299 | // update GPS data only if the status is INVALID or PROCESSED |
300 | if(GPSData.Status != NEWDATA) |
300 | if(GPSData.Status != NEWDATA) |
301 | { // wait for new data at all neccesary ubx messages |
301 | { // wait for new data at all neccesary ubx messages |
302 | CountNewGpsDataIn5Sec++; |
302 | CountNewGpsDataIn5Sec++; |
303 | GPSData.Status = INVALID; |
303 | GPSData.Status = INVALID; |
304 | // update message cycle time |
304 | // update message cycle time |
305 | GPSData.MsgCycleTime = (u16)(UbxSol.itow-last_itow); |
305 | GPSData.MsgCycleTime = (u16)(UbxSol.itow-last_itow); |
306 | milliseconds += GPSData.MsgCycleTime; |
306 | milliseconds += GPSData.MsgCycleTime; |
307 | last_itow = UbxSol.itow; // update last itow |
307 | last_itow = UbxSol.itow; // update last itow |
308 | // NAV SOL |
308 | // NAV SOL |
309 | GPSData.Flags = (GPSData.Flags & 0xf0) | (UbxSol.Flags & 0x0f); // we take only the lower bits |
309 | GPSData.Flags = (GPSData.Flags & 0xf0) | (UbxSol.Flags & 0x0f); // we take only the lower bits |
310 | GPSData.NumOfSats = UbxSol.numSV; |
310 | GPSData.NumOfSats = UbxSol.numSV; |
311 | GPSData.SatFix = UbxSol.GPSfix; |
311 | GPSData.SatFix = UbxSol.GPSfix; |
312 | //if(Parameter.User3 > 100) { GPSData.NumOfSats = 0; GPSData.SatFix = 0;} |
312 | //if(Parameter.User3 > 100) { GPSData.NumOfSats = 0; GPSData.SatFix = 0;} |
313 | //if(Parameter.User3 > 100) { GPSData.SatFix = 0;} |
313 | //if(Parameter.User3 > 100) { GPSData.SatFix = 0;} |
314 | //DebugOut.Analog[] = UbxPosLlh.Hacc; |
314 | //DebugOut.Analog[] = UbxPosLlh.Hacc; |
315 | //DebugOut.Analog[] = UbxPosLlh.Vacc; |
315 | //DebugOut.Analog[] = UbxPosLlh.Vacc; |
316 | GPSData.Position_Accuracy = UbxSol.PAcc; // in steps of 1cm |
316 | GPSData.Position_Accuracy = UbxSol.PAcc; // in steps of 1cm |
317 | GPSData.Speed_Accuracy = UbxSol.SAcc; // in steps of 1cm/s |
317 | GPSData.Speed_Accuracy = UbxSol.SAcc; // in steps of 1cm/s |
318 | SetGPSTime(&SystemTime); // update system time |
318 | SetGPSTime(&SystemTime); // update system time |
319 | // NAV VELNED |
319 | // NAV VELNED |
320 | GPSData.Speed_East = UbxVelNed.VEL_E; // in steps of 1cm/s |
320 | GPSData.Speed_East = UbxVelNed.VEL_E; // in steps of 1cm/s |
321 | GPSData.Speed_North = UbxVelNed.VEL_N; // in steps of 1cm/s |
321 | GPSData.Speed_North = UbxVelNed.VEL_N; // in steps of 1cm/s |
322 | GPSData.Speed_Top = -UbxVelNed.VEL_D; // in steps of 1cm/s |
322 | GPSData.Speed_Top = -UbxVelNed.VEL_D; // in steps of 1cm/s |
323 | GPSData.Speed_Ground = UbxVelNed.GSpeed; // in steps of 1cm/s |
323 | GPSData.Speed_Ground = UbxVelNed.GSpeed; // in steps of 1cm/s |
324 | GPSData.Heading = UbxVelNed.Heading; //in steps of 1E-5 deg |
324 | GPSData.Heading = UbxVelNed.Heading; //in steps of 1E-5 deg |
325 | // NAV POSLLH |
325 | // NAV POSLLH |
326 | GPSData.Position.Status = INVALID; |
326 | GPSData.Position.Status = INVALID; |
327 | if(!(SimulationFlags & SIMULATION_ACTIVE)) |
327 | if(!(SimulationFlags & SIMULATION_ACTIVE)) |
328 | { |
328 | { |
329 | GPSData.Position.Longitude = UbxPosLlh.LON; // in steps of 1E-7 deg |
329 | GPSData.Position.Longitude = UbxPosLlh.LON; // in steps of 1E-7 deg |
330 | GPSData.Position.Latitude = UbxPosLlh.LAT; // in steps of 1E-7 deg |
330 | GPSData.Position.Latitude = UbxPosLlh.LAT; // in steps of 1E-7 deg |
331 | GPSData.Position.Altitude = UbxPosLlh.HMSL; // in steps of 1 mm |
331 | GPSData.Position.Altitude = UbxPosLlh.HMSL; // in steps of 1 mm |
332 | } |
332 | } |
333 | else // simulation active |
333 | else // simulation active |
334 | { |
334 | { |
335 | if(GPSData.SatFix != SATFIX_3D || GPSData.NumOfSats < 6) // simulate satfix |
335 | if(GPSData.SatFix != SATFIX_3D || GPSData.NumOfSats < 6) // simulate satfix |
336 | { |
336 | { |
337 | GPSData.SatFix = SATFIX_3D; // Simulation |
337 | GPSData.SatFix = SATFIX_3D; // Simulation |
338 | GPSData.Flags |= FLAG_GPSFIXOK; // Simulation |
338 | GPSData.Flags |= FLAG_GPSFIXOK; // Simulation |
339 | GPSData.NumOfSats = 8; // Simulation |
339 | GPSData.NumOfSats = 8; // Simulation |
340 | if(!SystemTime.Valid) |
340 | if(!SystemTime.Valid) |
341 | { |
341 | { |
342 | UbxSol.Status = 1; |
342 | UbxSol.Status = 1; |
343 | UbxSol.Flags |= FLAG_WKNSET; |
343 | UbxSol.Flags |= FLAG_WKNSET; |
344 | UbxSol.Flags |= FLAG_TOWSET; |
344 | UbxSol.Flags |= FLAG_TOWSET; |
345 | UbxSol.week = 1043; // starts in year 2000 |
345 | UbxSol.week = 1043; // starts in year 2000 |
346 | UbxSol.itow = milliseconds; |
346 | UbxSol.itow = milliseconds; |
347 | SetGPSTime(&SystemTime); // update system time |
347 | SetGPSTime(&SystemTime); // update system time |
348 | SystemTime.Valid = 1; // use the time that is given by the GPS-Module |
348 | SystemTime.Valid = 1; // use the time that is given by the GPS-Module |
349 | } |
349 | } |
350 | } |
350 | } |
351 | } |
351 | } |
352 | GPSData.Position.Status = NEWDATA; |
352 | GPSData.Position.Status = NEWDATA; |
353 | 353 | ||
354 | GPSData.Status = NEWDATA; // new data available |
354 | GPSData.Status = NEWDATA; // new data available |
355 | } // EOF if(GPSData.Status != NEWDATA) |
355 | } // EOF if(GPSData.Status != NEWDATA) |
356 | // set state to collect new data |
356 | // set state to collect new data |
357 | UbxSol.Status = PROCESSED; // ready for new data |
357 | UbxSol.Status = PROCESSED; // ready for new data |
358 | UbxPosLlh.Status = PROCESSED; // ready for new data |
358 | UbxPosLlh.Status = PROCESSED; // ready for new data |
359 | UbxVelNed.Status = PROCESSED; // ready for new data |
359 | UbxVelNed.Status = PROCESSED; // ready for new data |
360 | } // EOF all itow are equal |
360 | } // EOF all itow are equal |
361 | } // EOF all ubx messages received |
361 | } // EOF all ubx messages received |
362 | 362 | ||
363 | 363 | ||
364 | //++++++++++++++++++++++++++++++++ |
364 | //++++++++++++++++++++++++++++++++ |
365 | // Please do not delete |
365 | // Please do not delete |
366 | // This helps me for testing |
366 | // This helps me for testing |
367 | //++++++++++++++++++++++++++++++++ |
367 | //++++++++++++++++++++++++++++++++ |
368 | //GPSData.Position.Longitude = 1517409123L; // Hamilton, Australia |
368 | //GPSData.Position.Longitude = 1517409123L; // Hamilton, Australia |
369 | //GPSData.Position.Latitude = -329294773L; // Hamilton, Australia |
369 | //GPSData.Position.Latitude = -329294773L; // Hamilton, Australia |
370 | //++++++++ |
370 | //++++++++ |
371 | //GPSData.Position.Longitude =-1556010020L; // Alaska |
371 | //GPSData.Position.Longitude =-1556010020L; // Alaska |
372 | //GPSData.Position.Latitude = 629581270L; // Alaska |
372 | //GPSData.Position.Latitude = 629581270L; // Alaska |
373 | //++++++++ |
373 | //++++++++ |
374 | //GPSData.Position.Longitude =-584343419L; // Buenos aires |
374 | //GPSData.Position.Longitude =-584343419L; // Buenos aires |
375 | //GPSData.Position.Latitude = -345464421L; // Buenos aires |
375 | //GPSData.Position.Latitude = -345464421L; // Buenos aires |
376 | //++++++++ |
376 | //++++++++ |
377 | //GPSData.Position.Longitude =1683362691L; // Neuseeland |
377 | //GPSData.Position.Longitude =1683362691L; // Neuseeland |
378 | //GPSData.Position.Latitude = -465945926L; // Neuseeland |
378 | //GPSData.Position.Latitude = -465945926L; // Neuseeland |
379 | //++++++++ |
379 | //++++++++ |
380 | //GPSData.Position.Longitude = 194140605L; // Afrika |
380 | //GPSData.Position.Longitude = 194140605L; // Afrika |
381 | //GPSData.Position.Latitude = -345384656L; // Afrika |
381 | //GPSData.Position.Latitude = -345384656L; // Afrika |
382 | //++++++++ |
382 | //++++++++ |
383 | //GPSData.Position.Longitude =-740443840L; // Liberty Staue davor |
383 | //GPSData.Position.Longitude =-740443840L; // Liberty Staue davor |
384 | //GPSData.Position.Latitude = 406888880L; // Liberty Staue |
384 | //GPSData.Position.Latitude = 406888880L; // Liberty Staue |
385 | 385 | ||
386 | //GPSData.Position.Longitude =-740451660L; // Liberty Staue daneben |
386 | //GPSData.Position.Longitude =-740451660L; // Liberty Staue daneben |
387 | //GPSData.Position.Latitude = 406891880L; // Liberty Staue |
387 | //GPSData.Position.Latitude = 406891880L; // Liberty Staue |
388 | 388 | ||
389 | //GPSData.Position.Longitude =-740446540L; // Liberty Staue direkt |
389 | //GPSData.Position.Longitude =-740446540L; // Liberty Staue direkt |
390 | //GPSData.Position.Latitude = 406891590L; // Liberty Staue 1 |
390 | //GPSData.Position.Latitude = 406891590L; // Liberty Staue 1 |
391 | 391 | ||
392 | //GPSData.Position.Longitude =-1142878694L; // Flori |
392 | //GPSData.Position.Longitude =-1142878694L; // Flori |
393 | //GPSData.Position.Latitude = 483712102L; // |
393 | //GPSData.Position.Latitude = 483712102L; // |
394 | 394 | ||
395 | //GPSData.Position.Longitude =1251674613L; // Bubble |
395 | //GPSData.Position.Longitude =1251674613L; // Bubble |
396 | //GPSData.Position.Latitude = 466058365L; // |
396 | //GPSData.Position.Latitude = 466058365L; // |
397 | 397 | ||
398 | } |
398 | } |
399 | 399 | ||
400 | u8 UbxVersionParser(void) |
400 | u8 UbxVersionParser(void) |
401 | { |
401 | { |
402 | // HW:00000040: Antaris |
402 | // HW:00000040: Antaris |
403 | // HW:00040001: Antaris-4 |
403 | // HW:00040001: Antaris-4 |
404 | // HW:80040001: Antaris-4 |
404 | // HW:80040001: Antaris-4 |
405 | // HW:00040005: u-blox 5 |
405 | // HW:00040005: u-blox 5 |
406 | // HW:00040006: u-blox 6 |
406 | // HW:00040006: u-blox 6 |
407 | // HW:00040007: u-blox 6 |
407 | // HW:00040007: u-blox 6 |
408 | // HW:00070000: u-blox 7 |
408 | // HW:00070000: u-blox 7 |
409 | // HW:00080000: u-blox M8 |
409 | // HW:00080000: u-blox M8 |
410 | // MKGPS V1 -> 1500 -> LEA-4H-0-000 -> ubxsw == 5.00 HW:00040001 |
410 | // MKGPS V1 -> 1500 -> LEA-4H-0-000 -> ubxsw == 5.00 HW:00040001 |
411 | // MKGPS V2 -> 2602 -> LEA-6S-0-000 -> ubxsw == 6.02 HW:00040007 |
411 | // MKGPS V2 -> 2602 -> LEA-6S-0-000 -> ubxsw == 6.02 HW:00040007 |
412 | // MKGPS V2 -> 2703 -> LEA-6S-0-001 -> ubxsw == 7.03 HW:00040007 |
412 | // MKGPS V2 -> 2703 -> LEA-6S-0-001 -> ubxsw == 7.03 HW:00040007 |
413 | // MKGPS V3 -> 3201 -> NEO-M8Q-0-00 -> ubxsw == 2.01 HW:00080000 (Flash-oder ROM Variante) |
413 | // MKGPS V3 -> 3201 -> NEO-M8Q-0-00 -> ubxsw == 2.01 HW:00080000 (Flash-oder ROM Variante) |
414 | 414 | ||
415 | u8 retval = 0xFF; |
415 | u8 retval = 0xFF; |
416 | if(UbxMsg.Data[33] == '4' && UbxMsg.Data[37] == '1') // LEA-4 |
416 | if(UbxMsg.Data[33] == '4' && UbxMsg.Data[37] == '1') // LEA-4 |
417 | { |
417 | { |
418 | GPS_Version = 1000 + (UbxMsg.Data[0] - '0') * 100 + (UbxMsg.Data[2] - '0') * 10 + (UbxMsg.Data[3] - '0'); |
418 | GPS_Version = 1000 + (UbxMsg.Data[0] - '0') * 100 + (UbxMsg.Data[2] - '0') * 10 + (UbxMsg.Data[3] - '0'); |
419 | retval = 10; // MKGPS V1 |
419 | retval = 10; // MKGPS V1 |
420 | } |
420 | } |
421 | else |
421 | else |
422 | if(UbxMsg.Data[33] == '4' && UbxMsg.Data[37] == '7') // LEA-6 |
422 | if(UbxMsg.Data[33] == '4' && UbxMsg.Data[37] == '7') // LEA-6 |
423 | { |
423 | { |
424 | GPS_Version = 2000 + (UbxMsg.Data[0] - '0') * 100 + (UbxMsg.Data[2] - '0') * 10 + (UbxMsg.Data[3] - '0'); |
424 | GPS_Version = 2000 + (UbxMsg.Data[0] - '0') * 100 + (UbxMsg.Data[2] - '0') * 10 + (UbxMsg.Data[3] - '0'); |
425 | retval = 20; // MKGPS V2 |
425 | retval = 20; // MKGPS V2 |
426 | } |
426 | } |
427 | else |
427 | else |
428 | if(UbxMsg.Data[33] == '8' && UbxMsg.Data[37] == '0') // NEO-8 |
428 | if(UbxMsg.Data[33] == '8' && UbxMsg.Data[37] == '0') // NEO-8 |
429 | { |
429 | { |
430 | GPS_Version = 3000 + (UbxMsg.Data[0] - '0') * 100 + (UbxMsg.Data[2] - '0') * 10 + (UbxMsg.Data[3] - '0'); |
430 | GPS_Version = 3000 + (UbxMsg.Data[0] - '0') * 100 + (UbxMsg.Data[2] - '0') * 10 + (UbxMsg.Data[3] - '0'); |
431 | retval = 30; // MKGPS V3 |
431 | retval = 30; // MKGPS V3 |
432 | } |
432 | } |
433 | return(retval); |
433 | return(retval); |
434 | } |
434 | } |
435 | 435 | ||
436 | /********************************************************/ |
436 | /********************************************************/ |
437 | /* UBX Parser */ |
437 | /* UBX Parser */ |
438 | /********************************************************/ |
438 | /********************************************************/ |
439 | void UBX_RxParser(u8 c) |
439 | void UBX_RxParser(u8 c) |
440 | { |
440 | { |
441 | static ubxState_t ubxState = UBXSTATE_IDLE; |
441 | static ubxState_t ubxState = UBXSTATE_IDLE; |
442 | static ubxmsghdr_t RxHdr; |
442 | static ubxmsghdr_t RxHdr; |
443 | static u8 RxData[UBX_MSG_DATA_SIZE]; |
443 | static u8 RxData[UBX_MSG_DATA_SIZE]; |
444 | static u16 RxBytes = 0; |
444 | static u16 RxBytes = 0; |
445 | static u8 cka, ckb; |
445 | static u8 cka, ckb; |
446 | 446 | ||
447 | 447 | ||
448 | //state machine |
448 | //state machine |
449 | switch (ubxState) // ubx message parser |
449 | switch (ubxState) // ubx message parser |
450 | { |
450 | { |
451 | case UBXSTATE_IDLE: // check 1st sync byte |
451 | case UBXSTATE_IDLE: // check 1st sync byte |
452 | if (c == UBX_SYNC1_CHAR) ubxState = UBXSTATE_SYNC1; |
452 | if (c == UBX_SYNC1_CHAR) ubxState = UBXSTATE_SYNC1; |
453 | else ubxState = UBXSTATE_IDLE; // out of synchronization |
453 | else ubxState = UBXSTATE_IDLE; // out of synchronization |
454 | break; |
454 | break; |
455 | 455 | ||
456 | case UBXSTATE_SYNC1: // check 2nd sync byte |
456 | case UBXSTATE_SYNC1: // check 2nd sync byte |
457 | if (c == UBX_SYNC2_CHAR) ubxState = UBXSTATE_SYNC2; |
457 | if (c == UBX_SYNC2_CHAR) ubxState = UBXSTATE_SYNC2; |
458 | else ubxState = UBXSTATE_IDLE; // out of synchronization |
458 | else ubxState = UBXSTATE_IDLE; // out of synchronization |
459 | break; |
459 | break; |
460 | 460 | ||
461 | case UBXSTATE_SYNC2: // check msg class to be NAV |
461 | case UBXSTATE_SYNC2: // check msg class to be NAV |
462 | RxHdr.Class = c; |
462 | RxHdr.Class = c; |
463 | ubxState = UBXSTATE_CLASS; |
463 | ubxState = UBXSTATE_CLASS; |
464 | break; |
464 | break; |
465 | 465 | ||
466 | case UBXSTATE_CLASS: // check message identifier |
466 | case UBXSTATE_CLASS: // check message identifier |
467 | RxHdr.Id = c; |
467 | RxHdr.Id = c; |
468 | ubxState = UBXSTATE_LEN1; |
468 | ubxState = UBXSTATE_LEN1; |
469 | cka = RxHdr.Class + RxHdr.Id; |
469 | cka = RxHdr.Class + RxHdr.Id; |
470 | ckb = RxHdr.Class + cka; |
470 | ckb = RxHdr.Class + cka; |
471 | break; |
471 | break; |
472 | 472 | ||
473 | case UBXSTATE_LEN1: // 1st message length byte |
473 | case UBXSTATE_LEN1: // 1st message length byte |
474 | RxHdr.Length = (u16)c; // lowbyte first |
474 | RxHdr.Length = (u16)c; // lowbyte first |
475 | cka += c; |
475 | cka += c; |
476 | ckb += cka; |
476 | ckb += cka; |
477 | ubxState = UBXSTATE_LEN2; |
477 | ubxState = UBXSTATE_LEN2; |
478 | break; |
478 | break; |
479 | 479 | ||
480 | case UBXSTATE_LEN2: // 2nd message length byte |
480 | case UBXSTATE_LEN2: // 2nd message length byte |
481 | RxHdr.Length += ((u16)c)<<8; // high byte last |
481 | RxHdr.Length += ((u16)c)<<8; // high byte last |
482 | if (RxHdr.Length >= UBX_MSG_DATA_SIZE) |
482 | if (RxHdr.Length >= UBX_MSG_DATA_SIZE) |
483 | { |
483 | { |
484 | ubxState = UBXSTATE_IDLE; |
484 | ubxState = UBXSTATE_IDLE; |
485 | } |
485 | } |
486 | else |
486 | else |
487 | { |
487 | { |
488 | cka += c; |
488 | cka += c; |
489 | ckb += cka; |
489 | ckb += cka; |
490 | RxBytes = 0; // reset data byte counter |
490 | RxBytes = 0; // reset data byte counter |
491 | ubxState = UBXSTATE_DATA; |
491 | ubxState = UBXSTATE_DATA; |
492 | } |
492 | } |
493 | break; |
493 | break; |
494 | 494 | ||
495 | case UBXSTATE_DATA: // collecting data |
495 | case UBXSTATE_DATA: // collecting data |
496 | if (RxBytes < UBX_MSG_DATA_SIZE) |
496 | if (RxBytes < UBX_MSG_DATA_SIZE) |
497 | { |
497 | { |
498 | RxData[RxBytes++] = c; // copy curent data byte if any space is left |
498 | RxData[RxBytes++] = c; // copy curent data byte if any space is left |
499 | cka += c; |
499 | cka += c; |
500 | ckb += cka; |
500 | ckb += cka; |
501 | if (RxBytes >= RxHdr.Length) ubxState = UBXSTATE_CKA; // switch to next state if all data have been received |
501 | if (RxBytes >= RxHdr.Length) ubxState = UBXSTATE_CKA; // switch to next state if all data have been received |
502 | } |
502 | } |
503 | else // rx buffer overrun |
503 | else // rx buffer overrun |
504 | { |
504 | { |
505 | ubxState = UBXSTATE_IDLE; |
505 | ubxState = UBXSTATE_IDLE; |
506 | } |
506 | } |
507 | break; |
507 | break; |
508 | 508 | ||
509 | case UBXSTATE_CKA: |
509 | case UBXSTATE_CKA: |
510 | if (c == cka) ubxState = UBXSTATE_CKB; |
510 | if (c == cka) ubxState = UBXSTATE_CKB; |
511 | else |
511 | else |
512 | { |
512 | { |
513 | ubxState = UBXSTATE_IDLE; |
513 | ubxState = UBXSTATE_IDLE; |
514 | } |
514 | } |
515 | break; |
515 | break; |
516 | 516 | ||
517 | case UBXSTATE_CKB: |
517 | case UBXSTATE_CKB: |
518 | if (c == ckb) |
518 | if (c == ckb) |
519 | { // checksum is ok |
519 | { // checksum is ok |
520 | 520 | ||
521 | switch(RxHdr.Class) |
521 | switch(RxHdr.Class) |
522 | { |
522 | { |
523 | case UBX_CLASS_NAV: |
523 | case UBX_CLASS_NAV: |
524 | switch(RxHdr.Id) |
524 | switch(RxHdr.Id) |
525 | { |
525 | { |
526 | case UBX_ID_POSLLH: // geodetic position |
526 | case UBX_ID_POSLLH: // geodetic position |
527 | memcpy((u8*)&UbxPosLlh, RxData, RxHdr.Length); |
527 | memcpy((u8*)&UbxPosLlh, RxData, RxHdr.Length); |
528 | UbxPosLlh.Status = NEWDATA; |
528 | UbxPosLlh.Status = NEWDATA; |
529 | break; |
529 | break; |
530 | 530 | ||
531 | case UBX_ID_VELNED: // velocity vector in tangent plane |
531 | case UBX_ID_VELNED: // velocity vector in tangent plane |
532 | memcpy((u8*)&UbxVelNed, RxData, RxHdr.Length); |
532 | memcpy((u8*)&UbxVelNed, RxData, RxHdr.Length); |
533 | UbxVelNed.Status = NEWDATA; |
533 | UbxVelNed.Status = NEWDATA; |
534 | break; |
534 | break; |
535 | 535 | ||
536 | case UBX_ID_SOL: // navigation solution |
536 | case UBX_ID_SOL: // navigation solution |
537 | memcpy((u8*)&UbxSol, RxData, RxHdr.Length); |
537 | memcpy((u8*)&UbxSol, RxData, RxHdr.Length); |
538 | UbxSol.Status = NEWDATA; |
538 | UbxSol.Status = NEWDATA; |
539 | break; |
539 | break; |
540 | 540 | ||
541 | default: |
541 | default: |
542 | break; |
542 | break; |
543 | } // EOF switch(Id) |
543 | } // EOF switch(Id) |
544 | Update_GPSData(); |
544 | Update_GPSData(); |
545 | break; |
545 | break; |
546 | case UBX_CLASS_MON: // version |
546 | case UBX_CLASS_MON: // version |
547 | switch(RxHdr.Id) |
547 | switch(RxHdr.Id) |
548 | { |
548 | { |
549 | case UBX_ID_MON_VER: |
549 | case UBX_ID_MON_VER: |
550 | if(UbxMsg.Hdr.Length <= UBX_MSG_DATA_SIZE) memcpy(UbxMsg.Data, RxData, RxHdr.Length); |
550 | if(UbxMsg.Hdr.Length <= UBX_MSG_DATA_SIZE) memcpy(UbxMsg.Data, RxData, RxHdr.Length); |
551 | UbxVersionParser(); |
551 | UbxVersionParser(); |
552 | break; |
552 | break; |
553 | 553 | ||
554 | default: |
554 | default: |
555 | break; |
555 | break; |
556 | } |
556 | } |
557 | default: |
557 | default: |
558 | break; |
558 | break; |
559 | } // EOF switch(class) |
559 | } // EOF switch(class) |
560 | 560 | ||
561 | // check generic msg filter |
561 | // check generic msg filter |
562 | if(UbxMsg.Status != NEWDATA) |
562 | if(UbxMsg.Status != NEWDATA) |
563 | { // msg buffer is free |
563 | { // msg buffer is free |
564 | if(((UbxMsg.Hdr.Class&UbxMsg.ClassMask) == (RxHdr.Class&UbxMsg.ClassMask)) && ((UbxMsg.Hdr.Id&UbxMsg.IdMask) == (RxHdr.Id&UbxMsg.IdMask))) |
564 | if(((UbxMsg.Hdr.Class&UbxMsg.ClassMask) == (RxHdr.Class&UbxMsg.ClassMask)) && ((UbxMsg.Hdr.Id&UbxMsg.IdMask) == (RxHdr.Id&UbxMsg.IdMask))) |
565 | { // msg matches to the filter criteria |
565 | { // msg matches to the filter criteria |
566 | UbxMsg.Status = INVALID; |
566 | UbxMsg.Status = INVALID; |
567 | UbxMsg.Hdr.Class = RxHdr.Class; |
567 | UbxMsg.Hdr.Class = RxHdr.Class; |
568 | UbxMsg.Hdr.Id = RxHdr.Id; |
568 | UbxMsg.Hdr.Id = RxHdr.Id; |
569 | UbxMsg.Hdr.Length = RxHdr.Length; |
569 | UbxMsg.Hdr.Length = RxHdr.Length; |
570 | if(UbxMsg.Hdr.Length <= UBX_MSG_DATA_SIZE) |
570 | if(UbxMsg.Hdr.Length <= UBX_MSG_DATA_SIZE) |
571 | { // copy data block |
571 | { // copy data block |
572 | memcpy(UbxMsg.Data, RxData, RxHdr.Length); |
572 | memcpy(UbxMsg.Data, RxData, RxHdr.Length); |
573 | UbxMsg.Status = NEWDATA; |
573 | UbxMsg.Status = NEWDATA; |
574 | } |
574 | } |
575 | } // EOF filter matches |
575 | } // EOF filter matches |
576 | } // EOF != INVALID |
576 | } // EOF != INVALID |
577 | }// EOF crc ok |
577 | }// EOF crc ok |
578 | else DebugOut.Analog[13]++; // CRC Error -> since 2.10e (6.2015) |
578 | // else DebugOut.Analog[13]++; // CRC Error -> since 2.10e (6.2015) -> removed 11.2016 (V2.16) |
579 | ubxState = UBXSTATE_IDLE; // ready to parse new data |
579 | ubxState = UBXSTATE_IDLE; // ready to parse new data |
580 | break; |
580 | break; |
581 | 581 | ||
582 | default: // unknown ubx state |
582 | default: // unknown ubx state |
583 | ubxState = UBXSTATE_IDLE; |
583 | ubxState = UBXSTATE_IDLE; |
584 | break; |
584 | break; |
585 | 585 | ||
586 | } |
586 | } |
587 | } |
587 | } |
588 | 588 | ||
589 | u8 UBX_CreateMsg(Buffer_t* pBuff, u8* pData, u16 Len) |
589 | u8 UBX_CreateMsg(Buffer_t* pBuff, u8* pData, u16 Len) |
590 | { |
590 | { |
591 | u16 i; |
591 | u16 i; |
592 | u8 cka = 0, ckb = 0; |
592 | u8 cka = 0, ckb = 0; |
593 | // check if buffer is available |
593 | // check if buffer is available |
594 | if(pBuff->Locked == TRUE) return(0); |
594 | if(pBuff->Locked == TRUE) return(0); |
595 | // check if buffer size is sufficient |
595 | // check if buffer size is sufficient |
596 | if(pBuff->Size < 8 + Len) return(0); |
596 | if(pBuff->Size < 8 + Len) return(0); |
597 | // lock the buffer |
597 | // lock the buffer |
598 | pBuff->Locked = TRUE; |
598 | pBuff->Locked = TRUE; |
599 | // start at begin |
599 | // start at begin |
600 | pBuff->Position = 0; |
600 | pBuff->Position = 0; |
601 | pBuff->pData[pBuff->Position++] = UBX_SYNC1_CHAR; |
601 | pBuff->pData[pBuff->Position++] = UBX_SYNC1_CHAR; |
602 | pBuff->pData[pBuff->Position++] = UBX_SYNC2_CHAR; |
602 | pBuff->pData[pBuff->Position++] = UBX_SYNC2_CHAR; |
603 | for(i=0;i<Len;i++) |
603 | for(i=0;i<Len;i++) |
604 | { |
604 | { |
605 | pBuff->pData[pBuff->Position++] = pData[i]; |
605 | pBuff->pData[pBuff->Position++] = pData[i]; |
606 | } |
606 | } |
607 | // calculate checksum |
607 | // calculate checksum |
608 | for(i=2;i<pBuff->Position;i++) |
608 | for(i=2;i<pBuff->Position;i++) |
609 | { |
609 | { |
610 | cka += pBuff->pData[i]; |
610 | cka += pBuff->pData[i]; |
611 | ckb += cka; |
611 | ckb += cka; |
612 | } |
612 | } |
613 | pBuff->pData[pBuff->Position++] = cka; |
613 | pBuff->pData[pBuff->Position++] = cka; |
614 | pBuff->pData[pBuff->Position++] = ckb; |
614 | pBuff->pData[pBuff->Position++] = ckb; |
615 | pBuff->DataBytes = pBuff->Position; |
615 | pBuff->DataBytes = pBuff->Position; |
616 | pBuff->Position = 0; // reset buffer position for transmision |
616 | pBuff->Position = 0; // reset buffer position for transmision |
617 | return(1); |
617 | return(1); |
618 | } |
618 | } |
619 | /* |
619 | /* |
620 | switch(ubxclass) |
620 | switch(ubxclass) |
621 | { |
621 | { |
622 | case UBX_CLASS_NAV: |
622 | case UBX_CLASS_NAV: |
623 | switch(ubxid) |
623 | switch(ubxid) |
624 | { |
624 | { |
625 | case UBX_ID_POSLLH: // geodetic position |
625 | case UBX_ID_POSLLH: // geodetic position |
626 | ubxSp = (u8 *)&UbxPosLlh; // data start pointer |
626 | ubxSp = (u8 *)&UbxPosLlh; // data start pointer |
627 | ubxEp = (u8 *)(&UbxPosLlh + 1); // data end pointer |
627 | ubxEp = (u8 *)(&UbxPosLlh + 1); // data end pointer |
628 | ubxStP = (u8 *)&UbxPosLlh.Status; // status pointer |
628 | ubxStP = (u8 *)&UbxPosLlh.Status; // status pointer |
629 | break; |
629 | break; |
630 | 630 | ||
631 | case UBX_ID_SOL: // navigation solution |
631 | case UBX_ID_SOL: // navigation solution |
632 | ubxSp = (u8 *)&UbxSol; // data start pointer |
632 | ubxSp = (u8 *)&UbxSol; // data start pointer |
633 | ubxEp = (u8 *)(&UbxSol + 1); // data end pointer |
633 | ubxEp = (u8 *)(&UbxSol + 1); // data end pointer |
634 | ubxStP = (u8 *)&UbxSol.Status; // status pointer |
634 | ubxStP = (u8 *)&UbxSol.Status; // status pointer |
635 | break; |
635 | break; |
636 | 636 | ||
637 | case UBX_ID_VELNED: // velocity vector in tangent plane |
637 | case UBX_ID_VELNED: // velocity vector in tangent plane |
638 | ubxSp = (u8 *)&UbxVelNed; // data start pointer |
638 | ubxSp = (u8 *)&UbxVelNed; // data start pointer |
639 | ubxEp = (u8 *)(&UbxVelNed + 1); // data end pointer |
639 | ubxEp = (u8 *)(&UbxVelNed + 1); // data end pointer |
640 | ubxStP = (u8 *)&UbxVelNed.Status; // status pointer |
640 | ubxStP = (u8 *)&UbxVelNed.Status; // status pointer |
641 | break; |
641 | break; |
642 | 642 | ||
643 | default: // unsupported identifier |
643 | default: // unsupported identifier |
644 | ubxState = UBXSTATE_IDLE; |
644 | ubxState = UBXSTATE_IDLE; |
645 | return; |
645 | return; |
646 | } |
646 | } |
647 | break; |
647 | break; |
648 | 648 | ||
649 | default: // other classes |
649 | default: // other classes |
650 | if(UbxMsg.Status == NEWDATA) ubxState = UBXSTATE_IDLE; |
650 | if(UbxMsg.Status == NEWDATA) ubxState = UBXSTATE_IDLE; |
651 | else if(((UbxMsg.Hdr.Class&UbxMsg.ClassMask) == (ubxclass&UbxMsg.ClassMask)) && ((UbxMsg.Hdr.Id&UbxMsg.IdMask) == (ubxid&UbxMsg.IdMask))) |
651 | else if(((UbxMsg.Hdr.Class&UbxMsg.ClassMask) == (ubxclass&UbxMsg.ClassMask)) && ((UbxMsg.Hdr.Id&UbxMsg.IdMask) == (ubxid&UbxMsg.IdMask))) |
652 | { // buffer is free and message matches to filter criteria |
652 | { // buffer is free and message matches to filter criteria |
653 | UbxMsg.Status = INVALID; |
653 | UbxMsg.Status = INVALID; |
654 | UbxMsg.Hdr.Class = ubxclass; |
654 | UbxMsg.Hdr.Class = ubxclass; |
655 | UbxMsg.Hdr.Id = ubxid; |
655 | UbxMsg.Hdr.Id = ubxid; |
656 | UbxMsg.Hdr.Length = msglen; |
656 | UbxMsg.Hdr.Length = msglen; |
657 | ubxSp = (u8 *)&(UbxMsg.Data); // data start pointer |
657 | ubxSp = (u8 *)&(UbxMsg.Data); // data start pointer |
658 | ubxEp = (u8 *)(&UbxMsg + 1); // data end pointer |
658 | ubxEp = (u8 *)(&UbxMsg + 1); // data end pointer |
659 | ubxStP = (u8 *)&UbxMsg.Status; // status pointer |
659 | ubxStP = (u8 *)&UbxMsg.Status; // status pointer |
660 | } |
660 | } |
661 | else ubxState = UBXSTATE_IDLE; |
661 | else ubxState = UBXSTATE_IDLE; |
662 | break; |
662 | break; |
663 | } |
663 | } |
664 | */ |
664 | */ |
665 | 665 | ||
666 | 666 |