mirror of
https://github.com/meshtastic/firmware.git
synced 2025-09-10 21:19:07 +00:00
Fix excluded modules configuration handling (#7838)
* Fix excluded modules configuration handling - Add excluded_modules flags in getDeviceMetadata() for MQTT, PAXCOUNTER, STOREFORWARD, RANGETEST, NEIGHBORINFO - Add conditional compilation guards in AdminModule for RANGETEST, AUDIO, PAXCOUNTER, STOREFORWARD, EXTNOTIF, DETECTIONSENSOR, AMBIENTLIGHTING - Add skip logic in PhoneAPI for excluded modules during config enumeration - Add conditional has_* flags in NodeDB only for included modules Fixes issue where excluded modules still appeared in client applications and sometimes caused PAYLOADVARIANT_NOT_SET errors. * Fix excluded modules issues and refactor code - Restore original PAXCOUNTER logic: only exclude on non-ESP32 platforms due to memory constraints - Fix has_store_forward flag to be conditionally compiled based on MESHTASTIC_EXCLUDE_STOREFORWARD - Refactor PhoneAPI module config skipping logic to use helper function skipExcludedModuleConfig() - Reduce code duplication in PhoneAPI by extracting common skip logic This addresses the three issues identified in the code review: 1. PAXCOUNTER memory impact on non-ESP32 devices 2. Unconditional has_store_forward flag setting 3. Duplicated state management logic across multiple #else blocks * Fix ambient lighting module exclusion in PhoneAPI and AdminModule - Add conditional compilation guards for ambient lighting in PhoneAPI.cpp - Replace old HAS_RGB_LED logic with MESHTASTIC_EXCLUDE_AMBIENTLIGHTING check in AdminModule.cpp - Ensure ambient lighting module is properly excluded when MESHTASTIC_EXCLUDE_AMBIENTLIGHTING=1
This commit is contained in:
parent
b6eeccadeb
commit
9c6544ebfa
@ -431,6 +431,7 @@ along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
#define MESHTASTIC_EXCLUDE_SERIAL 1
|
||||
#define MESHTASTIC_EXCLUDE_POWERSTRESS 1
|
||||
#define MESHTASTIC_EXCLUDE_ADMIN 1
|
||||
#define MESHTASTIC_EXCLUDE_AMBIENTLIGHTING 1
|
||||
#endif
|
||||
|
||||
// // Turn off wifi even if HW supports wifi (webserver relies on wifi and is also disabled)
|
||||
|
18
src/main.cpp
18
src/main.cpp
@ -1506,6 +1506,9 @@ extern meshtastic_DeviceMetadata getDeviceMetadata()
|
||||
deviceMetadata.hw_model = HW_VENDOR;
|
||||
deviceMetadata.hasRemoteHardware = moduleConfig.remote_hardware.enabled;
|
||||
deviceMetadata.excluded_modules = meshtastic_ExcludedModules_EXCLUDED_NONE;
|
||||
#if MESHTASTIC_EXCLUDE_MQTT
|
||||
deviceMetadata.excluded_modules |= meshtastic_ExcludedModules_MQTT_CONFIG;
|
||||
#endif
|
||||
#if MESHTASTIC_EXCLUDE_REMOTEHARDWARE
|
||||
deviceMetadata.excluded_modules |= meshtastic_ExcludedModules_REMOTEHARDWARE_CONFIG;
|
||||
#endif
|
||||
@ -1528,10 +1531,21 @@ extern meshtastic_DeviceMetadata getDeviceMetadata()
|
||||
#if NO_EXT_GPIO && NO_GPS || MESHTASTIC_EXCLUDE_SERIAL
|
||||
deviceMetadata.excluded_modules |= meshtastic_ExcludedModules_SERIAL_CONFIG;
|
||||
#endif
|
||||
#ifndef ARCH_ESP32
|
||||
#if defined(ARCH_ESP32) && !MESHTASTIC_EXCLUDE_PAXCOUNTER
|
||||
// PAXCOUNTER is only supported on ESP32 due to memory constraints
|
||||
#else
|
||||
deviceMetadata.excluded_modules |= meshtastic_ExcludedModules_PAXCOUNTER_CONFIG;
|
||||
#endif
|
||||
#if !defined(HAS_RGB_LED) && !RAK_4631
|
||||
#if MESHTASTIC_EXCLUDE_STOREFORWARD
|
||||
deviceMetadata.excluded_modules |= meshtastic_ExcludedModules_STOREFORWARD_CONFIG;
|
||||
#endif
|
||||
#if MESHTASTIC_EXCLUDE_RANGETEST
|
||||
deviceMetadata.excluded_modules |= meshtastic_ExcludedModules_RANGETEST_CONFIG;
|
||||
#endif
|
||||
#if MESHTASTIC_EXCLUDE_NEIGHBORINFO
|
||||
deviceMetadata.excluded_modules |= meshtastic_ExcludedModules_NEIGHBORINFO_CONFIG;
|
||||
#endif
|
||||
#if (!defined(HAS_RGB_LED) && !defined(RAK_4631)) || defined(MESHTASTIC_EXCLUDE_AMBIENTLIGHTING)
|
||||
deviceMetadata.excluded_modules |= meshtastic_ExcludedModules_AMBIENTLIGHTING_CONFIG;
|
||||
#endif
|
||||
|
||||
|
@ -775,7 +775,9 @@ void NodeDB::installDefaultModuleConfig()
|
||||
|
||||
moduleConfig.version = DEVICESTATE_CUR_VER;
|
||||
moduleConfig.has_mqtt = true;
|
||||
#if !MESHTASTIC_EXCLUDE_RANGETEST
|
||||
moduleConfig.has_range_test = true;
|
||||
#endif
|
||||
moduleConfig.has_serial = true;
|
||||
moduleConfig.has_store_forward = true;
|
||||
moduleConfig.has_telemetry = true;
|
||||
@ -841,6 +843,12 @@ void NodeDB::installDefaultModuleConfig()
|
||||
moduleConfig.canned_message.inputbroker_event_press = meshtastic_ModuleConfig_CannedMessageConfig_InputEventChar_SELECT;
|
||||
#endif
|
||||
moduleConfig.has_canned_message = true;
|
||||
#if !MESHTASTIC_EXCLUDE_AUDIO
|
||||
moduleConfig.has_audio = true;
|
||||
#endif
|
||||
#if !MESHTASTIC_EXCLUDE_PAXCOUNTER
|
||||
moduleConfig.has_paxcounter = true;
|
||||
#endif
|
||||
#if USERPREFS_MQTT_ENABLED && !MESHTASTIC_EXCLUDE_MQTT
|
||||
moduleConfig.mqtt.enabled = true;
|
||||
#endif
|
||||
@ -883,12 +891,14 @@ void NodeDB::installDefaultModuleConfig()
|
||||
moduleConfig.detection_sensor.detection_trigger_type = meshtastic_ModuleConfig_DetectionSensorConfig_TriggerType_LOGIC_HIGH;
|
||||
moduleConfig.detection_sensor.minimum_broadcast_secs = 45;
|
||||
|
||||
#if !MESHTASTIC_EXCLUDE_AMBIENTLIGHTING
|
||||
moduleConfig.has_ambient_lighting = true;
|
||||
moduleConfig.ambient_lighting.current = 10;
|
||||
// Default to a color based on our node number
|
||||
moduleConfig.ambient_lighting.red = (myNodeInfo.my_node_num & 0xFF0000) >> 16;
|
||||
moduleConfig.ambient_lighting.green = (myNodeInfo.my_node_num & 0x00FF00) >> 8;
|
||||
moduleConfig.ambient_lighting.blue = myNodeInfo.my_node_num & 0x0000FF;
|
||||
#endif
|
||||
|
||||
initModuleConfigIntervals();
|
||||
}
|
||||
@ -1428,15 +1438,25 @@ bool NodeDB::saveToDiskNoRetry(int saveWhat)
|
||||
moduleConfig.has_canned_message = true;
|
||||
moduleConfig.has_external_notification = true;
|
||||
moduleConfig.has_mqtt = true;
|
||||
#if !MESHTASTIC_EXCLUDE_RANGETEST
|
||||
moduleConfig.has_range_test = true;
|
||||
#endif
|
||||
moduleConfig.has_serial = true;
|
||||
#if !MESHTASTIC_EXCLUDE_STOREFORWARD
|
||||
moduleConfig.has_store_forward = true;
|
||||
#endif
|
||||
moduleConfig.has_telemetry = true;
|
||||
moduleConfig.has_neighbor_info = true;
|
||||
moduleConfig.has_detection_sensor = true;
|
||||
#if !MESHTASTIC_EXCLUDE_AMBIENTLIGHTING
|
||||
moduleConfig.has_ambient_lighting = true;
|
||||
#endif
|
||||
#if !MESHTASTIC_EXCLUDE_AUDIO
|
||||
moduleConfig.has_audio = true;
|
||||
#endif
|
||||
#if !MESHTASTIC_EXCLUDE_PAXCOUNTER
|
||||
moduleConfig.has_paxcounter = true;
|
||||
#endif
|
||||
|
||||
success &=
|
||||
saveProto(moduleConfigFileName, meshtastic_LocalModuleConfig_size, &meshtastic_LocalModuleConfig_msg, &moduleConfig);
|
||||
|
@ -34,6 +34,21 @@
|
||||
// Flag to indicate a heartbeat was received and we should send queue status
|
||||
bool heartbeatReceived = false;
|
||||
|
||||
// Helper function to skip excluded module configs and advance state
|
||||
size_t PhoneAPI::skipExcludedModuleConfig(uint8_t *buf)
|
||||
{
|
||||
config_state++;
|
||||
if (config_state > (_meshtastic_AdminMessage_ModuleConfigType_MAX + 1)) {
|
||||
if (config_nonce == SPECIAL_NONCE_ONLY_CONFIG) {
|
||||
state = STATE_SEND_FILEMANIFEST;
|
||||
} else {
|
||||
state = STATE_SEND_OTHER_NODEINFOS;
|
||||
}
|
||||
config_state = 0;
|
||||
}
|
||||
return getFromRadio(buf);
|
||||
}
|
||||
|
||||
PhoneAPI::PhoneAPI()
|
||||
{
|
||||
lastContactMsec = millis();
|
||||
@ -354,20 +369,35 @@ size_t PhoneAPI::getFromRadio(uint8_t *buf)
|
||||
fromRadioScratch.moduleConfig.payload_variant.serial = moduleConfig.serial;
|
||||
break;
|
||||
case meshtastic_ModuleConfig_external_notification_tag:
|
||||
#if !(NO_EXT_GPIO || MESHTASTIC_EXCLUDE_EXTERNALNOTIFICATION)
|
||||
LOG_DEBUG("Send module config: ext notification");
|
||||
fromRadioScratch.moduleConfig.which_payload_variant = meshtastic_ModuleConfig_external_notification_tag;
|
||||
fromRadioScratch.moduleConfig.payload_variant.external_notification = moduleConfig.external_notification;
|
||||
break;
|
||||
#else
|
||||
LOG_DEBUG("External Notification module excluded from build, skipping");
|
||||
return skipExcludedModuleConfig(buf);
|
||||
#endif
|
||||
case meshtastic_ModuleConfig_store_forward_tag:
|
||||
#if !MESHTASTIC_EXCLUDE_STOREFORWARD
|
||||
LOG_DEBUG("Send module config: store forward");
|
||||
fromRadioScratch.moduleConfig.which_payload_variant = meshtastic_ModuleConfig_store_forward_tag;
|
||||
fromRadioScratch.moduleConfig.payload_variant.store_forward = moduleConfig.store_forward;
|
||||
break;
|
||||
#else
|
||||
LOG_DEBUG("Store & Forward module excluded from build, skipping");
|
||||
return skipExcludedModuleConfig(buf);
|
||||
#endif
|
||||
case meshtastic_ModuleConfig_range_test_tag:
|
||||
#if !MESHTASTIC_EXCLUDE_RANGETEST
|
||||
LOG_DEBUG("Send module config: range test");
|
||||
fromRadioScratch.moduleConfig.which_payload_variant = meshtastic_ModuleConfig_range_test_tag;
|
||||
fromRadioScratch.moduleConfig.payload_variant.range_test = moduleConfig.range_test;
|
||||
break;
|
||||
#else
|
||||
LOG_DEBUG("Range Test module excluded from build, skipping");
|
||||
return skipExcludedModuleConfig(buf);
|
||||
#endif
|
||||
case meshtastic_ModuleConfig_telemetry_tag:
|
||||
LOG_DEBUG("Send module config: telemetry");
|
||||
fromRadioScratch.moduleConfig.which_payload_variant = meshtastic_ModuleConfig_telemetry_tag;
|
||||
@ -379,10 +409,15 @@ size_t PhoneAPI::getFromRadio(uint8_t *buf)
|
||||
fromRadioScratch.moduleConfig.payload_variant.canned_message = moduleConfig.canned_message;
|
||||
break;
|
||||
case meshtastic_ModuleConfig_audio_tag:
|
||||
#if !MESHTASTIC_EXCLUDE_AUDIO
|
||||
LOG_DEBUG("Send module config: audio");
|
||||
fromRadioScratch.moduleConfig.which_payload_variant = meshtastic_ModuleConfig_audio_tag;
|
||||
fromRadioScratch.moduleConfig.payload_variant.audio = moduleConfig.audio;
|
||||
break;
|
||||
#else
|
||||
LOG_DEBUG("Audio module excluded from build, skipping");
|
||||
return skipExcludedModuleConfig(buf);
|
||||
#endif
|
||||
case meshtastic_ModuleConfig_remote_hardware_tag:
|
||||
LOG_DEBUG("Send module config: remote hardware");
|
||||
fromRadioScratch.moduleConfig.which_payload_variant = meshtastic_ModuleConfig_remote_hardware_tag;
|
||||
@ -399,15 +434,25 @@ size_t PhoneAPI::getFromRadio(uint8_t *buf)
|
||||
fromRadioScratch.moduleConfig.payload_variant.detection_sensor = moduleConfig.detection_sensor;
|
||||
break;
|
||||
case meshtastic_ModuleConfig_ambient_lighting_tag:
|
||||
#if !MESHTASTIC_EXCLUDE_AMBIENTLIGHTING
|
||||
LOG_DEBUG("Send module config: ambient lighting");
|
||||
fromRadioScratch.moduleConfig.which_payload_variant = meshtastic_ModuleConfig_ambient_lighting_tag;
|
||||
fromRadioScratch.moduleConfig.payload_variant.ambient_lighting = moduleConfig.ambient_lighting;
|
||||
break;
|
||||
#else
|
||||
LOG_DEBUG("Ambient Lighting module excluded from build, skipping");
|
||||
return skipExcludedModuleConfig(buf);
|
||||
#endif
|
||||
case meshtastic_ModuleConfig_paxcounter_tag:
|
||||
#if !MESHTASTIC_EXCLUDE_PAXCOUNTER
|
||||
LOG_DEBUG("Send module config: paxcounter");
|
||||
fromRadioScratch.moduleConfig.which_payload_variant = meshtastic_ModuleConfig_paxcounter_tag;
|
||||
fromRadioScratch.moduleConfig.payload_variant.paxcounter = moduleConfig.paxcounter;
|
||||
break;
|
||||
#else
|
||||
LOG_DEBUG("Paxcounter module excluded from build, skipping");
|
||||
return skipExcludedModuleConfig(buf);
|
||||
#endif
|
||||
default:
|
||||
LOG_ERROR("Unknown module config type %d", config_state);
|
||||
}
|
||||
|
@ -172,4 +172,7 @@ class PhoneAPI
|
||||
|
||||
/// If the mesh service tells us fromNum has changed, tell the phone
|
||||
virtual int onNotify(uint32_t newValue) override;
|
||||
|
||||
/// Helper function to skip excluded module configs and advance state
|
||||
size_t skipExcludedModuleConfig(uint8_t *buf);
|
||||
};
|
||||
|
@ -1040,19 +1040,32 @@ void AdminModule::handleGetModuleConfig(const meshtastic_MeshPacket &req, const
|
||||
res.get_module_config_response.payload_variant.serial = moduleConfig.serial;
|
||||
break;
|
||||
case meshtastic_AdminMessage_ModuleConfigType_EXTNOTIF_CONFIG:
|
||||
#if !MESHTASTIC_EXCLUDE_EXTERNALNOTIFICATION
|
||||
LOG_INFO("Get module config: External Notification");
|
||||
res.get_module_config_response.which_payload_variant = meshtastic_ModuleConfig_external_notification_tag;
|
||||
res.get_module_config_response.payload_variant.external_notification = moduleConfig.external_notification;
|
||||
#else
|
||||
LOG_DEBUG("External Notification module excluded from build, skipping config");
|
||||
#endif
|
||||
break;
|
||||
case meshtastic_AdminMessage_ModuleConfigType_STOREFORWARD_CONFIG:
|
||||
#if !MESHTASTIC_EXCLUDE_STOREFORWARD
|
||||
LOG_INFO("Get module config: Store & Forward");
|
||||
res.get_module_config_response.which_payload_variant = meshtastic_ModuleConfig_store_forward_tag;
|
||||
res.get_module_config_response.payload_variant.store_forward = moduleConfig.store_forward;
|
||||
#else
|
||||
LOG_DEBUG("Store & Forward module excluded from build, skipping config");
|
||||
#endif
|
||||
break;
|
||||
case meshtastic_AdminMessage_ModuleConfigType_RANGETEST_CONFIG:
|
||||
#if !MESHTASTIC_EXCLUDE_RANGETEST
|
||||
LOG_INFO("Get module config: Range Test");
|
||||
res.get_module_config_response.which_payload_variant = meshtastic_ModuleConfig_range_test_tag;
|
||||
res.get_module_config_response.payload_variant.range_test = moduleConfig.range_test;
|
||||
#else
|
||||
LOG_DEBUG("Range Test module excluded from build, skipping config");
|
||||
// Don't set payload variant - will result in empty response
|
||||
#endif
|
||||
break;
|
||||
case meshtastic_AdminMessage_ModuleConfigType_TELEMETRY_CONFIG:
|
||||
LOG_INFO("Get module config: Telemetry");
|
||||
@ -1065,9 +1078,13 @@ void AdminModule::handleGetModuleConfig(const meshtastic_MeshPacket &req, const
|
||||
res.get_module_config_response.payload_variant.canned_message = moduleConfig.canned_message;
|
||||
break;
|
||||
case meshtastic_AdminMessage_ModuleConfigType_AUDIO_CONFIG:
|
||||
#if !MESHTASTIC_EXCLUDE_AUDIO
|
||||
LOG_INFO("Get module config: Audio");
|
||||
res.get_module_config_response.which_payload_variant = meshtastic_ModuleConfig_audio_tag;
|
||||
res.get_module_config_response.payload_variant.audio = moduleConfig.audio;
|
||||
#else
|
||||
LOG_DEBUG("Audio module excluded from build, skipping config");
|
||||
#endif
|
||||
break;
|
||||
case meshtastic_AdminMessage_ModuleConfigType_REMOTEHARDWARE_CONFIG:
|
||||
LOG_INFO("Get module config: Remote Hardware");
|
||||
@ -1080,19 +1097,31 @@ void AdminModule::handleGetModuleConfig(const meshtastic_MeshPacket &req, const
|
||||
res.get_module_config_response.payload_variant.neighbor_info = moduleConfig.neighbor_info;
|
||||
break;
|
||||
case meshtastic_AdminMessage_ModuleConfigType_DETECTIONSENSOR_CONFIG:
|
||||
#if !(NO_EXT_GPIO || MESHTASTIC_EXCLUDE_DETECTIONSENSOR)
|
||||
LOG_INFO("Get module config: Detection Sensor");
|
||||
res.get_module_config_response.which_payload_variant = meshtastic_ModuleConfig_detection_sensor_tag;
|
||||
res.get_module_config_response.payload_variant.detection_sensor = moduleConfig.detection_sensor;
|
||||
#else
|
||||
LOG_DEBUG("Detection Sensor module excluded from build, skipping config");
|
||||
#endif
|
||||
break;
|
||||
case meshtastic_AdminMessage_ModuleConfigType_AMBIENTLIGHTING_CONFIG:
|
||||
#if !MESHTASTIC_EXCLUDE_AMBIENTLIGHTING
|
||||
LOG_INFO("Get module config: Ambient Lighting");
|
||||
res.get_module_config_response.which_payload_variant = meshtastic_ModuleConfig_ambient_lighting_tag;
|
||||
res.get_module_config_response.payload_variant.ambient_lighting = moduleConfig.ambient_lighting;
|
||||
#else
|
||||
LOG_DEBUG("Ambient Lighting module excluded from build, skipping config");
|
||||
#endif
|
||||
break;
|
||||
case meshtastic_AdminMessage_ModuleConfigType_PAXCOUNTER_CONFIG:
|
||||
#if !MESHTASTIC_EXCLUDE_PAXCOUNTER
|
||||
LOG_INFO("Get module config: Paxcounter");
|
||||
res.get_module_config_response.which_payload_variant = meshtastic_ModuleConfig_paxcounter_tag;
|
||||
res.get_module_config_response.payload_variant.paxcounter = moduleConfig.paxcounter;
|
||||
#else
|
||||
LOG_DEBUG("Paxcounter module excluded from build, skipping config");
|
||||
#endif
|
||||
break;
|
||||
}
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user