kopia lustrzana https://github.com/rs1729/RS
Dropsonde RD94: ID, checksums
rodzic
a792c91df3
commit
64e866a17b
|
@ -22,16 +22,22 @@ int option_verbose = 0, // ausfuehrliche Anzeige
|
|||
rawin = 0;
|
||||
|
||||
typedef struct {
|
||||
int frnr1;
|
||||
int frnr2;
|
||||
int frnr;
|
||||
unsigned id;
|
||||
int week; int gpssec;
|
||||
int week; int gpstow;
|
||||
int jahr; int monat; int tag;
|
||||
int wday;
|
||||
int std; int min; int sek; int ms;
|
||||
double lat; double lon; double h;
|
||||
double lat; double lon; double alt;
|
||||
double X; double Y; double Z;
|
||||
double vX1; double vY1; double vZ1;
|
||||
int sats1;
|
||||
double vX2; double vY2; double vZ2;
|
||||
int sats2;
|
||||
double vN; double vE; double vU;
|
||||
double vH; double vD; double vD2;
|
||||
double P; double T; double U1; double U2;
|
||||
double bat; double iT;
|
||||
} gpx_t;
|
||||
|
||||
gpx_t gpx;
|
||||
|
@ -194,291 +200,6 @@ int read_bits_fsk(FILE *fp, int *bit, int *len) {
|
|||
return 0;
|
||||
}
|
||||
|
||||
/* ------------------------------------------------------------------------------------ */
|
||||
/*
|
||||
* Convert GPS Week and Seconds to Modified Julian Day.
|
||||
* - Adapted from sci.astro FAQ.
|
||||
* - Ignores UTC leap seconds.
|
||||
*/
|
||||
void Gps2Date(long GpsWeek, long GpsSeconds, int *Year, int *Month, int *Day) {
|
||||
|
||||
long GpsDays, Mjd;
|
||||
long J, C, Y, M;
|
||||
|
||||
GpsDays = GpsWeek * 7 + (GpsSeconds / 86400);
|
||||
Mjd = 44244 + GpsDays;
|
||||
|
||||
J = Mjd + 2468570;
|
||||
C = 4 * J / 146097;
|
||||
J = J - (146097 * C + 3) / 4;
|
||||
Y = 4000 * (J + 1) / 1461001;
|
||||
J = J - 1461 * Y / 4 + 31;
|
||||
M = 80 * J / 2447;
|
||||
*Day = J - 2447 * M / 80;
|
||||
J = M / 11;
|
||||
*Month = M + 2 - (12 * J);
|
||||
*Year = 100 * (C - 49) + Y + J;
|
||||
}
|
||||
/* ------------------------------------------------------------------------------------ */
|
||||
|
||||
|
||||
#define OFS (0x03) // HEADLEN/(2*BITS)
|
||||
#define pos_FrameNb (OFS+0x00) // 2 byte
|
||||
#define pos_GPSTOW (OFS+0x17) // 4 byte
|
||||
#define pos_GPSweek (OFS+0x1F) // 2 byte
|
||||
#define pos_GPSecefX (OFS+0x23) // 4 byte
|
||||
#define pos_GPSecefY (OFS+0x27) // 4 byte
|
||||
#define pos_GPSecefZ (OFS+0x2B) // 4 byte
|
||||
#define pos_GPSV (OFS+0x2F) // 4 byte...
|
||||
#define pos_GPSecefV1 (OFS+0x33) // 3*4 byte...
|
||||
#define pos_GPSecefV2 (OFS+0x49) // 3*4 byte...
|
||||
#define pos_sensorP (OFS+0x04) // 4 byte float32
|
||||
#define pos_sensorT (OFS+0x08) // 4 byte float32
|
||||
#define pos_sensorU1 (OFS+0x0C) // 4 byte float32
|
||||
#define pos_sensorU2 (OFS+0x10) // 4 byte float32
|
||||
#define pos_sensorTi (OFS+0x67) // 4 byte float32
|
||||
#define pos_ID (OFS+0x5C) // 4 byte ?
|
||||
#define pos_rev (OFS+0x60) // 2 byte char // e.g. "A5"
|
||||
|
||||
|
||||
int get_ID() {
|
||||
int i;
|
||||
unsigned byte;
|
||||
|
||||
byte = 0;
|
||||
for (i = 0; i < 4; i++) { // big endian?
|
||||
byte |= frame_bytes[pos_ID + i] << (24-8*i);
|
||||
}
|
||||
gpx.id = byte;
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
int get_FrameNb() {
|
||||
int i;
|
||||
unsigned byte;
|
||||
ui8_t frnr_bytes[4];
|
||||
int frnr;
|
||||
|
||||
for (i = 0; i < 2; i++) {
|
||||
byte = frame_bytes[pos_FrameNb + i];
|
||||
frnr_bytes[i] = byte;
|
||||
}
|
||||
frnr = frnr_bytes[0] + (frnr_bytes[1] << 8);
|
||||
gpx.frnr1 = frnr;
|
||||
|
||||
for (i = 0; i < 4; i++) {
|
||||
byte = frame_bytes[pos_FrameNb+2 + i];
|
||||
frnr_bytes[i] = byte;
|
||||
}
|
||||
gpx.frnr2 = frnr_bytes[0] | (frnr_bytes[1] << 8) | (frnr_bytes[2] << 16) | (frnr_bytes[3] << 24);
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
int get_GPSweek() {
|
||||
int i;
|
||||
unsigned byte;
|
||||
ui8_t gpsweek_bytes[2];
|
||||
int gpsweek;
|
||||
|
||||
for (i = 0; i < 2; i++) {
|
||||
byte = frame_bytes[pos_GPSweek + i];
|
||||
gpsweek_bytes[i] = byte;
|
||||
}
|
||||
|
||||
gpsweek = gpsweek_bytes[0] + (gpsweek_bytes[1] << 8);
|
||||
if (gpsweek < 0) { gpx.week = -1; return -1; }
|
||||
gpx.week = gpsweek;
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
char weekday[7][3] = { "So", "Mo", "Di", "Mi", "Do", "Fr", "Sa"};
|
||||
|
||||
int get_GPStime() {
|
||||
int i;
|
||||
unsigned byte;
|
||||
ui8_t gpstime_bytes[4];
|
||||
int gpstime = 0, // 32bit
|
||||
day;
|
||||
|
||||
for (i = 0; i < 4; i++) {
|
||||
byte = frame_bytes[pos_GPSTOW + i];
|
||||
gpstime_bytes[i] = byte;
|
||||
}
|
||||
|
||||
memcpy(&gpstime, gpstime_bytes, 4);
|
||||
gpx.ms = gpstime % 1000;
|
||||
gpstime /= 1000;
|
||||
|
||||
gpx.gpssec = gpstime;
|
||||
|
||||
day = gpstime / (24 * 3600);
|
||||
gpstime %= (24*3600);
|
||||
|
||||
if ((day < 0) || (day > 6)) return -1;
|
||||
gpx.wday = day;
|
||||
gpx.std = gpstime / 3600;
|
||||
gpx.min = (gpstime % 3600) / 60;
|
||||
gpx.sek = gpstime % 60;
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
#define EARTH_a 6378137.0
|
||||
#define EARTH_b 6356752.31424518
|
||||
#define EARTH_a2_b2 (EARTH_a*EARTH_a - EARTH_b*EARTH_b)
|
||||
|
||||
double a = EARTH_a,
|
||||
b = EARTH_b,
|
||||
a_b = EARTH_a2_b2,
|
||||
e2 = EARTH_a2_b2 / (EARTH_a*EARTH_a),
|
||||
ee2 = EARTH_a2_b2 / (EARTH_b*EARTH_b);
|
||||
|
||||
void ecef2elli(double X[], double *lat, double *lon, double *h) {
|
||||
double phi, lam, R, p, t;
|
||||
|
||||
lam = atan2( X[1] , X[0] );
|
||||
|
||||
p = sqrt( X[0]*X[0] + X[1]*X[1] );
|
||||
t = atan2( X[2]*a , p*b );
|
||||
|
||||
phi = atan2( X[2] + ee2 * b * sin(t)*sin(t)*sin(t) ,
|
||||
p - e2 * a * cos(t)*cos(t)*cos(t) );
|
||||
|
||||
R = a / sqrt( 1 - e2*sin(phi)*sin(phi) );
|
||||
*h = p / cos(phi) - R;
|
||||
|
||||
*lat = phi*180/M_PI;
|
||||
*lon = lam*180/M_PI;
|
||||
}
|
||||
|
||||
|
||||
int get_GPSkoord() {
|
||||
int i, k;
|
||||
unsigned byte;
|
||||
ui8_t XYZ_bytes[4];
|
||||
int XYZ; // 32bit
|
||||
double X[3], lat, lon, h;
|
||||
/*
|
||||
ui8_t gpsVel_bytes[4];
|
||||
int vel32; // 32bit
|
||||
double V[3], phi, lam, alpha, dir;
|
||||
*/
|
||||
|
||||
for (k = 0; k < 3; k++) {
|
||||
|
||||
for (i = 0; i < 4; i++) {
|
||||
byte = frame_bytes[pos_GPSecefX + 4*k + i];
|
||||
XYZ_bytes[i] = byte;
|
||||
}
|
||||
memcpy(&XYZ, XYZ_bytes, 4);
|
||||
X[k] = XYZ / 100.0;
|
||||
/*
|
||||
for (i = 0; i < 4; i++) {
|
||||
frame[pos_GPSecefV + 2*k + i];
|
||||
byte = byte ^ mask[(pos_GPSecefV + 2*k + i) % MASK_LEN];
|
||||
gpsVel_bytes[i] = byte;
|
||||
}
|
||||
vel32 = gpsVel_bytes[0] | gpsVel_bytes[1] << 8 | gpsVel_bytes[2] << 16 | gpsVel_bytes[3] << 24;
|
||||
V[k] = vel32 / 100.0;
|
||||
*/
|
||||
}
|
||||
|
||||
|
||||
// ECEF-Position
|
||||
ecef2elli(X, &lat, &lon, &h);
|
||||
gpx.lat = lat;
|
||||
gpx.lon = lon;
|
||||
gpx.h = h;
|
||||
if ((h < -1000) || (h > 80000)) return -1;
|
||||
|
||||
/*
|
||||
// ECEF-Velocities
|
||||
// ECEF-Vel -> NorthEastUp
|
||||
phi = lat*M_PI/180.0;
|
||||
lam = lon*M_PI/180.0;
|
||||
gpx.vN = -V[0]*sin(phi)*cos(lam) - V[1]*sin(phi)*sin(lam) + V[2]*cos(phi);
|
||||
gpx.vE = -V[0]*sin(lam) + V[1]*cos(lam);
|
||||
gpx.vU = V[0]*cos(phi)*cos(lam) + V[1]*cos(phi)*sin(lam) + V[2]*sin(phi);
|
||||
|
||||
// NEU -> HorDirVer
|
||||
gpx.vH = sqrt(gpx.vN*gpx.vN+gpx.vE*gpx.vE);
|
||||
//
|
||||
alpha = atan2(gpx.vN, gpx.vE)*180/M_PI; // ComplexPlane (von x-Achse nach links) - GeoMeteo (von y-Achse nach rechts)
|
||||
dir = 90-alpha; // z=x+iy= -> i*conj(z)=y+ix=re(i(pi/2-t)), Achsen und Drehsinn vertauscht
|
||||
if (dir < 0) dir += 360; // atan2(y,x)=atan(y/x)=pi/2-atan(x/y) , atan(1/t) = pi/2 - atan(t)
|
||||
gpx.vD2 = dir;
|
||||
//
|
||||
dir = atan2(gpx.vE, gpx.vN) * 180 / M_PI;
|
||||
if (dir < 0) dir += 360;
|
||||
gpx.vD = dir;
|
||||
*/
|
||||
return 0;
|
||||
}
|
||||
|
||||
int get_V() {
|
||||
int i, k;
|
||||
unsigned byte;
|
||||
ui8_t XYZ_bytes[4];
|
||||
int XYZ; // 32bit
|
||||
double X, V[3];
|
||||
double phi, lam, dir, vD, vH, vN, vE, vU;
|
||||
|
||||
|
||||
for (i = 0; i < 4; i++) {
|
||||
byte = frame_bytes[pos_GPSV + i];
|
||||
XYZ_bytes[i] = byte;
|
||||
}
|
||||
memcpy(&XYZ, XYZ_bytes, 4);
|
||||
X = XYZ / 100.0;
|
||||
if (option_verbose == 2) {
|
||||
printf(" # ");
|
||||
printf(" %6.2f ", X);
|
||||
}
|
||||
|
||||
for (k = 0; k < 3; k++) {
|
||||
for (i = 0; i < 4; i++) {
|
||||
byte = frame_bytes[pos_GPSecefV1 + 4*k + i];
|
||||
XYZ_bytes[i] = byte;
|
||||
}
|
||||
memcpy(&XYZ, XYZ_bytes, 4);
|
||||
V[k] = XYZ / 100.0;
|
||||
}
|
||||
if (option_verbose == 2) {
|
||||
printf(" # ");
|
||||
printf(" (%7.2f,%7.2f,%7.2f) ", V[0], V[1], V[2]);
|
||||
}
|
||||
|
||||
phi = gpx.lat*M_PI/180.0;
|
||||
lam = gpx.lon*M_PI/180.0;
|
||||
vN = -V[0]*sin(phi)*cos(lam) - V[1]*sin(phi)*sin(lam) + V[2]*cos(phi);
|
||||
vE = -V[0]*sin(lam) + V[1]*cos(lam);
|
||||
vU = V[0]*cos(phi)*cos(lam) + V[1]*cos(phi)*sin(lam) + V[2]*sin(phi);
|
||||
|
||||
vH = sqrt(vN*vN+vE*vE);
|
||||
dir = atan2(vE, vN) * 180 / M_PI;
|
||||
if (dir < 0) dir += 360;
|
||||
vD = dir;
|
||||
fprintf(stdout," vH: %.1fm/s D: %.1f° vV: %.1fm/s ", vH, vD, vU);
|
||||
|
||||
for (k = 0; k < 3; k++) {
|
||||
for (i = 0; i < 4; i++) {
|
||||
byte = frame_bytes[pos_GPSecefV2 + 4*k + i];
|
||||
XYZ_bytes[i] = byte;
|
||||
}
|
||||
memcpy(&XYZ, XYZ_bytes, 4);
|
||||
V[k] = XYZ / 100.0;
|
||||
}
|
||||
if (option_verbose == 2) {
|
||||
//printf(" # ");
|
||||
printf(" (%7.2f,%7.2f,%7.2f) ", V[0], V[1], V[2]);
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
/* ------------------------------------------------------------------------------------ */
|
||||
|
||||
|
||||
|
@ -559,6 +280,333 @@ int bits2bytes(char *bitstr, ui8_t *bytes) {
|
|||
return 0;
|
||||
}
|
||||
|
||||
|
||||
/* ------------------------------------------------------------------------------------ */
|
||||
/*
|
||||
* Convert GPS Week and Seconds to Modified Julian Day.
|
||||
* - Adapted from sci.astro FAQ.
|
||||
* - Ignores UTC leap seconds.
|
||||
*/
|
||||
void Gps2Date(long GpsWeek, long GpsSeconds, int *Year, int *Month, int *Day) {
|
||||
|
||||
long GpsDays, Mjd;
|
||||
long J, C, Y, M;
|
||||
|
||||
GpsDays = GpsWeek * 7 + (GpsSeconds / 86400);
|
||||
Mjd = 44244 + GpsDays;
|
||||
|
||||
J = Mjd + 2468570;
|
||||
C = 4 * J / 146097;
|
||||
J = J - (146097 * C + 3) / 4;
|
||||
Y = 4000 * (J + 1) / 1461001;
|
||||
J = J - 1461 * Y / 4 + 31;
|
||||
M = 80 * J / 2447;
|
||||
*Day = J - 2447 * M / 80;
|
||||
J = M / 11;
|
||||
*Month = M + 2 - (12 * J);
|
||||
*Year = 100 * (C - 49) + Y + J;
|
||||
}
|
||||
/* ------------------------------------------------------------------------------------ */
|
||||
|
||||
|
||||
#define OFS (0x02) // HEADLEN/(2*BITS)
|
||||
#define pos_FrameNb (OFS+0x01) // 2 byte
|
||||
#define pos_GPSTOW (OFS+0x18) // 4 byte...
|
||||
#define pos_GPSweek (OFS+0x20) // 2 byte
|
||||
#define pos_GPSecefX (OFS+0x24) // 4 byte
|
||||
#define pos_GPSecefY (OFS+0x28) // 4 byte
|
||||
#define pos_GPSecefZ (OFS+0x2C) // 4 byte
|
||||
#define pos_GPSV (OFS+0x30) // 4 byte...
|
||||
#define pos_GPSecefV1 (OFS+0x34) // 3*4 byte...
|
||||
#define pos_GPSecefV2 (OFS+0x4A) // 3*4 byte...
|
||||
#define pos_GPSsats1 (OFS+0x46) // 1 byte
|
||||
#define pos_GPSsats2 (OFS+0x5A) // 1 byte
|
||||
#define pos_sensorP (OFS+0x05) // 4 byte float32
|
||||
#define pos_sensorT (OFS+0x09) // 4 byte float32
|
||||
#define pos_sensorU1 (OFS+0x0D) // 4 byte float32
|
||||
#define pos_sensorU2 (OFS+0x11) // 4 byte float32
|
||||
#define pos_sensorTi (OFS+0x68) // 4 byte float32
|
||||
#define pos_ID (OFS+0x5D) // 4 byte
|
||||
#define pos_rev (OFS+0x61) // 2 byte char // e.g. "A5"
|
||||
#define pos_bat (OFS+0x66) // 2 byte
|
||||
#define pos_chkFrNb (pos_FrameNb-1 + 3) // 16 bit
|
||||
#define pos_chkPTU (pos_sensorP + 17) // 16 bit
|
||||
#define pos_chkGPS1 (pos_GPSTOW + 47) // 16 bit
|
||||
#define pos_chkGPS2 (pos_GPSecefV2-1 + 18) // 16 bit
|
||||
#define pos_chkIntern (pos_ID + 21) // 16 bit
|
||||
|
||||
|
||||
unsigned check16(ui8_t *bytes, int len) {
|
||||
unsigned sum1, sum2;
|
||||
int i;
|
||||
sum1 = sum2 = 0;
|
||||
for (i = 0; i < len; i++) {
|
||||
sum1 = (sum1 + bytes[i]) % 0x100;
|
||||
sum2 = (sum2 + sum1) % 0x100;
|
||||
}
|
||||
//return sum1 | (sum2<<8);
|
||||
return sum2 | (sum1<<8);
|
||||
}
|
||||
|
||||
unsigned chkFrame() {
|
||||
unsigned byte;
|
||||
unsigned checksum;
|
||||
int err = 0;
|
||||
|
||||
byte = check16(frame_bytes+pos_chkFrNb-3, 3);
|
||||
checksum = (frame_bytes[pos_chkFrNb]<<8) | frame_bytes[pos_chkFrNb+1];
|
||||
if (byte != checksum) err |= (0x1 << 0);
|
||||
|
||||
byte = check16(frame_bytes+pos_chkPTU-17, 17);
|
||||
checksum = (frame_bytes[pos_chkPTU]<<8) | frame_bytes[pos_chkPTU+1];
|
||||
if (byte != checksum) err |= (0x1 << 1);
|
||||
|
||||
byte = check16(frame_bytes+pos_chkGPS1-47, 47);
|
||||
checksum = (frame_bytes[pos_chkGPS1]<<8) | frame_bytes[pos_chkGPS1+1];
|
||||
if (byte != checksum) err |= (0x1 << 2);
|
||||
|
||||
byte = check16(frame_bytes+pos_chkGPS2-18, 18);
|
||||
checksum = (frame_bytes[pos_chkGPS2]<<8) | frame_bytes[pos_chkGPS2+1];
|
||||
if (byte != checksum) err |= (0x1 << 3);
|
||||
|
||||
byte = check16(frame_bytes+pos_chkIntern-21, 21);
|
||||
checksum = (frame_bytes[pos_chkIntern]<<8) | frame_bytes[pos_chkIntern+1];
|
||||
if (byte != checksum) err |= (0x1 << 4);
|
||||
|
||||
return err;
|
||||
}
|
||||
|
||||
int get_ID() {
|
||||
int i;
|
||||
unsigned byte;
|
||||
|
||||
byte = 0;
|
||||
for (i = 0; i < 4; i++) { // big endian
|
||||
byte |= frame_bytes[pos_ID + i] << (24-8*i);
|
||||
}
|
||||
gpx.id = byte;
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
int get_FrameNb() {
|
||||
int i;
|
||||
unsigned byte;
|
||||
ui8_t frnr_bytes[4];
|
||||
int frnr;
|
||||
|
||||
for (i = 0; i < 2; i++) {
|
||||
byte = frame_bytes[pos_FrameNb + i];
|
||||
frnr_bytes[i] = byte;
|
||||
}
|
||||
frnr = frnr_bytes[0] + (frnr_bytes[1] << 8);
|
||||
gpx.frnr = frnr;
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
int get_GPSweek() {
|
||||
int i;
|
||||
unsigned byte;
|
||||
ui8_t gpsweek_bytes[2];
|
||||
int gpsweek;
|
||||
|
||||
for (i = 0; i < 2; i++) {
|
||||
byte = frame_bytes[pos_GPSweek + i];
|
||||
gpsweek_bytes[i] = byte;
|
||||
}
|
||||
|
||||
gpsweek = gpsweek_bytes[0] + (gpsweek_bytes[1] << 8);
|
||||
if (gpsweek < 0) { gpx.week = -1; return -1; }
|
||||
gpx.week = gpsweek;
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
char weekday[7][3] = { "So", "Mo", "Di", "Mi", "Do", "Fr", "Sa"};
|
||||
|
||||
int get_GPStime() {
|
||||
int i;
|
||||
unsigned byte;
|
||||
ui8_t gpstime_bytes[4];
|
||||
int gpstime = 0, // 32bit
|
||||
day;
|
||||
|
||||
for (i = 0; i < 4; i++) {
|
||||
byte = frame_bytes[pos_GPSTOW + i];
|
||||
gpstime_bytes[i] = byte;
|
||||
}
|
||||
|
||||
memcpy(&gpstime, gpstime_bytes, 4);
|
||||
gpx.ms = gpstime % 1000;
|
||||
gpstime /= 1000;
|
||||
|
||||
gpx.gpstow = gpstime;
|
||||
|
||||
day = gpstime / (24 * 3600);
|
||||
gpstime %= (24*3600);
|
||||
|
||||
if ((day < 0) || (day > 6)) return -1;
|
||||
gpx.wday = day;
|
||||
gpx.std = gpstime / 3600;
|
||||
gpx.min = (gpstime % 3600) / 60;
|
||||
gpx.sek = gpstime % 60;
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
#define EARTH_a 6378137.0
|
||||
#define EARTH_b 6356752.31424518
|
||||
#define EARTH_a2_b2 (EARTH_a*EARTH_a - EARTH_b*EARTH_b)
|
||||
|
||||
double a = EARTH_a,
|
||||
b = EARTH_b,
|
||||
a_b = EARTH_a2_b2,
|
||||
e2 = EARTH_a2_b2 / (EARTH_a*EARTH_a),
|
||||
ee2 = EARTH_a2_b2 / (EARTH_b*EARTH_b);
|
||||
|
||||
void ecef2elli(double X[], double *lat, double *lon, double *h) {
|
||||
double phi, lam, R, p, t;
|
||||
|
||||
lam = atan2( X[1] , X[0] );
|
||||
|
||||
p = sqrt( X[0]*X[0] + X[1]*X[1] );
|
||||
t = atan2( X[2]*a , p*b );
|
||||
|
||||
phi = atan2( X[2] + ee2 * b * sin(t)*sin(t)*sin(t) ,
|
||||
p - e2 * a * cos(t)*cos(t)*cos(t) );
|
||||
|
||||
R = a / sqrt( 1 - e2*sin(phi)*sin(phi) );
|
||||
*h = p / cos(phi) - R;
|
||||
|
||||
*lat = phi*180/M_PI;
|
||||
*lon = lam*180/M_PI;
|
||||
}
|
||||
|
||||
|
||||
int get_GPSkoord() {
|
||||
int i, k;
|
||||
unsigned byte;
|
||||
ui8_t XYZ_bytes[4];
|
||||
int XYZ; // 32bit
|
||||
double X[3], lat, lon, h;
|
||||
|
||||
for (k = 0; k < 3; k++) {
|
||||
|
||||
for (i = 0; i < 4; i++) {
|
||||
byte = frame_bytes[pos_GPSecefX + 4*k + i];
|
||||
XYZ_bytes[i] = byte;
|
||||
}
|
||||
memcpy(&XYZ, XYZ_bytes, 4);
|
||||
X[k] = XYZ / 100.0;
|
||||
|
||||
}
|
||||
|
||||
// ECEF-Position
|
||||
ecef2elli(X, &lat, &lon, &h);
|
||||
gpx.lat = lat;
|
||||
gpx.lon = lon;
|
||||
gpx.alt = h;
|
||||
if ((h < -1000) || (h > 80000)) return -1;
|
||||
|
||||
|
||||
/*
|
||||
for (k = 0; k < 3; k++) {
|
||||
for (i = 0; i < 4; i++) {
|
||||
byte = frame_bytes[pos_GPSecefV1 + 4*k + i];
|
||||
XYZ_bytes[i] = byte;
|
||||
}
|
||||
memcpy(&XYZ, XYZ_bytes, 4);
|
||||
V[k] = XYZ / 100.0;
|
||||
}
|
||||
|
||||
// ECEF-Velocities
|
||||
// ECEF-Vel -> NorthEastUp
|
||||
phi = lat*M_PI/180.0;
|
||||
lam = lon*M_PI/180.0;
|
||||
gpx.vN = -V[0]*sin(phi)*cos(lam) - V[1]*sin(phi)*sin(lam) + V[2]*cos(phi);
|
||||
gpx.vE = -V[0]*sin(lam) + V[1]*cos(lam);
|
||||
gpx.vU = V[0]*cos(phi)*cos(lam) + V[1]*cos(phi)*sin(lam) + V[2]*sin(phi);
|
||||
|
||||
// NEU -> HorDirVer
|
||||
gpx.vH = sqrt(gpx.vN*gpx.vN+gpx.vE*gpx.vE);
|
||||
//
|
||||
alpha = atan2(gpx.vN, gpx.vE)*180/M_PI; // ComplexPlane (von x-Achse nach links) - GeoMeteo (von y-Achse nach rechts)
|
||||
dir = 90-alpha; // z=x+iy= -> i*conj(z)=y+ix=re(i(pi/2-t)), Achsen und Drehsinn vertauscht
|
||||
if (dir < 0) dir += 360; // atan2(y,x)=atan(y/x)=pi/2-atan(x/y) , atan(1/t) = pi/2 - atan(t)
|
||||
gpx.vD2 = dir;
|
||||
//
|
||||
dir = atan2(gpx.vE, gpx.vN) * 180 / M_PI;
|
||||
if (dir < 0) dir += 360;
|
||||
gpx.vD = dir;
|
||||
*/
|
||||
return 0;
|
||||
}
|
||||
|
||||
int get_V() {
|
||||
int i, k;
|
||||
unsigned byte;
|
||||
ui8_t XYZ_bytes[4];
|
||||
int XYZ; // 32bit
|
||||
double V[3];
|
||||
double phi, lam, dir;
|
||||
|
||||
/*
|
||||
double X;
|
||||
for (i = 0; i < 4; i++) {
|
||||
byte = frame_bytes[pos_GPSV + i];
|
||||
XYZ_bytes[i] = byte;
|
||||
}
|
||||
memcpy(&XYZ, XYZ_bytes, 4);
|
||||
X = XYZ / 100.0;
|
||||
if (option_verbose == 2) {
|
||||
printf(" # ");
|
||||
printf(" %6.2f ", X);
|
||||
}
|
||||
*/
|
||||
|
||||
for (k = 0; k < 3; k++) {
|
||||
for (i = 0; i < 4; i++) {
|
||||
byte = frame_bytes[pos_GPSecefV1 + 4*k + i];
|
||||
XYZ_bytes[i] = byte;
|
||||
}
|
||||
memcpy(&XYZ, XYZ_bytes, 4);
|
||||
V[k] = XYZ / 100.0;
|
||||
}
|
||||
gpx.vX1 = V[0];
|
||||
gpx.vY1 = V[1];
|
||||
gpx.vZ1 = V[2];
|
||||
gpx.sats1 = frame_bytes[pos_GPSsats1];
|
||||
|
||||
phi = gpx.lat*M_PI/180.0;
|
||||
lam = gpx.lon*M_PI/180.0;
|
||||
gpx.vN = -V[0]*sin(phi)*cos(lam) - V[1]*sin(phi)*sin(lam) + V[2]*cos(phi);
|
||||
gpx.vE = -V[0]*sin(lam) + V[1]*cos(lam);
|
||||
gpx.vU = V[0]*cos(phi)*cos(lam) + V[1]*cos(phi)*sin(lam) + V[2]*sin(phi);
|
||||
|
||||
gpx.vH = sqrt(gpx.vN*gpx.vN+gpx.vE*gpx.vE);
|
||||
dir = atan2(gpx.vE, gpx.vN) * 180 / M_PI;
|
||||
if (dir < 0) dir += 360;
|
||||
gpx.vD = dir;
|
||||
|
||||
|
||||
for (k = 0; k < 3; k++) {
|
||||
for (i = 0; i < 4; i++) {
|
||||
byte = frame_bytes[pos_GPSecefV2 + 4*k + i];
|
||||
XYZ_bytes[i] = byte;
|
||||
}
|
||||
memcpy(&XYZ, XYZ_bytes, 4);
|
||||
V[k] = XYZ / 100.0;
|
||||
}
|
||||
gpx.vX2 = V[0];
|
||||
gpx.vY2 = V[1];
|
||||
gpx.vZ2 = V[2];
|
||||
gpx.sats2 = frame_bytes[pos_GPSsats2];
|
||||
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
float float32(unsigned idx) {
|
||||
int i;
|
||||
unsigned num, val;
|
||||
|
@ -589,8 +637,31 @@ float float32(unsigned idx) {
|
|||
return f;
|
||||
}
|
||||
|
||||
int get_Sensors1() {
|
||||
|
||||
gpx.P = float32(pos_sensorP);
|
||||
gpx.T = float32(pos_sensorT);
|
||||
gpx.U1 = float32(pos_sensorU1);
|
||||
gpx.U2 = float32(pos_sensorU2);
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
int get_Sensors2() {
|
||||
int val;
|
||||
|
||||
gpx.iT = float32(pos_sensorTi);
|
||||
|
||||
val = frame_bytes[pos_bat] | (frame_bytes[pos_bat+1]<<8);
|
||||
gpx.bat = val/1e3;
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
||||
void print_frame(int len) {
|
||||
int i, err;
|
||||
int i, err=0;
|
||||
unsigned chk=0;
|
||||
|
||||
for (i = len; i < RAWBITFRAME_LEN; i++) frame_rawbits[i] = '0';
|
||||
manchester2(frame_rawbits, frame_bits);
|
||||
|
@ -602,7 +673,8 @@ void print_frame(int len) {
|
|||
fprintf(stdout, "%02x", frame_bytes[i]);
|
||||
//fprintf(stdout, "%02X ", frame_bytes[i]);
|
||||
if (option_raw == 2) {
|
||||
if ( i==2 || i==4 // frame-counter
|
||||
if ( i==1
|
||||
|| i==2 || i==4 // frame-counter
|
||||
|| i==6 || i==10 || i==14 || i==18 // sensors (P,T,U1,U2)
|
||||
|| i==22 || i==23
|
||||
|| i==25 || i==29 // TOW
|
||||
|
@ -611,14 +683,23 @@ void print_frame(int len) {
|
|||
|| i==49
|
||||
|| i==53 || i==57 || i==61 // ECEF-vel1
|
||||
|| i==65 || i==69
|
||||
|| i==71 || i==72 // sats-1
|
||||
|| i==74
|
||||
|| i==75 || i==79 || i==83 // ECEF-vel2
|
||||
|| i==87 || i==91
|
||||
|| i==94 || i==98 || i==100 // SondeID?Rev?
|
||||
|| i==103 || i==104
|
||||
|| i==105 || i==109
|
||||
|| i==110 || i==112 || i==113
|
||||
|| i==87
|
||||
|| i==91 || i==92 // sats-2
|
||||
|| i==94 || i==98 || i==100 // SondeID, Rev?
|
||||
|| i==103 // bat
|
||||
|| i==105 || i==109 // internT
|
||||
//|| i==110 || i==112 || i==113
|
||||
|| i==115 || i==117
|
||||
) fprintf(stdout, " ");
|
||||
|
||||
if ( i==pos_chkFrNb +1 ) fprintf(stdout, "[%04X] ", check16(frame_bytes+pos_chkFrNb-3, 3)); // OK
|
||||
if ( i==pos_chkPTU +1 ) fprintf(stdout, "[%04X] ", check16(frame_bytes+pos_chkPTU-17, 17)); // OK
|
||||
if ( i==pos_chkGPS1 +1 ) fprintf(stdout, "[%04X] ", check16(frame_bytes+pos_chkGPS1-47, 47)); // OK
|
||||
if ( i==pos_chkGPS2 +1 ) fprintf(stdout, "[%04X] ", check16(frame_bytes+pos_chkGPS2-18, 18)); // OK
|
||||
if ( i==pos_chkIntern+1 ) fprintf(stdout, "[%04X] ", check16(frame_bytes+pos_chkIntern-21, 21)); // OK
|
||||
}
|
||||
}
|
||||
fprintf(stdout, "\n");
|
||||
|
@ -631,9 +712,8 @@ void print_frame(int len) {
|
|||
err |= get_GPStime();
|
||||
err |= get_GPSkoord();
|
||||
if (!err) {
|
||||
Gps2Date(gpx.week, gpx.gpssec, &gpx.jahr, &gpx.monat, &gpx.tag);
|
||||
fprintf(stdout, "[%5d] ", gpx.frnr1);
|
||||
//fprintf(stdout, "0x%08X ", gpx.frnr2);
|
||||
Gps2Date(gpx.week, gpx.gpstow, &gpx.jahr, &gpx.monat, &gpx.tag);
|
||||
fprintf(stdout, "[%5d] ", gpx.frnr);
|
||||
fprintf(stdout, "%s ", weekday[gpx.wday]);
|
||||
fprintf(stdout, "%04d-%02d-%02d %02d:%02d:%02d.%03d",
|
||||
gpx.jahr, gpx.monat, gpx.tag, gpx.std, gpx.min, gpx.sek, gpx.ms);
|
||||
|
@ -641,27 +721,43 @@ void print_frame(int len) {
|
|||
fprintf(stdout, " ");
|
||||
fprintf(stdout, " lat: %.5f° ", gpx.lat);
|
||||
fprintf(stdout, " lon: %.5f° ", gpx.lon);
|
||||
fprintf(stdout, " alt: %.2fm ", gpx.h);
|
||||
/*
|
||||
if (option_verbose) {
|
||||
//fprintf(stdout, " (%.1f %.1f %.1f) ", gpx.vN, gpx.vE, gpx.vU);
|
||||
fprintf(stdout," vH: %.1f D: %.1f° vV: %.1f ", gpx.vH, gpx.vD, gpx.vU);
|
||||
}
|
||||
*/
|
||||
if (len > 2*BITS*(pos_GPSecefV2+12)) get_V();
|
||||
get_ID();
|
||||
fprintf(stdout, " alt: %.2fm ", gpx.alt);
|
||||
|
||||
if (option_verbose && frame_bytes[OFS+115] == 0x1A) {
|
||||
|
||||
//if (len > 2*BITS*(pos_GPSecefV2+12))
|
||||
get_V();
|
||||
if (option_verbose) fprintf(stdout," sats: %d ", gpx.sats1);
|
||||
if (option_verbose == 2) {
|
||||
fprintf(stdout," (%7.2f,%7.2f,%7.2f) ", gpx.vX1, gpx.vY1, gpx.vZ1);
|
||||
}
|
||||
fprintf(stdout," vH: %.1fm/s D: %.1f° vV: %.1fm/s ", gpx.vH, gpx.vD, gpx.vU);
|
||||
if (option_verbose == 2) {
|
||||
fprintf(stdout," (%7.2f,%7.2f,%7.2f) ", gpx.vX2, gpx.vY2, gpx.vZ2);
|
||||
fprintf(stdout," sats: %d ", gpx.sats2);
|
||||
}
|
||||
|
||||
|
||||
get_ID();
|
||||
get_Sensors1();
|
||||
fprintf(stdout, " ");
|
||||
fprintf(stdout, " P=%.2fhPa ", gpx.P);
|
||||
fprintf(stdout, " T=%.2f°C ", gpx.T);
|
||||
fprintf(stdout, " H1=%.2f%% ", gpx.U1);
|
||||
fprintf(stdout, " H2=%.2f%% ", gpx.U2);
|
||||
fprintf(stdout, " ");
|
||||
fprintf(stdout, " (%d) ", gpx.id);
|
||||
|
||||
if (option_verbose && frame_bytes[OFS+116] == 0x1A) {
|
||||
get_Sensors2();
|
||||
fprintf(stdout, " ");
|
||||
fprintf(stdout, " P=%.2fhPa ", float32(pos_sensorP));
|
||||
fprintf(stdout, " T=%.2f°C ", float32(pos_sensorT));
|
||||
fprintf(stdout, " H1=%.2f%% ", float32(pos_sensorU1));
|
||||
fprintf(stdout, " H2=%.2f%% ", float32(pos_sensorU2));
|
||||
fprintf(stdout, " Ti=%.2f°C ", float32(pos_sensorTi));
|
||||
fprintf(stdout, " Ti=%.2f°C ", gpx.iT);
|
||||
fprintf(stdout, " Bat=%.2fV ", gpx.bat);
|
||||
}
|
||||
|
||||
chk = chkFrame();
|
||||
printf(" Check: ");
|
||||
for (i = 0; i < 5; i++) printf("%d", (chk>>i)&1);
|
||||
|
||||
fprintf(stdout, "\n"); // fflush(stdout);
|
||||
}
|
||||
}
|
||||
|
|
Ładowanie…
Reference in New Issue