From 180c5e95b1dfc6b870bcb2478ba64f178ba4d35b Mon Sep 17 00:00:00 2001 From: zlynch2 Date: Tue, 10 Sep 2024 21:30:43 +0000 Subject: [PATCH] [nasa/nos3#84] fprime building in docker container, pull deployment fprime branch locally and build, also target cfs or fprime build-fsw --- Makefile | 26 ++++--- scripts/cfs_build_fsw.sh | 32 ++++++++ scripts/cfs_cosmos.sh | 149 ++++++++++++++++++++++++++++++++++++ scripts/configure.py | 4 + scripts/docker_build_fsw.sh | 2 +- scripts/docker_debug.sh | 3 +- scripts/env.sh | 4 +- scripts/fprime_build_fsw.sh | 31 ++++++++ 8 files changed, 237 insertions(+), 14 deletions(-) create mode 100755 scripts/cfs_build_fsw.sh create mode 100755 scripts/cfs_cosmos.sh create mode 100755 scripts/fprime_build_fsw.sh diff --git a/Makefile b/Makefile index 97c2885b..5074c1a6 100644 --- a/Makefile +++ b/Makefile @@ -52,17 +52,20 @@ build-cryptolib: $(MAKE) --no-print-directory -C $(GSWBUILDDIR) build-fsw: - ifeq($(FLIGHT_SOFTWARE), fprime) - cd fsw/fprime/fprime-nos3 - . fprime-venv/bin/activate - fprime-util build - endif + + +ifeq ($(FLIGHT_SOFTWARE), fprime) + cd fsw/fprime/fprime-nos3 && fprime-util generate && fprime-util build - ifeq($(FLIGHT_SOFTWARE), cfs) - mkdir -p $(FSWBUILDDIR) - cd $(FSWBUILDDIR) && cmake $(PREP_OPTS) ../cfe - $(MAKE) --no-print-directory -C $(FSWBUILDDIR) mission-install - endif +endif + +ifeq ($(FLIGHT_SOFTWARE), cfs) + mkdir -p $(FSWBUILDDIR) + cd $(FSWBUILDDIR) && cmake $(PREP_OPTS) ../cfe + $(MAKE) --no-print-directory -C $(FSWBUILDDIR) mission-install +else + pwd +endif build-sim: mkdir -p $(SIMBUILDDIR) @@ -103,7 +106,8 @@ fprime: ./scripts/fprime.sh fsw: - ./cfg/build/fsw_build.sh + ./scripts/docker_build_fsw.sh + # ./cfg/build/fsw_build.sh gsw: ./scripts/docker_build_cryptolib.sh diff --git a/scripts/cfs_build_fsw.sh b/scripts/cfs_build_fsw.sh new file mode 100755 index 00000000..38cf7aa0 --- /dev/null +++ b/scripts/cfs_build_fsw.sh @@ -0,0 +1,32 @@ +#!/bin/bash -i +# +# Convenience script for NOS3 development +# Use with the Dockerfile in the deployment repository +# https://github.com/nasa-itc/deployment +# + +SCRIPT_DIR=$( cd -- "$( dirname -- "${BASH_SOURCE[0]}" )" &> /dev/null && pwd ) +source $SCRIPT_DIR/env.sh +source FLIGHT_SOFTWARE=cfs + +# Check that local NOS3 directory exists +if [ ! -d $USER_NOS3_DIR ]; then + echo "" + echo " Need to run make prep first!" + echo "" + exit 1 +fi + +# Check that configure build directory exists +if [ ! -d $BASE_DIR/cfg/build ]; then + echo "" + echo " Need to run make config first!" + echo "" + exit 1 +fi + +# Make flight software build directory +mkdir -p $BASE_DIR/fsw/build + +# Build +$DFLAGS_CPUS -v $BASE_DIR:$BASE_DIR --name "nos_build_fsw" -w $BASE_DIR $DBOX make -j$NUM_CPUS build-fsw diff --git a/scripts/cfs_cosmos.sh b/scripts/cfs_cosmos.sh new file mode 100755 index 00000000..796c9d2c --- /dev/null +++ b/scripts/cfs_cosmos.sh @@ -0,0 +1,149 @@ +#!/bin/bash -i +# +# Convenience script for NOS3 development +# Use with the Dockerfile in the deployment repository +# https://github.com/nasa-itc/deployment +# + +SCRIPT_DIR=$( cd -- "$( dirname -- "${BASH_SOURCE[0]}" )" &> /dev/null && pwd ) +source $SCRIPT_DIR/env.sh + +# Check that local NOS3 directory exists +if [ ! -d $USER_NOS3_DIR ]; then + echo "" + echo " Need to run make prep first!" + echo "" + exit 1 +fi + +# Check that configure build directory exists +if [ ! -d $BASE_DIR/cfg/build ]; then + echo "" + echo " Need to run make config first!" + echo "" + exit 1 +fi + +echo "Make data folders..." +# FSW Side +mkdir $FSW_DIR/data 2> /dev/null +mkdir $FSW_DIR/data/cam 2> /dev/null +mkdir $FSW_DIR/data/evs 2> /dev/null +mkdir $FSW_DIR/data/hk 2> /dev/null +mkdir $FSW_DIR/data/inst 2> /dev/null +# GSW Side +mkdir /tmp/nos3 2> /dev/null +mkdir /tmp/nos3/data 2> /dev/null +mkdir /tmp/nos3/data/cam 2> /dev/null +mkdir /tmp/nos3/data/evs 2> /dev/null +mkdir /tmp/nos3/data/hk 2> /dev/null +mkdir /tmp/nos3/data/inst 2> /dev/null +mkdir /tmp/nos3/uplink 2> /dev/null +cp $BASE_DIR/fsw/build/exe/cpu1/cf/cfe_es_startup.scr /tmp/nos3/uplink/tmp0.so 2> /dev/null +cp $BASE_DIR/fsw/build/exe/cpu1/cf/sample.so /tmp/nos3/uplink/tmp1.so 2> /dev/null + +echo "Create ground networks..." +$DNETWORK create \ + --driver=bridge \ + --subnet=192.168.41.0/24 \ + --gateway=192.168.41.1 \ + nos3_core +echo "" + +#echo "Launch GSW..." +$BASE_DIR/cfg/build/gsw_launch.sh +echo "" + +echo "Create NOS interfaces..." +export GND_CFG_FILE="-f nos3-simulator.xml" +gnome-terminal --tab --title="NOS Terminal" -- $DFLAGS -v $SIM_DIR:$SIM_DIR --name "nos_terminal" --network=nos3_core -w $SIM_BIN $DBOX ./nos3-single-simulator $GND_CFG_FILE stdio-terminal +gnome-terminal --tab --title="NOS UDP Terminal" -- $DFLAGS -v $SIM_DIR:$SIM_DIR --name "nos_udp_terminal" --network=nos3_core -w $SIM_BIN $DBOX ./nos3-single-simulator $GND_CFG_FILE udp-terminal +echo "" + +# Note only currently working with a single spacecraft +export SATNUM=1 + +# +# Spacecraft Loop +# +for (( i=1; i<=$SATNUM; i++ )) +do + export SC_NUM="sc_"$i + export SC_NETNAME="nos3_"$SC_NUM + export SC_CFG_FILE="-f nos3-simulator.xml" #"-f sc_"$i"_nos3_simulator.xml" + + # Debugging + #echo "Spacecraft number = " $SC_NUM + #echo "Spacecraft network = " $SC_NETNAME + #echo "Spacecraft configuration = " $SC_CFG_FILE + + echo $SC_NUM " - Create spacecraft network..." + $DNETWORK create $SC_NETNAME 2> /dev/null + echo "" + + echo $SC_NUM " - Connect COSMOS to spacecraft network..." + $DNETWORK connect $SC_NETNAME cosmos_openc3-operator_1 --alias cosmos + echo "" + + echo $SC_NUM " - 42..." + rm -rf $USER_NOS3_DIR/42/NOS3InOut + cp -r $BASE_DIR/cfg/build/InOut $USER_NOS3_DIR/42/NOS3InOut + xhost +local:* + gnome-terminal --tab --title=$SC_NUM" - 42" -- $DFLAGS -e DISPLAY=$DISPLAY -v $USER_NOS3_DIR:$USER_NOS3_DIR -v /tmp/.X11-unix:/tmp/.X11-unix:ro --name $SC_NUM"_fortytwo" -h fortytwo --network=$SC_NETNAME -w $USER_NOS3_DIR/42 -t $DBOX $USER_NOS3_DIR/42/42 NOS3InOut + echo "" + + echo $SC_NUM " - Flight Software..." + cd $FSW_DIR + gnome-terminal --title=$SC_NUM" - NOS3 Flight Software" -- $DFLAGS -v $BASE_DIR:$BASE_DIR --name $SC_NUM"_nos_fsw" -h nos_fsw --network=$SC_NETNAME -w $FSW_DIR --sysctl fs.mqueue.msg_max=10000 --ulimit rtprio=99 --cap-add=sys_nice $DBOX $SCRIPT_DIR/fsw_respawn.sh & + #gnome-terminal --window-with-profile=KeepOpen --title=$SC_NUM" - NOS3 Flight Software" -- $DFLAGS -v $BASE_DIR:$BASE_DIR --name $SC_NUM"_nos_fsw" -h nos_fsw --network=$SC_NETNAME -w $FSW_DIR --sysctl fs.mqueue.msg_max=10000 --ulimit rtprio=99 --cap-add=sys_nice $DBOX $FSW_DIR/core-cpu1 -R PO & + echo "" + + # Debugging + # Replace `--tab` with `--window-with-profile=KeepOpen` once you've created this gnome-terminal profile manually + + echo $SC_NUM " - CryptoLib..." + gnome-terminal --tab --title=$SC_NUM" - CryptoLib" -- $DFLAGS -v $BASE_DIR:$BASE_DIR --name $SC_NUM"_cryptolib" --network=$SC_NETNAME --network-alias=cryptolib -w $BASE_DIR/gsw/build $DBOX ./support/standalone + echo "" + + echo $SC_NUM " - Simulators..." + cd $SIM_BIN + gnome-terminal --tab --title=$SC_NUM" - NOS Engine Server" -- $DFLAGS -v $SIM_DIR:$SIM_DIR --name $SC_NUM"_nos_engine_server" -h nos_engine_server --network=$SC_NETNAME -w $SIM_BIN $DBOX /usr/bin/nos_engine_server_standalone -f $SIM_BIN/nos_engine_server_config.json + gnome-terminal --tab --title=$SC_NUM" - 42 Truth Sim" -- $DFLAGS -v $SIM_DIR:$SIM_DIR --name $SC_NUM"_truth42sim" -h truth42sim --network=$SC_NETNAME -w $SIM_BIN $DBOX ./nos3-single-simulator $SC_CFG_FILE truth42sim + + $DNETWORK connect $SC_NETNAME nos_terminal + $DNETWORK connect $SC_NETNAME nos_udp_terminal + + # Component simulators + gnome-terminal --tab --title=$SC_NUM" - CAM Sim" -- $DFLAGS -v $SIM_DIR:$SIM_DIR --name $SC_NUM"_cam_sim" --network=$SC_NETNAME -w $SIM_BIN $DBOX ./nos3-single-simulator $SC_CFG_FILE camsim + gnome-terminal --tab --title=$SC_NUM" - CSS Sim" -- $DFLAGS -v $SIM_DIR:$SIM_DIR --name $SC_NUM"_css_sim" --network=$SC_NETNAME -w $SIM_BIN $DBOX ./nos3-single-simulator $SC_CFG_FILE generic_css_sim + gnome-terminal --tab --title=$SC_NUM" - EPS Sim" -- $DFLAGS -v $SIM_DIR:$SIM_DIR --name $SC_NUM"_eps_sim" --network=$SC_NETNAME -w $SIM_BIN $DBOX ./nos3-single-simulator $SC_CFG_FILE generic_eps_sim + gnome-terminal --tab --title=$SC_NUM" - FSS Sim" -- $DFLAGS -v $SIM_DIR:$SIM_DIR --name $SC_NUM"_fss_sim" --network=$SC_NETNAME -w $SIM_BIN $DBOX ./nos3-single-simulator $SC_CFG_FILE generic_fss_sim + gnome-terminal --tab --title=$SC_NUM" - GPS Sim" -- $DFLAGS -v $SIM_DIR:$SIM_DIR --name $SC_NUM"_gps_sim" --network=$SC_NETNAME -w $SIM_BIN $DBOX ./nos3-single-simulator $SC_CFG_FILE gps + gnome-terminal --tab --title=$SC_NUM" - IMU Sim" -- $DFLAGS -v $SIM_DIR:$SIM_DIR --name $SC_NUM"_imu_sim" --network=$SC_NETNAME -w $SIM_BIN $DBOX ./nos3-single-simulator $SC_CFG_FILE generic_imu_sim + gnome-terminal --tab --title=$SC_NUM" - MAG Sim" -- $DFLAGS -v $SIM_DIR:$SIM_DIR --name $SC_NUM"_mag_sim" --network=$SC_NETNAME -w $SIM_BIN $DBOX ./nos3-single-simulator $SC_CFG_FILE generic_mag_sim + gnome-terminal --tab --title=$SC_NUM" - RW 0 Sim" -- $DFLAGS -v $SIM_DIR:$SIM_DIR --name $SC_NUM"_rw_sim0" --network=$SC_NETNAME -w $SIM_BIN $DBOX ./nos3-single-simulator $SC_CFG_FILE generic-reactionwheel-sim0 + gnome-terminal --tab --title=$SC_NUM" - RW 1 Sim" -- $DFLAGS -v $SIM_DIR:$SIM_DIR --name $SC_NUM"_rw_sim1" --network=$SC_NETNAME -w $SIM_BIN $DBOX ./nos3-single-simulator $SC_CFG_FILE generic-reactionwheel-sim1 + gnome-terminal --tab --title=$SC_NUM" - RW 2 Sim" -- $DFLAGS -v $SIM_DIR:$SIM_DIR --name $SC_NUM"_rw_sim2" --network=$SC_NETNAME -w $SIM_BIN $DBOX ./nos3-single-simulator $SC_CFG_FILE generic-reactionwheel-sim2 + + gnome-terminal --tab --title=$SC_NUM" - Radio Sim" -- $DFLAGS -v $SIM_DIR:$SIM_DIR --name $SC_NUM"_radio_sim" -h radio_sim --network=$SC_NETNAME --network-alias=radio_sim -w $SIM_BIN $DBOX ./nos3-single-simulator $SC_CFG_FILE generic_radio_sim + + gnome-terminal --tab --title=$SC_NUM" - Sample Sim" -- $DFLAGS -v $SIM_DIR:$SIM_DIR --name $SC_NUM"_sample_sim" --network=$SC_NETNAME -w $SIM_BIN $DBOX ./nos3-single-simulator $SC_CFG_FILE sample_sim + gnome-terminal --tab --title=$SC_NUM" - StarTrk Sim" -- $DFLAGS -v $SIM_DIR:$SIM_DIR --name $SC_NUM"_startrk_sim" --network=$SC_NETNAME -w $SIM_BIN $DBOX ./nos3-single-simulator $SC_CFG_FILE generic_star_tracker_sim + gnome-terminal --tab --title=$SC_NUM" - Torquer Sim" -- $DFLAGS -v $SIM_DIR:$SIM_DIR --name $SC_NUM"_torquer_sim" --network=$SC_NETNAME -w $SIM_BIN $DBOX ./nos3-single-simulator $SC_CFG_FILE generic_torquer_sim + echo "" +done + +echo "NOS Time Driver..." +sleep 8 +gnome-terminal --tab --title="NOS Time Driver" -- $DFLAGS -v $SIM_DIR:$SIM_DIR --name nos_time_driver --network=nos3_core -w $SIM_BIN $DBOX ./nos3-single-simulator $GND_CFG_FILE time +sleep 1 +for (( i=1; i<=$SATNUM; i++ )) +do + export SC_NUM="sc_"$i + export SC_NETNAME="nos3_"$SC_NUM + export TIMENAME=$SC_NUM"_nos_time_driver" + $DNETWORK connect --alias nos_time_driver $SC_NETNAME nos_time_driver +done +echo "" + +echo "Docker launch script completed!" \ No newline at end of file diff --git a/scripts/configure.py b/scripts/configure.py index f5090b84..3e3d5e42 100755 --- a/scripts/configure.py +++ b/scripts/configure.py @@ -27,12 +27,14 @@ os.system('cp ./scripts/fsw_fprime_build.sh ./cfg/build/fsw_build.sh') os.system('cp ./scripts/fsw_fprime_launch.sh ./cfg/build/fsw_launch.sh') os.system('cp ./scripts/fprime.sh ./scripts/docker_launch.sh') + os.system('cp ./scripts/fprime_build_fsw.sh ./scripts/docker_build_fsw.sh') if (fsw_cfg == 'cfs'): fsw_identified = 1 # os.system('cp ./scripts/fsw_fprime_build.sh ./cfg/build/fsw_build.sh') # os.system('cp ./scripts/fsw_fprime_launch.sh ./cfg/build/fsw_launch.sh') os.system('cp ./scripts/cfs_cosmos.sh ./scripts/docker_launch.sh') + os.system('cp ./scripts/cfs_build_fsw.sh ./scripts/docker_build_fsw.sh') if (fsw_identified == 0): print('Invalid FSW in configuration file!') @@ -53,6 +55,8 @@ if (gsw_cfg == 'cosmos'): # Copy cosmos scripts into ./cfg/build gsw_identified = 1 + os.system('cp ./scripts/gsw_cosmos_build.sh ./cfg/build/gsw_build.sh') + os.system('cp ./scripts/gsw_cosmos_launch.sh ./cfg/build/gsw_launch.sh') if (gsw_cfg == 'fprime'): gsw_identified = 1 os.system('cp ./scripts/gsw_fprime_build.sh ./cfg/build/gsw_build.sh') diff --git a/scripts/docker_build_fsw.sh b/scripts/docker_build_fsw.sh index 0c29df0a..94b16bee 100755 --- a/scripts/docker_build_fsw.sh +++ b/scripts/docker_build_fsw.sh @@ -28,4 +28,4 @@ fi mkdir -p $BASE_DIR/fsw/build # Build -$DFLAGS_CPUS -v $BASE_DIR:$BASE_DIR --name "nos_build_fsw" -w $BASE_DIR $DBOX make -j$NUM_CPUS build-fsw +$DFLAGS_CPUS -v $BASE_DIR:$BASE_DIR --name "nos_build_fsw" -w $BASE_DIR $DBOX make -j$NUM_CPUS -e FLIGHT_SOFTWARE=fprime build-fsw diff --git a/scripts/docker_debug.sh b/scripts/docker_debug.sh index 8b153c0d..ab24d8b6 100755 --- a/scripts/docker_debug.sh +++ b/scripts/docker_debug.sh @@ -10,7 +10,8 @@ source $SCRIPT_DIR/env.sh mkdir -p $BASE_DIR/fsw/build # $DFLAGS_CPUS -v $BASE_DIR:$BASE_DIR -v $USER_NOS3_DIR:$USER_NOS3_DIR -w $BASE_DIR --name "nos3_debug" $DBOX bash -$DFLAGS_CPUS -it -v $BASE_DIR:$BASE_DIR --network nos3_sc_1 -p 5000:5000 -p 50000:50000 -p 5001:5001 -v $USERDIR:$USERDIR -w $BASE_DIR --name "nos3_debug" $DBOX bash +# $DFLAGS_CPUS -it -v $BASE_DIR:$BASE_DIR --network nos3_sc_1 -p 5000:5000 -p 50000:50000 -p 5001:5001 -v $USERDIR:$USERDIR -w $BASE_DIR --name "nos3_debug" $DBOX bash +$DFLAGS_CPUS -it -v $BASE_DIR:$BASE_DIR -p 5000:5000 -p 50000:50000 -p 5001:5001 -v $USERDIR:$USERDIR -w $BASE_DIR --name "nos3_debug" $DBOX bash # $DFLAGS_CPUS -v $BASE_DIR:$BASE_DIR --network host -v $USERDIR:$USERDIR -w $BASE_DIR --name "nos3_debug" $DBOX bash # $DFLAGS_CPUS -v $BASE_DIR:$BASE_DIR --expose 5000 -v $USERDIR:$USERDIR -w $BASE_DIR --name "nos3_debug" $DBOX bash # $DFLAGS_CPUS -v $BASE_DIR:$BASE_DIR -p 5000:5000 -v $USERDIR:$USERDIR -w $BASE_DIR --name "nos3_debug" $DBOX bash \ No newline at end of file diff --git a/scripts/env.sh b/scripts/env.sh index 4dce7cef..e1c7a799 100755 --- a/scripts/env.sh +++ b/scripts/env.sh @@ -10,6 +10,7 @@ GSW_BIN=$BASE_DIR/gsw/cosmos/build/openc3-cosmos-nos3 GSW_DIR=$BASE_DIR/gsw/cosmos SIM_DIR=$BASE_DIR/sims/build SIM_BIN=$SIM_DIR/bin +FLIGHT_SOFTWARE=fprime if [ -d $SIM_DIR/bin ]; then SIMS=$(ls $SIM_BIN/nos3*simulator) @@ -41,7 +42,8 @@ OPENC3_PATH=$OPENC3_DIR/openc3.sh DNETWORK="docker network" #fi -DBOX="ivvitc/nos3-64:20240618" +# DBOX="ivvitc/nos3-64:20240618" +DBOX="ivvitc/nos3-64:dev" # DBOX="ivvitc/nos3-64:fprime" # Debugging diff --git a/scripts/fprime_build_fsw.sh b/scripts/fprime_build_fsw.sh new file mode 100755 index 00000000..94b16bee --- /dev/null +++ b/scripts/fprime_build_fsw.sh @@ -0,0 +1,31 @@ +#!/bin/bash -i +# +# Convenience script for NOS3 development +# Use with the Dockerfile in the deployment repository +# https://github.com/nasa-itc/deployment +# + +SCRIPT_DIR=$( cd -- "$( dirname -- "${BASH_SOURCE[0]}" )" &> /dev/null && pwd ) +source $SCRIPT_DIR/env.sh + +# Check that local NOS3 directory exists +if [ ! -d $USER_NOS3_DIR ]; then + echo "" + echo " Need to run make prep first!" + echo "" + exit 1 +fi + +# Check that configure build directory exists +if [ ! -d $BASE_DIR/cfg/build ]; then + echo "" + echo " Need to run make config first!" + echo "" + exit 1 +fi + +# Make flight software build directory +mkdir -p $BASE_DIR/fsw/build + +# Build +$DFLAGS_CPUS -v $BASE_DIR:$BASE_DIR --name "nos_build_fsw" -w $BASE_DIR $DBOX make -j$NUM_CPUS -e FLIGHT_SOFTWARE=fprime build-fsw