78 lines
2.1 KiB
C++
78 lines
2.1 KiB
C++
#ifndef radio_h_included
|
|
#define radio_h_included
|
|
#include "config.h"
|
|
#include "display.h"
|
|
|
|
// msgType definitions to identify message and be able to use correcnt structure
|
|
#define msgType_Clock 'c' /* clock update, sent by master using broadcast */
|
|
#define msgType_OfferPairing 'R' /* Request Registration, sent by Master using broadcast; ask clients to register */
|
|
#define msgType_RequestPairing 'r' /* Registration message, sent by Client using 1:1 message to master */
|
|
#define msgType_ackPairingRequest 'A'
|
|
#define msgType_TextMessage 'T'
|
|
|
|
// address definitions for special addresses
|
|
#define MESSAGE_TO_ALL 0xff
|
|
#define MESSAGE_TO_Master 0x00
|
|
#define MESSAGE_FROM_Master MESSAGE_TO_Master
|
|
|
|
// message structures for easy access:
|
|
struct clockMsg_s {
|
|
uint8_t msgType;
|
|
uint8_t to;
|
|
uint8_t from;
|
|
char clockName[MAX_CLOCK_NAME_LEN];
|
|
uint8_t day;
|
|
uint8_t hour;
|
|
uint8_t minute;
|
|
uint8_t second;
|
|
uint8_t speed; // msPerModelSecond / 4 --> 0..250
|
|
};
|
|
|
|
struct offerPairing_s {
|
|
uint8_t msgType;
|
|
uint8_t to;
|
|
uint8_t from;
|
|
char clockName[MAX_CLOCK_NAME_LEN];
|
|
uint8_t channel;
|
|
};
|
|
|
|
struct requestPairing_s {
|
|
uint8_t msgType;
|
|
uint8_t to;
|
|
uint8_t from;
|
|
char clientName[MAX_CLIENT_NAME_LEN];
|
|
};
|
|
|
|
struct ackPairing_s {
|
|
uint8_t msgType;
|
|
uint8_t to;
|
|
uint8_t from;
|
|
char clockName[MAX_CLOCK_NAME_LEN];
|
|
char clientName[MAX_CLIENT_NAME_LEN];
|
|
uint8_t clientNetworkAddress; // address assigned to client by controller (instead of using names, used as from/to */
|
|
};
|
|
|
|
struct textMessage_s {
|
|
uint8_t msgType;
|
|
uint8_t to;
|
|
uint8_t from;
|
|
char text[MAX_TEXT_MESSAGE_LEN];
|
|
};
|
|
|
|
class Radio {
|
|
public:
|
|
Radio(Display *d, bool _isMaster):display(d), isMaster(_isMaster) { };
|
|
void begin(void);
|
|
void loop(void);
|
|
void broadcastClock(int day, int hour, int minute, int second, int msPerModelSecond);
|
|
void broadcastOfferPairing(const char *clockName, uint8_t channel);
|
|
void broadcastTextMessage(const char *text);
|
|
void handleRequestPairing(struct requestPairing_s *request);
|
|
void ackPairingRequest(char *clientName, uint8_t clientNetworkAddress);
|
|
private:
|
|
Display *display;
|
|
bool isMaster;
|
|
void broadcastMessage(void *msg, int len);
|
|
};
|
|
#endif
|