Eigen
Dependencies: Vector3
Dependents: optWingforHAPS_Eigen hexaTest_Eigen
GPSUBX_UART.hpp@1:71f5168e48c8, 2021-09-17 (annotated)
- Committer:
- cocorlow
- Date:
- Fri Sep 17 15:06:47 2021 +0000
- Revision:
- 1:71f5168e48c8
- Parent:
- 0:cf7c726ec8a1
- Child:
- 2:6218fe8e54f4
work!
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
cocorlow | 0:cf7c726ec8a1 | 1 | #ifndef __GPSUBX_UART_HPP__ |
cocorlow | 0:cf7c726ec8a1 | 2 | #define __GPSUBX_UART_HPP__ |
cocorlow | 0:cf7c726ec8a1 | 3 | |
cocorlow | 0:cf7c726ec8a1 | 4 | #include "mbed.h" |
cocorlow | 0:cf7c726ec8a1 | 5 | #include "Vector3.hpp" |
cocorlow | 0:cf7c726ec8a1 | 6 | |
cocorlow | 0:cf7c726ec8a1 | 7 | #define POSECEF_LEN 20 |
cocorlow | 0:cf7c726ec8a1 | 8 | #define POSLLH_LEN 28 |
cocorlow | 0:cf7c726ec8a1 | 9 | #define TIMEUTC_LEN 20 |
cocorlow | 0:cf7c726ec8a1 | 10 | #define VELECEF_LEN 20 |
cocorlow | 0:cf7c726ec8a1 | 11 | #define VELNED_LEN 36 |
cocorlow | 0:cf7c726ec8a1 | 12 | |
cocorlow | 0:cf7c726ec8a1 | 13 | #define UBX_SYNC 0x62 << 8 | 0xb5 |
cocorlow | 0:cf7c726ec8a1 | 14 | |
cocorlow | 1:71f5168e48c8 | 15 | #define RECEIVE_SIZE 1024 |
cocorlow | 0:cf7c726ec8a1 | 16 | #define SENTENCE_SIZE 64 |
cocorlow | 0:cf7c726ec8a1 | 17 | |
cocorlow | 0:cf7c726ec8a1 | 18 | extern Serial pc; |
cocorlow | 0:cf7c726ec8a1 | 19 | |
cocorlow | 0:cf7c726ec8a1 | 20 | //// 0x01 0x01 |
cocorlow | 0:cf7c726ec8a1 | 21 | //union POSECEF |
cocorlow | 0:cf7c726ec8a1 | 22 | //{ |
cocorlow | 0:cf7c726ec8a1 | 23 | // char byte_data[POSECEF_LEN+8]; |
cocorlow | 0:cf7c726ec8a1 | 24 | // struct |
cocorlow | 0:cf7c726ec8a1 | 25 | // { |
cocorlow | 0:cf7c726ec8a1 | 26 | // unsigned short sync; |
cocorlow | 0:cf7c726ec8a1 | 27 | // char m_class; |
cocorlow | 0:cf7c726ec8a1 | 28 | // char m_id; |
cocorlow | 0:cf7c726ec8a1 | 29 | // unsigned short pay_len; |
cocorlow | 0:cf7c726ec8a1 | 30 | // unsigned int iTOW; |
cocorlow | 0:cf7c726ec8a1 | 31 | // int ecefX; |
cocorlow | 0:cf7c726ec8a1 | 32 | // int ecefY; |
cocorlow | 0:cf7c726ec8a1 | 33 | // int ecefZ; |
cocorlow | 0:cf7c726ec8a1 | 34 | // unsigned int pAcc; |
cocorlow | 0:cf7c726ec8a1 | 35 | // char check_a; |
cocorlow | 0:cf7c726ec8a1 | 36 | // char check_b; |
cocorlow | 0:cf7c726ec8a1 | 37 | // } data; |
cocorlow | 0:cf7c726ec8a1 | 38 | //}; |
cocorlow | 0:cf7c726ec8a1 | 39 | |
cocorlow | 0:cf7c726ec8a1 | 40 | // 0x01 0x02 |
cocorlow | 0:cf7c726ec8a1 | 41 | union POSLLH |
cocorlow | 0:cf7c726ec8a1 | 42 | { |
cocorlow | 0:cf7c726ec8a1 | 43 | char byte_data[POSLLH_LEN]; |
cocorlow | 0:cf7c726ec8a1 | 44 | struct |
cocorlow | 0:cf7c726ec8a1 | 45 | { |
cocorlow | 0:cf7c726ec8a1 | 46 | unsigned int iTOW; |
cocorlow | 0:cf7c726ec8a1 | 47 | int lon; |
cocorlow | 0:cf7c726ec8a1 | 48 | int lat; |
cocorlow | 0:cf7c726ec8a1 | 49 | int height; |
cocorlow | 0:cf7c726ec8a1 | 50 | int hMSL; |
cocorlow | 0:cf7c726ec8a1 | 51 | unsigned int hAcc; |
cocorlow | 0:cf7c726ec8a1 | 52 | unsigned int vAcc; |
cocorlow | 0:cf7c726ec8a1 | 53 | } data; |
cocorlow | 0:cf7c726ec8a1 | 54 | }; |
cocorlow | 0:cf7c726ec8a1 | 55 | |
cocorlow | 0:cf7c726ec8a1 | 56 | // 0x01 0x21 |
cocorlow | 0:cf7c726ec8a1 | 57 | union TIMEUTC |
cocorlow | 0:cf7c726ec8a1 | 58 | { |
cocorlow | 0:cf7c726ec8a1 | 59 | char byte_data[TIMEUTC_LEN]; |
cocorlow | 0:cf7c726ec8a1 | 60 | struct |
cocorlow | 0:cf7c726ec8a1 | 61 | { |
cocorlow | 0:cf7c726ec8a1 | 62 | unsigned int iTOW; |
cocorlow | 0:cf7c726ec8a1 | 63 | unsigned int tAcc; |
cocorlow | 0:cf7c726ec8a1 | 64 | int nano; |
cocorlow | 0:cf7c726ec8a1 | 65 | unsigned short year; |
cocorlow | 0:cf7c726ec8a1 | 66 | unsigned char month; |
cocorlow | 0:cf7c726ec8a1 | 67 | unsigned char day; |
cocorlow | 0:cf7c726ec8a1 | 68 | unsigned char hour; |
cocorlow | 0:cf7c726ec8a1 | 69 | unsigned char min; |
cocorlow | 0:cf7c726ec8a1 | 70 | unsigned char sec; |
cocorlow | 0:cf7c726ec8a1 | 71 | unsigned char valid; |
cocorlow | 0:cf7c726ec8a1 | 72 | } data; |
cocorlow | 0:cf7c726ec8a1 | 73 | }; |
cocorlow | 0:cf7c726ec8a1 | 74 | |
cocorlow | 0:cf7c726ec8a1 | 75 | //// 0x01 0x11 |
cocorlow | 0:cf7c726ec8a1 | 76 | //union VELECEF |
cocorlow | 0:cf7c726ec8a1 | 77 | //{ |
cocorlow | 0:cf7c726ec8a1 | 78 | // char byte_data[VELECEF_LEN]; |
cocorlow | 0:cf7c726ec8a1 | 79 | // struct |
cocorlow | 0:cf7c726ec8a1 | 80 | // { |
cocorlow | 0:cf7c726ec8a1 | 81 | // unsigned int iTOW; |
cocorlow | 0:cf7c726ec8a1 | 82 | // int ecefVX; |
cocorlow | 0:cf7c726ec8a1 | 83 | // int ecefVY; |
cocorlow | 0:cf7c726ec8a1 | 84 | // int ecefVZ; |
cocorlow | 0:cf7c726ec8a1 | 85 | // unsigned int sAcc; |
cocorlow | 0:cf7c726ec8a1 | 86 | // } data; |
cocorlow | 0:cf7c726ec8a1 | 87 | //}; |
cocorlow | 0:cf7c726ec8a1 | 88 | |
cocorlow | 0:cf7c726ec8a1 | 89 | // 0x01 0x12 |
cocorlow | 0:cf7c726ec8a1 | 90 | union VELNED |
cocorlow | 0:cf7c726ec8a1 | 91 | { |
cocorlow | 0:cf7c726ec8a1 | 92 | char byte_data[VELNED_LEN]; |
cocorlow | 0:cf7c726ec8a1 | 93 | struct |
cocorlow | 0:cf7c726ec8a1 | 94 | { |
cocorlow | 0:cf7c726ec8a1 | 95 | unsigned int iTOW; |
cocorlow | 0:cf7c726ec8a1 | 96 | int velN; |
cocorlow | 0:cf7c726ec8a1 | 97 | int velE; |
cocorlow | 0:cf7c726ec8a1 | 98 | int velD; |
cocorlow | 0:cf7c726ec8a1 | 99 | unsigned int speed; |
cocorlow | 0:cf7c726ec8a1 | 100 | unsigned int gSpeed; |
cocorlow | 0:cf7c726ec8a1 | 101 | signed int heading; |
cocorlow | 0:cf7c726ec8a1 | 102 | unsigned int sAcc; |
cocorlow | 0:cf7c726ec8a1 | 103 | unsigned int cAcc; |
cocorlow | 0:cf7c726ec8a1 | 104 | } data; |
cocorlow | 0:cf7c726ec8a1 | 105 | }; |
cocorlow | 0:cf7c726ec8a1 | 106 | |
cocorlow | 0:cf7c726ec8a1 | 107 | class GPSUBX_UART |
cocorlow | 0:cf7c726ec8a1 | 108 | { |
cocorlow | 0:cf7c726ec8a1 | 109 | private: |
cocorlow | 1:71f5168e48c8 | 110 | RawSerial serial; |
cocorlow | 0:cf7c726ec8a1 | 111 | char receive_buffer[RECEIVE_SIZE]; |
cocorlow | 0:cf7c726ec8a1 | 112 | char sentence_buffer[SENTENCE_SIZE]; |
cocorlow | 0:cf7c726ec8a1 | 113 | static const float Radius = 6378136.6f; |
cocorlow | 0:cf7c726ec8a1 | 114 | |
cocorlow | 1:71f5168e48c8 | 115 | void Receive(); |
cocorlow | 1:71f5168e48c8 | 116 | void Decode(char buffer[], int mc, int mi); |
cocorlow | 0:cf7c726ec8a1 | 117 | |
cocorlow | 0:cf7c726ec8a1 | 118 | public: |
cocorlow | 0:cf7c726ec8a1 | 119 | int Year; |
cocorlow | 0:cf7c726ec8a1 | 120 | int Month; |
cocorlow | 0:cf7c726ec8a1 | 121 | int Day; |
cocorlow | 0:cf7c726ec8a1 | 122 | int Hours; |
cocorlow | 0:cf7c726ec8a1 | 123 | int Minutes; |
cocorlow | 0:cf7c726ec8a1 | 124 | int Seconds; |
cocorlow | 0:cf7c726ec8a1 | 125 | float Latitude; |
cocorlow | 0:cf7c726ec8a1 | 126 | float Longitude; |
cocorlow | 0:cf7c726ec8a1 | 127 | float Height; |
cocorlow | 0:cf7c726ec8a1 | 128 | int iTOW_POSLLH; |
cocorlow | 0:cf7c726ec8a1 | 129 | Vector3 VelocityNED; |
cocorlow | 0:cf7c726ec8a1 | 130 | float Speed; |
cocorlow | 0:cf7c726ec8a1 | 131 | float GroundSpeed; |
cocorlow | 0:cf7c726ec8a1 | 132 | float Heading; |
cocorlow | 0:cf7c726ec8a1 | 133 | int iTOW_VELNED; |
cocorlow | 1:71f5168e48c8 | 134 | |
cocorlow | 1:71f5168e48c8 | 135 | int TimeZone; |
cocorlow | 1:71f5168e48c8 | 136 | volatile int receive_index; |
cocorlow | 0:cf7c726ec8a1 | 137 | |
cocorlow | 0:cf7c726ec8a1 | 138 | Vector3 UniversalZeroPosition; |
cocorlow | 0:cf7c726ec8a1 | 139 | Vector3 UniversalZeroUnitN; |
cocorlow | 0:cf7c726ec8a1 | 140 | Vector3 UniversalZeroUnitE; |
cocorlow | 0:cf7c726ec8a1 | 141 | Vector3 UniversalZeroUnitD; |
cocorlow | 0:cf7c726ec8a1 | 142 | Vector3 UniversalPosition; |
cocorlow | 0:cf7c726ec8a1 | 143 | Vector3 PositionNED; |
cocorlow | 0:cf7c726ec8a1 | 144 | |
cocorlow | 1:71f5168e48c8 | 145 | GPSUBX_UART(PinName tx, PinName rx, int baud = 38400, int timezone = 9); |
cocorlow | 1:71f5168e48c8 | 146 | void Update(); |
cocorlow | 0:cf7c726ec8a1 | 147 | void Attach(); |
cocorlow | 0:cf7c726ec8a1 | 148 | |
cocorlow | 0:cf7c726ec8a1 | 149 | // Position Calculation |
cocorlow | 0:cf7c726ec8a1 | 150 | Vector3 ToUniversalUnit(); |
cocorlow | 0:cf7c726ec8a1 | 151 | Vector3 ToUniversal(); |
cocorlow | 0:cf7c726ec8a1 | 152 | void CalculateUnit(); |
cocorlow | 0:cf7c726ec8a1 | 153 | void Calculate(); |
cocorlow | 0:cf7c726ec8a1 | 154 | Vector3 Calculate(Vector3 position); |
cocorlow | 0:cf7c726ec8a1 | 155 | |
cocorlow | 0:cf7c726ec8a1 | 156 | static void Checksum(char payload[], int n, char* ck_a, char* ck_b); |
cocorlow | 0:cf7c726ec8a1 | 157 | }; |
cocorlow | 0:cf7c726ec8a1 | 158 | #endif |