Loom 4 v4.5
Arduino library for Internet of Things Rapid Prototyping in environmental sensing
Loading...
Searching...
No Matches
Radio.h
1#pragma once
2
3#include <SPI.h>
4#include "Logger.h"
5#include "../Module.h"
6#include <ArduinoJson.h>
7
13class Radio : public Module{
14 protected:
15 uint8_t deviceAddress; // Device address
16 uint16_t maxMessageLength; // Maximum length a packet can be
17 int16_t signalStrength; // Strength of the signal received
18
19 uint8_t powerLevel; // The power level we want to transmit at
20 uint8_t retryCount; // Number transmission retries allowed
21 uint16_t retryTimeout; // Delay between retries (MS)
22
23 StaticJsonDocument<300> recvDoc; // Individual Document Representing what is being received
24 StaticJsonDocument<300> sendDoc; // Individual Document Representing what is being sent
25
29 uint8_t getAddress() const { return deviceAddress; };
30
34 int16_t getSignalStrength() { return signalStrength; };
35
40 virtual bool receive(uint maxWaitTime) = 0;
41
46 virtual bool send(const uint8_t destinationAddress) = 0;
47
51 bool bufferToJson(uint8_t* buffer){
52 char output[OUTPUT_SIZE];
53 DeserializationError error = deserializeMsgPack(recvDoc, (const char*)buffer, maxMessageLength);
54
55 // Check if an error occurred
56 if(error != DeserializationError::Ok){
57 snprintf(output, OUTPUT_SIZE, "Error occurred parsing MsgPack: %s", error.c_str());
58 ERROR(output);
59 return false;
60 }
61
62 return true;
63 };
64
68 bool jsonToBuffer(uint8_t* buffer, JsonObjectConst json){
69
70 bool status = serializeMsgPack(json, buffer, maxMessageLength);
71 Serial.println();
72
73 return status;
74 };
75
76 public:
77
83 Radio(const char* moduleName) : Module(moduleName) {};
84};
Definition: Module.h:30
Definition: Radio.h:13
bool bufferToJson(uint8_t *buffer)
Definition: Radio.h:51
int16_t getSignalStrength()
Definition: Radio.h:34
uint8_t getAddress() const
Definition: Radio.h:29
bool jsonToBuffer(uint8_t *buffer, JsonObjectConst json)
Definition: Radio.h:68
virtual bool receive(uint maxWaitTime)=0
virtual bool send(const uint8_t destinationAddress)=0
Radio(const char *moduleName)
Definition: Radio.h:83