kopia lustrzana https://github.com/rs1729/RS
imet1rs/imet4: return crc-check
rodzic
9e45da78df
commit
738c9ae5de
|
@ -101,7 +101,7 @@ int read_signed_sample(FILE *fp) { // int = i32_t
|
||||||
byte = fgetc(fp);
|
byte = fgetc(fp);
|
||||||
if (byte == EOF) return EOF_INT;
|
if (byte == EOF) return EOF_INT;
|
||||||
if (i == 0) ret = byte;
|
if (i == 0) ret = byte;
|
||||||
|
|
||||||
if (bits_sample == 16) {
|
if (bits_sample == 16) {
|
||||||
byte = fgetc(fp);
|
byte = fgetc(fp);
|
||||||
if (byte == EOF) return EOF_INT;
|
if (byte == EOF) return EOF_INT;
|
||||||
|
@ -347,14 +347,14 @@ packet size = 18 bytes
|
||||||
#define pos_GPStim 0x0D // 3 byte
|
#define pos_GPStim 0x0D // 3 byte
|
||||||
#define pos_GPScrc 0x10 // 2 byte
|
#define pos_GPScrc 0x10 // 2 byte
|
||||||
|
|
||||||
void print_GPS(int pos) {
|
int print_GPS(int pos) {
|
||||||
float lat, lon;
|
float lat, lon;
|
||||||
int alt;
|
int alt;
|
||||||
int std, min, sek;
|
int std, min, sek;
|
||||||
int crc1, crc2;
|
int crc_val, crc;
|
||||||
|
|
||||||
crc1 = ((byteframe+pos)[pos_GPScrc] << 8) | (byteframe+pos)[pos_GPScrc+1];
|
crc_val = ((byteframe+pos)[pos_GPScrc] << 8) | (byteframe+pos)[pos_GPScrc+1];
|
||||||
crc2 = crc16(byteframe+pos, pos_GPScrc); // len=pos
|
crc = crc16(byteframe+pos, pos_GPScrc); // len=pos
|
||||||
|
|
||||||
lat = *(float*)(byteframe+pos+pos_GPSlat);
|
lat = *(float*)(byteframe+pos+pos_GPSlat);
|
||||||
lon = *(float*)(byteframe+pos+pos_GPSlon);
|
lon = *(float*)(byteframe+pos+pos_GPSlon);
|
||||||
|
@ -369,9 +369,11 @@ void print_GPS(int pos) {
|
||||||
fprintf(stdout, " alt: %dm ", alt);
|
fprintf(stdout, " alt: %dm ", alt);
|
||||||
|
|
||||||
fprintf(stdout, " # ");
|
fprintf(stdout, " # ");
|
||||||
fprintf(stdout, " CRC: %04X ", crc1);
|
fprintf(stdout, " CRC: %04X ", crc_val);
|
||||||
fprintf(stdout, "- %04X ", crc2);
|
fprintf(stdout, "- %04X ", crc);
|
||||||
if (crc1 == crc2) fprintf(stdout, "[OK]"); else fprintf(stdout, "[NO]");
|
if (crc_val == crc) fprintf(stdout, "[OK]"); else fprintf(stdout, "[NO]");
|
||||||
|
|
||||||
|
return (crc_val != crc);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
@ -398,14 +400,14 @@ packet size = 20 bytes
|
||||||
#define pos_PTUbat 0x0B // 1 byte
|
#define pos_PTUbat 0x0B // 1 byte
|
||||||
#define pos_PTUcrc 0x12 // 2 byte
|
#define pos_PTUcrc 0x12 // 2 byte
|
||||||
|
|
||||||
void print_ePTU(int pos) {
|
int print_ePTU(int pos) {
|
||||||
int P, U;
|
int P, U;
|
||||||
short T;
|
short T;
|
||||||
int bat, pcknum;
|
int bat, pcknum;
|
||||||
int crc1, crc2;
|
int crc_val, crc;
|
||||||
|
|
||||||
crc1 = ((byteframe+pos)[pos_PTUcrc] << 8) | (byteframe+pos)[pos_PTUcrc+1];
|
crc_val = ((byteframe+pos)[pos_PTUcrc] << 8) | (byteframe+pos)[pos_PTUcrc+1];
|
||||||
crc2 = crc16(byteframe+pos, pos_PTUcrc); // len=pos
|
crc = crc16(byteframe+pos, pos_PTUcrc); // len=pos
|
||||||
|
|
||||||
P = (byteframe+pos)[pos_PTUprs] | ((byteframe+pos)[pos_PTUprs+1]<<8) | ((byteframe+pos)[pos_PTUprs+2]<<16);
|
P = (byteframe+pos)[pos_PTUprs] | ((byteframe+pos)[pos_PTUprs+1]<<8) | ((byteframe+pos)[pos_PTUprs+2]<<16);
|
||||||
T = (byteframe+pos)[pos_PTUtem] | ((byteframe+pos)[pos_PTUtem+1]<<8);
|
T = (byteframe+pos)[pos_PTUtem] | ((byteframe+pos)[pos_PTUtem+1]<<8);
|
||||||
|
@ -421,10 +423,11 @@ void print_ePTU(int pos) {
|
||||||
fprintf(stdout, " bat:%.1fV ", bat/10.0);
|
fprintf(stdout, " bat:%.1fV ", bat/10.0);
|
||||||
|
|
||||||
fprintf(stdout, " # ");
|
fprintf(stdout, " # ");
|
||||||
fprintf(stdout, " CRC: %04X ", crc1);
|
fprintf(stdout, " CRC: %04X ", crc_val);
|
||||||
fprintf(stdout, "- %04X ", crc2);
|
fprintf(stdout, "- %04X ", crc);
|
||||||
if (crc1 == crc2) fprintf(stdout, "[OK]"); else fprintf(stdout, "[NO]");
|
if (crc_val == crc) fprintf(stdout, "[OK]"); else fprintf(stdout, "[NO]");
|
||||||
|
|
||||||
|
return (crc_val != crc);
|
||||||
}
|
}
|
||||||
|
|
||||||
/* -------------------------------------------------------------------------- */
|
/* -------------------------------------------------------------------------- */
|
||||||
|
@ -432,6 +435,8 @@ void print_ePTU(int pos) {
|
||||||
int print_frame(int len) {
|
int print_frame(int len) {
|
||||||
int i;
|
int i;
|
||||||
int framelen;
|
int framelen;
|
||||||
|
int crc_err1 = 0,
|
||||||
|
crc_err2 = 0;
|
||||||
|
|
||||||
if ( len < 2 || len > LEN_BYTEFRAME) return -1;
|
if ( len < 2 || len > LEN_BYTEFRAME) return -1;
|
||||||
for (i = len; i < LEN_BYTEFRAME; i++) byteframe[i] = 0;
|
for (i = len; i < LEN_BYTEFRAME; i++) byteframe[i] = 0;
|
||||||
|
@ -453,11 +458,11 @@ int print_frame(int len) {
|
||||||
//else
|
//else
|
||||||
{
|
{
|
||||||
if ((byteframe[0] == 0x01) && (byteframe[1] == 0x02)) { // GPS Data Packet
|
if ((byteframe[0] == 0x01) && (byteframe[1] == 0x02)) { // GPS Data Packet
|
||||||
print_GPS(0x00); // packet offset in byteframe
|
crc_err1 = print_GPS(0x00); // packet offset in byteframe
|
||||||
fprintf(stdout, "\n");
|
fprintf(stdout, "\n");
|
||||||
}
|
}
|
||||||
if ((byteframe[pos_GPScrc+2+0] == 0x01) && (byteframe[pos_GPScrc+2+1] == 0x04)) { // PTU Data Packet
|
if ((byteframe[pos_GPScrc+2+0] == 0x01) && (byteframe[pos_GPScrc+2+1] == 0x04)) { // PTU Data Packet
|
||||||
print_ePTU(pos_GPScrc+2); // packet offset in byteframe
|
crc_err2 = print_ePTU(pos_GPScrc+2); // packet offset in byteframe
|
||||||
fprintf(stdout, "\n");
|
fprintf(stdout, "\n");
|
||||||
}
|
}
|
||||||
/*
|
/*
|
||||||
|
@ -466,6 +471,7 @@ int print_frame(int len) {
|
||||||
fprintf(stdout, "\n");
|
fprintf(stdout, "\n");
|
||||||
}
|
}
|
||||||
*/
|
*/
|
||||||
|
// // if (crc_err1==0 && crc_err2==0) { }
|
||||||
fprintf(stdout, "\n");
|
fprintf(stdout, "\n");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -549,7 +555,7 @@ int main(int argc, char *argv[]) {
|
||||||
ptr = -1; sample_count = -1;
|
ptr = -1; sample_count = -1;
|
||||||
while ((sample=read_signed_sample(fp)) < EOF_INT) {
|
while ((sample=read_signed_sample(fp)) < EOF_INT) {
|
||||||
|
|
||||||
ptr++;
|
ptr++;
|
||||||
sample_count++;
|
sample_count++;
|
||||||
if (ptr == N) ptr = 0;
|
if (ptr == N) ptr = 0;
|
||||||
buffer[ptr] = sample / (double)(1<<bits_sample);
|
buffer[ptr] = sample / (double)(1<<bits_sample);
|
||||||
|
|
Ładowanie…
Reference in New Issue