GPS/GNSS UBX library for UART

Dependencies:   Vector3

Dependents:   GPS_0002

Revision:
0:cf7c726ec8a1
Child:
1:71f5168e48c8
diff -r 000000000000 -r cf7c726ec8a1 GPSUBX_UART.hpp
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/GPSUBX_UART.hpp	Mon Sep 13 16:04:40 2021 +0000
@@ -0,0 +1,156 @@
+#ifndef __GPSUBX_UART_HPP__
+#define __GPSUBX_UART_HPP__
+
+#include "mbed.h"
+#include "Vector3.hpp"
+
+#define POSECEF_LEN 20
+#define POSLLH_LEN 28
+#define TIMEUTC_LEN 20
+#define VELECEF_LEN 20
+#define VELNED_LEN 36
+
+#define UBX_SYNC 0x62 << 8 | 0xb5
+
+#define RECEIVE_SIZE 512
+#define SENTENCE_SIZE 64
+
+extern Serial pc;
+
+//// 0x01 0x01
+//union POSECEF
+//{
+//    char byte_data[POSECEF_LEN+8];
+//    struct
+//    {
+//        unsigned short sync;
+//        char m_class;
+//        char m_id;
+//        unsigned short pay_len;
+//        unsigned int iTOW;
+//        int ecefX;
+//        int ecefY;
+//        int ecefZ;
+//        unsigned int pAcc;
+//        char check_a;
+//        char check_b;
+//    } data;
+//};
+
+// 0x01 0x02
+union POSLLH
+{
+    char byte_data[POSLLH_LEN];
+    struct
+    {
+        unsigned int iTOW;
+        int lon;
+        int lat;
+        int height;
+        int hMSL;
+        unsigned int hAcc;
+        unsigned int vAcc;
+    } data;
+};
+
+// 0x01 0x21
+union TIMEUTC
+{
+    char byte_data[TIMEUTC_LEN];
+    struct
+    {
+        unsigned int iTOW;
+        unsigned int tAcc;
+        int nano;
+        unsigned short year;
+        unsigned char month;
+        unsigned char day;
+        unsigned char hour;
+        unsigned char min;
+        unsigned char sec;
+        unsigned char valid;
+    } data;
+};
+
+//// 0x01 0x11
+//union VELECEF
+//{
+//    char byte_data[VELECEF_LEN];
+//    struct
+//    {
+//        unsigned int iTOW;
+//        int ecefVX;
+//        int ecefVY;
+//        int ecefVZ;
+//        unsigned int sAcc;
+//    } data;  
+//};
+
+// 0x01 0x12
+union VELNED
+{
+    char byte_data[VELNED_LEN];
+    struct
+    {
+        unsigned int iTOW;
+        int velN;
+        int velE;
+        int velD;
+        unsigned int speed;
+        unsigned int gSpeed;
+        signed int heading;
+        unsigned int sAcc;
+        unsigned int cAcc;
+    } data;
+};
+
+class GPSUBX_UART
+{
+private:
+    Serial serial;
+    char receive_buffer[RECEIVE_SIZE];
+    char sentence_buffer[SENTENCE_SIZE];
+    static const float Radius = 6378136.6f;
+    
+    void Punctuate();
+    
+public:
+    int TimeZone;
+    int Year;
+    int Month;
+    int Day;
+    int Hours;
+    int Minutes;
+    int Seconds;
+    float Latitude;
+    float Longitude;
+    float Height;
+    int iTOW_POSLLH;
+    Vector3 VelocityNED;
+    float Speed;
+    float GroundSpeed;
+    float Heading;
+    int iTOW_VELNED;
+        
+    Vector3 UniversalZeroPosition;
+    Vector3 UniversalZeroUnitN;
+    Vector3 UniversalZeroUnitE;
+    Vector3 UniversalZeroUnitD;
+    Vector3 UniversalPosition;
+    Vector3 PositionNED;
+
+    GPSUBX_UART(PinName tx, PinName rx, int baud, int timezone);
+    void Receive();
+    void Attach();
+    void Decode(char buffer[], int mc, int mi);
+    
+    // Position Calculation
+    Vector3 ToUniversalUnit();
+    Vector3 ToUniversal();
+    void CalculateUnit();
+    void Calculate();
+    Vector3 Calculate(Vector3 position);
+    
+    static void Checksum(char payload[], int n, char* ck_a, char* ck_b);
+};
+#endif
\ No newline at end of file