Fixed issues in grid unpacking
This commit is contained in:
parent
a8d963cdfd
commit
73dd8e2709
2 changed files with 29 additions and 16 deletions
|
@ -84,13 +84,17 @@ void int_to_dd(char *str, int value, int width) {
|
||||||
++str;
|
++str;
|
||||||
value = -value;
|
value = -value;
|
||||||
}
|
}
|
||||||
|
else {
|
||||||
|
*str = '+';
|
||||||
|
++str;
|
||||||
|
}
|
||||||
|
|
||||||
int divisor = 1;
|
int divisor = 1;
|
||||||
for (int i = 0; i < width; ++i) {
|
for (int i = 0; i < width - 1; ++i) {
|
||||||
divisor *= 10;
|
divisor *= 10;
|
||||||
}
|
}
|
||||||
|
|
||||||
while (divisor > 1) {
|
while (divisor >= 1) {
|
||||||
int digit = value / divisor;
|
int digit = value / divisor;
|
||||||
|
|
||||||
*str = '0' + digit;
|
*str = '0' + digit;
|
||||||
|
|
|
@ -46,13 +46,23 @@ void unpackgrid(uint16_t ng, char *grid) {
|
||||||
constexpr uint16_t NGBASE = 180*180;
|
constexpr uint16_t NGBASE = 180*180;
|
||||||
|
|
||||||
if (ng == NGBASE + 1) {
|
if (ng == NGBASE + 1) {
|
||||||
|
// Empty grid is allowed
|
||||||
grid[0] = 0;
|
grid[0] = 0;
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
// if ng >= NGBASE+1 and ng < NGBASE+31:
|
|
||||||
// return " -%02d" % (ng - (NGBASE+1)) // sig str, -01 to -30 DB
|
// Check for signal strength reports (-01 to -30 dB)
|
||||||
// if ng >= NGBASE+31 and ng < NGBASE+62:
|
if (ng >= NGBASE + 1 && ng < NGBASE + 31) {
|
||||||
// return "R-%02d" % (ng - (NGBASE+31))
|
int_to_dd(grid, ((NGBASE + 1) - ng), 2);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
if (ng >= NGBASE + 31 && ng < NGBASE + 62) {
|
||||||
|
grid[0] = 'R';
|
||||||
|
int_to_dd(grid + 1, ((NGBASE + 31) - ng), 2);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
// Check for special cases
|
||||||
if (ng == NGBASE + 62) {
|
if (ng == NGBASE + 62) {
|
||||||
strcpy(grid, "RO");
|
strcpy(grid, "RO");
|
||||||
return;
|
return;
|
||||||
|
@ -66,6 +76,7 @@ void unpackgrid(uint16_t ng, char *grid) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Decode 4-symbol grid
|
||||||
int16_t lat = (int16_t)(ng % 180) - 90;
|
int16_t lat = (int16_t)(ng % 180) - 90;
|
||||||
int16_t lng = ((int16_t)(ng / 180) * 2) - 180;
|
int16_t lng = ((int16_t)(ng / 180) * 2) - 180;
|
||||||
|
|
||||||
|
@ -75,16 +86,16 @@ void unpackgrid(uint16_t ng, char *grid) {
|
||||||
grid[3] = '0' + ((90 + lat) % 10);
|
grid[3] = '0' + ((90 + lat) % 10);
|
||||||
grid[4] = 0;
|
grid[4] = 0;
|
||||||
|
|
||||||
|
// Check for extended range signal reports
|
||||||
if ((grid[0] == 'K') && (grid[1] == 'A')) {
|
if ((grid[0] == 'K') && (grid[1] == 'A')) {
|
||||||
// really + signal strength
|
int sig = dd_to_int(grid + 2, 2) - 50;
|
||||||
// sig = int(g[2:4]) - 50
|
int_to_dd(grid, sig, 2);
|
||||||
// return "+%02d" % (sig)
|
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
else if ((grid[0] == 'L') && (grid[1] == 'A')) {
|
if ((grid[0] == 'L') && (grid[1] == 'A')) {
|
||||||
// really R+ signal strength
|
int sig = dd_to_int(grid + 2, 2) - 50;
|
||||||
// sig = int(g[2:4]) - 50
|
grid[0] = 'R';
|
||||||
// return "R+%02d" % (sig)
|
int_to_dd(grid + 1, sig, 2);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -136,7 +147,7 @@ int unpack(const uint8_t *a72, char *message) {
|
||||||
nc2 |= (a72[5] << 8);
|
nc2 |= (a72[5] << 8);
|
||||||
nc2 |= (a72[6]);
|
nc2 |= (a72[6]);
|
||||||
|
|
||||||
ng = (a72[7] >> 8);
|
ng = (a72[7] << 8);
|
||||||
ng |= (a72[8]);
|
ng |= (a72[8]);
|
||||||
|
|
||||||
if (ng & 0x8000) {
|
if (ng & 0x8000) {
|
||||||
|
@ -200,7 +211,5 @@ int unpack(const uint8_t *a72, char *message) {
|
||||||
strcat(message, " ");
|
strcat(message, " ");
|
||||||
strcat(message, grid);
|
strcat(message, grid);
|
||||||
|
|
||||||
//if "000AAA" in msg:
|
|
||||||
// return None
|
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue