Bmag incl gps rettelse

Dependencies:   mbed WDT MODSERIAL BME280

Revision:
4:c70ef089a3fd
Parent:
2:39c4a85dc2a4
Child:
5:11782a2008c2
--- a/SPS/SPS.cpp	Thu Feb 23 14:54:35 2017 +0000
+++ b/SPS/SPS.cpp	Thu Mar 02 14:04:56 2017 +0000
@@ -4,7 +4,7 @@
 
     currentString = "";
     currentErrString = "";
-    headerString = "/>tag identifier_id group_id date time zzz | s1 source_id interpreter_id data_line_version encoding source_firmware_version interpreter_firmware_version | latitude longitude gpsFixFlag mag_time mag_nt mag_sq checksum<";
+    headerString = "/tag identifier_id group_id date time zzz | s1 source_id interpreter_id data_line_version encoding source_firmware_version interpreter_firmware_version | latitude longitude gpsFixFlag mag_time mag_nt mag_sq checksum";
            
 };
 
@@ -67,7 +67,46 @@
  
 };
 
-string SPS::checkSumCalc(){
-    
-    return "XXXX";
-};
\ No newline at end of file
+//Fills the array for calculation of the CRC-16 with values
+void SPS::init_crc16_tab()
+{
+    int i, j;
+    unsigned short crc, c;
+
+    for (i = 0; i < 256; i++)
+    {
+        crc = 0;
+        c = (unsigned short) i;
+
+        for (j = 0; j < 8; j++)
+        {
+            if ((crc ^ c) & 0x0001) 
+                crc = (crc >> 1) ^ P_16;
+            else
+                crc = crc >> 1;
+
+            c = c >> 1;
+        }
+        crc_tab16[i] = crc;
+    }
+    crc_tab16_init = 1;
+};
+
+
+//  The function update_crc_16 calculates a new CRC-16 value based on the 
+//  previous value of the CRC and the next byte of the data to be checked.
+unsigned short SPS::update_crc_16(unsigned short crc, char c)
+{
+    unsigned short tmp, short_c;
+
+    short_c = 0x00ff & (unsigned short) c;
+
+    if (!crc_tab16_init)
+        init_crc16_tab();
+
+    tmp = crc ^ short_c;
+    crc = (crc >> 8) ^ crc_tab16[tmp & 0xff];
+
+    return crc;
+};
+//***************************************************************************
\ No newline at end of file