make debug level configurable in FRAM
This commit is contained in:
parent
eb419b016a
commit
754404a771
|
|
@ -29,8 +29,6 @@
|
||||||
|
|
||||||
using namespace McciCatena;
|
using namespace McciCatena;
|
||||||
|
|
||||||
#define DEBUG
|
|
||||||
|
|
||||||
/****************************************************************************\
|
/****************************************************************************\
|
||||||
|
|
|
|
||||||
| MANIFEST CONSTANTS & TYPEDEFS
|
| MANIFEST CONSTANTS & TYPEDEFS
|
||||||
|
|
@ -103,6 +101,8 @@ cCommandStream::CommandFn cmdCalibrateZeroScaleA;
|
||||||
cCommandStream::CommandFn cmdCalibrateZeroScaleB;
|
cCommandStream::CommandFn cmdCalibrateZeroScaleB;
|
||||||
cCommandStream::CommandFn cmdCalibrateScaleA;
|
cCommandStream::CommandFn cmdCalibrateScaleA;
|
||||||
cCommandStream::CommandFn cmdCalibrateScaleB;
|
cCommandStream::CommandFn cmdCalibrateScaleB;
|
||||||
|
cCommandStream::CommandFn cmdSetDebugLevel;
|
||||||
|
cCommandStream::CommandFn cmdGetDebugLevel;
|
||||||
|
|
||||||
// the individual commmands are put in this table
|
// the individual commmands are put in this table
|
||||||
static const cCommandStream::cEntry sMyExtraCommmands[] =
|
static const cCommandStream::cEntry sMyExtraCommmands[] =
|
||||||
|
|
@ -114,6 +114,8 @@ static const cCommandStream::cEntry sMyExtraCommmands[] =
|
||||||
{ "calibrate_zero_scale_b", cmdCalibrateZeroScaleB },
|
{ "calibrate_zero_scale_b", cmdCalibrateZeroScaleB },
|
||||||
{ "calibrate_scale_a", cmdCalibrateScaleA },
|
{ "calibrate_scale_a", cmdCalibrateScaleA },
|
||||||
{ "calibrate_scale_b", cmdCalibrateScaleB },
|
{ "calibrate_scale_b", cmdCalibrateScaleB },
|
||||||
|
{ "set_debug_level", cmdSetDebugLevel },
|
||||||
|
{ "get_debug_level", cmdGetDebugLevel },
|
||||||
// other commands go here....
|
// other commands go here....
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
@ -146,17 +148,18 @@ static const uint16_t SEND_DIFF_THRESHOLD_5GRAMS = 10; // when weight value dr
|
||||||
|
|
|
|
||||||
\****************************************************************************/
|
\****************************************************************************/
|
||||||
|
|
||||||
// must be 65 bytes long...
|
// must be 139 bytes long (size of kBme680Cal)
|
||||||
typedef struct {
|
typedef struct {
|
||||||
long cal_w1_0; // 4 Bytes, Wert Waegezelle 1 ohne Gewicht
|
long cal_w1_0; // 4 Bytes, Wert Waegezelle 1 ohne Gewicht
|
||||||
long cal_w2_0; // 4 Bytes, Wert Waegezelle 2 ohne Gewicht
|
long cal_w2_0; // 4 Bytes, Wert Waegezelle 2 ohne Gewicht
|
||||||
float cal_w1_factor; // 4 Bytes,
|
float cal_w1_factor; // 4 Bytes, Kalibrationsfaktor Waegezelle 1
|
||||||
float cal_w2_factor;
|
float cal_w2_factor; // 4 Bytes, Kalibrationsfaktor Waegezelle 2
|
||||||
byte fill[123];
|
byte debug_level; // 0 => no debugging, 1 => infos, 2 => error, 3 => highest level
|
||||||
|
byte fill[122];
|
||||||
} __attribute__((packed)) CONFIG_data;
|
} __attribute__((packed)) CONFIG_data;
|
||||||
|
|
||||||
typedef struct {
|
typedef struct {
|
||||||
uint8_t version; // Version
|
uint8_t version; // Version of Packet Format (must be increased every time format changes...)
|
||||||
uint8_t vbat; // Batteriespannung (0: <= 2510mV, 70: 3000mV, 170: 3700mV, 255: >= 4295mV [1 Einheit => 7mV])
|
uint8_t vbat; // Batteriespannung (0: <= 2510mV, 70: 3000mV, 170: 3700mV, 255: >= 4295mV [1 Einheit => 7mV])
|
||||||
uint8_t humidity[MAX_VALUES_TO_SEND]; // Luftfeuchtigkeit in Prozent
|
uint8_t humidity[MAX_VALUES_TO_SEND]; // Luftfeuchtigkeit in Prozent
|
||||||
int16_t temperature; // Temperatur (Startwert) in 1/10 Grad Celsius
|
int16_t temperature; // Temperatur (Startwert) in 1/10 Grad Celsius
|
||||||
|
|
@ -212,7 +215,6 @@ Catena::LoRaWAN gLoRaWAN;
|
||||||
|
|
||||||
//
|
//
|
||||||
// the LED
|
// the LED
|
||||||
//
|
|
||||||
StatusLed gLed(Catena::PIN_STATUS_LED);
|
StatusLed gLed(Catena::PIN_STATUS_LED);
|
||||||
|
|
||||||
// The temperature/humidity sensor
|
// The temperature/humidity sensor
|
||||||
|
|
@ -267,18 +269,20 @@ void setup_platform(void)
|
||||||
);
|
);
|
||||||
|
|
||||||
// read config_data from fram...
|
// read config_data from fram...
|
||||||
#ifdef DEBUG
|
if (config_data.debug_level > 0) {
|
||||||
gCatena.SafePrintf("Reading Calibration Config from FRAM...\n");
|
gCatena.SafePrintf("Reading Calibration Config from FRAM...\n");
|
||||||
#endif
|
}
|
||||||
gCatena.getFram()->getField(cFramStorage::kBme680Cal, (uint8_t *)&config_data, sizeof(config_data));
|
gCatena.getFram()->getField(cFramStorage::kBme680Cal, (uint8_t *)&config_data, sizeof(config_data));
|
||||||
|
|
||||||
#ifdef DEBUG
|
if (config_data.debug_level > 0) {
|
||||||
gCatena.SafePrintf("cal_w1_0: %d\n", config_data.cal_w1_0);
|
gCatena.SafePrintf("cal_w1_0: %d\n", config_data.cal_w1_0);
|
||||||
gCatena.SafePrintf("cal_w2_0: %d\n", config_data.cal_w2_0);
|
gCatena.SafePrintf("cal_w2_0: %d\n", config_data.cal_w2_0);
|
||||||
gCatena.SafePrintf("cal_w1_factor: %d.%03d\n", (int)config_data.cal_w1_factor, (int)(config_data.cal_w1_factor * 1000) % 1000);
|
gCatena.SafePrintf("cal_w1_factor: %d.%03d\n", (int)config_data.cal_w1_factor, (int)(config_data.cal_w1_factor * 1000) % 1000);
|
||||||
gCatena.SafePrintf("cal_w2_factor: %d.%03d\n", (int)config_data.cal_w2_factor, (int)(config_data.cal_w2_factor * 1000) % 1000);
|
gCatena.SafePrintf("cal_w2_factor: %d.%03d\n", (int)config_data.cal_w2_factor, (int)(config_data.cal_w2_factor * 1000) % 1000);
|
||||||
gCatena.SafePrintf("Size of config_data: %d\n", sizeof(config_data));
|
gCatena.SafePrintf("debug_level: %d\n", (int)config_data.debug_level);
|
||||||
#endif
|
gCatena.SafePrintf("Size of config_data: %d\n", sizeof(config_data));
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
#ifdef USBCON
|
#ifdef USBCON
|
||||||
// if running unattended, don't wait for USB connect.
|
// if running unattended, don't wait for USB connect.
|
||||||
|
|
@ -381,9 +385,9 @@ bool setup_scales(void)
|
||||||
bool res;
|
bool res;
|
||||||
res = true;
|
res = true;
|
||||||
|
|
||||||
#ifdef DEBUG
|
if (config_data.debug_level > 0) {
|
||||||
gCatena.SafePrintf("Setup Scales...\n");
|
gCatena.SafePrintf("Setup Scales...\n");
|
||||||
#endif
|
}
|
||||||
|
|
||||||
// Enable Power
|
// Enable Power
|
||||||
digitalWrite(D10, HIGH);
|
digitalWrite(D10, HIGH);
|
||||||
|
|
@ -401,9 +405,9 @@ bool setup_scales(void)
|
||||||
res = false;
|
res = false;
|
||||||
}
|
}
|
||||||
|
|
||||||
#ifdef DEBUG
|
if (config_data.debug_level > 0) {
|
||||||
gCatena.SafePrintf("Setup Scale is complete\n");
|
gCatena.SafePrintf("Setup Scale is complete\n");
|
||||||
#endif
|
}
|
||||||
|
|
||||||
return res;
|
return res;
|
||||||
}
|
}
|
||||||
|
|
@ -413,13 +417,17 @@ void setup_flash(void)
|
||||||
if (gFlash.begin(&gSPI2, Catena::PIN_SPI2_FLASH_SS)) {
|
if (gFlash.begin(&gSPI2, Catena::PIN_SPI2_FLASH_SS)) {
|
||||||
fFlash = true;
|
fFlash = true;
|
||||||
gFlash.powerDown();
|
gFlash.powerDown();
|
||||||
gCatena.SafePrintf("FLASH found, but power down\n");
|
if (config_data.debug_level > 0) {
|
||||||
|
gCatena.SafePrintf("FLASH found, but power down\n");
|
||||||
|
}
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
fFlash = false;
|
fFlash = false;
|
||||||
gFlash.end();
|
gFlash.end();
|
||||||
gSPI2.end();
|
gSPI2.end();
|
||||||
gCatena.SafePrintf("No FLASH found: check hardware\n");
|
if (config_data.debug_level > 0) {
|
||||||
|
gCatena.SafePrintf("No FLASH found: check hardware\n");
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -427,7 +435,9 @@ void setup_uplink(void)
|
||||||
{
|
{
|
||||||
|
|
||||||
// Do an unjoin, so every reboot will trigger a join
|
// Do an unjoin, so every reboot will trigger a join
|
||||||
gCatena.SafePrintf("Do an unjoin...\n");
|
if (config_data.debug_level > 0) {
|
||||||
|
gCatena.SafePrintf("Do an unjoin...\n");
|
||||||
|
}
|
||||||
LMIC_unjoin();
|
LMIC_unjoin();
|
||||||
|
|
||||||
/* trigger a join by sending the first packet */
|
/* trigger a join by sending the first packet */
|
||||||
|
|
@ -563,7 +573,9 @@ uint8_t GetVBatValue(int millivolts)
|
||||||
|
|
||||||
void DoDeepSleep()
|
void DoDeepSleep()
|
||||||
{
|
{
|
||||||
gCatena.SafePrintf("Now going to deep sleep: %d\n", millis());
|
if (config_data.debug_level > 0) {
|
||||||
|
gCatena.SafePrintf("Now going to deep sleep: %d\n", millis());
|
||||||
|
}
|
||||||
|
|
||||||
// Prepare Deep Sleep
|
// Prepare Deep Sleep
|
||||||
gLed.Set(LedPattern::Off);
|
gLed.Set(LedPattern::Off);
|
||||||
|
|
@ -583,7 +595,9 @@ void DoDeepSleep()
|
||||||
SPI.begin();
|
SPI.begin();
|
||||||
if (fFlash)
|
if (fFlash)
|
||||||
gSPI2.begin();
|
gSPI2.begin();
|
||||||
gCatena.SafePrintf("Done with deep sleep: %d\n", millis());
|
if (config_data.debug_level > 0) {
|
||||||
|
gCatena.SafePrintf("Done with deep sleep: %d\n", millis());
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
@ -600,43 +614,43 @@ void ReadSensors(bool firstTime, bool readOnly)
|
||||||
|
|
||||||
// vBat
|
// vBat
|
||||||
float vBat = gCatena.ReadVbat();
|
float vBat = gCatena.ReadVbat();
|
||||||
#ifdef DEBUG
|
if (config_data.debug_level > 0) {
|
||||||
gCatena.SafePrintf("vBat: %d mV\n", (int)(vBat * 1000.0f));
|
gCatena.SafePrintf("vBat: %d mV\n", (int)(vBat * 1000.0f));
|
||||||
#endif
|
}
|
||||||
|
|
||||||
// vBus
|
// vBus
|
||||||
float vBus = gCatena.ReadVbus();
|
float vBus = gCatena.ReadVbus();
|
||||||
#ifdef DEBUG
|
if (config_data.debug_level > 0) {
|
||||||
gCatena.SafePrintf("vBus: %d mV\n", (int)(vBus * 1000.0f));
|
gCatena.SafePrintf("vBus: %d mV\n", (int)(vBus * 1000.0f));
|
||||||
#endif
|
}
|
||||||
fUsbPower = (vBus > 3.0) ? true : false;
|
fUsbPower = (vBus > 3.0) ? true : false;
|
||||||
|
|
||||||
// Setup Scales
|
// Setup Scales
|
||||||
//setup_scales();
|
|
||||||
|
|
||||||
// Read Scales
|
// Read Scales
|
||||||
//if (LoadCell.is_ready()) {
|
|
||||||
if (setup_scales()) {
|
if (setup_scales()) {
|
||||||
#ifdef DEBUG
|
if (config_data.debug_level > 0) {
|
||||||
gCatena.SafePrintf("HX711 LoadCell is ready.\n");
|
gCatena.SafePrintf("HX711 LoadCell is ready.\n");
|
||||||
#endif
|
}
|
||||||
LoadCell.set_gain(128);
|
LoadCell.set_gain(128);
|
||||||
long w1 = LoadCell.read_average(5);
|
long w1 = LoadCell.read_average(5);
|
||||||
weight1_current = (int32_t)w1;
|
weight1_current = (int32_t)w1;
|
||||||
#ifdef DEBUG
|
if (config_data.debug_level > 0) {
|
||||||
gCatena.SafePrintf("Load_cell 1 output val: %ld\n", w1);
|
gCatena.SafePrintf("Load_cell 1 output val: %ld\n", w1);
|
||||||
gCatena.SafePrintf("Load_cell 1 weight1_current: %ld\n", weight1_current);
|
gCatena.SafePrintf("Load_cell 1 weight1_current: %ld\n", weight1_current);
|
||||||
#endif
|
}
|
||||||
LoadCell.set_gain(32);
|
LoadCell.set_gain(32);
|
||||||
long w2 = LoadCell.read_average(5);
|
long w2 = LoadCell.read_average(5);
|
||||||
weight2_current = (int32_t)w2;
|
weight2_current = (int32_t)w2;
|
||||||
#ifdef DEBUG
|
if (config_data.debug_level > 0) {
|
||||||
gCatena.SafePrintf("Load_cell 2 output val: %ld\n", w2);
|
gCatena.SafePrintf("Load_cell 2 output val: %ld\n", w2);
|
||||||
gCatena.SafePrintf("Load_cell 2 weight2_current: %ld\n", weight2_current);
|
gCatena.SafePrintf("Load_cell 2 weight2_current: %ld\n", weight2_current);
|
||||||
#endif
|
}
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
gCatena.SafePrintf("HX711 LoadCell not ready.\n");
|
if (config_data.debug_level > 0) {
|
||||||
|
gCatena.SafePrintf("HX711 LoadCell not ready.\n");
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// Disable Power
|
// Disable Power
|
||||||
|
|
@ -659,19 +673,19 @@ void ReadSensors(bool firstTime, bool readOnly)
|
||||||
// temperature is 2 bytes from -0x80.00 to +0x7F.FF degrees C
|
// temperature is 2 bytes from -0x80.00 to +0x7F.FF degrees C
|
||||||
// pressure is 2 bytes, hPa * 10.
|
// pressure is 2 bytes, hPa * 10.
|
||||||
// humidity is one byte, where 0 == 0/256 and 0xFF == 255/256.
|
// humidity is one byte, where 0 == 0/256 and 0xFF == 255/256.
|
||||||
#ifdef DEBUG
|
if (config_data.debug_level > 0) {
|
||||||
gCatena.SafePrintf(
|
gCatena.SafePrintf(
|
||||||
"BME280: T: %d P: %d RH: %d\n",
|
"BME280: T: %d P: %d RH: %d\n",
|
||||||
(int)m.Temperature,
|
(int)m.Temperature,
|
||||||
(int)m.Pressure,
|
(int)m.Pressure,
|
||||||
(int)m.Humidity);
|
(int)m.Humidity);
|
||||||
#endif
|
}
|
||||||
temp_current = (int16_t)((m.Temperature) * 10);
|
temp_current = (int16_t)((m.Temperature) * 10);
|
||||||
humidity_current = (uint8_t)m.Humidity;
|
humidity_current = (uint8_t)m.Humidity;
|
||||||
pressure_current = (uint8_t)((m.Pressure / 100) - PRESSURE_OFFSET);
|
pressure_current = (uint8_t)((m.Pressure / 100) - PRESSURE_OFFSET);
|
||||||
#ifdef DEBUG
|
if (config_data.debug_level > 0) {
|
||||||
gCatena.SafePrintf("pressure_current: %d\n", pressure_current);
|
gCatena.SafePrintf("pressure_current: %d\n", pressure_current);
|
||||||
#endif
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if (not(readOnly)) {
|
if (not(readOnly)) {
|
||||||
|
|
@ -708,7 +722,9 @@ void ReadSensors(bool firstTime, bool readOnly)
|
||||||
timer_pos0 = millis();
|
timer_pos0 = millis();
|
||||||
}
|
}
|
||||||
|
|
||||||
ShowLORAData(firstTime);
|
if (config_data.debug_level > 0) {
|
||||||
|
ShowLORAData(firstTime);
|
||||||
|
}
|
||||||
my_position++;
|
my_position++;
|
||||||
|
|
||||||
// Should we send the Data?
|
// Should we send the Data?
|
||||||
|
|
@ -717,11 +733,20 @@ void ReadSensors(bool firstTime, bool readOnly)
|
||||||
// more than one hour old (which should not happen :-) )
|
// more than one hour old (which should not happen :-) )
|
||||||
if (firstTime || (my_position >= MAX_VALUES_TO_SEND) || ((last_sensor_reading.weight - weight_current) > SEND_DIFF_THRESHOLD_5GRAMS) || ((millis() - timer_pos0) > 3600000)) {
|
if (firstTime || (my_position >= MAX_VALUES_TO_SEND) || ((last_sensor_reading.weight - weight_current) > SEND_DIFF_THRESHOLD_5GRAMS) || ((millis() - timer_pos0) > 3600000)) {
|
||||||
lora_data.offset_last_reading = (uint8_t)((millis() - timer_pos0) / 1000 / 60);
|
lora_data.offset_last_reading = (uint8_t)((millis() - timer_pos0) / 1000 / 60);
|
||||||
gCatena.SafePrintf("startSendingUplink()\n");
|
if (config_data.debug_level > 0) {
|
||||||
|
gCatena.SafePrintf("startSendingUplink()\n");
|
||||||
|
}
|
||||||
startSendingUplink(firstTime);
|
startSendingUplink(firstTime);
|
||||||
} else {
|
} else {
|
||||||
gCatena.SafePrintf("now going to sleep for 6 minutes...\n");
|
if (config_data.debug_level > 0) {
|
||||||
//Serial.flush();
|
gCatena.SafePrintf("now going to sleep for 6 minutes...\n");
|
||||||
|
if (fUsbPower) {
|
||||||
|
gCatena.SafePrintf("USB Power is on\n");
|
||||||
|
} else {
|
||||||
|
gCatena.SafePrintf("USB Power is off\n");
|
||||||
|
}
|
||||||
|
//Serial.flush();
|
||||||
|
}
|
||||||
gLed.Set(LedPattern::Sleeping);
|
gLed.Set(LedPattern::Sleeping);
|
||||||
os_setTimedCallback(
|
os_setTimedCallback(
|
||||||
&sensorJob,
|
&sensorJob,
|
||||||
|
|
@ -754,21 +779,21 @@ void startSendingUplink(bool firstTime)
|
||||||
|
|
||||||
bool fConfirmed = false;
|
bool fConfirmed = false;
|
||||||
if (gCatena.GetOperatingFlags() & (1 << 16)) {
|
if (gCatena.GetOperatingFlags() & (1 << 16)) {
|
||||||
#ifdef DEBUG
|
if (config_data.debug_level > 0) {
|
||||||
gCatena.SafePrintf("requesting confirmed tx\n");
|
gCatena.SafePrintf("requesting confirmed tx\n");
|
||||||
#endif
|
}
|
||||||
fConfirmed = true;
|
fConfirmed = true;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (firstTime) {
|
if (firstTime) {
|
||||||
#ifdef DEBUG
|
if (config_data.debug_level > 0) {
|
||||||
gCatena.SafePrintf("SendBuffer firstTime\n");
|
gCatena.SafePrintf("SendBuffer firstTime\n");
|
||||||
#endif
|
}
|
||||||
gLoRaWAN.SendBuffer((uint8_t*)&lora_data_first, sizeof(LORA_data_first), sendBufferDoneCb, NULL, fConfirmed, kUplinkPort);
|
gLoRaWAN.SendBuffer((uint8_t*)&lora_data_first, sizeof(LORA_data_first), sendBufferDoneCb, NULL, fConfirmed, kUplinkPort);
|
||||||
} else {
|
} else {
|
||||||
#ifdef DEBUG
|
if (config_data.debug_level > 0) {
|
||||||
gCatena.SafePrintf("SendBuffer not firstTime\n");
|
gCatena.SafePrintf("SendBuffer not firstTime\n");
|
||||||
#endif
|
}
|
||||||
gLoRaWAN.SendBuffer((uint8_t*)&lora_data, sizeof(LORA_data), sendBufferDoneCb, NULL, fConfirmed, kUplinkPort);
|
gLoRaWAN.SendBuffer((uint8_t*)&lora_data, sizeof(LORA_data), sendBufferDoneCb, NULL, fConfirmed, kUplinkPort);
|
||||||
}
|
}
|
||||||
ClearLoraData();
|
ClearLoraData();
|
||||||
|
|
@ -794,7 +819,9 @@ static void sendBufferDoneCb(
|
||||||
gLoRaWAN.Shutdown();
|
gLoRaWAN.Shutdown();
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
gCatena.SafePrintf("send buffer failed\n");
|
if (config_data.debug_level > 0) {
|
||||||
|
gCatena.SafePrintf("send buffer failed\n");
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
os_setTimedCallback(
|
os_setTimedCallback(
|
||||||
|
|
@ -808,7 +835,9 @@ static void txNotProvisionedCb(
|
||||||
osjob_t *pSendJob
|
osjob_t *pSendJob
|
||||||
)
|
)
|
||||||
{
|
{
|
||||||
gCatena.SafePrintf("LoRaWAN not provisioned yet. Use the commands to set it up.\n");
|
if (config_data.debug_level > 0) {
|
||||||
|
gCatena.SafePrintf("LoRaWAN not provisioned yet. Use the commands to set it up.\n");
|
||||||
|
}
|
||||||
gLoRaWAN.Shutdown();
|
gLoRaWAN.Shutdown();
|
||||||
gLed.Set(LedPattern::NotProvisioned);
|
gLed.Set(LedPattern::NotProvisioned);
|
||||||
}
|
}
|
||||||
|
|
@ -817,17 +846,18 @@ static void txNotProvisionedCb(
|
||||||
static void settleDoneCb(
|
static void settleDoneCb(
|
||||||
osjob_t* pSendJob)
|
osjob_t* pSendJob)
|
||||||
{
|
{
|
||||||
#ifdef DEBUG
|
if (config_data.debug_level > 0) {
|
||||||
gCatena.SafePrintf("settleDoneCb\n");
|
gCatena.SafePrintf("settleDoneCb\n");
|
||||||
#endif
|
}
|
||||||
// Terry vv
|
|
||||||
gCatena.SafePrintf("LMIC.rxDelay: %i\n", LMIC.rxDelay);
|
|
||||||
gCatena.SafePrintf("LMIC.dn2Dr: %i\n", LMIC.dn2Dr);
|
|
||||||
gCatena.SafePrintf("LMIC.dn2Freq: %i\n", LMIC.dn2Freq);
|
|
||||||
gCatena.SafePrintf("LMIC.rx1DrOffset: %i\n", LMIC.rx1DrOffset);
|
|
||||||
|
|
||||||
// Terry ^^
|
|
||||||
|
|
||||||
|
if (config_data.debug_level > 2) {
|
||||||
|
// Terry vv
|
||||||
|
gCatena.SafePrintf("LMIC.rxDelay: %i\n", LMIC.rxDelay);
|
||||||
|
gCatena.SafePrintf("LMIC.dn2Dr: %i\n", LMIC.dn2Dr);
|
||||||
|
gCatena.SafePrintf("LMIC.dn2Freq: %i\n", LMIC.dn2Freq);
|
||||||
|
gCatena.SafePrintf("LMIC.rx1DrOffset: %i\n", LMIC.rx1DrOffset);
|
||||||
|
// Terry ^^
|
||||||
|
}
|
||||||
|
|
||||||
sleepDoneCb(pSendJob);
|
sleepDoneCb(pSendJob);
|
||||||
}
|
}
|
||||||
|
|
@ -852,42 +882,48 @@ static void receiveMessage(void *pContext, uint8_t port, const uint8_t *pMessage
|
||||||
unsigned txCycle;
|
unsigned txCycle;
|
||||||
unsigned txCount;
|
unsigned txCount;
|
||||||
|
|
||||||
#ifdef DEBUG
|
if (config_data.debug_level > 0) {
|
||||||
gCatena.SafePrintf("receiveMessage was called!!!\n");
|
gCatena.SafePrintf("receiveMessage was called!!!\n");
|
||||||
#endif
|
|
||||||
// Terry vv
|
|
||||||
if (port == 0)
|
|
||||||
{
|
|
||||||
gCatena.SafePrintf("MAC message:");
|
|
||||||
for (unsigned i = 0; i < LMIC.dataBeg; ++i)
|
|
||||||
{
|
|
||||||
gCatena.SafePrintf(" %02x", LMIC.frame[i]);
|
|
||||||
}
|
|
||||||
return;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (config_data.debug_level > 2) {
|
||||||
|
// Terry vv
|
||||||
|
if (port == 0)
|
||||||
|
{
|
||||||
|
gCatena.SafePrintf("MAC message:");
|
||||||
|
for (unsigned i = 0; i < LMIC.dataBeg; ++i)
|
||||||
|
{
|
||||||
|
gCatena.SafePrintf(" %02x", LMIC.frame[i]);
|
||||||
|
}
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
gCatena.SafePrintf("receiveMessage was called!!!!n");
|
gCatena.SafePrintf("receiveMessage was called!!!!n");
|
||||||
gCatena.SafePrintf("Port: %s\n", port);
|
gCatena.SafePrintf("Port: %s\n", port);
|
||||||
gCatena.SafePrintf("LMIC.rxDelay: %i\n", LMIC.rxDelay);
|
gCatena.SafePrintf("LMIC.rxDelay: %i\n", LMIC.rxDelay);
|
||||||
gCatena.SafePrintf("LMIC.dn2Dr: %i\n", LMIC.dn2Dr);
|
gCatena.SafePrintf("LMIC.dn2Dr: %i\n", LMIC.dn2Dr);
|
||||||
gCatena.SafePrintf("LMIC.dn2Freq: %i\n", LMIC.dn2Freq);
|
gCatena.SafePrintf("LMIC.dn2Freq: %i\n", LMIC.dn2Freq);
|
||||||
gCatena.SafePrintf("LMIC.rx1DrOffset: %i\n", LMIC.rx1DrOffset);
|
gCatena.SafePrintf("LMIC.rx1DrOffset: %i\n", LMIC.rx1DrOffset);
|
||||||
|
// Terry ^^
|
||||||
// Terry ^^
|
}
|
||||||
|
|
||||||
if (! (port == 1 && 2 <= nMessage && nMessage <= 3))
|
if (! (port == 1 && 2 <= nMessage && nMessage <= 3))
|
||||||
{
|
{
|
||||||
gCatena.SafePrintf("invalid message port(%02x)/length(%zx)\n",
|
if (config_data.debug_level > 0) {
|
||||||
port, nMessage
|
gCatena.SafePrintf("invalid message port(%02x)/length(%zx)\n",
|
||||||
);
|
port, nMessage
|
||||||
|
);
|
||||||
|
}
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
txCycle = (pMessage[0] << 8) | pMessage[1];
|
txCycle = (pMessage[0] << 8) | pMessage[1];
|
||||||
|
|
||||||
if (txCycle < CATCFG_T_MIN || txCycle > CATCFG_T_MAX)
|
if (txCycle < CATCFG_T_MIN || txCycle > CATCFG_T_MAX)
|
||||||
{
|
{
|
||||||
gCatena.SafePrintf("tx cycle time out of range: %u\n", txCycle);
|
if (config_data.debug_level > 0) {
|
||||||
|
gCatena.SafePrintf("tx cycle time out of range: %u\n", txCycle);
|
||||||
|
}
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -900,27 +936,31 @@ static void receiveMessage(void *pContext, uint8_t port, const uint8_t *pMessage
|
||||||
}
|
}
|
||||||
|
|
||||||
// we print out the received message...
|
// we print out the received message...
|
||||||
gCatena.SafePrintf("Received Data (Payload): \n");
|
if (config_data.debug_level > 2) {
|
||||||
for (byte i = 0; i < nMessage; i++) {
|
gCatena.SafePrintf("Received Data (Payload): \n");
|
||||||
gCatena.SafePrintf("%c", pMessage[i]);
|
for (byte i = 0; i < nMessage; i++) {
|
||||||
|
gCatena.SafePrintf("%c", pMessage[i]);
|
||||||
|
}
|
||||||
|
gCatena.SafePrintf("\n");
|
||||||
}
|
}
|
||||||
gCatena.SafePrintf("\n");
|
|
||||||
|
|
||||||
setTxCycleTime(txCycle, txCount);
|
setTxCycleTime(txCycle, txCount);
|
||||||
}
|
}
|
||||||
|
|
||||||
void setTxCycleTime(unsigned txCycle, unsigned txCount)
|
void setTxCycleTime(unsigned txCycle, unsigned txCount)
|
||||||
{
|
{
|
||||||
if (txCount > 0)
|
if (config_data.debug_level > 2) {
|
||||||
gCatena.SafePrintf(
|
if (txCount > 0)
|
||||||
"message cycle time %u seconds for %u messages\n",
|
gCatena.SafePrintf(
|
||||||
txCycle, txCount
|
"message cycle time %u seconds for %u messages\n",
|
||||||
);
|
txCycle, txCount
|
||||||
else
|
);
|
||||||
gCatena.SafePrintf(
|
else
|
||||||
"message cycle time %u seconds indefinitely\n",
|
gCatena.SafePrintf(
|
||||||
txCycle
|
"message cycle time %u seconds indefinitely\n",
|
||||||
);
|
txCycle
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
gTxCycle = txCycle;
|
gTxCycle = txCycle;
|
||||||
gTxCycleCount = txCount;
|
gTxCycleCount = txCount;
|
||||||
|
|
@ -1035,3 +1075,23 @@ cCommandStream::CommandStatus cmdCalibrateScaleB(cCommandStream *pThis, void *pC
|
||||||
return cCommandStream::CommandStatus::kSuccess;
|
return cCommandStream::CommandStatus::kSuccess;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
cCommandStream::CommandStatus cmdSetDebugLevel(cCommandStream *pThis, void *pContext, int argc, char **argv)
|
||||||
|
{
|
||||||
|
String s_debug_level(argv[1]);
|
||||||
|
|
||||||
|
config_data.debug_level = s_debug_level.toInt();
|
||||||
|
gCatena.getFram()->saveField(cFramStorage::kBme680Cal, (const uint8_t *)&config_data, sizeof(config_data));
|
||||||
|
|
||||||
|
pThis->printf("{ \"msg\": \"set_debug_level was successful\" }\n");
|
||||||
|
|
||||||
|
return cCommandStream::CommandStatus::kSuccess;
|
||||||
|
}
|
||||||
|
|
||||||
|
cCommandStream::CommandStatus cmdGetDebugLevel(cCommandStream *pThis, void *pContext, int argc, char **argv)
|
||||||
|
{
|
||||||
|
gCatena.getFram()->saveField(cFramStorage::kBme680Cal, (const uint8_t *)&config_data, sizeof(config_data));
|
||||||
|
|
||||||
|
pThis->printf("{ \"msg\": \"debug_level is %d\" }\n",config_data.debug_level);
|
||||||
|
|
||||||
|
return cCommandStream::CommandStatus::kSuccess;
|
||||||
|
}
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue