Add master to single slave transport
parent
7b88b8b7e1
commit
8cbfe79dd9
|
@ -79,6 +79,9 @@ void transport_recv_frame(uint8_t from, uint8_t* data, uint16_t size) {
|
|||
start = obj->buffer + LOCAL_OBJECT_SIZE(obj->object_size);
|
||||
start += (from - 1) * REMOTE_OBJECT_SIZE(obj->object_size);
|
||||
}
|
||||
else {
|
||||
start = obj->buffer + NUM_SLAVES * LOCAL_OBJECT_SIZE(obj->object_size);
|
||||
}
|
||||
triple_buffer_object_t* tb = (triple_buffer_object_t*)start;
|
||||
void* ptr = triple_buffer_begin_write_internal(obj->object_size, tb);
|
||||
memcpy(ptr, data, size -1);
|
||||
|
@ -101,5 +104,19 @@ void update_transport(void) {
|
|||
router_send_frame(dest, ptr, obj->object_size + 1);
|
||||
}
|
||||
}
|
||||
else {
|
||||
uint8_t* start = obj->buffer;
|
||||
int j;
|
||||
for (j=0;j<NUM_SLAVES;j++) {
|
||||
triple_buffer_object_t* tb = (triple_buffer_object_t*)start;
|
||||
uint8_t* ptr = (uint8_t*)triple_buffer_read_internal(obj->object_size + LOCAL_OBJECT_EXTRA, tb);
|
||||
if (ptr) {
|
||||
ptr[obj->object_size] = i;
|
||||
uint8_t dest = j + 1;
|
||||
router_send_frame(dest, ptr, obj->object_size + 1);
|
||||
}
|
||||
start += LOCAL_OBJECT_SIZE(obj->object_size);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -94,9 +94,25 @@ typedef struct { \
|
|||
} \
|
||||
}; \
|
||||
type* begin_write_##name(uint8_t slave) { \
|
||||
remote_object_t* obj = (remote_object_t*)&remote_object_##name; \
|
||||
uint8_t* start = obj->buffer;\
|
||||
start += slave * LOCAL_OBJECT_SIZE(obj->object_size); \
|
||||
triple_buffer_object_t* tb = (triple_buffer_object_t*)start; \
|
||||
return (type*)triple_buffer_begin_write_internal(sizeof(type) + LOCAL_OBJECT_EXTRA, tb); \
|
||||
}\
|
||||
void end_write_##name(uint8_t slave) { \
|
||||
remote_object_t* obj = (remote_object_t*)&remote_object_##name; \
|
||||
uint8_t* start = obj->buffer;\
|
||||
start += slave * LOCAL_OBJECT_SIZE(obj->object_size); \
|
||||
triple_buffer_object_t* tb = (triple_buffer_object_t*)start; \
|
||||
triple_buffer_end_write_internal(tb); \
|
||||
signal_data_written(); \
|
||||
}\
|
||||
type* read_##name() { \
|
||||
remote_object_t* obj = (remote_object_t*)&remote_object_##name; \
|
||||
uint8_t* start = obj->buffer + NUM_SLAVES * LOCAL_OBJECT_SIZE(obj->object_size);\
|
||||
triple_buffer_object_t* tb = (triple_buffer_object_t*)start; \
|
||||
return triple_buffer_read_internal(obj->object_size, tb); \
|
||||
}
|
||||
|
||||
#define SLAVE_TO_MASTER_OBJECT(name, type) \
|
||||
|
|
|
@ -108,3 +108,18 @@ Ensure(Transport, writes_from_slave_to_master) {
|
|||
assert_that(obj2, is_not_equal_to(NULL));
|
||||
assert_that(obj2->test, is_equal_to(7));
|
||||
}
|
||||
|
||||
Ensure(Transport, writes_from_master_to_single_slave) {
|
||||
update_transport();
|
||||
test_object1_t* obj = begin_write_master_to_single_slave(3);
|
||||
obj->test = 7;
|
||||
expect(signal_data_written);
|
||||
end_write_master_to_single_slave(3);
|
||||
expect(router_send_frame,
|
||||
when(destination, is_equal_to(4)));
|
||||
update_transport();
|
||||
transport_recv_frame(0, sent_data, sent_data_size);
|
||||
test_object1_t* obj2 = read_master_to_single_slave();
|
||||
assert_that(obj2, is_not_equal_to(NULL));
|
||||
assert_that(obj2->test, is_equal_to(7));
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue