Skip to content

Commit

Permalink
Merge pull request #6 from oresat/beacon-config-rework
Browse files Browse the repository at this point in the history
Beacon config rework
  • Loading branch information
ryanpdx authored Nov 12, 2023
2 parents 1910eda + 7f54fe7 commit d3e4ba7
Show file tree
Hide file tree
Showing 14 changed files with 203 additions and 59 deletions.
2 changes: 1 addition & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -167,4 +167,4 @@ cython_debug/
OD.*

# generated docs
docs/gen/
**/gen/*.rst
8 changes: 8 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,14 @@ transfers.
- The `c3.yaml` file also defines what objects have their values periodically
saved to the C3's F-RAM chip.

## Setup

Install project dev dependencies.

```bash
$ pip install -r requirements.txt
```

## Updating a Config

After updating configs for card(s), run the unit tests to validate all the
Expand Down
34 changes: 0 additions & 34 deletions docs/beacon.rst

This file was deleted.

4 changes: 3 additions & 1 deletion docs/index.rst
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,9 @@ Welcome to OreSat Configs documentation!
.. toctree::
:maxdepth: 2

beacon
oresat0/index
oresat0_5/index
oresat1/index


Indices and tables
Expand Down
7 changes: 7 additions & 0 deletions docs/oresat0/index.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
OreSat0 Configs
===============

.. toctree::
:maxdepth: 2

gen/beacon
7 changes: 7 additions & 0 deletions docs/oresat0_5/index.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
OreSat0.5 Configs
=================

.. toctree::
:maxdepth: 2

gen/beacon
7 changes: 7 additions & 0 deletions docs/oresat1/index.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
OreSat1 Configs
===============

.. toctree::
:maxdepth: 2

gen/beacon
131 changes: 114 additions & 17 deletions docs/scripts/gen_beacon_rst.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,15 @@

import os
import sys
from pathlib import Path

_FILE_PATH = os.path.dirname(os.path.abspath(__file__ + "/../.."))
sys.path.insert(0, _FILE_PATH)

import bitstring
import canopen

from oresat_configs import ORESAT_NICE_NAMES, OreSatConfig, OreSatId
from oresat_configs import NodeId, OreSatConfig, OreSatId

OD_DATA_TYPES = {
canopen.objectdictionary.BOOLEAN: "bool",
Expand All @@ -23,30 +25,121 @@
canopen.objectdictionary.REAL32: "float32",
canopen.objectdictionary.REAL64: "float64",
canopen.objectdictionary.VISIBLE_STRING: "str",
canopen.objectdictionary.OCTET_STRING: "octect_str",
canopen.objectdictionary.OCTET_STRING: "octet_str",
canopen.objectdictionary.DOMAIN: "domain",
}
"""Nice names for CANopen data types."""


def gen_beacon_rst(config: OreSatConfig, file_path: str):
def gen_beacon_rst(config: OreSatConfig, file_path: str, url: str):
"""Genetate a rst file for a beacon definition."""

title = f"{ORESAT_NICE_NAMES[config.oresat_id]} Beacon Definition"
title = "Beacon Definition"
header_title = "AX.25 Header"
lines = [
f"{title}\n",
f'{"=" * len(title)}\n',
"\n",
".. csv-table::\n",
' :header: "Offset", "Card", "Data Name", "Data Type", "Size", "Description"\n',
f"YAML configuration file that defines this beacon can be found at: {url}\n",
"\n",
f"{header_title}\n",
f'{"-" * len(header_title)}\n',
"\n",
]

c3_od = config.od_db[NodeId.C3]
src_callsign = c3_od["beacon"]["src_callsign"].value
src_callsign = src_callsign + " " * (6 - len(src_callsign))
src_ssid = c3_od["beacon"]["src_ssid"].value
dest_callsign = c3_od["beacon"]["dest_callsign"].value
dest_callsign = dest_callsign + " " * (6 - len(dest_callsign))
dest_ssid = c3_od["beacon"]["dest_ssid"].value
command = c3_od["beacon"]["command"].value
response = c3_od["beacon"]["response"].value
control = c3_od["beacon"]["control"].value
pid = c3_od["beacon"]["pid"].value

reserved_bits = 0b0110_0000
end_of_addresses = 0b1

dest_ssid = (dest_ssid << 1) | (int(command) << 7) | reserved_bits
src_ssid = (src_ssid << 1) | (int(response) << 7) | reserved_bits | end_of_addresses

header_line = (
"+------------------+-----------------------------------+-----------+---------------------"
"--------------+-----------+---------+-----+\n"
)
lines.append(header_line)
lines.append(
"| | Dest Callsign | Dest SSID | Src Callsign "
" | Src SSID | Control | PID |\n"
)
header_line = (
"+==================+=====+=====+=====+=====+=====+=====+===========+=====+=====+=====+==="
"==+=====+=====+===========+=========+=====+\n"
)
lines.append(header_line)
header_line = header_line.replace("=", "-")
lines.append(
f'| Value | "{dest_callsign[0]}" | "{dest_callsign[1]}" | "{dest_callsign[2]}" |'
f' "{dest_callsign[3]}" | "{dest_callsign[4]}" | "{dest_callsign[5]}" | {dest_ssid:02X} '
f' | "{src_callsign[0]}" | "{src_callsign[1]}" | "{src_callsign[2]}" | '
f'"{src_callsign[3]}" | "{src_callsign[4]}" | "{src_callsign[5]}" | {src_ssid:02X} '
f" | {control:02X} | {pid:02X} |\n"
)
sd = (
dest_callsign.encode()
+ dest_ssid.to_bytes(1, "little")
+ src_callsign.encode()
+ src_ssid.to_bytes(1, "little")
+ control.to_bytes(1, "little")
+ pid.to_bytes(1, "little")
)
lines.append(header_line)
lines.append(
f"| Hex | {sd[0]:02X} | {sd[1]:02X} | {sd[2]:02X} | {sd[3]:02X} | "
f"{sd[4]:02X} | {sd[5]:02X} | {sd[6]:02X} | {sd[7]:02X} | {sd[8]:02X} |"
f" {sd[9]:02X} | {sd[10]:02X} | {sd[11]:02X} | {sd[12]:02X} | {sd[13]:02X} | "
f"{sd[14]:02X} | {sd[15]:02X} |\n"
)
sd = (
(bitstring.BitArray(dest_callsign.encode()) << 1).bytes
+ dest_ssid.to_bytes(1, "little")
+ (bitstring.BitArray(src_callsign.encode()) << 1).bytes
+ src_ssid.to_bytes(1, "little")
+ control.to_bytes(1, "little")
+ pid.to_bytes(1, "little")
)
lines.append(header_line)
lines.append(
f"| Hex (bitshifted) | {sd[0]:02X} | {sd[1]:02X} | {sd[2]:02X} | {sd[3]:02X} | "
f"{sd[4]:02X} | {sd[5]:02X} | {sd[6]:02X} | {sd[7]:02X} | {sd[8]:02X} |"
f" {sd[9]:02X} | {sd[10]:02X} | {sd[11]:02X} | {sd[12]:02X} | {sd[13]:02X} | "
f"{sd[14]:02X} | {sd[15]:02X} |\n"
)
lines.append(header_line)
lines.append(
"| Offset | 0 | 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10"
" | 11 | 12 | 13 | 14 | 15 |\n"
)
lines.append(header_line)
lines.append("\n")

lines.append("Total header length: 16 octets\n")
lines.append("\n")

def_title = "Packet"
lines.append(f"{def_title}\n")
lines.append(f'{"-" * len(def_title)}\n')
lines.append("\n")
lines.append(".. csv-table::\n")
lines.append(' :header: "Offset", "Card", "Data Name", "Data Type", "Size", "Description"\n')
lines.append("\n")
offset = 0
size = 16
desc = "\nax.25 packet header\n"
size = len(sd)
desc = "\nax.25 packet header (see above)\n"
desc = desc.replace("\n", "\n ")
lines.append(f' "{offset}", "c3", "ax25_header", "octect_str", "{size}", "{desc}"\n')
lines.append(f' "{offset}", "c3", "ax25_header", "octet_str", "{size}", "{desc}"\n')
offset += size

for obj in config.beacon_def:
Expand Down Expand Up @@ -78,13 +171,11 @@ def gen_beacon_rst(config: OreSatConfig, file_path: str):
offset += size

size = 4
desc = "\npacket checksum\n"
desc = desc.replace("\n", "\n ")
lines.append(f' "{offset}", "c3", "crc32", "uint32", "{size}", "{desc}"\n')
lines.append(f' "{offset}", "c3", "crc32", "uint32", "{size}", "packet checksum"\n')
offset += size

lines.append("\n")
lines.append(f"Total length: {offset}\n")
lines.append(f"Total packet length: {offset} octets\n")

dir_path = os.path.dirname(file_path)
if not os.path.exists(dir_path):
Expand All @@ -97,7 +188,13 @@ def gen_beacon_rst(config: OreSatConfig, file_path: str):
def gen_beacon_rst_files():
"""Generate all beacon rst files."""

file_path = os.path.dirname(os.path.abspath(__file__ + "/..")) + "/gen"
gen_beacon_rst(OreSatConfig(OreSatId.ORESAT0), f"{file_path}/oresat0_beacon.rst")
gen_beacon_rst(OreSatConfig(OreSatId.ORESAT0_5), f"{file_path}/oresat0_5_beacon.rst")
gen_beacon_rst(OreSatConfig(OreSatId.ORESAT1), f"{file_path}/oresat1_beacon.rst")
parent_dir = os.path.dirname(os.path.abspath(__file__ + "/.."))
for mission in list(OreSatId):
mission_name = mission.name.lower()
url = (
f"https://github.com/oresat/oresat-configs/blob/master/oresat_configs/{mission_name}"
"/beacon.yaml"
)
file_path = f"{parent_dir}/{mission_name}/gen"
Path(file_path).mkdir(parents=True, exist_ok=True)
gen_beacon_rst(OreSatConfig(mission), f"{file_path}/beacon.rst", url)
8 changes: 8 additions & 0 deletions oresat_configs/_yaml_to_od.py
Original file line number Diff line number Diff line change
Expand Up @@ -670,6 +670,14 @@ def _gen_od_db(oresat_id: OreSatId, beacon_def: dict, configs: dict) -> dict:
od["satellite_id"].default = oresat_id.value
if node_id == NodeId.C3:
od["beacon"]["revision"].default = beacon_def["revision"]
od["beacon"]["dest_callsign"].default = beacon_def["ax25"]["dest_callsign"]
od["beacon"]["dest_ssid"].default = beacon_def["ax25"]["dest_ssid"]
od["beacon"]["src_callsign"].default = beacon_def["ax25"]["src_callsign"]
od["beacon"]["src_ssid"].default = beacon_def["ax25"]["src_ssid"]
od["beacon"]["control"].default = beacon_def["ax25"]["control"]
od["beacon"]["command"].default = beacon_def["ax25"]["command"]
od["beacon"]["response"].default = beacon_def["ax25"]["response"]
od["beacon"]["pid"].default = beacon_def["ax25"]["pid"]
od["flight_mode"].access_type = "ro"

od_db[node_id] = od
Expand Down
26 changes: 20 additions & 6 deletions oresat_configs/base/c3.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -364,14 +364,14 @@ objects:
data_type: str
description: the ax.25 header source callsign
access_type: const
default: "KJ7SAT"
# default set via beacon.yaml file

- subindex: 0x3
name: dest_callsign
data_type: str
description: the ax.25 header destination callsign
access_type: const
default: "SPACE"
# default set via beacon.yaml file

- subindex: 0x4
name: start_chars
Expand Down Expand Up @@ -404,28 +404,42 @@ objects:
data_type: uint8
description: the ax.25 header source ssid
access_type: const
default: 11 # balloons, aircraft, spacecraft, etc
# default set via beacon.yaml file

- subindex: 0x9
name: dest_ssid
data_type: uint8
description: the ax.25 header destination ssid
access_type: const
default: 0 # primary station
# default set via beacon.yaml file

- subindex: 0xa
name: control
data_type: uint8
description: the ax.25 header control field
access_type: const
default: 0x3 # ui-frame
# default set via beacon.yaml file

- subindex: 0xb
name: pid
data_type: uint8
description: the ax.25 header pid (protocol identifier) field
access_type: const
default: 0xf0 # no L3 protocol
# default set via beacon.yaml file

- subindex: 0xc
name: command
data_type: bool
description: the ax.25 header destination c-bit value
access_type: const
# default set via beacon.yaml file

- subindex: 0xd
name: response
data_type: bool
description: the ax.25 header source c-bit value
access_type: const
# default set via beacon.yaml file

- index: 0x400b
name: rtc
Expand Down
9 changes: 9 additions & 0 deletions oresat_configs/oresat0/beacon.yaml
Original file line number Diff line number Diff line change
@@ -1,4 +1,13 @@
revision: 0
ax25:
dest_callsign: SPACE
dest_ssid: 0
src_callsign: KJ7SAT
src_ssid: 0
control: 0x3 # ui-frame
pid: 0xf0 # no L3 protocol
command: false
response: false
fields:
# c3
- [beacon, start_chars]
Expand Down
9 changes: 9 additions & 0 deletions oresat_configs/oresat0_5/beacon.yaml
Original file line number Diff line number Diff line change
@@ -1,4 +1,13 @@
revision: 0
ax25:
dest_callsign: SPACE
dest_ssid: 0 # primary station
src_callsign: KJ7SAT
src_ssid: 11 # balloons, aircraft, spacecraft, etc
control: 0x3 # ui-frame
pid: 0xf0 # no L3 protocol
command: false
response: true
fields:
# c3
- [beacon, start_chars]
Expand Down
9 changes: 9 additions & 0 deletions oresat_configs/oresat1/beacon.yaml
Original file line number Diff line number Diff line change
@@ -1,4 +1,13 @@
revision: 0
ax25:
dest_callsign: SPACE
dest_ssid: 0 # primary station
src_callsign: KJ7SAT
src_ssid: 11 # balloons, aircraft, spacecraft, etc
control: 0x3 # ui-frame
pid: 0xf0 # no L3 protocol
command: false
response: true
fields:
- [beacon, start_chars]
- [satellite_id]
Expand Down
1 change: 1 addition & 0 deletions requirements.txt
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
bitstring
black
build
canopen
Expand Down

0 comments on commit d3e4ba7

Please sign in to comment.