mirror of
https://github.com/meshtastic/firmware.git
synced 2025-09-10 05:04:42 +00:00
Don't send to public channel
This depends on protobufs pr. Shorten messages. Allows sending Detection messages in a DM or private channel, sending to a public channel will be blocked.
This commit is contained in:
parent
8e2a3e5728
commit
786036f15a
@ -5,7 +5,9 @@
|
|||||||
#include "PowerFSM.h"
|
#include "PowerFSM.h"
|
||||||
#include "configuration.h"
|
#include "configuration.h"
|
||||||
#include "main.h"
|
#include "main.h"
|
||||||
|
#include <Channels.h>
|
||||||
#include <Throttle.h>
|
#include <Throttle.h>
|
||||||
|
|
||||||
DetectionSensorModule *detectionSensorModule;
|
DetectionSensorModule *detectionSensorModule;
|
||||||
|
|
||||||
#define GPIO_POLLING_INTERVAL 100
|
#define GPIO_POLLING_INTERVAL 100
|
||||||
@ -60,6 +62,8 @@ int32_t DetectionSensorModule::runOnce()
|
|||||||
// moduleConfig.detection_sensor.detection_trigger_type =
|
// moduleConfig.detection_sensor.detection_trigger_type =
|
||||||
// meshtastic_ModuleConfig_DetectionSensorConfig_TriggerType_LOGIC_HIGH;
|
// meshtastic_ModuleConfig_DetectionSensorConfig_TriggerType_LOGIC_HIGH;
|
||||||
// strcpy(moduleConfig.detection_sensor.name, "Motion");
|
// strcpy(moduleConfig.detection_sensor.name, "Motion");
|
||||||
|
// moduleConfig.detection_sensor.sendTochannel = true;
|
||||||
|
// strcpy(moduleConfig.detection_sensor.sendTo, "NIU"); // Send to NodeID or Channel Name
|
||||||
|
|
||||||
if (moduleConfig.detection_sensor.enabled == false)
|
if (moduleConfig.detection_sensor.enabled == false)
|
||||||
return disable();
|
return disable();
|
||||||
@ -76,16 +80,15 @@ int32_t DetectionSensorModule::runOnce()
|
|||||||
if (moduleConfig.detection_sensor.monitor_pin > 0) {
|
if (moduleConfig.detection_sensor.monitor_pin > 0) {
|
||||||
pinMode(moduleConfig.detection_sensor.monitor_pin, moduleConfig.detection_sensor.use_pullup ? INPUT_PULLUP : INPUT);
|
pinMode(moduleConfig.detection_sensor.monitor_pin, moduleConfig.detection_sensor.use_pullup ? INPUT_PULLUP : INPUT);
|
||||||
} else {
|
} else {
|
||||||
LOG_WARN("Detection Sensor Module: Set to enabled but no monitor pin is set. Disable module...");
|
LOG_WARN("DetectionSensor: no monitor pin set. Disabling module...");
|
||||||
return disable();
|
return disable();
|
||||||
}
|
}
|
||||||
LOG_INFO("Detection Sensor Module: init");
|
LOG_INFO("DetectionSensor: Init");
|
||||||
|
|
||||||
return DELAYED_INTERVAL;
|
return DELAYED_INTERVAL;
|
||||||
}
|
}
|
||||||
|
|
||||||
// LOG_DEBUG("Detection Sensor Module: Current pin state: %i", digitalRead(moduleConfig.detection_sensor.monitor_pin));
|
// LOG_DEBUG("Detection Sensor: Pin state: %i", digitalRead(moduleConfig.detection_sensor.monitor_pin));
|
||||||
|
|
||||||
if (!Throttle::isWithinTimespanMs(lastSentToMesh,
|
if (!Throttle::isWithinTimespanMs(lastSentToMesh,
|
||||||
Default::getConfiguredOrDefaultMs(moduleConfig.detection_sensor.minimum_broadcast_secs))) {
|
Default::getConfiguredOrDefaultMs(moduleConfig.detection_sensor.minimum_broadcast_secs))) {
|
||||||
bool isDetected = hasDetectionEvent();
|
bool isDetected = hasDetectionEvent();
|
||||||
@ -118,11 +121,24 @@ int32_t DetectionSensorModule::runOnce()
|
|||||||
|
|
||||||
void DetectionSensorModule::sendDetectionMessage()
|
void DetectionSensorModule::sendDetectionMessage()
|
||||||
{
|
{
|
||||||
LOG_DEBUG("Detected event observed. Send message");
|
if (moduleConfig.detection_sensor.sendTo[0] != 0x00) {
|
||||||
|
LOG_DEBUG("Detected event. Sending message");
|
||||||
char *message = new char[40];
|
char *message = new char[40];
|
||||||
|
bool isValidrecipient = false;
|
||||||
sprintf(message, "%s detected", moduleConfig.detection_sensor.name);
|
sprintf(message, "%s detected", moduleConfig.detection_sensor.name);
|
||||||
meshtastic_MeshPacket *p = allocDataPacket();
|
meshtastic_MeshPacket *p = allocDataPacket();
|
||||||
p->want_ack = false;
|
p->want_ack = false;
|
||||||
|
if (moduleConfig.detection_sensor.sendTochannel) {
|
||||||
|
const auto &ch = channels.getByName(moduleConfig.detection_sensor.sendTo);
|
||||||
|
if (!channels.isDefaultChannel(ch.index)) {
|
||||||
|
p->channel = ch.index;
|
||||||
|
isValidrecipient = true;
|
||||||
|
} else
|
||||||
|
LOG_INFO("%s is public/not found", moduleConfig.detection_sensor.sendTo);
|
||||||
|
} else {
|
||||||
|
p->to = (uint32_t)strtoul(moduleConfig.detection_sensor.sendTo, NULL, sizeof(moduleConfig.detection_sensor.sendTo));
|
||||||
|
isValidrecipient = true;
|
||||||
|
}
|
||||||
p->decoded.payload.size = strlen(message);
|
p->decoded.payload.size = strlen(message);
|
||||||
memcpy(p->decoded.payload.bytes, message, p->decoded.payload.size);
|
memcpy(p->decoded.payload.bytes, message, p->decoded.payload.size);
|
||||||
if (moduleConfig.detection_sensor.send_bell && p->decoded.payload.size < meshtastic_Constants_DATA_PAYLOAD_LEN) {
|
if (moduleConfig.detection_sensor.send_bell && p->decoded.payload.size < meshtastic_Constants_DATA_PAYLOAD_LEN) {
|
||||||
@ -130,30 +146,56 @@ void DetectionSensorModule::sendDetectionMessage()
|
|||||||
p->decoded.payload.bytes[p->decoded.payload.size + 1] = '\0'; // Bell character
|
p->decoded.payload.bytes[p->decoded.payload.size + 1] = '\0'; // Bell character
|
||||||
p->decoded.payload.size++;
|
p->decoded.payload.size++;
|
||||||
}
|
}
|
||||||
LOG_INFO("Send message id=%d, dest=%x, msg=%.*s", p->id, p->to, p->decoded.payload.size, p->decoded.payload.bytes);
|
|
||||||
lastSentToMesh = millis();
|
lastSentToMesh = millis();
|
||||||
|
if (isValidrecipient) {
|
||||||
|
LOG_INFO("Send message id=%d, dest=%x, msg=%.*s", p->id,
|
||||||
|
(moduleConfig.detection_sensor.sendTochannel ? p->channel : p->to),
|
||||||
|
p->decoded.payload.size,
|
||||||
|
p->decoded.payload.bytes);
|
||||||
service->sendToMesh(p);
|
service->sendToMesh(p);
|
||||||
|
}
|
||||||
delete[] message;
|
delete[] message;
|
||||||
|
} else
|
||||||
|
LOG_INFO("DetectionSensor: no recipient");
|
||||||
}
|
}
|
||||||
|
|
||||||
void DetectionSensorModule::sendCurrentStateMessage(bool state)
|
void DetectionSensorModule::sendCurrentStateMessage(bool state)
|
||||||
{
|
{
|
||||||
|
if (moduleConfig.detection_sensor.sendTo[0] != 0x00) {
|
||||||
char *message = new char[40];
|
char *message = new char[40];
|
||||||
|
bool isValidrecipient = false;
|
||||||
sprintf(message, "%s state: %i", moduleConfig.detection_sensor.name, state);
|
sprintf(message, "%s state: %i", moduleConfig.detection_sensor.name, state);
|
||||||
|
|
||||||
meshtastic_MeshPacket *p = allocDataPacket();
|
meshtastic_MeshPacket *p = allocDataPacket();
|
||||||
p->want_ack = false;
|
p->want_ack = false;
|
||||||
|
if (moduleConfig.detection_sensor.sendTochannel) {
|
||||||
|
const auto &ch = channels.getByName(moduleConfig.detection_sensor.sendTo);
|
||||||
|
if (!channels.isDefaultChannel(ch.index)) {
|
||||||
|
p->channel = ch.index;
|
||||||
|
isValidrecipient = true;
|
||||||
|
} else
|
||||||
|
LOG_INFO("%s is public/not found", moduleConfig.detection_sensor.sendTo);
|
||||||
|
} else {
|
||||||
|
p->to = (uint32_t)strtoul(moduleConfig.detection_sensor.sendTo, NULL, sizeof(moduleConfig.detection_sensor.sendTo));
|
||||||
|
isValidrecipient = true;
|
||||||
|
}
|
||||||
p->decoded.payload.size = strlen(message);
|
p->decoded.payload.size = strlen(message);
|
||||||
memcpy(p->decoded.payload.bytes, message, p->decoded.payload.size);
|
memcpy(p->decoded.payload.bytes, message, p->decoded.payload.size);
|
||||||
LOG_INFO("Send message id=%d, dest=%x, msg=%.*s", p->id, p->to, p->decoded.payload.size, p->decoded.payload.bytes);
|
|
||||||
lastSentToMesh = millis();
|
lastSentToMesh = millis();
|
||||||
|
if (isValidrecipient) {
|
||||||
|
LOG_INFO("Send message id=%d, dest=%x, msg=%.*s", p->id,
|
||||||
|
(moduleConfig.detection_sensor.sendTochannel ? p->channel : p->to),
|
||||||
|
p->decoded.payload.size,
|
||||||
|
p->decoded.payload.bytes);
|
||||||
service->sendToMesh(p);
|
service->sendToMesh(p);
|
||||||
|
}
|
||||||
delete[] message;
|
delete[] message;
|
||||||
|
} else
|
||||||
|
LOG_INFO("Detection Sensor: no recipient");
|
||||||
}
|
}
|
||||||
|
|
||||||
bool DetectionSensorModule::hasDetectionEvent()
|
bool DetectionSensorModule::hasDetectionEvent()
|
||||||
{
|
{
|
||||||
bool currentState = digitalRead(moduleConfig.detection_sensor.monitor_pin);
|
bool currentState = digitalRead(moduleConfig.detection_sensor.monitor_pin);
|
||||||
// LOG_DEBUG("Detection Sensor Module: Current state: %i", currentState);
|
// LOG_DEBUG("Detection Sensor: state: %i", currentState);
|
||||||
return (moduleConfig.detection_sensor.detection_trigger_type & 1) ? currentState : !currentState;
|
return (moduleConfig.detection_sensor.detection_trigger_type & 1) ? currentState : !currentState;
|
||||||
}
|
}
|
Loading…
Reference in New Issue
Block a user