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

TM code works now.

parent f99bcec5
......@@ -30,42 +30,42 @@ from PySide.QtGui import QDockWidget
__all__ = ['SQLTelecommands', 'SQLTelemetries']
# class TM(QDockWidget, QObject):
# ''' Subclasses of TM will receive ASN.1 data from the GUI whenever a
# value is updated (through a Qt slot)
# '''
# # specify a name for the combo button
# name = 'Generic TM'
#
# def __init__(self, unused_asn1_type=None, parent=None):
# ''' Initialisation of the Widget '''
# super(TM, self).__init__(parent)
#
# @staticmethod
# def applicable():
# '''' Return true is the widget is active '''
# return True
#
# @Slot()
# def update(self, value):
# ''' Receive ASN.1 value '''
# pass
#
#
# class TC(QDockWidget, QObject):
# ''' Subclasses of TC can be used to provide ASN.1 data to the main GUI
# and to automatically send it to the application.
# Example of uses: Buttons, SQL interface...
# Define your widget and send signals at will.
# '''
# send = Signal()
# update = Signal()
# # specify a name for the combo button
# name = 'Generic TM'
#
# def __init__(self, unused_asn1_type=None, parent=None):
# ''' Initialisation of the Widget '''
# super(TC, self).__init__(parent)
class TM(QDockWidget, QObject):
''' Subclasses of TM will receive ASN.1 data from the GUI whenever a
value is updated (through a Qt slot)
'''
# specify a name for the combo button
name = 'Generic TM'
def __init__(self, unused_asn1_type=None, parent=None):
''' Initialisation of the Widget '''
super(TM, self).__init__(parent)
@staticmethod
def applicable():
'''' Return true is the widget is active '''
return True
@Slot()
def update(self, value):
''' Receive ASN.1 value '''
pass
class TC(QDockWidget, QObject):
''' Subclasses of TC can be used to provide ASN.1 data to the main GUI
and to automatically send it to the application.
Example of uses: Buttons, SQL interface...
Define your widget and send signals at will.
'''
send = Signal()
update = Signal()
# specify a name for the combo button
name = 'Generic TM'
def __init__(self, unused_asn1_type=None, parent=None):
''' Initialisation of the Widget '''
super(TC, self).__init__(parent)
def connect_to_db():
......@@ -83,7 +83,7 @@ def connect_to_db():
db_module = importlib.import_module(dbname + "_model")
os.chdir("..")
from sqlalchemy import create_engine
engine = create_engine(sqlalchemy_url, echo=False)
engine = create_engine(sqlalchemy_url, echo=True)
getattr(db_module, 'Base').metadata.create_all(engine)
from sqlalchemy.orm import sessionmaker
SessionFactory = sessionmaker(bind=engine)
......@@ -91,8 +91,7 @@ def connect_to_db():
return session, dbname
#class SQLTelecommands(TC):
class SQLTelecommands(object):
class SQLTelecommands(TC):
'''Load telecommands from the database'''
name = 'Get TCs from DB'
session = None
......@@ -100,8 +99,7 @@ class SQLTelecommands(object):
def __init__(self, asn1_typename, parent=None):
''' Initialise the widget '''
#super(SQLTelecommands, self).__init__(asn1_typename, parent)
super(SQLTelecommands, self).__init__()
super(SQLTelecommands, self).__init__(asn1_typename, parent)
if SQLTelecommands.session is None:
SQLTelecommands.session, SQLTelecommands.dbname = \
connect_to_db()
......@@ -121,8 +119,10 @@ class SQLTelecommands(object):
x
for x, in SQLTelecommands.session.query(
self._asn1_klass.iid
).filter(
self._asn1_klass.iid.between(offset, offset + number)
).offset(
offset
).limit(
number
)
]
......@@ -150,8 +150,7 @@ class SQLTelecommands(object):
self.send.emit(as_asn1) # use signal to send data to the GUI
#class SQLTelemetries(TM):
class SQLTelemetries(object):
class SQLTelemetries(TM):
'''Save telemetries in the database'''
name = 'Store TMs in DB'
session = None
......@@ -159,8 +158,7 @@ class SQLTelemetries(object):
def __init__(self, parent=None):
''' Initialise the widget '''
#super(SQLTelemetries, self).__init__(parent)
super(SQLTelemetries, self).__init__()
super(SQLTelemetries, self).__init__(parent)
# to do here = display a window with two buttons:
# "start storing in DB", "stop storing in DB"
self.mode = 'recording'
......@@ -177,7 +175,7 @@ class SQLTelemetries(object):
if asn1_klass is None:
raise Exception(
"No class " + klass + " found in " + SQLTelemetries.dbname)
db_row = getattr(db_module, asn1_klass)(value)
db_row = asn1_klass(value)
iid = db_row.save(SQLTelemetries.session)
SQLTelemetries.session.commit()
return iid
......@@ -190,7 +188,14 @@ class SQLTelemetries(object):
return os.path.isdir("sql_db")
if __name__ == '__main__':
# print 'This module can only be imported from the main TASTE guis'
# sys.exit(-1)
a = SQLTelecommands('MyInteger_SQL')
print(a)
print 'This module can only be imported from the main TASTE guis'
sys.exit(-1)
#
# obsolete tests
#
#a = SQLTelecommands('MyInteger')
#assert a.sql2asn1(1).Get() == 22L
#b = db_module.MyInteger()
#b.Set(15)
#c = SQLTelemetries()
#c.update(b)
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