File: fossasat_1b.py

package info (click to toggle)
gr-satellites 5.8.0-2
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 10,836 kB
  • sloc: python: 29,546; cpp: 5,448; ansic: 1,247; sh: 118; makefile: 24
file content (95 lines) | stat: -rw-r--r-- 3,072 bytes parent folder | download | duplicates (3)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
#!/usr/bin/env python3
# -*- coding: utf-8 -*-

# Copyright 2020 jgromes <gromes.jan@gmail.com>
#
# This file is part of gr-satellites
#
# SPDX-License-Identifier: GPL-3.0-or-later
#

from construct import *

from ..adapters import LinearAdapter
from .fossasat import (
    VoltageValue, CurrentValue, TempValue, FuncId,
    StatsCurrents, StatsVoltages, StatsTemperatures, Pong, RepeatedMessage,
    SystemInfo, PacketInfo, Statistics, StoreAndForwardAssigned,
    ForwardedMessage, CameraPicture, DeploymentState)


SystemInfo = Struct(
    'v_batt' / VoltageValue,
    'i_chrg' / CurrentValue,
    'v_chrg' / VoltageValue,
    'uptime' / Int32ul,
    'power_cfg' / Struct(
        Padding(3),
        'tx_enabled' / Flag,
        'mppt_keep_alive' / Flag,
        'mppt_temp_switch' / Flag,
        'lp_enabled' / Flag,
        'lp_active' / Flag,
        ),
    'reset_ctr' / Int16ul,
    'v_panel_a' / VoltageValue,
    'v_panel_b' / VoltageValue,
    'v_panel_c' / VoltageValue,
    'batt_temp' / TempValue,
    'obc_temp' / TempValue,
    'mcu_temp' / Int8sl,
    )

Statistics = Struct(
    'flags' / BitStruct(
        'has_obc_temp' / Flag,
        'has_batt_temp' / Flag,
        'has_v_panel_c' / Flag,
        'has_v_panel_b' / Flag,
        'has_v_panel_a' / Flag,
        'has_v_batt' / Flag,
        'has_i_chrg' / Flag,
        'has_v_chrg' / Flag,
        ),
    'stats' / Struct(
        'v_chrg' / Optional(If(this._.flags.has_v_chrg, StatsVoltages)),
        'i_chrg' / Optional(If(this._.flags.has_i_chrg, StatsCurrents)),
        'v_batt' / Optional(If(this._.flags.has_v_batt, StatsVoltages)),
        'v_panel_a' / Optional(If(this._.flags.has_v_panel_a, StatsVoltages)),
        'v_panel_b' / Optional(If(this._.flags.has_v_panel_b, StatsVoltages)),
        'v_panel_c' / Optional(If(this._.flags.has_v_panel_c, StatsVoltages)),
        'batt_temp' / Optional(If(this._.flags.has_batt_temp,
                                  StatsTemperatures)),
        'obc_temp' / Optional(If(this._.flags.has_obc_temp,
                                 StatsTemperatures)),
        ),
    )

RecordedSolarCells = Struct(
    'samples' / GreedyRange(
        Struct(
            'v_panel_a' / VoltageValue,
            'v_panel_b' / VoltageValue,
            'v_panel_c' / VoltageValue,
            )
        )
    )

fossasat_1b = Struct(
    'callsign' / Const(b"FOSSASAT-1B"),
    'func_id' / FuncId,
    'opt_data_len' / Optional(Int8ul),
    'payload' / Switch(this.func_id, {
        'RESP_PONG': Pong,
        'RESP_REPEATED_MESSAGE': RepeatedMessage,
        'RESP_REPEATED_MESSAGE_CUSTOM': RepeatedMessage,
        'RESP_SYSTEM_INFO': SystemInfo,
        'RESP_PACKET_INFO': PacketInfo,
        'RESP_STATISTICS': Statistics,
        'RESP_STORE_AND_FORWARD_ASSIGNED_SLOT': StoreAndForwardAssigned,
        'RESP_FORWARDED_MESSAGE': ForwardedMessage,
        'RESP_PUBLIC_PICTURE': CameraPicture,
        'RESP_DEPLOYMENT_STATE': DeploymentState,
        'RESP_RECORDED_SOLAR_CELLS': RecordedSolarCells,
        }, default=HexDump(GreedyBytes)),
    )