Skip to content

Commit

Permalink
43 calypso buildroot (#77)
Browse files Browse the repository at this point in the history
* builds cleanly

* calypso working

see nanomq issue! probably not from calypso

* initial plugin support

* basic plugin and support

still cant find symbols via buildroot, plugin tested on debian.

* remove upstream header

* add nanomq plugin ability

actually works on buildroot so happy

* add nanomq and calypso to nero

* vital fixups

* important: switch to pid forking of nanomq

* bump calypso version

* fixes nanomq bug (#79) by some miracle

* bump nanomq version

* add comments to the timestamp plugin
  • Loading branch information
jr1221 authored Feb 1, 2024
1 parent e5a112d commit 923057f
Show file tree
Hide file tree
Showing 14 changed files with 225 additions and 17 deletions.
1 change: 1 addition & 0 deletions odysseus/odysseus_tree/Config.in
Original file line number Diff line number Diff line change
Expand Up @@ -9,3 +9,4 @@ source "$BR2_EXTERNAL_ODY_TREE_PATH/package/auto-modloader/Config.in"
source "$BR2_EXTERNAL_ODY_TREE_PATH/package/rpi-dtloader/Config.in"
source "$BR2_EXTERNAL_ODY_TREE_PATH/package/nero2/Config.in"
source "$BR2_EXTERNAL_ODY_TREE_PATH/package/nerqt6/Config.in"
source "$BR2_EXTERNAL_ODY_TREE_PATH/package/calypso/Config.in"
46 changes: 46 additions & 0 deletions odysseus/odysseus_tree/board/tpu/plugin_user_property_timestamp.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
#include <stdio.h>
#include <stdlib.h>
#include <sys/time.h>


#include "nanomq/plugin.h"

// upstream calls this function and accesses property from the data variable, then frees the properties after message is sent
int cb(void *data)
{
char **property = data;
if (property != NULL) {

// key of ts, add 1 bc termination byte
property[0] = malloc(strlen("ts") + 1);
strcpy(property[0], "ts");


// the below is used to get the time in miliseconds, required since there is no api for milisecond precision
struct timeval tv;

gettimeofday(&tv, NULL);

// do the math to get the miliseconds since unix epoch
unsigned long long millisecondsSinceEpoch =
(unsigned long long)(tv.tv_sec) * 1000 +
(unsigned long long)(tv.tv_usec) / 1000;

// currently the time is using 13 characters, so 30 should be enough
char str[30];
// convert the epoch time to a char arr
sprintf(str, "%llu", millisecondsSinceEpoch);

// value of the time, add 1 bc termination byte
property[1] = malloc(strlen(str)+1);
strcpy(property[1], str);
}

return 0;
}

int nano_plugin_init()
{
plugin_hook_register(HOOK_USER_PROPERTY, cb);
return 0;
}
8 changes: 6 additions & 2 deletions odysseus/odysseus_tree/configs/raspberrypi4_64_nero_defconfig
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ BR2_TARGET_GENERIC_HOSTNAME="rasberrypi-nero"
BR2_TARGET_GENERIC_ISSUE="Welcome to odysseus, NER custom linux"
BR2_ROOTFS_DEVICE_CREATION_DYNAMIC_EUDEV=y
BR2_TARGET_GENERIC_ROOT_PASSWD="password"
BR2_ROOTFS_OVERLAY="$(BR2_EXTERNAL_ODY_TREE_PATH)/overlays/rootfs_overlay_hostapd_common $(BR2_EXTERNAL_ODY_TREE_PATH)/overlays/rootfs_overlay_nero"
BR2_ROOTFS_OVERLAY="$(BR2_EXTERNAL_ODY_TREE_PATH)/overlays/rootfs_overlay_hostapd_common $(BR2_EXTERNAL_ODY_TREE_PATH)/overlays/rootfs_overlay_can_common $(BR2_EXTERNAL_ODY_TREE_PATH)/overlays/rootfs_overlay_nero"
BR2_ROOTFS_POST_BUILD_SCRIPT="board/raspberrypi4-64/post-build.sh"
BR2_ROOTFS_POST_IMAGE_SCRIPT="board/raspberrypi4-64/post-image.sh"
BR2_LINUX_KERNEL=y
Expand Down Expand Up @@ -44,6 +44,7 @@ BR2_PACKAGE_LM_SENSORS=y
BR2_PACKAGE_RASPI_GPIO=y
BR2_PACKAGE_PYTHON3=y
BR2_PACKAGE_CA_CERTIFICATES=y
BR2_PACKAGE_OPENSSL=y
BR2_PACKAGE_PIXMAN=y
BR2_PACKAGE_BMON=y
BR2_PACKAGE_CAN_UTILS=y
Expand All @@ -56,7 +57,6 @@ BR2_PACKAGE_IPERF3=y
BR2_PACKAGE_IPROUTE2=y
BR2_PACKAGE_IPUTILS=y
BR2_PACKAGE_IW=y
BR2_PACKAGE_SOCKETCAND=y
BR2_PACKAGE_WIRELESS_REGDB=y
BR2_PACKAGE_HTOP=y
BR2_PACKAGE_KMOD_TOOLS=y
Expand All @@ -75,6 +75,9 @@ BR2_PACKAGE_NANOMQ_QUIC=y
BR2_PACKAGE_NANOMQ_BENCH=y
BR2_PACKAGE_NANOMQ_SQLITE=y
BR2_PACKAGE_NANOMQ_DISABLE_SHAREDLIB=y
BR2_PACKAGE_NANOMQ_RULE_ENGINE=y
BR2_PACKAGE_NANOMQ_PLUGIN=y
BR2_PACKAGE_NANOMQ_PLUGIN_LIST="$(BR2_EXTERNAL_ODY_TREE_PATH)/board/tpu/plugin_user_property_timestamp.c"
BR2_PACKAGE_RPI_DTLOADER=y
BR2_PACKAGE_NERO2=y
BR2_PACKAGE_NERQT6=y
Expand All @@ -86,3 +89,4 @@ BR2_PACKAGE_NERQT6BASE_SYSLOG=y
BR2_PACKAGE_NERQT6DECLARATIVE=y
BR2_PACKAGE_NERQT6DECLARATIVE_QUICK=y
BR2_PACKAGE_NERQT6MQTT=y
BR2_PACKAGE_CALYPSO=y
8 changes: 6 additions & 2 deletions odysseus/odysseus_tree/configs/raspberrypi4_64_tpu_defconfig
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ BR2_TARGET_GENERIC_HOSTNAME="raspberrypi-sta"
BR2_TARGET_GENERIC_ISSUE="Welcome to odysseus, NER custom linux"
BR2_ROOTFS_DEVICE_CREATION_DYNAMIC_EUDEV=y
BR2_TARGET_GENERIC_ROOT_PASSWD="password"
BR2_ROOTFS_OVERLAY="$(BR2_EXTERNAL_ODY_TREE_PATH)/overlays/rootfs_overlay_nrc_common $(BR2_EXTERNAL_ODY_TREE_PATH)/overlays/rootfs_overlay_hostapd_common $(BR2_EXTERNAL_ODY_TREE_PATH)/overlays/rootfs_overlay_tpu"
BR2_ROOTFS_OVERLAY="$(BR2_EXTERNAL_ODY_TREE_PATH)/overlays/rootfs_overlay_nrc_common $(BR2_EXTERNAL_ODY_TREE_PATH)/overlays/rootfs_overlay_hostapd_common $(BR2_EXTERNAL_ODY_TREE_PATH)/overlays/rootfs_overlay_can_common $(BR2_EXTERNAL_ODY_TREE_PATH)/overlays/rootfs_overlay_tpu"
BR2_ROOTFS_PRE_BUILD_SCRIPT="$(BR2_EXTERNAL_ODY_TREE_PATH)/pre-make-sta.sh"
BR2_ROOTFS_POST_BUILD_SCRIPT="board/raspberrypi4-64/post-build.sh"
BR2_ROOTFS_POST_IMAGE_SCRIPT="board/raspberrypi4-64/post-image.sh"
Expand Down Expand Up @@ -41,6 +41,7 @@ BR2_PACKAGE_PPS_TOOLS=y
BR2_PACKAGE_RASPI_GPIO=y
# BR2_PACKAGE_PYTHON3_UNICODEDATA is not set
BR2_PACKAGE_CA_CERTIFICATES=y
BR2_PACKAGE_OPENSSL=y
BR2_PACKAGE_BMON=y
BR2_PACKAGE_CAN_UTILS=y
BR2_PACKAGE_CHRONY=y
Expand All @@ -53,7 +54,6 @@ BR2_PACKAGE_IPERF3=y
BR2_PACKAGE_IPROUTE2=y
BR2_PACKAGE_IPUTILS=y
BR2_PACKAGE_IW=y
BR2_PACKAGE_SOCKETCAND=y
BR2_PACKAGE_WIRELESS_REGDB=y
BR2_PACKAGE_WPA_SUPPLICANT=y
BR2_PACKAGE_WPA_SUPPLICANT_CLI=y
Expand Down Expand Up @@ -82,5 +82,9 @@ BR2_PACKAGE_NANOMQ_QUIC=y
BR2_PACKAGE_NANOMQ_BENCH=y
BR2_PACKAGE_NANOMQ_SQLITE=y
BR2_PACKAGE_NANOMQ_DISABLE_SHAREDLIB=y
BR2_PACKAGE_NANOMQ_RULE_ENGINE=y
BR2_PACKAGE_NANOMQ_PLUGIN=y
BR2_PACKAGE_NANOMQ_PLUGIN_LIST="$(BR2_EXTERNAL_ODY_TREE_PATH)/board/tpu/plugin_user_property_timestamp.c"
BR2_PACKAGE_RPI_DTLOADER=y
BR2_PACKAGE_RPI_DTLOADER_FILES="$(BR2_EXTERNAL_ODY_TREE_PATH)/package/nrc7292/newracom_for_5-16_or_later.dts"
BR2_PACKAGE_CALYPSO=y
Original file line number Diff line number Diff line change
@@ -0,0 +1,66 @@
#! /bin/sh

### BEGIN INIT INFO
# Provides: socketcand
# Required-Start: $remote_fs
# Required-Stop: $remote_fs
# Default-Start: 2 3 4 5
# Default-Stop:
# Short-Description: socketcand
# Description: daemon that provides network access to local CAN busses
### END INIT INFO

[ -f /etc/default/rcS ] && . /etc/default/rcS
PATH=/bin:/usr/bin:/sbin:/usr/sbin
prefix=@prefix@
exec_prefix=@exec_prefix@
DAEMON=@bindir@/socketcand
DESC="SocketCAN daemon"
NAME="socketcand"
PIDFILE=/var/run/socketcand.pid

test -x $DAEMON || exit 0

case "$1" in
start)
echo "Starting $DESC" "$NAME"
start-stop-daemon --start --quiet --background --pidfile $PIDFILE --startas $DAEMON -m -- --daemon
;;
stop)
echo "Stopping $DESC" "$NAME"
start-stop-daemon --stop --quiet --pidfile $PIDFILE --oknodo --startas $DAEMON
rm -f $PIDFILE
;;
status)
printf "%-50s" "Checking $NAME..."
if [ -f $PIDFILE ]; then
PID=`cat $PIDFILE`
if [ -z "`ps axf | grep ${PID} | grep -v grep`" ]; then
printf "%s\n" "Process dead but pidfile exists"
return 1
else
echo "Running"
return 0
fi
else
printf "%s\n" "Service not running"
return 1
fi
;;
restart)
$0 stop
sleep 1
$0 start
;;
force-reload)
if start-stop-daemon --stop --test --quiet --pidfile $PIDFILE --startas $DAEMON ; then
$0 restart
fi
;;
*)
echo "Usage: /etc/init.d/socketcand {start|stop|restart|force-reload}"
exit 1
;;
esac

