mirror of
https://github.com/meshtastic/firmware.git
synced 2025-12-29 22:20:37 +00:00
Finish config transition
This commit is contained in:
@@ -56,11 +56,6 @@ bool AdminModule::handleReceivedProtobuf(const MeshPacket &mp, AdminMessage *r)
|
||||
handleGetOwner(mp);
|
||||
break;
|
||||
|
||||
case AdminMessage_get_radio_request_tag:
|
||||
DEBUG_MSG("Client is getting radio\n");
|
||||
handleGetRadio(mp);
|
||||
break;
|
||||
|
||||
case AdminMessage_get_config_request_tag:
|
||||
DEBUG_MSG("Client is getting config\n");
|
||||
handleGetConfig(mp, r->get_channel_request);
|
||||
@@ -89,11 +84,6 @@ bool AdminModule::handleReceivedProtobuf(const MeshPacket &mp, AdminMessage *r)
|
||||
handleSetOwner(r->set_owner);
|
||||
break;
|
||||
|
||||
case AdminMessage_set_radio_tag:
|
||||
DEBUG_MSG("Client is setting radio\n");
|
||||
handleSetRadio(r->set_radio);
|
||||
break;
|
||||
|
||||
case AdminMessage_set_config_tag:
|
||||
DEBUG_MSG("Client is setting the config\n");
|
||||
handleSetConfig(r->set_config);
|
||||
@@ -181,36 +171,40 @@ void AdminModule::handleSetOwner(const User &o)
|
||||
service.reloadOwner();
|
||||
}
|
||||
|
||||
void AdminModule::handleSetRadio(RadioConfig &r)
|
||||
{
|
||||
writeSecret(r.preferences.wifi_password, radioConfig.preferences.wifi_password);
|
||||
radioConfig = r;
|
||||
// void AdminModule::handleSetRadio(RadioConfig &r)
|
||||
// {
|
||||
// // writeSecret(r.preferences.wifi_password, radioConfig.preferences.wifi_password);
|
||||
// radioConfig = r;
|
||||
|
||||
service.reloadConfig();
|
||||
}
|
||||
// service.reloadConfig();
|
||||
// }
|
||||
|
||||
void AdminModule::handleSetConfig(const Config &c)
|
||||
{
|
||||
switch (c.which_payloadVariant) {
|
||||
case Config_device_config_tag:
|
||||
case Config_device_tag:
|
||||
DEBUG_MSG("Setting config: Device\n");
|
||||
config.payloadVariant.device = c.payloadVariant.device;
|
||||
break;
|
||||
case Config_gps_config_tag:
|
||||
DEBUG_MSG("Setting config: GPS\n");
|
||||
case Config_position_tag:
|
||||
DEBUG_MSG("Setting config: Position\n");
|
||||
config.payloadVariant.position = c.payloadVariant.position;
|
||||
break;
|
||||
case Config_power_config_tag:
|
||||
case Config_power_tag:
|
||||
DEBUG_MSG("Setting config: Power\n");
|
||||
config.payloadVariant.power = c.payloadVariant.power;
|
||||
break;
|
||||
case Config_wifi_config_tag:
|
||||
case Config_wifi_tag:
|
||||
DEBUG_MSG("Setting config: WiFi\n");
|
||||
config.payloadVariant.wifi = c.payloadVariant.wifi;
|
||||
break;
|
||||
case Config_display_config_tag:
|
||||
case Config_display_tag:
|
||||
DEBUG_MSG("Setting config: Display\n");
|
||||
config.payloadVariant.display = c.payloadVariant.display;
|
||||
break;
|
||||
case Config_lora_config_tag:
|
||||
case Config_lora_tag:
|
||||
DEBUG_MSG("Setting config: LoRa\n");
|
||||
config.payloadVariant.lora_config = c.payloadVariant.lora_config;
|
||||
service.reloadConfig();
|
||||
config.payloadVariant.lora = c.payloadVariant.lora;
|
||||
break;
|
||||
}
|
||||
|
||||
@@ -220,27 +214,33 @@ void AdminModule::handleSetConfig(const Config &c)
|
||||
void AdminModule::handleSetModuleConfig(const ModuleConfig &c)
|
||||
{
|
||||
switch (c.which_payloadVariant) {
|
||||
case ModuleConfig_mqtt_config_tag:
|
||||
case ModuleConfig_mqtt_tag:
|
||||
DEBUG_MSG("Setting module config: MQTT\n");
|
||||
moduleConfig.payloadVariant.mqtt = c.payloadVariant.mqtt;
|
||||
break;
|
||||
case ModuleConfig_serial_config_tag:
|
||||
case ModuleConfig_serial_tag:
|
||||
DEBUG_MSG("Setting module config: Serial\n");
|
||||
moduleConfig.payloadVariant.serial = c.payloadVariant.serial;
|
||||
break;
|
||||
case ModuleConfig_external_notification_config_tag:
|
||||
case ModuleConfig_external_notification_tag:
|
||||
DEBUG_MSG("Setting module config: External Notification\n");
|
||||
moduleConfig.payloadVariant.external_notification = c.payloadVariant.external_notification;
|
||||
break;
|
||||
case ModuleConfig_store_forward_config_tag:
|
||||
case ModuleConfig_store_forward_tag:
|
||||
DEBUG_MSG("Setting module config: Store & Forward\n");
|
||||
moduleConfig.payloadVariant.store_forward = c.payloadVariant.store_forward;
|
||||
break;
|
||||
case ModuleConfig_range_test_config_tag:
|
||||
case ModuleConfig_range_test_tag:
|
||||
DEBUG_MSG("Setting module config: Range Test\n");
|
||||
moduleConfig.payloadVariant.range_test = c.payloadVariant.range_test;
|
||||
break;
|
||||
case ModuleConfig_telemetry_config_tag:
|
||||
case ModuleConfig_telemetry_tag:
|
||||
DEBUG_MSG("Setting module config: Telemetry\n");
|
||||
moduleConfig.payloadVariant.telemetry_config = c.payloadVariant.telemetry_config;
|
||||
moduleConfig.payloadVariant.telemetry = c.payloadVariant.telemetry;
|
||||
break;
|
||||
case ModuleConfig_canned_message_config_tag:
|
||||
case ModuleConfig_canned_message_tag:
|
||||
DEBUG_MSG("Setting module config: Canned Message\n");
|
||||
moduleConfig.payloadVariant.canned_message = c.payloadVariant.canned_message;
|
||||
break;
|
||||
}
|
||||
|
||||
@@ -270,26 +270,28 @@ void AdminModule::handleGetOwner(const MeshPacket &req)
|
||||
}
|
||||
}
|
||||
|
||||
void AdminModule::handleGetRadio(const MeshPacket &req)
|
||||
{
|
||||
if (req.decoded.want_response) {
|
||||
// We create the reply here
|
||||
AdminMessage res = AdminMessage_init_default;
|
||||
res.get_radio_response = radioConfig;
|
||||
// void AdminModule::handleGetRadio(const MeshPacket &req)
|
||||
// {
|
||||
// if (req.decoded.want_response) {
|
||||
// // We create the reply here
|
||||
// AdminMessage res = AdminMessage_init_default;
|
||||
// res.get_radio_response = radioConfig;
|
||||
|
||||
// NOTE: The phone app needs to know the ls_secs & phone_timeout value so it can properly expect sleep behavior.
|
||||
// So even if we internally use 0 to represent 'use default' we still need to send the value we are
|
||||
// using to the app (so that even old phone apps work with new device loads).
|
||||
res.get_radio_response.preferences.ls_secs = getPref_ls_secs();
|
||||
res.get_radio_response.preferences.phone_timeout_secs = getPref_phone_timeout_secs();
|
||||
// hideSecret(r.get_radio_response.preferences.wifi_ssid); // hmm - leave public for now, because only minimally private
|
||||
// and useful for users to know current provisioning)
|
||||
hideSecret(res.get_radio_response.preferences.wifi_password);
|
||||
// // NOTE: The phone app needs to know the ls_secs & phone_timeout value so it can properly expect sleep behavior.
|
||||
// // So even if we internally use 0 to represent 'use default' we still need to send the value we are
|
||||
// // using to the app (so that even old phone apps work with new device loads).
|
||||
// // res.get_radio_response.preferences.ls_secs = getPref_ls_secs(); //TODO: Re-implement if necceasry
|
||||
// // res.get_radio_response.preferences.phone_timeout_secs = getPref_phone_timeout_secs(); //TODO: Re-implement if
|
||||
// necceasry
|
||||
// // hideSecret(r.get_radio_response.preferences.wifi_ssid); // hmm - leave public for now, because only minimally
|
||||
// private
|
||||
// // and useful for users to know current provisioning)
|
||||
// // hideSecret(res.get_radio_response.preferences.wifi_password);
|
||||
|
||||
res.which_variant = AdminMessage_get_radio_response_tag;
|
||||
myReply = allocDataProtobuf(res);
|
||||
}
|
||||
}
|
||||
// res.which_variant = AdminMessage_get_radio_response_tag;
|
||||
// myReply = allocDataProtobuf(res);
|
||||
// }
|
||||
// }
|
||||
|
||||
void AdminModule::handleGetConfig(const MeshPacket &req, const uint32_t configType)
|
||||
{
|
||||
@@ -299,28 +301,28 @@ void AdminModule::handleGetConfig(const MeshPacket &req, const uint32_t configTy
|
||||
switch (configType) {
|
||||
case AdminMessage_ConfigType_DEVICE_CONFIG:
|
||||
DEBUG_MSG("Getting config: Device\n");
|
||||
res.get_config_response.which_payloadVariant = Config_device_config_tag;
|
||||
res.get_config_response.which_payloadVariant = Config_device_tag;
|
||||
break;
|
||||
case AdminMessage_ConfigType_GPS_CONFIG:
|
||||
DEBUG_MSG("Getting config: GPS\n");
|
||||
res.get_config_response.which_payloadVariant = Config_gps_config_tag;
|
||||
case AdminMessage_ConfigType_POSITION_CONFIG:
|
||||
DEBUG_MSG("Getting config: Position\n");
|
||||
res.get_config_response.which_payloadVariant = Config_position_tag;
|
||||
break;
|
||||
case AdminMessage_ConfigType_POWER_CONFIG:
|
||||
DEBUG_MSG("Getting config: Power\n");
|
||||
res.get_config_response.which_payloadVariant = Config_power_config_tag;
|
||||
res.get_config_response.which_payloadVariant = Config_power_tag;
|
||||
break;
|
||||
case AdminMessage_ConfigType_WIFI_CONFIG:
|
||||
DEBUG_MSG("Getting config: WiFi\n");
|
||||
res.get_config_response.which_payloadVariant = Config_wifi_config_tag;
|
||||
res.get_config_response.which_payloadVariant = Config_wifi_tag;
|
||||
break;
|
||||
case AdminMessage_ConfigType_DISPLAY_CONFIG:
|
||||
DEBUG_MSG("Getting config: Display\n");
|
||||
res.get_config_response.which_payloadVariant = Config_display_config_tag;
|
||||
res.get_config_response.which_payloadVariant = Config_display_tag;
|
||||
break;
|
||||
case AdminMessage_ConfigType_LORA_CONFIG:
|
||||
DEBUG_MSG("Getting config: LoRa\n");
|
||||
res.get_config_response.which_payloadVariant = Config_lora_config_tag;
|
||||
res.get_config_response.payloadVariant.lora_config = config.payloadVariant.lora_config;
|
||||
res.get_config_response.which_payloadVariant = Config_lora_tag;
|
||||
res.get_config_response.payloadVariant.lora = config.payloadVariant.lora;
|
||||
break;
|
||||
}
|
||||
|
||||
@@ -331,7 +333,7 @@ void AdminModule::handleGetConfig(const MeshPacket &req, const uint32_t configTy
|
||||
// r.get_radio_response.preferences.phone_timeout_secs = getPref_phone_timeout_secs();
|
||||
// hideSecret(r.get_radio_response.preferences.wifi_ssid); // hmm - leave public for now, because only minimally private
|
||||
// and useful for users to know current provisioning) hideSecret(r.get_radio_response.preferences.wifi_password);
|
||||
// r.get_config_response.which_payloadVariant = Config_ModuleConfig_telemetry_config_tag;
|
||||
// r.get_config_response.which_payloadVariant = Config_ModuleConfig_telemetry_tag;
|
||||
res.which_variant = AdminMessage_get_config_response_tag;
|
||||
myReply = allocDataProtobuf(res);
|
||||
}
|
||||
@@ -345,32 +347,39 @@ void AdminModule::handleGetModuleConfig(const MeshPacket &req, const uint32_t co
|
||||
switch (configType) {
|
||||
case AdminMessage_ModuleConfigType_MQTT_CONFIG:
|
||||
DEBUG_MSG("Getting module config: MQTT\n");
|
||||
res.get_module_config_response.which_payloadVariant = ModuleConfig_mqtt_config_tag;
|
||||
res.get_module_config_response.which_payloadVariant = ModuleConfig_mqtt_tag;
|
||||
res.get_module_config_response.payloadVariant.mqtt = moduleConfig.payloadVariant.mqtt;
|
||||
break;
|
||||
case AdminMessage_ModuleConfigType_SERIAL_CONFIG:
|
||||
DEBUG_MSG("Getting module config: Serial\n");
|
||||
res.get_module_config_response.which_payloadVariant = ModuleConfig_serial_config_tag;
|
||||
res.get_module_config_response.which_payloadVariant = ModuleConfig_serial_tag;
|
||||
res.get_module_config_response.payloadVariant.serial = moduleConfig.payloadVariant.serial;
|
||||
break;
|
||||
case AdminMessage_ModuleConfigType_EXTNOTIF_CONFIG:
|
||||
DEBUG_MSG("Getting module config: External Notification\n");
|
||||
res.get_module_config_response.which_payloadVariant = ModuleConfig_external_notification_config_tag;
|
||||
res.get_module_config_response.which_payloadVariant = ModuleConfig_external_notification_tag;
|
||||
res.get_module_config_response.payloadVariant.external_notification =
|
||||
moduleConfig.payloadVariant.external_notification;
|
||||
break;
|
||||
case AdminMessage_ModuleConfigType_STOREFORWARD_CONFIG:
|
||||
DEBUG_MSG("Getting module config: Store & Forward\n");
|
||||
res.get_module_config_response.which_payloadVariant = ModuleConfig_store_forward_config_tag;
|
||||
res.get_module_config_response.which_payloadVariant = ModuleConfig_store_forward_tag;
|
||||
res.get_module_config_response.payloadVariant.store_forward = moduleConfig.payloadVariant.store_forward;
|
||||
break;
|
||||
case AdminMessage_ModuleConfigType_RANGETEST_CONFIG:
|
||||
DEBUG_MSG("Getting module config: Range Test\n");
|
||||
res.get_module_config_response.which_payloadVariant = ModuleConfig_range_test_config_tag;
|
||||
res.get_module_config_response.which_payloadVariant = ModuleConfig_range_test_tag;
|
||||
res.get_module_config_response.payloadVariant.range_test = moduleConfig.payloadVariant.range_test;
|
||||
break;
|
||||
case AdminMessage_ModuleConfigType_TELEMETRY_CONFIG:
|
||||
DEBUG_MSG("Getting module config: Telemetry\n");
|
||||
res.get_module_config_response.which_payloadVariant = ModuleConfig_telemetry_config_tag;
|
||||
res.get_module_config_response.payloadVariant.telemetry_config = moduleConfig.payloadVariant.telemetry_config;
|
||||
res.get_module_config_response.which_payloadVariant = ModuleConfig_telemetry_tag;
|
||||
res.get_module_config_response.payloadVariant.telemetry = moduleConfig.payloadVariant.telemetry;
|
||||
break;
|
||||
case AdminMessage_ModuleConfigType_CANNEDMSG_CONFIG:
|
||||
DEBUG_MSG("Getting module config: Canned Message\n");
|
||||
res.get_module_config_response.which_payloadVariant = ModuleConfig_canned_message_config_tag;
|
||||
res.get_module_config_response.which_payloadVariant = ModuleConfig_canned_message_tag;
|
||||
res.get_module_config_response.payloadVariant.canned_message = moduleConfig.payloadVariant.canned_message;
|
||||
break;
|
||||
}
|
||||
|
||||
@@ -381,7 +390,7 @@ void AdminModule::handleGetModuleConfig(const MeshPacket &req, const uint32_t co
|
||||
// r.get_radio_response.preferences.phone_timeout_secs = getPref_phone_timeout_secs();
|
||||
// hideSecret(r.get_radio_response.preferences.wifi_ssid); // hmm - leave public for now, because only minimally private
|
||||
// and useful for users to know current provisioning) hideSecret(r.get_radio_response.preferences.wifi_password);
|
||||
// r.get_config_response.which_payloadVariant = Config_ModuleConfig_telemetry_config_tag;
|
||||
// r.get_config_response.which_payloadVariant = Config_ModuleConfig_telemetry_tag;
|
||||
res.which_variant = AdminMessage_get_module_config_response_tag;
|
||||
myReply = allocDataProtobuf(res);
|
||||
}
|
||||
|
||||
@@ -24,7 +24,6 @@ class AdminModule : public ProtobufModule<AdminMessage>
|
||||
* Getters
|
||||
*/
|
||||
void handleGetOwner(const MeshPacket &req);
|
||||
void handleGetRadio(const MeshPacket &req);
|
||||
void handleGetConfig(const MeshPacket &req, uint32_t configType);
|
||||
void handleGetModuleConfig(const MeshPacket &req, uint32_t configType);
|
||||
void handleGetChannel(const MeshPacket &req, uint32_t channelIndex);
|
||||
@@ -33,7 +32,6 @@ class AdminModule : public ProtobufModule<AdminMessage>
|
||||
* Setters
|
||||
*/
|
||||
void handleSetOwner(const User &o);
|
||||
void handleSetRadio(RadioConfig &r);
|
||||
void handleSetChannel(const Channel &cc);
|
||||
void handleSetConfig(const Config &c);
|
||||
void handleSetModuleConfig(const ModuleConfig &c);
|
||||
|
||||
@@ -1,9 +1,9 @@
|
||||
#include "configuration.h"
|
||||
#ifndef NO_SCREEN
|
||||
#include "CannedMessageModule.h"
|
||||
#include "PowerFSM.h" // neede for button bypass
|
||||
#include "MeshService.h"
|
||||
#include "FSCommon.h"
|
||||
#include "MeshService.h"
|
||||
#include "PowerFSM.h" // neede for button bypass
|
||||
#include "mesh/generated/cannedmessages.pb.h"
|
||||
|
||||
// TODO: reuse defined from Screen.cpp
|
||||
@@ -22,22 +22,18 @@ CannedMessageModule *cannedMessageModule;
|
||||
|
||||
// TODO: move it into NodeDB.h!
|
||||
extern bool loadProto(const char *filename, size_t protoSize, size_t objSize, const pb_msgdesc_t *fields, void *dest_struct);
|
||||
extern bool saveProto(const char *filename, size_t protoSize, size_t objSize, const pb_msgdesc_t *fields, const void *dest_struct);
|
||||
extern bool saveProto(const char *filename, size_t protoSize, size_t objSize, const pb_msgdesc_t *fields,
|
||||
const void *dest_struct);
|
||||
|
||||
CannedMessageModule::CannedMessageModule()
|
||||
: SinglePortModule("canned", PortNum_TEXT_MESSAGE_APP),
|
||||
concurrency::OSThread("CannedMessageModule")
|
||||
: SinglePortModule("canned", PortNum_TEXT_MESSAGE_APP), concurrency::OSThread("CannedMessageModule")
|
||||
{
|
||||
if (radioConfig.preferences.canned_message_module_enabled)
|
||||
{
|
||||
if (moduleConfig.payloadVariant.canned_message.enabled) {
|
||||
this->loadProtoForModule();
|
||||
if(this->splitConfiguredMessages() <= 0)
|
||||
{
|
||||
if (this->splitConfiguredMessages() <= 0) {
|
||||
DEBUG_MSG("CannedMessageModule: No messages are configured. Module is disabled\n");
|
||||
this->runState = CANNED_MESSAGE_RUN_STATE_DISABLED;
|
||||
}
|
||||
else
|
||||
{
|
||||
} else {
|
||||
DEBUG_MSG("CannedMessageModule is enabled\n");
|
||||
this->inputObserver.observe(inputBroker);
|
||||
}
|
||||
@@ -56,57 +52,38 @@ int CannedMessageModule::splitConfiguredMessages()
|
||||
int i = 0;
|
||||
|
||||
// collect all the message parts
|
||||
strcpy(
|
||||
this->messageStore,
|
||||
cannedMessageModuleConfig.messagesPart1);
|
||||
strcat(
|
||||
this->messageStore,
|
||||
cannedMessageModuleConfig.messagesPart2);
|
||||
strcat(
|
||||
this->messageStore,
|
||||
cannedMessageModuleConfig.messagesPart3);
|
||||
strcat(
|
||||
this->messageStore,
|
||||
cannedMessageModuleConfig.messagesPart4);
|
||||
strcpy(this->messageStore, cannedMessageModuleConfig.messagesPart1);
|
||||
strcat(this->messageStore, cannedMessageModuleConfig.messagesPart2);
|
||||
strcat(this->messageStore, cannedMessageModuleConfig.messagesPart3);
|
||||
strcat(this->messageStore, cannedMessageModuleConfig.messagesPart4);
|
||||
|
||||
// The first message points to the beginning of the store.
|
||||
this->messages[messageIndex++] =
|
||||
this->messageStore;
|
||||
int upTo =
|
||||
strlen(this->messageStore) - 1;
|
||||
this->messages[messageIndex++] = this->messageStore;
|
||||
int upTo = strlen(this->messageStore) - 1;
|
||||
|
||||
while (i < upTo)
|
||||
{
|
||||
if (this->messageStore[i] == '|')
|
||||
{
|
||||
while (i < upTo) {
|
||||
if (this->messageStore[i] == '|') {
|
||||
// Message ending found, replace it with string-end character.
|
||||
this->messageStore[i] = '\0';
|
||||
DEBUG_MSG("CannedMessage %d is: '%s'\n",
|
||||
messageIndex-1, this->messages[messageIndex-1]);
|
||||
DEBUG_MSG("CannedMessage %d is: '%s'\n", messageIndex - 1, this->messages[messageIndex - 1]);
|
||||
|
||||
// hit our max messages, bail
|
||||
if (messageIndex >= CANNED_MESSAGE_MODULE_MESSAGE_MAX_COUNT)
|
||||
{
|
||||
if (messageIndex >= CANNED_MESSAGE_MODULE_MESSAGE_MAX_COUNT) {
|
||||
this->messagesCount = messageIndex;
|
||||
return this->messagesCount;
|
||||
}
|
||||
|
||||
// Next message starts after pipe (|) just found.
|
||||
this->messages[messageIndex++] =
|
||||
(this->messageStore + i + 1);
|
||||
this->messages[messageIndex++] = (this->messageStore + i + 1);
|
||||
}
|
||||
i += 1;
|
||||
}
|
||||
if (strlen(this->messages[messageIndex-1]) > 0)
|
||||
{
|
||||
if (strlen(this->messages[messageIndex - 1]) > 0) {
|
||||
// We have a last message.
|
||||
DEBUG_MSG("CannedMessage %d is: '%s'\n",
|
||||
messageIndex-1, this->messages[messageIndex-1]);
|
||||
DEBUG_MSG("CannedMessage %d is: '%s'\n", messageIndex - 1, this->messages[messageIndex - 1]);
|
||||
this->messagesCount = messageIndex;
|
||||
}
|
||||
else
|
||||
{
|
||||
this->messagesCount = messageIndex-1;
|
||||
} else {
|
||||
this->messagesCount = messageIndex - 1;
|
||||
}
|
||||
|
||||
return this->messagesCount;
|
||||
@@ -114,11 +91,9 @@ int CannedMessageModule::splitConfiguredMessages()
|
||||
|
||||
int CannedMessageModule::handleInputEvent(const InputEvent *event)
|
||||
{
|
||||
if (
|
||||
(strlen(radioConfig.preferences.canned_message_module_allow_input_source) > 0) &&
|
||||
(strcmp(radioConfig.preferences.canned_message_module_allow_input_source, event->source) != 0) &&
|
||||
(strcmp(radioConfig.preferences.canned_message_module_allow_input_source, "_any") != 0))
|
||||
{
|
||||
if ((strlen(moduleConfig.payloadVariant.canned_message.allow_input_source) > 0) &&
|
||||
(strcmp(moduleConfig.payloadVariant.canned_message.allow_input_source, event->source) != 0) &&
|
||||
(strcmp(moduleConfig.payloadVariant.canned_message.allow_input_source, "_any") != 0)) {
|
||||
// Event source is not accepted.
|
||||
// Event only accepted if source matches the configured one, or
|
||||
// the configured one is "_any" (or if there is no configured
|
||||
@@ -127,32 +102,28 @@ int CannedMessageModule::handleInputEvent(const InputEvent *event)
|
||||
}
|
||||
|
||||
bool validEvent = false;
|
||||
if (event->inputEvent == static_cast<char>(InputEventChar_KEY_UP))
|
||||
{
|
||||
if (event->inputEvent == static_cast<char>(ModuleConfig_CannedMessageConfig_InputEventChar_KEY_UP)) {
|
||||
DEBUG_MSG("Canned message event UP\n");
|
||||
this->runState = CANNED_MESSAGE_RUN_STATE_ACTION_UP;
|
||||
validEvent = true;
|
||||
}
|
||||
if (event->inputEvent == static_cast<char>(InputEventChar_KEY_DOWN))
|
||||
{
|
||||
if (event->inputEvent == static_cast<char>(ModuleConfig_CannedMessageConfig_InputEventChar_KEY_DOWN)) {
|
||||
DEBUG_MSG("Canned message event DOWN\n");
|
||||
this->runState = CANNED_MESSAGE_RUN_STATE_ACTION_DOWN;
|
||||
validEvent = true;
|
||||
}
|
||||
if (event->inputEvent == static_cast<char>(InputEventChar_KEY_SELECT))
|
||||
{
|
||||
if (event->inputEvent == static_cast<char>(ModuleConfig_CannedMessageConfig_InputEventChar_KEY_SELECT)) {
|
||||
DEBUG_MSG("Canned message event Select\n");
|
||||
// when inactive, call the onebutton shortpress instead. Activate Module only on up/down
|
||||
if ((this->runState == CANNED_MESSAGE_RUN_STATE_INACTIVE) || (this->runState == CANNED_MESSAGE_RUN_STATE_DISABLED)) {
|
||||
powerFSM.trigger(EVENT_PRESS);
|
||||
}else{
|
||||
} else {
|
||||
this->runState = CANNED_MESSAGE_RUN_STATE_ACTION_SELECT;
|
||||
validEvent = true;
|
||||
}
|
||||
}
|
||||
|
||||
if (validEvent)
|
||||
{
|
||||
if (validEvent) {
|
||||
// Let runOnce to be called immediately.
|
||||
setIntervalFromNow(0);
|
||||
}
|
||||
@@ -160,90 +131,67 @@ int CannedMessageModule::handleInputEvent(const InputEvent *event)
|
||||
return 0;
|
||||
}
|
||||
|
||||
void CannedMessageModule::sendText(NodeNum dest,
|
||||
const char* message,
|
||||
bool wantReplies)
|
||||
void CannedMessageModule::sendText(NodeNum dest, const char *message, bool wantReplies)
|
||||
{
|
||||
MeshPacket *p = allocDataPacket();
|
||||
p->to = dest;
|
||||
p->want_ack = true;
|
||||
p->decoded.payload.size = strlen(message);
|
||||
memcpy(p->decoded.payload.bytes, message, p->decoded.payload.size);
|
||||
if (radioConfig.preferences.canned_message_module_send_bell)
|
||||
{
|
||||
p->decoded.payload.bytes[p->decoded.payload.size-1] = 7; // Bell character
|
||||
p->decoded.payload.bytes[p->decoded.payload.size] = '\0'; // Bell character
|
||||
if (moduleConfig.payloadVariant.canned_message.send_bell) {
|
||||
p->decoded.payload.bytes[p->decoded.payload.size - 1] = 7; // Bell character
|
||||
p->decoded.payload.bytes[p->decoded.payload.size] = '\0'; // Bell character
|
||||
p->decoded.payload.size++;
|
||||
}
|
||||
|
||||
DEBUG_MSG("Sending message id=%d, msg=%.*s\n",
|
||||
p->id, p->decoded.payload.size, p->decoded.payload.bytes);
|
||||
DEBUG_MSG("Sending message id=%d, msg=%.*s\n", p->id, p->decoded.payload.size, p->decoded.payload.bytes);
|
||||
|
||||
service.sendToMesh(p);
|
||||
}
|
||||
|
||||
int32_t CannedMessageModule::runOnce()
|
||||
{
|
||||
if ((!radioConfig.preferences.canned_message_module_enabled)
|
||||
|| (this->runState == CANNED_MESSAGE_RUN_STATE_DISABLED)
|
||||
|| (this->runState == CANNED_MESSAGE_RUN_STATE_INACTIVE))
|
||||
{
|
||||
if ((!moduleConfig.payloadVariant.canned_message.enabled) || (this->runState == CANNED_MESSAGE_RUN_STATE_DISABLED) ||
|
||||
(this->runState == CANNED_MESSAGE_RUN_STATE_INACTIVE)) {
|
||||
return 30000; // TODO: should return MAX_VAL
|
||||
}
|
||||
DEBUG_MSG("Check status\n");
|
||||
UIFrameEvent e = {false, true};
|
||||
if (this->runState == CANNED_MESSAGE_RUN_STATE_SENDING_ACTIVE)
|
||||
{
|
||||
if (this->runState == CANNED_MESSAGE_RUN_STATE_SENDING_ACTIVE) {
|
||||
// TODO: might have some feedback of sendig state
|
||||
this->runState = CANNED_MESSAGE_RUN_STATE_INACTIVE;
|
||||
e.frameChanged = true;
|
||||
this->currentMessageIndex = -1;
|
||||
this->notifyObservers(&e);
|
||||
}
|
||||
else if (
|
||||
(this->runState == CANNED_MESSAGE_RUN_STATE_ACTIVE)
|
||||
&& (millis() - this->lastTouchMillis) > INACTIVATE_AFTER_MS)
|
||||
{
|
||||
} else if ((this->runState == CANNED_MESSAGE_RUN_STATE_ACTIVE) && (millis() - this->lastTouchMillis) > INACTIVATE_AFTER_MS) {
|
||||
// Reset module
|
||||
DEBUG_MSG("Reset due the lack of activity.\n");
|
||||
e.frameChanged = true;
|
||||
this->currentMessageIndex = -1;
|
||||
this->runState = CANNED_MESSAGE_RUN_STATE_INACTIVE;
|
||||
this->notifyObservers(&e);
|
||||
}
|
||||
else if (this->currentMessageIndex == -1)
|
||||
{
|
||||
} else if (this->currentMessageIndex == -1) {
|
||||
this->currentMessageIndex = 0;
|
||||
DEBUG_MSG("First touch (%d):%s\n", this->currentMessageIndex, this->getCurrentMessage());
|
||||
e.frameChanged = true;
|
||||
this->runState = CANNED_MESSAGE_RUN_STATE_ACTIVE;
|
||||
}
|
||||
else if (this->runState == CANNED_MESSAGE_RUN_STATE_ACTION_SELECT)
|
||||
{
|
||||
sendText(
|
||||
NODENUM_BROADCAST,
|
||||
this->messages[this->currentMessageIndex],
|
||||
true);
|
||||
} else if (this->runState == CANNED_MESSAGE_RUN_STATE_ACTION_SELECT) {
|
||||
sendText(NODENUM_BROADCAST, this->messages[this->currentMessageIndex], true);
|
||||
this->runState = CANNED_MESSAGE_RUN_STATE_SENDING_ACTIVE;
|
||||
this->currentMessageIndex = -1;
|
||||
this->notifyObservers(&e);
|
||||
return 2000;
|
||||
}
|
||||
else if (this->runState == CANNED_MESSAGE_RUN_STATE_ACTION_UP)
|
||||
{
|
||||
} else if (this->runState == CANNED_MESSAGE_RUN_STATE_ACTION_UP) {
|
||||
this->currentMessageIndex = getPrevIndex();
|
||||
this->runState = CANNED_MESSAGE_RUN_STATE_ACTIVE;
|
||||
DEBUG_MSG("MOVE UP (%d):%s\n", this->currentMessageIndex, this->getCurrentMessage());
|
||||
}
|
||||
else if (this->runState == CANNED_MESSAGE_RUN_STATE_ACTION_DOWN)
|
||||
{
|
||||
} else if (this->runState == CANNED_MESSAGE_RUN_STATE_ACTION_DOWN) {
|
||||
this->currentMessageIndex = this->getNextIndex();
|
||||
this->runState = CANNED_MESSAGE_RUN_STATE_ACTIVE;
|
||||
DEBUG_MSG("MOVE DOWN (%d):%s\n", this->currentMessageIndex, this->getCurrentMessage());
|
||||
}
|
||||
|
||||
if (this->runState == CANNED_MESSAGE_RUN_STATE_ACTIVE)
|
||||
{
|
||||
if (this->runState == CANNED_MESSAGE_RUN_STATE_ACTIVE) {
|
||||
this->lastTouchMillis = millis();
|
||||
this->notifyObservers(&e);
|
||||
return INACTIVATE_AFTER_MS;
|
||||
@@ -252,22 +200,21 @@ int32_t CannedMessageModule::runOnce()
|
||||
return 30000; // TODO: should return MAX_VAL
|
||||
}
|
||||
|
||||
const char* CannedMessageModule::getCurrentMessage()
|
||||
const char *CannedMessageModule::getCurrentMessage()
|
||||
{
|
||||
return this->messages[this->currentMessageIndex];
|
||||
}
|
||||
const char* CannedMessageModule::getPrevMessage()
|
||||
const char *CannedMessageModule::getPrevMessage()
|
||||
{
|
||||
return this->messages[this->getPrevIndex()];
|
||||
}
|
||||
const char* CannedMessageModule::getNextMessage()
|
||||
const char *CannedMessageModule::getNextMessage()
|
||||
{
|
||||
return this->messages[this->getNextIndex()];
|
||||
}
|
||||
bool CannedMessageModule::shouldDraw()
|
||||
{
|
||||
if (!radioConfig.preferences.canned_message_module_enabled)
|
||||
{
|
||||
if (!moduleConfig.payloadVariant.canned_message.enabled) {
|
||||
return false;
|
||||
}
|
||||
return (currentMessageIndex != -1) || (this->runState != CANNED_MESSAGE_RUN_STATE_INACTIVE);
|
||||
@@ -275,47 +222,35 @@ bool CannedMessageModule::shouldDraw()
|
||||
|
||||
int CannedMessageModule::getNextIndex()
|
||||
{
|
||||
if (this->currentMessageIndex >= (this->messagesCount -1))
|
||||
{
|
||||
if (this->currentMessageIndex >= (this->messagesCount - 1)) {
|
||||
return 0;
|
||||
}
|
||||
else
|
||||
{
|
||||
} else {
|
||||
return this->currentMessageIndex + 1;
|
||||
}
|
||||
}
|
||||
|
||||
int CannedMessageModule::getPrevIndex()
|
||||
{
|
||||
if (this->currentMessageIndex <= 0)
|
||||
{
|
||||
if (this->currentMessageIndex <= 0) {
|
||||
return this->messagesCount - 1;
|
||||
}
|
||||
else
|
||||
{
|
||||
} else {
|
||||
return this->currentMessageIndex - 1;
|
||||
}
|
||||
}
|
||||
|
||||
void CannedMessageModule::drawFrame(
|
||||
OLEDDisplay *display, OLEDDisplayUiState *state, int16_t x, int16_t y)
|
||||
void CannedMessageModule::drawFrame(OLEDDisplay *display, OLEDDisplayUiState *state, int16_t x, int16_t y)
|
||||
{
|
||||
displayedNodeNum = 0; // Not currently showing a node pane
|
||||
|
||||
if (cannedMessageModule->runState == CANNED_MESSAGE_RUN_STATE_SENDING_ACTIVE)
|
||||
{
|
||||
if (cannedMessageModule->runState == CANNED_MESSAGE_RUN_STATE_SENDING_ACTIVE) {
|
||||
display->setTextAlignment(TEXT_ALIGN_CENTER);
|
||||
display->setFont(FONT_MEDIUM);
|
||||
display->drawString(display->getWidth()/2 + x, 0 + y + 12, "Sending...");
|
||||
}
|
||||
else if (cannedMessageModule->runState == CANNED_MESSAGE_RUN_STATE_DISABLED)
|
||||
{
|
||||
display->drawString(display->getWidth() / 2 + x, 0 + y + 12, "Sending...");
|
||||
} else if (cannedMessageModule->runState == CANNED_MESSAGE_RUN_STATE_DISABLED) {
|
||||
display->setTextAlignment(TEXT_ALIGN_LEFT);
|
||||
display->setFont(FONT_SMALL);
|
||||
display->drawString(10 + x, 0 + y + 16, "Canned Message\nModule disabled.");
|
||||
}
|
||||
else
|
||||
{
|
||||
} else {
|
||||
display->setTextAlignment(TEXT_ALIGN_LEFT);
|
||||
display->setFont(FONT_SMALL);
|
||||
display->drawString(0 + x, 0 + y, cannedMessageModule->getPrevMessage());
|
||||
@@ -328,7 +263,8 @@ void CannedMessageModule::drawFrame(
|
||||
|
||||
void CannedMessageModule::loadProtoForModule()
|
||||
{
|
||||
if (!loadProto(cannedMessagesConfigFile, CannedMessageModuleConfig_size, sizeof(cannedMessagesConfigFile), CannedMessageModuleConfig_fields, &cannedMessageModuleConfig)) {
|
||||
if (!loadProto(cannedMessagesConfigFile, CannedMessageModuleConfig_size, sizeof(cannedMessagesConfigFile),
|
||||
CannedMessageModuleConfig_fields, &cannedMessageModuleConfig)) {
|
||||
installDefaultCannedMessageModuleConfig();
|
||||
}
|
||||
}
|
||||
@@ -347,7 +283,8 @@ bool CannedMessageModule::saveProtoForModule()
|
||||
FS.mkdir("/prefs");
|
||||
#endif
|
||||
|
||||
okay &= saveProto(cannedMessagesConfigFile, CannedMessageModuleConfig_size, sizeof(CannedMessageModuleConfig), CannedMessageModuleConfig_fields, &cannedMessageModuleConfig);
|
||||
okay &= saveProto(cannedMessagesConfigFile, CannedMessageModuleConfig_size, sizeof(CannedMessageModuleConfig),
|
||||
CannedMessageModuleConfig_fields, &cannedMessageModuleConfig);
|
||||
|
||||
return okay;
|
||||
}
|
||||
@@ -372,8 +309,8 @@ void CannedMessageModule::installDefaultCannedMessageModuleConfig()
|
||||
* @return AdminMessageHandleResult HANDLED if message was handled
|
||||
* HANDLED_WITH_RESULT if a result is also prepared.
|
||||
*/
|
||||
AdminMessageHandleResult CannedMessageModule::handleAdminMessageForModule(
|
||||
const MeshPacket &mp, AdminMessage *request, AdminMessage *response)
|
||||
AdminMessageHandleResult CannedMessageModule::handleAdminMessageForModule(const MeshPacket &mp, AdminMessage *request,
|
||||
AdminMessage *response)
|
||||
{
|
||||
AdminMessageHandleResult result;
|
||||
|
||||
@@ -404,29 +341,25 @@ AdminMessageHandleResult CannedMessageModule::handleAdminMessageForModule(
|
||||
|
||||
case AdminMessage_set_canned_message_module_part1_tag:
|
||||
DEBUG_MSG("Client is setting radio canned message part 1\n");
|
||||
this->handleSetCannedMessageModulePart1(
|
||||
request->set_canned_message_module_part1);
|
||||
this->handleSetCannedMessageModulePart1(request->set_canned_message_module_part1);
|
||||
result = AdminMessageHandleResult::HANDLED;
|
||||
break;
|
||||
|
||||
case AdminMessage_set_canned_message_module_part2_tag:
|
||||
DEBUG_MSG("Client is setting radio canned message part 2\n");
|
||||
this->handleSetCannedMessageModulePart2(
|
||||
request->set_canned_message_module_part2);
|
||||
this->handleSetCannedMessageModulePart2(request->set_canned_message_module_part2);
|
||||
result = AdminMessageHandleResult::HANDLED;
|
||||
break;
|
||||
|
||||
case AdminMessage_set_canned_message_module_part3_tag:
|
||||
DEBUG_MSG("Client is setting radio canned message part 3\n");
|
||||
this->handleSetCannedMessageModulePart3(
|
||||
request->set_canned_message_module_part3);
|
||||
this->handleSetCannedMessageModulePart3(request->set_canned_message_module_part3);
|
||||
result = AdminMessageHandleResult::HANDLED;
|
||||
break;
|
||||
|
||||
case AdminMessage_set_canned_message_module_part4_tag:
|
||||
DEBUG_MSG("Client is setting radio canned message part 4\n");
|
||||
this->handleSetCannedMessageModulePart4(
|
||||
request->set_canned_message_module_part4);
|
||||
this->handleSetCannedMessageModulePart4(request->set_canned_message_module_part4);
|
||||
result = AdminMessageHandleResult::HANDLED;
|
||||
break;
|
||||
|
||||
@@ -437,67 +370,53 @@ AdminMessageHandleResult CannedMessageModule::handleAdminMessageForModule(
|
||||
return result;
|
||||
}
|
||||
|
||||
void CannedMessageModule::handleGetCannedMessageModulePart1(
|
||||
const MeshPacket &req, AdminMessage *response)
|
||||
void CannedMessageModule::handleGetCannedMessageModulePart1(const MeshPacket &req, AdminMessage *response)
|
||||
{
|
||||
DEBUG_MSG("*** handleGetCannedMessageModulePart1\n");
|
||||
assert(req.decoded.want_response);
|
||||
|
||||
response->which_variant = AdminMessage_get_canned_message_module_part1_response_tag;
|
||||
strcpy(
|
||||
response->get_canned_message_module_part1_response,
|
||||
cannedMessageModuleConfig.messagesPart1);
|
||||
strcpy(response->get_canned_message_module_part1_response, cannedMessageModuleConfig.messagesPart1);
|
||||
}
|
||||
|
||||
void CannedMessageModule::handleGetCannedMessageModulePart2(
|
||||
const MeshPacket &req, AdminMessage *response)
|
||||
void CannedMessageModule::handleGetCannedMessageModulePart2(const MeshPacket &req, AdminMessage *response)
|
||||
{
|
||||
DEBUG_MSG("*** handleGetCannedMessageModulePart2\n");
|
||||
assert(req.decoded.want_response);
|
||||
|
||||
response->which_variant = AdminMessage_get_canned_message_module_part2_response_tag;
|
||||
strcpy(
|
||||
response->get_canned_message_module_part2_response,
|
||||
cannedMessageModuleConfig.messagesPart2);
|
||||
strcpy(response->get_canned_message_module_part2_response, cannedMessageModuleConfig.messagesPart2);
|
||||
}
|
||||
|
||||
void CannedMessageModule::handleGetCannedMessageModulePart3(
|
||||
const MeshPacket &req, AdminMessage *response)
|
||||
void CannedMessageModule::handleGetCannedMessageModulePart3(const MeshPacket &req, AdminMessage *response)
|
||||
{
|
||||
DEBUG_MSG("*** handleGetCannedMessageModulePart3\n");
|
||||
assert(req.decoded.want_response);
|
||||
|
||||
response->which_variant = AdminMessage_get_canned_message_module_part3_response_tag;
|
||||
strcpy(
|
||||
response->get_canned_message_module_part3_response,
|
||||
cannedMessageModuleConfig.messagesPart3);
|
||||
strcpy(response->get_canned_message_module_part3_response, cannedMessageModuleConfig.messagesPart3);
|
||||
}
|
||||
|
||||
void CannedMessageModule::handleGetCannedMessageModulePart4(
|
||||
const MeshPacket &req, AdminMessage *response)
|
||||
void CannedMessageModule::handleGetCannedMessageModulePart4(const MeshPacket &req, AdminMessage *response)
|
||||
{
|
||||
DEBUG_MSG("*** handleGetCannedMessageModulePart4\n");
|
||||
assert(req.decoded.want_response);
|
||||
|
||||
response->which_variant = AdminMessage_get_canned_message_module_part4_response_tag;
|
||||
strcpy(
|
||||
response->get_canned_message_module_part4_response,
|
||||
cannedMessageModuleConfig.messagesPart4);
|
||||
strcpy(response->get_canned_message_module_part4_response, cannedMessageModuleConfig.messagesPart4);
|
||||
}
|
||||
|
||||
void CannedMessageModule::handleSetCannedMessageModulePart1(const char *from_msg)
|
||||
{
|
||||
int changed = 0;
|
||||
|
||||
if (*from_msg)
|
||||
{
|
||||
if (*from_msg) {
|
||||
changed |= strcmp(cannedMessageModuleConfig.messagesPart1, from_msg);
|
||||
strcpy(cannedMessageModuleConfig.messagesPart1, from_msg);
|
||||
DEBUG_MSG("*** from_msg.text:%s\n", from_msg);
|
||||
}
|
||||
|
||||
if (changed)
|
||||
{
|
||||
if (changed) {
|
||||
this->saveProtoForModule();
|
||||
}
|
||||
}
|
||||
@@ -506,14 +425,12 @@ void CannedMessageModule::handleSetCannedMessageModulePart2(const char *from_msg
|
||||
{
|
||||
int changed = 0;
|
||||
|
||||
if (*from_msg)
|
||||
{
|
||||
if (*from_msg) {
|
||||
changed |= strcmp(cannedMessageModuleConfig.messagesPart2, from_msg);
|
||||
strcpy(cannedMessageModuleConfig.messagesPart2, from_msg);
|
||||
}
|
||||
|
||||
if (changed)
|
||||
{
|
||||
if (changed) {
|
||||
this->saveProtoForModule();
|
||||
}
|
||||
}
|
||||
@@ -522,14 +439,12 @@ void CannedMessageModule::handleSetCannedMessageModulePart3(const char *from_msg
|
||||
{
|
||||
int changed = 0;
|
||||
|
||||
if (*from_msg)
|
||||
{
|
||||
if (*from_msg) {
|
||||
changed |= strcmp(cannedMessageModuleConfig.messagesPart3, from_msg);
|
||||
strcpy(cannedMessageModuleConfig.messagesPart3, from_msg);
|
||||
}
|
||||
|
||||
if (changed)
|
||||
{
|
||||
if (changed) {
|
||||
this->saveProtoForModule();
|
||||
}
|
||||
}
|
||||
@@ -538,14 +453,12 @@ void CannedMessageModule::handleSetCannedMessageModulePart4(const char *from_msg
|
||||
{
|
||||
int changed = 0;
|
||||
|
||||
if (*from_msg)
|
||||
{
|
||||
if (*from_msg) {
|
||||
changed |= strcmp(cannedMessageModuleConfig.messagesPart4, from_msg);
|
||||
strcpy(cannedMessageModuleConfig.messagesPart4, from_msg);
|
||||
}
|
||||
|
||||
if (changed)
|
||||
{
|
||||
if (changed) {
|
||||
this->saveProtoForModule();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,9 +1,9 @@
|
||||
#include "configuration.h"
|
||||
#include "ExternalNotificationModule.h"
|
||||
#include "MeshService.h"
|
||||
#include "NodeDB.h"
|
||||
#include "RTC.h"
|
||||
#include "Router.h"
|
||||
#include "configuration.h"
|
||||
#include <Arduino.h>
|
||||
|
||||
//#include <assert.h>
|
||||
@@ -19,26 +19,26 @@
|
||||
|
||||
Quick reference:
|
||||
|
||||
radioConfig.preferences.ext_notification_module_enabled
|
||||
moduleConfig.payloadVariant.external_notification.enabled
|
||||
0 = Disabled (Default)
|
||||
1 = Enabled
|
||||
|
||||
radioConfig.preferences.ext_notification_module_active
|
||||
moduleConfig.payloadVariant.external_notification.active
|
||||
0 = Active Low (Default)
|
||||
1 = Active High
|
||||
|
||||
radioConfig.preferences.ext_notification_module_alert_message
|
||||
moduleConfig.payloadVariant.external_notification.alert_message
|
||||
0 = Disabled (Default)
|
||||
1 = Alert when a text message comes
|
||||
|
||||
radioConfig.preferences.ext_notification_module_alert_bell
|
||||
moduleConfig.payloadVariant.external_notification.alert_bell
|
||||
0 = Disabled (Default)
|
||||
1 = Alert when the bell character is received
|
||||
|
||||
radioConfig.preferences.ext_notification_module_output
|
||||
moduleConfig.payloadVariant.external_notification.output
|
||||
GPIO of the output. (Default = 13)
|
||||
|
||||
radioConfig.preferences.ext_notification_module_output_ms
|
||||
moduleConfig.payloadVariant.external_notification.output_ms
|
||||
Amount of time in ms for the alert. Default is 1000.
|
||||
|
||||
*/
|
||||
@@ -59,19 +59,19 @@ int32_t ExternalNotificationModule::runOnce()
|
||||
without having to configure it from the PythonAPI or WebUI.
|
||||
*/
|
||||
|
||||
// radioConfig.preferences.ext_notification_module_enabled = 1;
|
||||
// radioConfig.preferences.ext_notification_module_alert_message = 1;
|
||||
// moduleConfig.payloadVariant.external_notification.enabled = 1;
|
||||
// moduleConfig.payloadVariant.external_notification.alert_message = 1;
|
||||
|
||||
// radioConfig.preferences.ext_notification_module_active = 1;
|
||||
// radioConfig.preferences.ext_notification_module_alert_bell = 1;
|
||||
// radioConfig.preferences.ext_notification_module_output_ms = 1000;
|
||||
// radioConfig.preferences.ext_notification_module_output = 13;
|
||||
// moduleConfig.payloadVariant.external_notification.active = 1;
|
||||
// moduleConfig.payloadVariant.external_notification.alert_bell = 1;
|
||||
// moduleConfig.payloadVariant.external_notification.output_ms = 1000;
|
||||
// moduleConfig.payloadVariant.external_notification.output = 13;
|
||||
|
||||
if (externalCurrentState) {
|
||||
|
||||
// If the output is turned on, turn it back off after the given period of time.
|
||||
if (externalTurnedOn + (radioConfig.preferences.ext_notification_module_output_ms
|
||||
? radioConfig.preferences.ext_notification_module_output_ms
|
||||
if (externalTurnedOn + (moduleConfig.payloadVariant.external_notification.output_ms
|
||||
? moduleConfig.payloadVariant.external_notification.output_ms
|
||||
: EXT_NOTIFICATION_MODULE_OUTPUT_MS) <
|
||||
millis()) {
|
||||
DEBUG_MSG("Turning off external notification\n");
|
||||
@@ -84,59 +84,62 @@ int32_t ExternalNotificationModule::runOnce()
|
||||
|
||||
void ExternalNotificationModule::setExternalOn()
|
||||
{
|
||||
#ifdef EXT_NOTIFY_OUT
|
||||
#ifdef EXT_NOTIFY_OUT
|
||||
externalCurrentState = 1;
|
||||
externalTurnedOn = millis();
|
||||
|
||||
digitalWrite((radioConfig.preferences.ext_notification_module_output ? radioConfig.preferences.ext_notification_module_output
|
||||
: EXT_NOTIFICATION_MODULE_OUTPUT),
|
||||
(radioConfig.preferences.ext_notification_module_active ? true : false));
|
||||
#endif
|
||||
digitalWrite((moduleConfig.payloadVariant.external_notification.output
|
||||
? moduleConfig.payloadVariant.external_notification.output
|
||||
: EXT_NOTIFICATION_MODULE_OUTPUT),
|
||||
(moduleConfig.payloadVariant.external_notification.active ? true : false));
|
||||
#endif
|
||||
}
|
||||
|
||||
void ExternalNotificationModule::setExternalOff()
|
||||
{
|
||||
#ifdef EXT_NOTIFY_OUT
|
||||
#ifdef EXT_NOTIFY_OUT
|
||||
externalCurrentState = 0;
|
||||
|
||||
digitalWrite((radioConfig.preferences.ext_notification_module_output ? radioConfig.preferences.ext_notification_module_output
|
||||
: EXT_NOTIFICATION_MODULE_OUTPUT),
|
||||
(radioConfig.preferences.ext_notification_module_active ? false : true));
|
||||
#endif
|
||||
digitalWrite((moduleConfig.payloadVariant.external_notification.output
|
||||
? moduleConfig.payloadVariant.external_notification.output
|
||||
: EXT_NOTIFICATION_MODULE_OUTPUT),
|
||||
(moduleConfig.payloadVariant.external_notification.active ? false : true));
|
||||
#endif
|
||||
}
|
||||
|
||||
// --------
|
||||
|
||||
ExternalNotificationModule::ExternalNotificationModule()
|
||||
: SinglePortModule("ExternalNotificationModule", PortNum_TEXT_MESSAGE_APP), concurrency::OSThread(
|
||||
"ExternalNotificationModule")
|
||||
"ExternalNotificationModule")
|
||||
{
|
||||
// restrict to the admin channel for rx
|
||||
boundChannel = Channels::gpioChannel;
|
||||
|
||||
#ifndef NO_ESP32
|
||||
#ifdef EXT_NOTIFY_OUT
|
||||
#ifdef EXT_NOTIFY_OUT
|
||||
|
||||
/*
|
||||
Uncomment the preferences below if you want to use the module
|
||||
without having to configure it from the PythonAPI or WebUI.
|
||||
*/
|
||||
|
||||
// radioConfig.preferences.ext_notification_module_enabled = 1;
|
||||
// radioConfig.preferences.ext_notification_module_alert_message = 1;
|
||||
// moduleConfig.payloadVariant.external_notification.enabled = 1;
|
||||
// moduleConfig.payloadVariant.external_notification.alert_message = 1;
|
||||
|
||||
// radioConfig.preferences.ext_notification_module_active = 1;
|
||||
// radioConfig.preferences.ext_notification_module_alert_bell = 1;
|
||||
// radioConfig.preferences.ext_notification_module_output_ms = 1000;
|
||||
// radioConfig.preferences.ext_notification_module_output = 13;
|
||||
// moduleConfig.payloadVariant.external_notification.active = 1;
|
||||
// moduleConfig.payloadVariant.external_notification.alert_bell = 1;
|
||||
// moduleConfig.payloadVariant.external_notification.output_ms = 1000;
|
||||
// moduleConfig.payloadVariant.external_notification.output = 13;
|
||||
|
||||
if (radioConfig.preferences.ext_notification_module_enabled) {
|
||||
if (moduleConfig.payloadVariant.external_notification.enabled) {
|
||||
|
||||
DEBUG_MSG("Initializing External Notification Module\n");
|
||||
|
||||
// Set the direction of a pin
|
||||
pinMode((radioConfig.preferences.ext_notification_module_output ? radioConfig.preferences.ext_notification_module_output
|
||||
: EXT_NOTIFICATION_MODULE_OUTPUT),
|
||||
pinMode((moduleConfig.payloadVariant.external_notification.output
|
||||
? moduleConfig.payloadVariant.external_notification.output
|
||||
: EXT_NOTIFICATION_MODULE_OUTPUT),
|
||||
OUTPUT);
|
||||
|
||||
// Turn off the pin
|
||||
@@ -145,22 +148,22 @@ ExternalNotificationModule::ExternalNotificationModule()
|
||||
DEBUG_MSG("External Notification Module Disabled\n");
|
||||
enabled = false;
|
||||
}
|
||||
#endif
|
||||
#endif
|
||||
#endif
|
||||
}
|
||||
|
||||
ProcessMessage ExternalNotificationModule::handleReceived(const MeshPacket &mp)
|
||||
{
|
||||
#ifndef NO_ESP32
|
||||
#ifdef EXT_NOTIFY_OUT
|
||||
#ifdef EXT_NOTIFY_OUT
|
||||
|
||||
if (radioConfig.preferences.ext_notification_module_enabled) {
|
||||
if (moduleConfig.payloadVariant.external_notification.enabled) {
|
||||
|
||||
if (getFrom(&mp) != nodeDB.getNodeNum()) {
|
||||
|
||||
// TODO: This may be a problem if messages are sent in unicide, but I'm not sure if it will.
|
||||
// Need to know if and how this could be a problem.
|
||||
if (radioConfig.preferences.ext_notification_module_alert_bell) {
|
||||
if (moduleConfig.payloadVariant.external_notification.alert_bell) {
|
||||
auto &p = mp.decoded;
|
||||
DEBUG_MSG("externalNotificationModule - Notification Bell\n");
|
||||
for (int i = 0; i < p.payload.size; i++) {
|
||||
@@ -170,7 +173,7 @@ ProcessMessage ExternalNotificationModule::handleReceived(const MeshPacket &mp)
|
||||
}
|
||||
}
|
||||
|
||||
if (radioConfig.preferences.ext_notification_module_alert_message) {
|
||||
if (moduleConfig.payloadVariant.external_notification.alert_message) {
|
||||
DEBUG_MSG("externalNotificationModule - Notification Module\n");
|
||||
setExternalOn();
|
||||
}
|
||||
@@ -179,7 +182,7 @@ ProcessMessage ExternalNotificationModule::handleReceived(const MeshPacket &mp)
|
||||
} else {
|
||||
DEBUG_MSG("External Notification Module Disabled\n");
|
||||
}
|
||||
#endif
|
||||
#endif
|
||||
|
||||
#endif
|
||||
|
||||
|
||||
@@ -1,9 +1,9 @@
|
||||
#include "configuration.h"
|
||||
#include "NodeInfoModule.h"
|
||||
#include "MeshService.h"
|
||||
#include "NodeDB.h"
|
||||
#include "RTC.h"
|
||||
#include "Router.h"
|
||||
#include "configuration.h"
|
||||
#include "main.h"
|
||||
|
||||
NodeInfoModule *nodeInfoModule;
|
||||
@@ -19,7 +19,7 @@ bool NodeInfoModule::handleReceivedProtobuf(const MeshPacket &mp, User *pptr)
|
||||
// Show new nodes on LCD screen
|
||||
if (wasBroadcast) {
|
||||
String lcd = String("Joined: ") + p.long_name + "\n";
|
||||
if(screen)
|
||||
if (screen)
|
||||
screen->print(lcd.c_str());
|
||||
}
|
||||
|
||||
@@ -69,6 +69,6 @@ int32_t NodeInfoModule::runOnce()
|
||||
DEBUG_MSG("Sending our nodeinfo to mesh (wantReplies=%d)\n", requestReplies);
|
||||
sendOurNodeInfo(NODENUM_BROADCAST, requestReplies); // Send our info (don't request replies)
|
||||
|
||||
return getPref_position_broadcast_secs() * 1000;
|
||||
}
|
||||
|
||||
return config.payloadVariant.position.position_broadcast_secs ? config.payloadVariant.position.position_broadcast_secs
|
||||
: default_broadcast_interval_secs * 1000;
|
||||
}
|
||||
@@ -60,7 +60,7 @@ MeshPacket *PositionModule::allocReply()
|
||||
|
||||
// configuration of POSITION packet
|
||||
// consider making this a function argument?
|
||||
uint32_t pos_flags = radioConfig.preferences.position_flags;
|
||||
uint32_t pos_flags = config.payloadVariant.position.position_flags;
|
||||
|
||||
// Populate a Position struct with ONLY the requested fields
|
||||
Position p = Position_init_default; // Start with an empty structure
|
||||
@@ -70,28 +70,28 @@ MeshPacket *PositionModule::allocReply()
|
||||
p.longitude_i = node->position.longitude_i;
|
||||
p.time = node->position.time;
|
||||
|
||||
if (pos_flags & PositionFlags_POS_ALTITUDE) {
|
||||
if (pos_flags & PositionFlags_POS_ALT_MSL)
|
||||
if (pos_flags & Config_PositionConfig_PositionFlags_POS_ALTITUDE) {
|
||||
if (pos_flags & Config_PositionConfig_PositionFlags_POS_ALT_MSL)
|
||||
p.altitude = node->position.altitude;
|
||||
else
|
||||
p.altitude_hae = node->position.altitude_hae;
|
||||
|
||||
if (pos_flags & PositionFlags_POS_GEO_SEP)
|
||||
if (pos_flags & Config_PositionConfig_PositionFlags_POS_GEO_SEP)
|
||||
p.alt_geoid_sep = node->position.alt_geoid_sep;
|
||||
}
|
||||
|
||||
if (pos_flags & PositionFlags_POS_DOP) {
|
||||
if (pos_flags & PositionFlags_POS_HVDOP) {
|
||||
if (pos_flags & Config_PositionConfig_PositionFlags_POS_DOP) {
|
||||
if (pos_flags & Config_PositionConfig_PositionFlags_POS_HVDOP) {
|
||||
p.HDOP = node->position.HDOP;
|
||||
p.VDOP = node->position.VDOP;
|
||||
} else
|
||||
p.PDOP = node->position.PDOP;
|
||||
}
|
||||
|
||||
if (pos_flags & PositionFlags_POS_SATINVIEW)
|
||||
if (pos_flags & Config_PositionConfig_PositionFlags_POS_SATINVIEW)
|
||||
p.sats_in_view = node->position.sats_in_view;
|
||||
|
||||
if (pos_flags & PositionFlags_POS_TIMESTAMP)
|
||||
if (pos_flags & Config_PositionConfig_PositionFlags_POS_TIMESTAMP)
|
||||
p.pos_timestamp = node->position.pos_timestamp;
|
||||
|
||||
// Strip out any time information before sending packets to other nodes - to keep the wire size small (and because other
|
||||
@@ -127,7 +127,9 @@ int32_t PositionModule::runOnce()
|
||||
|
||||
// We limit our GPS broadcasts to a max rate
|
||||
uint32_t now = millis();
|
||||
if (lastGpsSend == 0 || now - lastGpsSend >= getPref_position_broadcast_secs() * 1000) {
|
||||
if (lastGpsSend == 0 || now - lastGpsSend >= config.payloadVariant.position.position_broadcast_secs
|
||||
? config.payloadVariant.position.position_broadcast_secs
|
||||
: default_broadcast_interval_secs * 1000) {
|
||||
|
||||
// Only send packets if the channel is less than 40% utilized.
|
||||
if (airTime->channelUtilizationPercent() < 40) {
|
||||
@@ -149,7 +151,7 @@ int32_t PositionModule::runOnce()
|
||||
DEBUG_MSG("Channel utilization is >50 percent. Skipping this opportunity to send.\n");
|
||||
}
|
||||
|
||||
} else if (!radioConfig.preferences.position_broadcast_smart_disabled) {
|
||||
} else if (!config.payloadVariant.position.position_broadcast_smart_disabled) {
|
||||
|
||||
// Only send packets if the channel is less than 25% utilized.
|
||||
if (airTime->channelUtilizationPercent() < 25) {
|
||||
|
||||
@@ -1,8 +1,8 @@
|
||||
#include "DeviceTelemetry.h"
|
||||
#include "../mesh/generated/telemetry.pb.h"
|
||||
#include "PowerFSM.h"
|
||||
#include "MeshService.h"
|
||||
#include "NodeDB.h"
|
||||
#include "PowerFSM.h"
|
||||
#include "RTC.h"
|
||||
#include "Router.h"
|
||||
#include "configuration.h"
|
||||
@@ -20,8 +20,8 @@ int32_t DeviceTelemetryModule::runOnce()
|
||||
}
|
||||
sendOurTelemetry();
|
||||
// OSThread library. Multiply the preference value by 1000 to convert seconds to miliseconds
|
||||
|
||||
return getIntervalOrDefaultMs(moduleConfig.device_update_interval);
|
||||
|
||||
return getIntervalOrDefaultMs(moduleConfig.payloadVariant.telemetry.device_update_interval);
|
||||
#endif
|
||||
}
|
||||
|
||||
@@ -33,7 +33,7 @@ bool DeviceTelemetryModule::handleReceivedProtobuf(const MeshPacket &mp, Telemet
|
||||
DEBUG_MSG("-----------------------------------------\n");
|
||||
DEBUG_MSG("Device Telemetry: Received data from %s\n", sender);
|
||||
DEBUG_MSG("Telemetry->time: %i\n", t->time);
|
||||
DEBUG_MSG("Telemetry->air_util_tx: %f\n", t->variant.device_metrics.air_util_tx );
|
||||
DEBUG_MSG("Telemetry->air_util_tx: %f\n", t->variant.device_metrics.air_util_tx);
|
||||
DEBUG_MSG("Telemetry->battery_level: %i\n", t->variant.device_metrics.battery_level);
|
||||
DEBUG_MSG("Telemetry->channel_utilization: %f\n", t->variant.device_metrics.channel_utilization);
|
||||
DEBUG_MSG("Telemetry->voltage: %f\n", t->variant.device_metrics.voltage);
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
#pragma once
|
||||
#include "../mesh/generated/telemetry.pb.h"
|
||||
#include "ProtobufModule.h"
|
||||
#include "NodeDB.h"
|
||||
#include "ProtobufModule.h"
|
||||
#include <OLEDDisplay.h>
|
||||
#include <OLEDDisplayUi.h>
|
||||
|
||||
@@ -9,8 +9,7 @@ class DeviceTelemetryModule : private concurrency::OSThread, public ProtobufModu
|
||||
{
|
||||
public:
|
||||
DeviceTelemetryModule()
|
||||
: concurrency::OSThread("DeviceTelemetryModule"),
|
||||
ProtobufModule("DeviceTelemetry", PortNum_TELEMETRY_APP, &Telemetry_msg)
|
||||
: concurrency::OSThread("DeviceTelemetryModule"), ProtobufModule("DeviceTelemetry", PortNum_TELEMETRY_APP, &Telemetry_msg)
|
||||
{
|
||||
lastMeasurementPacket = nullptr;
|
||||
}
|
||||
@@ -28,7 +27,6 @@ class DeviceTelemetryModule : private concurrency::OSThread, public ProtobufModu
|
||||
bool sendOurTelemetry(NodeNum dest = NODENUM_BROADCAST, bool wantReplies = false);
|
||||
|
||||
private:
|
||||
Config_ModuleConfig_TelemetryConfig moduleConfig = config.payloadVariant.module_config.payloadVariant.telemetry_config;
|
||||
bool firstTime = 1;
|
||||
const MeshPacket *lastMeasurementPacket;
|
||||
};
|
||||
|
||||
@@ -1,8 +1,8 @@
|
||||
#include "EnvironmentTelemetry.h"
|
||||
#include "../mesh/generated/telemetry.pb.h"
|
||||
#include "PowerFSM.h"
|
||||
#include "MeshService.h"
|
||||
#include "NodeDB.h"
|
||||
#include "PowerFSM.h"
|
||||
#include "RTC.h"
|
||||
#include "Router.h"
|
||||
#include "configuration.h"
|
||||
@@ -50,17 +50,17 @@ int32_t EnvironmentTelemetryModule::runOnce()
|
||||
without having to configure it from the PythonAPI or WebUI.
|
||||
*/
|
||||
/*
|
||||
moduleConfig.environment_measurement_enabled = 1;
|
||||
moduleConfig.environment_screen_enabled = 1;
|
||||
moduleConfig.environment_read_error_count_threshold = 5;
|
||||
moduleConfig.environment_update_interval = 600;
|
||||
moduleConfig.environment_recovery_interval = 60;
|
||||
moduleConfig.environment_sensor_pin = 13; // If one-wire
|
||||
moduleConfig.environment_sensor_type = TelemetrySensorType::TelemetrySensorType_BME280;
|
||||
moduleConfig.payloadVariant.telemetry.environment_measurement_enabled = 1;
|
||||
moduleConfig.payloadVariant.telemetry.environment_screen_enabled = 1;
|
||||
moduleConfig.payloadVariant.telemetry.environment_read_error_count_threshold = 5;
|
||||
moduleConfig.payloadVariant.telemetry.environment_update_interval = 600;
|
||||
moduleConfig.payloadVariant.telemetry.environment_recovery_interval = 60;
|
||||
moduleConfig.payloadVariant.telemetry.environment_sensor_pin = 13; // If one-wire
|
||||
moduleConfig.payloadVariant.telemetry.environment_sensor_type = TelemetrySensorType::TelemetrySensorType_BME280;
|
||||
*/
|
||||
|
||||
if (!(moduleConfig.environment_measurement_enabled ||
|
||||
moduleConfig.environment_screen_enabled)) {
|
||||
|
||||
if (!(moduleConfig.payloadVariant.telemetry.environment_measurement_enabled ||
|
||||
moduleConfig.payloadVariant.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
|
||||
return (INT32_MAX);
|
||||
}
|
||||
@@ -69,82 +69,81 @@ int32_t EnvironmentTelemetryModule::runOnce()
|
||||
// This is the first time the OSThread library has called this function, so do some setup
|
||||
firstTime = 0;
|
||||
|
||||
if (moduleConfig.environment_measurement_enabled) {
|
||||
if (moduleConfig.payloadVariant.telemetry.environment_measurement_enabled) {
|
||||
DEBUG_MSG("Environment Telemetry: Initializing\n");
|
||||
// it's possible to have this module enabled, only for displaying values on the screen.
|
||||
// therefore, we should only enable the sensor loop if measurement is also enabled
|
||||
switch (moduleConfig.environment_sensor_type) {
|
||||
switch (moduleConfig.payloadVariant.telemetry.environment_sensor_type) {
|
||||
|
||||
case TelemetrySensorType_DHT11:
|
||||
case TelemetrySensorType_DHT12:
|
||||
case TelemetrySensorType_DHT21:
|
||||
case TelemetrySensorType_DHT22:
|
||||
return dhtSensor.runOnce();
|
||||
case TelemetrySensorType_DS18B20:
|
||||
return dallasSensor.runOnce();
|
||||
case TelemetrySensorType_BME280:
|
||||
return bme280Sensor.runOnce();
|
||||
case TelemetrySensorType_BME680:
|
||||
return bme680Sensor.runOnce();
|
||||
case TelemetrySensorType_MCP9808:
|
||||
return mcp9808Sensor.runOnce();
|
||||
default:
|
||||
DEBUG_MSG("Environment Telemetry: Invalid sensor type selected; Disabling module");
|
||||
return (INT32_MAX);
|
||||
break;
|
||||
case TelemetrySensorType_DHT11:
|
||||
case TelemetrySensorType_DHT12:
|
||||
case TelemetrySensorType_DHT21:
|
||||
case TelemetrySensorType_DHT22:
|
||||
return dhtSensor.runOnce();
|
||||
case TelemetrySensorType_DS18B20:
|
||||
return dallasSensor.runOnce();
|
||||
case TelemetrySensorType_BME280:
|
||||
return bme280Sensor.runOnce();
|
||||
case TelemetrySensorType_BME680:
|
||||
return bme680Sensor.runOnce();
|
||||
case TelemetrySensorType_MCP9808:
|
||||
return mcp9808Sensor.runOnce();
|
||||
default:
|
||||
DEBUG_MSG("Environment Telemetry: Invalid sensor type selected; Disabling module");
|
||||
return (INT32_MAX);
|
||||
break;
|
||||
}
|
||||
}
|
||||
return (INT32_MAX);
|
||||
} else {
|
||||
// if we somehow got to a second run of this module with measurement disabled, then just wait forever
|
||||
if (!moduleConfig.environment_measurement_enabled)
|
||||
if (!moduleConfig.payloadVariant.telemetry.environment_measurement_enabled)
|
||||
return (INT32_MAX);
|
||||
// this is not the first time OSThread library has called this function
|
||||
// so just do what we intend to do on the interval
|
||||
if (sensor_read_error_count > moduleConfig.environment_read_error_count_threshold) {
|
||||
if (moduleConfig.environment_recovery_interval > 0) {
|
||||
if (sensor_read_error_count > moduleConfig.payloadVariant.telemetry.environment_read_error_count_threshold) {
|
||||
if (moduleConfig.payloadVariant.telemetry.environment_recovery_interval > 0) {
|
||||
DEBUG_MSG("Environment Telemetry: TEMPORARILY DISABLED; The "
|
||||
"telemetry_module_environment_read_error_count_threshold has been exceed: %d. Will retry reads in "
|
||||
"%d seconds\n",
|
||||
moduleConfig.environment_read_error_count_threshold,
|
||||
moduleConfig.environment_recovery_interval);
|
||||
moduleConfig.payloadVariant.telemetry.environment_read_error_count_threshold,
|
||||
moduleConfig.payloadVariant.telemetry.environment_recovery_interval);
|
||||
sensor_read_error_count = 0;
|
||||
return (moduleConfig.environment_recovery_interval * 1000);
|
||||
return (moduleConfig.payloadVariant.telemetry.environment_recovery_interval * 1000);
|
||||
}
|
||||
DEBUG_MSG("Environment Telemetry: DISABLED; The telemetry_module_environment_read_error_count_threshold has "
|
||||
"been exceed: %d. Reads will not be retried until after device reset\n",
|
||||
moduleConfig.environment_read_error_count_threshold);
|
||||
moduleConfig.payloadVariant.telemetry.environment_read_error_count_threshold);
|
||||
return (INT32_MAX);
|
||||
|
||||
} else if (sensor_read_error_count > 0) {
|
||||
DEBUG_MSG("Environment Telemetry: There have been %d sensor read failures. Will retry %d more times\n",
|
||||
sensor_read_error_count, sensor_read_error_count, sensor_read_error_count,
|
||||
moduleConfig.environment_read_error_count_threshold -
|
||||
sensor_read_error_count);
|
||||
moduleConfig.payloadVariant.telemetry.environment_read_error_count_threshold - sensor_read_error_count);
|
||||
}
|
||||
if (!sendOurTelemetry()) {
|
||||
// if we failed to read the sensor, then try again
|
||||
// as soon as we can according to the maximum polling frequency
|
||||
|
||||
switch (moduleConfig.environment_sensor_type) {
|
||||
case TelemetrySensorType_DHT11:
|
||||
case TelemetrySensorType_DHT12:
|
||||
case TelemetrySensorType_DHT21:
|
||||
case TelemetrySensorType_DHT22:
|
||||
return (DHT_SENSOR_MINIMUM_WAIT_TIME_BETWEEN_READS);
|
||||
case TelemetrySensorType_DS18B20:
|
||||
return (DS18B20_SENSOR_MINIMUM_WAIT_TIME_BETWEEN_READS);
|
||||
case TelemetrySensorType_BME280:
|
||||
case TelemetrySensorType_BME680:
|
||||
return (BME_SENSOR_MINIMUM_WAIT_TIME_BETWEEN_READS);
|
||||
case TelemetrySensorType_MCP9808:
|
||||
return (MCP_SENSOR_MINIMUM_WAIT_TIME_BETWEEN_READS);
|
||||
default:
|
||||
return (DEFAULT_SENSOR_MINIMUM_WAIT_TIME_BETWEEN_READS);
|
||||
switch (moduleConfig.payloadVariant.telemetry.environment_sensor_type) {
|
||||
case TelemetrySensorType_DHT11:
|
||||
case TelemetrySensorType_DHT12:
|
||||
case TelemetrySensorType_DHT21:
|
||||
case TelemetrySensorType_DHT22:
|
||||
return (DHT_SENSOR_MINIMUM_WAIT_TIME_BETWEEN_READS);
|
||||
case TelemetrySensorType_DS18B20:
|
||||
return (DS18B20_SENSOR_MINIMUM_WAIT_TIME_BETWEEN_READS);
|
||||
case TelemetrySensorType_BME280:
|
||||
case TelemetrySensorType_BME680:
|
||||
return (BME_SENSOR_MINIMUM_WAIT_TIME_BETWEEN_READS);
|
||||
case TelemetrySensorType_MCP9808:
|
||||
return (MCP_SENSOR_MINIMUM_WAIT_TIME_BETWEEN_READS);
|
||||
default:
|
||||
return (DEFAULT_SENSOR_MINIMUM_WAIT_TIME_BETWEEN_READS);
|
||||
}
|
||||
}
|
||||
}
|
||||
return getIntervalOrDefaultMs(moduleConfig.environment_update_interval);
|
||||
return getIntervalOrDefaultMs(moduleConfig.payloadVariant.telemetry.environment_update_interval);
|
||||
#endif
|
||||
}
|
||||
|
||||
@@ -162,7 +161,7 @@ uint32_t GetTimeSinceMeshPacket(const MeshPacket *mp)
|
||||
|
||||
bool EnvironmentTelemetryModule::wantUIFrame()
|
||||
{
|
||||
return moduleConfig.environment_screen_enabled;
|
||||
return moduleConfig.payloadVariant.telemetry.environment_screen_enabled;
|
||||
}
|
||||
|
||||
float EnvironmentTelemetryModule::CelsiusToFahrenheit(float c)
|
||||
@@ -196,13 +195,16 @@ void EnvironmentTelemetryModule::drawFrame(OLEDDisplay *display, OLEDDisplayUiSt
|
||||
|
||||
display->setFont(FONT_SMALL);
|
||||
String last_temp = String(lastMeasurement.variant.environment_metrics.temperature, 0) + "°C";
|
||||
if (moduleConfig.environment_display_fahrenheit) {
|
||||
if (moduleConfig.payloadVariant.telemetry.environment_display_fahrenheit) {
|
||||
last_temp = String(CelsiusToFahrenheit(lastMeasurement.variant.environment_metrics.temperature), 0) + "°F";
|
||||
}
|
||||
display->drawString(x, y += fontHeight(FONT_MEDIUM) - 2, "From: " + String(lastSender) + "(" + String(agoSecs) + "s)");
|
||||
display->drawString(x, y += fontHeight(FONT_SMALL) - 2, "Temp/Hum: " + last_temp + " / " + String(lastMeasurement.variant.environment_metrics.relative_humidity, 0) + "%");
|
||||
if (lastMeasurement.variant.environment_metrics.barometric_pressure != 0)
|
||||
display->drawString(x, y += fontHeight(FONT_SMALL), "Press: " + String(lastMeasurement.variant.environment_metrics.barometric_pressure, 0) + "hPA");
|
||||
display->drawString(x, y += fontHeight(FONT_SMALL) - 2,
|
||||
"Temp/Hum: " + last_temp + " / " +
|
||||
String(lastMeasurement.variant.environment_metrics.relative_humidity, 0) + "%");
|
||||
if (lastMeasurement.variant.environment_metrics.barometric_pressure != 0)
|
||||
display->drawString(x, y += fontHeight(FONT_SMALL),
|
||||
"Press: " + String(lastMeasurement.variant.environment_metrics.barometric_pressure, 0) + "hPA");
|
||||
}
|
||||
|
||||
bool EnvironmentTelemetryModule::handleReceivedProtobuf(const MeshPacket &mp, Telemetry *t)
|
||||
@@ -238,33 +240,33 @@ bool EnvironmentTelemetryModule::sendOurTelemetry(NodeNum dest, bool wantReplies
|
||||
m.variant.environment_metrics.relative_humidity = 0;
|
||||
m.variant.environment_metrics.temperature = 0;
|
||||
m.variant.environment_metrics.voltage = 0;
|
||||
|
||||
|
||||
DEBUG_MSG("-----------------------------------------\n");
|
||||
DEBUG_MSG("Environment Telemetry: Read data\n");
|
||||
|
||||
switch (moduleConfig.environment_sensor_type) {
|
||||
case TelemetrySensorType_DS18B20:
|
||||
if (!dallasSensor.getMeasurement(&m))
|
||||
sensor_read_error_count++;
|
||||
break;
|
||||
case TelemetrySensorType_DHT11:
|
||||
case TelemetrySensorType_DHT12:
|
||||
case TelemetrySensorType_DHT21:
|
||||
case TelemetrySensorType_DHT22:
|
||||
if (!dhtSensor.getMeasurement(&m))
|
||||
sensor_read_error_count++;
|
||||
break;
|
||||
case TelemetrySensorType_BME280:
|
||||
bme280Sensor.getMeasurement(&m);
|
||||
break;
|
||||
case TelemetrySensorType_BME680:
|
||||
bme680Sensor.getMeasurement(&m);
|
||||
break;
|
||||
case TelemetrySensorType_MCP9808:
|
||||
mcp9808Sensor.getMeasurement(&m);
|
||||
break;
|
||||
default:
|
||||
DEBUG_MSG("Environment Telemetry: No external sensor type selected; Only sending internal metrics\n");
|
||||
switch (moduleConfig.payloadVariant.telemetry.environment_sensor_type) {
|
||||
case TelemetrySensorType_DS18B20:
|
||||
if (!dallasSensor.getMeasurement(&m))
|
||||
sensor_read_error_count++;
|
||||
break;
|
||||
case TelemetrySensorType_DHT11:
|
||||
case TelemetrySensorType_DHT12:
|
||||
case TelemetrySensorType_DHT21:
|
||||
case TelemetrySensorType_DHT22:
|
||||
if (!dhtSensor.getMeasurement(&m))
|
||||
sensor_read_error_count++;
|
||||
break;
|
||||
case TelemetrySensorType_BME280:
|
||||
bme280Sensor.getMeasurement(&m);
|
||||
break;
|
||||
case TelemetrySensorType_BME680:
|
||||
bme680Sensor.getMeasurement(&m);
|
||||
break;
|
||||
case TelemetrySensorType_MCP9808:
|
||||
mcp9808Sensor.getMeasurement(&m);
|
||||
break;
|
||||
default:
|
||||
DEBUG_MSG("Environment Telemetry: No external sensor type selected; Only sending internal metrics\n");
|
||||
}
|
||||
|
||||
DEBUG_MSG("Telemetry->time: %i\n", m.time);
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
#pragma once
|
||||
#include "../mesh/generated/telemetry.pb.h"
|
||||
#include "ProtobufModule.h"
|
||||
#include "NodeDB.h"
|
||||
#include "ProtobufModule.h"
|
||||
#include <OLEDDisplay.h>
|
||||
#include <OLEDDisplayUi.h>
|
||||
|
||||
@@ -15,7 +15,7 @@ class EnvironmentTelemetryModule : private concurrency::OSThread, public Protobu
|
||||
lastMeasurementPacket = nullptr;
|
||||
}
|
||||
virtual bool wantUIFrame() override;
|
||||
#ifdef NO_SCREEN
|
||||
#ifdef NO_SCREEN
|
||||
void drawFrame(OLEDDisplay *display, OLEDDisplayUiState *state, int16_t x, int16_t y);
|
||||
#else
|
||||
virtual void drawFrame(OLEDDisplay *display, OLEDDisplayUiState *state, int16_t x, int16_t y) override;
|
||||
@@ -33,7 +33,6 @@ class EnvironmentTelemetryModule : private concurrency::OSThread, public Protobu
|
||||
bool sendOurTelemetry(NodeNum dest = NODENUM_BROADCAST, bool wantReplies = false);
|
||||
|
||||
private:
|
||||
Config_ModuleConfig_TelemetryConfig moduleConfig = config.payloadVariant.module_config.payloadVariant.telemetry_config;
|
||||
float CelsiusToFahrenheit(float c);
|
||||
bool firstTime = 1;
|
||||
const MeshPacket *lastMeasurementPacket;
|
||||
|
||||
@@ -1,31 +1,29 @@
|
||||
#include "../mesh/generated/telemetry.pb.h"
|
||||
#include "configuration.h"
|
||||
#include "DHTSensor.h"
|
||||
#include "./mesh/generated/telemetry.pb.h"
|
||||
#include "MeshService.h"
|
||||
#include "TelemetrySensor.h"
|
||||
#include "DHTSensor.h"
|
||||
#include "configuration.h"
|
||||
#include <DHT.h>
|
||||
|
||||
DHTSensor::DHTSensor() : TelemetrySensor {} {
|
||||
}
|
||||
DHTSensor::DHTSensor() : TelemetrySensor{} {}
|
||||
|
||||
int32_t DHTSensor::runOnce() {
|
||||
if (TelemetrySensorType_DHT11 ||
|
||||
TelemetrySensorType_DHT12) {
|
||||
dht = new DHT(moduleConfig.environment_sensor_pin, DHT11);
|
||||
}
|
||||
else {
|
||||
dht = new DHT(moduleConfig.environment_sensor_pin, DHT22);
|
||||
int32_t DHTSensor::runOnce()
|
||||
{
|
||||
if (TelemetrySensorType_DHT11 || TelemetrySensorType_DHT12) {
|
||||
dht = new DHT(moduleConfig.payloadVariant.telemetry.environment_sensor_pin, DHT11);
|
||||
} else {
|
||||
dht = new DHT(moduleConfig.payloadVariant.telemetry.environment_sensor_pin, DHT22);
|
||||
}
|
||||
|
||||
dht->begin();
|
||||
dht->read();
|
||||
DEBUG_MSG("Telemetry: Opened DHT11/DHT12 on pin: %d\n",
|
||||
moduleConfig.environment_sensor_pin);
|
||||
DEBUG_MSG("Telemetry: Opened DHT11/DHT12 on pin: %d\n", moduleConfig.payloadVariant.telemetry.environment_sensor_pin);
|
||||
|
||||
return (DHT_SENSOR_MINIMUM_WAIT_TIME_BETWEEN_READS);
|
||||
}
|
||||
|
||||
bool DHTSensor::getMeasurement(Telemetry *measurement) {
|
||||
bool DHTSensor::getMeasurement(Telemetry *measurement)
|
||||
{
|
||||
if (!dht->read(true)) {
|
||||
DEBUG_MSG("Telemetry: FAILED TO READ DATA\n");
|
||||
return false;
|
||||
@@ -33,4 +31,4 @@ bool DHTSensor::getMeasurement(Telemetry *measurement) {
|
||||
measurement->variant.environment_metrics.relative_humidity = dht->readHumidity();
|
||||
measurement->variant.environment_metrics.temperature = dht->readTemperature();
|
||||
return true;
|
||||
}
|
||||
}
|
||||
@@ -1,31 +1,31 @@
|
||||
#include "DallasSensor.h"
|
||||
#include "../mesh/generated/telemetry.pb.h"
|
||||
#include "configuration.h"
|
||||
#include "MeshService.h"
|
||||
#include "TelemetrySensor.h"
|
||||
#include "DallasSensor.h"
|
||||
#include "configuration.h"
|
||||
#include <DS18B20.h>
|
||||
#include <OneWire.h>
|
||||
|
||||
DallasSensor::DallasSensor() : TelemetrySensor {} {
|
||||
}
|
||||
DallasSensor::DallasSensor() : TelemetrySensor{} {}
|
||||
|
||||
int32_t DallasSensor::runOnce() {
|
||||
oneWire = new OneWire(moduleConfig.environment_sensor_pin);
|
||||
int32_t DallasSensor::runOnce()
|
||||
{
|
||||
oneWire = new OneWire(moduleConfig.payloadVariant.telemetry.environment_sensor_pin);
|
||||
ds18b20 = new DS18B20(oneWire);
|
||||
ds18b20->begin();
|
||||
ds18b20->setResolution(12);
|
||||
ds18b20->requestTemperatures();
|
||||
DEBUG_MSG("Telemetry: Opened DS18B20 on pin: %d\n",
|
||||
moduleConfig.environment_sensor_pin);
|
||||
DEBUG_MSG("Telemetry: Opened DS18B20 on pin: %d\n", moduleConfig.payloadVariant.telemetry.environment_sensor_pin);
|
||||
return (DS18B20_SENSOR_MINIMUM_WAIT_TIME_BETWEEN_READS);
|
||||
}
|
||||
|
||||
bool DallasSensor::getMeasurement(Telemetry *measurement) {
|
||||
bool DallasSensor::getMeasurement(Telemetry *measurement)
|
||||
{
|
||||
if (ds18b20->isConversionComplete()) {
|
||||
measurement->variant.environment_metrics.temperature = ds18b20->getTempC();
|
||||
measurement->variant.environment_metrics.relative_humidity = 0;
|
||||
ds18b20->requestTemperatures();
|
||||
return true;
|
||||
}
|
||||
}
|
||||
return false;
|
||||
}
|
||||
@@ -3,11 +3,12 @@
|
||||
#include "NodeDB.h"
|
||||
#define DEFAULT_SENSOR_MINIMUM_WAIT_TIME_BETWEEN_READS 1000
|
||||
|
||||
class TelemetrySensor {
|
||||
protected:
|
||||
TelemetrySensor() { }
|
||||
Config_ModuleConfig_TelemetryConfig moduleConfig = config.payloadVariant.module_config.payloadVariant.telemetry_config;
|
||||
public:
|
||||
class TelemetrySensor
|
||||
{
|
||||
protected:
|
||||
TelemetrySensor() {}
|
||||
|
||||
public:
|
||||
virtual int32_t runOnce() = 0;
|
||||
virtual bool getMeasurement(Telemetry *measurement) = 0;
|
||||
virtual bool getMeasurement(Telemetry *measurement) = 0;
|
||||
};
|
||||
|
||||
@@ -36,23 +36,23 @@ int32_t RangeTestModule::runOnce()
|
||||
without having to configure it from the PythonAPI or WebUI.
|
||||
*/
|
||||
|
||||
// radioConfig.preferences.range_test_module_enabled = 1;
|
||||
// radioConfig.preferences.range_test_module_sender = 45;
|
||||
// radioConfig.preferences.range_test_module_save = 1;
|
||||
// moduleConfig.payloadVariant.range_test.enabled = 1;
|
||||
// moduleConfig.payloadVariant.range_test.sender = 45;
|
||||
// moduleConfig.payloadVariant.range_test.save = 1;
|
||||
|
||||
// Fixed position is useful when testing indoors.
|
||||
// radioConfig.preferences.fixed_position = 1;
|
||||
|
||||
uint32_t senderHeartbeat = radioConfig.preferences.range_test_module_sender * 1000;
|
||||
uint32_t senderHeartbeat = moduleConfig.payloadVariant.range_test.sender * 1000;
|
||||
|
||||
if (radioConfig.preferences.range_test_module_enabled) {
|
||||
if (moduleConfig.payloadVariant.range_test.enabled) {
|
||||
|
||||
if (firstTime) {
|
||||
rangeTestModuleRadio = new RangeTestModuleRadio();
|
||||
|
||||
firstTime = 0;
|
||||
|
||||
if (radioConfig.preferences.range_test_module_sender) {
|
||||
if (moduleConfig.payloadVariant.range_test.sender) {
|
||||
DEBUG_MSG("Initializing Range Test Module -- Sender\n");
|
||||
return (5000); // Sending first message 5 seconds after initilization.
|
||||
} else {
|
||||
@@ -62,7 +62,7 @@ int32_t RangeTestModule::runOnce()
|
||||
|
||||
} else {
|
||||
|
||||
if (radioConfig.preferences.range_test_module_sender) {
|
||||
if (moduleConfig.payloadVariant.range_test.sender) {
|
||||
// If sender
|
||||
DEBUG_MSG("Range Test Module - Sending heartbeat every %d ms\n", (senderHeartbeat));
|
||||
|
||||
@@ -71,7 +71,7 @@ int32_t RangeTestModule::runOnce()
|
||||
DEBUG_MSG("gpsStatus->getHasLock() %d\n", gpsStatus->getHasLock());
|
||||
DEBUG_MSG("gpsStatus->getDOP() %d\n", gpsStatus->getDOP());
|
||||
DEBUG_MSG("gpsStatus->getHasLock() %d\n", gpsStatus->getHasLock());
|
||||
DEBUG_MSG("pref.fixed_position() %d\n", radioConfig.preferences.fixed_position);
|
||||
DEBUG_MSG("pref.fixed_position() %d\n", config.payloadVariant.position.fixed_position);
|
||||
|
||||
// Only send packets if the channel is less than 25% utilized.
|
||||
if (airTime->channelUtilizationPercent() < 25) {
|
||||
@@ -131,7 +131,7 @@ ProcessMessage RangeTestModuleRadio::handleReceived(const MeshPacket &mp)
|
||||
{
|
||||
#ifndef NO_ESP32
|
||||
|
||||
if (radioConfig.preferences.range_test_module_enabled) {
|
||||
if (moduleConfig.payloadVariant.range_test.enabled) {
|
||||
|
||||
/*
|
||||
auto &p = mp.decoded;
|
||||
@@ -141,7 +141,7 @@ ProcessMessage RangeTestModuleRadio::handleReceived(const MeshPacket &mp)
|
||||
|
||||
if (getFrom(&mp) != nodeDB.getNodeNum()) {
|
||||
|
||||
if (radioConfig.preferences.range_test_module_save) {
|
||||
if (moduleConfig.payloadVariant.range_test.save) {
|
||||
appendFile(mp);
|
||||
}
|
||||
|
||||
|
||||
@@ -1,9 +1,9 @@
|
||||
#include "configuration.h"
|
||||
#include "SerialModule.h"
|
||||
#include "MeshService.h"
|
||||
#include "NodeDB.h"
|
||||
#include "RTC.h"
|
||||
#include "Router.h"
|
||||
#include "configuration.h"
|
||||
#include <Arduino.h>
|
||||
|
||||
#include <assert.h>
|
||||
@@ -20,18 +20,18 @@
|
||||
|
||||
Basic Usage:
|
||||
|
||||
1) Enable the module by setting serial_module_enabled to 1.
|
||||
2) Set the pins (serial_module_rxd / serial_module_rxd) for your preferred RX and TX GPIO pins.
|
||||
1) Enable the module by setting enabled to 1.
|
||||
2) Set the pins (rxd / rxd) for your preferred RX and TX GPIO pins.
|
||||
On tbeam, recommend to use:
|
||||
RXD 35
|
||||
TXD 15
|
||||
3) Set serial_module_timeout to the amount of time to wait before we consider
|
||||
3) Set timeout to the amount of time to wait before we consider
|
||||
your packet as "done".
|
||||
4) (Optional) In SerialModule.h set the port to PortNum_TEXT_MESSAGE_APP if you want to
|
||||
send messages to/from the general text message channel.
|
||||
5) Connect to your device over the serial interface at 38400 8N1.
|
||||
6) Send a packet up to 240 bytes in length. This will get relayed over the mesh network.
|
||||
7) (Optional) Set serial_module_echo to 1 and any message you send out will be echoed back
|
||||
7) (Optional) Set echo to 1 and any message you send out will be echoed back
|
||||
to your device.
|
||||
|
||||
TODO (in this order):
|
||||
@@ -48,11 +48,11 @@
|
||||
|
||||
#define RXD2 16
|
||||
#define TXD2 17
|
||||
#define SERIAL_MODULE_RX_BUFFER 128
|
||||
#define SERIAL_MODULE_STRING_MAX Constants_DATA_PAYLOAD_LEN
|
||||
#define SERIAL_MODULE_TIMEOUT 250
|
||||
#define SERIAL_MODULE_BAUD 38400
|
||||
#define SERIAL_MODULE_ACK 1
|
||||
#define RX_BUFFER 128
|
||||
#define STRING_MAX Constants_DATA_PAYLOAD_LEN
|
||||
#define TIMEOUT 250
|
||||
#define BAUD 38400
|
||||
#define ACK 1
|
||||
|
||||
SerialModule *serialModule;
|
||||
SerialModuleRadio *serialModuleRadio;
|
||||
@@ -76,89 +76,86 @@ int32_t SerialModule::runOnce()
|
||||
without having to configure it from the PythonAPI or WebUI.
|
||||
*/
|
||||
|
||||
// radioConfig.preferences.serial_module_enabled = 1;
|
||||
// radioConfig.preferences.serial_module_rxd = 35;
|
||||
// radioConfig.preferences.serial_module_txd = 15;
|
||||
// radioConfig.preferences.serial_module_timeout = 1000;
|
||||
// radioConfig.preferences.serial_module_echo = 1;
|
||||
// moduleConfig.payloadVariant.serial.enabled = 1;
|
||||
// moduleConfig.payloadVariant.serial.rxd = 35;
|
||||
// moduleConfig.payloadVariant.serial.txd = 15;
|
||||
// moduleConfig.payloadVariant.serial.timeout = 1000;
|
||||
// moduleConfig.payloadVariant.serial.echo = 1;
|
||||
|
||||
if (radioConfig.preferences.serial_module_enabled) {
|
||||
if (moduleConfig.payloadVariant.serial.enabled) {
|
||||
|
||||
if (firstTime) {
|
||||
|
||||
// Interface with the serial peripheral from in here.
|
||||
DEBUG_MSG("Initializing serial peripheral interface\n");
|
||||
|
||||
|
||||
uint32_t baud = 0;
|
||||
|
||||
if (radioConfig.preferences.serial_module_baud == RadioConfig_UserPreferences_Serial_Baud_BAUD_Default) {
|
||||
if (moduleConfig.payloadVariant.serial.baud == ModuleConfig_SerialConfig_Serial_Baud_BAUD_Default) {
|
||||
baud = 38400;
|
||||
|
||||
} else if (radioConfig.preferences.serial_module_baud == RadioConfig_UserPreferences_Serial_Baud_BAUD_110) {
|
||||
|
||||
} else if (moduleConfig.payloadVariant.serial.baud == ModuleConfig_SerialConfig_Serial_Baud_BAUD_110) {
|
||||
baud = 110;
|
||||
|
||||
} else if (radioConfig.preferences.serial_module_baud == RadioConfig_UserPreferences_Serial_Baud_BAUD_300) {
|
||||
} else if (moduleConfig.payloadVariant.serial.baud == ModuleConfig_SerialConfig_Serial_Baud_BAUD_300) {
|
||||
baud = 300;
|
||||
|
||||
} else if (radioConfig.preferences.serial_module_baud == RadioConfig_UserPreferences_Serial_Baud_BAUD_600) {
|
||||
} else if (moduleConfig.payloadVariant.serial.baud == ModuleConfig_SerialConfig_Serial_Baud_BAUD_600) {
|
||||
baud = 600;
|
||||
|
||||
} else if (radioConfig.preferences.serial_module_baud == RadioConfig_UserPreferences_Serial_Baud_BAUD_1200) {
|
||||
} else if (moduleConfig.payloadVariant.serial.baud == ModuleConfig_SerialConfig_Serial_Baud_BAUD_1200) {
|
||||
baud = 1200;
|
||||
|
||||
} else if (radioConfig.preferences.serial_module_baud == RadioConfig_UserPreferences_Serial_Baud_BAUD_2400) {
|
||||
} else if (moduleConfig.payloadVariant.serial.baud == ModuleConfig_SerialConfig_Serial_Baud_BAUD_2400) {
|
||||
baud = 2400;
|
||||
|
||||
} else if (radioConfig.preferences.serial_module_baud == RadioConfig_UserPreferences_Serial_Baud_BAUD_4800) {
|
||||
} else if (moduleConfig.payloadVariant.serial.baud == ModuleConfig_SerialConfig_Serial_Baud_BAUD_4800) {
|
||||
baud = 4800;
|
||||
|
||||
} else if (radioConfig.preferences.serial_module_baud == RadioConfig_UserPreferences_Serial_Baud_BAUD_9600) {
|
||||
} else if (moduleConfig.payloadVariant.serial.baud == ModuleConfig_SerialConfig_Serial_Baud_BAUD_9600) {
|
||||
baud = 9600;
|
||||
|
||||
} else if (radioConfig.preferences.serial_module_baud == RadioConfig_UserPreferences_Serial_Baud_BAUD_19200) {
|
||||
} else if (moduleConfig.payloadVariant.serial.baud == ModuleConfig_SerialConfig_Serial_Baud_BAUD_19200) {
|
||||
baud = 19200;
|
||||
|
||||
} else if (radioConfig.preferences.serial_module_baud == RadioConfig_UserPreferences_Serial_Baud_BAUD_38400) {
|
||||
} else if (moduleConfig.payloadVariant.serial.baud == ModuleConfig_SerialConfig_Serial_Baud_BAUD_38400) {
|
||||
baud = 38400;
|
||||
|
||||
} else if (radioConfig.preferences.serial_module_baud == RadioConfig_UserPreferences_Serial_Baud_BAUD_57600) {
|
||||
} else if (moduleConfig.payloadVariant.serial.baud == ModuleConfig_SerialConfig_Serial_Baud_BAUD_57600) {
|
||||
baud = 57600;
|
||||
|
||||
} else if (radioConfig.preferences.serial_module_baud == RadioConfig_UserPreferences_Serial_Baud_BAUD_115200) {
|
||||
} else if (moduleConfig.payloadVariant.serial.baud == ModuleConfig_SerialConfig_Serial_Baud_BAUD_115200) {
|
||||
baud = 115200;
|
||||
|
||||
} else if (radioConfig.preferences.serial_module_baud == RadioConfig_UserPreferences_Serial_Baud_BAUD_230400) {
|
||||
} else if (moduleConfig.payloadVariant.serial.baud == ModuleConfig_SerialConfig_Serial_Baud_BAUD_230400) {
|
||||
baud = 230400;
|
||||
|
||||
} else if (radioConfig.preferences.serial_module_baud == RadioConfig_UserPreferences_Serial_Baud_BAUD_460800) {
|
||||
} else if (moduleConfig.payloadVariant.serial.baud == ModuleConfig_SerialConfig_Serial_Baud_BAUD_460800) {
|
||||
baud = 460800;
|
||||
|
||||
} else if (radioConfig.preferences.serial_module_baud == RadioConfig_UserPreferences_Serial_Baud_BAUD_576000) {
|
||||
} else if (moduleConfig.payloadVariant.serial.baud == ModuleConfig_SerialConfig_Serial_Baud_BAUD_576000) {
|
||||
baud = 576000;
|
||||
|
||||
} else if (radioConfig.preferences.serial_module_baud == RadioConfig_UserPreferences_Serial_Baud_BAUD_921600) {
|
||||
} else if (moduleConfig.payloadVariant.serial.baud == ModuleConfig_SerialConfig_Serial_Baud_BAUD_921600) {
|
||||
baud = 921600;
|
||||
|
||||
|
||||
}
|
||||
|
||||
if (radioConfig.preferences.serial_module_rxd && radioConfig.preferences.serial_module_txd) {
|
||||
Serial2.begin(baud, SERIAL_8N1, radioConfig.preferences.serial_module_rxd,
|
||||
radioConfig.preferences.serial_module_txd);
|
||||
if (moduleConfig.payloadVariant.serial.rxd && moduleConfig.payloadVariant.serial.txd) {
|
||||
Serial2.begin(baud, SERIAL_8N1, moduleConfig.payloadVariant.serial.rxd, moduleConfig.payloadVariant.serial.txd);
|
||||
|
||||
} else {
|
||||
Serial2.begin(baud, SERIAL_8N1, RXD2, TXD2);
|
||||
}
|
||||
|
||||
if (radioConfig.preferences.serial_module_timeout) {
|
||||
if (moduleConfig.payloadVariant.serial.timeout) {
|
||||
Serial2.setTimeout(
|
||||
radioConfig.preferences.serial_module_timeout); // Number of MS to wait to set the timeout for the string.
|
||||
moduleConfig.payloadVariant.serial.timeout); // Number of MS to wait to set the timeout for the string.
|
||||
|
||||
} else {
|
||||
Serial2.setTimeout(SERIAL_MODULE_TIMEOUT); // Number of MS to wait to set the timeout for the string.
|
||||
Serial2.setTimeout(TIMEOUT); // Number of MS to wait to set the timeout for the string.
|
||||
}
|
||||
|
||||
Serial2.setRxBufferSize(SERIAL_MODULE_RX_BUFFER);
|
||||
Serial2.setRxBufferSize(RX_BUFFER);
|
||||
|
||||
serialModuleRadio = new SerialModuleRadio();
|
||||
|
||||
@@ -202,7 +199,7 @@ void SerialModuleRadio::sendPayload(NodeNum dest, bool wantReplies)
|
||||
p->to = dest;
|
||||
p->decoded.want_response = wantReplies;
|
||||
|
||||
p->want_ack = SERIAL_MODULE_ACK;
|
||||
p->want_ack = ACK;
|
||||
|
||||
p->decoded.payload.size = strlen(serialStringChar); // You must specify how many bytes are in the reply
|
||||
memcpy(p->decoded.payload.bytes, serialStringChar, p->decoded.payload.size);
|
||||
@@ -214,7 +211,7 @@ ProcessMessage SerialModuleRadio::handleReceived(const MeshPacket &mp)
|
||||
{
|
||||
#ifndef NO_ESP32
|
||||
|
||||
if (radioConfig.preferences.serial_module_enabled) {
|
||||
if (moduleConfig.payloadVariant.serial.enabled) {
|
||||
|
||||
auto &p = mp.decoded;
|
||||
// DEBUG_MSG("Received text msg self=0x%0x, from=0x%0x, to=0x%0x, id=%d, msg=%.*s\n",
|
||||
@@ -223,10 +220,10 @@ ProcessMessage SerialModuleRadio::handleReceived(const MeshPacket &mp)
|
||||
if (getFrom(&mp) == nodeDB.getNodeNum()) {
|
||||
|
||||
/*
|
||||
* If radioConfig.preferences.serial_module_echo is true, then echo the packets that are sent out back to the TX
|
||||
* of the serial interface.
|
||||
* If moduleConfig.payloadVariant.serial.echo is true, then echo the packets that are sent out
|
||||
* back to the TX of the serial interface.
|
||||
*/
|
||||
if (radioConfig.preferences.serial_module_echo) {
|
||||
if (moduleConfig.payloadVariant.serial.echo) {
|
||||
|
||||
// For some reason, we get the packet back twice when we send out of the radio.
|
||||
// TODO: need to find out why.
|
||||
@@ -240,13 +237,13 @@ ProcessMessage SerialModuleRadio::handleReceived(const MeshPacket &mp)
|
||||
|
||||
} else {
|
||||
|
||||
if (radioConfig.preferences.serial_module_mode == RadioConfig_UserPreferences_Serial_Mode_MODE_Default || radioConfig.preferences.serial_module_mode == RadioConfig_UserPreferences_Serial_Mode_MODE_SIMPLE) {
|
||||
if (moduleConfig.payloadVariant.serial.mode == ModuleConfig_SerialConfig_Serial_Mode_MODE_Default ||
|
||||
moduleConfig.payloadVariant.serial.mode == ModuleConfig_SerialConfig_Serial_Mode_MODE_SIMPLE) {
|
||||
// DEBUG_MSG("* * Message came from the mesh\n");
|
||||
// Serial2.println("* * Message came from the mesh");
|
||||
Serial2.printf("%s", p.payload.bytes);
|
||||
|
||||
} else if (radioConfig.preferences.serial_module_mode == RadioConfig_UserPreferences_Serial_Mode_MODE_PROTO) {
|
||||
|
||||
} else if (moduleConfig.payloadVariant.serial.mode == ModuleConfig_SerialConfig_Serial_Mode_MODE_PROTO) {
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -19,13 +19,12 @@ int32_t StoreForwardModule::runOnce()
|
||||
|
||||
#ifndef NO_ESP32
|
||||
|
||||
if (radioConfig.preferences.store_forward_module_enabled) {
|
||||
if (moduleConfig.payloadVariant.store_forward.enabled) {
|
||||
|
||||
if (radioConfig.preferences.role == Role_Router) {
|
||||
if (config.payloadVariant.device.role == Config_DeviceConfig_Role_Router) {
|
||||
|
||||
// Send out the message queue.
|
||||
if (this->busy) {
|
||||
|
||||
|
||||
// Only send packets if the channel is less than 25% utilized.
|
||||
if (airTime->channelUtilizationPercent() < 25) {
|
||||
@@ -43,7 +42,7 @@ int32_t StoreForwardModule::runOnce()
|
||||
} else {
|
||||
this->packetHistoryTXQueue_index++;
|
||||
}
|
||||
|
||||
|
||||
} else {
|
||||
DEBUG_MSG("Channel utilization is too high. Skipping this opportunity to send and will retry later.\n");
|
||||
}
|
||||
@@ -243,7 +242,7 @@ void StoreForwardModule::sendMessage(NodeNum dest, char *str)
|
||||
ProcessMessage StoreForwardModule::handleReceived(const MeshPacket &mp)
|
||||
{
|
||||
#ifndef NO_ESP32
|
||||
if (radioConfig.preferences.store_forward_module_enabled) {
|
||||
if (moduleConfig.payloadVariant.store_forward.enabled) {
|
||||
|
||||
DEBUG_MSG("--- S&F Received something\n");
|
||||
|
||||
@@ -267,10 +266,11 @@ ProcessMessage StoreForwardModule::handleReceived(const MeshPacket &mp)
|
||||
}
|
||||
} else if ((p.payload.bytes[0] == 'S') && (p.payload.bytes[1] == 'F') && (p.payload.bytes[2] == 'm') &&
|
||||
(p.payload.bytes[3] == 0x00)) {
|
||||
strlcpy(this->routerMessage, "01234567890123456789012345678901234567890123456789012345678901234567890123456789"
|
||||
"01234567890123456789012345678901234567890123456789012345678901234567890123456789"
|
||||
"01234567890123456789012345678901234567890123456789012345678901234567890123456",
|
||||
sizeof(this->routerMessage));
|
||||
strlcpy(this->routerMessage,
|
||||
"01234567890123456789012345678901234567890123456789012345678901234567890123456789"
|
||||
"01234567890123456789012345678901234567890123456789012345678901234567890123456789"
|
||||
"01234567890123456789012345678901234567890123456789012345678901234567890123456",
|
||||
sizeof(this->routerMessage));
|
||||
storeForwardModule->sendMessage(getFrom(&mp), this->routerMessage);
|
||||
|
||||
} else {
|
||||
@@ -295,7 +295,7 @@ ProcessMessage StoreForwardModule::handleReceived(const MeshPacket &mp)
|
||||
|
||||
ProcessMessage StoreForwardModule::handleReceivedProtobuf(const MeshPacket &mp, StoreAndForward *p)
|
||||
{
|
||||
if (!radioConfig.preferences.store_forward_module_enabled) {
|
||||
if (!moduleConfig.payloadVariant.store_forward.enabled) {
|
||||
// If this module is not enabled in any capacity, don't handle the packet, and allow other modules to consume
|
||||
return ProcessMessage::CONTINUE;
|
||||
}
|
||||
@@ -391,14 +391,14 @@ StoreForwardModule::StoreForwardModule()
|
||||
without having to configure it from the PythonAPI or WebUI.
|
||||
*/
|
||||
|
||||
radioConfig.preferences.store_forward_module_enabled = 1;
|
||||
radioConfig.preferences.is_always_powered = 1;
|
||||
moduleConfig.payloadVariant.store_forward.enabled = 1;
|
||||
config.payloadVariant.power.is_always_powered = 1;
|
||||
}
|
||||
|
||||
if (radioConfig.preferences.store_forward_module_enabled) {
|
||||
if (moduleConfig.payloadVariant.store_forward.enabled) {
|
||||
|
||||
// Router
|
||||
if (radioConfig.preferences.role == Role_Router) {
|
||||
if (config.payloadVariant.device.role == Config_DeviceConfig_Role_Router) {
|
||||
DEBUG_MSG("Initializing Store & Forward Module - Enabled as Router\n");
|
||||
if (ESP.getPsramSize()) {
|
||||
if (ESP.getFreePsram() >= 1024 * 1024) {
|
||||
@@ -406,20 +406,20 @@ StoreForwardModule::StoreForwardModule()
|
||||
// Do the startup here
|
||||
|
||||
// Maximum number of records to return.
|
||||
if (radioConfig.preferences.store_forward_module_history_return_max)
|
||||
this->historyReturnMax = radioConfig.preferences.store_forward_module_history_return_max;
|
||||
if (moduleConfig.payloadVariant.store_forward.history_return_max)
|
||||
this->historyReturnMax = moduleConfig.payloadVariant.store_forward.history_return_max;
|
||||
|
||||
// Maximum time window for records to return (in minutes)
|
||||
if (radioConfig.preferences.store_forward_module_history_return_window)
|
||||
this->historyReturnWindow = radioConfig.preferences.store_forward_module_history_return_window;
|
||||
if (moduleConfig.payloadVariant.store_forward.history_return_window)
|
||||
this->historyReturnWindow = moduleConfig.payloadVariant.store_forward.history_return_window;
|
||||
|
||||
// Maximum number of records to store in memory
|
||||
if (radioConfig.preferences.store_forward_module_records)
|
||||
this->records = radioConfig.preferences.store_forward_module_records;
|
||||
if (moduleConfig.payloadVariant.store_forward.records)
|
||||
this->records = moduleConfig.payloadVariant.store_forward.records;
|
||||
|
||||
// Maximum number of records to store in memory
|
||||
if (radioConfig.preferences.store_forward_module_heartbeat)
|
||||
this->heartbeat = radioConfig.preferences.store_forward_module_heartbeat;
|
||||
if (moduleConfig.payloadVariant.store_forward.heartbeat)
|
||||
this->heartbeat = moduleConfig.payloadVariant.store_forward.heartbeat;
|
||||
|
||||
// Popupate PSRAM with our data structures.
|
||||
this->populatePSRAM();
|
||||
|
||||
Reference in New Issue
Block a user