Murata RF modules are designed to simplify wireless development and certification by minimizing the amount of RF expertise you need to wirelessly enable a wide range of applications.
Diff: UARTFrame.cpp
- Revision:
- 0:8e83b9448758
- Child:
- 7:a71d7c24afc0
diff -r 000000000000 -r 8e83b9448758 UARTFrame.cpp --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/UARTFrame.cpp Tue Feb 03 21:24:15 2015 +0000 @@ -0,0 +1,96 @@ +#include "UARTFrame.h" + +using namespace SmartLabMuRata; + +char UARTFrame::GetL0() +{ + return l0; +} + +void UARTFrame::SetL0(const int value) +{ + l0 = value & 0x7F; +} + +char UARTFrame::GetL1() +{ + return l1; +} + +void UARTFrame::SetL1(const int value) +{ + l1 = value & 0x3F; + + if ((value & 0x40) == 0x40) + needACK = true; + else needACK = false; +} + +int UARTFrame::GetPayloadLength() +{ + return (l1 << 7) | l0; +} + +void UARTFrame::SetPayloadLength(const int length) +{ + SetL0(length); + SetL1(length >> 7); +} + +// ack +bool UARTFrame::GetACKRequired() +{ + return needACK; +} + +void UARTFrame::SetACKRequired(const bool ack) +{ + needACK = ack; +} + +//command id +CommandID UARTFrame::GetCommandID() +{ + return commandid; +} + +void UARTFrame::SetCommandID(const CommandID id) +{ + commandid = id; +} + +void UARTFrame::SetCommandID(const int value) +{ + commandid = (CommandID)(value & 0x7F); +} + +// payload +void UARTFrame::SetPayload(Payload * payload) +{ + this->payload = payload; + SetPayloadLength(payload->GetPosition()); + SetChecksum(l0 + (needACK ? l1 | 0x40 : l1) + commandid); +} + +Payload * UARTFrame::GetPayload() +{ + return payload; +} + +// checksum +char UARTFrame::GetChecksum() +{ + return checksum; +} + +void UARTFrame::SetChecksum(const int checksum) +{ + this->checksum = checksum & 0x7F; +} + +bool UARTFrame::VerifyChecksum() +{ + if (((l0 + (needACK ? l1 | 0x40 : l1) + commandid) & 0x7F) == checksum) + return true; + return false; +} \ No newline at end of file