exit 0
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ case "$1" in
start)
echo "Starting hostapd..."
# start (S) executable (x), make pid file (m) at p, run in background (-- -B),
start-stop-daemon -S -x "$EXECUTABLE" -m -p "$PIDFILE" -- -B "$CONF"
start-stop-daemon -S -x "$EXECUTABLE" -b -m -p "$PIDFILE" -- "$CONF"
;;
stop)
echo "Stopping hostapd..."
Expand Down
12 changes: 12 additions & 0 deletions odysseus/odysseus_tree/package/calypso/Config.in
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
config BR2_PACKAGE_CALYPSO
bool "calypso"
depends on BR2_PACKAGE_HOST_RUSTC_TARGET_ARCH_SUPPORTS
depends on BR2_PACKAGE_OPENSSL
select BR2_PACKAGE_HOST_RUSTC
select BR2_PACKAGE_SOCKETCAND
help
The NER CAN message decoding software.

Written in Rust, utlizing socketcand.

https://github.com/Northeastern-Electric-Racing/Calypso
26 changes: 26 additions & 0 deletions odysseus/odysseus_tree/package/calypso/S76calypso
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
#!/bin/sh

PIDFILE=/var/run/calypso.pid
EXECUTABLE=/usr/bin/calypso
INTERFACE_NAME=can0

case "$1" in
start)
echo "Starting calypso..."
# start (S) executable (x) in background (b), make pid file (m) at p
start-stop-daemon -S -x "$EXECUTABLE" -b -m -p "$PIDFILE" -- mqtt localhost:1883 $INTERFACE_NAME skip_can_configure
;;
stop)
echo "Stopping calypso..."
# stop (K) and remove pidfile
start-stop-daemon -K -p "$PIDFILE"
rm "$PIDFILE"
;;
restart|reload)
"$0" stop
"$0" start
;;
*)
echo "Usage: {start|stop|restart/reload}"
exit 1
esac
10 changes: 10 additions & 0 deletions odysseus/odysseus_tree/package/calypso/calypso.mk
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
CALYPSO_VERSION = 684379919866ee2c15e824486305b916ecd4d344
CALYPSO_SITE_METHOD = git
CALYPSO_SITE = https://github.com/Northeastern-Electric-Racing/Calypso
CALYPSO_DEPENDENCIES += openssl

define CALYPSO_INSTALL_INIT_SYSV
$(INSTALL) -D -m 0755 $(BR2_EXTERNAL_ODY_TREE_PATH)/package/calypso/S76calypso $(TARGET_DIR)/etc/init.d/S76calypso
endef

$(eval $(cargo-package))
19 changes: 19 additions & 0 deletions odysseus/odysseus_tree/package/nanomq/Config.in
Original file line number Diff line number Diff line change
Expand Up @@ -77,6 +77,7 @@ config BR2_PACKAGE_NANOMQ_JWT

config BR2_PACKAGE_NANOMQ_SQLITE
bool "sqlite"
select BR2_PACKAGE_SQLITE3
help
to build nanomq with sqlite support

Expand Down Expand Up @@ -143,4 +144,22 @@ config BR2_PACKAGE_NANOMQ_TESTS
help
Enable nanomqy unit tests

config BR2_PACKAGE_NANOMQ_PLUGIN
bool "plugin support"
default n
help
Enable plugin support

if BR2_PACKAGE_NANOMQ_PLUGIN

config BR2_PACKAGE_NANOMQ_PLUGIN_LIST
string "list of plugins"
help
Space seperated path lists of plugins.
Remember to add them to the conf file yourself.
They are installed to /usr/lib/nanomq/

endif


endif
12 changes: 7 additions & 5 deletions odysseus/odysseus_tree/package/nanomq/S75nanomq
Original file line number Diff line number Diff line change
@@ -1,22 +1,24 @@
#!/bin/sh

PIDFILE=/var/run/nanomq_br.pid
EXECUTABLE=/usr/bin/nanomq
CONF_FILE=/etc/nanomq.conf

case "$1" in
start)
echo "Starting nanomq..."
# start (S) executable (x) in background (b) -- send in conf file and run as daemon
start-stop-daemon -S -x "$EXECUTABLE" -- start --conf "$CONF_FILE" -d
start-stop-daemon -S -x "$EXECUTABLE" -b -m -p "$PIDFILE" -- start --conf "$CONF_FILE"
;;
stop)
echo "Stopping nanomq..."
# stop using nanomq binary
"$EXECUTABLE" stop
# stop (K) and remove pidfile
start-stop-daemon -K -p "$PIDFILE"
rm "$PIDFILE"
;;
restart|reload)
# reload using nanomq binary, conf requires re-send
"$EXECUTABLE" -- reload --conf "$CONF_FILE"
"$0" stop
"$0" start
;;
*)
echo "Usage: {start|stop|restart/reload}"
Expand Down
30 changes: 25 additions & 5 deletions odysseus/odysseus_tree/package/nanomq/nanomq.mk
Original file line number Diff line number Diff line change
@@ -1,20 +1,39 @@
# must use later version then stable due to build issue with log_err function.
# Fix upon next nanomq release, as the build system is somewhat complicated and often changes
NANOMQ_VERSION = 9828d7b0c432d9495c5f940d75df0a621203b814
NANOMQ_VERSION = 0.21.2
NANOMQ_SITE_METHOD = git
NANOMQ_SITE = https://github.com/nanomq/nanomq
NANOMQ_GIT_SUBMODULES = YES
NANOMQ_GIT_LFS = YES
NANOMQ_LICENSE = MIT
# Note: this doesn't seem to be in use despite setting it?
NANOMQ_CMAKE_BACKEND = ninja
# so it uses a build subdirectory
NANOMQ_SUPPORTS_IN_SOURCE_BUILD = NO
NANOMQ_INSTALL_STAGING = YES

