Rework Debugging Macros to also Work in Libraries (#6)

Co-authored-by: Stefan Brand <seiichiro@seiichiro0185.org>
Reviewed-on: https://www.seiichiro0185.org/git/attnode/v3_firmware/pulls/6
Co-authored-by: seiichiro <seiichiro@seiichiro0185.org>
Co-committed-by: seiichiro <seiichiro@seiichiro0185.org>
This commit is contained in:
seiichiro 2021-05-03 16:35:37 +00:00
parent c862eec6d0
commit 34d8c92281
15 changed files with 45 additions and 15 deletions

View file

@ -16,6 +16,15 @@ Before programming a node, copy src/config.h.example to src/config.h and set the
Programming is done using a [MicroUPDI Programmer](https://github.com/MCUdude/microUPDI), settings in platformio.ini are set to use it. For other pogrammer options see the PlatformIO Documentation Programming is done using a [MicroUPDI Programmer](https://github.com/MCUdude/microUPDI), settings in platformio.ini are set to use it. For other pogrammer options see the PlatformIO Documentation
## Debugging
The firmware has the ability to produce some debug output via the Serial UART as long as there is no sensor using the UART. To enable it, uncomment the line -D DEBUG in platformio.ini. This will produce some debug output showing the state of the node. The following macros are available as a replacement for the normal Serial.print and Serial.println functions:
DEBUG_PRINT("Debug Output");
DEBUG_PRINTLN("Debug Output with Linebreak");
These will only produce additional code in the firmware when the DEBUG-Flag is enabled, and will be entirely removed in the ouput binary if not. The macros work like the normal Serial.print* statements form the standard arduino functions.
## Payload Decoder ## Payload Decoder
You need to specify a Payload Decoder fitting for your configured Sensors for a Node. See payload/index.html in this repository. Open it in your Browser of Choice and select the enabled sensors. It will generate the Payload Decoder fitting for the choosen Sensors. You can also use the Online Version at [attno.de](https://www.attno.de/payload-generator) You need to specify a Payload Decoder fitting for your configured Sensors for a Node. See payload/index.html in this repository. Open it in your Browser of Choice and select the enabled sensors. It will generate the Payload Decoder fitting for the choosen Sensors. You can also use the Online Version at [attno.de](https://www.attno.de/payload-generator)

View file

@ -5,8 +5,6 @@ DebugUtils.h - Simple debugging utilities.
#ifndef DEBUGUTILS_H #ifndef DEBUGUTILS_H
#define DEBUGUTILS_H #define DEBUGUTILS_H
#include "config.h"
#ifdef DEBUG #ifdef DEBUG
#define DEBUG_PRINT(...) Serial.print(__VA_ARGS__); Serial.flush(); #define DEBUG_PRINT(...) Serial.print(__VA_ARGS__); Serial.flush();
#define DEBUG_PRINTLN(...) Serial.println(__VA_ARGS__); Serial.flush(); #define DEBUG_PRINTLN(...) Serial.println(__VA_ARGS__); Serial.flush();

View file

@ -5,6 +5,7 @@
BME280::BME280() {} BME280::BME280() {}
void BME280::getCalData() { void BME280::getCalData() {
DEBUG_PRINTLN("BME280::getCalData");
dig_T1 = read16_LE(0x88); dig_T1 = read16_LE(0x88);
dig_T2 = readS16_LE(0x8A); dig_T2 = readS16_LE(0x8A);
dig_T3 = readS16_LE(0x8C); dig_T3 = readS16_LE(0x8C);
@ -82,6 +83,8 @@ uint8_t BME280::getSensorData(char *payload, uint8_t startbyte) {
int32_t UP, UT, UH; int32_t UP, UT, UH;
int32_t rawP, rawT; int32_t rawP, rawT;
DEBUG_PRINTLN("BME280::geSensorData");
// Trigger Measurement // Trigger Measurement
// Set Sensor Config // Set Sensor Config
write8(0xF2, 0b00000001); // 1x Oversampling for Humidity write8(0xF2, 0b00000001); // 1x Oversampling for Humidity

View file

@ -2,6 +2,7 @@
#define BME280_H #define BME280_H
#include "../../include/attsensor.h" #include "../../include/attsensor.h"
#include "../../include/debug.h"
#define BME280_I2CADDR 0x76 #define BME280_I2CADDR 0x76

View file

@ -50,6 +50,7 @@ DS18B20::DS18B20(uint8_t owpin, uint8_t resbits = 12, bool para = false) {
} }
void DS18B20::initialize(void){ void DS18B20::initialize(void){
DEBUG_PRINTLN("DS18B20::initialize");
onewire->reset(); onewire->reset();
onewire->reset_search(); onewire->reset_search();
sensorcount = 0; sensorcount = 0;
@ -84,6 +85,8 @@ uint8_t DS18B20::getSensorData(char *payload, uint8_t startbyte){
uint8_t data[9]; uint8_t data[9];
int16_t value; int16_t value;
DEBUG_PRINTLN("DS18B20::getSensorData");
// Start Conversation on all Sensors // Start Conversation on all Sensors
onewire->reset(); onewire->reset();
onewire->skip(); onewire->skip();

View file

@ -28,6 +28,7 @@
#define DS18B20_H #define DS18B20_H
#include "../../include/attsensor.h" #include "../../include/attsensor.h"
#include "../../include/debug.h"
#include <OneWire.h> #include <OneWire.h>
// Sensor Resolutions // Sensor Resolutions

View file

@ -35,6 +35,8 @@ HM330x::HM330x() {};
// Initialize the Sensor // Initialize the Sensor
void HM330x::initialize(void) { void HM330x::initialize(void) {
uint8_t retryCount = 0; uint8_t retryCount = 0;
DEBUG_PRINTLN("HM330x::initialize");
// Send select command // Send select command
while (!sendCmd(HM330x_SELECT)) { while (!sendCmd(HM330x_SELECT)) {
if (retryCount++ >= 0) { if (retryCount++ >= 0) {
@ -50,6 +52,8 @@ uint8_t HM330x::getSensorData(char *payload, uint8_t startbyte) {
uint8_t data[HM330x_DATA_LEN] = {0}; uint8_t data[HM330x_DATA_LEN] = {0};
uint16_t value = 0; uint16_t value = 0;
DEBUG_PRINTLN("HM330x::getSensorData");
// Initialize Payload with 0s // Initialize Payload with 0s
for (uint8_t i=startbyte; i < startbyte+6; i++) for (uint8_t i=startbyte; i < startbyte+6; i++)
payload[i] = 0; payload[i] = 0;

View file

@ -28,6 +28,7 @@
#define HM330x_H #define HM330x_H
#include "../../include/attsensor.h" #include "../../include/attsensor.h"
#include "../../include/debug.h"
// Sensor I2C Address // Sensor I2C Address
#define HM330x_ADDR 0x40 #define HM330x_ADDR 0x40

View file

@ -41,6 +41,8 @@ SCD30::SCD30(uint8_t interval, bool selfcalib) {
// Initialize the Sensor, Enable Constant Measurement, Set Autocalibration and Interval // Initialize the Sensor, Enable Constant Measurement, Set Autocalibration and Interval
void SCD30::initialize(void) { void SCD30::initialize(void) {
uint8_t fw[3]; uint8_t fw[3];
DEBUG_PRINTLN("SCD30::initialize");
// Soft Reset // Soft Reset
reset(); reset();
// Send Get Firmware, Workaround to Avoid First Real Command to be Ignored // Send Get Firmware, Workaround to Avoid First Real Command to be Ignored
@ -63,6 +65,9 @@ void SCD30::initialize(void) {
uint8_t SCD30::getSensorData(char *payload, uint8_t startbyte) { uint8_t SCD30::getSensorData(char *payload, uint8_t startbyte) {
uint8_t ready[2] = {0}; uint8_t ready[2] = {0};
uint8_t data[18] = {0}; uint8_t data[18] = {0};
DEBUG_PRINTLN("SCD30::getSensorData");
// Check if Sensor Data is Available // Check if Sensor Data is Available
getBytes(SCD30_DATA_READY, ready, 2); getBytes(SCD30_DATA_READY, ready, 2);
if (ready[1] == 1){ if (ready[1] == 1){

View file

@ -28,6 +28,7 @@
#define SCD30_H #define SCD30_H
#include "../../include/attsensor.h" #include "../../include/attsensor.h"
#include "../../include/debug.h"
// Sensor I2C Address // Sensor I2C Address
#define SCD30_ADDR 0x61 #define SCD30_ADDR 0x61

View file

@ -53,6 +53,8 @@ uint16_t SHT21::sensorRead(uint8_t command) {
} }
uint8_t SHT21::getSensorData(char *payload, uint8_t startbyte) { uint8_t SHT21::getSensorData(char *payload, uint8_t startbyte) {
DEBUG_PRINTLN("SHT21::getSensorData");
// Temperature // Temperature
int32ToPayload((int32_t)((-46.85 + 175.72 / 65536.0 * (float)(sensorRead(SHT21_TEMPHOLD)))*100), payload, startbyte); int32ToPayload((int32_t)((-46.85 + 175.72 / 65536.0 * (float)(sensorRead(SHT21_TEMPHOLD)))*100), payload, startbyte);
// Humidity // Humidity

View file

@ -28,6 +28,7 @@
#define SHT21_H #define SHT21_H
#include "../../include/attsensor.h" #include "../../include/attsensor.h"
#include "../../include/debug.h"
#define SHT21_I2CADDR 0x40 #define SHT21_I2CADDR 0x40

View file

@ -24,13 +24,20 @@ board_hardware.bod = disabled
monitor_speed = 115200 monitor_speed = 115200
monitor_port = /dev/ttyACM1 monitor_port = /dev/ttyACM1
## LMIC Config via Build Flags ## ## LMIC Config and Debug Mode via Build Flags ##
#**************************************************************************************************************************
# Uncomment -D DEBUG to enable Serial Debugging. Parameters for the Serial Port are 115200 Baud 8n1
# By default the Firmware will output some messages about LoRa-Status and indicate sending
# The Macros DEBUG_PRINT() and DEBUG_PRINTLN() can be used to produce debug output depending on this define
# Please be aware that this will not work when a Serial Sensor like the SG112A/MH-Z19C or Sensair S8 ist used
#*************************************************************************************************************************/
build_flags = build_flags =
-D CFG_eu868 -D CFG_eu868
-D CFG_sx1276_radio -D CFG_sx1276_radio
-D DISABLE_PING -D DISABLE_PING
-D DISABLE_BEACONS -D DISABLE_BEACONS
-D ARDUINO_LMIC_PROJECT_CONFIG_H_SUPPRESS -D ARDUINO_LMIC_PROJECT_CONFIG_H_SUPPRESS
# -D DEBUG
## Programmer Config (MicroUPDI) ## ## Programmer Config (MicroUPDI) ##
upload_port = usb upload_port = usb

View file

@ -26,15 +26,6 @@
*************************************************************************************************************************/ *************************************************************************************************************************/
// #define BTN_PIN PIN_PC2 // #define BTN_PIN PIN_PC2
/**************************************************************************************************************************
* Enable Serial Debugging. Parameters for the Serial Port are 115200 Baud 8n1
* By default the Firmware will output some messages about LoRa-Status and indicate sending
* The Macros DEBUG_PRINT() and DEBUG_PRINTLN() can be used to produce debug output depending on this define
* Please be aware that this will not work when a Serial Sensor like the SG112A/MH-Z19C or Sensair S8 ist used
*************************************************************************************************************************/
// #define DEBUG
/************************************************************************************************************************** /**************************************************************************************************************************
* Number of active Sensors (used as long as HAS_NO_SENSOR is not enabled) * Number of active Sensors (used as long as HAS_NO_SENSOR is not enabled)
* Set to the correct number of enabled sensors below * Set to the correct number of enabled sensors below

View file

@ -13,8 +13,8 @@
// Include Config and Helpers // Include Config and Helpers
#include "config.h" #include "config.h"
#include "debug.h" #include <debug.h>
#include "attsensor.h" #include <attsensor.h>
// Include All Sensors Activated in config.h // Include All Sensors Activated in config.h
#ifndef HAS_NO_SENSOR #ifndef HAS_NO_SENSOR
@ -189,11 +189,14 @@ void onEvent(ev_t ev) {
} }
// Got to sleep for specified Time // Got to sleep for specified Time
DEBUG_PRINTLN("Going to Sleep"); DEBUG_PRINT("Going to Sleep for ");
DEBUG_PRINT(sleep_time*64);
DEBUG_PRINTLN(" Seconds");
for (uint16_t i = 0; i < sleep_time*2; i++) { for (uint16_t i = 0; i < sleep_time*2; i++) {
// Cancel sleep Cycle if Button was Pressed // Cancel sleep Cycle if Button was Pressed
#ifdef BTN_PIN #ifdef BTN_PIN
if (btn_pressed && digitalRead(BTN_PIN) == HIGH) { if (btn_pressed && digitalRead(BTN_PIN) == HIGH) {
DEBUG_PRINTLN("Button Pressed, waking up");
i = sleep_time*2; i = sleep_time*2;
btn_pressed = 0; btn_pressed = 0;
} else { } else {