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.
Dependents: LoRaBaseStation LoRaTerminal
Diff: ControPacket/ControlPacket.cpp
- Revision:
- 2:f4f46b04ab8a
- Parent:
- 0:f32c0e562e9a
- Child:
- 5:dcf7271595af
diff -r dda08634a9be -r f4f46b04ab8a ControPacket/ControlPacket.cpp
--- a/ControPacket/ControlPacket.cpp Wed Jun 29 01:49:03 2016 +0000
+++ b/ControPacket/ControlPacket.cpp Thu Jun 30 09:14:54 2016 +0000
@@ -1,13 +1,19 @@
#include "ControlPacket.h"
+#ifdef _DEBUG
+#include <cassert>
+#endif
+
ControlPacket::ControlPacket()
: BasicPacket()
{
+ setFid(0x0);
}
ControlPacket::ControlPacket(uint8_t *data)
: BasicPacket(data)
{
+ setFid(0x0);
}
ControlPacket::~ControlPacket()
@@ -80,3 +86,40 @@
{
return (getField3() & 0xf0) >> 4;
}
+
+#ifdef _DEBUG
+void ControlPacket::unit_test()
+{
+ // value test
+ ControlPacket testObject;
+
+ testObject.setSequenceID(0x1);
+ testObject.setSourceID(0x2);
+ testObject.setDestinationID(0x3);
+ testObject.setCommand(0x4);
+
+ assert(0x0 == testObject.getFid());
+ assert(0x1 == testObject.getSequenceID());
+ assert(0x2 == testObject.getSourceID());
+ assert(0x3 == testObject.getDestinationID());
+ assert(0x4 == testObject.getCommand());
+
+ assert(false == testObject.verify());
+ testObject.generateCrc();
+ assert(0x3d == testObject.getCrc());
+
+ // value test 2
+ uint8_t testString[] = { 0x01, 0x23, 0x40, 0x3d };
+ ControlPacket testObject2(testString);
+
+ assert(0x0 == testObject2.getFid());
+ assert(0x1 == testObject2.getSequenceID());
+ assert(0x2 == testObject2.getSourceID());
+ assert(0x3 == testObject2.getDestinationID());
+ assert(0x4 == testObject2.getCommand());
+
+ assert(true == testObject2.verify());
+ testObject2.generateCrc();
+ assert(0x3d == testObject2.getCrc());
+}
+#endif
\ No newline at end of file