* companion radio: connection status now supported (Keep_alive pings, etc)

This commit is contained in:
Scott Powell 2025-03-02 20:15:13 +11:00
parent 0a5bcb9e2c
commit 1a4063bbe8
4 changed files with 168 additions and 9 deletions

View file

@ -27,7 +27,8 @@ struct ContactInfo {
#define MSG_SEND_SENT_FLOOD 1
#define MSG_SEND_SENT_DIRECT 2
#define CMD_GET_STATUS 0x01 // same as _GET_STATS
#define REQ_TYPE_GET_STATUS 0x01 // same as _GET_STATS
#define REQ_TYPE_KEEP_ALIVE 0x02
#define RESP_SERVER_LOGIN_OK 0 // response to ANON_REQ
@ -48,6 +49,18 @@ public:
#define MAX_CONTACTS 32
#endif
#ifndef MAX_CONNECTIONS
#define MAX_CONNECTIONS 16
#endif
struct ConnectionInfo {
mesh::Identity server_id;
unsigned long next_ping;
uint32_t last_activity;
uint32_t keep_alive_millis;
uint32_t expected_ack;
};
/**
* \brief abstract Mesh class for common 'chat' client
*/
@ -66,6 +79,7 @@ class BaseChatMesh : public mesh::Mesh {
#endif
mesh::Packet* _pendingLoopback;
uint8_t temp_buf[MAX_TRANS_UNIT];
ConnectionInfo connections[MAX_CONNECTIONS];
mesh::Packet* composeMsgPacket(const ContactInfo& recipient, uint32_t timestamp, uint8_t attempt, const char *text, uint32_t& expected_ack);
@ -79,6 +93,7 @@ protected:
#endif
txt_send_timeout = 0;
_pendingLoopback = NULL;
memset(connections, 0, sizeof(connections));
}
// 'UI' concepts, for sub-classes to implement
@ -110,6 +125,14 @@ protected:
#endif
void onGroupDataRecv(mesh::Packet* packet, uint8_t type, const mesh::GroupChannel& channel, uint8_t* data, size_t len) override;
// Connections
bool startConnection(const ContactInfo& contact, uint16_t keep_alive_secs);
void stopConnection(const uint8_t* pub_key);
bool hasConnectionTo(const uint8_t* pub_key);
void markConnectionActive(const ContactInfo& contact);
bool checkConnectionsAck(const uint8_t* data);
void checkConnections();
public:
mesh::Packet* createSelfAdvert(const char* name, double lat=0.0, double lon=0.0);
int sendMessage(const ContactInfo& recipient, uint32_t timestamp, uint8_t attempt, const char* text, uint32_t& expected_ack, uint32_t& est_timeout);