Skip to content

Commit 41943f4

Browse files
committed
Merge branch 'new-packet-format' of https://github.com/CarletonURocketry/ground-station into new-packet-format
2 parents 1fb3628 + 212fd5d commit 41943f4

File tree

6 files changed

+62
-57
lines changed

6 files changed

+62
-57
lines changed

Dockerfile

Lines changed: 6 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,28 +1,24 @@
11
# Python-slim base image
22
FROM python:3.11-slim
33

4-
MAINTAINER Jacob Terkuc
4+
LABEL MAINTAINER="Jacob Terkuc"
5+
LABEL MAINTAINER="Elias Hawa"
56

67
# Update and upgrade packages
78
RUN apt-get update && apt-get upgrade -y && pip install --upgrade pip
89

9-
# Install Virtual Env
10-
RUN pip install virtualenv
11-
1210
# Set the working directory in the container
1311
WORKDIR /app/ground-station
1412

1513
# Copy files
16-
COPY . .
17-
18-
# Set up VENV and "source"
19-
ENV VIRTUAL_ENV=/app/ground-station
20-
RUN python3 -m venv $VIRTUAL_ENV
21-
ENV PATH="$VIRTUAL_ENV/bin:$PATH"
14+
COPY requirements.txt .
2215

2316
# Install any needed packages specified in requirements.txt
2417
RUN pip install -r requirements.txt
2518

19+
# Copy files
20+
COPY . .
21+
2622
# Expose port 33845
2723
EXPOSE 33845/udp
2824

config.json

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -7,16 +7,16 @@
77
"frequency": 433050000,
88
"power": 15,
99
"spread_factor": 7,
10-
"coding_rate": "4/7",
11-
"bandwidth": 500,
10+
"coding_rate": "4/5",
11+
"bandwidth": 125,
1212
"preamble_len": 6,
1313
"cyclic_redundancy": true,
14-
"iqi": false,
15-
"sync_word": "0x43"
14+
"iqi": false
1615
},
1716
"approved_callsigns": {
1817
"VA3INI": "Matteo Golin",
1918
"VA3ZTA": "Darwin Jull",
20-
"VE3LWN": "Thomas Selwyn"
19+
"VE3LWN": "Thomas Selwyn",
20+
"VA3EHJ": "Elias Hawa"
2121
}
2222
}

modules/misc/config.py

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -66,7 +66,7 @@ class RadioParameters:
6666
preamble_len: int = 6
6767
cyclic_redundancy: bool = True
6868
iqi: bool = False
69-
sync_word: str = "0x43"
69+
# sync_word: str = "0x43"
7070

7171
def __post_init__(self):
7272
if self.frequency not in range(*LF_RANGE) and self.frequency not in range(*HF_RANGE):
@@ -83,9 +83,9 @@ def __post_init__(self):
8383
if self.preamble_len not in range(*PREAMBLE_RANGE):
8484
raise ValueError(f"Preamble length '{self.preamble_len}' not within allowed range of {PREAMBLE_RANGE}")
8585

86-
if int(self.sync_word, 16) not in range(*SYNC_RANGE):
87-
raise ValueError(f"Sync word '{self.sync_word}' not within allowed range of {SYNC_RANGE}")
88-
self.sync_word = self.sync_word[2:] # Remove 0x
86+
# if int(self.sync_word, 16) not in range(*SYNC_RANGE):
87+
# raise ValueError(f"Sync word '{self.sync_word}' not within allowed range of {SYNC_RANGE}")
88+
# self.sync_word = self.sync_word[2:] # Remove 0x
8989

9090
@classmethod
9191
def from_json(cls, data: JSON) -> Self:
@@ -103,7 +103,7 @@ def from_json(cls, data: JSON) -> Self:
103103
preamble_len=data.get("preamble_len", 6),
104104
cyclic_redundancy=data.get("cyclic_redundancy", True),
105105
iqi=data.get("iqi", False),
106-
sync_word=data.get("sync_word", "0x43"),
106+
# sync_word=data.get("sync_word", "0x43"),
107107
)
108108

109109
def __iter__(self):
@@ -116,7 +116,7 @@ def __iter__(self):
116116
yield "preamble_len", self.preamble_len
117117
yield "cyclic_redundancy", self.cyclic_redundancy
118118
yield "iqi", self.iqi
119-
yield "sync_word", self.sync_word
119+
# yield "sync_word", self.sync_word
120120

121121

122122
@dataclass

modules/serial/rn2483_radio.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@
3636
"preamble_len": "prlen",
3737
"cyclic_redundancy": "crc",
3838
"iqi": "iqi",
39-
"sync_word": "sync",
39+
# "sync_word": "sync",
4040
}
4141

4242

modules/telemetry/parsing_utils.py

Lines changed: 34 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -3,14 +3,16 @@
33
import logging
44

55

6-
from modules.telemetry.v1.block import (
7-
PacketHeader,
8-
BlockHeader,
9-
DeviceAddress,
10-
UnsupportedEncodingVersionError,
11-
InvalidHeaderFieldValueError,
12-
)
13-
import modules.telemetry.v1.data_block as v1db
6+
# from modules.telemetry.v1.block import (
7+
# PacketHeader,
8+
# BlockHeader,
9+
# DeviceAddress,
10+
# UnsupportedEncodingVersionError,
11+
# InvalidHeaderFieldValueError,
12+
# )
13+
# import modules.telemetry.v1.data_block as v1db
14+
15+
from modules.telemetry.v2.block import *
1416
from modules.misc.config import Config
1517

1618
MIN_SUPPORTED_VERSION: int = 1
@@ -54,48 +56,51 @@ def parse_rn2483_transmission(data: str, config: Config) -> Optional[ParsedTrans
5456

5557
# Catch unsupported encoding versions by skipping packet
5658
try:
57-
pkt_hdr = PacketHeader.from_hex(data[:32])
58-
except UnsupportedEncodingVersionError as e:
59+
pkt_hdr: PacketHeader = parse_packet_header(data[:PACKET_HEADER_LENGTH])
60+
except InvalidHeaderFieldValueError as e:
5961
logger.error(f"{e}, skipping packet")
6062
return
63+
64+
logger.info(pkt_hdr)
6165

6266
# We can keep unauthorized callsigns but we'll log them as warnings
6367
from_approved_callsign(pkt_hdr, config.approved_callsigns)
6468

65-
if len(pkt_hdr) <= 32: # If this packet nothing more than just the header
69+
if len(pkt_hdr) <= PACKET_HEADER_LENGTH: # If this packet nothing more than just the header
6670
logger.debug(f"{pkt_hdr}")
6771

68-
blocks = data[32:] # Remove the packet header
72+
blocks = data[PACKET_HEADER_LENGTH:] # Remove the packet header
6973

7074
# Parse through all blocks
7175
while blocks != "":
7276
# Parse block header
7377
logger.debug(f"Blocks: {blocks}")
74-
logger.debug(f"Block header: {blocks[:8]}")
78+
logger.debug(f"Block header: {blocks[:BLOCK_HEADER_LENGTH]}")
7579

7680
# Catch invalid block headers field values by skipping packet
7781
try:
78-
block_header = BlockHeader.from_hex(blocks[:8])
82+
block_header = parse_block_header(blocks[:BLOCK_HEADER_LENGTH])
7983
except InvalidHeaderFieldValueError as e:
8084
logger.error(f"{e}, skipping packet")
8185
return
86+
logger.info(block_header)
8287

8388
# Select block contents
84-
block_len = len(block_header) * 2 # Convert length in bytes to length in hex symbols
85-
block_contents = blocks[8:block_len]
86-
logger.debug(f"Block info: {block_header}")
87-
88-
# Check if message is destined for ground station for processing
89-
if block_header.destination in [DeviceAddress.GROUND_STATION, DeviceAddress.MULTICAST]:
90-
cur_block = parse_radio_block(pkt_hdr.version, block_header, block_contents)
91-
if cur_block:
92-
parsed_blocks.append(cur_block) # Append parsed block to list
93-
else:
94-
logger.warning("Invalid destination address")
95-
96-
# Remove the data we processed from the whole set, and move onto the next data block
97-
blocks = blocks[block_len:]
98-
return ParsedTransmission(pkt_hdr, parsed_blocks)
89+
# block_len = len(block_header) * 2 # Convert length in bytes to length in hex symbols
90+
# block_contents = blocks[8:block_len]
91+
# logger.debug(f"Block info: {block_header}")
92+
93+
# # Check if message is destined for ground station for processing
94+
# if block_header.destination in [DeviceAddress.GROUND_STATION, DeviceAddress.MULTICAST]:
95+
# cur_block = parse_radio_block(pkt_hdr.version, block_header, block_contents)
96+
# if cur_block:
97+
# parsed_blocks.append(cur_block) # Append parsed block to list
98+
# else:
99+
# logger.warning("Invalid destination address")
100+
101+
# # Remove the data we processed from the whole set, and move onto the next data block
102+
# blocks = blocks[block_len:]
103+
# return ParsedTransmission(pkt_hdr, parsed_blocks)
99104

100105

101106
def from_approved_callsign(pkt_hdr: PacketHeader, approved_callsigns: dict[str, str]) -> bool:

modules/telemetry/v2/block.py

Lines changed: 10 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,8 @@
99

1010
MIN_SUPPORTED_VERSION: int = 1
1111
MAX_SUPPORTED_VERSION: int = 1
12+
PACKET_HEADER_LENGTH: int = 26
13+
BLOCK_HEADER_LENGTH: int = 2
1214

1315
# Set up logging
1416
logger = logging.getLogger(__name__)
@@ -59,12 +61,14 @@ class BlockHeader:
5961

6062
#Parse packet header
6163
def parse_packet_header(header_bytes: bytes) -> PacketHeader:
62-
callsign_bytes = header_bytes[:9]
63-
callsign = ''
64-
for c in callsign_bytes:
65-
callsign += chr(c)
66-
timestamp, num_blocks, packet_num = struct.unpack("<HBB", header_bytes[9:])
67-
return PacketHeader(callsign, timestamp, num_blocks, packet_num)
64+
try:
65+
logger.info(header_bytes)
66+
callsign_bytes = header_bytes[:18]
67+
callsign = bytes.fromhex(callsign_bytes)
68+
timestamp, num_blocks, packet_num = struct.unpack("<HBB", bytes(header_bytes[18:]))
69+
return PacketHeader(callsign, timestamp, num_blocks, packet_num)
70+
except ValueError as e:
71+
raise InvalidHeaderFieldValueError(e)
6872

6973
#Parse block header
7074
def parse_block_header(header_bytes: bytes) -> BlockHeader:

0 commit comments

Comments
 (0)