Layer 2 Aloha packet
AlohaFrame.h@1:b714fce6e23b, 2016-07-14 (annotated)
- Committer:
- rba90
- Date:
- Thu Jul 14 04:47:43 2016 +0000
- Revision:
- 1:b714fce6e23b
- Parent:
- 0:bd0c4fdc6833
- Child:
- 2:849128cfddb8
Fix a bug where negative offset is given
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
rba90 | 0:bd0c4fdc6833 | 1 | #ifndef ALOHAFRAME_H_ |
rba90 | 0:bd0c4fdc6833 | 2 | #define ALOHAFRAME_H_ |
rba90 | 0:bd0c4fdc6833 | 3 | |
rba90 | 0:bd0c4fdc6833 | 4 | #include <stdint.h> |
rba90 | 0:bd0c4fdc6833 | 5 | |
rba90 | 0:bd0c4fdc6833 | 6 | #define MAX_FRAME_SZ 20 |
rba90 | 0:bd0c4fdc6833 | 7 | #define MAX_PAYLOAD_SZ 16 |
rba90 | 0:bd0c4fdc6833 | 8 | |
rba90 | 1:b714fce6e23b | 9 | #define ALOHA_MAX_TYPE 16 |
rba90 | 1:b714fce6e23b | 10 | |
rba90 | 0:bd0c4fdc6833 | 11 | class AlohaFrame |
rba90 | 0:bd0c4fdc6833 | 12 | { |
rba90 | 0:bd0c4fdc6833 | 13 | private: |
rba90 | 0:bd0c4fdc6833 | 14 | uint8_t _buffer[MAX_FRAME_SZ]; |
rba90 | 0:bd0c4fdc6833 | 15 | |
rba90 | 0:bd0c4fdc6833 | 16 | bool _isVerified; |
rba90 | 1:b714fce6e23b | 17 | |
rba90 | 1:b714fce6e23b | 18 | public: |
rba90 | 1:b714fce6e23b | 19 | typedef enum |
rba90 | 1:b714fce6e23b | 20 | { |
rba90 | 1:b714fce6e23b | 21 | Aloha_Join_Request = 0x0, |
rba90 | 1:b714fce6e23b | 22 | Aloha_Join_Accepted, |
rba90 | 1:b714fce6e23b | 23 | Aloha_Join_Denied, |
rba90 | 1:b714fce6e23b | 24 | Aloha_Authentication, |
rba90 | 1:b714fce6e23b | 25 | Aloha_Deauthentication, |
rba90 | 1:b714fce6e23b | 26 | Aloha_RTS, |
rba90 | 1:b714fce6e23b | 27 | Aloha_CTS, |
rba90 | 1:b714fce6e23b | 28 | Aloha_Data, |
rba90 | 1:b714fce6e23b | 29 | Aloha_ACK, |
rba90 | 1:b714fce6e23b | 30 | Aloha_NACK, |
rba90 | 1:b714fce6e23b | 31 | } AlohaType_t; |
rba90 | 0:bd0c4fdc6833 | 32 | |
rba90 | 0:bd0c4fdc6833 | 33 | public: |
rba90 | 0:bd0c4fdc6833 | 34 | AlohaFrame(); |
rba90 | 0:bd0c4fdc6833 | 35 | AlohaFrame(uint8_t *data, uint8_t sz=MAX_PAYLOAD_SZ); |
rba90 | 0:bd0c4fdc6833 | 36 | ~AlohaFrame(); |
rba90 | 0:bd0c4fdc6833 | 37 | |
rba90 | 0:bd0c4fdc6833 | 38 | public: |
rba90 | 0:bd0c4fdc6833 | 39 | void generateCrc(); |
rba90 | 0:bd0c4fdc6833 | 40 | |
rba90 | 0:bd0c4fdc6833 | 41 | bool verify(); |
rba90 | 0:bd0c4fdc6833 | 42 | |
rba90 | 0:bd0c4fdc6833 | 43 | uint8_t serialize(uint8_t *buffer); |
rba90 | 0:bd0c4fdc6833 | 44 | |
rba90 | 0:bd0c4fdc6833 | 45 | public: |
rba90 | 0:bd0c4fdc6833 | 46 | void setType(uint8_t type); |
rba90 | 0:bd0c4fdc6833 | 47 | void setPayloadLength(uint8_t length); |
rba90 | 0:bd0c4fdc6833 | 48 | void setSourceAddress(uint8_t sa); |
rba90 | 0:bd0c4fdc6833 | 49 | void setDestinationAddress(uint8_t da); |
rba90 | 0:bd0c4fdc6833 | 50 | void setFullMessageFlag(uint8_t fmf); |
rba90 | 0:bd0c4fdc6833 | 51 | void setSequenceID(uint8_t seqid); |
rba90 | 0:bd0c4fdc6833 | 52 | void setPayload(uint8_t payload, uint8_t idx); |
rba90 | 0:bd0c4fdc6833 | 53 | |
rba90 | 0:bd0c4fdc6833 | 54 | uint8_t getType(); |
rba90 | 0:bd0c4fdc6833 | 55 | uint8_t getPayloadLength(); |
rba90 | 0:bd0c4fdc6833 | 56 | uint8_t getSourceAddress(); |
rba90 | 0:bd0c4fdc6833 | 57 | uint8_t getDestinationAddress(); |
rba90 | 0:bd0c4fdc6833 | 58 | uint8_t getFullMessageFlag(); |
rba90 | 0:bd0c4fdc6833 | 59 | uint8_t getSequenceID(); |
rba90 | 0:bd0c4fdc6833 | 60 | uint8_t getPayload(uint8_t idx); |
rba90 | 0:bd0c4fdc6833 | 61 | uint8_t getCrc(); |
rba90 | 0:bd0c4fdc6833 | 62 | |
rba90 | 0:bd0c4fdc6833 | 63 | #ifdef _DEBUG |
rba90 | 0:bd0c4fdc6833 | 64 | public: |
rba90 | 0:bd0c4fdc6833 | 65 | void unit_test(); |
rba90 | 0:bd0c4fdc6833 | 66 | #endif |
rba90 | 0:bd0c4fdc6833 | 67 | }; |
rba90 | 0:bd0c4fdc6833 | 68 | |
rba90 | 0:bd0c4fdc6833 | 69 | #endif |