define NANOMQ_INSTALL_INIT_SYSV
$(INSTALL) -D -m 0755 $(BR2_EXTERNAL_ODY_TREE_PATH)/package/nanomq/S75nanomq $(TARGET_DIR)/etc/init.d/S75nanomq
endef

ifeq ($(BR2_PACKAGE_NANOMQ_PLUGIN),y)
NANOMQ_CONF_OPTS += -DENABLE_PLUGIN=ON
NANOMQ_CONF_OPTS += -DCMAKE_EXE_LINKER_FLAGS="-export-dynamic"
define NANOMQ_PLUGIN_INSTALLATION
$(foreach plugin,$(call qstrip,$(BR2_PACKAGE_NANOMQ_PLUGIN_LIST)), \
$(TARGET_CC) $(NANOMQ_CFLAGS) -I$(STAGING_DIR)/usr/include/nanomq $(plugin) -fPIC -shared -o $(@D)/$(notdir $(basename $(plugin))).so
)

$(INSTALL) -d $(TARGET_DIR)/usr/lib/nanomq/
$(foreach plugin,$(call qstrip,$(BR2_PACKAGE_NANOMQ_PLUGIN_LIST)), \
$(info, "Installing $(plugin)!") \
$(INSTALL) -D -m 0755 $(@D)/$(notdir $(basename $(plugin))).so $(TARGET_DIR)/usr/lib/nanomq/
)
endef

NANOMQ_POST_INSTALL_TARGET_HOOKS += NANOMQ_PLUGIN_INSTALLATION

endif

ifeq ($(BR2_PACKAGE_NANOMQ_QUIC), y)
NANOMQ_CONF_OPTS += -DNNG_ENABLE_QUIC=ON
Expand Down Expand Up @@ -53,11 +72,11 @@ NANOMQ_CONF_OPTS += -DBUILD_ZMQ_GATEWAY=ON
endif

ifeq ($(BR2_PACKAGE_NANOMQ_VSOMEIP_GATEWAY), y)
NANOMQ_CONF_OPTS += -DBUILD_VSOMEIP_GATEWAY
NANOMQ_CONF_OPTS += -DBUILD_VSOMEIP_GATEWAY=ON
endif

ifeq ($(BR2_PACKAGE_NANOMQ_NNG_PROXY), y)
NANOMQ_CONF_OPTS += -DBUILD_NNG_PROXY
NANOMQ_CONF_OPTS += -DBUILD_NNG_PROXY=ON
endif

ifeq ($(BR2_PACKAGE_NANOMQ_BENCH), y)
Expand All @@ -73,6 +92,7 @@ NANOMQ_CONF_OPTS += -DNNG_ENABLE_SQLITE=ON
endif

ifeq ($(BR2_PACKAGE_NANOMQ_STATICLIB), y)
NANOMQ_CONF_OPTS += -DBUILD_WITH_STATIC_LIBS=ON
NANOMQ_CONF_OPTS += -DBUILD_STATIC_LIB=ON
endif

Expand Down Expand Up @@ -113,7 +133,7 @@ NANOMQ_CONF_OPTS += -DENABLE_SYSLOG=OFF
endif

ifeq ($(BR2_PACKAGE_NANOMQ_TESTS), y)
NANOMQ_CONF_OPTS += -DNANOMQ_TESTS
NANOMQ_CONF_OPTS += -DNANOMQ_TESTS=ON
endif

$(eval $(cmake-package))
1 change: 0 additions & 1 deletion odysseus/odysseus_tree/package/nrc7292/nrc7292.mk
Original file line number Diff line number Diff line change
Expand Up @@ -22,4 +22,3 @@ NRC7292_POST_BUILD_HOOKS += NRC7292_BUILD_DTO

$(eval $(kernel-module))
$(eval $(generic-package))

1 change: 0 additions & 1 deletion odysseus/odysseus_tree/package/nrc7394/nrc7394.mk
Original file line number Diff line number Diff line change
Expand Up @@ -22,4 +22,3 @@ NRC7394_POST_BUILD_HOOKS += NRC7394_BUILD_DTO

$(eval $(kernel-module))
$(eval $(generic-package))

0 comments on commit 923057f

Please sign in to comment.