1
0
mirror of https://bitbucket.org/librepilot/librepilot.git synced 2025-02-20 10:54:14 +01:00

LP-212 uncrustify and remove junk comments

This commit is contained in:
Cliff Geerdes 2016-02-09 15:11:52 -05:00
parent 2ae1f9c63d
commit fad0e9f24c
5 changed files with 245 additions and 241 deletions

View File

@ -58,9 +58,9 @@ typedef struct {
} dji_message_handler;
const dji_message_handler dji_handler_table[] = {
{ .msgID = DJI_ID_GPS, .handler = &parse_dji_gps },
{ .msgID = DJI_ID_MAG, .handler = &parse_dji_mag },
{ .msgID = DJI_ID_VER, .handler = &parse_dji_ver },
{ .msgID = DJI_ID_GPS, .handler = &parse_dji_gps },
{ .msgID = DJI_ID_MAG, .handler = &parse_dji_mag },
{ .msgID = DJI_ID_VER, .handler = &parse_dji_ver },
};
#define DJI_HANDLER_TABLE_SIZE NELEMENTS(dji_handler_table)
@ -91,7 +91,7 @@ int parse_dji_stream(uint8_t *rx, uint16_t len, char *gps_rx_buffer, GPSPosition
static enum proto_states proto_state = START;
static uint16_t rx_count = 0;
struct DJIPacket *dji = (struct DJIPacket *)gps_rx_buffer;
uint16_t i = 0;
uint16_t i = 0;
uint16_t restart_index = 0;
enum restart_states restart_state;
static bool previous_packet_good = true;
@ -103,13 +103,14 @@ int parse_dji_stream(uint8_t *rx, uint16_t len, char *gps_rx_buffer, GPSPosition
c = rx[i++];
switch (proto_state) {
case START: // detect protocol
if (c == DJI_SYNC1) { // first DJI sync char found
proto_state = DJI_SY2;
if (c == DJI_SYNC1) { // first DJI sync char found
proto_state = DJI_SY2;
// restart here, at byte after SYNC1, if we fail to parse
restart_index = i; }
restart_index = i;
}
continue;
case DJI_SY2:
if (c == DJI_SYNC2) { // second DJI sync char found
if (c == DJI_SYNC2) { // second DJI sync char found
proto_state = DJI_ID;
} else {
restart_state = RESTART_NO_ERROR;
@ -117,8 +118,8 @@ int parse_dji_stream(uint8_t *rx, uint16_t len, char *gps_rx_buffer, GPSPosition
}
continue;
case DJI_ID:
dji->header.id = c;
proto_state = DJI_LEN;
dji->header.id = c;
proto_state = DJI_LEN;
continue;
case DJI_LEN:
if (c > sizeof(DJIPayload)) {
@ -131,7 +132,7 @@ int parse_dji_stream(uint8_t *rx, uint16_t len, char *gps_rx_buffer, GPSPosition
break;
#endif
} else {
dji->header.len = c;
dji->header.len = c;
if (c == 0) {
proto_state = DJI_CHK1;
} else {
@ -161,7 +162,7 @@ int parse_dji_stream(uint8_t *rx, uint16_t len, char *gps_rx_buffer, GPSPosition
// instead of a mag packet (30 per second)
current_packet_good = checksum_dji_message(dji);
// message complete and valid or (it's a mag packet and the previous "any" packet was good)
if (current_packet_good || (dji->header.id==DJI_ID_MAG && previous_packet_good)) {
if (current_packet_good || (dji->header.id == DJI_ID_MAG && previous_packet_good)) {
parse_dji_message(dji, GpsData);
gpsRxStats->gpsRxReceived++;
proto_state = START;
@ -171,7 +172,7 @@ int parse_dji_stream(uint8_t *rx, uint16_t len, char *gps_rx_buffer, GPSPosition
// only pass PARSER_COMPLETE back to caller if we parsed a full set of GPS data
// that allows the caller to know if we are parsing GPS data
// or just other packets for some reason (DJI clone firmware bug that happens sometimes)
if (dji->header.id==DJI_ID_GPS && ret==PARSER_INCOMPLETE) {
if (dji->header.id == DJI_ID_GPS && ret == PARSER_INCOMPLETE) {
ret = PARSER_COMPLETE; // message complete & processed
}
} else {
@ -192,7 +193,7 @@ int parse_dji_stream(uint8_t *rx, uint16_t len, char *gps_rx_buffer, GPSPosition
// if restarting due to error detected in 2nd call to this function (on split packet)
// then we just restart at index 0, which is mid-packet, not the second byte
if (restart_state == RESTART_WITH_ERROR) {
ret = PARSER_ERROR; // inform caller that we found at least one error (along with 0 or more good packets)
ret = PARSER_ERROR; // inform caller that we found at least one error (along with 0 or more good packets)
}
rx += restart_index; // restart parsing just past the most recent SYNC1
len -= restart_index;
@ -209,8 +210,8 @@ bool checksum_dji_message(struct DJIPacket *dji)
int i;
uint8_t ck_a, ck_b;
ck_a = dji->header.id;
ck_b = ck_a;
ck_a = dji->header.id;
ck_b = ck_a;
ck_a += dji->header.len;
ck_b += ck_a;
@ -231,7 +232,8 @@ bool checksum_dji_message(struct DJIPacket *dji)
static void parse_dji_gps(struct DJIPacket *dji, GPSPositionSensorData *GpsPosition)
{
static bool inited=false;
static bool inited = false;
if (!inited) {
inited = true;
// Is there a model calculation we can do to get a reasonable value for geoid separation?
@ -242,11 +244,11 @@ static void parse_dji_gps(struct DJIPacket *dji, GPSPositionSensorData *GpsPosit
// decode with xor mask
uint8_t mask = gps->unused5;
//for (uint8_t i=0; i<dji->header->len; ++i) {
for (uint8_t i=0; i<56; ++i) {
//if (i!=48 && i!=49 && i<=55) {
if (i!=48 && i!=49) {
dji->payload.payload[i]^=mask;
// for (uint8_t i=0; i<dji->header->len; ++i) {
for (uint8_t i = 0; i < 56; ++i) {
// if (i!=48 && i!=49 && i<=55) {
if (i != 48 && i != 49) {
dji->payload.payload[i] ^= mask;
}
}
@ -255,7 +257,7 @@ static void parse_dji_gps(struct DJIPacket *dji, GPSPositionSensorData *GpsPosit
GpsVelocity.Down = (float)gps->velD * 0.01f;
GPSVelocitySensorSet(&GpsVelocity);
GpsPosition->Groundspeed = sqrtf(GpsVelocity.North*GpsVelocity.North + GpsVelocity.East*GpsVelocity.East);
GpsPosition->Groundspeed = sqrtf(GpsVelocity.North * GpsVelocity.North + GpsVelocity.East * GpsVelocity.East);
GpsPosition->Heading = RAD2DEG(atan2f(-GpsVelocity.East, -GpsVelocity.North)) + 180.0f;
GpsPosition->Altitude = (float)gps->hMSL * 0.001f;
// there is no source of geoid separation data in the DJI protocol
@ -264,14 +266,7 @@ static void parse_dji_gps(struct DJIPacket *dji, GPSPositionSensorData *GpsPosit
GpsPosition->Longitude = gps->lon;
GpsPosition->Satellites = gps->numSV;
GpsPosition->PDOP = gps->pDOP * 0.01f;
// cliffg FIXME
// might get away with just using a max function here...
// hmmm pdop=sqrt(hdop*hdop+hdop*hdop+vdop*vdop)
// pdop*pdop=hdop*hdop+hdop*hdop+vdop*vdop
// pdop*pdop-vdop*vdop=hdop*hdop+hdop*hdop
// (pdop*pdop-vdop*vdop)/2=hdop*hdop
// srtq(pdop*pdop-vdop*vdop)/2=hdop
GpsPosition->HDOP = sqrtf((float)gps->nDOP*(float)gps->nDOP + (float)gps->eDOP*(float)gps->eDOP) * 0.01f;
GpsPosition->HDOP = sqrtf((float)gps->nDOP * (float)gps->nDOP + (float)gps->eDOP * (float)gps->eDOP) * 0.01f;
GpsPosition->VDOP = gps->vDOP * 0.01f;
if (gps->flags & FLAGS_GPSFIX_OK) {
GpsPosition->Status = gps->fixType == FIXTYPE_3D ?
@ -281,18 +276,17 @@ static void parse_dji_gps(struct DJIPacket *dji, GPSPositionSensorData *GpsPosit
}
GpsPosition->SensorType = GPSPOSITIONSENSOR_SENSORTYPE_DJI;
GpsPosition->AutoConfigStatus = GPSPOSITIONSENSOR_AUTOCONFIGSTATUS_DISABLED;
//GpsPosition->BaudRate = GPSPOSITIONSENSOR_BAUDRATE_115200;
GPSPositionSensorSet(GpsPosition);
// Time is valid, set GpsTime
GPSTimeData GpsTime;
// cliffg FIXME
// the lowest bit of day and the highest bit of hour overlap (xored? no stranger than that)
// the lowest bit of day and the highest bit of hour overlap (xored? no, stranger than that)
// this causes strange day/hour changes
// we could track it here and even if we guess wrong initially
// we can massage the data so that time doesn't jump
// and maybe make the assumption that most people will fly at 5pm, not 1am
// so if it looks if we have to make a choice between 5pm on the 10th and
// this is part of the DJI protocol
// see DJI.h for further info
GpsTime.Year = (int16_t)gps->year + 2000;
GpsTime.Month = gps->month;
GpsTime.Day = gps->day;
@ -316,10 +310,10 @@ static void parse_dji_mag(struct DJIPacket *dji, __attribute__((unused)) GPSPosi
};
int16_t maskmask;
} u;
u.mask = (int8_t) (dji->payload.payload[4]);
u.mask = (int8_t)(dji->payload.payload[4]);
u.mask = u.mask2 = (((u.mask ^ (u.mask >> 4)) & 0x0F) | ((u.mask << 3) & 0xF0)) ^ (((u.mask & 0x01) << 3) | ((u.mask & 0x01) << 7));
// yes, z is only xored by mask<<8, not maskmask
float mags[3] = { mag->x^u.maskmask, mag->y^u.maskmask, mag->z^((int16_t)u.mask<<8) };
float mags[3] = { mag->x ^ u.maskmask, mag->y ^ u.maskmask, mag->z ^ ((int16_t)u.mask << 8) };
auxmagsupport_publish_samples(mags, AUXMAGSENSOR_STATUS_OK);
}
@ -330,9 +324,10 @@ static void parse_dji_ver(struct DJIPacket *dji, __attribute__((unused)) GPSPosi
// decode with xor mask
uint8_t mask = (uint8_t)(ver->unused1);
//for (uint8_t i=0; i<dji->header->len; ++i) {
for (uint8_t i=4; i<12; ++i) {
dji->payload.payload[i]^=mask;
// for (uint8_t i=0; i<dji->header->len; ++i) {
for (uint8_t i = 4; i < 12; ++i) {
dji->payload.payload[i] ^= mask;
}
djiHwVersion = ver->hwVersion;

View File

@ -229,10 +229,14 @@ int32_t GPSInitialize(void)
size_t bufSize = 0;
#endif
#if defined(PIOS_INCLUDE_GPS_UBX_PARSER)
if (bufSize < sizeof(struct UBXPacket)) bufSize = sizeof(struct UBXPacket);
if (bufSize < sizeof(struct UBXPacket)) {
bufSize = sizeof(struct UBXPacket);
}
#endif
#if defined(PIOS_INCLUDE_GPS_DJI_PARSER)
if (bufSize < sizeof(struct DJIPacket)) bufSize = sizeof(struct DJIPacket);
if (bufSize < sizeof(struct DJIPacket)) {
bufSize = sizeof(struct DJIPacket);
}
#endif
gps_rx_buffer = pios_malloc(bufSize);
#else /* defined(PIOS_INCLUDE_GPS_NMEA_PARSER) || defined(PIOS_INCLUDE_GPS_UBX_PARSER) || defined(PIOS_INCLUDE_GPS_DJI_PARSER) */
@ -269,6 +273,7 @@ static void gpsTask(__attribute__((unused)) void *parameters)
// 100ms is way slow too, considering we do everything possible to make the sensor data as contemporary as possible
portTickType xDelay = 5 / portTICK_RATE_MS;
uint32_t timeNowMs = xTaskGetTickCount() * portTICK_RATE_MS;
#ifdef PIOS_GPS_SETS_HOMELOCATION
portTickType homelocationSetDelay = 0;
#endif
@ -411,11 +416,11 @@ static void gpsTask(__attribute__((unused)) void *parameters)
homelocationSetDelay = 0;
}
#endif
// else if (we are at least getting what might be usable GPS data to finish a flight with) {
// else if (we are at least getting what might be usable GPS data to finish a flight with) {
} else if ((gpspositionsensor.Status == GPSPOSITIONSENSOR_STATUS_FIX3D) &&
(gpspositionsensor.Latitude != 0 || gpspositionsensor.Longitude != 0)) {
AlarmsSet(SYSTEMALARMS_ALARM_GPS, SYSTEMALARMS_ALARM_WARNING);
// else data is probably not good enough to fly
// else data is probably not good enough to fly
} else {
AlarmsSet(SYSTEMALARMS_ALARM_GPS, SYSTEMALARMS_ALARM_CRITICAL);
}
@ -536,15 +541,16 @@ void gps_set_fc_baud_from_arg(uint8_t baud)
static void gps_set_fc_baud_from_settings()
{
uint8_t speed;
// Retrieve settings
#if defined(PIOS_INCLUDE_GPS_DJI_PARSER) && !defined(PIOS_GPS_MINIMAL)
if (gpsSettings.DataProtocol == GPSSETTINGS_DATAPROTOCOL_DJI) {
speed = HWSETTINGS_GPSSPEED_115200;
} else {
#endif
HwSettingsGPSSpeedGet(&speed);
HwSettingsGPSSpeedGet(&speed);
#if defined(PIOS_INCLUDE_GPS_DJI_PARSER) && !defined(PIOS_GPS_MINIMAL)
}
}
#endif
// set fc baud
gps_set_fc_baud_from_arg(speed);

View File

@ -131,7 +131,7 @@ int parse_ubx_stream(uint8_t *rx, uint16_t len, char *gps_rx_buffer, GPSPosition
static enum proto_states proto_state = START;
static uint16_t rx_count = 0;
struct UBXPacket *ubx = (struct UBXPacket *)gps_rx_buffer;
uint16_t i = 0;
uint16_t i = 0;
uint16_t restart_index = 0;
enum restart_states restart_state;
@ -216,7 +216,7 @@ int parse_ubx_stream(uint8_t *rx, uint16_t len, char *gps_rx_buffer, GPSPosition
// only pass PARSER_COMPLETE back to caller if we parsed a full set of GPS data
// that allows the caller to know if we are parsing GPS data
// or just other packets for some reason (mis-configuration)
if (parse_ubx_message(ubx, GpsData)==GPSPOSITIONSENSOR_OBJID
if (parse_ubx_message(ubx, GpsData) == GPSPOSITIONSENSOR_OBJID
&& ret == PARSER_INCOMPLETE) {
ret = PARSER_COMPLETE;
}
@ -236,7 +236,7 @@ int parse_ubx_stream(uint8_t *rx, uint16_t len, char *gps_rx_buffer, GPSPosition
// if restarting due to error detected in 2nd call to this function (on split packet)
// then we just restart at index 0, which is mid-packet, not the second byte
if (restart_state == RESTART_WITH_ERROR) {
ret = PARSER_ERROR; // inform caller that we found at least one error (along with 0 or more good packets)
ret = PARSER_ERROR; // inform caller that we found at least one error (along with 0 or more good packets)
}
rx += restart_index; // restart parsing just past the most recent SYNC1
len -= restart_index;

View File

@ -39,8 +39,8 @@
#include "GPS.h"
#define DJI_SYNC1 0x55 // DJI protocol synchronization characters
#define DJI_SYNC2 0xaa
#define DJI_SYNC1 0x55 // DJI protocol synchronization characters
#define DJI_SYNC2 0xaa
// Message IDs
typedef enum {
@ -52,268 +52,268 @@ typedef enum {
// private structures
/*
GPS protocol info from
http://www.rcgroups.com/forums/showpost.php?p=26210591&postcount=15
GPS protocol info from
http://www.rcgroups.com/forums/showpost.php?p=26210591&postcount=15
The 0x10 message contains GPS data. Here is the structure of the message,
fields marked with XX I'm not sure about yet. The others will be described below.
The 0x10 message contains GPS data. Here is the structure of the message,
fields marked with XX I'm not sure about yet. The others will be described below.
55 AA 10 3A DT DT DT DT LO LO LO LO LA LA LA LA AL AL AL AL HA HA HA HA VA VA VA VA XX XX XX XX
NV NV NV NV EV EV EV EV DV DV DV DV PD PD VD VD ND ND ED ED NS XX FT XX SF XX XX XM SN SN CS CS
55 AA 10 3A DT DT DT DT LO LO LO LO LA LA LA LA AL AL AL AL HA HA HA HA VA VA VA VA XX XX XX XX
NV NV NV NV EV EV EV EV DV DV DV DV PD PD VD VD ND ND ED ED NS XX FT XX SF XX XX XM SN SN CS CS
The payload is XORed with a mask that changes over time (see below for more details).
The payload is XORed with a mask that changes over time (see below for more details).
Values in the message are stored in little endian.
Values in the message are stored in little endian.
HEADER
-------------
BYTE 1-2: message header - always 55 AA
BYTE 3: message id (0x10 for GPS message)
BYTE 4: lenght of the payload (0x3A or 58 decimal for 0x10 message)
HEADER
-------------
BYTE 1-2: message header - always 55 AA
BYTE 3: message id (0x10 for GPS message)
BYTE 4: lenght of the payload (0x3A or 58 decimal for 0x10 message)
PAYLOAD
--------------
BYTE 5-8 (DT) : date and time, see details below
BYTE 9-12 (LO) : longitude (x10^7, degree decimal)
BYTE 13-16 (LA): latitude (x10^7, degree decimal)
BYTE 17-20 (AL): altitude (in milimeters)
BYTE 21-24 (HA): horizontal accuracy estimate (see uBlox NAV-POSLLH message for details)
BYTE 25-28 (VA): vertical accuracy estimate (see uBlox NAV-POSLLH message for details)
BYTE 29-32 : ??? (seems to be always 0)
BYTE 33-36 (NV): NED north velocity (see uBlox NAV-VELNED message for details)
BYTE 37-40 (EV): NED east velocity (see uBlox NAV-VELNED message for details)
BYTE 41-44 (DV): NED down velocity (see uBlox NAV-VELNED message for details)
BYTE 45-46 (PD): position DOP (see uBlox NAV-DOP message for details)
BYTE 47-48 (VD): vertical DOP (see uBlox NAV-DOP message for details)
BYTE 49-50 (ND): northing DOP (see uBlox NAV-DOP message for details)
BYTE 51-52 (ED): easting DOP (see uBlox NAV-DOP message for details)
BYTE 53 (NS) : number of satellites (not XORed)
BYTE 54 : ??? (not XORed, seems to be always 0)
BYTE 55 (FT) : fix type (0 - no lock, 2 - 2D lock, 3 - 3D lock, not sure if other values can be expected
PAYLOAD
--------------
BYTE 5-8 (DT) : date and time, see details below
BYTE 9-12 (LO) : longitude (x10^7, degree decimal)
BYTE 13-16 (LA): latitude (x10^7, degree decimal)
BYTE 17-20 (AL): altitude (in milimeters)
BYTE 21-24 (HA): horizontal accuracy estimate (see uBlox NAV-POSLLH message for details)
BYTE 25-28 (VA): vertical accuracy estimate (see uBlox NAV-POSLLH message for details)
BYTE 29-32 : ??? (seems to be always 0)
BYTE 33-36 (NV): NED north velocity (see uBlox NAV-VELNED message for details)
BYTE 37-40 (EV): NED east velocity (see uBlox NAV-VELNED message for details)
BYTE 41-44 (DV): NED down velocity (see uBlox NAV-VELNED message for details)
BYTE 45-46 (PD): position DOP (see uBlox NAV-DOP message for details)
BYTE 47-48 (VD): vertical DOP (see uBlox NAV-DOP message for details)
BYTE 49-50 (ND): northing DOP (see uBlox NAV-DOP message for details)
BYTE 51-52 (ED): easting DOP (see uBlox NAV-DOP message for details)
BYTE 53 (NS) : number of satellites (not XORed)
BYTE 54 : ??? (not XORed, seems to be always 0)
BYTE 55 (FT) : fix type (0 - no lock, 2 - 2D lock, 3 - 3D lock, not sure if other values can be expected
: see uBlox NAV-SOL message for details)
BYTE 56 : ??? (seems to be always 0)
BYTE 57 (SF) : fix status flags (see uBlox NAV-SOL message for details)
BYTE 58-59 : ??? (seems to be always 0)
BYTE 60 (XM) : not sure yet, but I use it as the XOR mask
BYTE 61-62 (SN): sequence number (not XORed), once there is a lock - increases with every message.
BYTE 56 : ??? (seems to be always 0)
BYTE 57 (SF) : fix status flags (see uBlox NAV-SOL message for details)
BYTE 58-59 : ??? (seems to be always 0)
BYTE 60 (XM) : not sure yet, but I use it as the XOR mask
BYTE 61-62 (SN): sequence number (not XORed), once there is a lock - increases with every message.
When the lock is lost later LSB and MSB are swapped with every message.
CHECKSUM
-----------------
BYTE 63-64 (CS): checksum, calculated the same way as for uBlox binary messages
CHECKSUM
-----------------
BYTE 63-64 (CS): checksum, calculated the same way as for uBlox binary messages
XOR mask
---------------
All bytes of the payload except 53rd (NS), 54th, 61st (SN LSB) and 62nd (SN MSB) are XORed with a mask.
Mask is calculated based on the value of byte 53rd (NS) and 61st (SN LSB).
XOR mask
---------------
All bytes of the payload except 53rd (NS), 54th, 61st (SN LSB) and 62nd (SN MSB) are XORed with a mask.
Mask is calculated based on the value of byte 53rd (NS) and 61st (SN LSB).
If we index bits from LSB to MSB as 0-7 we have:
mask[0] = 53rdByte[0] xor 61stByte[4]
mask[1] = 53rdByte[1] xor 61stByte[5]
mask[2] = 53rdByte[2] xor 61stByte[6]
mask[3] = 53rdByte[3] xor 61stByte[7] xor 53rdByte[0];
mask[4] = 53rdByte[1];
mask[5] = 53rdByte[2];
mask[6] = 53rdByte[3];
mask[7] = 53rdByte[0] xor 61stByte[4];
If we index bits from LSB to MSB as 0-7 we have:
mask[0] = 53rdByte[0] xor 61stByte[4]
mask[1] = 53rdByte[1] xor 61stByte[5]
mask[2] = 53rdByte[2] xor 61stByte[6]
mask[3] = 53rdByte[3] xor 61stByte[7] xor 53rdByte[0];
mask[4] = 53rdByte[1];
mask[5] = 53rdByte[2];
mask[6] = 53rdByte[3];
mask[7] = 53rdByte[0] xor 61stByte[4];
To simplify calculations any of the unknown bytes that when XORer seem to be always 0 (29-32, 56, 58-60)
can be used as XOR mask (based on the fact that 0 XOR mask == mask). In the library I use byte 60.
To simplify calculations any of the unknown bytes that when XORer seem to be always 0 (29-32, 56, 58-60)
can be used as XOR mask (based on the fact that 0 XOR mask == mask). In the library I use byte 60.
Date and time format
----------------------------
Date (Year, Month, Day) and time (Hour, Minute, Second) are stored as little endian 32bit unsigned integer,
the meaning of particular bits is as follows:
Date and time format
----------------------------
Date (Year, Month, Day) and time (Hour, Minute, Second) are stored as little endian 32bit unsigned integer,
the meaning of particular bits is as follows:
YYYYYYYMMMMDDDDDHHHHMMMMMMSSSSSS
YYYYYYYMMMMDDDDDHHHHMMMMMMSSSSSS
NOTE 1: to get the day value correct you must add 1 when hour is > 7
NOTE 2: for the time between 16:00 and 23:59 the hour will be returned as 0-7
NOTE 1: to get the day value correct you must add 1 when hour is > 7
NOTE 2: for the time between 16:00 and 23:59 the hour will be returned as 0-7
and there seems to be no way to differentiate between 00:00 - 07:59 and 16:00 - 23:59.
From further discussion in the thread, it sounds like the day is written into the buffer
(buffer initially zero bits) and then the hour is xored into the buffer
with the bottom bit of day and top bit of hour mapped to the same buffer bit?
Is that even correct? Or could we have a correct hour and the day is just wrong?
http://www.rcgroups.com/forums/showpost.php?p=28158918&postcount=180
Midnight between 13th and 14th of March
0001110 0011 01110 0000 000000 000000 -> 14.3.14 00:00:00 -> 0
identical with
4PM, 14th of March
0001110 0011 01110 0000 000000 000000 -> 14.3.14 00:00:00 -> 0
From further discussion in the thread, it sounds like the day is written into the buffer
(buffer initially zero bits) and then the hour is xored into the buffer
with the bottom bit of day and top bit of hour mapped to the same buffer bit?
Is that even correct? Or could we have a correct hour and the day is just wrong?
Midnight between 14th and 15th of March
0001110 0011 01111 0000 000000 000000 -> 14.3.15 00:00:00 -> 16
identical with
4PM, 15th of March
0001110 0011 01111 0000 000000 000000 -> 14.3.15 00:00:00 -> 16
http://www.rcgroups.com/forums/showpost.php?p=28158918&postcount=180
Midnight between 13th and 14th of March
0001110 0011 01110 0000 000000 000000 -> 14.3.14 00:00:00 -> 0
identical with
4PM, 14th of March
0001110 0011 01110 0000 000000 000000 -> 14.3.14 00:00:00 -> 0
So as you can see even if we take 5 bits the hour is not correct either
Are they are xored? If we knew the date from a different source we would know the time.
Maybe the xor mask itself contains the bit. Does the mask change? and how? across the transitions.
Midnight between 14th and 15th of March
0001110 0011 01111 0000 000000 000000 -> 14.3.15 00:00:00 -> 16
identical with
4PM, 15th of March
0001110 0011 01111 0000 000000 000000 -> 14.3.15 00:00:00 -> 16
http://www.rcgroups.com/forums/showpost.php?p=28168741&postcount=182
Originally Posted by gwouite View Post
Question, are you sure that at 4PM, you're day value doesn't increase of 1 ?
It does, but it also does decrease by 1 at 8am so you have:
00:00 - 07:59 => day = X, hour = 0 - 7
08:00 - 15:59 => day = X - 1, hour = 8 - 15
16:00 - 23:59 => day = X, hour = 0 - 7
So as you can see even if we take 5 bits the hour is not correct either
Are they are xored? If we knew the date from a different source we would know the time.
Maybe the xor mask itself contains the bit. Does the mask change? and how? across the transitions.
http://www.rcgroups.com/forums/showpost.php?p=28782603&postcount=218
Here is the SBAS config from the Naza GPS
CFG-SBAS - 06 16 08 00 01 03 03 00 51 62 06 00
If I read it correctly EGNOS (PRN 124/124/126), MSAS (PRN 129/137) and WAAS (PRN 133/134/135/138) are enabled.
*/
http://www.rcgroups.com/forums/showpost.php?p=28168741&postcount=182
Originally Posted by gwouite View Post
Question, are you sure that at 4PM, you're day value doesn't increase of 1 ?
It does, but it also does decrease by 1 at 8am so you have:
00:00 - 07:59 => day = X, hour = 0 - 7
08:00 - 15:59 => day = X - 1, hour = 8 - 15
16:00 - 23:59 => day = X, hour = 0 - 7
http://www.rcgroups.com/forums/showpost.php?p=28782603&postcount=218
Here is the SBAS config from the Naza GPS
CFG-SBAS - 06 16 08 00 01 03 03 00 51 62 06 00
If I read it correctly EGNOS (PRN 124/124/126), MSAS (PRN 129/137) and WAAS (PRN 133/134/135/138) are enabled.
*/
// DJI GPS packet
struct DJI_GPS { // byte offset from beginning of packet, subtract 5 for struct offset
struct { // YYYYYYYMMMMDDDDDHHHHMMMMMMSSSSSS
uint32_t sec:6;
uint32_t min:6;
uint32_t hour:4;
uint32_t day:5;
uint32_t month:4;
uint32_t year:7;
}; // BYTE 5-8 (DT): date and time, see details above
struct DJI_GPS { // byte offset from beginning of packet, subtract 5 for struct offset
struct { // YYYYYYYMMMMDDDDDHHHHMMMMMMSSSSSS
uint32_t sec : 6;
uint32_t min : 6;
uint32_t hour : 4;
uint32_t day : 5;
uint32_t month : 4;
uint32_t year : 7;
}; // BYTE 5-8 (DT): date and time, see details above
int32_t lon; // BYTE 9-12 (LO): longitude (x10^7, degree decimal)
int32_t lat; // BYTE 13-16 (LA): latitude (x10^7, degree decimal)
int32_t hMSL; // BYTE 17-20 (AL): altitude (in millimeters) (is this MSL or geoid?)
uint32_t hAcc; // BYTE 21-24 (HA): horizontal accuracy estimate (see uBlox NAV-POSLLH message for details)
uint32_t vAcc; // BYTE 25-28 (VA): vertical accuracy estimate (see uBlox NAV-POSLLH message for details)
uint32_t unused1; // BYTE 29-32: ??? (seems to be always 0)
uint32_t hAcc; // BYTE 21-24 (HA): horizontal accuracy estimate (see uBlox NAV-POSLLH message for details)
uint32_t vAcc; // BYTE 25-28 (VA): vertical accuracy estimate (see uBlox NAV-POSLLH message for details)
uint32_t unused1; // BYTE 29-32: ??? (seems to be always 0)
int32_t velN; // BYTE 33-36 (NV): NED north velocity (see uBlox NAV-VELNED message for details)
int32_t velE; // BYTE 37-40 (EV): NED east velocity (see uBlox NAV-VELNED message for details)
int32_t velD; // BYTE 41-44 (DV): NED down velocity (see uBlox NAV-VELNED message for details)
uint16_t pDOP; // BYTE 45-46 (PD): position DOP (see uBlox NAV-DOP message for details)
uint16_t vDOP; // BYTE 47-48 (VD): vertical DOP (see uBlox NAV-DOP message for details)
uint16_t nDOP; // BYTE 49-50 (ND): northing DOP (see uBlox NAV-DOP message for details)
uint16_t eDOP; // BYTE 51-52 (ED): easting DOP (see uBlox NAV-DOP message for details)
uint16_t pDOP; // BYTE 45-46 (PD): position DOP (see uBlox NAV-DOP message for details)
uint16_t vDOP; // BYTE 47-48 (VD): vertical DOP (see uBlox NAV-DOP message for details)
uint16_t nDOP; // BYTE 49-50 (ND): northing DOP (see uBlox NAV-DOP message for details)
uint16_t eDOP; // BYTE 51-52 (ED): easting DOP (see uBlox NAV-DOP message for details)
uint8_t numSV; // BYTE 53 (NS): number of satellites (not XORed)
uint8_t unused2; // BYTE 54: ??? (not XORed, seems to be always 0)
uint8_t fixType; // BYTE 55 (FT): fix type (0 - no lock, 2 - 2D lock, 3 - 3D lock, not sure if other values can be expected
// see uBlox NAV-SOL message for details)
uint8_t unused3; // BYTE 56: ??? (seems to be always 0)
uint8_t flags; // BYTE 57 (SF): fix status flags (see uBlox NAV-SOL message for details)
uint16_t unused4; // BYTE 58-59: ??? (seems to be always 0)
uint16_t unused4; // BYTE 58-59: ??? (seems to be always 0)
uint8_t unused5; // BYTE 60 (XM): not sure yet, but I use it as the XOR mask
uint16_t seqNo; // BYTE 61-62 (SN): sequence number (not XORed), once there is a lock
// increases with every message. When the lock is lost later LSB and MSB are swapped with every message.
uint16_t seqNo; // BYTE 61-62 (SN): sequence number (not XORed), once there is a lock
// increases with every message. When the lock is lost later LSB and MSB are swapped with every message.
} __attribute__((packed));
#define FLAGS_GPSFIX_OK (1 << 0)
#define FLAGS_DIFFSOLN (1 << 1)
#define FLAGS_WKNSET (1 << 2)
#define FLAGS_TOWSET (1 << 3)
#define FLAGS_GPSFIX_OK (1 << 0)
#define FLAGS_DIFFSOLN (1 << 1)
#define FLAGS_WKNSET (1 << 2)
#define FLAGS_TOWSET (1 << 3)
#define FIXTYPE_NO_FIX 0
#define FIXTYPE_DEAD_RECKON 0x01 // Dead Reckoning only
#define FIXTYPE_2D 0x02 // 2D-Fix
#define FIXTYPE_3D 0x03 // 3D-Fix
#define FIXTYPE_GNSS_DEAD_RECKON 0x04 // GNSS + dead reckoning combined
#define FIXTYPE_TIME_ONLY 0x05 // Time only fix
#define FIXTYPE_NO_FIX 0
#define FIXTYPE_DEAD_RECKON 0x01 // Dead Reckoning only
#define FIXTYPE_2D 0x02 // 2D-Fix
#define FIXTYPE_3D 0x03 // 3D-Fix
#define FIXTYPE_GNSS_DEAD_RECKON 0x04 // GNSS + dead reckoning combined
#define FIXTYPE_TIME_ONLY 0x05 // Time only fix
/*
mag protocol info from
http://www.rcgroups.com/forums/showpost.php?p=26248426&postcount=62
mag protocol info from
http://www.rcgroups.com/forums/showpost.php?p=26248426&postcount=62
The 0x20 message contains compass data. Here is the structure of the message,
fields marked with XX I'm not sure about yet. The others will be described below.
The 0x20 message contains compass data. Here is the structure of the message,
fields marked with XX I'm not sure about yet. The others will be described below.
55 AA 20 06 CX CX CY CY CZ CZ CS CS
55 AA 20 06 CX CX CY CY CZ CZ CS CS
Values in the message are stored in little endian.
Values in the message are stored in little endian.
HEADER
-------------
BYTE 1-2: message header - always 55 AA
BYTE 3: message id (0x20 for compass message)
BYTE 4: length of the payload (0x06 or 6 decimal for 0x20 message)
HEADER
-------------
BYTE 1-2: message header - always 55 AA
BYTE 3: message id (0x20 for compass message)
BYTE 4: length of the payload (0x06 or 6 decimal for 0x20 message)
PAYLOAD
--------------
BYTE 5-6 (CX): compass X axis data (signed) - see comments below
BYTE 7-8 (CY): compass Y axis data (signed) - see comments below
BYTE 9-10 (CZ): compass Z axis data (signed) - see comments below
PAYLOAD
--------------
BYTE 5-6 (CX): compass X axis data (signed) - see comments below
BYTE 7-8 (CY): compass Y axis data (signed) - see comments below
BYTE 9-10 (CZ): compass Z axis data (signed) - see comments below
CHECKSUM
-----------------
BYTE 11-12 (CS): checksum, calculated the same way as for uBlox binary messages
CHECKSUM
-----------------
BYTE 11-12 (CS): checksum, calculated the same way as for uBlox binary messages
All the bytes of the payload except 9th are XORed with a mask.
Mask is calculated based on the value of the 9th byte.
All the bytes of the payload except 9th are XORed with a mask.
Mask is calculated based on the value of the 9th byte.
If we index bits from LSB to MSB as 0-7 we have:
mask[0] = 9thByte[0] xor 9thByte[4]
mask[1] = 9thByte[1] xor 9thByte[5]
mask[2] = 9thByte[2] xor 9thByte[6]
mask[3] = 9thByte[3] xor 9thByte[7] xor 9thByte[0];
mask[4] = 9thByte[1];
mask[5] = 9thByte[2];
mask[6] = 9thByte[3];
mask[7] = 9thByte[4] xor 9thByte[0];
If we index bits from LSB to MSB as 0-7 we have:
mask[0] = 9thByte[0] xor 9thByte[4]
mask[1] = 9thByte[1] xor 9thByte[5]
mask[2] = 9thByte[2] xor 9thByte[6]
mask[3] = 9thByte[3] xor 9thByte[7] xor 9thByte[0];
mask[4] = 9thByte[1];
mask[5] = 9thByte[2];
mask[6] = 9thByte[3];
mask[7] = 9thByte[4] xor 9thByte[0];
To calculate the heading (not tilt compensated) you need to do atan2 on the resulting
y any a (y and x?) values, convert radians to degrees and add 360 if the result is negative.
*/
To calculate the heading (not tilt compensated) you need to do atan2 on the resulting
y any a (y and x?) values, convert radians to degrees and add 360 if the result is negative.
*/
struct DJI_MAG { // byte offset from beginning of packet, subtract 5 for struct offset
int16_t x; // BYTE 5-6 (CX): compass X axis data (signed) - see comments below
int16_t y; // BYTE 7-8 (CY): compass Y axis data (signed) - see comments below
int16_t z; // BYTE 9-10 (CZ): compass Z axis data (signed) - see comments below
int16_t x; // BYTE 5-6 (CX): compass X axis data (signed) - see comments below
int16_t y; // BYTE 7-8 (CY): compass Y axis data (signed) - see comments below
int16_t z; // BYTE 9-10 (CZ): compass Z axis data (signed) - see comments below
} __attribute__((packed));
/*
version info from
http://www.rcgroups.com/forums/showpost.php?p=27058649&postcount=120
version info from
http://www.rcgroups.com/forums/showpost.php?p=27058649&postcount=120
This is still to be confirmed but I believe the 0x30 message carries the GPS module hardware id and firmware version.
This is still to be confirmed but I believe the 0x30 message carries the GPS module hardware id and firmware version.
55 AA 30 0C XX XX XX XX FW FW FW FW HW HW HW HW CS CS
55 AA 30 0C XX XX XX XX FW FW FW FW HW HW HW HW CS CS
Note that you need to read version numbers backwards (02 01 00 06 means v6.0.1.2)
Note that you need to read version numbers backwards (02 01 00 06 means v6.0.1.2)
HEADER
-------------
BYTE 1-2: message header - always 55 AA
BYTE 3: message id (0x30 for GPS module versions message)
BYTE 4: length of the payload (0x0C or 12 decimal for 0x30 message)
HEADER
-------------
BYTE 1-2: message header - always 55 AA
BYTE 3: message id (0x30 for GPS module versions message)
BYTE 4: length of the payload (0x0C or 12 decimal for 0x30 message)
PAYLOAD
--------------
BYTE 5-8" ??? (seems to be always 0)
BYTE 9-12 (FW): firmware version
BYTE 13-16 (HW): hardware id
PAYLOAD
--------------
BYTE 5-8" ??? (seems to be always 0)
BYTE 9-12 (FW): firmware version
BYTE 13-16 (HW): hardware id
CHECKSUM
-----------------
BYTE 17-18 (CS): checksum, calculated the same way as for uBlox binary messages
*/
CHECKSUM
-----------------
BYTE 17-18 (CS): checksum, calculated the same way as for uBlox binary messages
*/
struct DJI_VER { // byte offset from beginning of packet, subtract 5 for struct offset
uint32_t unused1; // BYTE 5-8" ??? (seems to be always 0)
uint32_t swVersion; // BYTE 9-12 (FW): firmware version
uint32_t hwVersion; // BYTE 13-16 (HW): hardware id
struct DJI_VER { // byte offset from beginning of packet, subtract 5 for struct offset
uint32_t unused1; // BYTE 5-8" ??? (seems to be always 0)
uint32_t swVersion; // BYTE 9-12 (FW): firmware version
uint32_t hwVersion; // BYTE 13-16 (HW): hardware id
} __attribute__((packed));
typedef union {
uint8_t payload[0];
// Nav Class
struct DJI_GPS gps;
struct DJI_MAG mag;
struct DJI_VER ver;
struct DJI_GPS gps;
struct DJI_MAG mag;
struct DJI_VER ver;
} DJIPayload;
struct DJIHeader {
uint8_t id;
uint8_t len;
uint8_t ck_a; // these are not part of the dji header, they are actually in the trailer
uint8_t ck_b; // but they are kept here for parsing ease
uint8_t id;
uint8_t len;
uint8_t ck_a; // these are not part of the dji header, they are actually in the trailer
uint8_t ck_b; // but they are kept here for parsing ease
} __attribute__((packed));
struct DJIPacket {

View File

@ -387,7 +387,7 @@ static void processSamples3d(sensor_fetch_context *sensor_context, const PIOS_SE
#if defined(PIOS_INCLUDE_HMC5X83)
|| (sensor->type == PIOS_SENSORS_TYPE_3AXIS_AUXMAG)
#endif
) {
) {
float t = inv_count * scales[0];
samples[0] = ((float)sensor_context->accum[0].x * t);
samples[1] = ((float)sensor_context->accum[0].y * t);
@ -398,11 +398,13 @@ static void processSamples3d(sensor_fetch_context *sensor_context, const PIOS_SE
handleMag(samples, temperature);
PERF_MEASURE_PERIOD(counterMagPeriod);
return;
#if defined(PIOS_INCLUDE_HMC5X83)
case PIOS_SENSORS_TYPE_3AXIS_AUXMAG:
handleAuxMag(samples);
PERF_MEASURE_PERIOD(counterMagPeriod);
return;
#endif
default:
PERF_TRACK_VALUE(counterAccelSamples, sensor_context->count);
@ -632,7 +634,8 @@ static void settingsUpdatedCb(__attribute__((unused)) UAVObjEvent *objEv)
}
#if defined(PIOS_INCLUDE_HMC5X83)
void aux_hmc5x83_load_mag_settings() {
void aux_hmc5x83_load_mag_settings()
{
uint8_t magType = auxmagsupport_get_type();
if (magType == AUXMAGSETTINGS_TYPE_I2C || magType == AUXMAGSETTINGS_TYPE_FLEXI) {