void analyze_efergy_message(int debug_level) { // See how balanced/centered the sample data is. Best case is diff close to 0 int avg_pos, avg_neg; int difference = calculate_wave_center(&avg_pos, &avg_neg); if (debug_level > 1) { time_t ltime; char buffer[80]; time( <ime ); struct tm *curtime = localtime( <ime ); strftime(buffer, 80, "%x,%X", curtime); printf("\nAnalysis of rtl_fm sample data for frame received on %s\n", buffer); printf(" Number of Samples: %6d\n", sample_store_index); printf(" Avg. Sample Values: %6d (negative) %6d (positive)\n", avg_neg, avg_pos); printf(" Wave Center: %6d (this frame) %6d (last frame)\n", difference, analysis_wavecenter); } analysis_wavecenter = difference; // Use the calculated wave center from this sample to process next frame if (debug_level == 4) { // Raw Sample Dump only in highest debug level int wrap_count = 0; printf("\nShowing raw rtl_fm sample data received between start of frame and end of frame\n"); int i; for (i = 0; i < sample_store_index; i++) { printf("%6d ", sample_storage[i] - analysis_wavecenter); wrap_count++; if (wrap_count >= 16) { printf("\n"); wrap_count = 0; } } printf("\n\n"); } int display_pulse_details = (debug_level >= 3 ? 1 : 0); int pulse_count_storage[SAMPLE_STORE_SIZE]; int pulse_store_index = generate_pulse_count_array(display_pulse_details, pulse_count_storage); unsigned char bytearray[FRAMEBYTECOUNT]; int bytecount = decode_bytes_from_pulse_counts(pulse_count_storage, pulse_store_index, bytearray); char *frame_msg; if (sample_storage[2] < analysis_wavecenter) frame_msg = "Msg:"; else frame_msg = "Msg (from negative pulses):"; display_frame_data(debug_level, frame_msg, bytearray, bytecount); if (debug_level > 1) printf("\n"); }
// Verbosity level (from 0 to 3) controls amount of debug output void analyze_efergy_message(int verbosity_level) { int i; // See how balanced/centered the sample data is. Best case is avg_neg + avg_pos = 0 // If abs(avg neg) is greater than avg pos, try increasing frequency // If avg pos is greater than abs(avg neg), try decreasing frequency double avg_neg=0; double avg_pos=0; int pos_count=0; int neg_count=0; for (i=0;i<sample_store_index;i++) if (sample_storage[i] >=0) { avg_pos += sample_storage[i]; pos_count++; } else { avg_neg += sample_storage[i]; neg_count++; } if (pos_count!=0) avg_pos /= pos_count; if (neg_count!=0) avg_neg /= neg_count; double difference = avg_neg + ((avg_pos-avg_neg)/2); time_t ltime; char buffer[80]; time( <ime ); struct tm *curtime = localtime( <ime ); strftime(buffer,80,"%x,%X", curtime); if (verbosity_level > 0) { printf("\nAnalysis of rtl_fm sample data for frame received on %s\n", buffer); printf(" Number of Samples: %6d\n", sample_store_index); printf(" Avg. Sample Values: %6.0f (negative) %6.0f (positive)\n", avg_neg, avg_pos); printf(" Wave Center: %6.0f (this frame) %6d (last frame)\n", difference, analysis_wavecenter); } else printf("%s ", buffer); analysis_wavecenter = difference; // Use the calculated wave center from this sample to process next frame if (verbosity_level==3) { // Raw Sample Dump only in highest verbosity level int wrap_count=0; printf("\nShowing raw rtl_fm sample data received between start of frame and end of frame\n"); for(i=0;i<sample_store_index;i++) { printf("%6d ", sample_storage[i] - analysis_wavecenter); wrap_count++; if (wrap_count >= 16) { printf("\n"); wrap_count=0; } } printf("\n\n"); } int display_pulse_details = (verbosity_level >= 2?1:0); if (display_pulse_details) printf("\nPulse stream for this frame (P-Consecutive samples > center, N-Consecutive samples < center)\n"); int wrap_count=0; int pulse_count=0; int space_count=0; int pulse_count_storage[SAMPLE_STORE_SIZE]; int space_count_storage[SAMPLE_STORE_SIZE]; int pulse_store_index=0; int space_store_index=0; int display_pulse_info=1; for(i=0;i<sample_store_index;i++) { int samplec = sample_storage[i] - analysis_wavecenter; if (samplec < 0) { if (pulse_count > 0) { pulse_count_storage[pulse_store_index++]=pulse_count; if (display_pulse_details) printf("%2dP ", pulse_count); wrap_count++; } pulse_count=0; space_count++; } else { if (space_count > 0) { space_count_storage[space_store_index++]=space_count; if (display_pulse_details) printf("%2dN ", space_count); wrap_count++; } space_count=0; pulse_count++; } if (wrap_count >= 16) { if (display_pulse_details) printf("\n"); wrap_count=0; } } if (display_pulse_details) printf("\n\n"); // From empirical analysis with an Elite 3.0 TPM transmitter, sometimes the data can be decoded by counting negative pulses rather than positive // pulses. It seems that if the first sequence after the preamble is positive pulses, the data can be decoded by parsing using the negative pulse counts. // The code below tests it both ways. unsigned char bytearray[ANALYZEBYTECOUNT]; int bytecount; if (sample_storage[2] < analysis_wavecenter) { bytecount=decode_bytes_from_pulse_counts(pulse_count_storage, pulse_store_index, bytearray); display_frame_data("Decode from positive pulses: ", bytearray, bytecount); } else { bytecount = decode_bytes_from_pulse_counts(space_count_storage, space_store_index, bytearray); display_frame_data("Decode from negative pulses: ", bytearray, bytecount); } if (verbosity_level>0) printf("\n"); }