Commit e8ee5a44 authored by Thanassis Tsiodras's avatar Thanassis Tsiodras
Browse files

TC part written (untested)

parent c4376192
......@@ -12,21 +12,19 @@
be placed in a docking window.
(c) 2016 European Space Agency
Authors: Maxime Perrotin, Thanassis Tsiodras
__author__ = "Maxime Perrotin, Thanassis Tsiodras"
__license__ = "LGPL"
__version__ = "1.0"
__url__ = ""
import sys
import os
from PySide.QtCore import (QObject, Signal, Slot, Qt, QRectF, QPointF, QPoint)
from PySide.QtGui import QDockWidget
__author__ = "Maxime Perrotin, Thanassis Tsiodras"
__license__ = "LGPL"
__version__ = "1.0"
__url__ = ""
# User must list explicitly the classes he wants to expose to the GUI:
__all__ = ['SQLTelecommands', 'SQLTelemetries']
......@@ -38,7 +36,7 @@ class TM(QDockWidget, QObject):
# specify a name for the combo button
name = 'Generic TM'
def __init__(self, asn1_type=None, parent=None):
def __init__(self, unused_asn1_type=None, parent=None):
''' Initialisation of the Widget '''
super(TM, self).__init__(parent)
......@@ -64,7 +62,7 @@ class TC(QDockWidget, QObject):
# specify a name for the combo button
name = 'Generic TM'
def __init__(self, asn1_type=None, parent=None):
def __init__(self, unused_asn1_type=None, parent=None):
''' Initialisation of the Widget '''
super(TC, self).__init__(parent)
......@@ -73,17 +71,47 @@ class SQLTelecommands(TC):
''' Handle Postgresql databases for telecommands '''
name = 'Get TCs from db'
session = None
dbname = None
asn1SQLclasses = {}
def __init__(self, asn1_typename, parent=None):
''' Initialise the widget '''
super(SQLTelecommands, self).__init__(asn1_typename, parent)
# to do here = create a table widget, and place all the entries
# of the given ASN.1 type
if SQLTelecommands.session is None:
SQLTelecommands.session = SQLTelecommands.connect_to_db()
self._asn1_typename = asn1_typename
typename_sql = asn1_typename + "_SQL"
self._asn1_klass = globals().get(typename_sql, None)
if self._asn1_klass is None:
print "No class", typename_sql, "found in", SQLTelecommands.dbname
def connectToDB():
def connect_to_db():
This will fetch all _model classes in global scope,
connect to the DB and return a session object.'''
config_info = open("sql_db/").readlines()
sqlalchemy_url, dbname = config_info[0], config_info[1]
print "The sql_db/ is either missing or invalid!"
print "Aborting..."
SQLTelecommands.dbname = dbname
for key, val in vars(__import__(dbname + "_model")).iteritems():
if key not in globals():
globals()[key] = val
from sqlalchemy import create_engine
engine = create_engine(sqlalchemy_url, echo=False)
from sqlalchemy.orm import sessionmaker
SessionFactory = sessionmaker(bind=engine)
session = SessionFactory()
return session
def applicable():
......@@ -91,13 +119,21 @@ class SQLTelecommands(TC):
return os.path.isdir("sql_db")
def getPageIndexes(self, offset, number):
# Thanassis, please fill this one
return [
for x in SQLTelecommands.session.query(
self._asn1_klass.iid.between(offset, offset + number)
def sql2asn1(self, idx):
''' Thanassis: please retrieve the db entry for index "lineNb"
and convert it to an ASN.1 native type '''
return SQLTelecommands.session.query(
self._asn1_klass.iid == idx
def onUpdateButtonClick(self, lineNb):
''' When user clicks on Update, the content of the selected TC will
......@@ -128,7 +164,6 @@ class SQLTelemetries(TM):
def update(self, value):
''' Receive ASN.1 value '''
# value should be in native ASN.1 format
if self.mode == 'recording':
# Convert value to SQL entry and store in DB
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment