mirror of
https://github.com/meshtastic/firmware.git
synced 2025-04-25 09:42:35 +00:00
Add ClientNotification hello world
This commit is contained in:
parent
2012a0ae1c
commit
861f0b6769
@ -48,14 +48,18 @@ static MemoryDynamic<meshtastic_MqttClientProxyMessage> staticMqttClientProxyMes
|
||||
|
||||
static MemoryDynamic<meshtastic_QueueStatus> staticQueueStatusPool;
|
||||
|
||||
static MemoryDynamic<meshtastic_ClientNotification> staticClientNotificationPool;
|
||||
|
||||
Allocator<meshtastic_MqttClientProxyMessage> &mqttClientProxyMessagePool = staticMqttClientProxyMessagePool;
|
||||
|
||||
Allocator<meshtastic_ClientNotification> &clientNotificationPool = staticClientNotificationPool;
|
||||
|
||||
Allocator<meshtastic_QueueStatus> &queueStatusPool = staticQueueStatusPool;
|
||||
|
||||
#include "Router.h"
|
||||
|
||||
MeshService::MeshService()
|
||||
: toPhoneQueue(MAX_RX_TOPHONE), toPhoneQueueStatusQueue(MAX_RX_TOPHONE), toPhoneMqttProxyQueue(MAX_RX_TOPHONE)
|
||||
: toPhoneQueue(MAX_RX_TOPHONE), toPhoneQueueStatusQueue(MAX_RX_TOPHONE), toPhoneMqttProxyQueue(MAX_RX_TOPHONE), toPhoneClientNotificationQueue(MAX_RX_TOPHONE / 2)
|
||||
{
|
||||
lastQueueStatus = {0, 0, 16, 0};
|
||||
}
|
||||
@ -324,6 +328,20 @@ void MeshService::sendMqttMessageToClientProxy(meshtastic_MqttClientProxyMessage
|
||||
fromNum++;
|
||||
}
|
||||
|
||||
void MeshService::sendClientNotification(meshtastic_ClientNotification *n)
|
||||
{
|
||||
LOG_DEBUG("Sending client notification to phone\n");
|
||||
if (toPhoneClientNotificationQueue.numFree() == 0) {
|
||||
LOG_WARN("ClientNotification queue is full, discarding oldest\n");
|
||||
meshtastic_ClientNotification *d = toPhoneClientNotificationQueue.dequeuePtr(0);
|
||||
if (d)
|
||||
releaseClientNotificationToPool(d);
|
||||
}
|
||||
|
||||
assert(toPhoneClientNotificationQueue.enqueue(n, 0));
|
||||
fromNum++;
|
||||
}
|
||||
|
||||
meshtastic_NodeInfoLite *MeshService::refreshLocalMeshNode()
|
||||
{
|
||||
meshtastic_NodeInfoLite *node = nodeDB->getMeshNode(nodeDB->getNodeNum());
|
||||
|
@ -21,6 +21,7 @@
|
||||
|
||||
extern Allocator<meshtastic_QueueStatus> &queueStatusPool;
|
||||
extern Allocator<meshtastic_MqttClientProxyMessage> &mqttClientProxyMessagePool;
|
||||
extern Allocator<meshtastic_ClientNotification> &clientNotificationPool;
|
||||
|
||||
/**
|
||||
* Top level app for this service. keeps the mesh, the radio config and the queue of received packets.
|
||||
@ -44,6 +45,9 @@ class MeshService
|
||||
// keep list of MqttClientProxyMessages to be send to the client for delivery
|
||||
PointerQueue<meshtastic_MqttClientProxyMessage> toPhoneMqttProxyQueue;
|
||||
|
||||
// keep list of ClientNotifications to be send to the client (phone)
|
||||
PointerQueue<meshtastic_ClientNotification> toPhoneClientNotificationQueue;
|
||||
|
||||
// This holds the last QueueStatus send
|
||||
meshtastic_QueueStatus lastQueueStatus;
|
||||
|
||||
@ -97,6 +101,9 @@ class MeshService
|
||||
// Release MqttClientProxyMessage packet to pool
|
||||
void releaseMqttClientProxyMessageToPool(meshtastic_MqttClientProxyMessage *p) { mqttClientProxyMessagePool.release(p); }
|
||||
|
||||
/// Release the next ClientNotification packet to pool.
|
||||
void releaseClientNotificationToPool(meshtastic_ClientNotification *p) { clientNotificationPool.release(p); }
|
||||
|
||||
/**
|
||||
* Given a ToRadio buffer parse it and properly handle it (setup radio, owner or send packet into the mesh)
|
||||
* Called by PhoneAPI.handleToRadio. Note: p is a scratch buffer, this function is allowed to write to it but it can not keep
|
||||
@ -134,6 +141,9 @@ class MeshService
|
||||
/// Send an MQTT message to the phone for client proxying
|
||||
void sendMqttMessageToClientProxy(meshtastic_MqttClientProxyMessage *m);
|
||||
|
||||
/// Send a ClientNotification to the phone
|
||||
void sendClientNotification(meshtastic_ClientNotification *cn);
|
||||
|
||||
bool isToPhoneQueueEmpty();
|
||||
|
||||
ErrorCode sendQueueStatusToPhone(const meshtastic_QueueStatus &qs, ErrorCode res, uint32_t mesh_packet_id);
|
||||
|
@ -66,6 +66,9 @@ class PhoneAPI
|
||||
// Keep MqttClientProxyMessage packet just as packetForPhone
|
||||
meshtastic_MqttClientProxyMessage *mqttClientProxyMessageForPhone = NULL;
|
||||
|
||||
// Keep ClientNotification packet just as packetForPhone
|
||||
meshtastic_ClientNotification *clientNotification = NULL;
|
||||
|
||||
/// We temporarily keep the nodeInfo here between the call to available and getFromRadio
|
||||
meshtastic_NodeInfo nodeInfoForPhone = meshtastic_NodeInfo_init_default;
|
||||
|
||||
|
@ -2,6 +2,7 @@
|
||||
#include "Channels.h"
|
||||
#include "CryptoEngine.h"
|
||||
#include "MeshRadio.h"
|
||||
#include "MeshService.h"
|
||||
#include "NodeDB.h"
|
||||
#include "RTC.h"
|
||||
#include "configuration.h"
|
||||
@ -209,6 +210,13 @@ ErrorCode Router::send(meshtastic_MeshPacket *p)
|
||||
#ifdef DEBUG_PORT
|
||||
uint8_t silentMinutes = airTime->getSilentMinutes(hourlyTxPercent, myRegion->dutyCycle);
|
||||
LOG_WARN("Duty cycle limit exceeded. Aborting send for now, you can send again in %d minutes.\n", silentMinutes);
|
||||
meshtastic_ClientNotification *cn = clientNotificationPool.allocZeroed();
|
||||
cn->has_reply_id = true;
|
||||
cn->reply_id = p->id;
|
||||
cn->level = meshtastic_LogRecord_Level_WARNING;
|
||||
cn->time = getValidTime(RTCQualityFromNet);
|
||||
sprintf(cn->message, "Duty cycle limit exceeded. You can send again in %d minutes.", silentMinutes);
|
||||
service->sendClientNotification(cn);
|
||||
#endif
|
||||
meshtastic_Routing_Error err = meshtastic_Routing_Error_DUTY_CYCLE_LIMIT;
|
||||
if (getFrom(p) == nodeDB->getNodeNum()) { // only send NAK to API, not to the mesh
|
||||
|
Loading…
Reference in New Issue
Block a user