File: kr01.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 (88 lines) | stat: -rw-r--r-- 1,731 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
#!/usr/bin/env python3
# -*- coding: utf-8 -*-

# Copyright 2017,2019 Daniel Estevez <daniel@destevez.net>
#
# This file is part of gr-satellites
#
# SPDX-License-Identifier: GPL-3.0-or-later
#

from construct import *


Mode = Enum(
    Int8ub,
    Otherwise=0,
    MissionMode=1,
    )


class BatVoltageAdapter(Adapter):
    def _encode(self, obj, context, path=None):
        return int((obj - 3.0) * 20.0)

    def _decode(self, obj, context, path=None):
        return obj / 20.0 + 3.0


BatVoltage = BatVoltageAdapter(Int8ub)


class BatCurrentAdapter(Adapter):
    def _encode(self, obj, context, path=None):
        return int((obj + 1.0) * 127.0)

    def _decode(self, obj, context, path=None):
        return obj / 127.0 - 1.0


BatCurrent = BatCurrentAdapter(Int8ub)


class BusCurrentAdapter(Adapter):
    def _encode(self, obj, context, path=None):
        return int(obj * 40.0)

    def _decode(self, obj, context, path=None):
        return obj / 40.0


BusCurrent = BusCurrentAdapter(Int8ub)


class TempAdapter(Adapter):
    def _encode(self, obj, context, path=None):
        return int((obj + 15.0) * 4.0)

    def _decode(self, obj, context, path=None):
        return obj / 4.0 - 15.0


Temp = TempAdapter(Int8ub)

SpacecraftMode = Enum(
    Int8ub,
    GndDebug=0,
    Initial=1,
    Commissioning=2,
    Mission=3,
    Comm=4,
    Powersafe=17,
    Detumble=18,
    Debug=19,
    Standby=32,
    )

kr01 = Struct(
    'header' / Bytes(0x23),
    'mode' / Mode,
    'batvoltage' / BatVoltage,
    'batcurrent' / BatCurrent,
    '3v3buscurrent' / BusCurrent,
    '5vbuscurrent' / BusCurrent,
    'tempcomm' / Temp,
    'tempeps' / Temp,
    'tempbattery' / Temp,
    'spacecraftmode' / SpacecraftMode
    )