Skip to content

Commit 26b668a

Browse files
Add RIOT CoAP Channel (#120)
* Add CoAP channel for RIOT platform * Improve protocol and implement close * Give the application a more reasonable name * Add send message * Fix main.c after rebase * Rename to CoapUdpIpChannel * Finish message send implementation * Fix return codes * Remove memcpy! * FIx missing implementations * Add reconnect implementation * Restructure and add full example * Fix warnings * Fix type checker * Add coap channel test * Cleanup * Add todos * Add network channel type * Move coap channel test to test/platform/riot * Fix typo and always inform bundle about new states * Update src/platform/riot/coap_udp_ip_channel.c Co-authored-by: erling <[email protected]> * Fix test * Add basic test to CI * Improve ci * Test * Test * Test * Fix typo * Test if a broken test is reported * It worked => Fix test * Change endpoints to POST and make messages confirmable * Cleanup * Remove example for now * Simplify socket creation * Add mutex to coap channel * Run formatter and remove some unneeded includes --------- Co-authored-by: erling <[email protected]>
1 parent 18c1af6 commit 26b668a

File tree

23 files changed

+662
-33
lines changed

23 files changed

+662
-33
lines changed

.github/workflows/pico.yml

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,22 +1,24 @@
1-
name: Pico examples
1+
name: "Platform: PICO"
22

33
on:
44
pull_request:
55

66
jobs:
77
ci:
8-
name: Build Pico examples
8+
name: Build examples
99
runs-on: ubuntu-latest
1010
steps:
1111
- name: Checkout
1212
uses: actions/checkout@v3
1313
with:
1414
submodules: recursive
15+
1516
- name: Install dependencies
1617
uses: ./.github/actions/pico
18+
1719
- name: Build examples
20+
working-directory: ${{ github.workspace }}/examples/pico
1821
run: |
19-
cd examples/pico
2022
cmake -Bbuild && cd build
2123
make
2224

.github/workflows/posix.yml

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,19 +1,19 @@
1-
name: Posix examples
1+
name: "Platform: POSIX"
22

33
on:
44
pull_request:
55

66
jobs:
77
ci:
8-
name: Build zephyr examples
8+
name: Build examples
99
runs-on: ubuntu-latest
1010
steps:
1111
- name: Checkout
1212
uses: actions/checkout@v3
1313
with:
1414
submodules: recursive
15+
1516
- name: Build and run Posix examples
16-
run: |
17-
cd examples/posix
18-
./buildAll.sh
17+
working-directory: ${{ github.workspace }}/examples/posix
18+
run: ./buildAll.sh
1919

.github/workflows/riot.yml

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,11 @@
1-
name: RIOT examples
1+
name: "Platform: RIOT"
22

33
on:
44
pull_request:
55

66
jobs:
77
ci:
8-
name: Build RIOT examples
8+
name: Build examples and run tests
99
runs-on: ubuntu-latest
1010
container:
1111
image: riot/riotbuild:latest
@@ -22,6 +22,9 @@ jobs:
2222
uses: ./.github/actions/riot
2323

2424
- name: Build examples
25-
run: |
26-
cd examples/riot
27-
./buildAll.sh
25+
working-directory: ${{ github.workspace }}/examples/riot
26+
run: ./buildAll.sh
27+
28+
- name: Run platform tests
29+
working-directory: ${{ github.workspace }}/test/platform/riot
30+
run: ./runAll.sh

.github/workflows/zephyr.yml

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,21 +1,22 @@
1-
name: Zephyr examples
1+
name: "Platform: Zephyr"
22

33
on:
44
pull_request:
55

66
jobs:
77
ci:
8-
name: Build zephyr examples
8+
name: Build examples
99
runs-on: ubuntu-latest
1010
steps:
1111
- name: Checkout
1212
uses: actions/checkout@v3
1313
with:
1414
submodules: recursive
15+
1516
- name: Install dependencies
1617
uses: ./.github/actions/zephyr
18+
1719
- name: Build examples
18-
run: |
19-
cd examples/zephyr
20-
./buildAll.sh
20+
working-directory: ${{ github.workspace }}/examples/zephyr
21+
run: ./buildAll.sh
2122

examples/riot/buildAll.sh

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,4 +20,4 @@ for board in "${BOARDS[@]}"; do
2020
$COMMAND
2121
popd
2222
done
23-
done
23+
done

include/reactor-uc/macros.h

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,8 @@
11
#ifndef REACTOR_UC_MACROS_H
22
#define REACTOR_UC_MACROS_H
33

4+
#define LF_STRINGIFY(x) #x
5+
46
// Sets an output port, copies data and triggers all downstream reactions.
57
#define lf_set(port, val) \
68
do { \
@@ -187,7 +189,7 @@
187189
(void)_bundle_idx;
188190

189191
#define REACTOR_CTOR(ReactorName) \
190-
Reactor_ctor(&self->super, __STRING(ReactorName), env, parent, self->_children, \
192+
Reactor_ctor(&self->super, LF_STRINGIFY(ReactorName), env, parent, self->_children, \
191193
sizeof(self->_children) / sizeof(self->_children[0]), self->_reactions, \
192194
sizeof(self->_reactions) / sizeof(self->_reactions[0]), self->_triggers, \
193195
sizeof(self->_triggers) / sizeof(self->_triggers[0]));

include/reactor-uc/network_channel.h

Lines changed: 16 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -2,22 +2,27 @@
22
#define REACTOR_UC_NETWORK_CHANNEL_H
33

44
#include <nanopb/pb.h>
5-
#include <pthread.h>
6-
#include <sys/select.h>
75

86
#include "proto/message.pb.h"
97
#include "reactor-uc/tag.h"
108
#include "reactor-uc/error.h"
9+
#include "reactor-uc/federated.h"
1110

1211
typedef enum {
1312
NETWORK_CHANNEL_STATE_UNINITIALIZED,
1413
NETWORK_CHANNEL_STATE_OPEN,
1514
NETWORK_CHANNEL_STATE_CONNECTION_IN_PROGRESS,
15+
NETWORK_CHANNEL_STATE_CONNECTION_FAILED,
1616
NETWORK_CHANNEL_STATE_CONNECTED,
17-
NETWORK_CHANNEL_STATE_DISCONNECTED,
1817
NETWORK_CHANNEL_STATE_LOST_CONNECTION,
18+
NETWORK_CHANNEL_STATE_CLOSED,
1919
} NetworkChannelState;
2020

21+
typedef enum {
22+
NETWORK_CHANNEL_TYPE_TCP_IP,
23+
NETWORK_CHANNEL_TYPE_COAP_UDP_IP,
24+
} NetworkChannelType;
25+
2126
typedef struct FederatedConnectionBundle FederatedConnectionBundle;
2227
typedef struct NetworkChannel NetworkChannel;
2328

@@ -27,14 +32,20 @@ struct NetworkChannel {
2732
*/
2833
interval_t expected_try_connect_duration;
2934

35+
/**
36+
* @brief Type of the network channel to differentiate between different implementations such as TcpIp or CoapUdpIp.
37+
*/
38+
NetworkChannelType type;
39+
3040
/**
3141
* @brief Get the current state of the connection.
3242
* @return NETWORK_CHANNEL_STATE_UNINITIALIZED if the connection has not been initialized yet,
3343
* NETWORK_CHANNEL_STATE_OPEN if the connection is open and waiting for try_connect to be called,
3444
* NETWORK_CHANNEL_STATE_CONNECTION_IN_PROGRESS if try_connect has been called but it is not yet connected,
45+
* NETWORK_CHANNEL_STATE_CONNECTION_FAILED if the connection failed,
3546
* NETWORK_CHANNEL_STATE_CONNECTED if the channel is successfully connected to another federate,
36-
* NETWORK_CHANNEL_STATE_DISCONNECTED if the connection was manually closed,
37-
* NETWORK_CHANNEL_STATE_LOST_CONNECTION if the connection was unexpectedly closed.
47+
* NETWORK_CHANNEL_STATE_LOST_CONNECTION if the connection was unexpectedly closed,
48+
* NETWORK_CHANNEL_STATE_CLOSED if the connection was manually closed.
3849
*/
3950
NetworkChannelState (*get_connection_state)(NetworkChannel *self);
4051

include/reactor-uc/platform/posix/tcp_ip_channel.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@
99
#include "reactor-uc/network_channel.h"
1010

1111
#define TCP_IP_CHANNEL_BUFFERSIZE 1024
12-
#define TCP_IP_CHANNEL_NUM_RETRIES 255;
12+
#define TCP_IP_CHANNEL_NUM_RETRIES 255
1313
#define TCP_IP_CHANNEL_RECV_THREAD_STACK_SIZE 2048
1414
#define TCP_IP_CHANNEL_RECV_THREAD_STACK_GUARD_SIZE 128
1515

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
#ifndef REACTOR_UC_COAP_UDP_IP_CHANNEL_H
2+
#define REACTOR_UC_COAP_UDP_IP_CHANNEL_H
3+
#include "reactor-uc/network_channel.h"
4+
#include "reactor-uc/environment.h"
5+
#include "net/sock/udp.h"
6+
#include "mutex.h"
7+
8+
#define COAP_UDP_IP_CHANNEL_BUFFERSIZE 1024
9+
// #define COAP_UDP_IP_CHANNEL_NUM_RETRIES 255;
10+
// #define COAP_UDP_IP_CHANNEL_RECV_THREAD_STACK_SIZE 2048
11+
// #define COAP_UDP_IP_CHANNEL_RECV_THREAD_STACK_GUARD_SIZE 128
12+
13+
typedef struct CoapUdpIpChannel CoapUdpIpChannel;
14+
typedef struct FederatedConnectionBundle FederatedConnectionBundle;
15+
16+
struct CoapUdpIpChannel {
17+
NetworkChannel super;
18+
19+
NetworkChannelState state;
20+
mutex_t state_mutex;
21+
22+
sock_udp_ep_t remote;
23+
24+
FederateMessage output;
25+
uint8_t write_buffer[COAP_UDP_IP_CHANNEL_BUFFERSIZE];
26+
27+
FederatedConnectionBundle *federated_connection;
28+
void (*receive_callback)(FederatedConnectionBundle *conn, const FederateMessage *message);
29+
};
30+
31+
void CoapUdpIpChannel_ctor(CoapUdpIpChannel *self, Environment *env, const char *remote_address,
32+
int remote_protocol_family);
33+
34+
#endif
Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
include $(RIOTBASE)/Makefile.base
2+
3+
SRC_DIR := $(realpath $(CURDIR)/../../../../external/Unity/src)
4+
5+
all:
6+
$(QQ)"$(MAKE)" -C $(SRC_DIR) -f $(CURDIR)/Unity.mk

0 commit comments

Comments
 (0)