mirror of
https://github.com/mikecarper/MeshCore.git
synced 2026-10-22 16:31:15 +00:00
Extend GPIO timers and status reporting
This commit is contained in:
1 parent
1e009abe4c
commit
9b8c68d926
13 files changed
+863
-61
No files matched your search
@@ -495,7 +495,69 @@ uint8_t SensorMesh::handleLoginReq(const mesh::Identity& sender, const uint8_t*
|
||||
return 13; // reply length
|
||||
}
|
||||
|
||||
void SensorMesh::handleCommand(uint32_t sender_timestamp, char* command, char* reply) {
|
||||
#if defined(ESP32_PLATFORM) || defined(USER_GPIO_CONTROL)
|
||||
void SensorMesh::onUserGpioTimerCompleted(uint8_t pin, uint8_t state,
|
||||
uint32_t request_id) {
|
||||
int client_index;
|
||||
uint8_t path_hash_size;
|
||||
uint8_t client_tag[UserGpioReplyTracker::CLIENT_TAG_SIZE];
|
||||
if (!_gpio_reply_tracker.takeRoute(pin, request_id, client_index,
|
||||
path_hash_size, client_tag)) {
|
||||
MESH_DEBUG_PRINTLN("GPIO %u timer complete: %s", pin,
|
||||
UserGpio::stateName((UserGpio::State)state));
|
||||
return;
|
||||
}
|
||||
ClientInfo* client = NULL;
|
||||
if (client_index >= 0 && client_index < acl.getNumClients()) {
|
||||
ClientInfo* indexed = acl.getClientByIdx(client_index);
|
||||
if (UserGpioReplyTracker::matchesClient(indexed->id.pub_key, client_tag)) {
|
||||
client = indexed;
|
||||
}
|
||||
}
|
||||
if (client == NULL) {
|
||||
for (int i = 0; i < acl.getNumClients(); i++) {
|
||||
ClientInfo* candidate = acl.getClientByIdx(i);
|
||||
if (UserGpioReplyTracker::matchesClient(candidate->id.pub_key, client_tag)) {
|
||||
client = candidate;
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
if (client == NULL) return;
|
||||
|
||||
uint8_t data[72];
|
||||
uint32_t timestamp = getRTCClock()->getCurrentTimeUnique();
|
||||
if (timestamp == request_id) timestamp++;
|
||||
memcpy(data, ×tamp, 4);
|
||||
data[4] = (TXT_TYPE_CLI_DATA << 2);
|
||||
const int text_len = snprintf((char*)&data[5], sizeof(data) - 5,
|
||||
"> GPIO %u timer complete: %s", pin,
|
||||
UserGpio::stateName((UserGpio::State)state));
|
||||
if (text_len <= 0) return;
|
||||
|
||||
mesh::Packet* packet = createDatagram(PAYLOAD_TYPE_TXT_MSG, client->id,
|
||||
client->shared_secret, data,
|
||||
5 + (size_t)text_len);
|
||||
if (!packet) return;
|
||||
if (client->out_path_len == OUT_PATH_UNKNOWN) {
|
||||
sendFlood(packet, CLI_REPLY_DELAY_MILLIS, path_hash_size);
|
||||
} else {
|
||||
sendDirect(packet, client->out_path, client->out_path_len,
|
||||
CLI_REPLY_DELAY_MILLIS);
|
||||
}
|
||||
}
|
||||
#endif
|
||||
|
||||
void SensorMesh::handleCommand(uint32_t sender_timestamp, char* command, char* reply,
|
||||
int gpio_client_index,
|
||||
uint8_t gpio_path_hash_size) {
|
||||
#if defined(ESP32_PLATFORM) || defined(USER_GPIO_CONTROL)
|
||||
const uint8_t* gpio_client_key = gpio_client_index >= 0 &&
|
||||
gpio_client_index < acl.getNumClients()
|
||||
? acl.getClientByIdx(gpio_client_index)->id.pub_key : NULL;
|
||||
_gpio_reply_tracker.beginCommand(gpio_client_index, gpio_path_hash_size,
|
||||
gpio_client_key);
|
||||
#endif
|
||||
while (*command == ' ') command++; // skip leading spaces
|
||||
|
||||
if (strlen(command) > 4 && command[2] == '|') { // optional prefix (for companion radio CLI)
|
||||
@@ -707,7 +769,8 @@ void SensorMesh::onPeerDataRecv(mesh::Packet* packet, uint8_t type, int sender_i
|
||||
uint8_t temp[166];
|
||||
char *command = (char *) &data[5];
|
||||
char *reply = (char *) &temp[5];
|
||||
handleCommand(sender_timestamp, command, reply);
|
||||
handleCommand(sender_timestamp, command, reply, i,
|
||||
packet->getPathHashSize());
|
||||
|
||||
int text_len = strlen(reply);
|
||||
if (text_len > 0) {
|
||||
|
||||
Reference in new issue
Block a user