Esempio n. 1
0
def init(dir_name):
    """
    Initializes the spying
    """
    global SPY_REC
    global SPY_TRANS    
    global running
    global DIRNAME
    if running:
        return
    DIRNAME = str(dir_name).lstrip(os.sep)
    sub_dir = param_all.Pathing('~', ALL_TEL, DIRNAME)
    if sub_dir.exists:
        print("Directory '{}' already exists. Please change the name!"\
                                                        .format(sub_dir.path))
    else:
        os.mkdir(sub_dir.path)
        os.mkdir(param_all.Pathing(sub_dir, 'tm_data').path)
        SPY_TRANS = SpyTrans(port=param_all.SPYINGPORT[0],
                             nreceivermax=5,
                             start=True,
                             portname=param_all.SPYINGPORT[1],
                             timeoutACK=3)        
        SPY_REC = SpyRec(port=param_all.LISTENINGPORT[0],
                                name=param_all.SPYINGNAME, connect=True,
                                connectWait=0.5,
                                portname=param_all.LISTENINGPORT[1],
                                hostname = 'localhost')
        running = True
Esempio n. 2
0
def load_json_cmds(path):
    """
    Loads all the commands from the json file, given the path list
    """
    f = open(param_all.Pathing('param', *path).path, mode='r')
    allcmds = json.load(f)
    f.close()
    return allcmds
Esempio n. 3
0
def save_json_cmds(path, cmds):
    """
    Saves all the commands from the json file, given the path and
    the commands list
    """
    f = open(param_all.Pathing('param', *path).path, mode='w')
    json.dump(cmds, f)
    f.close()
Esempio n. 4
0
def process_data(data):
    """
    A callback function that saves the package and sends it
    over the TM socket
    """
    if len(data) == 0:
        return
    filename = os.path.split(str(data['path']))[1]
    local_path = os.path.join(DIRNAME, 'tm_data', filename)
    print("Spying: '{}' >> {}".format(data['data'].hex(), local_path))
    # locally saved
    f = open(param_all.Pathing('~', ALL_TEL, local_path).path, mode='wb')
    f.write(data['data'])
    f.close()
    SPY_TRANS.tell_dict(**data)
Esempio n. 5
0
def process_data(data):
    """
    A callback function that saves the package and sends it
    over the TM socket
    """
    if len(data) == 0:
        return
    now = core.now()
    name = now.strftime(param_all.TELEMETRYNAMEFORMAT)
    name = param_all.Pathing(param_all.TELEMETRYDUMPFOLDER, name)
    if name.isfile:  # already exists
        name.path += ".{}".format(len(glob.glob(name.path))+1)
    # locally saved
    f = open(name.path, mode='wb')
    f.write(data)
    f.close()
    # sends packets on the socket
    LISTEN_TRANS.tell_dict(t=now, path=name.path, data=data)
Esempio n. 6
0
    def generate(self, clean_tex=True):
        """
        Generates the document and saves it to disk

        Args:.path
          * clean_tex (bool): whether to delete the .tex file after
            compiling
        """
        HEADER = open(param_all.Pathing('ctrl', 'mgmt', 'header.tex').path,
                      mode='r').read()
        HEADER2 = open(param_all.Pathing('ctrl', 'mgmt', 'header-2.tex').path,
                       mode='r').read()
        doc = Document(self.docname)
        for k, v in REPL.items():
            HEADER = HEADER.replace(k, v)
            HEADER2 = HEADER2.replace(k, v)
        doc.preamble.append(NoEscape(HEADER))
        doc.append(NoEscape(HEADER2))
        section = Section('Principles')
        section.append(
            """The Telecommand (TC) and Telemetry (TM) packets format specifications are based on the CCSDS format: the concatenation of a primary header, secondary header, (optional) auxiliary header, (optional) data field.

TC are composed of a 6 octets primary header and a 18 octets secondary header. There is no auxiliary header. The data field contains values which depend on the command ID, that are treated by the satelite as input parameters.

TM are composed of a 6 octets primary header and a 6 octets secondary header. The TM category defines what type of TM is transmitted (e.g. beacon, house keeping) and how the auxiliary header and data field are encoded.

This document covers the content of headers for TC, and headers and data fields for TM.

This documents does not cover the content of data field for TC, and the content of auxiliary header and data fields for the TM category 'TC Answer'. This information is available in the dedicated TC-TM communication document."""
        )
        doc.append(section)
        # Telecommands
        section = Section('Telecommands')
        subsection = self._trousseau2subsection('Primary Header',
                                                param_ccsds.HEADER_P_KEYS)
        section.append(subsection)
        subsection = self._trousseau2subsection(
            'Secondary Header', param_ccsds.HEADER_S_KEYS_TELECOMMAND)
        section.append(subsection)
        subsection = self._TCauxHeader()
        section.append(subsection)
        doc.append(section)
        # Telemetries
        section = Section('Telemetries')
        subsection = self._trousseau2subsection('Primary Header',
                                                param_ccsds.HEADER_P_KEYS)
        section.append(subsection)
        subsection = self._trousseau2subsection(
            'Secondary Header', param_ccsds.HEADER_S_KEYS_TELEMETRY)
        section.append(subsection)
        subsection = self._TMauxHeader()
        section.append(subsection)
        doc.append(section)
        # Packet Categories
        sectionname = {
            0: 'Packet Categories for OBC',
            1: 'Packet Categories for Payload'
        }
        for idx, pldflag in ([0, False], [1, True]):
            section = Section(sectionname[idx])
            for catnum, cat in param_category.\
                                    CATEGORIES[idx].items():
                subsection = self._trousseau2subsection(
                    '{} ({:d}) - Auxiliary Header'.format(cat.name, catnum),
                    cat.aux_trousseau,
                    catnum=catnum,
                    pldflag=pldflag)
                section.append(subsection)
                # case of TC answer, dedicated doc
                if catnum == param_category.TELECOMMANDANSWERCAT:
                    subsection = Subsection('{} ({:d}) - Data'\
                                                .format(cat.name, catnum))
                    subsection.append("Refer to the dedicated TC-TM "\
                                      "communication document")
                    section.append(subsection)
                # case of meta-trousseau
                elif isinstance(cat.data_trousseau, CCSDSMetaTrousseau):
                    for mtpart, mtT in cat.data_trousseau.TROUSSEAUDIC.items():
                        subsection = self._trousseau2subsection(
                            '{} ({:d}) [part {:d}] - Data'.format(
                                cat.name, catnum, mtpart),
                            mtT,
                            catnum=catnum,
                            pldflag=pldflag)
                        section.append(subsection)
                else:  # normal case
                    subsection = self._trousseau2subsection(
                        '{} ({:d}) - Data'.format(cat.name, catnum),
                        cat.data_trousseau,
                        catnum=catnum,
                        pldflag=pldflag)
                    section.append(subsection)
            doc.append(section)
        self._compile(doc, clean_tex=clean_tex)
Esempio n. 7
0
from pylatex.utils import italic
from nanoparam import param_all_processed as param_all
from nanoparam import param_ccsds
from nanoparam.categories import param_category
from nanoutils.ccsds import CCSDSMetaTrousseau
import os
import re

__all__ = ['DocComm']

DOCNAME = "PICSAT-COMM-SPEC-01"
REPL = {
    "<!SHORTTITLE!>": 'PicSat Comm. Spec.',
    "<!VERSION!>": '1.0',
    "<!STITLE!>": 'PicSat Communication Specifications',
    "<!PATH!>": param_all.Pathing('ctrl', 'mgmt').path,
    "<!REF!>": DOCNAME
}


class DocComm(object):
    def __init__(self):
        """
        Generates the pdf for PicSat communication specifications

        Args:
          * docname (str): the name of the pdf document generated
            optionnally with the path (default is "here")

        Method:
          * generate: use it to generate the document
Esempio n. 8
0
    def generate(self, clean_tex=True):
        """
        Generates the document and saves it to disk

        Args:
          * clean_tex (bool): whether to delete the .tex file after
            compiling
        """
        HEADER = open(param_all.Pathing('ctrl', 'mgmt', 'header.tex').path,
                      mode='r').read()
        HEADER2 = open(param_all.Pathing('ctrl', 'mgmt', 'header-2.tex').path,
                       mode='r').read()
        doc = Document(self.docname)
        for k, v in REPL.items():
            HEADER = HEADER.replace(k, v)
            HEADER2 = HEADER2.replace(k, v)
        doc.preamble.append(NoEscape(HEADER))
        doc.append(NoEscape(HEADER2))
        section = Section('Principles')
        section.append(
            """The Telecommand (TC) and Telemetry (TM) packets format specifications are based on the CCSDS format: the concatenation of a primary header, secondary header, (optional) auxiliary header, (optional) data field.

TC are composed of a 6 octets primary header and a 18 octets secondary header. There is no auxiliary header. The data field contains values which depend on the command ID, that are treated by the satelite as input parameters.

TM are composed of a 6 octets primary header and a 6 octets secondary header. The TM category defines what type of TM is transmitted (e.g. beacon, house keeping) and how the auxiliary header and data field are encoded.

This documents covers the content of data field for TC, and the content of auxiliary header and data fields for the TM category 'TC Answer'.

This document does not cover the content of headers for TC, and headers and data fields for TM. This information is available in the dedicated communication specifications document."""
        )
        doc.append(section)
        # Telecommands
        section = Section('Commands for OBC-L0')
        for item in list(sorted(allcommand.L0CMDS, key=lambda x: x.number)):
            subsection = Subsection('#{:d}: {}'.format(item.number, item.name))
            subsection.append(self._print_TC(item))
            section.append(subsection)
            # add TM if need be
            if item.number in param_tc_answer.TROUSSEAUDIC.keys():
                subsection = self._trousseau2subsection(
                    "Answer TM to {}".format(item.name),
                    param_tc_answer.TROUSSEAUDIC[item.number])
                section.append(subsection)
        doc.append(section)

        section = Section('Commands for OBC-L1')
        for item in list(sorted(allcommand.L1OBCCMDS, key=lambda x: x.number)):
            subsection = Subsection(item.name)
            subsection.append(self._print_TC(item))
            section.append(subsection)
            # add TM if need be
            if item.number in param_tc_answer.TROUSSEAUDIC.keys():
                subsection = self._trousseau2subsection(
                    "Answer TM to {}".format(item.name),
                    param_tc_answer.TROUSSEAUDIC[item.number])
                section.append(subsection)
        doc.append(section)

        section = Section('Commands for PLD-L1')
        for item in list(sorted(allcommand.L1PLDCMDS, key=lambda x: x.number)):
            subsection = Subsection(item.name)
            subsection.append(self._print_TC(item))
            section.append(subsection)
            # add TM if need be
            if item.number in param_tc_answer.TROUSSEAUDIC.keys():
                subsection = self._trousseau2subsection(
                    "Answer TM to {}".format(item.name),
                    param_tc_answer.TROUSSEAUDIC[item.number])
                section.append(subsection)
        doc.append(section)
        self._compile(doc, clean_tex=clean_tex)