Clean up stdout+printf in devices; add style check

This commit is contained in:
Christian W. Zuckschwerdt 2019-08-21 11:16:53 +02:00
parent dbe6e58c6e
commit b863bf1298
13 changed files with 96 additions and 75 deletions

View file

@ -33,19 +33,19 @@ static int cardin_callback(r_device *decoder, bitbuffer_t *bitbuffer) {
(bb[0][2] & 0x0f) == 6) ) {
/*
fprintf(stdout, "------------------------------\n");
fprintf(stdout, "protocol = Cardin S466\n");
fprintf(stdout, "message = ");
fprintf(stderr, "------------------------------\n");
fprintf(stderr, "protocol = Cardin S466\n");
fprintf(stderr, "message = ");
for (i=0 ; i<3 ; i++) {
for (k = 7; k >= 0; k--) {
if (bb[0][i] & 1 << k)
fprintf(stdout, "1");
fprintf(stderr, "1");
else
fprintf(stdout, "0");
fprintf(stderr, "0");
}
fprintf(stdout, " ");
fprintf(stderr, " ");
}
fprintf(stdout, "\n\n");
fprintf(stderr, "\n\n");
*/
// Dip 1

View file

@ -118,8 +118,7 @@ static int dsc_callback(r_device *decoder, bitbuffer_t *bitbuffer)
(b[3] & 0x02) &&
(b[4] & 0x01))) {
if (decoder->verbose > 1) {
fprintf(stderr, "DSC Invalid start/sync bits ");
bitrow_print(b, 40);
bitrow_printf(b, 40, "DSC Invalid start/sync bits ");
}
continue;
}
@ -130,10 +129,8 @@ static int dsc_callback(r_device *decoder, bitbuffer_t *bitbuffer)
bytes[3] = ((b[3] & 0x01) << 7) | ((b[4] & 0xFE) >> 1);
bytes[4] = ((b[5]));
// XXX change to decoder->verbose
if (decoder->verbose) {
fprintf(stdout, "DSC Contact Raw Data: ");
bitrow_print(bytes, 40);
bitrow_printf(bytes, 40, "DSC Contact Raw Data: ");
}
status = bytes[0];
@ -214,7 +211,7 @@ static char *output_fields[] = {
"status",
"battery_ok",
"mic",
NULL
NULL,
};
r_device DSC = {

View file

@ -29,17 +29,22 @@ static int em1000_callback(r_device *decoder, bitbuffer_t *bitbuffer)
// check and combine the 3 repetitions
for (i = 0; i < 14; i++) {
if(bb[0][i]==bb[1][i] || bb[0][i]==bb[2][i]) bb_p[i]=bb[0][i];
else if(bb[1][i]==bb[2][i]) bb_p[i]=bb[1][i];
else return 0;
if (bb[0][i] == bb[1][i] || bb[0][i] == bb[2][i])
bb_p[i] = bb[0][i];
else if (bb[1][i] == bb[2][i])
bb_p[i] = bb[1][i];
else
return 0;
}
// read 9 bytes with stopbit ...
for (i = 0; i < 9; i++) {
dec[i] = AD_POP (bb_p, 8, bit); bit+=8;
stopbit=AD_POP (bb_p, 1, bit); bit+=1;
dec[i] = AD_POP(bb_p, 8, bit);
bit += 8;
stopbit = AD_POP(bb_p, 1, bit);
bit += 1;
if (!stopbit) {
// fprintf(stdout, "!stopbit: %i\n", i);
// fprintf(stderr, "!stopbit: %i\n", i);
return 0;
}
checksum_calculated ^= dec[i];
@ -49,11 +54,11 @@ static int em1000_callback(r_device *decoder, bitbuffer_t *bitbuffer)
// Read checksum
checksum_received = AD_POP (bb_p, 8, bit); bit+=8;
if (checksum_received != checksum_calculated) {
// fprintf(stdout, "checksum_received != checksum_calculated: %d %d\n", checksum_received, checksum_calculated);
// fprintf(stderr, "checksum_received != checksum_calculated: %d %d\n", checksum_received, checksum_calculated);
return 0;
}
//for (i = 0; i < bytes; i++) fprintf(stdout, "%02X ", dec[i]); fprintf(stdout, "\n");
//for (i = 0; i < bytes; i++) fprintf(stderr, "%02X ", dec[i]); fprintf(stderr, "\n");
// based on 15_CUL_EM.pm
char *subtype = dec[0] >= 1 && dec[0] <= 3 ? types[dec[0] - 1] : "?";
@ -84,7 +89,7 @@ static char *elv_em1000_output_fields[] = {
"total",
"current",
"peak",
NULL
NULL,
};
r_device elv_em1000 = {
@ -118,7 +123,8 @@ static int ws2000_callback(r_device *decoder, bitbuffer_t *bitbuffer)
dec[0] = AD_POP (bb[0], 4, bit); bit+=4;
stopbit= AD_POP (bb[0], 1, bit); bit+=1;
if (!stopbit) {
if(decoder->verbose) fprintf(stdout, "!stopbit\n");
if (decoder->verbose)
fprintf(stderr, "!stopbit\n");
return 0;
}
check_calculated ^= dec[0];
@ -129,17 +135,21 @@ static int ws2000_callback(r_device *decoder, bitbuffer_t *bitbuffer)
dec[i] = AD_POP (bb[0], 4, bit); bit+=4;
stopbit= AD_POP (bb[0], 1, bit); bit+=1;
if (!stopbit) {
if(decoder->verbose) fprintf(stdout, "!stopbit %i\n", bit);
if (decoder->verbose)
fprintf(stderr, "!stopbit %i\n", bit);
return 0;
}
check_calculated ^= dec[i];
sum_calculated += dec[i];
nibbles++;
}
if(decoder->verbose) { for (i = 0; i < nibbles; i++) fprintf(stdout, "%02X ", dec[i]); fprintf(stdout, "\n"); }
if (decoder->verbose) {
bitrow_print(dec, nibbles * 8);
}
if (check_calculated) {
if(decoder->verbose) fprintf(stdout, "check_calculated (%d) != 0\n", check_calculated);
if (decoder->verbose)
fprintf(stderr, "check_calculated (%d) != 0\n", check_calculated);
return 0;
}
@ -148,7 +158,8 @@ static int ws2000_callback(r_device *decoder, bitbuffer_t *bitbuffer)
sum_calculated+=5;
sum_calculated&=0xF;
if (sum_received != sum_calculated) {
if(decoder->verbose) fprintf(stdout, "sum_received (%d) != sum_calculated (%d) ", sum_received, sum_calculated);
if (decoder->verbose)
fprintf(stderr, "sum_received (%d) != sum_calculated (%d) ", sum_received, sum_calculated);
return 0;
}
@ -182,7 +193,7 @@ static char *elv_ws2000_output_fields[] = {
"temperature",
"humidity",
"pressure",
NULL
NULL,
};
r_device elv_ws2000 = {

View file

@ -42,7 +42,7 @@ unsigned long extract_number(uint8_t *data, unsigned bit_offset, unsigned bit_co
unsigned shl = bit_offset - pos * 8; // shift left we need to align
unsigned len = (shl + bit_count + 7) / 8; // number of bytes we need
unsigned shr = 8 * len - shl - bit_count; // actual shift right
// printf("pos: %d, shl: %d, len: %d, shr: %d\n", pos, shl, len, shr);
// fprintf(stderr, "pos: %d, shl: %d, len: %d, shr: %d\n", pos, shl, len, shr);
unsigned long val = data[pos];
val = (uint8_t)(val << shl) >> shl; // mask off top bits
for (unsigned i = 1; i < len - 1; ++i) {

View file

@ -81,10 +81,10 @@ static int holman_ws5029_decode(r_device *decoder, bitbuffer_t *bitbuffer)
for (uint8_t firstbyte = 0; firstbyte < 21; firstbyte++) {
for (uint8_t poly=0; poly<255; poly++) {
if (crc8(&b[firstbyte], 21-firstbyte, poly, 0x00) == b[21]) {
printf("CORRECT CRC8 with offset %u poly 0x%x\n", firstbyte, poly);
fprintf(stderr, "CORRECT CRC8 with offset %u poly 0x%x\n", firstbyte, poly);
}
if (crc8le(&b[firstbyte], 21-firstbyte, poly, 0x00) == b[21]) {
printf("CORRECT CRC8LE with offset %u poly 0x%x\n", firstbyte, poly);
fprintf(stderr, "CORRECT CRC8LE with offset %u poly 0x%x\n", firstbyte, poly);
}
}
}

View file

@ -44,17 +44,13 @@ static int kw9015b_callback(r_device *decoder, bitbuffer_t *bitbuffer)
(reverse8(b[3])>>4)+(reverse8(b[3])&0x0F));
if (decoder->verbose) {
fprintf(stdout, "\nSensor = Inovalley kw9015b, TFA Dostmann 30.3161 (Rain and temperature sensor)\n");
fprintf(stdout, "Device = %d\n", device);
fprintf(stdout, "Temp = %f\n", temp_c);
fprintf(stdout, "Rain = %d\n", rain);
fprintf(stdout, "checksum = %02x==%02x\n", chksum&0xF, reverse8(b[4]));
fprintf(stdout, "Received Data = %02X %02X %02X %02X %02X\n",
reverse8(b[0]),
reverse8(b[1]),
reverse8(b[2]),
reverse8(b[3]),
reverse8(b[4]));
fprintf(stderr, "\nSensor = Inovalley kw9015b, TFA Dostmann 30.3161 (Rain and temperature sensor)\n");
fprintf(stderr, "Device = %d\n", device);
fprintf(stderr, "Temp = %f\n", temp_c);
fprintf(stderr, "Rain = %d\n", rain);
fprintf(stderr, "checksum = %02x==%02x\n", chksum&0xF, reverse8(b[4]));
fprintf(stderr, "Received Data = %02X %02X %02X %02X %02X\n",
reverse8(b[0]), reverse8(b[1]), reverse8(b[2]), reverse8(b[3]), reverse8(b[4]));
}
if ((chksum&0x0F) != (reverse8(b[4]) & 0x0F))

View file

@ -22,19 +22,19 @@ static int intertechno_callback(r_device *decoder, bitbuffer_t *bitbuffer)
return 0;
if (decoder->verbose > 1) {
fprintf(stdout, "Switch event:\n");
fprintf(stdout, "protocol = Intertechno\n");
fprintf(stdout, "rid = %x\n", b[0]);
fprintf(stdout, "rid = %x\n", b[1]);
fprintf(stdout, "rid = %x\n", b[2]);
fprintf(stdout, "rid = %x\n", b[3]);
fprintf(stdout, "rid = %x\n", b[4]);
fprintf(stdout, "rid = %x\n", b[5]);
fprintf(stdout, "rid = %x\n", b[6]);
fprintf(stdout, "rid = %x\n", b[7]);
fprintf(stdout, "ADDR Slave = %i\n", b[7] & 0x0f);
fprintf(stdout, "ADDR Master = %i\n",( b[7] & 0xf0) >> 4);
fprintf(stdout, "command = %i\n",( b[6] & 0x07));
fprintf(stderr, "Switch event:\n");
fprintf(stderr, "protocol = Intertechno\n");
fprintf(stderr, "rid = %x\n", b[0]);
fprintf(stderr, "rid = %x\n", b[1]);
fprintf(stderr, "rid = %x\n", b[2]);
fprintf(stderr, "rid = %x\n", b[3]);
fprintf(stderr, "rid = %x\n", b[4]);
fprintf(stderr, "rid = %x\n", b[5]);
fprintf(stderr, "rid = %x\n", b[6]);
fprintf(stderr, "rid = %x\n", b[7]);
fprintf(stderr, "ADDR Slave = %i\n", b[7] & 0x0f);
fprintf(stderr, "ADDR Master = %i\n",( b[7] & 0xf0) >> 4);
fprintf(stderr, "command = %i\n",( b[6] & 0x07));
}
sprintf(id_str, "%02x%02x%02x%02x%02x", b[0], b[1], b[2], b[3], b[4]);

View file

@ -86,7 +86,7 @@ static int lacrossetx_detect(r_device *decoder, uint8_t *pRow, uint8_t *msg_nybb
parity += bit;
}
// fprintf(stdout, "recv: [%d/%d] %d -> msg [%d/%d] %02x, Parity: %d %s\n", rbyte_no, rbit_no,
// fprintf(stderr, "recv: [%d/%d] %d -> msg [%d/%d] %02x, Parity: %d %s\n", rbyte_no, rbit_no,
// bit, mnybble_no, mbit_no, msg_nybbles[mnybble_no], parity,
// ( mbit_no == 0 ) ? "\n" : "" );
}
@ -100,13 +100,13 @@ static int lacrossetx_detect(r_device *decoder, uint8_t *pRow, uint8_t *msg_nybb
checksum = (checksum + msg_nybbles[i]) & 0x0F;
}
// fprintf(stdout,"Parity: %d, parity bit %d, Good %d\n", parity, parity_bit, parity % 2);
// fprintf(stderr,"Parity: %d, parity bit %d, Good %d\n", parity, parity_bit, parity % 2);
if (checksum == msg_nybbles[10] && (parity % 2 == 0)) {
return 1;
} else {
if (decoder->verbose > 1) {
fprintf(stdout,
fprintf(stderr,
"LaCrosse TX Checksum/Parity error: Comp. %d != Recv. %d, Parity %d\n",
checksum, msg_nybbles[10], parity);
}

View file

@ -72,7 +72,7 @@ static int lacrossews_detect(r_device *decoder, uint8_t *pRow, uint8_t *msg_nybb
return 1;
if (decoder->verbose > 1) {
fprintf(stdout,
fprintf(stderr,
"LaCrosse Packet Validation Failed error: Checksum Comp. %d != Recv. %d, Parity %d\n",
checksum, msg_nybbles[12], parity);
bitrow_print(msg_nybbles, LACROSSE_WS_BITLEN);

View file

@ -232,7 +232,7 @@ static int oregon_scientific_v2_1_decode(r_device *decoder, bitbuffer_t *bitbuff
int sensor_id = (msg[0] << 8) | msg[1];
if (decoder->verbose) {
fprintf(stdout,"Found sensor_id (%08x)\n",sensor_id);
fprintf(stderr,"Found sensor_id (%08x)\n",sensor_id);
}
if ((sensor_id == ID_THGR122N) || (sensor_id == ID_THGR968)) {
if (validate_os_v2_message(decoder, msg, 76, msg_bits, 15) != 0)
@ -530,7 +530,7 @@ static int oregon_scientific_v3_decode(r_device *decoder, bitbuffer_t *bitbuffer
unsigned int pattern2 = (unsigned int)(0xff500000 >> pattern_index);
unsigned int pattern3 = (unsigned int)(0x00500000 >> pattern_index);
unsigned int pattern4 = (unsigned int)(0x04600000 >> pattern_index);
//fprintf(stdout, "OS v3 Sync nibble search - test_val=%08x pattern=%08x mask=%08x\n", sync_test_val, pattern, mask);
//fprintf(stderr, "OS v3 Sync nibble search - test_val=%08x pattern=%08x mask=%08x\n", sync_test_val, pattern, mask);
if (((sync_test_val & mask) != pattern)
&& ((sync_test_val & mask) != pattern2)
&& ((sync_test_val & mask) != pattern3)

View file

@ -29,9 +29,7 @@
static int steelmate_callback(r_device *decoder, bitbuffer_t *bitbuffer) {
//if (decoder->verbose) {
// fprintf(stdout, "Steelmate TPMS decoder\n");
// bitbuffer_print(bitbuffer);
// fprintf(stdout, "\n");
// bitbuffer_printf(bitbuffer, "Steelmate TPMS decoder: ");
//}
bitrow_t *bb = bitbuffer->bb;

View file

@ -56,16 +56,16 @@ static int wssensor_callback(r_device *decoder, bitbuffer_t *bitbuffer) {
temperature_c = (temperature >> 4) * 0.1f;
if (decoder->verbose) {
fprintf(stdout, "Hyundai WS SENZOR received raw data:\n");
fprintf(stderr, "Hyundai WS SENZOR received raw data:\n");
bitbuffer_print(bitbuffer);
fprintf(stdout, "Sensor ID = %01d = 0x%02x\n", sensor_id, sensor_id);
fprintf(stdout, "Bitstream HEX = ");
fprintf(stderr, "Sensor ID = %01d = 0x%02x\n", sensor_id, sensor_id);
fprintf(stderr, "Bitstream HEX = ");
bitrow_print(b, 24);
fprintf(stdout, "Battery OK = %0d\n", battery_status);
fprintf(stdout, "Startup = %0d\n", startup);
fprintf(stdout, "Channel = %0d\n", channel);
fprintf(stdout, "temp = %d = 0x%02x\n", temperature, temperature);
fprintf(stdout, "TemperatureC = %.1f\n", temperature_c);
fprintf(stderr, "Battery OK = %0d\n", battery_status);
fprintf(stderr, "Startup = %0d\n", startup);
fprintf(stderr, "Channel = %0d\n", channel);
fprintf(stderr, "temp = %d = 0x%02x\n", temperature, temperature);
fprintf(stderr, "TemperatureC = %.1f\n", temperature_c);
}
data = data_make(
@ -86,7 +86,7 @@ static char *output_fields[] = {
"channel",
"battery",
"temperature_C",
NULL
NULL,
};
r_device wssensor = {
@ -98,5 +98,5 @@ r_device wssensor = {
.reset_limit = 4400,
.decode_fn = &wssensor_callback,
.disabled = 0,
.fields = output_fields
.fields = output_fields,
};

View file

@ -24,6 +24,8 @@
/// Check that there are no mixed tabs/spaces.
static int style_check(char *path)
{
char *strict = strstr(path, "/devices/");
FILE *fp = fopen(path, "r");
assert(fp);
if(!fp)
@ -37,6 +39,9 @@ static int style_check(char *path)
int leading_tabs = 0;
int leading_spcs = 0;
int use_stdout = 0;
int use_printf = 0;
char str[MAX_LEN];
while (fgets(str, MAX_LEN, fp)) {
int len = strlen(str);
@ -57,6 +62,16 @@ static int style_check(char *path)
if (len >= 4 && str[0] == ' ' && str[1] == ' ' && str[2] == ' ' && str[3] == ' ') {
leading_spcs++;
}
if (strstr(str, "stdout")) {
use_stdout++;
}
char *p;
if ((p = strstr(str, "printf"))) {
if (p == str || p[-1] < '_'|| p[-1] > 'z') {
use_printf++;
}
}
}
if (leading_tabs && leading_spcs) {
tabs_errors = leading_tabs > leading_spcs ? leading_spcs : leading_tabs;
@ -72,8 +87,12 @@ static int style_check(char *path)
printf("File \"%s\" has %d MIXED tab/spaces errors.\n", path, tabs_errors);
if (leading_tabs)
printf("File \"%s\" has %d TAB indented lines.\n", path, leading_tabs);
if (strict && use_stdout)
printf("File \"%s\" has %d STDOUT lines.\n", path, use_stdout);
if (strict && use_printf)
printf("File \"%s\" has %d PRINTF lines.\n", path, use_printf);
return read_errors + long_errors + crlf_errors + tabs_errors + leading_tabs;
return read_errors + long_errors + crlf_errors + tabs_errors + leading_tabs + (strict ? use_stdout + use_printf : 0);
}
int main(int argc, char *argv[])