123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869 |
- #include "serial_link/protocol/frame_router.h"
- #include "serial_link/protocol/transport.h"
- #include "serial_link/protocol/frame_validator.h"
- static bool is_master;
- void router_set_master(bool master) {
- is_master = master;
- }
- void route_incoming_frame(uint8_t link, uint8_t* data, uint16_t size){
- if (is_master) {
- if (link == DOWN_LINK) {
- transport_recv_frame(data[size-1], data, size - 1);
- }
- }
- else {
- if (link == UP_LINK) {
- if (data[size-1] & 1) {
- transport_recv_frame(0, data, size - 1);
- }
- data[size-1] >>= 1;
- validator_send_frame(DOWN_LINK, data, size);
- }
- else {
- data[size-1]++;
- validator_send_frame(UP_LINK, data, size);
- }
- }
- }
- void router_send_frame(uint8_t destination, uint8_t* data, uint16_t size) {
- if (destination == 0) {
- if (!is_master) {
- data[size] = 1;
- validator_send_frame(UP_LINK, data, size + 1);
- }
- }
- else {
- if (is_master) {
- data[size] = destination;
- validator_send_frame(DOWN_LINK, data, size + 1);
- }
- }
- }
|