Skip to content
Snippets Groups Projects
Commit 192c0477 authored by Dónal Murray's avatar Dónal Murray
Browse files

Rename protocol address enum to priority

parent be6031c7
No related merge requests found
...@@ -40,11 +40,11 @@ ...@@ -40,11 +40,11 @@
#define PACKET_SET 0x20 //set vs get ? #define PACKET_SET 0x20 //set vs get ?
// enum of all transfer types // enum of all transfer types
enum PAYLOAD_TYPE { enum PRIORITY {
DATA, DATA = PACKET_DATA,
CMD, CMD = PACKET_CMD,
ALARM, ALARM = PACKET_ALARM,
UNSET UNSET = 0x00
}; };
// payload consists of type and information // payload consists of type and information
...@@ -52,7 +52,7 @@ enum PAYLOAD_TYPE { ...@@ -52,7 +52,7 @@ enum PAYLOAD_TYPE {
// information is set as information in the protocol // information is set as information in the protocol
class Payload { class Payload {
public: public:
Payload(PAYLOAD_TYPE type = PAYLOAD_TYPE::UNSET) {_type = type; } Payload(PRIORITY type = PRIORITY::UNSET) {_type = type; }
Payload(const Payload &other) { Payload(const Payload &other) {
_type = other._type; _type = other._type;
_size = other._size; _size = other._size;
...@@ -66,15 +66,15 @@ public: ...@@ -66,15 +66,15 @@ public:
} }
~Payload() { unset(); } ~Payload() { unset(); }
void unset() { memset( _buffer, 0, PAYLOAD_MAX_SIZE_BUFFER); _type = PAYLOAD_TYPE::UNSET; _size = 0;} void unset() { memset( _buffer, 0, PAYLOAD_MAX_SIZE_BUFFER); _type = PRIORITY::UNSET; _size = 0;}
void setType(PAYLOAD_TYPE type) { _type = type; } void setType(PRIORITY type) { _type = type; }
PAYLOAD_TYPE getType() {return _type; } PRIORITY getType() {return _type; }
void setSize(uint8_t size) { _size = size; } void setSize(uint8_t size) { _size = size; }
uint8_t getSize() { return _size; } uint8_t getSize() { return _size; }
bool setPayload(PAYLOAD_TYPE type, void* information, uint8_t size) { bool setPayload(PRIORITY type, void* information, uint8_t size) {
if (information == nullptr) { if (information == nullptr) {
return false; return false;
} }
...@@ -87,12 +87,12 @@ public: ...@@ -87,12 +87,12 @@ public:
} }
bool getPayload(void* information) { bool getPayload(void* information) {
PAYLOAD_TYPE type; PRIORITY type;
uint8_t size; uint8_t size;
return getPayload(information, type, size); return getPayload(information, type, size);
} }
bool getPayload(void* information, PAYLOAD_TYPE &type, uint8_t &size) { bool getPayload(void* information, PRIORITY &type, uint8_t &size) {
if (information == nullptr) { if (information == nullptr) {
return false; return false;
} }
...@@ -108,7 +108,7 @@ public: ...@@ -108,7 +108,7 @@ public:
void *getInformation() { return reinterpret_cast<void*>(_buffer); } void *getInformation() { return reinterpret_cast<void*>(_buffer); }
private: private:
PAYLOAD_TYPE _type; PRIORITY _type;
uint8_t _buffer[PAYLOAD_MAX_SIZE_BUFFER]; uint8_t _buffer[PAYLOAD_MAX_SIZE_BUFFER];
uint8_t _size; uint8_t _size;
}; };
......
...@@ -88,7 +88,7 @@ void CommsControl::receiver() { ...@@ -88,7 +88,7 @@ void CommsControl::receiver() {
uint8_t address = *_comms_tmp.getAddress(); uint8_t address = *_comms_tmp.getAddress();
// to decide what kind of packets received // to decide what kind of packets received
PAYLOAD_TYPE type = getInfoType(address); PRIORITY type = getInfoType(address);
// switch on received data to know what to do - received ACK/NACK or other // switch on received data to know what to do - received ACK/NACK or other
switch(control & COMMS_CONTROL_TYPES) { switch(control & COMMS_CONTROL_TYPES) {
...@@ -136,8 +136,8 @@ void CommsControl::receiver() { ...@@ -136,8 +136,8 @@ void CommsControl::receiver() {
} }
bool CommsControl::writePayload(Payload &pl) { bool CommsControl::writePayload(Payload &pl) {
PAYLOAD_TYPE payload_type = pl.getType(); PRIORITY payload_type = pl.getType();
if (payload_type != PAYLOAD_TYPE::UNSET) { if (payload_type != PRIORITY::UNSET) {
// create comms format using payload, the type is deduced from the payload itself // create comms format using payload, the type is deduced from the payload itself
CommsFormat comms = CommsFormat(pl); CommsFormat comms = CommsFormat(pl);
...@@ -243,7 +243,7 @@ void CommsControl::resendPacket(RingBuf<CommsFormat, COMMS_MAX_SIZE_RB_SENDING> ...@@ -243,7 +243,7 @@ void CommsControl::resendPacket(RingBuf<CommsFormat, COMMS_MAX_SIZE_RB_SENDING>
// receiving anything of commsFormat // receiving anything of commsFormat
bool CommsControl::receivePacket(PAYLOAD_TYPE &type) { bool CommsControl::receivePacket(PRIORITY &type) {
_payload_tmp.unset(); _payload_tmp.unset();
_payload_tmp.setPayload(type, reinterpret_cast<void *>(_comms_tmp.getInformation()), _comms_tmp.getInfoSize()); _payload_tmp.setPayload(type, reinterpret_cast<void *>(_comms_tmp.getInformation()), _comms_tmp.getInfoSize());
...@@ -258,7 +258,7 @@ bool CommsControl::receivePacket(PAYLOAD_TYPE &type) { ...@@ -258,7 +258,7 @@ bool CommsControl::receivePacket(PAYLOAD_TYPE &type) {
} }
// if FCS is ok, remove from queue // if FCS is ok, remove from queue
void CommsControl::finishPacket(PAYLOAD_TYPE &type) { void CommsControl::finishPacket(PRIORITY &type) {
RingBuf<CommsFormat, COMMS_MAX_SIZE_RB_SENDING> *queue = getQueue(type); RingBuf<CommsFormat, COMMS_MAX_SIZE_RB_SENDING> *queue = getQueue(type);
if (queue != nullptr && !queue->isEmpty()) { if (queue != nullptr && !queue->isEmpty()) {
...@@ -274,27 +274,27 @@ void CommsControl::finishPacket(PAYLOAD_TYPE &type) { ...@@ -274,27 +274,27 @@ void CommsControl::finishPacket(PAYLOAD_TYPE &type) {
} }
} }
PAYLOAD_TYPE CommsControl::getInfoType(uint8_t &address) { PRIORITY CommsControl::getInfoType(uint8_t &address) {
switch (address & PACKET_TYPE) { switch (address & PACKET_TYPE) {
case PACKET_ALARM: case PACKET_ALARM:
return PAYLOAD_TYPE::ALARM; return PRIORITY::ALARM;
case PACKET_CMD: case PACKET_CMD:
return PAYLOAD_TYPE::CMD; return PRIORITY::CMD;
case PACKET_DATA: case PACKET_DATA:
return PAYLOAD_TYPE::DATA; return PRIORITY::DATA;
default: default:
return PAYLOAD_TYPE::UNSET; return PRIORITY::UNSET;
} }
} }
// get link to queue according to packet format // get link to queue according to packet format
RingBuf<CommsFormat, COMMS_MAX_SIZE_RB_SENDING> *CommsControl::getQueue(PAYLOAD_TYPE &type) { RingBuf<CommsFormat, COMMS_MAX_SIZE_RB_SENDING> *CommsControl::getQueue(PRIORITY &type) {
switch (type) { switch (type) {
case PAYLOAD_TYPE::ALARM: case PRIORITY::ALARM:
return &_ring_buff_alarm; return &_ring_buff_alarm;
case PAYLOAD_TYPE::CMD: case PRIORITY::CMD:
return &_ring_buff_cmd; return &_ring_buff_cmd;
case PAYLOAD_TYPE::DATA: case PRIORITY::DATA:
return &_ring_buff_data; return &_ring_buff_data;
default: default:
return nullptr; return nullptr;
......
...@@ -26,13 +26,13 @@ public: ...@@ -26,13 +26,13 @@ public:
void receiver(); void receiver();
private: private:
RingBuf<CommsFormat, COMMS_MAX_SIZE_RB_SENDING> *getQueue(PAYLOAD_TYPE &type); RingBuf<CommsFormat, COMMS_MAX_SIZE_RB_SENDING> *getQueue(PRIORITY &type);
PAYLOAD_TYPE getInfoType(uint8_t &address); PRIORITY getInfoType(uint8_t &address);
void sendQueue (RingBuf<CommsFormat, COMMS_MAX_SIZE_RB_SENDING> *queue); void sendQueue (RingBuf<CommsFormat, COMMS_MAX_SIZE_RB_SENDING> *queue);
void resendPacket (RingBuf<CommsFormat, COMMS_MAX_SIZE_RB_SENDING> *queue); void resendPacket (RingBuf<CommsFormat, COMMS_MAX_SIZE_RB_SENDING> *queue);
bool receivePacket(PAYLOAD_TYPE &type); bool receivePacket(PRIORITY &type);
void finishPacket (PAYLOAD_TYPE &type); void finishPacket (PRIORITY &type);
bool encoder(uint8_t* payload, uint8_t data_size); bool encoder(uint8_t* payload, uint8_t data_size);
bool decoder(uint8_t* payload, uint8_t dataStart, uint8_t data_stop); bool decoder(uint8_t* payload, uint8_t dataStart, uint8_t data_stop);
......
...@@ -8,13 +8,13 @@ CommsFormat::CommsFormat(uint8_t info_size, uint8_t address, uint16_t control) { ...@@ -8,13 +8,13 @@ CommsFormat::CommsFormat(uint8_t info_size, uint8_t address, uint16_t control) {
CommsFormat::CommsFormat(Payload &pl) { CommsFormat::CommsFormat(Payload &pl) {
uint8_t address; uint8_t address;
switch (pl.getType()) { switch (pl.getType()) {
case PAYLOAD_TYPE::ALARM: case PRIORITY::ALARM:
address = PACKET_ALARM; address = PACKET_ALARM;
break; break;
case PAYLOAD_TYPE::CMD: case PRIORITY::CMD:
address = PACKET_CMD; address = PACKET_CMD;
break; break;
case PAYLOAD_TYPE::DATA: case PRIORITY::DATA:
address = PACKET_DATA; address = PACKET_DATA;
break; break;
default: default:
......
...@@ -25,7 +25,7 @@ void UILoop::receiveCommands() ...@@ -25,7 +25,7 @@ void UILoop::receiveCommands()
// check any received payload // check any received payload
if(_comms->readPayload(_plReceive)) { if(_comms->readPayload(_plReceive)) {
if (_plReceive.getType() == PAYLOAD_TYPE::CMD) { if (_plReceive.getType() == PRIORITY::CMD) {
// apply received cmd to ui loop // apply received cmd to ui loop
cmd_format cmd; cmd_format cmd;
_plReceive.getPayload(reinterpret_cast<void*>(&cmd)); _plReceive.getPayload(reinterpret_cast<void*>(&cmd));
...@@ -33,7 +33,7 @@ void UILoop::receiveCommands() ...@@ -33,7 +33,7 @@ void UILoop::receiveCommands()
} }
// unset received type not to read it again // unset received type not to read it again
_plReceive.setType(PAYLOAD_TYPE::UNSET); _plReceive.setType(PRIORITY::UNSET);
} }
} }
...@@ -56,7 +56,7 @@ void UILoop::reportFastReadings() ...@@ -56,7 +56,7 @@ void UILoop::reportFastReadings()
_fast_data.pressure_o2_regulated = readings_avgs.pressure_o2_regulated; _fast_data.pressure_o2_regulated = readings_avgs.pressure_o2_regulated;
_fast_data.pressure_diff_patient = readings_avgs.pressure_diff_patient; _fast_data.pressure_diff_patient = readings_avgs.pressure_diff_patient;
_plSend.setPayload(PAYLOAD_TYPE::DATA, reinterpret_cast<void *>(&_fast_data), sizeof(_fast_data)); _plSend.setPayload(PRIORITY::DATA, reinterpret_cast<void *>(&_fast_data), sizeof(_fast_data));
_comms->writePayload(_plSend); _comms->writePayload(_plSend);
_fast_report_time = tnow; _fast_report_time = tnow;
} }
...@@ -107,7 +107,7 @@ void UILoop::reportReadbackValues() ...@@ -107,7 +107,7 @@ void UILoop::reportReadbackValues()
// _readback_data.peep = _breathing_loop->peep(); // _readback_data.peep = _breathing_loop->peep();
_readback_data.inhale_exhale_ratio = _breathing_loop->getIERatio(); _readback_data.inhale_exhale_ratio = _breathing_loop->getIERatio();
_plSend.setPayload(PAYLOAD_TYPE::DATA, reinterpret_cast<void *>(&_readback_data), sizeof(_readback_data)); _plSend.setPayload(PRIORITY::DATA, reinterpret_cast<void *>(&_readback_data), sizeof(_readback_data));
_comms->writePayload(_plSend); _comms->writePayload(_plSend);
_readback_report_time = tnow; _readback_report_time = tnow;
} }
...@@ -121,7 +121,7 @@ void UILoop::reportCycleReadings() ...@@ -121,7 +121,7 @@ void UILoop::reportCycleReadings()
_cycle_data.timestamp = tnow; _cycle_data.timestamp = tnow;
_plSend.setPayload(PAYLOAD_TYPE::DATA, reinterpret_cast<void *>(&_cycle_data), sizeof(_cycle_data)); _plSend.setPayload(PRIORITY::DATA, reinterpret_cast<void *>(&_cycle_data), sizeof(_cycle_data));
_comms->writePayload(_plSend); _comms->writePayload(_plSend);
_cycle_report_time = tnow; _cycle_report_time = tnow;
} }
......
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment