-
Notifications
You must be signed in to change notification settings - Fork 241
/
Copy pathPJONDynamicRouter.h
90 lines (73 loc) · 2.84 KB
/
PJONDynamicRouter.h
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
/*-O//\ __ __
|-gfo\ |__| | | | |\ | ®
|!y°o:\ | __| |__| | \| v11.0
|y"s§+`\ multi-master, multi-media bus network protocol
/so+:-..`\ Copyright 2010-2018 by Giovanni Blu Mitolo [email protected]
|+/:ngr-*.`\
|5/:%&-a3f.:;\
\+//u/+g%{osv,,\
\=+&/osw+olds.\\
\:/+-.-°-:+oss\
| | \oy\\
> <
______-| |-__________________________________________________________________
PJONDynamicRouter has been contributed by Fred Larsen.
It performs the same as PJONRouterExtended, but populates the routing table
dynamically based on observed packets from remote 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 [email protected]
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
#ifndef PJON_ROUTER_TABLE_SIZE
#define PJON_ROUTER_TABLE_SIZE 100
#endif
#include <PJONRouter.h>
class PJONDynamicRouter : public PJONRouter {
protected:
void add_sender_to_routing_table(
const PJON_Packet_Info &packet_info,
uint8_t sender_bus
) {
uint8_t start_search = 0;
uint8_t found_bus = find_bus_with_id(
packet_info.sender_bus_id,
packet_info.sender_id,
start_search
);
// Not found among attached buses or in routing table. Add to table.
if(found_bus == PJON_NOT_ASSIGNED)
add(packet_info.sender_bus_id, sender_bus);
};
virtual void dynamic_receiver_function(
uint8_t *payload,
uint16_t length,
const PJON_Packet_Info &packet_info
) {
// Do standard routing but also add unknown remote buses to routing table
add_sender_to_routing_table(packet_info, current_bus);
PJONSwitch::dynamic_receiver_function(payload, length, packet_info);
};
public:
PJONDynamicRouter() { };
PJONDynamicRouter(
uint8_t bus_count,
PJONAny *buses[],
uint8_t default_gateway = PJON_NOT_ASSIGNED
) : PJONRouter(bus_count, buses, default_gateway) { };
};