SingingCat
0
application
src
nic_registry.c
1
#include "networkif.h"
2
#include "sx1262/sx1262.h"
3
4
static
struct
network_context
registrations[5];
5
void
init_nic_registry() {
6
memset(®istrations,
sizeof
(registrations), 0);
7
}
8
9
void
register_nic(
struct
networkif
*nif,
int
SOURCE) {
10
int
i;
11
12
for
(i = 0; i < 5; i++) {
13
struct
network_context
*r = ®istrations[i];
//not nic_by_index, because we need to figure out wether it is full or not free
14
if
(r->nif == NULL) {
15
r->nif = nif;
16
r->status = 0;
17
r->source = SOURCE;
18
r->mculib_handle = i + 10;
19
return
;
20
}
21
}
22
printf(
"Too many nics registered.\r\n"
);
23
}
24
// e.g. lora/radio/bluetooth.. (or NULL)
25
struct
network_context
*nic_by_type(
int
type) {
26
int
i = 0;
27
28
for
(;;) {
29
struct
network_context
*r = nic_by_index(i);
30
if
(r == NULL) {
31
return
NULL;
32
}
33
if
(r->source == type) {
34
return
r;
35
}
36
i++;
37
}
38
return
NULL;
39
}
40
41
// NULL if none at that index (count [0..n], stop at first NULL)
42
struct
network_context
*nic_by_index(
int
index) {
43
if
(index > 5) {
44
return
NULL;
45
}
46
struct
network_context
*r = ®istrations[index];
47
48
if
(r->nif == NULL) {
49
return
NULL;
50
}
51
return
r;
52
}
network_context
Definition:
networkif.h:18
networkif
Definition:
networkif.h:26
Generated on Tue May 28 2024 19:13:43 for SingingCat by
1.9.4