forked from gioblu/PJON
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathPJONRouterExtended.h
More file actions
101 lines (85 loc) · 3.77 KB
/
PJONRouterExtended.h
File metadata and controls
101 lines (85 loc) · 3.77 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
/*-O//\ __ __
|-gfo\ |__| | | | |\ | ®
|!y°o:\ | __| |__| | \| v10.1
|y"s§+`\ multi-master, multi-media bus network protocol
/so+:-..`\ Copyright 2010-2018 by Giovanni Blu Mitolo gioscarab@gmail.com
|+/:ngr-*.`\
|5/:%&-a3f.:;\
\+//u/+g%{osv,,\
\=+&/osw+olds.\\
\:/+-.-°-:+oss\
| | \oy\\
> <
______-| |-__________________________________________________________________
PJONRouterExtended has been contributed by Fred Larsen.
It performs the same routing as the PJONRouter for locally attached buses,
but supports a static routing table to enable traversing multiple levels of
buses.
If you believe in this project and you appreciate our work, please, make a
donation. The PJON Foundation is entirely financed by contributions of wise
people like you and its resources are solely invested to cover the development
and maintainance costs.
- Paypal: https://www.paypal.me/PJON
- Bitcoin: 1FupxAyDTuAMGz33PtwnhwBm4ppc7VLwpD
- Ethereum: 0xf34AEAF3B149454522019781668F9a2d1762559b
Thank you and happy tinkering!
_____________________________________________________________________________
Copyright 2010-2018 by Giovanni Blu Mitolo gioscarab@gmail.com
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License. */
#pragma once
#include <PJONRouter.h>
#ifndef PJON_ROUTER_TABLE_SIZE
#define PJON_ROUTER_TABLE_SIZE 10
#endif
class PJONRouterExtended : public PJONRouter {
protected:
uint8_t remote_bus_ids[PJON_ROUTER_MAX_BUSES][4];
uint8_t remote_bus_via_attached_bus[PJON_ROUTER_MAX_BUSES];
uint8_t table_size = 0;
uint8_t find_bus_in_table(const uint8_t *bus_id, const uint8_t device_id, uint8_t &start_bus) {
uint8_t start = start_bus - bus_count;
for (uint8_t i=start; i<bus_count; i++) {
if (PJONAny::bus_id_equality(bus_id, remote_bus_ids[i])) {
start_bus = bus_count + i + 1; // Continue searching for more matches after this
return i; // Explicit bus id match
}
}
start_bus = PJON_NOT_ASSIGNED;
return PJON_NOT_ASSIGNED;
}
virtual uint8_t find_bus_with_id(const uint8_t *bus_id, const uint8_t device_id, uint8_t &start_bus) {
// Search for a locally attached bus first
uint8_t receiver_bus = PJON_NOT_ASSIGNED;
if (start_bus < bus_count) {
receiver_bus = find_attached_bus_with_id(bus_id, device_id, start_bus);
if (receiver_bus == PJON_NOT_ASSIGNED) start_bus = bus_count; // Not found among attached
}
// Then search in the routing table
if (receiver_bus == PJON_NOT_ASSIGNED && start_bus >= bus_count && start_bus != PJON_NOT_ASSIGNED) {
receiver_bus = find_bus_in_table(bus_id, device_id, start_bus);
}
if (receiver_bus == PJON_NOT_ASSIGNED) start_bus = PJON_NOT_ASSIGNED;
return receiver_bus;
}
public:
PJONRouterExtended() {}
PJONRouterExtended(uint8_t bus_count,
PJONAny *buses[],
uint8_t default_gateway = PJON_NOT_ASSIGNED)
: PJONRouter(bus_count, buses, default_gateway) { }
void add(const uint8_t bus_id[], uint8_t via_attached_bus) {
if (table_size < PJON_ROUTER_TABLE_SIZE) {
PJONAny::copy_bus_id(remote_bus_ids[table_size], bus_id);
remote_bus_via_attached_bus[table_size] = via_attached_bus;
table_size++;
}
}
};