AP_GPS: move byte swapping code to cpp

This commit is contained in:
Andrew Tridgell 2013-04-28 14:51:37 +10:00
parent 84ed37938d
commit f5d062d5ba
2 changed files with 32 additions and 34 deletions

View File

@ -179,3 +179,33 @@ void GPS::_update_progstr(void)
}
}
}
int32_t GPS::_swapl(const void *bytes) const
{
const uint8_t *b = (const uint8_t *)bytes;
union {
int32_t v;
uint8_t b[4];
} u;
u.b[0] = b[3];
u.b[1] = b[2];
u.b[2] = b[1];
u.b[3] = b[0];
return(u.v);
}
int16_t GPS::_swapi(const void *bytes) const
{
const uint8_t *b = (const uint8_t *)bytes;
union {
int16_t v;
uint8_t b[2];
} u;
u.b[0] = b[1];
u.b[1] = b[0];
return(u.v);
}

View File

@ -168,14 +168,14 @@ protected:
/// long in the wrong byte order
/// @returns endian-swapped value
///
int32_t _swapl(const void *bytes);
int32_t _swapl(const void *bytes) const;
/// perform an endian swap on an int
///
/// @param bytes pointer to a buffer containing bytes representing an
/// int in the wrong byte order
/// @returns endian-swapped value
int16_t _swapi(const void *bytes);
int16_t _swapi(const void *bytes) const;
/// emit an error message
///
@ -228,36 +228,4 @@ private:
float _velocity_down;
};
inline int32_t
GPS::_swapl(const void *bytes)
{
const uint8_t *b = (const uint8_t *)bytes;
union {
int32_t v;
uint8_t b[4];
} u;
u.b[0] = b[3];
u.b[1] = b[2];
u.b[2] = b[1];
u.b[3] = b[0];
return(u.v);
}
inline int16_t
GPS::_swapi(const void *bytes)
{
const uint8_t *b = (const uint8_t *)bytes;
union {
int16_t v;
uint8_t b[2];
} u;
u.b[0] = b[1];
u.b[1] = b[0];
return(u.v);
}
#endif // __GPS_H__