Add #ifdef-ed code to display mode A/C signals graphically.
This commit is contained in:
parent
32231cf142
commit
5063efe064
87
demod_2400.c
87
demod_2400.c
|
@ -21,6 +21,10 @@
|
||||||
|
|
||||||
#include <assert.h>
|
#include <assert.h>
|
||||||
|
|
||||||
|
#ifdef MODEAC_DEBUG
|
||||||
|
#include <gd.h>
|
||||||
|
#endif
|
||||||
|
|
||||||
// 2.4MHz sampling rate version
|
// 2.4MHz sampling rate version
|
||||||
//
|
//
|
||||||
// When sampling at 2.4MHz we have exactly 6 samples per 5 symbols.
|
// When sampling at 2.4MHz we have exactly 6 samples per 5 symbols.
|
||||||
|
@ -368,6 +372,85 @@ void demodulate2400(struct mag_buf *mag)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
#ifdef MODEAC_DEBUG
|
||||||
|
|
||||||
|
static int yscale(unsigned signal)
|
||||||
|
{
|
||||||
|
return (int) (299 - 299.0 * signal / 65536.0);
|
||||||
|
}
|
||||||
|
|
||||||
|
static void draw_modeac(uint16_t *m, unsigned modeac, unsigned f1_clock, unsigned noise_threshold, unsigned signal_threshold, unsigned bits, unsigned noisy_bits, unsigned uncertain_bits)
|
||||||
|
{
|
||||||
|
// 25 bits at 87*60MHz
|
||||||
|
// use 1 pixel = 30MHz = 1087 pixels
|
||||||
|
|
||||||
|
gdImagePtr im = gdImageCreate(1088, 300);
|
||||||
|
int red = gdImageColorAllocate(im, 255, 0, 0);
|
||||||
|
int brightgreen = gdImageColorAllocate(im, 0, 255, 0);
|
||||||
|
int darkgreen = gdImageColorAllocate(im, 0, 180, 0);
|
||||||
|
int blue = gdImageColorAllocate(im, 0, 0, 255);
|
||||||
|
int grey = gdImageColorAllocate(im, 200, 200, 200);
|
||||||
|
int white = gdImageColorAllocate(im, 255, 255, 255);
|
||||||
|
int black = gdImageColorAllocate(im, 0, 0, 0);
|
||||||
|
|
||||||
|
gdImageFilledRectangle(im, 0, 0, 1087, 299, white);
|
||||||
|
|
||||||
|
// draw samples
|
||||||
|
for (unsigned pixel = 0; pixel < 1088; ++pixel) {
|
||||||
|
int clock_offset = (pixel - 150) * 2;
|
||||||
|
int bit = clock_offset / 87;
|
||||||
|
int sample = (f1_clock + clock_offset) / 25;
|
||||||
|
int bitoffset = clock_offset % 87;
|
||||||
|
int color;
|
||||||
|
|
||||||
|
if (sample < 0)
|
||||||
|
continue;
|
||||||
|
|
||||||
|
if (clock_offset < 0 || bit >= 20) {
|
||||||
|
color = grey;
|
||||||
|
} else if (bitoffset < 27 && (uncertain_bits & (1 << (19-bit)))) {
|
||||||
|
color = red;
|
||||||
|
} else if (bitoffset >= 27 && (noisy_bits & (1 << (19-bit)))) {
|
||||||
|
color = red;
|
||||||
|
} else if (bitoffset >= 27) {
|
||||||
|
color = grey;
|
||||||
|
} else if (bits & (1 << (19-bit))) {
|
||||||
|
color = brightgreen;
|
||||||
|
} else {
|
||||||
|
color = darkgreen;
|
||||||
|
}
|
||||||
|
|
||||||
|
gdImageLine(im, pixel, 299, pixel, yscale(m[sample]), color);
|
||||||
|
}
|
||||||
|
|
||||||
|
// draw bit boundaries
|
||||||
|
for (unsigned bit = 0; bit < 20; ++bit) {
|
||||||
|
unsigned clock = 87 * bit;
|
||||||
|
unsigned pixel0 = clock / 2 + 150;
|
||||||
|
unsigned pixel1 = (clock + 27) / 2 + 150;
|
||||||
|
|
||||||
|
gdImageLine(im, pixel0, 0, pixel0, 299, (bit == 0 || bit == 14) ? black : grey);
|
||||||
|
gdImageLine(im, pixel1, 0, pixel1, 299, (bit == 0 || bit == 14) ? black : grey);
|
||||||
|
}
|
||||||
|
|
||||||
|
// draw thresholds
|
||||||
|
gdImageLine(im, 0, yscale(noise_threshold), 1087, yscale(noise_threshold), blue);
|
||||||
|
gdImageLine(im, 0, yscale(signal_threshold), 1087, yscale(signal_threshold), blue);
|
||||||
|
|
||||||
|
// save it
|
||||||
|
|
||||||
|
static int file_counter;
|
||||||
|
char filename[PATH_MAX];
|
||||||
|
sprintf(filename, "modeac_%04X_%04d.png", modeac, ++file_counter);
|
||||||
|
fprintf(stderr, "writing %s\n", filename);
|
||||||
|
|
||||||
|
FILE *pngout = fopen(filename, "wb");
|
||||||
|
gdImagePng(im, pngout);
|
||||||
|
fclose(pngout);
|
||||||
|
gdImageDestroy(im);
|
||||||
|
}
|
||||||
|
|
||||||
|
#endif
|
||||||
|
|
||||||
//////////
|
//////////
|
||||||
////////// MODE A/C
|
////////// MODE A/C
|
||||||
|
@ -548,6 +631,10 @@ void demodulate2400AC(struct mag_buf *mag)
|
||||||
((bits & 0x00040) ? 0x0004 : 0) | // D4
|
((bits & 0x00040) ? 0x0004 : 0) | // D4
|
||||||
((bits & 0x00004) ? 0x0080 : 0); // SPI
|
((bits & 0x00004) ? 0x0080 : 0); // SPI
|
||||||
|
|
||||||
|
#ifdef MODEAC_DEBUG
|
||||||
|
draw_modeac(m, modeac, f1_clock, noise_threshold, signal_threshold, bits, noisy_bits, uncertain_bits);
|
||||||
|
#endif
|
||||||
|
|
||||||
// This message looks good, submit it
|
// This message looks good, submit it
|
||||||
|
|
||||||
// compute message receive time as block-start-time + difference in the 12MHz clock
|
// compute message receive time as block-start-time + difference in the 12MHz clock
|
||||||
|
|
Loading…
Reference in a new issue