1
0
Fork 0
forked from forks/qmk_firmware

First link sending to master

This commit is contained in:
Fred Sundvik 2016-02-20 15:02:53 +02:00
parent 82b5037b9d
commit c28e19c546
2 changed files with 42 additions and 12 deletions

View file

@ -32,14 +32,24 @@ void router_set_master(bool master) {
} }
void route_incoming_frame(uint8_t link, uint8_t* data, uint16_t size){ void route_incoming_frame(uint8_t link, uint8_t* data, uint16_t size){
if (is_master) {
transport_recv_frame(1, data, size);
}
else {
if (data[size-1] & 1) { if (data[size-1] & 1) {
transport_recv_frame(0, data, size - 1); transport_recv_frame(0, data, size - 1);
} }
data[size-1] >>= 1; data[size-1] >>= 1;
validator_send_frame(DOWN_LINK, data, size); validator_send_frame(DOWN_LINK, data, size);
} }
}
void router_send_frame(uint8_t destination, uint8_t* data, uint16_t size) { void router_send_frame(uint8_t destination, uint8_t* data, uint16_t size) {
if (destination == 0) {
validator_send_frame(UP_LINK, data, size);
}
else {
data[size] = destination; data[size] = destination;
validator_send_frame(DOWN_LINK, data, size + 1); validator_send_frame(DOWN_LINK, data, size + 1);
} }
}

View file

@ -46,13 +46,13 @@ router_buffer_t router_buffers[8];
router_buffer_t* current_router_buffer; router_buffer_t* current_router_buffer;
Describe(ByteStuffer); Describe(FrameRouter);
BeforeEach(ByteStuffer) { BeforeEach(FrameRouter) {
init_byte_stuffer(); init_byte_stuffer();
memset(router_buffers, 0, sizeof(router_buffers)); memset(router_buffers, 0, sizeof(router_buffers));
current_router_buffer = 0; current_router_buffer = 0;
} }
AfterEach(ByteStuffer) {} AfterEach(FrameRouter) {}
typedef struct { typedef struct {
uint32_t data; uint32_t data;
@ -81,6 +81,9 @@ static void activate_router(uint8_t num) {
static void simulate_transport(uint8_t from, uint8_t to) { static void simulate_transport(uint8_t from, uint8_t to) {
activate_router(to); activate_router(to);
if (from > to) { if (from > to) {
receive_data(DOWN_LINK,
router_buffers[from].send_buffers[UP_LINK].sent_data,
router_buffers[from].send_buffers[UP_LINK].sent_data_size);
} }
else if(to > from) { else if(to > from) {
receive_data(UP_LINK, receive_data(UP_LINK,
@ -94,7 +97,7 @@ void transport_recv_frame(uint8_t from, uint8_t* data, uint16_t size) {
} }
Ensure(ByteStuffer, master_broadcast_is_received_by_everyone) { Ensure(FrameRouter, master_broadcast_is_received_by_everyone) {
frame_buffer_t data; frame_buffer_t data;
data.data = 0xAB7055BB; data.data = 0xAB7055BB;
activate_router(0); activate_router(0);
@ -121,8 +124,7 @@ Ensure(ByteStuffer, master_broadcast_is_received_by_everyone) {
assert_that(router_buffers[2].send_buffers[UP_LINK].sent_data_size, is_equal_to(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) { Ensure(FrameRouter, master_send_is_received_by_targets) {
printf("Here\n");
frame_buffer_t data; frame_buffer_t data;
data.data = 0xAB7055BB; data.data = 0xAB7055BB;
activate_router(0); activate_router(0);
@ -152,3 +154,21 @@ Ensure(ByteStuffer, master_send_is_received_by_targets) {
assert_that(router_buffers[3].send_buffers[DOWN_LINK].sent_data_size, is_greater_than(0)); 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)); assert_that(router_buffers[3].send_buffers[UP_LINK].sent_data_size, is_equal_to(0));
} }
Ensure(FrameRouter, first_sends_to_master) {
frame_buffer_t data;
data.data = 0xAB7055BB;
activate_router(1);
router_send_frame(0, (uint8_t*)&data, 4);
assert_that(router_buffers[1].send_buffers[UP_LINK].sent_data_size, is_greater_than(0));
assert_that(router_buffers[1].send_buffers[DOWN_LINK].sent_data_size, is_equal_to(0));
expect(transport_recv_frame,
when(from, is_equal_to(1)),
when(size, is_equal_to(4)),
when(data, is_equal_to_contents_of(&data.data, 4))
);
simulate_transport(1, 0);
assert_that(router_buffers[0].send_buffers[DOWN_LINK].sent_data_size, is_equal_to(0));
assert_that(router_buffers[0].send_buffers[UP_LINK].sent_data_size, is_equal_to(0));
}