some code reorg
This commit is contained in:
parent
26c7be76df
commit
b35f265b6f
|
|
@ -242,7 +242,7 @@ const String sondeTypeSelect(int activeType) {
|
|||
//trying to work around
|
||||
//"assertion "heap != NULL && "free() target pointer is outside heap areas"" failed:"
|
||||
// which happens if request->send is called in createQRGForm!?!??
|
||||
char message[10240 * 4]; //needs to be large enough for all forms (not checked in code)
|
||||
char message[10240 * 4-512]; //needs to be large enough for all forms (not checked in code)
|
||||
// QRG form is currently about 24kb with 100 entries
|
||||
|
||||
///////////////////////// Functions for Reading / Writing QRG list from/to qrg.txt
|
||||
|
|
|
|||
|
|
@ -47,6 +47,17 @@ static struct st_dfmstat {
|
|||
float meas[5+2];
|
||||
} dfmstate;
|
||||
|
||||
decoderSetupCfg DFMSetupCfg {
|
||||
.bitrate = 2500,
|
||||
// continuous mode
|
||||
// Enable auto-AFC, auto-AGC, RX Trigger by preamble ????
|
||||
.rx_cfg = 0x1E,
|
||||
.sync_cfg = 0x70,
|
||||
.sync_len = 2,
|
||||
.sync_data = (const uint8_t *)"\xAA\xAA",
|
||||
.preamble_cfg = 0xA8,
|
||||
};
|
||||
|
||||
int DFM::setup(float frequency, int type)
|
||||
{
|
||||
stype = type;
|
||||
|
|
@ -57,6 +68,12 @@ int DFM::setup(float frequency, int type)
|
|||
DFM_DBG(Serial.println("Setting SX1278 power on FAILED"));
|
||||
return 1;
|
||||
}
|
||||
|
||||
if(DecoderBase::setup(DFMSetupCfg, sonde.config.dfm.agcbw, sonde.config.dfm.rxbw) != 0) {
|
||||
return 1;
|
||||
}
|
||||
#if 0
|
||||
// This is now all done by the generic setup method in base class
|
||||
if(sx1278.setFSK()!=0) {
|
||||
DFM_DBG(Serial.println("Setting FSM mode FAILED"));
|
||||
return 1;
|
||||
|
|
@ -65,12 +82,6 @@ int DFM::setup(float frequency, int type)
|
|||
DFM_DBG(Serial.println("Setting bitrate 2500bit/s FAILED"));
|
||||
return 1;
|
||||
}
|
||||
#if DFM_DEBUG
|
||||
float br = sx1278.getBitrate();
|
||||
Serial.print("Exact bitrate is ");
|
||||
Serial.println(br);
|
||||
#endif
|
||||
|
||||
if(sx1278.setAFCBandwidth(sonde.config.dfm.agcbw)!=0) {
|
||||
DFM_DBG(Serial.printf("Setting AFC bandwidth %d Hz FAILED", sonde.config.dfm.agcbw));
|
||||
return 1;
|
||||
|
|
@ -79,11 +90,7 @@ int DFM::setup(float frequency, int type)
|
|||
DFM_DBG(Serial.printf("Setting RX bandwidth to %d Hz FAILED", sonde.config.dfm.rxbw));
|
||||
return 1;
|
||||
}
|
||||
|
||||
// DFM OLD support has been removed
|
||||
{
|
||||
// continuous mode
|
||||
// Enable auto-AFC, auto-AGC, RX Trigger by preamble ????
|
||||
if(sx1278.setRxConf(0x1E)!=0) {
|
||||
DFM_DBG(Serial.println("Setting RX Config FAILED"));
|
||||
return 1;
|
||||
|
|
@ -99,12 +106,13 @@ int DFM::setup(float frequency, int type)
|
|||
DFM_DBG(Serial.println("Setting PreambleDetect FAILED"));
|
||||
return 1;
|
||||
}
|
||||
if(sx1278.setPacketConfig(0x08, 0x40)!=0) {
|
||||
DFM_DBG(Serial.println("Setting Packet config FAILED"));
|
||||
return 1;
|
||||
}
|
||||
sx1278.setPayloadLength(0); // infinite for now...
|
||||
}
|
||||
#endif
|
||||
if(sx1278.setPacketConfig(0x08, 0x40)!=0) {
|
||||
DFM_DBG(Serial.println("Setting Packet config FAILED"));
|
||||
return 1;
|
||||
}
|
||||
sx1278.setPayloadLength(0); // infinite for now...
|
||||
Serial.print("DFM: setting RX frequency to ");
|
||||
Serial.println(frequency);
|
||||
|
||||
|
|
|
|||
|
|
@ -15,12 +15,13 @@
|
|||
#ifndef inttypes_h
|
||||
#include <inttypes.h>
|
||||
#endif
|
||||
#include "DecoderBase.h"
|
||||
|
||||
#define DFM_NORMAL 0
|
||||
#define DFM_INVERSE 1
|
||||
|
||||
/* Main class */
|
||||
class DFM
|
||||
class DFM : public DecoderBase
|
||||
{
|
||||
private:
|
||||
int stype;
|
||||
|
|
|
|||
|
|
@ -0,0 +1,51 @@
|
|||
|
||||
#include "DecoderBase.h"
|
||||
#include "SX1278FSK.h"
|
||||
#include "Sonde.h"
|
||||
|
||||
#define DECODERBASE_DEBUG 1
|
||||
|
||||
#if DECODERBASE_DEBUG
|
||||
#define DBG(x) x
|
||||
#else
|
||||
#define DBG(x)
|
||||
#endif
|
||||
|
||||
|
||||
int DecoderBase::setup(decoderSetupCfg &setupcfg, uint16_t agcbw, uint16_t rxbw) {
|
||||
if(sx1278.setFSK()!=0) {
|
||||
DBG(Serial.println("Setting FSK mode FAILED"));
|
||||
return 1;
|
||||
}
|
||||
if(sx1278.setBitrate(setupcfg.bitrate)!=0) {
|
||||
DBG(Serial.println("Setting bitrate FAILED"));
|
||||
return 1;
|
||||
}
|
||||
#if DECODERBASE_DEBUG
|
||||
float br = sx1278.getBitrate();
|
||||
Serial.print("Exact bitrate is ");
|
||||
Serial.println(br);
|
||||
#endif
|
||||
if(sx1278.setAFCBandwidth(agcbw)!=0) {
|
||||
DBG(Serial.printf("Setting AFC bandwidth %d Hz FAILED", agcbw));
|
||||
return 1;
|
||||
}
|
||||
if(sx1278.setRxBandwidth(rxbw)!=0) {
|
||||
DBG(Serial.printf("Setting RX bandwidth to %d Hz FAILED", rxbw));
|
||||
return 1;
|
||||
}
|
||||
|
||||
if(sx1278.setRxConf(setupcfg.rx_cfg)!=0) {
|
||||
DBG(Serial.println("Setting RX Config FAILED"));
|
||||
return 1;
|
||||
}
|
||||
if(sx1278.setSyncConf(setupcfg.sync_cfg, setupcfg.sync_len, setupcfg.sync_data)!=0) {
|
||||
DBG(Serial.println("Setting SYNC Config FAILED"));
|
||||
return 1;
|
||||
}
|
||||
if(sx1278.setPreambleDetect(setupcfg.preamble_cfg)!=0) {
|
||||
DBG(Serial.println("Setting PreambleDetect FAILED"));
|
||||
return 1;
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
|
@ -0,0 +1,38 @@
|
|||
|
||||
#ifndef DECODER_BASE_H
|
||||
#define DECODER_BASE_H
|
||||
|
||||
#include <stdlib.h>
|
||||
#include <stdint.h>
|
||||
#include <Arduino.h>
|
||||
#ifndef inttypes_h
|
||||
#include <inttypes.h>
|
||||
#endif
|
||||
#include "Sonde.h"
|
||||
|
||||
typedef struct _decoderSetupCfg {
|
||||
uint16_t bitrate;
|
||||
//uint16_t agcbw;
|
||||
//uint16_t rxbw;
|
||||
uint8_t rx_cfg;
|
||||
uint8_t sync_cfg;
|
||||
uint8_t sync_len;
|
||||
const uint8_t *sync_data;
|
||||
uint8_t preamble_cfg;
|
||||
} decoderSetupCfg;
|
||||
|
||||
/* Generic base class for all sonde decoders */
|
||||
class DecoderBase
|
||||
{
|
||||
protected:
|
||||
|
||||
public:
|
||||
int setup(decoderSetupCfg &setupcfg, uint16_t agcbw, uint16_t rxbw);
|
||||
virtual int setup(float frequency, int type=0) = 0;
|
||||
|
||||
virtual int receive() = 0;
|
||||
virtual int waitRXcomplete() = 0;
|
||||
};
|
||||
|
||||
|
||||
#endif
|
||||
|
|
@ -26,7 +26,19 @@ static int haveNewFrame = 0;
|
|||
//static int lastFrame = 0;
|
||||
static int headerDetected = 0;
|
||||
|
||||
int M10M20::setup(float frequency)
|
||||
|
||||
decoderSetupCfg m10m20SetupCfg = {
|
||||
.bitrate = 9600,
|
||||
//// Disable auto-AFC, auto-AGC, RX Trigger by preamble
|
||||
.rx_cfg = 0x00,
|
||||
.sync_cfg = 0x70,
|
||||
.sync_len = 1,
|
||||
.sync_data = (const uint8_t *)"\x66\x66",
|
||||
// Preamble detection off (+ size 1 byte, maximum tolerance; should not matter for "off"?)
|
||||
.preamble_cfg = 0x00 | 0x00 | 0x1F,
|
||||
};
|
||||
|
||||
int M10M20::setup(float frequency, int /*type*/)
|
||||
{
|
||||
M10M20_DBG(Serial.println("Setup sx1278 for M10/M20 sonde"));;
|
||||
if(sx1278.ON()!=0) {
|
||||
|
|
@ -92,6 +104,11 @@ int M10M20::setup(float frequency)
|
|||
}
|
||||
|
||||
//// Step 2: Real reception
|
||||
if( DecoderBase::setup(m10m20SetupCfg, sonde.config.m10m20.agcbw, sonde.config.m10m20.rxbw)!=0 ) {
|
||||
return 1;
|
||||
}
|
||||
#if 0
|
||||
// Now all done in DecoderBase::setup
|
||||
// FSK standby mode, seems like otherweise baudrate cannot be changed?
|
||||
sx1278.setFSK();
|
||||
if(sx1278.setBitrate(9600)!=0) {
|
||||
|
|
@ -127,6 +144,7 @@ int M10M20::setup(float frequency)
|
|||
M10M20_DBG(Serial.println("Setting PreambleDetect FAILED"));
|
||||
return 1;
|
||||
}
|
||||
#endif
|
||||
|
||||
// Packet config 1: fixed len, no mancecer, no crc, no address filter
|
||||
// Packet config 2: packet mode, no home ctrl, no beackn, msb(packetlen)=0)
|
||||
|
|
|
|||
|
|
@ -15,9 +15,10 @@
|
|||
#ifndef inttypes_h
|
||||
#include <inttypes.h>
|
||||
#endif
|
||||
#include "DecoderBase.h"
|
||||
|
||||
/* Main class */
|
||||
class M10M20
|
||||
class M10M20 : public DecoderBase
|
||||
{
|
||||
private:
|
||||
void printRaw(uint8_t *data, int len);
|
||||
|
|
@ -53,7 +54,7 @@ private:
|
|||
|
||||
public:
|
||||
M10M20();
|
||||
int setup(float frequency);
|
||||
int setup(float frequency, int type = 0);
|
||||
int receive();
|
||||
int waitRXcomplete();
|
||||
|
||||
|
|
|
|||
|
|
@ -35,7 +35,16 @@ static int headerDetected = 0;
|
|||
|
||||
extern uint16_t MON[];
|
||||
|
||||
int MP3H::setup(float frequency)
|
||||
decoderSetupCfg mp3hSetupCfg = {
|
||||
.bitrate = 2400,
|
||||
.rx_cfg = 0x00,
|
||||
.sync_cfg = 0x70,
|
||||
.sync_len = 1,
|
||||
.sync_data = (const uint8_t *)"\x66\x66",
|
||||
.preamble_cfg = 0x00 | 0x00 | 0x1F
|
||||
};
|
||||
|
||||
int MP3H::setup(float frequency, int /*type*/)
|
||||
{
|
||||
MP3H_DBG(Serial.println("Setup sx1278 for MP3H sonde"));;
|
||||
if(sx1278.ON()!=0) {
|
||||
|
|
@ -63,6 +72,11 @@ int MP3H::setup(float frequency)
|
|||
}
|
||||
|
||||
//// Step 2: Real reception
|
||||
if(DecoderBase::setup(mp3hSetupCfg, sonde.config.mp3h.agcbw, sonde.config.mp3h.rxbw)!=0) {
|
||||
return 1;
|
||||
}
|
||||
#if 0
|
||||
// Now all done in Decoderbase
|
||||
// FSK standby mode, seems like otherweise baudrate cannot be changed?
|
||||
sx1278.setFSK();
|
||||
if(sx1278.setBitrate(2400)!=0) {
|
||||
|
|
@ -98,6 +112,7 @@ int MP3H::setup(float frequency)
|
|||
MP3H_DBG(Serial.println("Setting PreambleDetect FAILED"));
|
||||
return 1;
|
||||
}
|
||||
#endif
|
||||
|
||||
// Packet config 1: fixed len, no mancecer, no crc, no address filter
|
||||
// Packet config 2: packet mode, no home ctrl, no beackn, msb(packetlen)=0)
|
||||
|
|
|
|||
|
|
@ -15,9 +15,10 @@
|
|||
#ifndef inttypes_h
|
||||
#include <inttypes.h>
|
||||
#endif
|
||||
#include "DecoderBase.h"
|
||||
|
||||
/* Main class */
|
||||
class MP3H
|
||||
class MP3H : public DecoderBase
|
||||
{
|
||||
private:
|
||||
void printRaw(uint8_t *data, int len);
|
||||
|
|
@ -25,7 +26,7 @@ private:
|
|||
int decodeframeMP3H(uint8_t *data);
|
||||
public:
|
||||
MP3H();
|
||||
int setup(float frequency);
|
||||
int setup(float frequency, int type = 0);
|
||||
int receive();
|
||||
int waitRXcomplete();
|
||||
};
|
||||
|
|
|
|||
|
|
@ -193,7 +193,17 @@ static void Gencrctab(void)
|
|||
} /* end for */
|
||||
} /* end Gencrctab() */
|
||||
|
||||
int RS41::setup(float frequency)
|
||||
decoderSetupCfg rs41SetupCfg = {
|
||||
.bitrate = 4800,
|
||||
.rx_cfg = 0x1E, // Enable auto-AFC, auto-AGC, RX Trigger by preamble
|
||||
.sync_cfg = 0x57, // Set autostart_RX to 01, preamble 0, SYNC detect==on, syncsize=3 (==4 byte
|
||||
.sync_len = 8,
|
||||
.sync_data = (const uint8_t *)"\x08\x6D\x53\x88\x44\x69\x48\x1F",
|
||||
.preamble_cfg = 0xA8,
|
||||
};
|
||||
|
||||
|
||||
int RS41::setup(float frequency, int /*type*/)
|
||||
{
|
||||
if(!initialized) {
|
||||
Gencrctab();
|
||||
|
|
@ -205,6 +215,11 @@ int RS41::setup(float frequency)
|
|||
RS41_DBG(Serial.println("Setting SX1278 power on FAILED"));
|
||||
return 1;
|
||||
}
|
||||
if(DecoderBase::setup(rs41SetupCfg, sonde.config.rs41.agcbw, sonde.config.rs41.rxbw)!=0 ) {
|
||||
return 1;
|
||||
}
|
||||
#if 0
|
||||
// all moved to DecoderBase now
|
||||
if(sx1278.setFSK()!=0) {
|
||||
RS41_DBG(Serial.println("Setting FSK mode FAILED"));
|
||||
return 1;
|
||||
|
|
@ -240,6 +255,7 @@ int RS41::setup(float frequency)
|
|||
RS41_DBG(Serial.println("Setting PreambleDetect FAILED"));
|
||||
return 1;
|
||||
}
|
||||
#endif
|
||||
|
||||
// Packet config 1: fixed len, no mancecer, no crc, no address filter
|
||||
// Packet config 2: packet mode, no home ctrl, no beackn, msb(packetlen)=0)
|
||||
|
|
|
|||
|
|
@ -16,9 +16,10 @@
|
|||
#include <inttypes.h>
|
||||
#endif
|
||||
#include "Sonde.h"
|
||||
#include "DecoderBase.h"
|
||||
|
||||
/* Main class */
|
||||
class RS41
|
||||
class RS41 : public DecoderBase
|
||||
{
|
||||
private:
|
||||
uint32_t bits2val(const uint8_t *bits, int len);
|
||||
|
|
@ -51,7 +52,7 @@ public:
|
|||
RS41();
|
||||
// New interface:
|
||||
// setup() is called when channel is activated (sets mode and frequency and activates receiver)
|
||||
int setup(float frequency);
|
||||
int setup(float frequency, int type = 0);
|
||||
// processRXbyte is called by background task for each received byte
|
||||
// should be fast enough to not cause sx127x fifo buffer overflow
|
||||
// void processRXbyte(uint8_t data);
|
||||
|
|
|
|||
|
|
@ -68,7 +68,16 @@ static int haveNewFrame = 0;
|
|||
static int lastFrame = 0;
|
||||
static int headerDetected = 0;
|
||||
|
||||
int RS92::setup(float frequency)
|
||||
decoderSetupCfg rs92SetupCfg = {
|
||||
.bitrate = 4800,
|
||||
.rx_cfg = 0x1E,
|
||||
.sync_cfg = 0x70,
|
||||
.sync_len = 2,
|
||||
.sync_data = (const uint8_t *)"\x66\x65",
|
||||
.preamble_cfg = 0xA8,
|
||||
};
|
||||
|
||||
int RS92::setup(float frequency, int /*type*/)
|
||||
{
|
||||
#if RS92_DEBUG
|
||||
Serial.println("Setup sx1278 for RS92 sonde");
|
||||
|
|
@ -84,6 +93,10 @@ int RS92::setup(float frequency)
|
|||
RS92_DBG(Serial.println("Setting SX1278 power on FAILED"));
|
||||
return 1;
|
||||
}
|
||||
if(DecoderBase::setup(rs92SetupCfg, sonde.config.rs92.rxbw, sonde.config.rs92.rxbw)!=0) {
|
||||
return 1;
|
||||
}
|
||||
#if 0
|
||||
if(sx1278.setFSK()!=0) {
|
||||
RS92_DBG(Serial.println("Setting FSJ mode FAILED"));
|
||||
return 1;
|
||||
|
|
@ -118,7 +131,6 @@ int RS92::setup(float frequency)
|
|||
//const char *SYNC="\x08\x6D\x53\x88\x44\x69\x48\x1F";
|
||||
// was 0x57
|
||||
//const char *SYNC="\x99\x9A";
|
||||
#if 1
|
||||
// version 1, working with continuous RX
|
||||
const char *SYNC="\x66\x65";
|
||||
if(sx1278.setSyncConf(0x70, 2, (const uint8_t *)SYNC)!=0) {
|
||||
|
|
@ -130,6 +142,7 @@ int RS92::setup(float frequency)
|
|||
return 1;
|
||||
}
|
||||
#endif
|
||||
|
||||
#if 0
|
||||
// version 2, with per-packet rx start, untested
|
||||
// header is 2a 10 65, i.e. with lsb first
|
||||
|
|
|
|||
|
|
@ -15,6 +15,7 @@
|
|||
#ifndef inttypes_h
|
||||
#include <inttypes.h>
|
||||
#endif
|
||||
#include "DecoderBase.h"
|
||||
|
||||
|
||||
struct CONTEXTR9 {
|
||||
|
|
@ -49,7 +50,7 @@ struct CONTEXTR9 {
|
|||
|
||||
|
||||
/* Main class */
|
||||
class RS92
|
||||
class RS92 : public DecoderBase
|
||||
{
|
||||
private:
|
||||
void process8N1data(uint8_t data);
|
||||
|
|
@ -79,7 +80,7 @@ private:
|
|||
|
||||
public:
|
||||
RS92();
|
||||
int setup(float frequency);
|
||||
int setup(float frequency, int type = 0);
|
||||
int receive();
|
||||
int waitRXcomplete();
|
||||
|
||||
|
|
|
|||
Loading…
Reference in New Issue