43 #define PJON_ROUTER_NEED_INHERITANCE
45 #include "PJONSwitch.h"
47 #ifndef PJON_ROUTER_TABLE_SIZE
48 #define PJON_ROUTER_TABLE_SIZE 10
54 uint8_t remote_bus_ids[PJON_ROUTER_TABLE_SIZE][4];
55 uint8_t remote_bus_via_attached_bus[PJON_ROUTER_TABLE_SIZE];
56 uint8_t table_size = 0;
58 uint8_t find_bus_in_table(
59 const uint8_t *bus_id,
64 uint8_t start = start_bus - bus_count;
65 for(uint8_t i = start; i < table_size; i++) {
66 if(memcmp(bus_id, remote_bus_ids[i], 4) == 0) {
67 start_bus = bus_count + i + 1;
68 return remote_bus_via_attached_bus[i];
71 start_bus = PJON_NOT_ASSIGNED;
72 return PJON_NOT_ASSIGNED;
75 virtual uint8_t find_bus_with_id(
76 const uint8_t *bus_id,
77 const uint8_t device_id,
82 uint8_t receiver_bus = PJON_NOT_ASSIGNED;
83 if(start_bus < bus_count) {
84 receiver_bus = find_attached_bus_with_id(bus_id, device_id, start_bus);
85 if(receiver_bus == PJON_NOT_ASSIGNED) {
86 start_bus = bus_count;
91 (receiver_bus == PJON_NOT_ASSIGNED) &&
92 (start_bus >= bus_count) &&
93 (start_bus != PJON_NOT_ASSIGNED)
95 receiver_bus = find_bus_in_table(bus_id, device_id, start_bus);
97 if(receiver_bus == PJON_NOT_ASSIGNED) {
98 start_bus = PJON_NOT_ASSIGNED;
108 uint8_t default_gateway = PJON_NOT_ASSIGNED
109 ) :
PJONSwitch(bus_count, buses, default_gateway) { };
111 void add(
const uint8_t bus_id[], uint8_t via_attached_bus)
113 if(table_size < PJON_ROUTER_TABLE_SIZE) {
114 memcpy(remote_bus_ids[table_size], bus_id, 4);
115 remote_bus_via_attached_bus[table_size] = via_attached_bus;
123 template<
class A,
class B>
130 PJONRouter2(uint8_t default_gateway = PJON_NOT_ASSIGNED)
134 busA.set_link(&linkA);
135 busB.set_link(&linkB);
138 PJONAny &get_bus(
const uint8_t ix)
140 return ix == 0 ? busA : busB;
145 return linkA.strategy;
149 return linkB.strategy;
154 template<
class A,
class B,
class C>
162 PJONRouter3(uint8_t default_gateway = PJON_NOT_ASSIGNED)
164 PJON<Any> *buses[3] = { &busA, &busB, &busC };
166 busA.set_link(&linkA);
167 busB.set_link(&linkB);
168 busC.set_link(&linkC);
171 PJONAny &get_bus(
const uint8_t ix)
173 return ix == 0 ? busA : (ix == 1 ? busB : busC);
178 return linkA.strategy;
182 return linkB.strategy;
186 return linkC.strategy;