summaryrefslogtreecommitdiffstats
path: root/serial_link
diff options
context:
space:
mode:
authorFred Sundvik <fsundvik@gmail.com>2016-02-14 21:31:01 +0200
committerFred Sundvik <fsundvik@gmail.com>2016-02-14 21:31:01 +0200
commit2a6696bd3d0837c2e655a99000bcbcc759b40075 (patch)
treec3e91dc448073e788b5f3559aa747ed01d3c29c1 /serial_link
parent62058329ff9000589ddba6454ff8ef8a551b7243 (diff)
Add validator send frame
Diffstat (limited to 'serial_link')
-rw-r--r--serial_link/protocol/frame_validator.c7
-rw-r--r--serial_link/tests/frame_validator_tests.c26
2 files changed, 31 insertions, 2 deletions
diff --git a/serial_link/protocol/frame_validator.c b/serial_link/protocol/frame_validator.c
index d3337f6e32..fdb3ef51c3 100644
--- a/serial_link/protocol/frame_validator.c
+++ b/serial_link/protocol/frame_validator.c
@@ -24,6 +24,7 @@ SOFTWARE.
#include "protocol/frame_validator.h"
#include "protocol/frame_router.h"
+#include "protocol/byte_stuffer.h"
const uint32_t poly8_lookup[256] =
{
@@ -110,3 +111,9 @@ void recv_frame(uint8_t* data, uint16_t size) {
}
}
}
+
+void validator_send_frame(uint8_t* data, uint16_t size) {
+ uint32_t* crc = (uint32_t*)(data + size);
+ *crc = crc32_byte(data, size);
+ send_frame(data, size + 4);
+}
diff --git a/serial_link/tests/frame_validator_tests.c b/serial_link/tests/frame_validator_tests.c
index 1aca9f95fc..816256f6b7 100644
--- a/serial_link/tests/frame_validator_tests.c
+++ b/serial_link/tests/frame_validator_tests.c
@@ -30,6 +30,10 @@ void route_frame(uint8_t* data, uint16_t size) {
mock(data, size);
}
+void send_frame(uint8_t* data, uint16_t size) {
+ mock(data, size);
+}
+
Describe(FrameValidator);
BeforeEach(FrameValidator) {}
AfterEach(FrameValidator) {}
@@ -68,8 +72,6 @@ Ensure(FrameValidator, validates_four_byte_frame_with_correct_crc) {
}
Ensure(FrameValidator, validates_five_byte_frame_with_correct_crc) {
- //0xBA304E74
- //0x470B99F4
uint8_t data[] = {1, 2, 3, 4, 5, 0xF4, 0x99, 0x0B, 0x47};
expect(route_frame,
when(size, is_equal_to(5)),
@@ -77,3 +79,23 @@ Ensure(FrameValidator, validates_five_byte_frame_with_correct_crc) {
);
recv_frame(data, 9);
}
+
+Ensure(FrameValidator, sends_one_byte_with_correct_crc) {
+ uint8_t original[] = {0x44, 0, 0, 0, 0};
+ uint8_t expected[] = {0x44, 0x04, 0x6A, 0xB3, 0xA3};
+ expect(send_frame,
+ when(size, is_equal_to(sizeof(expected))),
+ when(data, is_equal_to_contents_of(expected, sizeof(expected)))
+ );
+ validator_send_frame(original, 1);
+}
+
+Ensure(FrameValidator, sends_five_bytes_with_correct_crc) {
+ uint8_t original[] = {1, 2, 3, 4, 5, 0, 0, 0, 0};
+ uint8_t expected[] = {1, 2, 3, 4, 5, 0xF4, 0x99, 0x0B, 0x47};
+ expect(send_frame,
+ when(size, is_equal_to(sizeof(expected))),
+ when(data, is_equal_to_contents_of(expected, sizeof(expected)))
+ );
+ validator_send_frame(original, 5);
+}