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.

Committer:
yangcq88517
Date:
Sun Feb 08 01:22:29 2015 +0000
Revision:
7:a71d7c24afc0
Parent:
0:8e83b9448758
bug fix

Who changed what in which revision?

UserRevisionLine numberNew contents of line
yangcq88517 0:8e83b9448758 1 #include "UARTFrame.h"
yangcq88517 0:8e83b9448758 2
yangcq88517 0:8e83b9448758 3 using namespace SmartLabMuRata;
yangcq88517 0:8e83b9448758 4
yangcq88517 0:8e83b9448758 5 char UARTFrame::GetL0()
yangcq88517 0:8e83b9448758 6 {
yangcq88517 0:8e83b9448758 7 return l0;
yangcq88517 0:8e83b9448758 8 }
yangcq88517 0:8e83b9448758 9
yangcq88517 0:8e83b9448758 10 void UARTFrame::SetL0(const int value)
yangcq88517 0:8e83b9448758 11 {
yangcq88517 0:8e83b9448758 12 l0 = value & 0x7F;
yangcq88517 0:8e83b9448758 13 }
yangcq88517 0:8e83b9448758 14
yangcq88517 0:8e83b9448758 15 char UARTFrame::GetL1()
yangcq88517 0:8e83b9448758 16 {
yangcq88517 0:8e83b9448758 17 return l1;
yangcq88517 0:8e83b9448758 18 }
yangcq88517 0:8e83b9448758 19
yangcq88517 0:8e83b9448758 20 void UARTFrame::SetL1(const int value)
yangcq88517 0:8e83b9448758 21 {
yangcq88517 0:8e83b9448758 22 l1 = value & 0x3F;
yangcq88517 0:8e83b9448758 23
yangcq88517 0:8e83b9448758 24 if ((value & 0x40) == 0x40)
yangcq88517 0:8e83b9448758 25 needACK = true;
yangcq88517 0:8e83b9448758 26 else needACK = false;
yangcq88517 0:8e83b9448758 27 }
yangcq88517 0:8e83b9448758 28
yangcq88517 0:8e83b9448758 29 int UARTFrame::GetPayloadLength()
yangcq88517 0:8e83b9448758 30 {
yangcq88517 0:8e83b9448758 31 return (l1 << 7) | l0;
yangcq88517 0:8e83b9448758 32 }
yangcq88517 0:8e83b9448758 33
yangcq88517 0:8e83b9448758 34 void UARTFrame::SetPayloadLength(const int length)
yangcq88517 0:8e83b9448758 35 {
yangcq88517 0:8e83b9448758 36 SetL0(length);
yangcq88517 0:8e83b9448758 37 SetL1(length >> 7);
yangcq88517 0:8e83b9448758 38 }
yangcq88517 0:8e83b9448758 39
yangcq88517 0:8e83b9448758 40 // ack
yangcq88517 0:8e83b9448758 41 bool UARTFrame::GetACKRequired()
yangcq88517 0:8e83b9448758 42 {
yangcq88517 0:8e83b9448758 43 return needACK;
yangcq88517 0:8e83b9448758 44 }
yangcq88517 0:8e83b9448758 45
yangcq88517 0:8e83b9448758 46 void UARTFrame::SetACKRequired(const bool ack)
yangcq88517 0:8e83b9448758 47 {
yangcq88517 0:8e83b9448758 48 needACK = ack;
yangcq88517 0:8e83b9448758 49 }
yangcq88517 0:8e83b9448758 50
yangcq88517 0:8e83b9448758 51 //command id
yangcq88517 0:8e83b9448758 52 CommandID UARTFrame::GetCommandID()
yangcq88517 0:8e83b9448758 53 {
yangcq88517 0:8e83b9448758 54 return commandid;
yangcq88517 0:8e83b9448758 55 }
yangcq88517 0:8e83b9448758 56
yangcq88517 0:8e83b9448758 57 void UARTFrame::SetCommandID(const CommandID id)
yangcq88517 0:8e83b9448758 58 {
yangcq88517 7:a71d7c24afc0 59 SetCommandID ((int)id);
yangcq88517 0:8e83b9448758 60 }
yangcq88517 0:8e83b9448758 61
yangcq88517 0:8e83b9448758 62 void UARTFrame::SetCommandID(const int value)
yangcq88517 0:8e83b9448758 63 {
yangcq88517 0:8e83b9448758 64 commandid = (CommandID)(value & 0x7F);
yangcq88517 0:8e83b9448758 65 }
yangcq88517 0:8e83b9448758 66
yangcq88517 0:8e83b9448758 67 // payload
yangcq88517 0:8e83b9448758 68 void UARTFrame::SetPayload(Payload * payload)
yangcq88517 0:8e83b9448758 69 {
yangcq88517 0:8e83b9448758 70 this->payload = payload;
yangcq88517 0:8e83b9448758 71 SetPayloadLength(payload->GetPosition());
yangcq88517 0:8e83b9448758 72 SetChecksum(l0 + (needACK ? l1 | 0x40 : l1) + commandid);
yangcq88517 0:8e83b9448758 73 }
yangcq88517 0:8e83b9448758 74
yangcq88517 0:8e83b9448758 75 Payload * UARTFrame::GetPayload()
yangcq88517 0:8e83b9448758 76 {
yangcq88517 0:8e83b9448758 77 return payload;
yangcq88517 0:8e83b9448758 78 }
yangcq88517 0:8e83b9448758 79
yangcq88517 0:8e83b9448758 80 // checksum
yangcq88517 0:8e83b9448758 81 char UARTFrame::GetChecksum()
yangcq88517 0:8e83b9448758 82 {
yangcq88517 0:8e83b9448758 83 return checksum;
yangcq88517 0:8e83b9448758 84 }
yangcq88517 0:8e83b9448758 85
yangcq88517 0:8e83b9448758 86 void UARTFrame::SetChecksum(const int checksum)
yangcq88517 0:8e83b9448758 87 {
yangcq88517 0:8e83b9448758 88 this->checksum = checksum & 0x7F;
yangcq88517 0:8e83b9448758 89 }
yangcq88517 0:8e83b9448758 90
yangcq88517 0:8e83b9448758 91 bool UARTFrame::VerifyChecksum()
yangcq88517 0:8e83b9448758 92 {
yangcq88517 0:8e83b9448758 93 if (((l0 + (needACK ? l1 | 0x40 : l1) + commandid) & 0x7F) == checksum)
yangcq88517 0:8e83b9448758 94 return true;
yangcq88517 0:8e83b9448758 95 return false;
yangcq88517 0:8e83b9448758 96 }