Skip to content

Commit a4a2b10

Browse files
committed
implement tmux and split gs cli
1 parent a0d78fb commit a4a2b10

File tree

10 files changed

+133
-13
lines changed

10 files changed

+133
-13
lines changed

.tmux.conf

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
set -g mouse on
2+
set -g pane-border-status top
3+
4+
select-pane -t 0 -T "logs"
5+
select-pane -t 1 -T "gs_cli"
6+
7+
set -g pane-border-format "#P: #{pane_title}"

CMakeLists.txt

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ if(${CMAKE_BUILD_TYPE} MATCHES OBC)
88
endif()
99
set(CMAKE_TOOLCHAIN_FILE ${CMAKE_SOURCE_DIR}/cmake/toolchain_arm_none_eabi.cmake)
1010
elseif(${CMAKE_BUILD_TYPE} MATCHES GS)
11-
set(CMAKE_TOOLCHAIN_FILE ${CMAKE_SOURCE_DIR}/cmake/toolchain_ground_station_gcc.cmake)
11+
#set(CMAKE_TOOLCHAIN_FILE ${CMAKE_SOURCE_DIR}/cmake/toolchain_ground_station_gcc.cmake)
1212
elseif(${CMAKE_BUILD_TYPE} MATCHES HIL)
1313
include(${CMAKE_SOURCE_DIR}/cmake/fetch_googletest.cmake)
1414
set(CMAKE_TOOLCHAIN_FILE ${CMAKE_SOURCE_DIR}/cmake/toolchain_hil_gcc.cmake)
@@ -63,4 +63,4 @@ endif()
6363
add_subdirectory(libs)
6464

6565
# Build interface libs
66-
add_subdirectory(interfaces)
66+
add_subdirectory(interfaces)

README.md

Lines changed: 62 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -167,7 +167,68 @@ Take a look at `cmake/fw_build_options.cmake` to see the available build options
167167

168168
#### **Ground Station**
169169

170-
From the top-level directory, run the following to build the ground station. Currently, the ground station is only supported on Windows.
170+
From the top-level directory, run the following to build the ground station. Currently, the ground station has only been supported for Windows and may be subject to bugs on MacOS. If on a Linux or Windows system, skip the MacOS instructions.
171+
172+
<b>For MacOS users only</b>:\
173+
First, add the following to the top of file `./obc/CMakeLists.txt`, and should be placed as shown:
174+
```
175+
...
176+
cmake_minimum_required(VERSION 3.15)
177+
178+
# Add the following 4 lines
179+
if(APPLE)
180+
find_library(COREFOUNDATION CoreFoundation)
181+
find_library(IOKIT IOKit)
182+
endif()
183+
...
184+
```
185+
186+
Next, add the following to the file `./gs/backend/CMakeLists.txt` positioned as below:
187+
```
188+
...
189+
target_compile_options(gs.out PUBLIC -Wall -g)
190+
191+
# Add the following 6 lines
192+
if(APPLE)
193+
target_link_libraries(gs.out PUBLIC
194+
"-framework CoreFoundation"
195+
"-framework IOKit"
196+
)
197+
endif()
198+
...
199+
```
200+
201+
Next, comment out line in `./CMakeLists.txt` like as shown:
202+
```
203+
...
204+
#set(CMAKE_TOOLCHAIN_FILE ${CMAKE_SOURCE_DIR}/cmake/toolchain_ground_station_gcc.cmake)
205+
...
206+
```
207+
208+
Next, open `./gs/backend/main.c` and add and remove the following headers:
209+
```.c
210+
...
211+
<malloc.h> # Remove
212+
...
213+
<CoreFoundation/CoreFoundation.h> # Add
214+
...
215+
```
216+
217+
Next, open `./gs/interfaces/obc_gs_interface/__init__.py` and change the end of the path extension to `.dylib`, as shown:
218+
```py
219+
...
220+
path = (Path(__file__).parent / "../../build_gs/interfaces/libobc-gs-interface.dylib").resolve()
221+
# originally ...interface.so, change to ...interface.dylib
222+
...
223+
```
224+
225+
Lastly, run the following in the terminal:
226+
```sh
227+
pip install -e .
228+
```
229+
<b>End of MacOS instructions. Continue with the last step below.</b>
230+
231+
Then, run the following in the terminal from the top-level directory:
171232

