summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorFred Sundvik <fsundvik@gmail.com>2016-02-20 13:52:17 +0100
committerFred Sundvik <fsundvik@gmail.com>2016-02-20 13:52:17 +0100
commit82b5037b9db628c3f34d8fb38848753ff3e41e2f (patch)
treea30ebc072be36b6cc40fb6cabae28602fcb2eb1e
parentcee5406ed76f16670a54720b8d3c6d8f8c193c49 (diff)
downloadqmk_firmware-82b5037b9db628c3f34d8fb38848753ff3e41e2f.tar.gz
qmk_firmware-82b5037b9db628c3f34d8fb38848753ff3e41e2f.tar.xz
Add master send to specific destinations
-rw-r--r--serial_link/protocol/frame_router.c8
-rw-r--r--serial_link/tests/frame_router_tests.c32
2 files changed, 38 insertions, 2 deletions
diff --git a/serial_link/protocol/frame_router.c b/serial_link/protocol/frame_router.c
index 0675cea28..861c0d7d2 100644
--- a/serial_link/protocol/frame_router.c
+++ b/serial_link/protocol/frame_router.c
@@ -32,10 +32,14 @@ void router_set_master(bool master) {
}
void route_incoming_frame(uint8_t link, uint8_t* data, uint16_t size){
- transport_recv_frame(0, data, size);
+ if (data[size-1] & 1) {
+ transport_recv_frame(0, data, size - 1);
+ }
+ data[size-1] >>= 1;
validator_send_frame(DOWN_LINK, data, size);
}
void router_send_frame(uint8_t destination, uint8_t* data, uint16_t size) {
- validator_send_frame(DOWN_LINK, data, size);
+ data[size] = destination;
+ validator_send_frame(DOWN_LINK, data, size + 1);
}
diff --git a/serial_link/tests/frame_router_tests.c b/serial_link/tests/frame_router_tests.c
index eb0c710ea..7a4ccb0c4 100644
--- a/serial_link/tests/frame_router_tests.c
+++ b/serial_link/tests/frame_router_tests.c
@@ -120,3 +120,35 @@ Ensure(ByteStuffer, master_broadcast_is_received_by_everyone) {
assert_that(router_buffers[2].send_buffers[DOWN_LINK].sent_data_size, is_greater_than(0));
assert_that(router_buffers[2].send_buffers[UP_LINK].sent_data_size, is_equal_to(0));
}
+
+Ensure(ByteStuffer, master_send_is_received_by_targets) {
+ printf("Here\n");
+ frame_buffer_t data;
+ data.data = 0xAB7055BB;
+ activate_router(0);
+ router_send_frame((1 << 1) | (1 << 2), (uint8_t*)&data, 4);
+ assert_that(router_buffers[0].send_buffers[DOWN_LINK].sent_data_size, is_greater_than(0));
+ assert_that(router_buffers[0].send_buffers[UP_LINK].sent_data_size, is_equal_to(0));
+
+ simulate_transport(0, 1);
+ assert_that(router_buffers[1].send_buffers[DOWN_LINK].sent_data_size, is_greater_than(0));
+ assert_that(router_buffers[1].send_buffers[UP_LINK].sent_data_size, is_equal_to(0));
+
+ expect(transport_recv_frame,
+ when(from, is_equal_to(0)),
+ when(size, is_equal_to(4)),
+ when(data, is_equal_to_contents_of(&data.data, 4))
+ );
+ simulate_transport(1, 2);
+ assert_that(router_buffers[2].send_buffers[DOWN_LINK].sent_data_size, is_greater_than(0));
+ assert_that(router_buffers[2].send_buffers[UP_LINK].sent_data_size, is_equal_to(0));
+
+ expect(transport_recv_frame,
+ when(from, is_equal_to(0)),
+ when(size, is_equal_to(4)),
+ when(data, is_equal_to_contents_of(&data.data, 4))
+ );
+ simulate_transport(2, 3);
+ assert_that(router_buffers[3].send_buffers[DOWN_LINK].sent_data_size, is_greater_than(0));
+ assert_that(router_buffers[3].send_buffers[UP_LINK].sent_data_size, is_equal_to(0));
+}