From inspecting the MTK serial datastream in binary mode i found some problems wich the current readout in the I2C version, wich also exists in the apm code. The checksum B is not transmitted at all. I rewrote the binary readout for mtk. I omitted the single byte checksum, because i found it useless anyway. It can be added. I watched the data over minutes at 57K serial speed and 10Hz MTK updaterate and had no serial errors at all. Sorry for the simple code - but it works! Perhaps the binary mtk protocol can be re-enabled in the next DEV?
Code: Select all
bool GPS_MTK_newFrame(uint8_t data)
{
static uint8_t pstep; // Parse Step
static uint8_t lastbyte; // Last Byte for Sync detection
static uint8_t LSLshifter; // Bitshiftvalue
static int32_t lat; // MTK Dataset
static int32_t lon; // MTK Dataset
static int32_t alt; // MTK Dataset
static int32_t grspeed; // MTK Dataset
static int32_t grcourse; // MTK Dataset
static uint8_t satn; // MTK Dataset
int32_t tmp32;
bool parsed;
parsed = false;
if (data == 0xdd && lastbyte == 0xd0) pstep = 100; // Detect Sync "0xD0,0xDD"
lastbyte = data;
switch(pstep) {
case 0: // Special Case: Do Nothing
break;
case 100: // Special Case: Jump into decoding on next run
pstep = 1;
break;
case 1: // Ignore Payload Byte (This is the first Byte after sync preamble)
pstep++;
break;
case 2: // Read Dataset Latitude
lat = data;
LSLshifter = 0;
pstep++;
break;
case 3:
LSLshifter = LSLshifter+8;
tmp32 = data;
tmp32 = tmp32<<LSLshifter;
lat = lat | tmp32;
if (LSLshifter == 24){lat = lat * 10; pstep++;}
break;
case 4: // Read Dataset Longitude
lon = data;
LSLshifter = 0;
pstep++;
break;
case 5:
LSLshifter = LSLshifter+8;
tmp32 = data;
tmp32 = tmp32<<LSLshifter;
lon = lon | tmp32;
if (LSLshifter == 24){lon = lon * 10; pstep++;}
break;
case 6: // Read Dataset MSL Altitude
alt = data;
LSLshifter = 0;
pstep++;
break;
case 7:
LSLshifter = LSLshifter+8;
tmp32 = data;
tmp32 = tmp32<<LSLshifter;
alt = alt | tmp32;
if (LSLshifter == 24){alt = alt/100; pstep++;}
break;
case 8: // Read Dataset Ground Speed
grspeed = data;
LSLshifter = 0;
pstep++;
break;
case 9:
LSLshifter = LSLshifter+8;
tmp32 = data;
tmp32 = tmp32<<LSLshifter;
grspeed = grspeed | tmp32;
if (LSLshifter == 24) pstep++;
break;
case 10: // Read Dataset Heading
grcourse = data;
LSLshifter = 0;
pstep++;
break;
case 11:
LSLshifter = LSLshifter+8;
tmp32 = data;
tmp32 = tmp32<<LSLshifter;
grcourse = grcourse | tmp32;
if (LSLshifter == 24) pstep++;
break;
case 12: // Read number of satellites in view
satn = data;
pstep++;
break;
case 13: // Read Fix Type and finish readout, mwii does not need the rest
if (data==1){ // No Fix
i2c_dataset.status.gps2dfix = 0;
i2c_dataset.status.gps3dfix = 0;}
if (data==2){ // GPS 2D Fix
i2c_dataset.status.gps2dfix = 1;
i2c_dataset.status.gps3dfix = 0;}
if (data==3){ // GPS 3D Fix
i2c_dataset.status.gps2dfix = 1;
i2c_dataset.status.gps3dfix = 1;}
GPS_read[LAT] = lat;
GPS_read[LON] = lon;
i2c_dataset.altitude = alt;
i2c_dataset.ground_speed = grspeed;
i2c_dataset.ground_course = grcourse;
i2c_dataset.status.numsats = satn;
parsed = true; // RDY
pstep = 0; // Do nothing with the next bytes
break;
}
return parsed;
}
So long
Kraut Rob