mirror of
https://github.com/meshtastic/firmware.git
synced 2025-12-22 10:42:49 +00:00
I don't like this formatting but I need trunk to STFU
This commit is contained in:
@@ -1,11 +1,11 @@
|
|||||||
#include "../configuration.h"
|
#include "../configuration.h"
|
||||||
#include "../main.h"
|
#include "../main.h"
|
||||||
#include <Wire.h>
|
|
||||||
#include "mesh/generated/meshtastic/telemetry.pb.h"
|
#include "mesh/generated/meshtastic/telemetry.pb.h"
|
||||||
|
#include <Wire.h>
|
||||||
|
|
||||||
// AXP192 and AXP2101 have the same device address, we just need to identify it in Power.cpp
|
// AXP192 and AXP2101 have the same device address, we just need to identify it in Power.cpp
|
||||||
#ifndef XPOWERS_AXP192_AXP2101_ADDRESS
|
#ifndef XPOWERS_AXP192_AXP2101_ADDRESS
|
||||||
#define XPOWERS_AXP192_AXP2101_ADDRESS 0x34
|
#define XPOWERS_AXP192_AXP2101_ADDRESS 0x34
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
#if HAS_WIRE
|
#if HAS_WIRE
|
||||||
@@ -16,27 +16,27 @@ void printATECCInfo()
|
|||||||
atecc.readConfigZone(false);
|
atecc.readConfigZone(false);
|
||||||
|
|
||||||
LOG_DEBUG("ATECC608B Serial Number: ");
|
LOG_DEBUG("ATECC608B Serial Number: ");
|
||||||
for (int i = 0 ; i < 9 ; i++) {
|
for (int i = 0; i < 9; i++) {
|
||||||
LOG_DEBUG("%02x",atecc.serialNumber[i]);
|
LOG_DEBUG("%02x", atecc.serialNumber[i]);
|
||||||
}
|
}
|
||||||
|
|
||||||
LOG_DEBUG(", Rev Number: ");
|
LOG_DEBUG(", Rev Number: ");
|
||||||
for (int i = 0 ; i < 4 ; i++) {
|
for (int i = 0; i < 4; i++) {
|
||||||
LOG_DEBUG("%02x",atecc.revisionNumber[i]);
|
LOG_DEBUG("%02x", atecc.revisionNumber[i]);
|
||||||
}
|
}
|
||||||
LOG_DEBUG("\n");
|
LOG_DEBUG("\n");
|
||||||
|
|
||||||
LOG_DEBUG("ATECC608B Config %s",atecc.configLockStatus ? "Locked" : "Unlocked");
|
LOG_DEBUG("ATECC608B Config %s", atecc.configLockStatus ? "Locked" : "Unlocked");
|
||||||
LOG_DEBUG(", Data %s",atecc.dataOTPLockStatus ? "Locked" : "Unlocked");
|
LOG_DEBUG(", Data %s", atecc.dataOTPLockStatus ? "Locked" : "Unlocked");
|
||||||
LOG_DEBUG(", Slot 0 %s\n",atecc.slot0LockStatus ? "Locked" : "Unlocked");
|
LOG_DEBUG(", Slot 0 %s\n", atecc.slot0LockStatus ? "Locked" : "Unlocked");
|
||||||
|
|
||||||
if (atecc.configLockStatus && atecc.dataOTPLockStatus && atecc.slot0LockStatus) {
|
if (atecc.configLockStatus && atecc.dataOTPLockStatus && atecc.slot0LockStatus) {
|
||||||
if (atecc.generatePublicKey() == false) {
|
if (atecc.generatePublicKey() == false) {
|
||||||
LOG_DEBUG("ATECC608B Error generating public key\n");
|
LOG_DEBUG("ATECC608B Error generating public key\n");
|
||||||
} else {
|
} else {
|
||||||
LOG_DEBUG("ATECC608B Public Key: ");
|
LOG_DEBUG("ATECC608B Public Key: ");
|
||||||
for (int i = 0 ; i < 64 ; i++) {
|
for (int i = 0; i < 64; i++) {
|
||||||
LOG_DEBUG("%02x",atecc.publicKey64Bytes[i]);
|
LOG_DEBUG("%02x", atecc.publicKey64Bytes[i]);
|
||||||
}
|
}
|
||||||
LOG_DEBUG("\n");
|
LOG_DEBUG("\n");
|
||||||
}
|
}
|
||||||
@@ -44,7 +44,8 @@ void printATECCInfo()
|
|||||||
#endif
|
#endif
|
||||||
}
|
}
|
||||||
|
|
||||||
uint16_t getRegisterValue(uint8_t address, uint8_t reg, uint8_t length) {
|
uint16_t getRegisterValue(uint8_t address, uint8_t reg, uint8_t length)
|
||||||
|
{
|
||||||
uint16_t value = 0x00;
|
uint16_t value = 0x00;
|
||||||
Wire.beginTransmission(address);
|
Wire.beginTransmission(address);
|
||||||
Wire.write(reg);
|
Wire.write(reg);
|
||||||
@@ -81,7 +82,7 @@ uint8_t oled_probe(byte addr)
|
|||||||
|
|
||||||
if (r == 0x08 || r == 0x00) {
|
if (r == 0x08 || r == 0x00) {
|
||||||
o_probe = 2; // SH1106
|
o_probe = 2; // SH1106
|
||||||
} else if ( r == 0x03 || r == 0x04 || r == 0x06 || r == 0x07) {
|
} else if (r == 0x03 || r == 0x04 || r == 0x06 || r == 0x07) {
|
||||||
o_probe = 1; // SSD1306
|
o_probe = 1; // SSD1306
|
||||||
}
|
}
|
||||||
c++;
|
c++;
|
||||||
@@ -126,17 +127,17 @@ void scanI2Cdevice()
|
|||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
#ifdef RV3028_RTC
|
#ifdef RV3028_RTC
|
||||||
if (addr == RV3028_RTC){
|
if (addr == RV3028_RTC) {
|
||||||
rtc_found = addr;
|
rtc_found = addr;
|
||||||
LOG_INFO("RV3028 RTC found\n");
|
LOG_INFO("RV3028 RTC found\n");
|
||||||
Melopero_RV3028 rtc;
|
Melopero_RV3028 rtc;
|
||||||
rtc.initI2C();
|
rtc.initI2C();
|
||||||
rtc.writeToRegister(0x35,0x07); // no Clkout
|
rtc.writeToRegister(0x35, 0x07); // no Clkout
|
||||||
rtc.writeToRegister(0x37,0xB4);
|
rtc.writeToRegister(0x37, 0xB4);
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
#ifdef PCF8563_RTC
|
#ifdef PCF8563_RTC
|
||||||
if (addr == PCF8563_RTC){
|
if (addr == PCF8563_RTC) {
|
||||||
rtc_found = addr;
|
rtc_found = addr;
|
||||||
LOG_INFO("PCF8563 RTC found\n");
|
LOG_INFO("PCF8563 RTC found\n");
|
||||||
}
|
}
|
||||||
@@ -225,7 +226,7 @@ void scanI2Cdevice()
|
|||||||
if (nDevices == 0)
|
if (nDevices == 0)
|
||||||
LOG_INFO("No I2C devices found\n");
|
LOG_INFO("No I2C devices found\n");
|
||||||
else
|
else
|
||||||
LOG_INFO("%i I2C devices found\n",nDevices);
|
LOG_INFO("%i I2C devices found\n", nDevices);
|
||||||
}
|
}
|
||||||
#else
|
#else
|
||||||
void scanI2Cdevice() {}
|
void scanI2Cdevice() {}
|
||||||
|
|||||||
@@ -8,4 +8,5 @@
|
|||||||
#define RECORD_CRITICALERROR(code) recordCriticalError(code, __LINE__, __FILE__)
|
#define RECORD_CRITICALERROR(code) recordCriticalError(code, __LINE__, __FILE__)
|
||||||
|
|
||||||
/// Record an error that should be reported via analytics
|
/// Record an error that should be reported via analytics
|
||||||
void recordCriticalError(CriticalErrorCode code = CriticalErrorCode_UNSPECIFIED, uint32_t address = 0, const char *filename = NULL);
|
void recordCriticalError(CriticalErrorCode code = CriticalErrorCode_UNSPECIFIED, uint32_t address = 0,
|
||||||
|
const char *filename = NULL);
|
||||||
|
|||||||
@@ -34,8 +34,8 @@ along with this program. If not, see <http://www.gnu.org/licenses/>.
|
|||||||
#include "mesh-pb-constants.h"
|
#include "mesh-pb-constants.h"
|
||||||
#include "mesh/Channels.h"
|
#include "mesh/Channels.h"
|
||||||
#include "mesh/generated/meshtastic/deviceonly.pb.h"
|
#include "mesh/generated/meshtastic/deviceonly.pb.h"
|
||||||
#include "modules/TextMessageModule.h"
|
|
||||||
#include "modules/ExternalNotificationModule.h"
|
#include "modules/ExternalNotificationModule.h"
|
||||||
|
#include "modules/TextMessageModule.h"
|
||||||
#include "sleep.h"
|
#include "sleep.h"
|
||||||
#include "target_specific.h"
|
#include "target_specific.h"
|
||||||
#include "utils.h"
|
#include "utils.h"
|
||||||
@@ -97,9 +97,9 @@ static uint16_t displayWidth, displayHeight;
|
|||||||
|
|
||||||
#if defined(USE_EINK) || defined(ILI9341_DRIVER) || defined(ST7735_CS)
|
#if defined(USE_EINK) || defined(ILI9341_DRIVER) || defined(ST7735_CS)
|
||||||
// The screen is bigger so use bigger fonts
|
// The screen is bigger so use bigger fonts
|
||||||
#define FONT_SMALL ArialMT_Plain_16 // Height: 19
|
#define FONT_SMALL ArialMT_Plain_16 // Height: 19
|
||||||
#define FONT_MEDIUM ArialMT_Plain_24 // Height: 28
|
#define FONT_MEDIUM ArialMT_Plain_24 // Height: 28
|
||||||
#define FONT_LARGE ArialMT_Plain_24 // Height: 28
|
#define FONT_LARGE ArialMT_Plain_24 // Height: 28
|
||||||
#else
|
#else
|
||||||
#ifdef OLED_RU
|
#ifdef OLED_RU
|
||||||
#define FONT_SMALL ArialMT_Plain_10_RU
|
#define FONT_SMALL ArialMT_Plain_10_RU
|
||||||
@@ -107,7 +107,7 @@ static uint16_t displayWidth, displayHeight;
|
|||||||
#define FONT_SMALL ArialMT_Plain_10 // Height: 13
|
#define FONT_SMALL ArialMT_Plain_10 // Height: 13
|
||||||
#endif
|
#endif
|
||||||
#define FONT_MEDIUM ArialMT_Plain_16 // Height: 19
|
#define FONT_MEDIUM ArialMT_Plain_16 // Height: 19
|
||||||
#define FONT_LARGE ArialMT_Plain_24 // Height: 28
|
#define FONT_LARGE ArialMT_Plain_24 // Height: 28
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
#define fontHeight(font) ((font)[1] + 1) // height is position 1
|
#define fontHeight(font) ((font)[1] + 1) // height is position 1
|
||||||
@@ -118,7 +118,6 @@ static uint16_t displayWidth, displayHeight;
|
|||||||
|
|
||||||
#define getStringCenteredX(s) ((SCREEN_WIDTH - display->getStringWidth(s)) / 2)
|
#define getStringCenteredX(s) ((SCREEN_WIDTH - display->getStringWidth(s)) / 2)
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Draw the icon with extra info printed around the corners
|
* Draw the icon with extra info printed around the corners
|
||||||
*/
|
*/
|
||||||
@@ -292,7 +291,7 @@ static void drawFrameBluetooth(OLEDDisplay *display, OLEDDisplayUiState *state,
|
|||||||
display->drawString(x_offset + x, y_offset + y, "Bluetooth");
|
display->drawString(x_offset + x, y_offset + y, "Bluetooth");
|
||||||
|
|
||||||
display->setFont(FONT_SMALL);
|
display->setFont(FONT_SMALL);
|
||||||
y_offset = display->height() == 64 ? y_offset + FONT_HEIGHT_MEDIUM -4 : y_offset + FONT_HEIGHT_MEDIUM + 5;
|
y_offset = display->height() == 64 ? y_offset + FONT_HEIGHT_MEDIUM - 4 : y_offset + FONT_HEIGHT_MEDIUM + 5;
|
||||||
display->drawString(x_offset + x, y_offset + y, "Enter this code");
|
display->drawString(x_offset + x, y_offset + y, "Enter this code");
|
||||||
|
|
||||||
display->setFont(FONT_LARGE);
|
display->setFont(FONT_LARGE);
|
||||||
@@ -302,7 +301,7 @@ static void drawFrameBluetooth(OLEDDisplay *display, OLEDDisplayUiState *state,
|
|||||||
display->drawString(x_offset + x, y_offset + y, pin);
|
display->drawString(x_offset + x, y_offset + y, pin);
|
||||||
|
|
||||||
display->setFont(FONT_SMALL);
|
display->setFont(FONT_SMALL);
|
||||||
String deviceName = "Name: ";
|
String deviceName = "Name: ";
|
||||||
deviceName.concat(getDeviceName());
|
deviceName.concat(getDeviceName());
|
||||||
y_offset = display->height() == 64 ? y_offset + FONT_HEIGHT_LARGE - 6 : y_offset + FONT_HEIGHT_LARGE + 5;
|
y_offset = display->height() == 64 ? y_offset + FONT_HEIGHT_LARGE - 6 : y_offset + FONT_HEIGHT_LARGE + 5;
|
||||||
display->drawString(x_offset + x, y_offset + y, deviceName);
|
display->drawString(x_offset + x, y_offset + y, deviceName);
|
||||||
@@ -332,7 +331,8 @@ static void drawFrameFirmware(OLEDDisplay *display, OLEDDisplayUiState *state, i
|
|||||||
|
|
||||||
display->setFont(FONT_SMALL);
|
display->setFont(FONT_SMALL);
|
||||||
display->setTextAlignment(TEXT_ALIGN_LEFT);
|
display->setTextAlignment(TEXT_ALIGN_LEFT);
|
||||||
display->drawStringMaxWidth(0 + x, 2 + y + FONT_HEIGHT_SMALL *2, x + display->getWidth(), "Please be patient and do not power off.");
|
display->drawStringMaxWidth(0 + x, 2 + y + FONT_HEIGHT_SMALL * 2, x + display->getWidth(),
|
||||||
|
"Please be patient and do not power off.");
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Draw the last text message we received
|
/// Draw the last text message we received
|
||||||
@@ -354,8 +354,7 @@ static void drawCriticalFaultFrame(OLEDDisplay *display, OLEDDisplayUiState *sta
|
|||||||
// Ignore messages orginating from phone (from the current node 0x0) unless range test or store and forward module are enabled
|
// Ignore messages orginating from phone (from the current node 0x0) unless range test or store and forward module are enabled
|
||||||
static bool shouldDrawMessage(const MeshPacket *packet)
|
static bool shouldDrawMessage(const MeshPacket *packet)
|
||||||
{
|
{
|
||||||
return packet->from != 0 && !moduleConfig.range_test.enabled &&
|
return packet->from != 0 && !moduleConfig.range_test.enabled && !moduleConfig.store_forward.enabled;
|
||||||
!moduleConfig.store_forward.enabled;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Draw the last text message we received
|
/// Draw the last text message we received
|
||||||
@@ -381,7 +380,7 @@ static void drawTextMessageFrame(OLEDDisplay *display, OLEDDisplayUiState *state
|
|||||||
display->setColor(BLACK);
|
display->setColor(BLACK);
|
||||||
}
|
}
|
||||||
display->drawStringf(0 + x, 0 + y, tempBuf, "From: %s", (node && node->has_user) ? node->user.short_name : "???");
|
display->drawStringf(0 + x, 0 + y, tempBuf, "From: %s", (node && node->has_user) ? node->user.short_name : "???");
|
||||||
if(config.display.heading_bold) {
|
if (config.display.heading_bold) {
|
||||||
display->drawStringf(1 + x, 0 + y, tempBuf, "From: %s", (node && node->has_user) ? node->user.short_name : "???");
|
display->drawStringf(1 + x, 0 + y, tempBuf, "From: %s", (node && node->has_user) ? node->user.short_name : "???");
|
||||||
}
|
}
|
||||||
display->setColor(WHITE);
|
display->setColor(WHITE);
|
||||||
@@ -477,7 +476,7 @@ static void drawNodes(OLEDDisplay *display, int16_t x, int16_t y, NodeStatus *no
|
|||||||
display->drawFastImage(x, y, 8, 8, imgUser);
|
display->drawFastImage(x, y, 8, 8, imgUser);
|
||||||
#endif
|
#endif
|
||||||
display->drawString(x + 10, y - 2, usersString);
|
display->drawString(x + 10, y - 2, usersString);
|
||||||
if(config.display.heading_bold)
|
if (config.display.heading_bold)
|
||||||
display->drawString(x + 11, y - 2, usersString);
|
display->drawString(x + 11, y - 2, usersString);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -487,20 +486,20 @@ static void drawGPS(OLEDDisplay *display, int16_t x, int16_t y, const GPSStatus
|
|||||||
if (config.position.fixed_position) {
|
if (config.position.fixed_position) {
|
||||||
// GPS coordinates are currently fixed
|
// GPS coordinates are currently fixed
|
||||||
display->drawString(x - 1, y - 2, "Fixed GPS");
|
display->drawString(x - 1, y - 2, "Fixed GPS");
|
||||||
if(config.display.heading_bold)
|
if (config.display.heading_bold)
|
||||||
display->drawString(x, y - 2, "Fixed GPS");
|
display->drawString(x, y - 2, "Fixed GPS");
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
if (!gps->getIsConnected()) {
|
if (!gps->getIsConnected()) {
|
||||||
display->drawString(x, y - 2, "No GPS");
|
display->drawString(x, y - 2, "No GPS");
|
||||||
if(config.display.heading_bold)
|
if (config.display.heading_bold)
|
||||||
display->drawString(x + 1, y - 2, "No GPS");
|
display->drawString(x + 1, y - 2, "No GPS");
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
display->drawFastImage(x, y, 6, 8, gps->getHasLock() ? imgPositionSolid : imgPositionEmpty);
|
display->drawFastImage(x, y, 6, 8, gps->getHasLock() ? imgPositionSolid : imgPositionEmpty);
|
||||||
if (!gps->getHasLock()) {
|
if (!gps->getHasLock()) {
|
||||||
display->drawString(x + 8, y - 2, "No sats");
|
display->drawString(x + 8, y - 2, "No sats");
|
||||||
if(config.display.heading_bold)
|
if (config.display.heading_bold)
|
||||||
display->drawString(x + 9, y - 2, "No sats");
|
display->drawString(x + 9, y - 2, "No sats");
|
||||||
return;
|
return;
|
||||||
} else {
|
} else {
|
||||||
@@ -523,24 +522,24 @@ static void drawGPS(OLEDDisplay *display, int16_t x, int16_t y, const GPSStatus
|
|||||||
// Draw the number of satellites
|
// Draw the number of satellites
|
||||||
snprintf(satsString, sizeof(satsString), "%u", gps->getNumSatellites());
|
snprintf(satsString, sizeof(satsString), "%u", gps->getNumSatellites());
|
||||||
display->drawString(x + 34, y - 2, satsString);
|
display->drawString(x + 34, y - 2, satsString);
|
||||||
if(config.display.heading_bold)
|
if (config.display.heading_bold)
|
||||||
display->drawString(x + 35, y - 2, satsString);
|
display->drawString(x + 35, y - 2, satsString);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
//Draw status when gps is disabled by PMU
|
// Draw status when gps is disabled by PMU
|
||||||
static void drawGPSpowerstat(OLEDDisplay *display, int16_t x, int16_t y, const GPSStatus *gps)
|
static void drawGPSpowerstat(OLEDDisplay *display, int16_t x, int16_t y, const GPSStatus *gps)
|
||||||
{
|
{
|
||||||
#ifdef HAS_PMU
|
#ifdef HAS_PMU
|
||||||
String displayLine = "GPS disabled";
|
String displayLine = "GPS disabled";
|
||||||
int16_t xPos = display->getStringWidth(displayLine);
|
int16_t xPos = display->getStringWidth(displayLine);
|
||||||
|
|
||||||
if (!config.position.gps_enabled){
|
if (!config.position.gps_enabled) {
|
||||||
display->drawString(x + xPos, y, displayLine);
|
display->drawString(x + xPos, y, displayLine);
|
||||||
#ifdef GPS_POWER_TOGGLE
|
#ifdef GPS_POWER_TOGGLE
|
||||||
display->drawString(x + xPos, y - 2 + FONT_HEIGHT_SMALL, " by button");
|
display->drawString(x + xPos, y - 2 + FONT_HEIGHT_SMALL, " by button");
|
||||||
#endif
|
#endif
|
||||||
//display->drawString(x + xPos, y + 2, displayLine);
|
// display->drawString(x + xPos, y + 2, displayLine);
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
}
|
}
|
||||||
@@ -582,22 +581,23 @@ static void drawGPScoordinates(OLEDDisplay *display, int16_t x, int16_t y, const
|
|||||||
if (gpsFormat != Config_DisplayConfig_GpsCoordinateFormat_DMS) {
|
if (gpsFormat != Config_DisplayConfig_GpsCoordinateFormat_DMS) {
|
||||||
char coordinateLine[22];
|
char coordinateLine[22];
|
||||||
if (gpsFormat == Config_DisplayConfig_GpsCoordinateFormat_DEC) { // Decimal Degrees
|
if (gpsFormat == Config_DisplayConfig_GpsCoordinateFormat_DEC) { // Decimal Degrees
|
||||||
snprintf(coordinateLine, sizeof(coordinateLine), "%f %f", geoCoord.getLatitude() * 1e-7, geoCoord.getLongitude() * 1e-7);
|
snprintf(coordinateLine, sizeof(coordinateLine), "%f %f", geoCoord.getLatitude() * 1e-7,
|
||||||
|
geoCoord.getLongitude() * 1e-7);
|
||||||
} else if (gpsFormat == Config_DisplayConfig_GpsCoordinateFormat_UTM) { // Universal Transverse Mercator
|
} else if (gpsFormat == Config_DisplayConfig_GpsCoordinateFormat_UTM) { // Universal Transverse Mercator
|
||||||
snprintf(coordinateLine, sizeof(coordinateLine), "%2i%1c %06u %07u", geoCoord.getUTMZone(), geoCoord.getUTMBand(),
|
snprintf(coordinateLine, sizeof(coordinateLine), "%2i%1c %06u %07u", geoCoord.getUTMZone(), geoCoord.getUTMBand(),
|
||||||
geoCoord.getUTMEasting(), geoCoord.getUTMNorthing());
|
geoCoord.getUTMEasting(), geoCoord.getUTMNorthing());
|
||||||
} else if (gpsFormat == Config_DisplayConfig_GpsCoordinateFormat_MGRS) { // Military Grid Reference System
|
} else if (gpsFormat == Config_DisplayConfig_GpsCoordinateFormat_MGRS) { // Military Grid Reference System
|
||||||
snprintf(coordinateLine, sizeof(coordinateLine), "%2i%1c %1c%1c %05u %05u", geoCoord.getMGRSZone(), geoCoord.getMGRSBand(),
|
snprintf(coordinateLine, sizeof(coordinateLine), "%2i%1c %1c%1c %05u %05u", geoCoord.getMGRSZone(),
|
||||||
geoCoord.getMGRSEast100k(), geoCoord.getMGRSNorth100k(), geoCoord.getMGRSEasting(),
|
geoCoord.getMGRSBand(), geoCoord.getMGRSEast100k(), geoCoord.getMGRSNorth100k(),
|
||||||
geoCoord.getMGRSNorthing());
|
geoCoord.getMGRSEasting(), geoCoord.getMGRSNorthing());
|
||||||
} else if (gpsFormat == Config_DisplayConfig_GpsCoordinateFormat_OLC) { // Open Location Code
|
} else if (gpsFormat == Config_DisplayConfig_GpsCoordinateFormat_OLC) { // Open Location Code
|
||||||
geoCoord.getOLCCode(coordinateLine);
|
geoCoord.getOLCCode(coordinateLine);
|
||||||
} else if (gpsFormat == Config_DisplayConfig_GpsCoordinateFormat_OSGR) { // Ordnance Survey Grid Reference
|
} else if (gpsFormat == Config_DisplayConfig_GpsCoordinateFormat_OSGR) { // Ordnance Survey Grid Reference
|
||||||
if (geoCoord.getOSGRE100k() == 'I' || geoCoord.getOSGRN100k() == 'I') // OSGR is only valid around the UK region
|
if (geoCoord.getOSGRE100k() == 'I' || geoCoord.getOSGRN100k() == 'I') // OSGR is only valid around the UK region
|
||||||
snprintf(coordinateLine, sizeof(coordinateLine), "%s", "Out of Boundary");
|
snprintf(coordinateLine, sizeof(coordinateLine), "%s", "Out of Boundary");
|
||||||
else
|
else
|
||||||
snprintf(coordinateLine, sizeof(coordinateLine), "%1c%1c %05u %05u", geoCoord.getOSGRE100k(), geoCoord.getOSGRN100k(),
|
snprintf(coordinateLine, sizeof(coordinateLine), "%1c%1c %05u %05u", geoCoord.getOSGRE100k(),
|
||||||
geoCoord.getOSGREasting(), geoCoord.getOSGRNorthing());
|
geoCoord.getOSGRN100k(), geoCoord.getOSGREasting(), geoCoord.getOSGRNorthing());
|
||||||
}
|
}
|
||||||
|
|
||||||
// If fixed position, display text "Fixed GPS" alternating with the coordinates.
|
// If fixed position, display text "Fixed GPS" alternating with the coordinates.
|
||||||
@@ -614,10 +614,10 @@ static void drawGPScoordinates(OLEDDisplay *display, int16_t x, int16_t y, const
|
|||||||
} else {
|
} else {
|
||||||
char latLine[22];
|
char latLine[22];
|
||||||
char lonLine[22];
|
char lonLine[22];
|
||||||
snprintf(latLine, sizeof(latLine), "%2i° %2i' %2u\" %1c", geoCoord.getDMSLatDeg(), geoCoord.getDMSLatMin(), geoCoord.getDMSLatSec(),
|
snprintf(latLine, sizeof(latLine), "%2i° %2i' %2u\" %1c", geoCoord.getDMSLatDeg(), geoCoord.getDMSLatMin(),
|
||||||
geoCoord.getDMSLatCP());
|
geoCoord.getDMSLatSec(), geoCoord.getDMSLatCP());
|
||||||
snprintf(lonLine, sizeof(lonLine), "%3i° %2i' %2u\" %1c", geoCoord.getDMSLonDeg(), geoCoord.getDMSLonMin(), geoCoord.getDMSLonSec(),
|
snprintf(lonLine, sizeof(lonLine), "%3i° %2i' %2u\" %1c", geoCoord.getDMSLonDeg(), geoCoord.getDMSLonMin(),
|
||||||
geoCoord.getDMSLonCP());
|
geoCoord.getDMSLonSec(), geoCoord.getDMSLonCP());
|
||||||
display->drawString(x + (SCREEN_WIDTH - (display->getStringWidth(latLine))) / 2, y - FONT_HEIGHT_SMALL * 1, latLine);
|
display->drawString(x + (SCREEN_WIDTH - (display->getStringWidth(latLine))) / 2, y - FONT_HEIGHT_SMALL * 1, latLine);
|
||||||
display->drawString(x + (SCREEN_WIDTH - (display->getStringWidth(lonLine))) / 2, y, lonLine);
|
display->drawString(x + (SCREEN_WIDTH - (display->getStringWidth(lonLine))) / 2, y, lonLine);
|
||||||
}
|
}
|
||||||
@@ -653,8 +653,8 @@ class Point
|
|||||||
|
|
||||||
void scale(float f)
|
void scale(float f)
|
||||||
{
|
{
|
||||||
//We use -f here to counter the flip that happens
|
// We use -f here to counter the flip that happens
|
||||||
//on the y axis when drawing and rotating on screen
|
// on the y axis when drawing and rotating on screen
|
||||||
x *= f;
|
x *= f;
|
||||||
y *= -f;
|
y *= -f;
|
||||||
}
|
}
|
||||||
@@ -713,7 +713,7 @@ static uint16_t getCompassDiam(OLEDDisplay *display)
|
|||||||
offset = FONT_HEIGHT_SMALL;
|
offset = FONT_HEIGHT_SMALL;
|
||||||
|
|
||||||
// get the smaller of the 2 dimensions and subtract 20
|
// get the smaller of the 2 dimensions and subtract 20
|
||||||
if(display->getWidth() > (display->getHeight() - offset)) {
|
if (display->getWidth() > (display->getHeight() - offset)) {
|
||||||
diam = display->getHeight() - offset;
|
diam = display->getHeight() - offset;
|
||||||
// if 2/3 of the other size would be smaller, use that
|
// if 2/3 of the other size would be smaller, use that
|
||||||
if (diam > (display->getWidth() * 2 / 3)) {
|
if (diam > (display->getWidth() * 2 / 3)) {
|
||||||
@@ -756,8 +756,8 @@ static void drawNodeHeading(OLEDDisplay *display, int16_t compassX, int16_t comp
|
|||||||
// Draw north
|
// Draw north
|
||||||
static void drawCompassNorth(OLEDDisplay *display, int16_t compassX, int16_t compassY, float myHeading)
|
static void drawCompassNorth(OLEDDisplay *display, int16_t compassX, int16_t compassY, float myHeading)
|
||||||
{
|
{
|
||||||
//If north is supposed to be at the top of the compass we want rotation to be +0
|
// If north is supposed to be at the top of the compass we want rotation to be +0
|
||||||
if(config.display.compass_north_top)
|
if (config.display.compass_north_top)
|
||||||
myHeading = -0;
|
myHeading = -0;
|
||||||
|
|
||||||
Point N1(-0.04f, 0.65f), N2(0.04f, 0.65f);
|
Point N1(-0.04f, 0.65f), N2(0.04f, 0.65f);
|
||||||
@@ -874,7 +874,7 @@ static void drawNodeInfo(OLEDDisplay *display, OLEDDisplayUiState *state, int16_
|
|||||||
GeoCoord::bearing(DegD(op.latitude_i), DegD(op.longitude_i), DegD(p.latitude_i), DegD(p.longitude_i));
|
GeoCoord::bearing(DegD(op.latitude_i), DegD(op.longitude_i), DegD(p.latitude_i), DegD(p.longitude_i));
|
||||||
// If the top of the compass is a static north then bearingToOther can be drawn on the compass directly
|
// If the top of the compass is a static north then bearingToOther can be drawn on the compass directly
|
||||||
// If the top of the compass is not a static north we need adjust bearingToOther based on heading
|
// If the top of the compass is not a static north we need adjust bearingToOther based on heading
|
||||||
if(!config.display.compass_north_top)
|
if (!config.display.compass_north_top)
|
||||||
bearingToOther -= myHeading;
|
bearingToOther -= myHeading;
|
||||||
drawNodeHeading(display, compassX, compassY, bearingToOther);
|
drawNodeHeading(display, compassX, compassY, bearingToOther);
|
||||||
}
|
}
|
||||||
@@ -1000,8 +1000,8 @@ void Screen::setup()
|
|||||||
#ifdef SCREEN_MIRROR
|
#ifdef SCREEN_MIRROR
|
||||||
dispdev.mirrorScreen();
|
dispdev.mirrorScreen();
|
||||||
#else
|
#else
|
||||||
// Standard behaviour is to FLIP the screen (needed on T-Beam). If this config item is set, unflip it, and thereby logically flip it.
|
// Standard behaviour is to FLIP the screen (needed on T-Beam). If this config item is set, unflip it, and thereby logically
|
||||||
// If you have a headache now, you're welcome.
|
// flip it. If you have a headache now, you're welcome.
|
||||||
if (!config.display.flip_screen) {
|
if (!config.display.flip_screen) {
|
||||||
dispdev.flipScreenVertically();
|
dispdev.flipScreenVertically();
|
||||||
}
|
}
|
||||||
@@ -1414,7 +1414,7 @@ void DebugInfo::drawFrame(OLEDDisplay *display, OLEDDisplayUiState *state, int16
|
|||||||
// Display power status
|
// Display power status
|
||||||
if (powerStatus->getHasBattery()) {
|
if (powerStatus->getHasBattery()) {
|
||||||
if (config.display.displaymode == Config_DisplayConfig_DisplayMode_DEFAULT) {
|
if (config.display.displaymode == Config_DisplayConfig_DisplayMode_DEFAULT) {
|
||||||
drawBattery(display, x , y + 2, imgBattery, powerStatus);
|
drawBattery(display, x, y + 2, imgBattery, powerStatus);
|
||||||
} else {
|
} else {
|
||||||
drawBattery(display, x + 1, y + 3, imgBattery, powerStatus);
|
drawBattery(display, x + 1, y + 3, imgBattery, powerStatus);
|
||||||
}
|
}
|
||||||
@@ -1432,7 +1432,7 @@ void DebugInfo::drawFrame(OLEDDisplay *display, OLEDDisplayUiState *state, int16
|
|||||||
drawNodes(display, x + (SCREEN_WIDTH * 0.25), y + 3, nodeStatus);
|
drawNodes(display, x + (SCREEN_WIDTH * 0.25), y + 3, nodeStatus);
|
||||||
}
|
}
|
||||||
// Display GPS status
|
// Display GPS status
|
||||||
if (!config.position.gps_enabled){
|
if (!config.position.gps_enabled) {
|
||||||
int16_t yPos = y + 2;
|
int16_t yPos = y + 2;
|
||||||
#ifdef GPS_POWER_TOGGLE
|
#ifdef GPS_POWER_TOGGLE
|
||||||
yPos = (y + 10 + FONT_HEIGHT_SMALL);
|
yPos = (y + 10 + FONT_HEIGHT_SMALL);
|
||||||
@@ -1452,26 +1452,35 @@ void DebugInfo::drawFrame(OLEDDisplay *display, OLEDDisplayUiState *state, int16
|
|||||||
// Draw our hardware ID to assist with bluetooth pairing. Either prefix with Info or S&F Logo
|
// Draw our hardware ID to assist with bluetooth pairing. Either prefix with Info or S&F Logo
|
||||||
if (moduleConfig.store_forward.enabled) {
|
if (moduleConfig.store_forward.enabled) {
|
||||||
#ifdef ARCH_ESP32
|
#ifdef ARCH_ESP32
|
||||||
if (millis() - storeForwardModule->lastHeartbeat > (storeForwardModule->heartbeatInterval * 1200)) { //no heartbeat, overlap a bit
|
if (millis() - storeForwardModule->lastHeartbeat >
|
||||||
|
(storeForwardModule->heartbeatInterval * 1200)) { // no heartbeat, overlap a bit
|
||||||
#if defined(USE_EINK) || defined(ILI9341_DRIVER) || defined(ST7735_CS)
|
#if defined(USE_EINK) || defined(ILI9341_DRIVER) || defined(ST7735_CS)
|
||||||
display->drawFastImage(x + SCREEN_WIDTH - 14 - display->getStringWidth(ourId), y + 3 + FONT_HEIGHT_SMALL, 12, 8, imgQuestionL1);
|
display->drawFastImage(x + SCREEN_WIDTH - 14 - display->getStringWidth(ourId), y + 3 + FONT_HEIGHT_SMALL, 12, 8,
|
||||||
display->drawFastImage(x + SCREEN_WIDTH - 14 - display->getStringWidth(ourId), y + 11 + FONT_HEIGHT_SMALL, 12, 8, imgQuestionL2);
|
imgQuestionL1);
|
||||||
|
display->drawFastImage(x + SCREEN_WIDTH - 14 - display->getStringWidth(ourId), y + 11 + FONT_HEIGHT_SMALL, 12, 8,
|
||||||
|
imgQuestionL2);
|
||||||
#else
|
#else
|
||||||
display->drawFastImage(x + SCREEN_WIDTH - 10 - display->getStringWidth(ourId), y + 2 + FONT_HEIGHT_SMALL, 8, 8, imgQuestion);
|
display->drawFastImage(x + SCREEN_WIDTH - 10 - display->getStringWidth(ourId), y + 2 + FONT_HEIGHT_SMALL, 8, 8,
|
||||||
|
imgQuestion);
|
||||||
#endif
|
#endif
|
||||||
} else {
|
} else {
|
||||||
#if defined(USE_EINK) || defined(ILI9341_DRIVER) || defined(ST7735_CS)
|
#if defined(USE_EINK) || defined(ILI9341_DRIVER) || defined(ST7735_CS)
|
||||||
display->drawFastImage(x + SCREEN_WIDTH - 18 - display->getStringWidth(ourId), y + 3 + FONT_HEIGHT_SMALL, 16, 8, imgSFL1);
|
display->drawFastImage(x + SCREEN_WIDTH - 18 - display->getStringWidth(ourId), y + 3 + FONT_HEIGHT_SMALL, 16, 8,
|
||||||
display->drawFastImage(x + SCREEN_WIDTH - 18 - display->getStringWidth(ourId), y + 11 + FONT_HEIGHT_SMALL, 16, 8, imgSFL2);
|
imgSFL1);
|
||||||
|
display->drawFastImage(x + SCREEN_WIDTH - 18 - display->getStringWidth(ourId), y + 11 + FONT_HEIGHT_SMALL, 16, 8,
|
||||||
|
imgSFL2);
|
||||||
#else
|
#else
|
||||||
display->drawFastImage(x + SCREEN_WIDTH - 13 - display->getStringWidth(ourId), y + 2 + FONT_HEIGHT_SMALL, 11, 8, imgSF);
|
display->drawFastImage(x + SCREEN_WIDTH - 13 - display->getStringWidth(ourId), y + 2 + FONT_HEIGHT_SMALL, 11, 8,
|
||||||
|
imgSF);
|
||||||
#endif
|
#endif
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
} else {
|
} else {
|
||||||
#if defined(USE_EINK) || defined(ILI9341_DRIVER) || defined(ST7735_CS)
|
#if defined(USE_EINK) || defined(ILI9341_DRIVER) || defined(ST7735_CS)
|
||||||
display->drawFastImage(x + SCREEN_WIDTH - 14 - display->getStringWidth(ourId), y + 3 + FONT_HEIGHT_SMALL, 12, 8, imgInfoL1);
|
display->drawFastImage(x + SCREEN_WIDTH - 14 - display->getStringWidth(ourId), y + 3 + FONT_HEIGHT_SMALL, 12, 8,
|
||||||
display->drawFastImage(x + SCREEN_WIDTH - 14 - display->getStringWidth(ourId), y + 11 + FONT_HEIGHT_SMALL, 12, 8, imgInfoL2);
|
imgInfoL1);
|
||||||
|
display->drawFastImage(x + SCREEN_WIDTH - 14 - display->getStringWidth(ourId), y + 11 + FONT_HEIGHT_SMALL, 12, 8,
|
||||||
|
imgInfoL2);
|
||||||
#else
|
#else
|
||||||
display->drawFastImage(x + SCREEN_WIDTH - 10 - display->getStringWidth(ourId), y + 2 + FONT_HEIGHT_SMALL, 8, 8, imgInfo);
|
display->drawFastImage(x + SCREEN_WIDTH - 10 - display->getStringWidth(ourId), y + 2 + FONT_HEIGHT_SMALL, 8, 8, imgInfo);
|
||||||
#endif
|
#endif
|
||||||
@@ -1510,16 +1519,16 @@ void DebugInfo::drawFrameWiFi(OLEDDisplay *display, OLEDDisplayUiState *state, i
|
|||||||
|
|
||||||
if (WiFi.status() != WL_CONNECTED) {
|
if (WiFi.status() != WL_CONNECTED) {
|
||||||
display->drawString(x, y, String("WiFi: Not Connected"));
|
display->drawString(x, y, String("WiFi: Not Connected"));
|
||||||
if(config.display.heading_bold)
|
if (config.display.heading_bold)
|
||||||
display->drawString(x + 1, y, String("WiFi: Not Connected"));
|
display->drawString(x + 1, y, String("WiFi: Not Connected"));
|
||||||
} else {
|
} else {
|
||||||
display->drawString(x, y, String("WiFi: Connected"));
|
display->drawString(x, y, String("WiFi: Connected"));
|
||||||
if(config.display.heading_bold)
|
if (config.display.heading_bold)
|
||||||
display->drawString(x + 1, y, String("WiFi: Connected"));
|
display->drawString(x + 1, y, String("WiFi: Connected"));
|
||||||
|
|
||||||
display->drawString(x + SCREEN_WIDTH - display->getStringWidth("RSSI " + String(WiFi.RSSI())), y,
|
display->drawString(x + SCREEN_WIDTH - display->getStringWidth("RSSI " + String(WiFi.RSSI())), y,
|
||||||
"RSSI " + String(WiFi.RSSI()));
|
"RSSI " + String(WiFi.RSSI()));
|
||||||
if(config.display.heading_bold) {
|
if (config.display.heading_bold) {
|
||||||
display->drawString(x + SCREEN_WIDTH - display->getStringWidth("RSSI " + String(WiFi.RSSI())) - 1, y,
|
display->drawString(x + SCREEN_WIDTH - display->getStringWidth("RSSI " + String(WiFi.RSSI())) - 1, y,
|
||||||
"RSSI " + String(WiFi.RSSI()));
|
"RSSI " + String(WiFi.RSSI()));
|
||||||
}
|
}
|
||||||
@@ -1650,12 +1659,12 @@ void DebugInfo::drawFrameSettings(OLEDDisplay *display, OLEDDisplayUiState *stat
|
|||||||
|
|
||||||
// Line 1
|
// Line 1
|
||||||
display->drawString(x, y, batStr);
|
display->drawString(x, y, batStr);
|
||||||
if(config.display.heading_bold)
|
if (config.display.heading_bold)
|
||||||
display->drawString(x + 1, y, batStr);
|
display->drawString(x + 1, y, batStr);
|
||||||
} else {
|
} else {
|
||||||
// Line 1
|
// Line 1
|
||||||
display->drawString(x, y, String("USB"));
|
display->drawString(x, y, String("USB"));
|
||||||
if(config.display.heading_bold)
|
if (config.display.heading_bold)
|
||||||
display->drawString(x + 1, y, String("USB"));
|
display->drawString(x + 1, y, String("USB"));
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -1689,7 +1698,7 @@ void DebugInfo::drawFrameSettings(OLEDDisplay *display, OLEDDisplayUiState *stat
|
|||||||
}
|
}
|
||||||
|
|
||||||
display->drawString(x + SCREEN_WIDTH - display->getStringWidth(mode), y, mode);
|
display->drawString(x + SCREEN_WIDTH - display->getStringWidth(mode), y, mode);
|
||||||
if(config.display.heading_bold)
|
if (config.display.heading_bold)
|
||||||
display->drawString(x + SCREEN_WIDTH - display->getStringWidth(mode) - 1, y, mode);
|
display->drawString(x + SCREEN_WIDTH - display->getStringWidth(mode) - 1, y, mode);
|
||||||
|
|
||||||
// Line 2
|
// Line 2
|
||||||
@@ -1740,17 +1749,16 @@ void DebugInfo::drawFrameSettings(OLEDDisplay *display, OLEDDisplayUiState *stat
|
|||||||
char chUtil[13];
|
char chUtil[13];
|
||||||
snprintf(chUtil, sizeof(chUtil), "ChUtil %2.0f%%", airTime->channelUtilizationPercent());
|
snprintf(chUtil, sizeof(chUtil), "ChUtil %2.0f%%", airTime->channelUtilizationPercent());
|
||||||
display->drawString(x + SCREEN_WIDTH - display->getStringWidth(chUtil), y + FONT_HEIGHT_SMALL * 1, chUtil);
|
display->drawString(x + SCREEN_WIDTH - display->getStringWidth(chUtil), y + FONT_HEIGHT_SMALL * 1, chUtil);
|
||||||
if (config.position.gps_enabled) {
|
if (config.position.gps_enabled) {
|
||||||
// Line 3
|
// Line 3
|
||||||
if (config.display.gps_format !=
|
if (config.display.gps_format != Config_DisplayConfig_GpsCoordinateFormat_DMS) // if DMS then don't draw altitude
|
||||||
Config_DisplayConfig_GpsCoordinateFormat_DMS) // if DMS then don't draw altitude
|
drawGPSAltitude(display, x, y + FONT_HEIGHT_SMALL * 2, gpsStatus);
|
||||||
drawGPSAltitude(display, x, y + FONT_HEIGHT_SMALL * 2, gpsStatus);
|
|
||||||
|
|
||||||
// Line 4
|
// Line 4
|
||||||
drawGPScoordinates(display, x, y + FONT_HEIGHT_SMALL * 3, gpsStatus);
|
drawGPScoordinates(display, x, y + FONT_HEIGHT_SMALL * 3, gpsStatus);
|
||||||
} else {
|
} else {
|
||||||
drawGPSpowerstat(display, x - (SCREEN_WIDTH / 4), y + FONT_HEIGHT_SMALL * 2, gpsStatus);
|
drawGPSpowerstat(display, x - (SCREEN_WIDTH / 4), y + FONT_HEIGHT_SMALL * 2, gpsStatus);
|
||||||
}
|
}
|
||||||
/* Display a heartbeat pixel that blinks every time the frame is redrawn */
|
/* Display a heartbeat pixel that blinks every time the frame is redrawn */
|
||||||
#ifdef SHOW_REDRAWS
|
#ifdef SHOW_REDRAWS
|
||||||
if (heartbeat)
|
if (heartbeat)
|
||||||
|
|||||||
@@ -1,11 +1,11 @@
|
|||||||
#pragma once
|
#pragma once
|
||||||
|
|
||||||
#include <map>
|
|
||||||
#include "GPSStatus.h"
|
#include "GPSStatus.h"
|
||||||
#include "NodeStatus.h"
|
#include "NodeStatus.h"
|
||||||
#include "PowerStatus.h"
|
#include "PowerStatus.h"
|
||||||
#include "graphics/Screen.h"
|
#include "graphics/Screen.h"
|
||||||
#include "mesh/generated/meshtastic/telemetry.pb.h"
|
#include "mesh/generated/meshtastic/telemetry.pb.h"
|
||||||
|
#include <map>
|
||||||
#if !defined(ARCH_PORTDUINO) && !defined(ARCH_STM32WL)
|
#if !defined(ARCH_PORTDUINO) && !defined(ARCH_STM32WL)
|
||||||
#include <SparkFun_ATECCX08a_Arduino_Library.h>
|
#include <SparkFun_ATECCX08a_Arduino_Library.h>
|
||||||
#endif
|
#endif
|
||||||
|
|||||||
@@ -157,7 +157,7 @@ size_t PhoneAPI::getFromRadio(uint8_t *buf)
|
|||||||
|
|
||||||
if (info) {
|
if (info) {
|
||||||
LOG_INFO("Sending nodeinfo: num=0x%x, lastseen=%u, id=%s, name=%s\n", info->num, info->last_heard, info->user.id,
|
LOG_INFO("Sending nodeinfo: num=0x%x, lastseen=%u, id=%s, name=%s\n", info->num, info->last_heard, info->user.id,
|
||||||
info->user.long_name);
|
info->user.long_name);
|
||||||
fromRadioScratch.which_payload_variant = FromRadio_node_info_tag;
|
fromRadioScratch.which_payload_variant = FromRadio_node_info_tag;
|
||||||
fromRadioScratch.node_info = *info;
|
fromRadioScratch.node_info = *info;
|
||||||
// Stay in current state until done sending nodeinfos
|
// Stay in current state until done sending nodeinfos
|
||||||
|
|||||||
@@ -16,14 +16,15 @@
|
|||||||
* Eventually there should be once instance of this class for each live connection (because it has a bit of state
|
* Eventually there should be once instance of this class for each live connection (because it has a bit of state
|
||||||
* for that connection)
|
* for that connection)
|
||||||
*/
|
*/
|
||||||
class PhoneAPI : public Observer<uint32_t> // FIXME, we shouldn't be inheriting from Observer, instead use CallbackObserver as a member
|
class PhoneAPI
|
||||||
|
: public Observer<uint32_t> // FIXME, we shouldn't be inheriting from Observer, instead use CallbackObserver as a member
|
||||||
{
|
{
|
||||||
enum State {
|
enum State {
|
||||||
STATE_SEND_NOTHING, // Initial state, don't send anything until the client starts asking for config
|
STATE_SEND_NOTHING, // Initial state, don't send anything until the client starts asking for config
|
||||||
STATE_SEND_MY_INFO, // send our my info record
|
STATE_SEND_MY_INFO, // send our my info record
|
||||||
STATE_SEND_NODEINFO, // states progress in this order as the device sends to to the client
|
STATE_SEND_NODEINFO, // states progress in this order as the device sends to to the client
|
||||||
STATE_SEND_CHANNELS, // Send all channels
|
STATE_SEND_CHANNELS, // Send all channels
|
||||||
STATE_SEND_CONFIG, // Replacement for the old Radioconfig
|
STATE_SEND_CONFIG, // Replacement for the old Radioconfig
|
||||||
STATE_SEND_MODULECONFIG, // Send Module specific config
|
STATE_SEND_MODULECONFIG, // Send Module specific config
|
||||||
STATE_SEND_COMPLETE_ID,
|
STATE_SEND_COMPLETE_ID,
|
||||||
STATE_SEND_PACKETS // send packets or debug strings
|
STATE_SEND_PACKETS // send packets or debug strings
|
||||||
|
|||||||
@@ -1,9 +1,9 @@
|
|||||||
#pragma once
|
#pragma once
|
||||||
|
|
||||||
#include "mesh/generated/meshtastic/mesh.pb.h"
|
|
||||||
#include "mesh/generated/meshtastic/localonly.pb.h"
|
|
||||||
#include "mesh/generated/meshtastic/deviceonly.pb.h"
|
|
||||||
#include "mesh/generated/meshtastic/admin.pb.h"
|
#include "mesh/generated/meshtastic/admin.pb.h"
|
||||||
|
#include "mesh/generated/meshtastic/deviceonly.pb.h"
|
||||||
|
#include "mesh/generated/meshtastic/localonly.pb.h"
|
||||||
|
#include "mesh/generated/meshtastic/mesh.pb.h"
|
||||||
|
|
||||||
// this file defines constants which come from mesh.options
|
// this file defines constants which come from mesh.options
|
||||||
|
|
||||||
@@ -11,8 +11,8 @@
|
|||||||
#define member_size(type, member) sizeof(((type *)0)->member)
|
#define member_size(type, member) sizeof(((type *)0)->member)
|
||||||
|
|
||||||
/// max number of packets which can be waiting for delivery to android - note, this value comes from mesh.options protobuf
|
/// max number of packets which can be waiting for delivery to android - note, this value comes from mesh.options protobuf
|
||||||
// FIXME - max_count is actually 32 but we save/load this as one long string of preencoded MeshPacket bytes - not a big array in RAM
|
// FIXME - max_count is actually 32 but we save/load this as one long string of preencoded MeshPacket bytes - not a big array in
|
||||||
// #define MAX_RX_TOPHONE (member_size(DeviceState, receive_queue) / member_size(DeviceState, receive_queue[0]))
|
// RAM #define MAX_RX_TOPHONE (member_size(DeviceState, receive_queue) / member_size(DeviceState, receive_queue[0]))
|
||||||
#define MAX_RX_TOPHONE 32
|
#define MAX_RX_TOPHONE 32
|
||||||
|
|
||||||
/// max number of nodes allowed in the mesh
|
/// max number of nodes allowed in the mesh
|
||||||
|
|||||||
@@ -2,8 +2,8 @@
|
|||||||
#if HAS_SCREEN
|
#if HAS_SCREEN
|
||||||
#include "CannedMessageModule.h"
|
#include "CannedMessageModule.h"
|
||||||
#include "FSCommon.h"
|
#include "FSCommon.h"
|
||||||
#include "NodeDB.h"
|
|
||||||
#include "MeshService.h"
|
#include "MeshService.h"
|
||||||
|
#include "NodeDB.h"
|
||||||
#include "PowerFSM.h" // neede for button bypass
|
#include "PowerFSM.h" // neede for button bypass
|
||||||
#include "mesh/generated/meshtastic/cannedmessages.pb.h"
|
#include "mesh/generated/meshtastic/cannedmessages.pb.h"
|
||||||
|
|
||||||
@@ -152,7 +152,7 @@ int CannedMessageModule::handleInputEvent(const InputEvent *event)
|
|||||||
if ((event->inputEvent == static_cast<char>(ModuleConfig_CannedMessageConfig_InputEventChar_BACK)) ||
|
if ((event->inputEvent == static_cast<char>(ModuleConfig_CannedMessageConfig_InputEventChar_BACK)) ||
|
||||||
(event->inputEvent == static_cast<char>(ModuleConfig_CannedMessageConfig_InputEventChar_LEFT)) ||
|
(event->inputEvent == static_cast<char>(ModuleConfig_CannedMessageConfig_InputEventChar_LEFT)) ||
|
||||||
(event->inputEvent == static_cast<char>(ModuleConfig_CannedMessageConfig_InputEventChar_RIGHT))) {
|
(event->inputEvent == static_cast<char>(ModuleConfig_CannedMessageConfig_InputEventChar_RIGHT))) {
|
||||||
LOG_DEBUG("Canned message event (%x)\n",event->kbchar);
|
LOG_DEBUG("Canned message event (%x)\n", event->kbchar);
|
||||||
if (this->runState == CANNED_MESSAGE_RUN_STATE_FREETEXT) {
|
if (this->runState == CANNED_MESSAGE_RUN_STATE_FREETEXT) {
|
||||||
// pass the pressed key
|
// pass the pressed key
|
||||||
this->payload = event->kbchar;
|
this->payload = event->kbchar;
|
||||||
@@ -163,7 +163,8 @@ int CannedMessageModule::handleInputEvent(const InputEvent *event)
|
|||||||
if (event->inputEvent == static_cast<char>(ANYKEY)) {
|
if (event->inputEvent == static_cast<char>(ANYKEY)) {
|
||||||
LOG_DEBUG("Canned message event any key pressed\n");
|
LOG_DEBUG("Canned message event any key pressed\n");
|
||||||
// when inactive, this will switch to the freetext mode
|
// when inactive, this will switch to the freetext mode
|
||||||
if ((this->runState == CANNED_MESSAGE_RUN_STATE_INACTIVE) || (this->runState == CANNED_MESSAGE_RUN_STATE_ACTIVE) || (this->runState == CANNED_MESSAGE_RUN_STATE_DISABLED)) {
|
if ((this->runState == CANNED_MESSAGE_RUN_STATE_INACTIVE) || (this->runState == CANNED_MESSAGE_RUN_STATE_ACTIVE) ||
|
||||||
|
(this->runState == CANNED_MESSAGE_RUN_STATE_DISABLED)) {
|
||||||
this->runState = CANNED_MESSAGE_RUN_STATE_FREETEXT;
|
this->runState = CANNED_MESSAGE_RUN_STATE_FREETEXT;
|
||||||
}
|
}
|
||||||
// pass the pressed key
|
// pass the pressed key
|
||||||
@@ -176,7 +177,7 @@ int CannedMessageModule::handleInputEvent(const InputEvent *event)
|
|||||||
// this will send the text immediately on matrix press
|
// this will send the text immediately on matrix press
|
||||||
this->runState = CANNED_MESSAGE_RUN_STATE_ACTION_SELECT;
|
this->runState = CANNED_MESSAGE_RUN_STATE_ACTION_SELECT;
|
||||||
this->payload = MATRIXKEY;
|
this->payload = MATRIXKEY;
|
||||||
this->currentMessageIndex = event->kbchar -1;
|
this->currentMessageIndex = event->kbchar - 1;
|
||||||
this->lastTouchMillis = millis();
|
this->lastTouchMillis = millis();
|
||||||
validEvent = true;
|
validEvent = true;
|
||||||
}
|
}
|
||||||
@@ -224,7 +225,8 @@ int32_t CannedMessageModule::runOnce()
|
|||||||
this->cursor = 0;
|
this->cursor = 0;
|
||||||
this->destSelect = false;
|
this->destSelect = false;
|
||||||
this->notifyObservers(&e);
|
this->notifyObservers(&e);
|
||||||
} else if (((this->runState == CANNED_MESSAGE_RUN_STATE_ACTIVE) || (this->runState == CANNED_MESSAGE_RUN_STATE_FREETEXT)) && ((millis() - this->lastTouchMillis) > INACTIVATE_AFTER_MS)) {
|
} else if (((this->runState == CANNED_MESSAGE_RUN_STATE_ACTIVE) || (this->runState == CANNED_MESSAGE_RUN_STATE_FREETEXT)) &&
|
||||||
|
((millis() - this->lastTouchMillis) > INACTIVATE_AFTER_MS)) {
|
||||||
// Reset module
|
// Reset module
|
||||||
LOG_DEBUG("Reset due to lack of activity.\n");
|
LOG_DEBUG("Reset due to lack of activity.\n");
|
||||||
e.frameChanged = true;
|
e.frameChanged = true;
|
||||||
@@ -245,7 +247,7 @@ int32_t CannedMessageModule::runOnce()
|
|||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
if ((this->messagesCount > this->currentMessageIndex) && (strlen(this->messages[this->currentMessageIndex]) > 0)) {
|
if ((this->messagesCount > this->currentMessageIndex) && (strlen(this->messages[this->currentMessageIndex]) > 0)) {
|
||||||
if(strcmp (this->messages[this->currentMessageIndex], "~") == 0) {
|
if (strcmp(this->messages[this->currentMessageIndex], "~") == 0) {
|
||||||
powerFSM.trigger(EVENT_PRESS);
|
powerFSM.trigger(EVENT_PRESS);
|
||||||
return INT32_MAX;
|
return INT32_MAX;
|
||||||
} else {
|
} else {
|
||||||
@@ -264,7 +266,7 @@ int32_t CannedMessageModule::runOnce()
|
|||||||
this->destSelect = false;
|
this->destSelect = false;
|
||||||
this->notifyObservers(&e);
|
this->notifyObservers(&e);
|
||||||
return 2000;
|
return 2000;
|
||||||
} else if ((this->runState != CANNED_MESSAGE_RUN_STATE_FREETEXT) && (this->currentMessageIndex == -1)) {
|
} else if ((this->runState != CANNED_MESSAGE_RUN_STATE_FREETEXT) && (this->currentMessageIndex == -1)) {
|
||||||
this->currentMessageIndex = 0;
|
this->currentMessageIndex = 0;
|
||||||
LOG_DEBUG("First touch (%d):%s\n", this->currentMessageIndex, this->getCurrentMessage());
|
LOG_DEBUG("First touch (%d):%s\n", this->currentMessageIndex, this->getCurrentMessage());
|
||||||
e.frameChanged = true;
|
e.frameChanged = true;
|
||||||
@@ -290,79 +292,79 @@ int32_t CannedMessageModule::runOnce()
|
|||||||
} else if (this->runState == CANNED_MESSAGE_RUN_STATE_FREETEXT) {
|
} else if (this->runState == CANNED_MESSAGE_RUN_STATE_FREETEXT) {
|
||||||
e.frameChanged = true;
|
e.frameChanged = true;
|
||||||
switch (this->payload) {
|
switch (this->payload) {
|
||||||
case 0xb4: // left
|
case 0xb4: // left
|
||||||
if (this->destSelect){
|
if (this->destSelect) {
|
||||||
size_t numNodes = nodeDB.getNumNodes();
|
size_t numNodes = nodeDB.getNumNodes();
|
||||||
if(this->dest == NODENUM_BROADCAST) {
|
if (this->dest == NODENUM_BROADCAST) {
|
||||||
this->dest = nodeDB.getNodeNum();
|
this->dest = nodeDB.getNodeNum();
|
||||||
}
|
}
|
||||||
for (unsigned int i = 0; i < numNodes; i++) {
|
for (unsigned int i = 0; i < numNodes; i++) {
|
||||||
if (nodeDB.getNodeByIndex(i)->num == this->dest) {
|
if (nodeDB.getNodeByIndex(i)->num == this->dest) {
|
||||||
this->dest = (i > 0) ? nodeDB.getNodeByIndex(i-1)->num : nodeDB.getNodeByIndex(numNodes-1)->num;
|
this->dest = (i > 0) ? nodeDB.getNodeByIndex(i - 1)->num : nodeDB.getNodeByIndex(numNodes - 1)->num;
|
||||||
break;
|
break;
|
||||||
}
|
|
||||||
}
|
|
||||||
if(this->dest == nodeDB.getNodeNum()) {
|
|
||||||
this->dest = NODENUM_BROADCAST;
|
|
||||||
}
|
|
||||||
}else{
|
|
||||||
if (this->cursor > 0) {
|
|
||||||
this->cursor--;
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
break;
|
if (this->dest == nodeDB.getNodeNum()) {
|
||||||
case 0xb7: // right
|
this->dest = NODENUM_BROADCAST;
|
||||||
if (this->destSelect){
|
|
||||||
size_t numNodes = nodeDB.getNumNodes();
|
|
||||||
if(this->dest == NODENUM_BROADCAST) {
|
|
||||||
this->dest = nodeDB.getNodeNum();
|
|
||||||
}
|
|
||||||
for (unsigned int i = 0; i < numNodes; i++) {
|
|
||||||
if (nodeDB.getNodeByIndex(i)->num == this->dest) {
|
|
||||||
this->dest = (i < numNodes-1) ? nodeDB.getNodeByIndex(i+1)->num : nodeDB.getNodeByIndex(0)->num;
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
if(this->dest == nodeDB.getNodeNum()) {
|
|
||||||
this->dest = NODENUM_BROADCAST;
|
|
||||||
}
|
|
||||||
}else{
|
|
||||||
if (this->cursor < this->freetext.length()) {
|
|
||||||
this->cursor++;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
break;
|
} else {
|
||||||
case 0x08: // backspace
|
if (this->cursor > 0) {
|
||||||
if (this->freetext.length() > 0) {
|
|
||||||
if(this->cursor == this->freetext.length()) {
|
|
||||||
this->freetext = this->freetext.substring(0, this->freetext.length() - 1);
|
|
||||||
} else {
|
|
||||||
this->freetext = this->freetext.substring(0, this->cursor - 1) + this->freetext.substring(this->cursor, this->freetext.length());
|
|
||||||
}
|
|
||||||
this->cursor--;
|
this->cursor--;
|
||||||
}
|
}
|
||||||
break;
|
}
|
||||||
case 0x09: // tab
|
break;
|
||||||
if(this->destSelect) {
|
case 0xb7: // right
|
||||||
this->destSelect = false;
|
if (this->destSelect) {
|
||||||
|
size_t numNodes = nodeDB.getNumNodes();
|
||||||
|
if (this->dest == NODENUM_BROADCAST) {
|
||||||
|
this->dest = nodeDB.getNodeNum();
|
||||||
|
}
|
||||||
|
for (unsigned int i = 0; i < numNodes; i++) {
|
||||||
|
if (nodeDB.getNodeByIndex(i)->num == this->dest) {
|
||||||
|
this->dest = (i < numNodes - 1) ? nodeDB.getNodeByIndex(i + 1)->num : nodeDB.getNodeByIndex(0)->num;
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if (this->dest == nodeDB.getNodeNum()) {
|
||||||
|
this->dest = NODENUM_BROADCAST;
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
if (this->cursor < this->freetext.length()) {
|
||||||
|
this->cursor++;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
break;
|
||||||
|
case 0x08: // backspace
|
||||||
|
if (this->freetext.length() > 0) {
|
||||||
|
if (this->cursor == this->freetext.length()) {
|
||||||
|
this->freetext = this->freetext.substring(0, this->freetext.length() - 1);
|
||||||
} else {
|
} else {
|
||||||
this->destSelect = true;
|
this->freetext = this->freetext.substring(0, this->cursor - 1) +
|
||||||
|
this->freetext.substring(this->cursor, this->freetext.length());
|
||||||
}
|
}
|
||||||
break;
|
this->cursor--;
|
||||||
default:
|
}
|
||||||
if(this->cursor == this->freetext.length()) {
|
break;
|
||||||
this->freetext += this->payload;
|
case 0x09: // tab
|
||||||
} else {
|
if (this->destSelect) {
|
||||||
this->freetext = this->freetext.substring(0, this->cursor)
|
this->destSelect = false;
|
||||||
+ this->payload
|
} else {
|
||||||
+ this->freetext.substring(this->cursor);
|
this->destSelect = true;
|
||||||
}
|
}
|
||||||
this->cursor += 1;
|
break;
|
||||||
if (this->freetext.length() > Constants_DATA_PAYLOAD_LEN) {
|
default:
|
||||||
this->cursor = Constants_DATA_PAYLOAD_LEN;
|
if (this->cursor == this->freetext.length()) {
|
||||||
this->freetext = this->freetext.substring(0, Constants_DATA_PAYLOAD_LEN);
|
this->freetext += this->payload;
|
||||||
}
|
} else {
|
||||||
break;
|
this->freetext =
|
||||||
|
this->freetext.substring(0, this->cursor) + this->payload + this->freetext.substring(this->cursor);
|
||||||
|
}
|
||||||
|
this->cursor += 1;
|
||||||
|
if (this->freetext.length() > Constants_DATA_PAYLOAD_LEN) {
|
||||||
|
this->cursor = Constants_DATA_PAYLOAD_LEN;
|
||||||
|
this->freetext = this->freetext.substring(0, Constants_DATA_PAYLOAD_LEN);
|
||||||
|
}
|
||||||
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
this->lastTouchMillis = millis();
|
this->lastTouchMillis = millis();
|
||||||
@@ -391,14 +393,15 @@ const char *CannedMessageModule::getNextMessage()
|
|||||||
{
|
{
|
||||||
return this->messages[this->getNextIndex()];
|
return this->messages[this->getNextIndex()];
|
||||||
}
|
}
|
||||||
const char* CannedMessageModule::getNodeName(NodeNum node) {
|
const char *CannedMessageModule::getNodeName(NodeNum node)
|
||||||
if (node == NODENUM_BROADCAST){
|
{
|
||||||
|
if (node == NODENUM_BROADCAST) {
|
||||||
return "Broadcast";
|
return "Broadcast";
|
||||||
}else{
|
} else {
|
||||||
NodeInfo *info = nodeDB.getNode(node);
|
NodeInfo *info = nodeDB.getNode(node);
|
||||||
if(info != NULL) {
|
if (info != NULL) {
|
||||||
return info->user.long_name;
|
return info->user.long_name;
|
||||||
}else{
|
} else {
|
||||||
return "Unknown";
|
return "Unknown";
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -444,7 +447,7 @@ void CannedMessageModule::drawFrame(OLEDDisplay *display, OLEDDisplayUiState *st
|
|||||||
display->setTextAlignment(TEXT_ALIGN_LEFT);
|
display->setTextAlignment(TEXT_ALIGN_LEFT);
|
||||||
display->setFont(FONT_SMALL);
|
display->setFont(FONT_SMALL);
|
||||||
display->drawString(10 + x, 0 + y + FONT_HEIGHT_SMALL, "Canned Message\nModule disabled.");
|
display->drawString(10 + x, 0 + y + FONT_HEIGHT_SMALL, "Canned Message\nModule disabled.");
|
||||||
}else if (cannedMessageModule->runState == CANNED_MESSAGE_RUN_STATE_FREETEXT) {
|
} else if (cannedMessageModule->runState == CANNED_MESSAGE_RUN_STATE_FREETEXT) {
|
||||||
display->setTextAlignment(TEXT_ALIGN_LEFT);
|
display->setTextAlignment(TEXT_ALIGN_LEFT);
|
||||||
display->setFont(FONT_SMALL);
|
display->setFont(FONT_SMALL);
|
||||||
if (this->destSelect) {
|
if (this->destSelect) {
|
||||||
@@ -460,7 +463,9 @@ void CannedMessageModule::drawFrame(OLEDDisplay *display, OLEDDisplayUiState *st
|
|||||||
display->drawString(x + display->getWidth() - display->getStringWidth(buffer) - 1, y + 0, buffer);
|
display->drawString(x + display->getWidth() - display->getStringWidth(buffer) - 1, y + 0, buffer);
|
||||||
}
|
}
|
||||||
display->setColor(WHITE);
|
display->setColor(WHITE);
|
||||||
display->drawStringMaxWidth(0 + x, 0 + y + FONT_HEIGHT_SMALL, x + display->getWidth(), cannedMessageModule->drawWithCursor(cannedMessageModule->freetext, cannedMessageModule->cursor));
|
display->drawStringMaxWidth(
|
||||||
|
0 + x, 0 + y + FONT_HEIGHT_SMALL, x + display->getWidth(),
|
||||||
|
cannedMessageModule->drawWithCursor(cannedMessageModule->freetext, cannedMessageModule->cursor));
|
||||||
} else {
|
} else {
|
||||||
if (this->messagesCount > 0) {
|
if (this->messagesCount > 0) {
|
||||||
display->setTextAlignment(TEXT_ALIGN_LEFT);
|
display->setTextAlignment(TEXT_ALIGN_LEFT);
|
||||||
@@ -479,7 +484,7 @@ void CannedMessageModule::drawFrame(OLEDDisplay *display, OLEDDisplayUiState *st
|
|||||||
void CannedMessageModule::loadProtoForModule()
|
void CannedMessageModule::loadProtoForModule()
|
||||||
{
|
{
|
||||||
if (!nodeDB.loadProto(cannedMessagesConfigFile, CannedMessageModuleConfig_size, sizeof(CannedMessageModuleConfig),
|
if (!nodeDB.loadProto(cannedMessagesConfigFile, CannedMessageModuleConfig_size, sizeof(CannedMessageModuleConfig),
|
||||||
&CannedMessageModuleConfig_msg, &cannedMessageModuleConfig)) {
|
&CannedMessageModuleConfig_msg, &cannedMessageModuleConfig)) {
|
||||||
installDefaultCannedMessageModuleConfig();
|
installDefaultCannedMessageModuleConfig();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -498,8 +503,8 @@ bool CannedMessageModule::saveProtoForModule()
|
|||||||
FS.mkdir("/prefs");
|
FS.mkdir("/prefs");
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
okay &= nodeDB.saveProto(cannedMessagesConfigFile, CannedMessageModuleConfig_size,
|
okay &= nodeDB.saveProto(cannedMessagesConfigFile, CannedMessageModuleConfig_size, &CannedMessageModuleConfig_msg,
|
||||||
&CannedMessageModuleConfig_msg, &cannedMessageModuleConfig);
|
&cannedMessageModuleConfig);
|
||||||
|
|
||||||
return okay;
|
return okay;
|
||||||
}
|
}
|
||||||
@@ -549,13 +554,13 @@ AdminMessageHandleResult CannedMessageModule::handleAdminMessageForModule(const
|
|||||||
void CannedMessageModule::handleGetCannedMessageModuleMessages(const MeshPacket &req, AdminMessage *response)
|
void CannedMessageModule::handleGetCannedMessageModuleMessages(const MeshPacket &req, AdminMessage *response)
|
||||||
{
|
{
|
||||||
LOG_DEBUG("*** handleGetCannedMessageModuleMessages\n");
|
LOG_DEBUG("*** handleGetCannedMessageModuleMessages\n");
|
||||||
if(req.decoded.want_response) {
|
if (req.decoded.want_response) {
|
||||||
response->which_payload_variant = AdminMessage_get_canned_message_module_messages_response_tag;
|
response->which_payload_variant = AdminMessage_get_canned_message_module_messages_response_tag;
|
||||||
strncpy(response->get_canned_message_module_messages_response, cannedMessageModuleConfig.messages, sizeof(response->get_canned_message_module_messages_response));
|
strncpy(response->get_canned_message_module_messages_response, cannedMessageModuleConfig.messages,
|
||||||
|
sizeof(response->get_canned_message_module_messages_response));
|
||||||
} // Don't send anything if not instructed to. Better than asserting.
|
} // Don't send anything if not instructed to. Better than asserting.
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
void CannedMessageModule::handleSetCannedMessageModuleMessages(const char *from_msg)
|
void CannedMessageModule::handleSetCannedMessageModuleMessages(const char *from_msg)
|
||||||
{
|
{
|
||||||
int changed = 0;
|
int changed = 0;
|
||||||
@@ -573,9 +578,7 @@ void CannedMessageModule::handleSetCannedMessageModuleMessages(const char *from_
|
|||||||
|
|
||||||
String CannedMessageModule::drawWithCursor(String text, int cursor)
|
String CannedMessageModule::drawWithCursor(String text, int cursor)
|
||||||
{
|
{
|
||||||
String result = text.substring(0, cursor)
|
String result = text.substring(0, cursor) + "_" + text.substring(cursor);
|
||||||
+ "_"
|
|
||||||
+ text.substring(cursor);
|
|
||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -58,19 +58,19 @@ int32_t ExternalNotificationModule::runOnce()
|
|||||||
|
|
||||||
// If the output is turned on, turn it back off after the given period of time.
|
// If the output is turned on, turn it back off after the given period of time.
|
||||||
if (isNagging) {
|
if (isNagging) {
|
||||||
if (externalTurnedOn[0] + (moduleConfig.external_notification.output_ms
|
if (externalTurnedOn[0] + (moduleConfig.external_notification.output_ms ? moduleConfig.external_notification.output_ms
|
||||||
? moduleConfig.external_notification.output_ms
|
: EXT_NOTIFICATION_MODULE_OUTPUT_MS) <
|
||||||
: EXT_NOTIFICATION_MODULE_OUTPUT_MS) < millis()) {
|
millis()) {
|
||||||
getExternal(0) ? setExternalOff(0) : setExternalOn(0);
|
getExternal(0) ? setExternalOff(0) : setExternalOn(0);
|
||||||
}
|
}
|
||||||
if (externalTurnedOn[1] + (moduleConfig.external_notification.output_ms
|
if (externalTurnedOn[1] + (moduleConfig.external_notification.output_ms ? moduleConfig.external_notification.output_ms
|
||||||
? moduleConfig.external_notification.output_ms
|
: EXT_NOTIFICATION_MODULE_OUTPUT_MS) <
|
||||||
: EXT_NOTIFICATION_MODULE_OUTPUT_MS) < millis()) {
|
millis()) {
|
||||||
getExternal(1) ? setExternalOff(1) : setExternalOn(1);
|
getExternal(1) ? setExternalOff(1) : setExternalOn(1);
|
||||||
}
|
}
|
||||||
if (externalTurnedOn[2] + (moduleConfig.external_notification.output_ms
|
if (externalTurnedOn[2] + (moduleConfig.external_notification.output_ms ? moduleConfig.external_notification.output_ms
|
||||||
? moduleConfig.external_notification.output_ms
|
: EXT_NOTIFICATION_MODULE_OUTPUT_MS) <
|
||||||
: EXT_NOTIFICATION_MODULE_OUTPUT_MS) < millis()) {
|
millis()) {
|
||||||
getExternal(2) ? setExternalOff(2) : setExternalOn(2);
|
getExternal(2) ? setExternalOff(2) : setExternalOn(2);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -93,18 +93,18 @@ void ExternalNotificationModule::setExternalOn(uint8_t index)
|
|||||||
externalCurrentState[index] = 1;
|
externalCurrentState[index] = 1;
|
||||||
externalTurnedOn[index] = millis();
|
externalTurnedOn[index] = millis();
|
||||||
|
|
||||||
switch(index) {
|
switch (index) {
|
||||||
case 1:
|
case 1:
|
||||||
if(moduleConfig.external_notification.output_vibra)
|
if (moduleConfig.external_notification.output_vibra)
|
||||||
digitalWrite(moduleConfig.external_notification.output_vibra, true);
|
digitalWrite(moduleConfig.external_notification.output_vibra, true);
|
||||||
break;
|
break;
|
||||||
case 2:
|
case 2:
|
||||||
if(moduleConfig.external_notification.output_buzzer)
|
if (moduleConfig.external_notification.output_buzzer)
|
||||||
digitalWrite(moduleConfig.external_notification.output_buzzer, true);
|
digitalWrite(moduleConfig.external_notification.output_buzzer, true);
|
||||||
break;
|
break;
|
||||||
default:
|
default:
|
||||||
digitalWrite(output, (moduleConfig.external_notification.active ? true : false));
|
digitalWrite(output, (moduleConfig.external_notification.active ? true : false));
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -113,18 +113,18 @@ void ExternalNotificationModule::setExternalOff(uint8_t index)
|
|||||||
externalCurrentState[index] = 0;
|
externalCurrentState[index] = 0;
|
||||||
externalTurnedOn[index] = millis();
|
externalTurnedOn[index] = millis();
|
||||||
|
|
||||||
switch(index) {
|
switch (index) {
|
||||||
case 1:
|
case 1:
|
||||||
if(moduleConfig.external_notification.output_vibra)
|
if (moduleConfig.external_notification.output_vibra)
|
||||||
digitalWrite(moduleConfig.external_notification.output_vibra, false);
|
digitalWrite(moduleConfig.external_notification.output_vibra, false);
|
||||||
break;
|
break;
|
||||||
case 2:
|
case 2:
|
||||||
if(moduleConfig.external_notification.output_buzzer)
|
if (moduleConfig.external_notification.output_buzzer)
|
||||||
digitalWrite(moduleConfig.external_notification.output_buzzer, false);
|
digitalWrite(moduleConfig.external_notification.output_buzzer, false);
|
||||||
break;
|
break;
|
||||||
default:
|
default:
|
||||||
digitalWrite(output, (moduleConfig.external_notification.active ? false : true));
|
digitalWrite(output, (moduleConfig.external_notification.active ? false : true));
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -133,7 +133,8 @@ bool ExternalNotificationModule::getExternal(uint8_t index)
|
|||||||
return externalCurrentState[index];
|
return externalCurrentState[index];
|
||||||
}
|
}
|
||||||
|
|
||||||
void ExternalNotificationModule::stopNow() {
|
void ExternalNotificationModule::stopNow()
|
||||||
|
{
|
||||||
rtttl::stop();
|
rtttl::stop();
|
||||||
nagCycleCutoff = 1; // small value
|
nagCycleCutoff = 1; // small value
|
||||||
isNagging = false;
|
isNagging = false;
|
||||||
@@ -165,36 +166,35 @@ ExternalNotificationModule::ExternalNotificationModule()
|
|||||||
if (moduleConfig.external_notification.enabled) {
|
if (moduleConfig.external_notification.enabled) {
|
||||||
if (!nodeDB.loadProto(rtttlConfigFile, RTTTLConfig_size, sizeof(RTTTLConfig), &RTTTLConfig_msg, &rtttlConfig)) {
|
if (!nodeDB.loadProto(rtttlConfigFile, RTTTLConfig_size, sizeof(RTTTLConfig), &RTTTLConfig_msg, &rtttlConfig)) {
|
||||||
memset(rtttlConfig.ringtone, 0, sizeof(rtttlConfig.ringtone));
|
memset(rtttlConfig.ringtone, 0, sizeof(rtttlConfig.ringtone));
|
||||||
strncpy(rtttlConfig.ringtone, "a:d=8,o=5,b=125:4d#6,a#,2d#6,16p,g#,4a#,4d#.,p,16g,16a#,d#6,a#,f6,2d#6,16p,c#.6,16c6,16a#,g#.,2a#", sizeof(rtttlConfig.ringtone));
|
strncpy(rtttlConfig.ringtone,
|
||||||
|
"a:d=8,o=5,b=125:4d#6,a#,2d#6,16p,g#,4a#,4d#.,p,16g,16a#,d#6,a#,f6,2d#6,16p,c#.6,16c6,16a#,g#.,2a#",
|
||||||
|
sizeof(rtttlConfig.ringtone));
|
||||||
}
|
}
|
||||||
|
|
||||||
LOG_INFO("Initializing External Notification Module\n");
|
LOG_INFO("Initializing External Notification Module\n");
|
||||||
|
|
||||||
output = moduleConfig.external_notification.output
|
output = moduleConfig.external_notification.output ? moduleConfig.external_notification.output
|
||||||
? moduleConfig.external_notification.output
|
: EXT_NOTIFICATION_MODULE_OUTPUT;
|
||||||
: EXT_NOTIFICATION_MODULE_OUTPUT;
|
|
||||||
|
|
||||||
// Set the direction of a pin
|
// Set the direction of a pin
|
||||||
LOG_INFO("Using Pin %i in digital mode\n", output);
|
LOG_INFO("Using Pin %i in digital mode\n", output);
|
||||||
pinMode(output, OUTPUT);
|
pinMode(output, OUTPUT);
|
||||||
setExternalOff(0);
|
setExternalOff(0);
|
||||||
externalTurnedOn[0] = 0;
|
externalTurnedOn[0] = 0;
|
||||||
if(moduleConfig.external_notification.output_vibra) {
|
if (moduleConfig.external_notification.output_vibra) {
|
||||||
LOG_INFO("Using Pin %i for vibra motor\n", moduleConfig.external_notification.output_vibra);
|
LOG_INFO("Using Pin %i for vibra motor\n", moduleConfig.external_notification.output_vibra);
|
||||||
pinMode(moduleConfig.external_notification.output_vibra, OUTPUT);
|
pinMode(moduleConfig.external_notification.output_vibra, OUTPUT);
|
||||||
setExternalOff(1);
|
setExternalOff(1);
|
||||||
externalTurnedOn[1] = 0;
|
externalTurnedOn[1] = 0;
|
||||||
}
|
}
|
||||||
if(moduleConfig.external_notification.output_buzzer) {
|
if (moduleConfig.external_notification.output_buzzer) {
|
||||||
if (!moduleConfig.external_notification.use_pwm) {
|
if (!moduleConfig.external_notification.use_pwm) {
|
||||||
LOG_INFO("Using Pin %i for buzzer\n", moduleConfig.external_notification.output_buzzer);
|
LOG_INFO("Using Pin %i for buzzer\n", moduleConfig.external_notification.output_buzzer);
|
||||||
pinMode(moduleConfig.external_notification.output_buzzer, OUTPUT);
|
pinMode(moduleConfig.external_notification.output_buzzer, OUTPUT);
|
||||||
setExternalOff(2);
|
setExternalOff(2);
|
||||||
externalTurnedOn[2] = 0;
|
externalTurnedOn[2] = 0;
|
||||||
} else {
|
} else {
|
||||||
config.device.buzzer_gpio = config.device.buzzer_gpio
|
config.device.buzzer_gpio = config.device.buzzer_gpio ? config.device.buzzer_gpio : PIN_BUZZER;
|
||||||
? config.device.buzzer_gpio
|
|
||||||
: PIN_BUZZER;
|
|
||||||
// in PWM Mode we force the buzzer pin if it is set
|
// in PWM Mode we force the buzzer pin if it is set
|
||||||
LOG_INFO("Using Pin %i in PWM mode\n", config.device.buzzer_gpio);
|
LOG_INFO("Using Pin %i in PWM mode\n", config.device.buzzer_gpio);
|
||||||
}
|
}
|
||||||
@@ -274,7 +274,6 @@ ProcessMessage ExternalNotificationModule::handleReceived(const MeshPacket &mp)
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
if (moduleConfig.external_notification.alert_message_vibra) {
|
if (moduleConfig.external_notification.alert_message_vibra) {
|
||||||
LOG_INFO("externalNotificationModule - Notification Module (Vibra)\n");
|
LOG_INFO("externalNotificationModule - Notification Module (Vibra)\n");
|
||||||
isNagging = true;
|
isNagging = true;
|
||||||
@@ -320,7 +319,8 @@ ProcessMessage ExternalNotificationModule::handleReceived(const MeshPacket &mp)
|
|||||||
* @return AdminMessageHandleResult HANDLED if message was handled
|
* @return AdminMessageHandleResult HANDLED if message was handled
|
||||||
* HANDLED_WITH_RESULT if a result is also prepared.
|
* HANDLED_WITH_RESULT if a result is also prepared.
|
||||||
*/
|
*/
|
||||||
AdminMessageHandleResult ExternalNotificationModule::handleAdminMessageForModule(const MeshPacket &mp, AdminMessage *request, AdminMessage *response)
|
AdminMessageHandleResult ExternalNotificationModule::handleAdminMessageForModule(const MeshPacket &mp, AdminMessage *request,
|
||||||
|
AdminMessage *response)
|
||||||
{
|
{
|
||||||
AdminMessageHandleResult result;
|
AdminMessageHandleResult result;
|
||||||
|
|
||||||
@@ -347,13 +347,12 @@ AdminMessageHandleResult ExternalNotificationModule::handleAdminMessageForModule
|
|||||||
void ExternalNotificationModule::handleGetRingtone(const MeshPacket &req, AdminMessage *response)
|
void ExternalNotificationModule::handleGetRingtone(const MeshPacket &req, AdminMessage *response)
|
||||||
{
|
{
|
||||||
LOG_INFO("*** handleGetRingtone\n");
|
LOG_INFO("*** handleGetRingtone\n");
|
||||||
if(req.decoded.want_response) {
|
if (req.decoded.want_response) {
|
||||||
response->which_payload_variant = AdminMessage_get_ringtone_response_tag;
|
response->which_payload_variant = AdminMessage_get_ringtone_response_tag;
|
||||||
strncpy(response->get_ringtone_response, rtttlConfig.ringtone, sizeof(response->get_ringtone_response));
|
strncpy(response->get_ringtone_response, rtttlConfig.ringtone, sizeof(response->get_ringtone_response));
|
||||||
} // Don't send anything if not instructed to. Better than asserting.
|
} // Don't send anything if not instructed to. Better than asserting.
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
void ExternalNotificationModule::handleSetRingtone(const char *from_msg)
|
void ExternalNotificationModule::handleSetRingtone(const char *from_msg)
|
||||||
{
|
{
|
||||||
int changed = 0;
|
int changed = 0;
|
||||||
|
|||||||
@@ -1,7 +1,7 @@
|
|||||||
#pragma once
|
#pragma once
|
||||||
#include "ProtobufModule.h"
|
#include "ProtobufModule.h"
|
||||||
#include "mesh/generated/meshtastic/remote_hardware.pb.h"
|
|
||||||
#include "concurrency/OSThread.h"
|
#include "concurrency/OSThread.h"
|
||||||
|
#include "mesh/generated/meshtastic/remote_hardware.pb.h"
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* A module that provides easy low-level remote access to device hardware.
|
* A module that provides easy low-level remote access to device hardware.
|
||||||
@@ -16,6 +16,7 @@ class RemoteHardwareModule : public ProtobufModule<HardwareMessage>, private con
|
|||||||
|
|
||||||
/// The timestamp of our last watch event (we throttle watches to 1 change every 30 seconds)
|
/// The timestamp of our last watch event (we throttle watches to 1 change every 30 seconds)
|
||||||
uint32_t lastWatchMsec = 0;
|
uint32_t lastWatchMsec = 0;
|
||||||
|
|
||||||
public:
|
public:
|
||||||
/** Constructor
|
/** Constructor
|
||||||
* name is for debugging output
|
* name is for debugging output
|
||||||
|
|||||||
@@ -9,13 +9,12 @@
|
|||||||
#include "main.h"
|
#include "main.h"
|
||||||
#include <OLEDDisplay.h>
|
#include <OLEDDisplay.h>
|
||||||
#include <OLEDDisplayUi.h>
|
#include <OLEDDisplayUi.h>
|
||||||
#include "MeshService.h"
|
|
||||||
|
|
||||||
int32_t DeviceTelemetryModule::runOnce()
|
int32_t DeviceTelemetryModule::runOnce()
|
||||||
{
|
{
|
||||||
uint32_t now = millis();
|
uint32_t now = millis();
|
||||||
if ((lastSentToMesh == 0 ||
|
if ((lastSentToMesh == 0 ||
|
||||||
(now - lastSentToMesh) >= getConfiguredOrDefaultMs(moduleConfig.telemetry.device_update_interval)) &&
|
(now - lastSentToMesh) >= getConfiguredOrDefaultMs(moduleConfig.telemetry.device_update_interval)) &&
|
||||||
airTime->isTxAllowedChannelUtil() && airTime->isTxAllowedAirUtil()) {
|
airTime->isTxAllowedChannelUtil() && airTime->isTxAllowedAirUtil()) {
|
||||||
sendTelemetry();
|
sendTelemetry();
|
||||||
lastSentToMesh = now;
|
lastSentToMesh = now;
|
||||||
@@ -32,12 +31,9 @@ bool DeviceTelemetryModule::handleReceivedProtobuf(const MeshPacket &mp, Telemet
|
|||||||
if (t->which_variant == Telemetry_device_metrics_tag) {
|
if (t->which_variant == Telemetry_device_metrics_tag) {
|
||||||
const char *sender = getSenderShortName(mp);
|
const char *sender = getSenderShortName(mp);
|
||||||
|
|
||||||
LOG_INFO("(Received from %s): air_util_tx=%f, channel_utilization=%f, battery_level=%i, voltage=%f\n",
|
LOG_INFO("(Received from %s): air_util_tx=%f, channel_utilization=%f, battery_level=%i, voltage=%f\n", sender,
|
||||||
sender,
|
t->variant.device_metrics.air_util_tx, t->variant.device_metrics.channel_utilization,
|
||||||
t->variant.device_metrics.air_util_tx,
|
t->variant.device_metrics.battery_level, t->variant.device_metrics.voltage);
|
||||||
t->variant.device_metrics.channel_utilization,
|
|
||||||
t->variant.device_metrics.battery_level,
|
|
||||||
t->variant.device_metrics.voltage);
|
|
||||||
|
|
||||||
lastMeasurementPacket = packetPool.allocCopy(mp);
|
lastMeasurementPacket = packetPool.allocCopy(mp);
|
||||||
|
|
||||||
@@ -59,10 +55,8 @@ bool DeviceTelemetryModule::sendTelemetry(NodeNum dest, bool phoneOnly)
|
|||||||
t.variant.device_metrics.voltage = powerStatus->getBatteryVoltageMv() / 1000.0;
|
t.variant.device_metrics.voltage = powerStatus->getBatteryVoltageMv() / 1000.0;
|
||||||
|
|
||||||
LOG_INFO("(Sending): air_util_tx=%f, channel_utilization=%f, battery_level=%i, voltage=%f\n",
|
LOG_INFO("(Sending): air_util_tx=%f, channel_utilization=%f, battery_level=%i, voltage=%f\n",
|
||||||
t.variant.device_metrics.air_util_tx,
|
t.variant.device_metrics.air_util_tx, t.variant.device_metrics.channel_utilization,
|
||||||
t.variant.device_metrics.channel_utilization,
|
t.variant.device_metrics.battery_level, t.variant.device_metrics.voltage);
|
||||||
t.variant.device_metrics.battery_level,
|
|
||||||
t.variant.device_metrics.voltage);
|
|
||||||
|
|
||||||
MeshPacket *p = allocDataProtobuf(t);
|
MeshPacket *p = allocDataProtobuf(t);
|
||||||
p->to = dest;
|
p->to = dest;
|
||||||
|
|||||||
@@ -11,8 +11,8 @@ class DeviceTelemetryModule : private concurrency::OSThread, public ProtobufModu
|
|||||||
DeviceTelemetryModule()
|
DeviceTelemetryModule()
|
||||||
: concurrency::OSThread("DeviceTelemetryModule"), ProtobufModule("DeviceTelemetry", PortNum_TELEMETRY_APP, &Telemetry_msg)
|
: concurrency::OSThread("DeviceTelemetryModule"), ProtobufModule("DeviceTelemetry", PortNum_TELEMETRY_APP, &Telemetry_msg)
|
||||||
{
|
{
|
||||||
lastMeasurementPacket = nullptr;
|
lastMeasurementPacket = nullptr;
|
||||||
setIntervalFromNow(10 * 1000);
|
setIntervalFromNow(10 * 1000);
|
||||||
}
|
}
|
||||||
virtual bool wantUIFrame() { return false; }
|
virtual bool wantUIFrame() { return false; }
|
||||||
|
|
||||||
|
|||||||
@@ -9,18 +9,17 @@
|
|||||||
#include "main.h"
|
#include "main.h"
|
||||||
#include <OLEDDisplay.h>
|
#include <OLEDDisplay.h>
|
||||||
#include <OLEDDisplayUi.h>
|
#include <OLEDDisplayUi.h>
|
||||||
#include "MeshService.h"
|
|
||||||
|
|
||||||
// Sensors
|
// Sensors
|
||||||
#include "Sensor/BMP280Sensor.h"
|
|
||||||
#include "Sensor/BME280Sensor.h"
|
#include "Sensor/BME280Sensor.h"
|
||||||
#include "Sensor/BME680Sensor.h"
|
#include "Sensor/BME680Sensor.h"
|
||||||
#include "Sensor/MCP9808Sensor.h"
|
#include "Sensor/BMP280Sensor.h"
|
||||||
#include "Sensor/INA260Sensor.h"
|
|
||||||
#include "Sensor/INA219Sensor.h"
|
#include "Sensor/INA219Sensor.h"
|
||||||
#include "Sensor/SHTC3Sensor.h"
|
#include "Sensor/INA260Sensor.h"
|
||||||
#include "Sensor/LPS22HBSensor.h"
|
#include "Sensor/LPS22HBSensor.h"
|
||||||
|
#include "Sensor/MCP9808Sensor.h"
|
||||||
#include "Sensor/SHT31Sensor.h"
|
#include "Sensor/SHT31Sensor.h"
|
||||||
|
#include "Sensor/SHTC3Sensor.h"
|
||||||
|
|
||||||
BMP280Sensor bmp280Sensor;
|
BMP280Sensor bmp280Sensor;
|
||||||
BME280Sensor bme280Sensor;
|
BME280Sensor bme280Sensor;
|
||||||
@@ -64,8 +63,7 @@ int32_t EnvironmentTelemetryModule::runOnce()
|
|||||||
// moduleConfig.telemetry.environment_screen_enabled = 1;
|
// moduleConfig.telemetry.environment_screen_enabled = 1;
|
||||||
// moduleConfig.telemetry.environment_update_interval = 45;
|
// moduleConfig.telemetry.environment_update_interval = 45;
|
||||||
|
|
||||||
if (!(moduleConfig.telemetry.environment_measurement_enabled ||
|
if (!(moduleConfig.telemetry.environment_measurement_enabled || moduleConfig.telemetry.environment_screen_enabled)) {
|
||||||
moduleConfig.telemetry.environment_screen_enabled)) {
|
|
||||||
// If this module is not enabled, and the user doesn't want the display screen don't waste any OSThread time on it
|
// If this module is not enabled, and the user doesn't want the display screen don't waste any OSThread time on it
|
||||||
return disable();
|
return disable();
|
||||||
}
|
}
|
||||||
@@ -106,7 +104,7 @@ int32_t EnvironmentTelemetryModule::runOnce()
|
|||||||
|
|
||||||
uint32_t now = millis();
|
uint32_t now = millis();
|
||||||
if ((lastSentToMesh == 0 ||
|
if ((lastSentToMesh == 0 ||
|
||||||
(now - lastSentToMesh) >= getConfiguredOrDefaultMs(moduleConfig.telemetry.environment_update_interval)) &&
|
(now - lastSentToMesh) >= getConfiguredOrDefaultMs(moduleConfig.telemetry.environment_update_interval)) &&
|
||||||
airTime->isTxAllowedAirUtil()) {
|
airTime->isTxAllowedAirUtil()) {
|
||||||
sendTelemetry();
|
sendTelemetry();
|
||||||
lastSentToMesh = now;
|
lastSentToMesh = now;
|
||||||
@@ -173,13 +171,15 @@ void EnvironmentTelemetryModule::drawFrame(OLEDDisplay *display, OLEDDisplayUiSt
|
|||||||
}
|
}
|
||||||
display->drawString(x, y += fontHeight(FONT_MEDIUM) - 2, "From: " + String(lastSender) + "(" + String(agoSecs) + "s)");
|
display->drawString(x, y += fontHeight(FONT_MEDIUM) - 2, "From: " + String(lastSender) + "(" + String(agoSecs) + "s)");
|
||||||
display->drawString(x, y += fontHeight(FONT_SMALL) - 2,
|
display->drawString(x, y += fontHeight(FONT_SMALL) - 2,
|
||||||
"Temp/Hum: " + last_temp + " / " + String(lastMeasurement.variant.environment_metrics.relative_humidity, 0) + "%");
|
"Temp/Hum: " + last_temp + " / " +
|
||||||
|
String(lastMeasurement.variant.environment_metrics.relative_humidity, 0) + "%");
|
||||||
if (lastMeasurement.variant.environment_metrics.barometric_pressure != 0)
|
if (lastMeasurement.variant.environment_metrics.barometric_pressure != 0)
|
||||||
display->drawString(x, y += fontHeight(FONT_SMALL),
|
display->drawString(x, y += fontHeight(FONT_SMALL),
|
||||||
"Press: " + String(lastMeasurement.variant.environment_metrics.barometric_pressure, 0) + "hPA");
|
"Press: " + String(lastMeasurement.variant.environment_metrics.barometric_pressure, 0) + "hPA");
|
||||||
if (lastMeasurement.variant.environment_metrics.voltage != 0)
|
if (lastMeasurement.variant.environment_metrics.voltage != 0)
|
||||||
display->drawString(x, y += fontHeight(FONT_SMALL),
|
display->drawString(x, y += fontHeight(FONT_SMALL),
|
||||||
"Volt/Cur: " + String(lastMeasurement.variant.environment_metrics.voltage, 0) + "V / " + String(lastMeasurement.variant.environment_metrics.current, 0) + "mA");
|
"Volt/Cur: " + String(lastMeasurement.variant.environment_metrics.voltage, 0) + "V / " +
|
||||||
|
String(lastMeasurement.variant.environment_metrics.current, 0) + "mA");
|
||||||
}
|
}
|
||||||
|
|
||||||
bool EnvironmentTelemetryModule::handleReceivedProtobuf(const MeshPacket &mp, Telemetry *t)
|
bool EnvironmentTelemetryModule::handleReceivedProtobuf(const MeshPacket &mp, Telemetry *t)
|
||||||
@@ -187,14 +187,11 @@ bool EnvironmentTelemetryModule::handleReceivedProtobuf(const MeshPacket &mp, Te
|
|||||||
if (t->which_variant == Telemetry_environment_metrics_tag) {
|
if (t->which_variant == Telemetry_environment_metrics_tag) {
|
||||||
const char *sender = getSenderShortName(mp);
|
const char *sender = getSenderShortName(mp);
|
||||||
|
|
||||||
LOG_INFO("(Received from %s): barometric_pressure=%f, current=%f, gas_resistance=%f, relative_humidity=%f, temperature=%f, voltage=%f\n",
|
LOG_INFO("(Received from %s): barometric_pressure=%f, current=%f, gas_resistance=%f, relative_humidity=%f, "
|
||||||
sender,
|
"temperature=%f, voltage=%f\n",
|
||||||
t->variant.environment_metrics.barometric_pressure,
|
sender, t->variant.environment_metrics.barometric_pressure, t->variant.environment_metrics.current,
|
||||||
t->variant.environment_metrics.current,
|
t->variant.environment_metrics.gas_resistance, t->variant.environment_metrics.relative_humidity,
|
||||||
t->variant.environment_metrics.gas_resistance,
|
t->variant.environment_metrics.temperature, t->variant.environment_metrics.voltage);
|
||||||
t->variant.environment_metrics.relative_humidity,
|
|
||||||
t->variant.environment_metrics.temperature,
|
|
||||||
t->variant.environment_metrics.voltage);
|
|
||||||
|
|
||||||
lastMeasurementPacket = packetPool.allocCopy(mp);
|
lastMeasurementPacket = packetPool.allocCopy(mp);
|
||||||
}
|
}
|
||||||
@@ -234,13 +231,11 @@ bool EnvironmentTelemetryModule::sendTelemetry(NodeNum dest, bool phoneOnly)
|
|||||||
if (ina260Sensor.hasSensor())
|
if (ina260Sensor.hasSensor())
|
||||||
ina260Sensor.getMetrics(&m);
|
ina260Sensor.getMetrics(&m);
|
||||||
|
|
||||||
LOG_INFO("(Sending): barometric_pressure=%f, current=%f, gas_resistance=%f, relative_humidity=%f, temperature=%f, voltage=%f\n",
|
LOG_INFO(
|
||||||
m.variant.environment_metrics.barometric_pressure,
|
"(Sending): barometric_pressure=%f, current=%f, gas_resistance=%f, relative_humidity=%f, temperature=%f, voltage=%f\n",
|
||||||
m.variant.environment_metrics.current,
|
m.variant.environment_metrics.barometric_pressure, m.variant.environment_metrics.current,
|
||||||
m.variant.environment_metrics.gas_resistance,
|
m.variant.environment_metrics.gas_resistance, m.variant.environment_metrics.relative_humidity,
|
||||||
m.variant.environment_metrics.relative_humidity,
|
m.variant.environment_metrics.temperature, m.variant.environment_metrics.voltage);
|
||||||
m.variant.environment_metrics.temperature,
|
|
||||||
m.variant.environment_metrics.voltage);
|
|
||||||
|
|
||||||
sensor_read_error_count = 0;
|
sensor_read_error_count = 0;
|
||||||
|
|
||||||
|
|||||||
@@ -12,8 +12,8 @@ class EnvironmentTelemetryModule : private concurrency::OSThread, public Protobu
|
|||||||
: concurrency::OSThread("EnvironmentTelemetryModule"),
|
: concurrency::OSThread("EnvironmentTelemetryModule"),
|
||||||
ProtobufModule("EnvironmentTelemetry", PortNum_TELEMETRY_APP, &Telemetry_msg)
|
ProtobufModule("EnvironmentTelemetry", PortNum_TELEMETRY_APP, &Telemetry_msg)
|
||||||
{
|
{
|
||||||
lastMeasurementPacket = nullptr;
|
lastMeasurementPacket = nullptr;
|
||||||
setIntervalFromNow(10 * 1000);
|
setIntervalFromNow(10 * 1000);
|
||||||
}
|
}
|
||||||
virtual bool wantUIFrame() override;
|
virtual bool wantUIFrame() override;
|
||||||
#if !HAS_SCREEN
|
#if !HAS_SCREEN
|
||||||
|
|||||||
@@ -1,35 +1,33 @@
|
|||||||
#include "../mesh/generated/meshtastic/telemetry.pb.h"
|
|
||||||
#include "configuration.h"
|
|
||||||
#include "TelemetrySensor.h"
|
|
||||||
#include "BME280Sensor.h"
|
#include "BME280Sensor.h"
|
||||||
|
#include "../mesh/generated/meshtastic/telemetry.pb.h"
|
||||||
|
#include "TelemetrySensor.h"
|
||||||
|
#include "configuration.h"
|
||||||
#include <Adafruit_BME280.h>
|
#include <Adafruit_BME280.h>
|
||||||
#include <typeinfo>
|
#include <typeinfo>
|
||||||
|
|
||||||
BME280Sensor::BME280Sensor() :
|
BME280Sensor::BME280Sensor() : TelemetrySensor(TelemetrySensorType_BME280, "BME280") {}
|
||||||
TelemetrySensor(TelemetrySensorType_BME280, "BME280")
|
|
||||||
{
|
|
||||||
}
|
|
||||||
|
|
||||||
int32_t BME280Sensor::runOnce() {
|
int32_t BME280Sensor::runOnce()
|
||||||
|
{
|
||||||
LOG_INFO("Init sensor: %s\n", sensorName);
|
LOG_INFO("Init sensor: %s\n", sensorName);
|
||||||
if (!hasSensor()) {
|
if (!hasSensor()) {
|
||||||
return DEFAULT_SENSOR_MINIMUM_WAIT_TIME_BETWEEN_READS;
|
return DEFAULT_SENSOR_MINIMUM_WAIT_TIME_BETWEEN_READS;
|
||||||
}
|
}
|
||||||
status = bme280.begin(nodeTelemetrySensorsMap[sensorType]);
|
status = bme280.begin(nodeTelemetrySensorsMap[sensorType]);
|
||||||
|
|
||||||
bme280.setSampling( Adafruit_BME280::MODE_FORCED,
|
bme280.setSampling(Adafruit_BME280::MODE_FORCED,
|
||||||
Adafruit_BME280::SAMPLING_X1, // Temp. oversampling
|
Adafruit_BME280::SAMPLING_X1, // Temp. oversampling
|
||||||
Adafruit_BME280::SAMPLING_X1, // Pressure oversampling
|
Adafruit_BME280::SAMPLING_X1, // Pressure oversampling
|
||||||
Adafruit_BME280::SAMPLING_X1, // Humidity oversampling
|
Adafruit_BME280::SAMPLING_X1, // Humidity oversampling
|
||||||
Adafruit_BME280::FILTER_OFF,
|
Adafruit_BME280::FILTER_OFF, Adafruit_BME280::STANDBY_MS_1000);
|
||||||
Adafruit_BME280::STANDBY_MS_1000);
|
|
||||||
|
|
||||||
return initI2CSensor();
|
return initI2CSensor();
|
||||||
}
|
}
|
||||||
|
|
||||||
void BME280Sensor::setup() { }
|
void BME280Sensor::setup() {}
|
||||||
|
|
||||||
bool BME280Sensor::getMetrics(Telemetry *measurement) {
|
bool BME280Sensor::getMetrics(Telemetry *measurement)
|
||||||
|
{
|
||||||
LOG_DEBUG("BME280Sensor::getMetrics\n");
|
LOG_DEBUG("BME280Sensor::getMetrics\n");
|
||||||
bme280.takeForcedMeasurement();
|
bme280.takeForcedMeasurement();
|
||||||
measurement->variant.environment_metrics.temperature = bme280.readTemperature();
|
measurement->variant.environment_metrics.temperature = bme280.readTemperature();
|
||||||
|
|||||||
@@ -2,14 +2,15 @@
|
|||||||
#include "TelemetrySensor.h"
|
#include "TelemetrySensor.h"
|
||||||
#include <Adafruit_BME280.h>
|
#include <Adafruit_BME280.h>
|
||||||
|
|
||||||
class BME280Sensor : virtual public TelemetrySensor {
|
class BME280Sensor : virtual public TelemetrySensor
|
||||||
private:
|
{
|
||||||
|
private:
|
||||||
Adafruit_BME280 bme280;
|
Adafruit_BME280 bme280;
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
virtual void setup() override;
|
virtual void setup() override;
|
||||||
|
|
||||||
public:
|
public:
|
||||||
BME280Sensor();
|
BME280Sensor();
|
||||||
virtual int32_t runOnce() override;
|
virtual int32_t runOnce() override;
|
||||||
virtual bool getMetrics(Telemetry *measurement) override;
|
virtual bool getMetrics(Telemetry *measurement) override;
|
||||||
|
|||||||
@@ -1,15 +1,13 @@
|
|||||||
#include "../mesh/generated/meshtastic/telemetry.pb.h"
|
|
||||||
#include "configuration.h"
|
|
||||||
#include "TelemetrySensor.h"
|
|
||||||
#include "BME680Sensor.h"
|
#include "BME680Sensor.h"
|
||||||
|
#include "../mesh/generated/meshtastic/telemetry.pb.h"
|
||||||
|
#include "TelemetrySensor.h"
|
||||||
|
#include "configuration.h"
|
||||||
#include <Adafruit_BME680.h>
|
#include <Adafruit_BME680.h>
|
||||||
|
|
||||||
BME680Sensor::BME680Sensor() :
|
BME680Sensor::BME680Sensor() : TelemetrySensor(TelemetrySensorType_BME680, "BME680") {}
|
||||||
TelemetrySensor(TelemetrySensorType_BME680, "BME680")
|
|
||||||
{
|
|
||||||
}
|
|
||||||
|
|
||||||
int32_t BME680Sensor::runOnce() {
|
int32_t BME680Sensor::runOnce()
|
||||||
|
{
|
||||||
LOG_INFO("Init sensor: %s\n", sensorName);
|
LOG_INFO("Init sensor: %s\n", sensorName);
|
||||||
if (!hasSensor()) {
|
if (!hasSensor()) {
|
||||||
return DEFAULT_SENSOR_MINIMUM_WAIT_TIME_BETWEEN_READS;
|
return DEFAULT_SENSOR_MINIMUM_WAIT_TIME_BETWEEN_READS;
|
||||||
@@ -19,9 +17,10 @@ int32_t BME680Sensor::runOnce() {
|
|||||||
return initI2CSensor();
|
return initI2CSensor();
|
||||||
}
|
}
|
||||||
|
|
||||||
void BME680Sensor::setup() { }
|
void BME680Sensor::setup() {}
|
||||||
|
|
||||||
bool BME680Sensor::getMetrics(Telemetry *measurement) {
|
bool BME680Sensor::getMetrics(Telemetry *measurement)
|
||||||
|
{
|
||||||
bme680.performReading();
|
bme680.performReading();
|
||||||
measurement->variant.environment_metrics.temperature = bme680.temperature;
|
measurement->variant.environment_metrics.temperature = bme680.temperature;
|
||||||
measurement->variant.environment_metrics.relative_humidity = bme680.humidity;
|
measurement->variant.environment_metrics.relative_humidity = bme680.humidity;
|
||||||
|
|||||||
@@ -2,14 +2,15 @@
|
|||||||
#include "TelemetrySensor.h"
|
#include "TelemetrySensor.h"
|
||||||
#include <Adafruit_BME680.h>
|
#include <Adafruit_BME680.h>
|
||||||
|
|
||||||
class BME680Sensor : virtual public TelemetrySensor {
|
class BME680Sensor : virtual public TelemetrySensor
|
||||||
private:
|
{
|
||||||
|
private:
|
||||||
Adafruit_BME680 bme680;
|
Adafruit_BME680 bme680;
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
virtual void setup() override;
|
virtual void setup() override;
|
||||||
|
|
||||||
public:
|
public:
|
||||||
BME680Sensor();
|
BME680Sensor();
|
||||||
virtual int32_t runOnce() override;
|
virtual int32_t runOnce() override;
|
||||||
virtual bool getMetrics(Telemetry *measurement) override;
|
virtual bool getMetrics(Telemetry *measurement) override;
|
||||||
|
|||||||
@@ -1,34 +1,32 @@
|
|||||||
#include "../mesh/generated/meshtastic/telemetry.pb.h"
|
|
||||||
#include "configuration.h"
|
|
||||||
#include "TelemetrySensor.h"
|
|
||||||
#include "BMP280Sensor.h"
|
#include "BMP280Sensor.h"
|
||||||
|
#include "../mesh/generated/meshtastic/telemetry.pb.h"
|
||||||
|
#include "TelemetrySensor.h"
|
||||||
|
#include "configuration.h"
|
||||||
#include <Adafruit_BMP280.h>
|
#include <Adafruit_BMP280.h>
|
||||||
#include <typeinfo>
|
#include <typeinfo>
|
||||||
|
|
||||||
BMP280Sensor::BMP280Sensor() :
|
BMP280Sensor::BMP280Sensor() : TelemetrySensor(TelemetrySensorType_BMP280, "BMP280") {}
|
||||||
TelemetrySensor(TelemetrySensorType_BMP280, "BMP280")
|
|
||||||
{
|
|
||||||
}
|
|
||||||
|
|
||||||
int32_t BMP280Sensor::runOnce() {
|
int32_t BMP280Sensor::runOnce()
|
||||||
|
{
|
||||||
LOG_INFO("Init sensor: %s\n", sensorName);
|
LOG_INFO("Init sensor: %s\n", sensorName);
|
||||||
if (!hasSensor()) {
|
if (!hasSensor()) {
|
||||||
return DEFAULT_SENSOR_MINIMUM_WAIT_TIME_BETWEEN_READS;
|
return DEFAULT_SENSOR_MINIMUM_WAIT_TIME_BETWEEN_READS;
|
||||||
}
|
}
|
||||||
status = bmp280.begin(nodeTelemetrySensorsMap[sensorType]);
|
status = bmp280.begin(nodeTelemetrySensorsMap[sensorType]);
|
||||||
|
|
||||||
bmp280.setSampling( Adafruit_BMP280::MODE_FORCED,
|
bmp280.setSampling(Adafruit_BMP280::MODE_FORCED,
|
||||||
Adafruit_BMP280::SAMPLING_X1, // Temp. oversampling
|
Adafruit_BMP280::SAMPLING_X1, // Temp. oversampling
|
||||||
Adafruit_BMP280::SAMPLING_X1, // Pressure oversampling
|
Adafruit_BMP280::SAMPLING_X1, // Pressure oversampling
|
||||||
Adafruit_BMP280::FILTER_OFF,
|
Adafruit_BMP280::FILTER_OFF, Adafruit_BMP280::STANDBY_MS_1000);
|
||||||
Adafruit_BMP280::STANDBY_MS_1000);
|
|
||||||
|
|
||||||
return initI2CSensor();
|
return initI2CSensor();
|
||||||
}
|
}
|
||||||
|
|
||||||
void BMP280Sensor::setup() { }
|
void BMP280Sensor::setup() {}
|
||||||
|
|
||||||
bool BMP280Sensor::getMetrics(Telemetry *measurement) {
|
bool BMP280Sensor::getMetrics(Telemetry *measurement)
|
||||||
|
{
|
||||||
LOG_DEBUG("BMP280Sensor::getMetrics\n");
|
LOG_DEBUG("BMP280Sensor::getMetrics\n");
|
||||||
bmp280.takeForcedMeasurement();
|
bmp280.takeForcedMeasurement();
|
||||||
measurement->variant.environment_metrics.temperature = bmp280.readTemperature();
|
measurement->variant.environment_metrics.temperature = bmp280.readTemperature();
|
||||||
|
|||||||
@@ -2,14 +2,15 @@
|
|||||||
#include "TelemetrySensor.h"
|
#include "TelemetrySensor.h"
|
||||||
#include <Adafruit_BMP280.h>
|
#include <Adafruit_BMP280.h>
|
||||||
|
|
||||||
class BMP280Sensor : virtual public TelemetrySensor {
|
class BMP280Sensor : virtual public TelemetrySensor
|
||||||
private:
|
{
|
||||||
|
private:
|
||||||
Adafruit_BMP280 bmp280;
|
Adafruit_BMP280 bmp280;
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
virtual void setup() override;
|
virtual void setup() override;
|
||||||
|
|
||||||
public:
|
public:
|
||||||
BMP280Sensor();
|
BMP280Sensor();
|
||||||
virtual int32_t runOnce() override;
|
virtual int32_t runOnce() override;
|
||||||
virtual bool getMetrics(Telemetry *measurement) override;
|
virtual bool getMetrics(Telemetry *measurement) override;
|
||||||
|
|||||||
@@ -1,15 +1,13 @@
|
|||||||
#include "../mesh/generated/meshtastic/telemetry.pb.h"
|
|
||||||
#include "configuration.h"
|
|
||||||
#include "TelemetrySensor.h"
|
|
||||||
#include "INA219Sensor.h"
|
#include "INA219Sensor.h"
|
||||||
|
#include "../mesh/generated/meshtastic/telemetry.pb.h"
|
||||||
|
#include "TelemetrySensor.h"
|
||||||
|
#include "configuration.h"
|
||||||
#include <Adafruit_INA219.h>
|
#include <Adafruit_INA219.h>
|
||||||
|
|
||||||
INA219Sensor::INA219Sensor() :
|
INA219Sensor::INA219Sensor() : TelemetrySensor(TelemetrySensorType_INA219, "INA219") {}
|
||||||
TelemetrySensor(TelemetrySensorType_INA219, "INA219")
|
|
||||||
{
|
|
||||||
}
|
|
||||||
|
|
||||||
int32_t INA219Sensor::runOnce() {
|
int32_t INA219Sensor::runOnce()
|
||||||
|
{
|
||||||
LOG_INFO("Init sensor: %s\n", sensorName);
|
LOG_INFO("Init sensor: %s\n", sensorName);
|
||||||
if (!hasSensor()) {
|
if (!hasSensor()) {
|
||||||
return DEFAULT_SENSOR_MINIMUM_WAIT_TIME_BETWEEN_READS;
|
return DEFAULT_SENSOR_MINIMUM_WAIT_TIME_BETWEEN_READS;
|
||||||
@@ -19,11 +17,10 @@ int32_t INA219Sensor::runOnce() {
|
|||||||
return initI2CSensor();
|
return initI2CSensor();
|
||||||
}
|
}
|
||||||
|
|
||||||
void INA219Sensor::setup()
|
void INA219Sensor::setup() {}
|
||||||
{
|
|
||||||
}
|
|
||||||
|
|
||||||
bool INA219Sensor::getMetrics(Telemetry *measurement) {
|
bool INA219Sensor::getMetrics(Telemetry *measurement)
|
||||||
|
{
|
||||||
measurement->variant.environment_metrics.voltage = ina219.getBusVoltage_V();
|
measurement->variant.environment_metrics.voltage = ina219.getBusVoltage_V();
|
||||||
measurement->variant.environment_metrics.current = ina219.getCurrent_mA();
|
measurement->variant.environment_metrics.current = ina219.getCurrent_mA();
|
||||||
return true;
|
return true;
|
||||||
|
|||||||
@@ -2,15 +2,15 @@
|
|||||||
#include "TelemetrySensor.h"
|
#include "TelemetrySensor.h"
|
||||||
#include <Adafruit_INA219.h>
|
#include <Adafruit_INA219.h>
|
||||||
|
|
||||||
|
class INA219Sensor : virtual public TelemetrySensor
|
||||||
class INA219Sensor : virtual public TelemetrySensor {
|
{
|
||||||
private:
|
private:
|
||||||
Adafruit_INA219 ina219;
|
Adafruit_INA219 ina219;
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
virtual void setup() override;
|
virtual void setup() override;
|
||||||
|
|
||||||
public:
|
public:
|
||||||
INA219Sensor();
|
INA219Sensor();
|
||||||
virtual int32_t runOnce() override;
|
virtual int32_t runOnce() override;
|
||||||
virtual bool getMetrics(Telemetry *measurement) override;
|
virtual bool getMetrics(Telemetry *measurement) override;
|
||||||
|
|||||||
@@ -1,15 +1,13 @@
|
|||||||
#include "../mesh/generated/meshtastic/telemetry.pb.h"
|
|
||||||
#include "configuration.h"
|
|
||||||
#include "TelemetrySensor.h"
|
|
||||||
#include "INA260Sensor.h"
|
#include "INA260Sensor.h"
|
||||||
|
#include "../mesh/generated/meshtastic/telemetry.pb.h"
|
||||||
|
#include "TelemetrySensor.h"
|
||||||
|
#include "configuration.h"
|
||||||
#include <Adafruit_INA260.h>
|
#include <Adafruit_INA260.h>
|
||||||
|
|
||||||
INA260Sensor::INA260Sensor() :
|
INA260Sensor::INA260Sensor() : TelemetrySensor(TelemetrySensorType_INA260, "INA260") {}
|
||||||
TelemetrySensor(TelemetrySensorType_INA260, "INA260")
|
|
||||||
{
|
|
||||||
}
|
|
||||||
|
|
||||||
int32_t INA260Sensor::runOnce() {
|
int32_t INA260Sensor::runOnce()
|
||||||
|
{
|
||||||
LOG_INFO("Init sensor: %s\n", sensorName);
|
LOG_INFO("Init sensor: %s\n", sensorName);
|
||||||
if (!hasSensor()) {
|
if (!hasSensor()) {
|
||||||
return DEFAULT_SENSOR_MINIMUM_WAIT_TIME_BETWEEN_READS;
|
return DEFAULT_SENSOR_MINIMUM_WAIT_TIME_BETWEEN_READS;
|
||||||
@@ -18,11 +16,10 @@ int32_t INA260Sensor::runOnce() {
|
|||||||
return initI2CSensor();
|
return initI2CSensor();
|
||||||
}
|
}
|
||||||
|
|
||||||
void INA260Sensor::setup()
|
void INA260Sensor::setup() {}
|
||||||
{
|
|
||||||
}
|
|
||||||
|
|
||||||
bool INA260Sensor::getMetrics(Telemetry *measurement) {
|
bool INA260Sensor::getMetrics(Telemetry *measurement)
|
||||||
|
{
|
||||||
// mV conversion to V
|
// mV conversion to V
|
||||||
measurement->variant.environment_metrics.voltage = ina260.readBusVoltage() / 1000;
|
measurement->variant.environment_metrics.voltage = ina260.readBusVoltage() / 1000;
|
||||||
measurement->variant.environment_metrics.current = ina260.readCurrent();
|
measurement->variant.environment_metrics.current = ina260.readCurrent();
|
||||||
|
|||||||
@@ -2,15 +2,15 @@
|
|||||||
#include "TelemetrySensor.h"
|
#include "TelemetrySensor.h"
|
||||||
#include <Adafruit_INA260.h>
|
#include <Adafruit_INA260.h>
|
||||||
|
|
||||||
|
class INA260Sensor : virtual public TelemetrySensor
|
||||||
class INA260Sensor : virtual public TelemetrySensor {
|
{
|
||||||
private:
|
private:
|
||||||
Adafruit_INA260 ina260 = Adafruit_INA260();
|
Adafruit_INA260 ina260 = Adafruit_INA260();
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
virtual void setup() override;
|
virtual void setup() override;
|
||||||
|
|
||||||
public:
|
public:
|
||||||
INA260Sensor();
|
INA260Sensor();
|
||||||
virtual int32_t runOnce() override;
|
virtual int32_t runOnce() override;
|
||||||
virtual bool getMetrics(Telemetry *measurement) override;
|
virtual bool getMetrics(Telemetry *measurement) override;
|
||||||
|
|||||||
@@ -1,16 +1,14 @@
|
|||||||
#include "../mesh/generated/meshtastic/telemetry.pb.h"
|
|
||||||
#include "configuration.h"
|
|
||||||
#include "TelemetrySensor.h"
|
|
||||||
#include "LPS22HBSensor.h"
|
#include "LPS22HBSensor.h"
|
||||||
|
#include "../mesh/generated/meshtastic/telemetry.pb.h"
|
||||||
|
#include "TelemetrySensor.h"
|
||||||
|
#include "configuration.h"
|
||||||
#include <Adafruit_LPS2X.h>
|
#include <Adafruit_LPS2X.h>
|
||||||
#include <Adafruit_Sensor.h>
|
#include <Adafruit_Sensor.h>
|
||||||
|
|
||||||
LPS22HBSensor::LPS22HBSensor() :
|
LPS22HBSensor::LPS22HBSensor() : TelemetrySensor(TelemetrySensorType_LPS22, "LPS22HB") {}
|
||||||
TelemetrySensor(TelemetrySensorType_LPS22, "LPS22HB")
|
|
||||||
{
|
|
||||||
}
|
|
||||||
|
|
||||||
int32_t LPS22HBSensor::runOnce() {
|
int32_t LPS22HBSensor::runOnce()
|
||||||
|
{
|
||||||
LOG_INFO("Init sensor: %s\n", sensorName);
|
LOG_INFO("Init sensor: %s\n", sensorName);
|
||||||
if (!hasSensor()) {
|
if (!hasSensor()) {
|
||||||
return DEFAULT_SENSOR_MINIMUM_WAIT_TIME_BETWEEN_READS;
|
return DEFAULT_SENSOR_MINIMUM_WAIT_TIME_BETWEEN_READS;
|
||||||
@@ -24,7 +22,8 @@ void LPS22HBSensor::setup()
|
|||||||
lps22hb.setDataRate(LPS22_RATE_10_HZ);
|
lps22hb.setDataRate(LPS22_RATE_10_HZ);
|
||||||
}
|
}
|
||||||
|
|
||||||
bool LPS22HBSensor::getMetrics(Telemetry *measurement) {
|
bool LPS22HBSensor::getMetrics(Telemetry *measurement)
|
||||||
|
{
|
||||||
sensors_event_t temp;
|
sensors_event_t temp;
|
||||||
sensors_event_t pressure;
|
sensors_event_t pressure;
|
||||||
lps22hb.getEvent(&pressure, &temp);
|
lps22hb.getEvent(&pressure, &temp);
|
||||||
|
|||||||
@@ -3,14 +3,15 @@
|
|||||||
#include <Adafruit_LPS2X.h>
|
#include <Adafruit_LPS2X.h>
|
||||||
#include <Adafruit_Sensor.h>
|
#include <Adafruit_Sensor.h>
|
||||||
|
|
||||||
class LPS22HBSensor : virtual public TelemetrySensor {
|
class LPS22HBSensor : virtual public TelemetrySensor
|
||||||
private:
|
{
|
||||||
|
private:
|
||||||
Adafruit_LPS22 lps22hb;
|
Adafruit_LPS22 lps22hb;
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
virtual void setup() override;
|
virtual void setup() override;
|
||||||
|
|
||||||
public:
|
public:
|
||||||
LPS22HBSensor();
|
LPS22HBSensor();
|
||||||
virtual int32_t runOnce() override;
|
virtual int32_t runOnce() override;
|
||||||
virtual bool getMetrics(Telemetry *measurement) override;
|
virtual bool getMetrics(Telemetry *measurement) override;
|
||||||
|
|||||||
@@ -1,15 +1,13 @@
|
|||||||
#include "../mesh/generated/meshtastic/telemetry.pb.h"
|
|
||||||
#include "configuration.h"
|
|
||||||
#include "TelemetrySensor.h"
|
|
||||||
#include "MCP9808Sensor.h"
|
#include "MCP9808Sensor.h"
|
||||||
|
#include "../mesh/generated/meshtastic/telemetry.pb.h"
|
||||||
|
#include "TelemetrySensor.h"
|
||||||
|
#include "configuration.h"
|
||||||
#include <Adafruit_MCP9808.h>
|
#include <Adafruit_MCP9808.h>
|
||||||
|
|
||||||
MCP9808Sensor::MCP9808Sensor() :
|
MCP9808Sensor::MCP9808Sensor() : TelemetrySensor(TelemetrySensorType_MCP9808, "MCP9808") {}
|
||||||
TelemetrySensor(TelemetrySensorType_MCP9808, "MCP9808")
|
|
||||||
{
|
|
||||||
}
|
|
||||||
|
|
||||||
int32_t MCP9808Sensor::runOnce() {
|
int32_t MCP9808Sensor::runOnce()
|
||||||
|
{
|
||||||
LOG_INFO("Init sensor: %s\n", sensorName);
|
LOG_INFO("Init sensor: %s\n", sensorName);
|
||||||
if (!hasSensor()) {
|
if (!hasSensor()) {
|
||||||
return DEFAULT_SENSOR_MINIMUM_WAIT_TIME_BETWEEN_READS;
|
return DEFAULT_SENSOR_MINIMUM_WAIT_TIME_BETWEEN_READS;
|
||||||
@@ -18,11 +16,13 @@ int32_t MCP9808Sensor::runOnce() {
|
|||||||
return initI2CSensor();
|
return initI2CSensor();
|
||||||
}
|
}
|
||||||
|
|
||||||
void MCP9808Sensor::setup() {
|
void MCP9808Sensor::setup()
|
||||||
|
{
|
||||||
mcp9808.setResolution(2);
|
mcp9808.setResolution(2);
|
||||||
}
|
}
|
||||||
|
|
||||||
bool MCP9808Sensor::getMetrics(Telemetry *measurement) {
|
bool MCP9808Sensor::getMetrics(Telemetry *measurement)
|
||||||
|
{
|
||||||
LOG_DEBUG("MCP9808Sensor::getMetrics\n");
|
LOG_DEBUG("MCP9808Sensor::getMetrics\n");
|
||||||
measurement->variant.environment_metrics.temperature = mcp9808.readTempC();
|
measurement->variant.environment_metrics.temperature = mcp9808.readTempC();
|
||||||
return true;
|
return true;
|
||||||
|
|||||||
@@ -2,14 +2,15 @@
|
|||||||
#include "TelemetrySensor.h"
|
#include "TelemetrySensor.h"
|
||||||
#include <Adafruit_MCP9808.h>
|
#include <Adafruit_MCP9808.h>
|
||||||
|
|
||||||
class MCP9808Sensor : virtual public TelemetrySensor {
|
class MCP9808Sensor : virtual public TelemetrySensor
|
||||||
private:
|
{
|
||||||
|
private:
|
||||||
Adafruit_MCP9808 mcp9808;
|
Adafruit_MCP9808 mcp9808;
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
virtual void setup() override;
|
virtual void setup() override;
|
||||||
|
|
||||||
public:
|
public:
|
||||||
MCP9808Sensor();
|
MCP9808Sensor();
|
||||||
virtual int32_t runOnce() override;
|
virtual int32_t runOnce() override;
|
||||||
virtual bool getMetrics(Telemetry *measurement) override;
|
virtual bool getMetrics(Telemetry *measurement) override;
|
||||||
|
|||||||
@@ -1,15 +1,13 @@
|
|||||||
#include "../mesh/generated/meshtastic/telemetry.pb.h"
|
|
||||||
#include "configuration.h"
|
|
||||||
#include "TelemetrySensor.h"
|
|
||||||
#include "SHT31Sensor.h"
|
#include "SHT31Sensor.h"
|
||||||
|
#include "../mesh/generated/meshtastic/telemetry.pb.h"
|
||||||
|
#include "TelemetrySensor.h"
|
||||||
|
#include "configuration.h"
|
||||||
#include <Adafruit_SHT31.h>
|
#include <Adafruit_SHT31.h>
|
||||||
|
|
||||||
SHT31Sensor::SHT31Sensor() :
|
SHT31Sensor::SHT31Sensor() : TelemetrySensor(TelemetrySensorType_SHT31, "SHT31") {}
|
||||||
TelemetrySensor(TelemetrySensorType_SHT31, "SHT31")
|
|
||||||
{
|
|
||||||
}
|
|
||||||
|
|
||||||
int32_t SHT31Sensor::runOnce() {
|
int32_t SHT31Sensor::runOnce()
|
||||||
|
{
|
||||||
LOG_INFO("Init sensor: %s\n", sensorName);
|
LOG_INFO("Init sensor: %s\n", sensorName);
|
||||||
if (!hasSensor()) {
|
if (!hasSensor()) {
|
||||||
return DEFAULT_SENSOR_MINIMUM_WAIT_TIME_BETWEEN_READS;
|
return DEFAULT_SENSOR_MINIMUM_WAIT_TIME_BETWEEN_READS;
|
||||||
@@ -23,7 +21,8 @@ void SHT31Sensor::setup()
|
|||||||
// Set up oversampling and filter initialization
|
// Set up oversampling and filter initialization
|
||||||
}
|
}
|
||||||
|
|
||||||
bool SHT31Sensor::getMetrics(Telemetry *measurement) {
|
bool SHT31Sensor::getMetrics(Telemetry *measurement)
|
||||||
|
{
|
||||||
measurement->variant.environment_metrics.temperature = sht31.readTemperature();
|
measurement->variant.environment_metrics.temperature = sht31.readTemperature();
|
||||||
measurement->variant.environment_metrics.relative_humidity = sht31.readHumidity();
|
measurement->variant.environment_metrics.relative_humidity = sht31.readHumidity();
|
||||||
|
|
||||||
|
|||||||
@@ -2,14 +2,15 @@
|
|||||||
#include "TelemetrySensor.h"
|
#include "TelemetrySensor.h"
|
||||||
#include <Adafruit_SHT31.h>
|
#include <Adafruit_SHT31.h>
|
||||||
|
|
||||||
class SHT31Sensor : virtual public TelemetrySensor {
|
class SHT31Sensor : virtual public TelemetrySensor
|
||||||
private:
|
{
|
||||||
|
private:
|
||||||
Adafruit_SHT31 sht31 = Adafruit_SHT31();
|
Adafruit_SHT31 sht31 = Adafruit_SHT31();
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
virtual void setup() override;
|
virtual void setup() override;
|
||||||
|
|
||||||
public:
|
public:
|
||||||
SHT31Sensor();
|
SHT31Sensor();
|
||||||
virtual int32_t runOnce() override;
|
virtual int32_t runOnce() override;
|
||||||
virtual bool getMetrics(Telemetry *measurement) override;
|
virtual bool getMetrics(Telemetry *measurement) override;
|
||||||
|
|||||||
@@ -1,15 +1,13 @@
|
|||||||
#include "../mesh/generated/meshtastic/telemetry.pb.h"
|
|
||||||
#include "configuration.h"
|
|
||||||
#include "TelemetrySensor.h"
|
|
||||||
#include "SHTC3Sensor.h"
|
#include "SHTC3Sensor.h"
|
||||||
|
#include "../mesh/generated/meshtastic/telemetry.pb.h"
|
||||||
|
#include "TelemetrySensor.h"
|
||||||
|
#include "configuration.h"
|
||||||
#include <Adafruit_SHTC3.h>
|
#include <Adafruit_SHTC3.h>
|
||||||
|
|
||||||
SHTC3Sensor::SHTC3Sensor() :
|
SHTC3Sensor::SHTC3Sensor() : TelemetrySensor(TelemetrySensorType_SHTC3, "SHTC3") {}
|
||||||
TelemetrySensor(TelemetrySensorType_SHTC3, "SHTC3")
|
|
||||||
{
|
|
||||||
}
|
|
||||||
|
|
||||||
int32_t SHTC3Sensor::runOnce() {
|
int32_t SHTC3Sensor::runOnce()
|
||||||
|
{
|
||||||
LOG_INFO("Init sensor: %s\n", sensorName);
|
LOG_INFO("Init sensor: %s\n", sensorName);
|
||||||
if (!hasSensor()) {
|
if (!hasSensor()) {
|
||||||
return DEFAULT_SENSOR_MINIMUM_WAIT_TIME_BETWEEN_READS;
|
return DEFAULT_SENSOR_MINIMUM_WAIT_TIME_BETWEEN_READS;
|
||||||
@@ -23,7 +21,8 @@ void SHTC3Sensor::setup()
|
|||||||
// Set up oversampling and filter initialization
|
// Set up oversampling and filter initialization
|
||||||
}
|
}
|
||||||
|
|
||||||
bool SHTC3Sensor::getMetrics(Telemetry *measurement) {
|
bool SHTC3Sensor::getMetrics(Telemetry *measurement)
|
||||||
|
{
|
||||||
sensors_event_t humidity, temp;
|
sensors_event_t humidity, temp;
|
||||||
shtc3.getEvent(&humidity, &temp);
|
shtc3.getEvent(&humidity, &temp);
|
||||||
|
|
||||||
|
|||||||
@@ -2,14 +2,15 @@
|
|||||||
#include "TelemetrySensor.h"
|
#include "TelemetrySensor.h"
|
||||||
#include <Adafruit_SHTC3.h>
|
#include <Adafruit_SHTC3.h>
|
||||||
|
|
||||||
class SHTC3Sensor : virtual public TelemetrySensor {
|
class SHTC3Sensor : virtual public TelemetrySensor
|
||||||
private:
|
{
|
||||||
|
private:
|
||||||
Adafruit_SHTC3 shtc3 = Adafruit_SHTC3();
|
Adafruit_SHTC3 shtc3 = Adafruit_SHTC3();
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
virtual void setup() override;
|
virtual void setup() override;
|
||||||
|
|
||||||
public:
|
public:
|
||||||
SHTC3Sensor();
|
SHTC3Sensor();
|
||||||
virtual int32_t runOnce() override;
|
virtual int32_t runOnce() override;
|
||||||
virtual bool getMetrics(Telemetry *measurement) override;
|
virtual bool getMetrics(Telemetry *measurement) override;
|
||||||
|
|||||||
@@ -19,7 +19,8 @@ class TelemetrySensor
|
|||||||
TelemetrySensorType sensorType;
|
TelemetrySensorType sensorType;
|
||||||
unsigned status;
|
unsigned status;
|
||||||
|
|
||||||
int32_t initI2CSensor() {
|
int32_t initI2CSensor()
|
||||||
|
{
|
||||||
if (!status) {
|
if (!status) {
|
||||||
LOG_WARN("Could not connect to detected %s sensor.\n Removing from nodeTelemetrySensorsMap.\n", sensorName);
|
LOG_WARN("Could not connect to detected %s sensor.\n Removing from nodeTelemetrySensorsMap.\n", sensorName);
|
||||||
nodeTelemetrySensorsMap[sensorType] = 0;
|
nodeTelemetrySensorsMap[sensorType] = 0;
|
||||||
@@ -32,9 +33,7 @@ class TelemetrySensor
|
|||||||
virtual void setup();
|
virtual void setup();
|
||||||
|
|
||||||
public:
|
public:
|
||||||
bool hasSensor() {
|
bool hasSensor() { return sensorType < sizeof(nodeTelemetrySensorsMap) && nodeTelemetrySensorsMap[sensorType] > 0; }
|
||||||
return sensorType < sizeof(nodeTelemetrySensorsMap) && nodeTelemetrySensorsMap[sensorType] > 0;
|
|
||||||
}
|
|
||||||
|
|
||||||
virtual int32_t runOnce() = 0;
|
virtual int32_t runOnce() = 0;
|
||||||
virtual bool getMetrics(Telemetry *measurement) = 0;
|
virtual bool getMetrics(Telemetry *measurement) = 0;
|
||||||
|
|||||||
@@ -63,7 +63,8 @@ void StoreForwardModule::populatePSRAM()
|
|||||||
https://learn.upesy.com/en/programmation/psram.html#psram-tab
|
https://learn.upesy.com/en/programmation/psram.html#psram-tab
|
||||||
*/
|
*/
|
||||||
|
|
||||||
LOG_DEBUG("*** Before PSRAM initilization: heap %d/%d PSRAM %d/%d\n", ESP.getFreeHeap(), ESP.getHeapSize(), ESP.getFreePsram(), ESP.getPsramSize());
|
LOG_DEBUG("*** Before PSRAM initilization: heap %d/%d PSRAM %d/%d\n", ESP.getFreeHeap(), ESP.getHeapSize(),
|
||||||
|
ESP.getFreePsram(), ESP.getPsramSize());
|
||||||
|
|
||||||
this->packetHistoryTXQueue =
|
this->packetHistoryTXQueue =
|
||||||
static_cast<PacketHistoryStruct *>(ps_calloc(this->historyReturnMax, sizeof(PacketHistoryStruct)));
|
static_cast<PacketHistoryStruct *>(ps_calloc(this->historyReturnMax, sizeof(PacketHistoryStruct)));
|
||||||
@@ -76,7 +77,8 @@ void StoreForwardModule::populatePSRAM()
|
|||||||
|
|
||||||
this->packetHistory = static_cast<PacketHistoryStruct *>(ps_calloc(numberOfPackets, sizeof(PacketHistoryStruct)));
|
this->packetHistory = static_cast<PacketHistoryStruct *>(ps_calloc(numberOfPackets, sizeof(PacketHistoryStruct)));
|
||||||
|
|
||||||
LOG_DEBUG("*** After PSRAM initilization: heap %d/%d PSRAM %d/%d\n", ESP.getFreeHeap(), ESP.getHeapSize(), ESP.getFreePsram(), ESP.getPsramSize());
|
LOG_DEBUG("*** After PSRAM initilization: heap %d/%d PSRAM %d/%d\n", ESP.getFreeHeap(), ESP.getHeapSize(), ESP.getFreePsram(),
|
||||||
|
ESP.getPsramSize());
|
||||||
LOG_DEBUG("*** numberOfPackets for packetHistory - %u\n", numberOfPackets);
|
LOG_DEBUG("*** numberOfPackets for packetHistory - %u\n", numberOfPackets);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -296,123 +298,125 @@ bool StoreForwardModule::handleReceivedProtobuf(const MeshPacket &mp, StoreAndFo
|
|||||||
requests++;
|
requests++;
|
||||||
|
|
||||||
switch (p->rr) {
|
switch (p->rr) {
|
||||||
case StoreAndForward_RequestResponse_CLIENT_ERROR:
|
case StoreAndForward_RequestResponse_CLIENT_ERROR:
|
||||||
case StoreAndForward_RequestResponse_CLIENT_ABORT:
|
case StoreAndForward_RequestResponse_CLIENT_ABORT:
|
||||||
if(is_server) {
|
if (is_server) {
|
||||||
// stop sending stuff, the client wants to abort or has another error
|
// stop sending stuff, the client wants to abort or has another error
|
||||||
if ((this->busy) && (this->busyTo == getFrom(&mp))) {
|
if ((this->busy) && (this->busyTo == getFrom(&mp))) {
|
||||||
LOG_ERROR("*** Client in ERROR or ABORT requested\n");
|
LOG_ERROR("*** Client in ERROR or ABORT requested\n");
|
||||||
this->packetHistoryTXQueue_index = 0;
|
this->packetHistoryTXQueue_index = 0;
|
||||||
this->busy = false;
|
this->busy = false;
|
||||||
}
|
|
||||||
}
|
}
|
||||||
break;
|
}
|
||||||
|
break;
|
||||||
|
|
||||||
case StoreAndForward_RequestResponse_CLIENT_HISTORY:
|
case StoreAndForward_RequestResponse_CLIENT_HISTORY:
|
||||||
if(is_server) {
|
if (is_server) {
|
||||||
requests_history++;
|
requests_history++;
|
||||||
LOG_INFO("*** Client Request to send HISTORY\n");
|
LOG_INFO("*** Client Request to send HISTORY\n");
|
||||||
// Send the last 60 minutes of messages.
|
// Send the last 60 minutes of messages.
|
||||||
if (this->busy) {
|
if (this->busy) {
|
||||||
storeForwardModule->sendMessage(getFrom(&mp), StoreAndForward_RequestResponse_ROUTER_BUSY);
|
storeForwardModule->sendMessage(getFrom(&mp), StoreAndForward_RequestResponse_ROUTER_BUSY);
|
||||||
LOG_INFO("*** S&F - Busy. Try again shortly.\n");
|
LOG_INFO("*** S&F - Busy. Try again shortly.\n");
|
||||||
|
} else {
|
||||||
|
if ((p->which_variant == StoreAndForward_history_tag) && (p->variant.history.window > 0)) {
|
||||||
|
storeForwardModule->historySend(p->variant.history.window * 60000, getFrom(&mp)); // window is in minutes
|
||||||
} else {
|
} else {
|
||||||
if ((p->which_variant == StoreAndForward_history_tag) && (p->variant.history.window > 0)){
|
storeForwardModule->historySend(historyReturnWindow * 60000, getFrom(&mp)); // defaults to 4 hours
|
||||||
storeForwardModule->historySend(p->variant.history.window * 60000, getFrom(&mp)); // window is in minutes
|
|
||||||
} else {
|
|
||||||
storeForwardModule->historySend(historyReturnWindow * 60000, getFrom(&mp)); // defaults to 4 hours
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
break;
|
}
|
||||||
|
break;
|
||||||
|
|
||||||
case StoreAndForward_RequestResponse_CLIENT_PING:
|
case StoreAndForward_RequestResponse_CLIENT_PING:
|
||||||
if(is_server) {
|
if (is_server) {
|
||||||
LOG_INFO("*** StoreAndForward_RequestResponse_CLIENT_PING\n");
|
LOG_INFO("*** StoreAndForward_RequestResponse_CLIENT_PING\n");
|
||||||
// respond with a ROUTER PONG
|
// respond with a ROUTER PONG
|
||||||
storeForwardModule->sendMessage(getFrom(&mp), StoreAndForward_RequestResponse_ROUTER_PONG);
|
storeForwardModule->sendMessage(getFrom(&mp), StoreAndForward_RequestResponse_ROUTER_PONG);
|
||||||
|
}
|
||||||
|
break;
|
||||||
|
|
||||||
|
case StoreAndForward_RequestResponse_CLIENT_PONG:
|
||||||
|
if (is_server) {
|
||||||
|
LOG_INFO("*** StoreAndForward_RequestResponse_CLIENT_PONG\n");
|
||||||
|
// The Client is alive, update NodeDB
|
||||||
|
nodeDB.updateFrom(mp);
|
||||||
|
}
|
||||||
|
break;
|
||||||
|
|
||||||
|
case StoreAndForward_RequestResponse_CLIENT_STATS:
|
||||||
|
if (is_server) {
|
||||||
|
LOG_INFO("*** Client Request to send STATS\n");
|
||||||
|
if (this->busy) {
|
||||||
|
storeForwardModule->sendMessage(getFrom(&mp), StoreAndForward_RequestResponse_ROUTER_BUSY);
|
||||||
|
LOG_INFO("*** S&F - Busy. Try again shortly.\n");
|
||||||
|
} else {
|
||||||
|
storeForwardModule->statsSend(getFrom(&mp));
|
||||||
}
|
}
|
||||||
break;
|
}
|
||||||
|
break;
|
||||||
|
|
||||||
case StoreAndForward_RequestResponse_CLIENT_PONG:
|
case StoreAndForward_RequestResponse_ROUTER_ERROR:
|
||||||
if(is_server) {
|
case StoreAndForward_RequestResponse_ROUTER_BUSY:
|
||||||
LOG_INFO("*** StoreAndForward_RequestResponse_CLIENT_PONG\n");
|
if (is_client) {
|
||||||
// The Client is alive, update NodeDB
|
LOG_DEBUG("*** StoreAndForward_RequestResponse_ROUTER_BUSY\n");
|
||||||
nodeDB.updateFrom(mp);
|
// retry in messages_saved * packetTimeMax ms
|
||||||
|
retry_delay =
|
||||||
|
millis() + packetHistoryCurrent * packetTimeMax * (StoreAndForward_RequestResponse_ROUTER_ERROR ? 2 : 1);
|
||||||
|
}
|
||||||
|
break;
|
||||||
|
|
||||||
|
case StoreAndForward_RequestResponse_ROUTER_PONG:
|
||||||
|
// A router responded, this is equal to receiving a heartbeat
|
||||||
|
case StoreAndForward_RequestResponse_ROUTER_HEARTBEAT:
|
||||||
|
if (is_client) {
|
||||||
|
// register heartbeat and interval
|
||||||
|
if (p->which_variant == StoreAndForward_heartbeat_tag) {
|
||||||
|
heartbeatInterval = p->variant.heartbeat.period;
|
||||||
}
|
}
|
||||||
break;
|
lastHeartbeat = millis();
|
||||||
|
LOG_INFO("*** StoreAndForward Heartbeat received\n");
|
||||||
|
}
|
||||||
|
break;
|
||||||
|
|
||||||
case StoreAndForward_RequestResponse_CLIENT_STATS:
|
case StoreAndForward_RequestResponse_ROUTER_PING:
|
||||||
if(is_server) {
|
if (is_client) {
|
||||||
LOG_INFO("*** Client Request to send STATS\n");
|
LOG_DEBUG("*** StoreAndForward_RequestResponse_ROUTER_PING\n");
|
||||||
if (this->busy) {
|
// respond with a CLIENT PONG
|
||||||
storeForwardModule->sendMessage(getFrom(&mp), StoreAndForward_RequestResponse_ROUTER_BUSY);
|
storeForwardModule->sendMessage(getFrom(&mp), StoreAndForward_RequestResponse_CLIENT_PONG);
|
||||||
LOG_INFO("*** S&F - Busy. Try again shortly.\n");
|
}
|
||||||
} else {
|
break;
|
||||||
storeForwardModule->statsSend(getFrom(&mp));
|
|
||||||
}
|
case StoreAndForward_RequestResponse_ROUTER_STATS:
|
||||||
|
if (is_client) {
|
||||||
|
LOG_DEBUG("*** Router Response STATS\n");
|
||||||
|
// These fields only have informational purpose on a client. Fill them to consume later.
|
||||||
|
if (p->which_variant == StoreAndForward_stats_tag) {
|
||||||
|
this->packetHistoryMax = p->variant.stats.messages_total;
|
||||||
|
this->packetHistoryCurrent = p->variant.stats.messages_saved;
|
||||||
|
this->records = p->variant.stats.messages_max;
|
||||||
|
this->requests = p->variant.stats.requests;
|
||||||
|
this->requests_history = p->variant.stats.requests_history;
|
||||||
|
this->heartbeat = p->variant.stats.heartbeat;
|
||||||
|
this->historyReturnMax = p->variant.stats.return_max;
|
||||||
|
this->historyReturnWindow = p->variant.stats.return_window;
|
||||||
}
|
}
|
||||||
break;
|
}
|
||||||
|
break;
|
||||||
|
|
||||||
case StoreAndForward_RequestResponse_ROUTER_ERROR:
|
case StoreAndForward_RequestResponse_ROUTER_HISTORY:
|
||||||
case StoreAndForward_RequestResponse_ROUTER_BUSY:
|
if (is_client) {
|
||||||
if(is_client) {
|
// These fields only have informational purpose on a client. Fill them to consume later.
|
||||||
LOG_DEBUG("*** StoreAndForward_RequestResponse_ROUTER_BUSY\n");
|
if (p->which_variant == StoreAndForward_history_tag) {
|
||||||
// retry in messages_saved * packetTimeMax ms
|
this->historyReturnWindow = p->variant.history.window / 60000;
|
||||||
retry_delay = millis() + packetHistoryCurrent * packetTimeMax * (StoreAndForward_RequestResponse_ROUTER_ERROR ? 2 : 1);
|
LOG_INFO("*** Router Response HISTORY - Sending %d messages from last %d minutes\n",
|
||||||
|
p->variant.history.history_messages, this->historyReturnWindow);
|
||||||
}
|
}
|
||||||
break;
|
}
|
||||||
|
break;
|
||||||
|
|
||||||
case StoreAndForward_RequestResponse_ROUTER_PONG:
|
default:
|
||||||
// A router responded, this is equal to receiving a heartbeat
|
assert(0); // unexpected state
|
||||||
case StoreAndForward_RequestResponse_ROUTER_HEARTBEAT:
|
|
||||||
if(is_client) {
|
|
||||||
// register heartbeat and interval
|
|
||||||
if (p->which_variant == StoreAndForward_heartbeat_tag) {
|
|
||||||
heartbeatInterval = p->variant.heartbeat.period;
|
|
||||||
}
|
|
||||||
lastHeartbeat = millis();
|
|
||||||
LOG_INFO("*** StoreAndForward Heartbeat received\n");
|
|
||||||
}
|
|
||||||
break;
|
|
||||||
|
|
||||||
case StoreAndForward_RequestResponse_ROUTER_PING:
|
|
||||||
if(is_client) {
|
|
||||||
LOG_DEBUG("*** StoreAndForward_RequestResponse_ROUTER_PING\n");
|
|
||||||
// respond with a CLIENT PONG
|
|
||||||
storeForwardModule->sendMessage(getFrom(&mp), StoreAndForward_RequestResponse_CLIENT_PONG);
|
|
||||||
}
|
|
||||||
break;
|
|
||||||
|
|
||||||
case StoreAndForward_RequestResponse_ROUTER_STATS:
|
|
||||||
if(is_client) {
|
|
||||||
LOG_DEBUG("*** Router Response STATS\n");
|
|
||||||
// These fields only have informational purpose on a client. Fill them to consume later.
|
|
||||||
if (p->which_variant == StoreAndForward_stats_tag) {
|
|
||||||
this->packetHistoryMax = p->variant.stats.messages_total;
|
|
||||||
this->packetHistoryCurrent = p->variant.stats.messages_saved;
|
|
||||||
this->records = p->variant.stats.messages_max;
|
|
||||||
this->requests = p->variant.stats.requests;
|
|
||||||
this->requests_history = p->variant.stats.requests_history;
|
|
||||||
this->heartbeat = p->variant.stats.heartbeat;
|
|
||||||
this->historyReturnMax = p->variant.stats.return_max;
|
|
||||||
this->historyReturnWindow = p->variant.stats.return_window;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
break;
|
|
||||||
|
|
||||||
case StoreAndForward_RequestResponse_ROUTER_HISTORY:
|
|
||||||
if(is_client) {
|
|
||||||
// These fields only have informational purpose on a client. Fill them to consume later.
|
|
||||||
if (p->which_variant == StoreAndForward_history_tag) {
|
|
||||||
this->historyReturnWindow = p->variant.history.window / 60000;
|
|
||||||
LOG_INFO("*** Router Response HISTORY - Sending %d messages from last %d minutes\n", p->variant.history.history_messages, this->historyReturnWindow);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
break;
|
|
||||||
|
|
||||||
default:
|
|
||||||
assert(0); // unexpected state
|
|
||||||
}
|
}
|
||||||
return true; // There's no need for others to look at this message.
|
return true; // There's no need for others to look at this message.
|
||||||
}
|
}
|
||||||
@@ -437,7 +441,8 @@ StoreForwardModule::StoreForwardModule()
|
|||||||
if (moduleConfig.store_forward.enabled) {
|
if (moduleConfig.store_forward.enabled) {
|
||||||
|
|
||||||
// Router
|
// Router
|
||||||
if ((config.device.role == Config_DeviceConfig_Role_ROUTER) || (config.device.role == Config_DeviceConfig_Role_ROUTER_CLIENT)) {
|
if ((config.device.role == Config_DeviceConfig_Role_ROUTER) ||
|
||||||
|
(config.device.role == Config_DeviceConfig_Role_ROUTER_CLIENT)) {
|
||||||
LOG_INFO("*** Initializing Store & Forward Module in Router mode\n");
|
LOG_INFO("*** Initializing Store & Forward Module in Router mode\n");
|
||||||
if (ESP.getPsramSize() > 0) {
|
if (ESP.getPsramSize() > 0) {
|
||||||
if (ESP.getFreePsram() >= 1024 * 1024) {
|
if (ESP.getFreePsram() >= 1024 * 1024) {
|
||||||
@@ -474,7 +479,8 @@ StoreForwardModule::StoreForwardModule()
|
|||||||
|
|
||||||
// Client
|
// Client
|
||||||
}
|
}
|
||||||
if ((config.device.role == Config_DeviceConfig_Role_CLIENT) || (config.device.role == Config_DeviceConfig_Role_ROUTER_CLIENT)) {
|
if ((config.device.role == Config_DeviceConfig_Role_CLIENT) ||
|
||||||
|
(config.device.role == Config_DeviceConfig_Role_ROUTER_CLIENT)) {
|
||||||
is_client = true;
|
is_client = true;
|
||||||
LOG_INFO("*** Initializing Store & Forward Module in Client mode\n");
|
LOG_INFO("*** Initializing Store & Forward Module in Client mode\n");
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -66,12 +66,12 @@ class StoreForwardModule : private concurrency::OSThread, public ProtobufModule<
|
|||||||
*/
|
*/
|
||||||
virtual bool wantPacket(const MeshPacket *p) override
|
virtual bool wantPacket(const MeshPacket *p) override
|
||||||
{
|
{
|
||||||
switch(p->decoded.portnum) {
|
switch (p->decoded.portnum) {
|
||||||
case PortNum_TEXT_MESSAGE_APP:
|
case PortNum_TEXT_MESSAGE_APP:
|
||||||
case PortNum_STORE_FORWARD_APP:
|
case PortNum_STORE_FORWARD_APP:
|
||||||
return true;
|
return true;
|
||||||
default:
|
default:
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -79,10 +79,10 @@ class StoreForwardModule : private concurrency::OSThread, public ProtobufModule<
|
|||||||
void populatePSRAM();
|
void populatePSRAM();
|
||||||
|
|
||||||
// S&F Defaults
|
// S&F Defaults
|
||||||
uint32_t historyReturnMax = 250; // 250 records
|
uint32_t historyReturnMax = 250; // 250 records
|
||||||
uint32_t historyReturnWindow = 240; // 4 hours
|
uint32_t historyReturnWindow = 240; // 4 hours
|
||||||
uint32_t records = 0; // Calculated
|
uint32_t records = 0; // Calculated
|
||||||
bool heartbeat = false; // No heartbeat.
|
bool heartbeat = false; // No heartbeat.
|
||||||
|
|
||||||
// stats
|
// stats
|
||||||
uint32_t requests = 0;
|
uint32_t requests = 0;
|
||||||
@@ -100,7 +100,6 @@ class StoreForwardModule : private concurrency::OSThread, public ProtobufModule<
|
|||||||
*/
|
*/
|
||||||
virtual ProcessMessage handleReceived(const MeshPacket &mp) override;
|
virtual ProcessMessage handleReceived(const MeshPacket &mp) override;
|
||||||
virtual bool handleReceivedProtobuf(const MeshPacket &mp, StoreAndForward *p);
|
virtual bool handleReceivedProtobuf(const MeshPacket &mp, StoreAndForward *p);
|
||||||
|
|
||||||
};
|
};
|
||||||
|
|
||||||
extern StoreForwardModule *storeForwardModule;
|
extern StoreForwardModule *storeForwardModule;
|
||||||
|
|||||||
@@ -12,8 +12,8 @@
|
|||||||
#if HAS_WIFI
|
#if HAS_WIFI
|
||||||
#include <WiFi.h>
|
#include <WiFi.h>
|
||||||
#endif
|
#endif
|
||||||
#include <assert.h>
|
|
||||||
#include "mqtt/JSON.h"
|
#include "mqtt/JSON.h"
|
||||||
|
#include <assert.h>
|
||||||
|
|
||||||
MQTT *mqtt;
|
MQTT *mqtt;
|
||||||
|
|
||||||
@@ -55,11 +55,15 @@ void MQTT::onPublish(char *topic, byte *payload, unsigned int length)
|
|||||||
}
|
}
|
||||||
LOG_DEBUG("Looking for Channel name: %s\n", ptr);
|
LOG_DEBUG("Looking for Channel name: %s\n", ptr);
|
||||||
Channel sendChannel = channels.getByName(ptr);
|
Channel sendChannel = channels.getByName(ptr);
|
||||||
LOG_DEBUG("Found Channel name: %s (Index %d)\n", channels.getGlobalId(sendChannel.settings.channel_num), sendChannel.settings.channel_num);
|
LOG_DEBUG("Found Channel name: %s (Index %d)\n", channels.getGlobalId(sendChannel.settings.channel_num),
|
||||||
|
sendChannel.settings.channel_num);
|
||||||
|
|
||||||
if ((json.find("sender") != json.end()) && (json.find("payload") != json.end()) && (json.find("type") != json.end()) && json["type"]->IsString() && (json["type"]->AsString().compare("sendtext") == 0)) {
|
if ((json.find("sender") != json.end()) && (json.find("payload") != json.end()) &&
|
||||||
|
(json.find("type") != json.end()) && json["type"]->IsString() &&
|
||||||
|
(json["type"]->AsString().compare("sendtext") == 0)) {
|
||||||
// this is a valid envelope
|
// this is a valid envelope
|
||||||
if (json["payload"]->IsString() && json["type"]->IsString() && (json["sender"]->AsString().compare(owner.id) != 0)) {
|
if (json["payload"]->IsString() && json["type"]->IsString() &&
|
||||||
|
(json["sender"]->AsString().compare(owner.id) != 0)) {
|
||||||
std::string jsonPayloadStr = json["payload"]->AsString();
|
std::string jsonPayloadStr = json["payload"]->AsString();
|
||||||
LOG_INFO("JSON payload %s, length %u\n", jsonPayloadStr.c_str(), jsonPayloadStr.length());
|
LOG_INFO("JSON payload %s, length %u\n", jsonPayloadStr.c_str(), jsonPayloadStr.length());
|
||||||
|
|
||||||
@@ -77,16 +81,20 @@ void MQTT::onPublish(char *topic, byte *payload, unsigned int length)
|
|||||||
LOG_WARN("Received MQTT json payload too long, dropping\n");
|
LOG_WARN("Received MQTT json payload too long, dropping\n");
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
LOG_WARN("Received MQTT json payload on channel %s, but downlink is disabled, dropping\n", sendChannel.settings.name);
|
LOG_WARN("Received MQTT json payload on channel %s, but downlink is disabled, dropping\n",
|
||||||
|
sendChannel.settings.name);
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
LOG_DEBUG("JSON Ignoring downlink message we originally sent.\n");
|
LOG_DEBUG("JSON Ignoring downlink message we originally sent.\n");
|
||||||
}
|
}
|
||||||
} else if ((json.find("sender") != json.end()) && (json.find("payload") != json.end()) && (json.find("type") != json.end()) && json["type"]->IsString() && (json["type"]->AsString().compare("sendposition") == 0)) {
|
} else if ((json.find("sender") != json.end()) && (json.find("payload") != json.end()) &&
|
||||||
//invent the "sendposition" type for a valid envelope
|
(json.find("type") != json.end()) && json["type"]->IsString() &&
|
||||||
if (json["payload"]->IsObject() && json["type"]->IsString() && (json["sender"]->AsString().compare(owner.id) != 0)) {
|
(json["type"]->AsString().compare("sendposition") == 0)) {
|
||||||
|
// invent the "sendposition" type for a valid envelope
|
||||||
|
if (json["payload"]->IsObject() && json["type"]->IsString() &&
|
||||||
|
(json["sender"]->AsString().compare(owner.id) != 0)) {
|
||||||
JSONObject posit;
|
JSONObject posit;
|
||||||
posit = json["payload"]->AsObject(); //get nested JSON Position
|
posit = json["payload"]->AsObject(); // get nested JSON Position
|
||||||
Position pos = Position_init_default;
|
Position pos = Position_init_default;
|
||||||
pos.latitude_i = posit["latitude_i"]->AsNumber();
|
pos.latitude_i = posit["latitude_i"]->AsNumber();
|
||||||
pos.longitude_i = posit["longitude_i"]->AsNumber();
|
pos.longitude_i = posit["longitude_i"]->AsNumber();
|
||||||
@@ -98,15 +106,17 @@ void MQTT::onPublish(char *topic, byte *payload, unsigned int length)
|
|||||||
p->decoded.portnum = PortNum_POSITION_APP;
|
p->decoded.portnum = PortNum_POSITION_APP;
|
||||||
p->channel = sendChannel.settings.channel_num;
|
p->channel = sendChannel.settings.channel_num;
|
||||||
if (sendChannel.settings.downlink_enabled) {
|
if (sendChannel.settings.downlink_enabled) {
|
||||||
p->decoded.payload.size = pb_encode_to_bytes(p->decoded.payload.bytes, sizeof(p->decoded.payload.bytes), &Position_msg, &pos); //make the Data protobuf from position
|
p->decoded.payload.size = pb_encode_to_bytes(p->decoded.payload.bytes, sizeof(p->decoded.payload.bytes),
|
||||||
|
&Position_msg, &pos); // make the Data protobuf from position
|
||||||
service.sendToMesh(p, RX_SRC_LOCAL);
|
service.sendToMesh(p, RX_SRC_LOCAL);
|
||||||
} else {
|
} else {
|
||||||
LOG_WARN("Received MQTT json payload on channel %s, but downlink is disabled, dropping\n", sendChannel.settings.name);
|
LOG_WARN("Received MQTT json payload on channel %s, but downlink is disabled, dropping\n",
|
||||||
|
sendChannel.settings.name);
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
LOG_DEBUG("JSON Ignoring downlink message we originally sent.\n");
|
LOG_DEBUG("JSON Ignoring downlink message we originally sent.\n");
|
||||||
}
|
}
|
||||||
} else{
|
} else {
|
||||||
LOG_ERROR("JSON Received payload on MQTT but not a valid envelope\n");
|
LOG_ERROR("JSON Received payload on MQTT but not a valid envelope\n");
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
@@ -118,7 +128,7 @@ void MQTT::onPublish(char *topic, byte *payload, unsigned int length)
|
|||||||
if (!pb_decode_from_bytes(payload, length, &ServiceEnvelope_msg, &e)) {
|
if (!pb_decode_from_bytes(payload, length, &ServiceEnvelope_msg, &e)) {
|
||||||
LOG_ERROR("Invalid MQTT service envelope, topic %s, len %u!\n", topic, length);
|
LOG_ERROR("Invalid MQTT service envelope, topic %s, len %u!\n", topic, length);
|
||||||
return;
|
return;
|
||||||
}else {
|
} else {
|
||||||
if (strcmp(e.gateway_id, owner.id) == 0)
|
if (strcmp(e.gateway_id, owner.id) == 0)
|
||||||
LOG_INFO("Ignoring downlink message we originally sent.\n");
|
LOG_INFO("Ignoring downlink message we originally sent.\n");
|
||||||
else {
|
else {
|
||||||
@@ -148,7 +158,7 @@ void mqttInit()
|
|||||||
|
|
||||||
MQTT::MQTT() : concurrency::OSThread("mqtt"), pubSub(mqttClient), mqttQueue(MAX_MQTT_QUEUE)
|
MQTT::MQTT() : concurrency::OSThread("mqtt"), pubSub(mqttClient), mqttQueue(MAX_MQTT_QUEUE)
|
||||||
{
|
{
|
||||||
if(moduleConfig.mqtt.enabled) {
|
if (moduleConfig.mqtt.enabled) {
|
||||||
|
|
||||||
assert(!mqtt);
|
assert(!mqtt);
|
||||||
mqtt = this;
|
mqtt = this;
|
||||||
@@ -192,7 +202,8 @@ void MQTT::reconnect()
|
|||||||
pubSub.setServer(serverAddr, serverPort);
|
pubSub.setServer(serverAddr, serverPort);
|
||||||
pubSub.setBufferSize(512);
|
pubSub.setBufferSize(512);
|
||||||
|
|
||||||
LOG_INFO("Connecting to MQTT server %s, port: %d, username: %s, password: %s\n", serverAddr, serverPort, mqttUsername, mqttPassword);
|
LOG_INFO("Connecting to MQTT server %s, port: %d, username: %s, password: %s\n", serverAddr, serverPort, mqttUsername,
|
||||||
|
mqttPassword);
|
||||||
auto myStatus = (statusTopic + owner.id);
|
auto myStatus = (statusTopic + owner.id);
|
||||||
bool connected = pubSub.connect(owner.id, mqttUsername, mqttPassword, myStatus.c_str(), 1, true, "offline");
|
bool connected = pubSub.connect(owner.id, mqttUsername, mqttPassword, myStatus.c_str(), 1, true, "offline");
|
||||||
if (connected) {
|
if (connected) {
|
||||||
@@ -208,7 +219,7 @@ void MQTT::reconnect()
|
|||||||
sendSubscriptions();
|
sendSubscriptions();
|
||||||
} else {
|
} else {
|
||||||
#if HAS_WIFI && !defined(ARCH_PORTDUINO)
|
#if HAS_WIFI && !defined(ARCH_PORTDUINO)
|
||||||
LOG_ERROR("Failed to contact MQTT server (%d/5)...\n",reconnectCount + 1);
|
LOG_ERROR("Failed to contact MQTT server (%d/5)...\n", reconnectCount + 1);
|
||||||
if (reconnectCount >= 4) {
|
if (reconnectCount >= 4) {
|
||||||
needReconnect = true;
|
needReconnect = true;
|
||||||
wifiReconnect->setIntervalFromNow(0);
|
wifiReconnect->setIntervalFromNow(0);
|
||||||
@@ -267,7 +278,7 @@ bool MQTT::wantsLink() const
|
|||||||
|
|
||||||
int32_t MQTT::runOnce()
|
int32_t MQTT::runOnce()
|
||||||
{
|
{
|
||||||
if(!moduleConfig.mqtt.enabled) {
|
if (!moduleConfig.mqtt.enabled) {
|
||||||
return disable();
|
return disable();
|
||||||
}
|
}
|
||||||
bool wantConnection = wantsLink();
|
bool wantConnection = wantsLink();
|
||||||
@@ -277,7 +288,8 @@ int32_t MQTT::runOnce()
|
|||||||
if (wantConnection) {
|
if (wantConnection) {
|
||||||
reconnect();
|
reconnect();
|
||||||
|
|
||||||
// If we succeeded, empty the queue one by one and start reading rapidly, else try again in 30 seconds (TCP connections are EXPENSIVE so try rarely)
|
// If we succeeded, empty the queue one by one and start reading rapidly, else try again in 30 seconds (TCP
|
||||||
|
// connections are EXPENSIVE so try rarely)
|
||||||
if (pubSub.connected()) {
|
if (pubSub.connected()) {
|
||||||
if (!mqttQueue.isEmpty()) {
|
if (!mqttQueue.isEmpty()) {
|
||||||
// FIXME - this size calculation is super sloppy, but it will go away once we dynamically alloc meshpackets
|
// FIXME - this size calculation is super sloppy, but it will go away once we dynamically alloc meshpackets
|
||||||
@@ -295,7 +307,8 @@ int32_t MQTT::runOnce()
|
|||||||
auto jsonString = this->downstreamPacketToJson(env->packet);
|
auto jsonString = this->downstreamPacketToJson(env->packet);
|
||||||
if (jsonString.length() != 0) {
|
if (jsonString.length() != 0) {
|
||||||
String topicJson = jsonTopic + env->channel_id + "/" + owner.id;
|
String topicJson = jsonTopic + env->channel_id + "/" + owner.id;
|
||||||
LOG_INFO("JSON publish message to %s, %u bytes: %s\n", topicJson.c_str(), jsonString.length(), jsonString.c_str());
|
LOG_INFO("JSON publish message to %s, %u bytes: %s\n", topicJson.c_str(), jsonString.length(),
|
||||||
|
jsonString.c_str());
|
||||||
pubSub.publish(topicJson.c_str(), jsonString.c_str(), false);
|
pubSub.publish(topicJson.c_str(), jsonString.c_str(), false);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -348,7 +361,8 @@ void MQTT::onSend(const MeshPacket &mp, ChannelIndex chIndex)
|
|||||||
auto jsonString = this->downstreamPacketToJson((MeshPacket *)&mp);
|
auto jsonString = this->downstreamPacketToJson((MeshPacket *)&mp);
|
||||||
if (jsonString.length() != 0) {
|
if (jsonString.length() != 0) {
|
||||||
String topicJson = jsonTopic + channelId + "/" + owner.id;
|
String topicJson = jsonTopic + channelId + "/" + owner.id;
|
||||||
LOG_INFO("JSON publish message to %s, %u bytes: %s\n", topicJson.c_str(), jsonString.length(), jsonString.c_str());
|
LOG_INFO("JSON publish message to %s, %u bytes: %s\n", topicJson.c_str(), jsonString.length(),
|
||||||
|
jsonString.c_str());
|
||||||
pubSub.publish(topicJson.c_str(), jsonString.c_str(), false);
|
pubSub.publish(topicJson.c_str(), jsonString.c_str(), false);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -453,11 +467,17 @@ std::string MQTT::downstreamPacketToJson(MeshPacket *mp)
|
|||||||
memset(&scratch, 0, sizeof(scratch));
|
memset(&scratch, 0, sizeof(scratch));
|
||||||
if (pb_decode_from_bytes(mp->decoded.payload.bytes, mp->decoded.payload.size, &Position_msg, &scratch)) {
|
if (pb_decode_from_bytes(mp->decoded.payload.bytes, mp->decoded.payload.size, &Position_msg, &scratch)) {
|
||||||
decoded = &scratch;
|
decoded = &scratch;
|
||||||
if((int)decoded->time){msgPayload["time"] = new JSONValue((int)decoded->time);}
|
if ((int)decoded->time) {
|
||||||
if ((int)decoded->timestamp){msgPayload["timestamp"] = new JSONValue((int)decoded->timestamp);}
|
msgPayload["time"] = new JSONValue((int)decoded->time);
|
||||||
|
}
|
||||||
|
if ((int)decoded->timestamp) {
|
||||||
|
msgPayload["timestamp"] = new JSONValue((int)decoded->timestamp);
|
||||||
|
}
|
||||||
msgPayload["latitude_i"] = new JSONValue((int)decoded->latitude_i);
|
msgPayload["latitude_i"] = new JSONValue((int)decoded->latitude_i);
|
||||||
msgPayload["longitude_i"] = new JSONValue((int)decoded->longitude_i);
|
msgPayload["longitude_i"] = new JSONValue((int)decoded->longitude_i);
|
||||||
if((int)decoded->altitude){msgPayload["altitude"] = new JSONValue((int)decoded->altitude);}
|
if ((int)decoded->altitude) {
|
||||||
|
msgPayload["altitude"] = new JSONValue((int)decoded->altitude);
|
||||||
|
}
|
||||||
jsonObj["payload"] = new JSONValue(msgPayload);
|
jsonObj["payload"] = new JSONValue(msgPayload);
|
||||||
} else {
|
} else {
|
||||||
LOG_ERROR("Error decoding protobuf for position message!\n");
|
LOG_ERROR("Error decoding protobuf for position message!\n");
|
||||||
|
|||||||
252
src/xmodem.cpp
252
src/xmodem.cpp
@@ -36,14 +36,14 @@ XModemAdapter xModem;
|
|||||||
|
|
||||||
XModemAdapter::XModemAdapter()
|
XModemAdapter::XModemAdapter()
|
||||||
{
|
{
|
||||||
xmodemStore = (XModem*)malloc(XModem_size);
|
xmodemStore = (XModem *)malloc(XModem_size);
|
||||||
}
|
}
|
||||||
|
|
||||||
unsigned short XModemAdapter::crc16_ccitt(const pb_byte_t *buffer, int length)
|
unsigned short XModemAdapter::crc16_ccitt(const pb_byte_t *buffer, int length)
|
||||||
{
|
{
|
||||||
unsigned short crc16 = 0;
|
unsigned short crc16 = 0;
|
||||||
while(length != 0) {
|
while (length != 0) {
|
||||||
crc16 = (unsigned char)(crc16 >> 8) | (crc16 << 8);
|
crc16 = (unsigned char)(crc16 >> 8) | (crc16 << 8);
|
||||||
crc16 ^= *buffer;
|
crc16 ^= *buffer;
|
||||||
crc16 ^= (unsigned char)(crc16 & 0xff) >> 4;
|
crc16 ^= (unsigned char)(crc16 & 0xff) >> 4;
|
||||||
crc16 ^= (crc16 << 8) << 4;
|
crc16 ^= (crc16 << 8) << 4;
|
||||||
@@ -64,7 +64,8 @@ int XModemAdapter::check(const pb_byte_t *buf, int sz, unsigned short tcrc)
|
|||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
void XModemAdapter::sendControl(XModem_Control c) {
|
void XModemAdapter::sendControl(XModem_Control c)
|
||||||
|
{
|
||||||
memset(xmodemStore, 0, XModem_size);
|
memset(xmodemStore, 0, XModem_size);
|
||||||
xmodemStore->control = c;
|
xmodemStore->control = c;
|
||||||
LOG_DEBUG("XModem: Notify Sending control %d.\n", c);
|
LOG_DEBUG("XModem: Notify Sending control %d.\n", c);
|
||||||
@@ -73,7 +74,7 @@ void XModemAdapter::sendControl(XModem_Control c) {
|
|||||||
|
|
||||||
XModem *XModemAdapter::getForPhone()
|
XModem *XModemAdapter::getForPhone()
|
||||||
{
|
{
|
||||||
if(xmodemStore) {
|
if (xmodemStore) {
|
||||||
return xmodemStore;
|
return xmodemStore;
|
||||||
} else {
|
} else {
|
||||||
return NULL;
|
return NULL;
|
||||||
@@ -82,138 +83,139 @@ XModem *XModemAdapter::getForPhone()
|
|||||||
|
|
||||||
void XModemAdapter::handlePacket(XModem xmodemPacket)
|
void XModemAdapter::handlePacket(XModem xmodemPacket)
|
||||||
{
|
{
|
||||||
switch(xmodemPacket.control) {
|
switch (xmodemPacket.control) {
|
||||||
case XModem_Control_SOH:
|
case XModem_Control_SOH:
|
||||||
case XModem_Control_STX:
|
case XModem_Control_STX:
|
||||||
if ((xmodemPacket.seq == 0) && !isReceiving && !isTransmitting) {
|
if ((xmodemPacket.seq == 0) && !isReceiving && !isTransmitting) {
|
||||||
// NULL packet has the destination filename
|
// NULL packet has the destination filename
|
||||||
memcpy(filename, &xmodemPacket.buffer.bytes, xmodemPacket.buffer.size);
|
memcpy(filename, &xmodemPacket.buffer.bytes, xmodemPacket.buffer.size);
|
||||||
if(xmodemPacket.control == XModem_Control_SOH) { // Receive this file and put to Flash
|
if (xmodemPacket.control == XModem_Control_SOH) { // Receive this file and put to Flash
|
||||||
file = FSCom.open(filename, FILE_O_WRITE);
|
file = FSCom.open(filename, FILE_O_WRITE);
|
||||||
if(file) {
|
if (file) {
|
||||||
sendControl(XModem_Control_ACK);
|
sendControl(XModem_Control_ACK);
|
||||||
isReceiving = true;
|
isReceiving = true;
|
||||||
packetno = 1;
|
packetno = 1;
|
||||||
break;
|
|
||||||
}
|
|
||||||
sendControl(XModem_Control_NAK);
|
|
||||||
isReceiving = false;
|
|
||||||
break;
|
|
||||||
} else { // Transmit this file from Flash
|
|
||||||
LOG_INFO("XModem: Transmitting file %s\n", filename);
|
|
||||||
file = FSCom.open(filename, FILE_O_READ);
|
|
||||||
if (file) {
|
|
||||||
packetno = 1;
|
|
||||||
isTransmitting = true;
|
|
||||||
memset(xmodemStore, 0, XModem_size);
|
|
||||||
xmodemStore->control = XModem_Control_SOH;
|
|
||||||
xmodemStore->seq = packetno;
|
|
||||||
xmodemStore->buffer.size = file.read(xmodemStore->buffer.bytes, sizeof(XModem_buffer_t::bytes));
|
|
||||||
xmodemStore->crc16 = crc16_ccitt(xmodemStore->buffer.bytes, xmodemStore->buffer.size);
|
|
||||||
LOG_DEBUG("XModem: STX Notify Sending packet %d, %d Bytes.\n", packetno, xmodemStore->buffer.size);
|
|
||||||
if (xmodemStore->buffer.size < sizeof(XModem_buffer_t::bytes)) {
|
|
||||||
isEOT = true;
|
|
||||||
// send EOT on next Ack
|
|
||||||
}
|
|
||||||
packetReady.notifyObservers(packetno);
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
sendControl(XModem_Control_NAK);
|
|
||||||
isTransmitting = false;
|
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
} else {
|
sendControl(XModem_Control_NAK);
|
||||||
if (isReceiving) {
|
isReceiving = false;
|
||||||
// normal file data packet
|
break;
|
||||||
if ((xmodemPacket.seq == packetno) && check(xmodemPacket.buffer.bytes, xmodemPacket.buffer.size, xmodemPacket.crc16)) {
|
} else { // Transmit this file from Flash
|
||||||
// valid packet
|
LOG_INFO("XModem: Transmitting file %s\n", filename);
|
||||||
file.write(xmodemPacket.buffer.bytes, xmodemPacket.buffer.size);
|
file = FSCom.open(filename, FILE_O_READ);
|
||||||
sendControl(XModem_Control_ACK);
|
if (file) {
|
||||||
packetno++;
|
packetno = 1;
|
||||||
break;
|
isTransmitting = true;
|
||||||
|
memset(xmodemStore, 0, XModem_size);
|
||||||
|
xmodemStore->control = XModem_Control_SOH;
|
||||||
|
xmodemStore->seq = packetno;
|
||||||
|
xmodemStore->buffer.size = file.read(xmodemStore->buffer.bytes, sizeof(XModem_buffer_t::bytes));
|
||||||
|
xmodemStore->crc16 = crc16_ccitt(xmodemStore->buffer.bytes, xmodemStore->buffer.size);
|
||||||
|
LOG_DEBUG("XModem: STX Notify Sending packet %d, %d Bytes.\n", packetno, xmodemStore->buffer.size);
|
||||||
|
if (xmodemStore->buffer.size < sizeof(XModem_buffer_t::bytes)) {
|
||||||
|
isEOT = true;
|
||||||
|
// send EOT on next Ack
|
||||||
}
|
}
|
||||||
// invalid packet
|
packetReady.notifyObservers(packetno);
|
||||||
sendControl(XModem_Control_NAK);
|
|
||||||
break;
|
|
||||||
} else if (isTransmitting) {
|
|
||||||
// just received something weird.
|
|
||||||
sendControl(XModem_Control_CAN);
|
|
||||||
isTransmitting = false;
|
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
sendControl(XModem_Control_NAK);
|
||||||
|
isTransmitting = false;
|
||||||
|
break;
|
||||||
}
|
}
|
||||||
break;
|
} else {
|
||||||
case XModem_Control_EOT:
|
if (isReceiving) {
|
||||||
// End of transmission
|
// normal file data packet
|
||||||
sendControl(XModem_Control_ACK);
|
if ((xmodemPacket.seq == packetno) &&
|
||||||
file.close();
|
check(xmodemPacket.buffer.bytes, xmodemPacket.buffer.size, xmodemPacket.crc16)) {
|
||||||
isReceiving = false;
|
// valid packet
|
||||||
break;
|
file.write(xmodemPacket.buffer.bytes, xmodemPacket.buffer.size);
|
||||||
case XModem_Control_CAN:
|
sendControl(XModem_Control_ACK);
|
||||||
// Cancel transmission and remove file
|
packetno++;
|
||||||
sendControl(XModem_Control_ACK);
|
|
||||||
file.close();
|
|
||||||
FSCom.remove(filename);
|
|
||||||
isReceiving = false;
|
|
||||||
break;
|
|
||||||
case XModem_Control_ACK:
|
|
||||||
// Acknowledge Send the next packet
|
|
||||||
if (isTransmitting) {
|
|
||||||
if (isEOT) {
|
|
||||||
sendControl(XModem_Control_EOT);
|
|
||||||
file.close();
|
|
||||||
LOG_INFO("XModem: Finished sending file %s\n", filename);
|
|
||||||
isTransmitting = false;
|
|
||||||
isEOT = false;
|
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
retrans = MAXRETRANS; // reset retransmit counter
|
// invalid packet
|
||||||
packetno++;
|
sendControl(XModem_Control_NAK);
|
||||||
memset(xmodemStore, 0, XModem_size);
|
break;
|
||||||
xmodemStore->control = XModem_Control_SOH;
|
} else if (isTransmitting) {
|
||||||
xmodemStore->seq = packetno;
|
|
||||||
xmodemStore->buffer.size = file.read(xmodemStore->buffer.bytes, sizeof(XModem_buffer_t::bytes));
|
|
||||||
xmodemStore->crc16 = crc16_ccitt(xmodemStore->buffer.bytes, xmodemStore->buffer.size);
|
|
||||||
LOG_DEBUG("XModem: ACK Notify Sending packet %d, %d Bytes.\n", packetno, xmodemStore->buffer.size);
|
|
||||||
if (xmodemStore->buffer.size < sizeof(XModem_buffer_t::bytes)) {
|
|
||||||
isEOT = true;
|
|
||||||
// send EOT on next Ack
|
|
||||||
}
|
|
||||||
packetReady.notifyObservers(packetno);
|
|
||||||
} else {
|
|
||||||
// just received something weird.
|
// just received something weird.
|
||||||
sendControl(XModem_Control_CAN);
|
sendControl(XModem_Control_CAN);
|
||||||
|
isTransmitting = false;
|
||||||
|
break;
|
||||||
}
|
}
|
||||||
break;
|
}
|
||||||
case XModem_Control_NAK:
|
break;
|
||||||
// Negative acknowledge. Send the same buffer again
|
case XModem_Control_EOT:
|
||||||
if (isTransmitting) {
|
// End of transmission
|
||||||
if (--retrans <= 0) {
|
sendControl(XModem_Control_ACK);
|
||||||
sendControl(XModem_Control_CAN);
|
file.close();
|
||||||
file.close();
|
isReceiving = false;
|
||||||
LOG_INFO("XModem: Retransmit timeout, cancelling file %s\n", filename);
|
break;
|
||||||
isTransmitting = false;
|
case XModem_Control_CAN:
|
||||||
break;
|
// Cancel transmission and remove file
|
||||||
}
|
sendControl(XModem_Control_ACK);
|
||||||
memset(xmodemStore, 0, XModem_size);
|
file.close();
|
||||||
xmodemStore->control = XModem_Control_SOH;
|
FSCom.remove(filename);
|
||||||
xmodemStore->seq = packetno;
|
isReceiving = false;
|
||||||
file.seek((packetno-1) * sizeof(XModem_buffer_t::bytes));
|
break;
|
||||||
xmodemStore->buffer.size = file.read(xmodemStore->buffer.bytes, sizeof(XModem_buffer_t::bytes));
|
case XModem_Control_ACK:
|
||||||
xmodemStore->crc16 = crc16_ccitt(xmodemStore->buffer.bytes, xmodemStore->buffer.size);
|
// Acknowledge Send the next packet
|
||||||
LOG_DEBUG("XModem: NAK Notify Sending packet %d, %d Bytes.\n", packetno, xmodemStore->buffer.size);
|
if (isTransmitting) {
|
||||||
if (xmodemStore->buffer.size < sizeof(XModem_buffer_t::bytes)) {
|
if (isEOT) {
|
||||||
isEOT = true;
|
sendControl(XModem_Control_EOT);
|
||||||
// send EOT on next Ack
|
file.close();
|
||||||
}
|
LOG_INFO("XModem: Finished sending file %s\n", filename);
|
||||||
packetReady.notifyObservers(packetno);
|
isTransmitting = false;
|
||||||
} else {
|
isEOT = false;
|
||||||
// just received something weird.
|
break;
|
||||||
|
}
|
||||||
|
retrans = MAXRETRANS; // reset retransmit counter
|
||||||
|
packetno++;
|
||||||
|
memset(xmodemStore, 0, XModem_size);
|
||||||
|
xmodemStore->control = XModem_Control_SOH;
|
||||||
|
xmodemStore->seq = packetno;
|
||||||
|
xmodemStore->buffer.size = file.read(xmodemStore->buffer.bytes, sizeof(XModem_buffer_t::bytes));
|
||||||
|
xmodemStore->crc16 = crc16_ccitt(xmodemStore->buffer.bytes, xmodemStore->buffer.size);
|
||||||
|
LOG_DEBUG("XModem: ACK Notify Sending packet %d, %d Bytes.\n", packetno, xmodemStore->buffer.size);
|
||||||
|
if (xmodemStore->buffer.size < sizeof(XModem_buffer_t::bytes)) {
|
||||||
|
isEOT = true;
|
||||||
|
// send EOT on next Ack
|
||||||
|
}
|
||||||
|
packetReady.notifyObservers(packetno);
|
||||||
|
} else {
|
||||||
|
// just received something weird.
|
||||||
|
sendControl(XModem_Control_CAN);
|
||||||
|
}
|
||||||
|
break;
|
||||||
|
case XModem_Control_NAK:
|
||||||
|
// Negative acknowledge. Send the same buffer again
|
||||||
|
if (isTransmitting) {
|
||||||
|
if (--retrans <= 0) {
|
||||||
sendControl(XModem_Control_CAN);
|
sendControl(XModem_Control_CAN);
|
||||||
|
file.close();
|
||||||
|
LOG_INFO("XModem: Retransmit timeout, cancelling file %s\n", filename);
|
||||||
|
isTransmitting = false;
|
||||||
|
break;
|
||||||
}
|
}
|
||||||
break;
|
memset(xmodemStore, 0, XModem_size);
|
||||||
default:
|
xmodemStore->control = XModem_Control_SOH;
|
||||||
// Unknown control character
|
xmodemStore->seq = packetno;
|
||||||
break;
|
file.seek((packetno - 1) * sizeof(XModem_buffer_t::bytes));
|
||||||
|
xmodemStore->buffer.size = file.read(xmodemStore->buffer.bytes, sizeof(XModem_buffer_t::bytes));
|
||||||
|
xmodemStore->crc16 = crc16_ccitt(xmodemStore->buffer.bytes, xmodemStore->buffer.size);
|
||||||
|
LOG_DEBUG("XModem: NAK Notify Sending packet %d, %d Bytes.\n", packetno, xmodemStore->buffer.size);
|
||||||
|
if (xmodemStore->buffer.size < sizeof(XModem_buffer_t::bytes)) {
|
||||||
|
isEOT = true;
|
||||||
|
// send EOT on next Ack
|
||||||
|
}
|
||||||
|
packetReady.notifyObservers(packetno);
|
||||||
|
} else {
|
||||||
|
// just received something weird.
|
||||||
|
sendControl(XModem_Control_CAN);
|
||||||
|
}
|
||||||
|
break;
|
||||||
|
default:
|
||||||
|
// Unknown control character
|
||||||
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
42
src/xmodem.h
42
src/xmodem.h
@@ -32,45 +32,45 @@
|
|||||||
|
|
||||||
#pragma once
|
#pragma once
|
||||||
|
|
||||||
|
#include "FSCommon.h"
|
||||||
#include "configuration.h"
|
#include "configuration.h"
|
||||||
#include "mesh/generated/meshtastic/xmodem.pb.h"
|
#include "mesh/generated/meshtastic/xmodem.pb.h"
|
||||||
#include "FSCommon.h"
|
|
||||||
|
|
||||||
#define MAXRETRANS 25
|
#define MAXRETRANS 25
|
||||||
|
|
||||||
class XModemAdapter
|
class XModemAdapter
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
// Called when we put a fragment in the outgoing memory
|
// Called when we put a fragment in the outgoing memory
|
||||||
Observable<uint32_t> packetReady;
|
Observable<uint32_t> packetReady;
|
||||||
|
|
||||||
XModemAdapter();
|
XModemAdapter();
|
||||||
|
|
||||||
void handlePacket(XModem xmodemPacket);
|
void handlePacket(XModem xmodemPacket);
|
||||||
XModem *getForPhone();
|
XModem *getForPhone();
|
||||||
|
|
||||||
private:
|
private:
|
||||||
bool isReceiving = false;
|
bool isReceiving = false;
|
||||||
bool isTransmitting = false;
|
bool isTransmitting = false;
|
||||||
bool isEOT = false;
|
bool isEOT = false;
|
||||||
|
|
||||||
int retrans = MAXRETRANS;
|
int retrans = MAXRETRANS;
|
||||||
|
|
||||||
uint16_t packetno = 0;
|
uint16_t packetno = 0;
|
||||||
|
|
||||||
#ifdef ARCH_NRF52
|
#ifdef ARCH_NRF52
|
||||||
File file = File(FSCom);
|
File file = File(FSCom);
|
||||||
#else
|
#else
|
||||||
File file;
|
File file;
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
char filename[sizeof(XModem_buffer_t::bytes)] = {0};
|
char filename[sizeof(XModem_buffer_t::bytes)] = {0};
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
XModem *xmodemStore = NULL;
|
XModem *xmodemStore = NULL;
|
||||||
unsigned short crc16_ccitt(const pb_byte_t *buffer, int length);
|
unsigned short crc16_ccitt(const pb_byte_t *buffer, int length);
|
||||||
int check(const pb_byte_t *buf, int sz, unsigned short tcrc);
|
int check(const pb_byte_t *buf, int sz, unsigned short tcrc);
|
||||||
void sendControl(XModem_Control c);
|
void sendControl(XModem_Control c);
|
||||||
};
|
};
|
||||||
|
|
||||||
extern XModemAdapter xModem;
|
extern XModemAdapter xModem;
|
||||||
|
|||||||
Reference in New Issue
Block a user