172233
```sh
173234
mkdir -p build_gs && cd build_gs

gs/backend/CMakeLists.txt

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,13 @@ target_include_directories(gs.out PUBLIC
1212
${CMAKE_CURRENT_SOURCE_DIR}/serial_utils
1313
)
1414

15+
if(APPLE)
16+
target_link_libraries(gs.out PUBLIC
17+
"-framework CoreFoundation"
18+
"-framework IOKit"
19+
)
20+
endif()
21+
1522
target_compile_options(gs.out PUBLIC -Wall -g)
1623

1724
if(UNIX)
@@ -20,13 +27,13 @@ if(UNIX)
2027
lib-correct
2128
obc-gs-interface
2229
CSerialPort
23-
)
30+
)
2431
elseif(WIN32)
2532
target_link_libraries(gs.out PUBLIC
2633
tiny-aes
2734
lib-correct
2835
obc-gs-interface
2936
CSerialPort
3037
setupapi
31-
)
32-
endif()
38+
)
39+
endif()

gs/backend/ground_station_cli.py

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@ def __init__(self, com_port: str) -> None:
3333
██║ ██║██║███╗██║ ██║ ██║██╔══██╗██╔══██╗██║ ██║ ██╔══██║██║
3434
╚██████╔╝╚███╔███╔╝ ╚██████╔╝██║ ██║██████╔╝██║ ██║ ██║ ██║███████╗
3535
╚═════╝ ╚══╝╚══╝ ╚═════╝ ╚═╝ ╚═╝╚═════╝ ╚═╝ ╚═╝ ╚═╝ ╚═╝╚══════╝
36-
Welcome to the UW Orbital Command Line Inteface! Type help or ? to list commands.\n
36+
Welcome to the UW Orbital Command Line Interface! Type help or ? to list commands.\n
3737
"""
3838
prompt = "(UW Orbital): "
3939
file = None
@@ -133,8 +133,10 @@ def do_print_logs(self, line: str) -> None:
133133
"""
134134
# Preliminary checks for the function to run
135135
# Write out the logs that we previously got
136-
with open(LOG_PATH) as file:
137-
print(file.read())
136+
137+
# Commented out as it is displayed in the left pane
138+
# with open(LOG_PATH) as file:
139+
# print(file.read())
138140

139141
if self.background_logging is not None:
140142
self.background_logging.kill()

gs/backend/main.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,11 +12,11 @@
1212
#include <aes.h>
1313
#include <cserialport.h>
1414

15-
#include <malloc.h>
1615
#include <stdint.h>
1716
#include <stdio.h>
1817
#include <stdlib.h>
1918
#include <string.h>
19+
#include <CoreFoundation/CoreFoundation.h>
2020
#include <time.h>
2121

2222
const uint8_t TEMP_STATIC_KEY[AES_KEY_SIZE] = {0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07,

gs/backend/obc_utils/command_utils.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -366,5 +366,5 @@ def poll(com_port: str, file_path: str | Path, timeout: int = 0, print_console:
366366

367367
file.write(data_string)
368368
file.flush()
369-
if print_console and len(data_string) != 0:
370-
print(data_string)
369+
# if print_console and len(data_string) != 0:
370+
# # print(data_string)

gs/backend/tmux_cli.py

Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
import libtmux
2+
import time
3+
from libtmux.constants import PaneDirection
4+
from sys import argv
5+
6+
def main() -> None:
7+
if len(argv) != 2:
8+
print("One argument needed: Com Port")
9+
return
10+
11+
com_port = str(argv[1])
12+
server = libtmux.Server()
13+
if server.has_session("gs_cli"):
14+
server.kill_session("gs_cli")
15+
16+
# Does not attach the new session right away through attach parameter
17+
session = server.new_session(session_name="gs_cli", attach=False)
18+
window = session.active_window
19+
20+
pane1 = window.active_pane
21+
pane2 = window.split(attach=True, direction=PaneDirection.Right, size=80)
22+
23+
# Initialize gs cli
24+
pane2.send_keys(f"source .venv/bin/activate && tmux source-file .tmux.conf && python3.11 gs/backend/ground_station_cli.py {com_port}")
25+
26+
# Sleep to allow appropriate time for cli setup
27+
time.sleep(1.5)
28+
29+
# Enable logs pane
30+
pane1.send_keys(f"tail -f gs/backend/logs.log")
31+
32+
# Display tmux cli
33+
session.attach()
34+
35+
36+
37+
if __name__ == "__main__":
38+
main()

interfaces/obc_gs_interface/__init__.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,5 +2,5 @@
22
from pathlib import Path
33

44
# The shared object file we are using the access the c functions via ctypes
5-
path = (Path(__file__).parent / "../../build_gs/interfaces/libobc-gs-interface.so").resolve()
5+
path = (Path(__file__).parent / "../../build_gs/interfaces/libobc-gs-interface.dylib").resolve()
66
interface = CDLL(str(path))

obc/CMakeLists.txt

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,10 @@
11
cmake_minimum_required(VERSION 3.15)
22

3+
if(APPLE)
4+
find_library(COREFOUNDATION CoreFoundation)
5+
find_library(IOKIT IOKit)
6+
endif()
7+
38
# Set default values for firmware build options
49
include(${CMAKE_SOURCE_DIR}/cmake/obc_build_options.cmake)
510

0 commit comments

Comments
 (0)