summaryrefslogtreecommitdiff
path: root/firmware/src/main.c
blob: 8b315053d726cc17f98c8e6c74cb72dd22b55577 (plain)
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
#include <stdbool.h>
#include <sys/types.h>

#include <zephyr/device.h>
#include <zephyr/drivers/uart.h>
#include <zephyr/kernel.h>
#include <zephyr/sys/util.h>

#include "eui64.h"
#include "data_link.h"

#define UART_DEVICE_NODE DT_CHOSEN(zephyr_shell_uart)
static const struct device *const uart_dev = DEVICE_DT_GET(UART_DEVICE_NODE);

int main(void)
{
	if (!device_is_ready(uart_dev)) {
		printk("UART device not found");
		return 0;
	}

	if (!eui64_available()) {
		printk("No EUI-64 address available");
		return 0;
	}

	uint8_t payload[] = {0xDE, DL_SLIP_END, DL_SLIP_ESC, 0xAD};
	uint8_t frame[DL_MAX_FRAME_SIZE];

	ssize_t flen = dl_encode_frame(payload, ARRAY_SIZE(payload), frame);
	if (flen < 0) {
		printk("Failed to encode frame");
		return 0;
	}

	while (true) {
		k_sleep(K_MSEC(1000));
		dl_send_frame(uart_dev, frame, flen);
	}

	return 0;
}