mirror of
https://github.com/meshtastic/firmware.git
synced 2025-12-29 14:10:53 +00:00
Remote hardware overhaul (#2495)
* Update protos * WIP * Param * Has remote hardware * Protos * Initializer * Added new admin message for node remote hardware pins * Badunkatrunk * Init and memcpy
This commit is contained in:
@@ -50,6 +50,7 @@ bool AdminModule::handleReceivedProtobuf(const meshtastic_MeshPacket &mp, meshta
|
||||
// if handled == false, then let others look at this message also if they want
|
||||
bool handled = false;
|
||||
assert(r);
|
||||
bool fromOthers = mp.from != 0 && mp.from != nodeDB.getNodeNum();
|
||||
|
||||
switch (r->which_payload_variant) {
|
||||
|
||||
@@ -175,6 +176,14 @@ bool AdminModule::handleReceivedProtobuf(const meshtastic_MeshPacket &mp, meshta
|
||||
handleGetDeviceConnectionStatus(mp);
|
||||
break;
|
||||
}
|
||||
case meshtastic_AdminMessage_get_module_config_response_tag: {
|
||||
LOG_INFO("Client is receiving a get_module_config response.\n");
|
||||
if (fromOthers && r->get_module_config_response.which_payload_variant ==
|
||||
meshtastic_AdminMessage_ModuleConfigType_REMOTEHARDWARE_CONFIG) {
|
||||
handleGetModuleConfigResponse(mp, r);
|
||||
}
|
||||
break;
|
||||
}
|
||||
#ifdef ARCH_PORTDUINO
|
||||
case meshtastic_AdminMessage_exit_simulator_tag:
|
||||
LOG_INFO("Exiting simulator\n");
|
||||
@@ -205,6 +214,29 @@ bool AdminModule::handleReceivedProtobuf(const meshtastic_MeshPacket &mp, meshta
|
||||
return handled;
|
||||
}
|
||||
|
||||
void AdminModule::handleGetModuleConfigResponse(const meshtastic_MeshPacket &mp, meshtastic_AdminMessage *r)
|
||||
{
|
||||
// Skip if it's disabled or no pins are exposed
|
||||
if (!r->get_module_config_response.payload_variant.remote_hardware.enabled ||
|
||||
!r->get_module_config_response.payload_variant.remote_hardware.available_pins) {
|
||||
LOG_DEBUG("Remote hardware module disabled or no vailable_pins. Skipping...\n");
|
||||
return;
|
||||
}
|
||||
for (uint8_t i = 0; i < devicestate.node_remote_hardware_pins_count; i++) {
|
||||
if (devicestate.node_remote_hardware_pins[i].node_num == 0 || !devicestate.node_remote_hardware_pins[i].has_pin) {
|
||||
continue;
|
||||
}
|
||||
for (uint8_t j = 0; j < sizeof(r->get_module_config_response.payload_variant.remote_hardware.available_pins); j++) {
|
||||
auto availablePin = r->get_module_config_response.payload_variant.remote_hardware.available_pins[j];
|
||||
if (i < devicestate.node_remote_hardware_pins_count) {
|
||||
devicestate.node_remote_hardware_pins[i].node_num = mp.from;
|
||||
devicestate.node_remote_hardware_pins[i].pin = availablePin;
|
||||
}
|
||||
i++;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Setter methods
|
||||
*/
|
||||
@@ -487,6 +519,16 @@ void AdminModule::handleGetModuleConfig(const meshtastic_MeshPacket &req, const
|
||||
}
|
||||
}
|
||||
|
||||
void AdminModule::handleGetNodeRemoteHardwarePins(const meshtastic_MeshPacket &req)
|
||||
{
|
||||
// We create the reply here
|
||||
meshtastic_AdminMessage r = meshtastic_AdminMessage_init_default;
|
||||
memcpy(r.get_node_remote_hardware_pins_response.node_remote_hardware_pins, devicestate.node_remote_hardware_pins,
|
||||
sizeof(devicestate.node_remote_hardware_pins));
|
||||
r.which_payload_variant = meshtastic_AdminMessage_get_node_remote_hardware_pins_response_tag;
|
||||
myReply = allocDataProtobuf(r);
|
||||
}
|
||||
|
||||
void AdminModule::handleGetDeviceMetadata(const meshtastic_MeshPacket &req)
|
||||
{
|
||||
meshtastic_AdminMessage r = meshtastic_AdminMessage_init_default;
|
||||
|
||||
@@ -26,15 +26,18 @@ class AdminModule : public ProtobufModule<meshtastic_AdminMessage>
|
||||
bool hasOpenEditTransaction = false;
|
||||
|
||||
void saveChanges(int saveWhat, bool shouldReboot = true);
|
||||
|
||||
/**
|
||||
* Getters
|
||||
*/
|
||||
void handleGetModuleConfigResponse(const meshtastic_MeshPacket &req, meshtastic_AdminMessage *p);
|
||||
void handleGetOwner(const meshtastic_MeshPacket &req);
|
||||
void handleGetConfig(const meshtastic_MeshPacket &req, uint32_t configType);
|
||||
void handleGetModuleConfig(const meshtastic_MeshPacket &req, uint32_t configType);
|
||||
void handleGetChannel(const meshtastic_MeshPacket &req, uint32_t channelIndex);
|
||||
void handleGetDeviceMetadata(const meshtastic_MeshPacket &req);
|
||||
void handleGetDeviceConnectionStatus(const meshtastic_MeshPacket &req);
|
||||
void handleGetNodeRemoteHardwarePins(const meshtastic_MeshPacket &req);
|
||||
/**
|
||||
* Setters
|
||||
*/
|
||||
|
||||
@@ -53,7 +53,7 @@ bool RemoteHardwareModule::handleReceivedProtobuf(const meshtastic_MeshPacket &r
|
||||
{
|
||||
if (moduleConfig.remote_hardware.enabled) {
|
||||
auto p = *pptr;
|
||||
LOG_INFO("Received RemoteHardware typ=%d\n", p.type);
|
||||
LOG_INFO("Received RemoteHardware type=%d\n", p.type);
|
||||
|
||||
switch (p.type) {
|
||||
case meshtastic_HardwareMessage_Type_WRITE_GPIOS:
|
||||
|
||||
Reference in New Issue
Block a user