Important changes to repositories hosted on mbed.com
Mbed hosted mercurial repositories are deprecated and are due to be permanently deleted in July 2026.
To keep a copy of this software download the repository Zip archive or clone locally using Mercurial.
It is also possible to export all your personal repositories from the account settings page.
Dependencies: mbed SimpleSerialProtocol MODSERIAL
TestProtocol.h@11:a051c3f9ca6d, 2014-08-27 (annotated)
- Committer:
- p3p
- Date:
- Wed Aug 27 18:05:51 2014 +0000
- Revision:
- 11:a051c3f9ca6d
- Parent:
- 10:f6862abba2d5
Simplified
Who changed what in which revision?
| User | Revision | Line number | New contents of line |
|---|---|---|---|
| p3p | 2:8799090c0fe4 | 1 | #ifndef _TEST_PROTOCOL_H |
| p3p | 2:8799090c0fe4 | 2 | #define _TEST_PROTOCOL_H |
| p3p | 2:8799090c0fe4 | 3 | |
| p3p | 2:8799090c0fe4 | 4 | #include <mbed.h> |
| p3p | 2:8799090c0fe4 | 5 | #include <SimpleSerialProtocol/Protocol.h> |
| p3p | 2:8799090c0fe4 | 6 | |
| p3p | 2:8799090c0fe4 | 7 | //class will receive a packet and echo it back out |
| p3p | 11:a051c3f9ca6d | 8 | class TestProtocol { |
| p3p | 2:8799090c0fe4 | 9 | public: |
| p3p | 11:a051c3f9ca6d | 10 | TestProtocol() { |
| p3p | 11:a051c3f9ca6d | 11 | temp = 0; |
| p3p | 11:a051c3f9ca6d | 12 | temp1 = 0; |
| p3p | 11:a051c3f9ca6d | 13 | temp2 = 0; |
| p3p | 11:a051c3f9ca6d | 14 | temp3 = 0.0f; |
| p3p | 2:8799090c0fe4 | 15 | } |
| p3p | 2:8799090c0fe4 | 16 | virtual ~TestProtocol() {}; |
| p3p | 11:a051c3f9ca6d | 17 | void onEchoPacket(SimpleSerialProtocol::Protocol* comms, SimpleSerialProtocol::Packet* packet); |
| p3p | 2:8799090c0fe4 | 18 | |
| p3p | 2:8799090c0fe4 | 19 | class EchoPacket : public SimpleSerialProtocol::Packet { |
| p3p | 2:8799090c0fe4 | 20 | public: |
| p3p | 2:8799090c0fe4 | 21 | EchoPacket() {} |
| p3p | 2:8799090c0fe4 | 22 | virtual ~EchoPacket() {} |
| p3p | 2:8799090c0fe4 | 23 | |
| p3p | 2:8799090c0fe4 | 24 | #pragma pack(push, 1) //must pack the structure to byte boundary for raw recast to work reliably |
| p3p | 11:a051c3f9ca6d | 25 | //this is used in Packet::interpretData and used to validate the packet |
| p3p | 2:8799090c0fe4 | 26 | struct Interface { |
| p3p | 2:8799090c0fe4 | 27 | Interface() { |
| p3p | 2:8799090c0fe4 | 28 | type = 1; // initialise the type |
| p3p | 2:8799090c0fe4 | 29 | } |
| p3p | 2:8799090c0fe4 | 30 | uint8_t type; |
| p3p | 2:8799090c0fe4 | 31 | uint8_t data; |
| p3p | 2:8799090c0fe4 | 32 | uint16_t datashort; |
| p3p | 2:8799090c0fe4 | 33 | uint32_t dataint; |
| p3p | 2:8799090c0fe4 | 34 | float datafloat; |
| p3p | 2:8799090c0fe4 | 35 | } interface; |
| p3p | 2:8799090c0fe4 | 36 | #pragma pack(pop) |
| p3p | 2:8799090c0fe4 | 37 | |
| p3p | 2:8799090c0fe4 | 38 | }; |
| p3p | 2:8799090c0fe4 | 39 | |
| p3p | 2:8799090c0fe4 | 40 | uint8_t temp; |
| p3p | 11:a051c3f9ca6d | 41 | uint16_t temp1; |
| p3p | 11:a051c3f9ca6d | 42 | uint32_t temp2; |
| p3p | 2:8799090c0fe4 | 43 | float temp3; |
| p3p | 2:8799090c0fe4 | 44 | }; |
| p3p | 2:8799090c0fe4 | 45 | |
| p3p | 2:8799090c0fe4 | 46 | #endif |