Beispiel #1
0
    def init(self, dPrm={}):
        if dPrm == {}: dPrm = get_dPrm()
        # Writing data.log
        from scada_logger_test import TestScadaLogger
        tsl = TestScadaLogger()
        tsl.test_write_data()

        # Delete yaml database file
        import os
        try:
            os.remove(dPrm['DATABASE']['file'])
        except:
            pass
        scadaDB = ScadaDatabase(createLog('DEBUG'), dPrm)
        scadaDB.add(
            ScadaVarLin(scadaDB,
                        'Y0', {
                            'input': 'A0',
                            'a': 0.001,
                            'b': -0.23
                        },
                        description='Water depth on sensor #0 (m)'))
        scadaDB.add(
            ScadaVarExp(scadaDB,
                        'Q0', {
                            'input': 'Y0',
                            'a': 1.4,
                            'b': 0.10,
                            'c': 2.5
                        },
                        description='Water discharge on sensor #0 (m3/s)'))

        return scadaDB
    def __init__(self, dPrm):
        self.dPrm = dPrm
        self.dPrmG = dPrm['GATEWAY']

        from scada_misc import createLog
        self.log = createLog(dPrm['LOGGER']['level'])
        self.log.info('Starting Scada Gateway')

        # Scheduled measurement
        import sched, time
        self.s = sched.scheduler(time.time, time.sleep)
        try:
            self.frequency = float(self.dPrmG['frequency'])
        except Exception as e:
            self.log.error('scada.ini: Parameter [GATEWAY] frequency: ' +
                           str(e))
            raise SystemExit(1)
Beispiel #3
0
    def __init__(self, tcpHandler, dPrm):
        self.tcpHandler = tcpHandler
        self.bConnected = True
        self.bTest = (tcpHandler == False)
        self.instructionSet = {
            'CLOSE': self.instrClose,
            'DEF': self.instrDef,
            'DEL': self.instrDel,
            'EXIT': self.instrClose,
            'GET': self.instrGet,
            'HELP': self.instrHelp,
            'LIST': self.instrList,
            'NET': self.instrNet,
            'QUIT': self.instrClose
        }
        from scada_misc import createLog
        self.dPrm = dPrm
        self.log = createLog(self.dPrm['LOGGER']['level'])

        from scada_database import ScadaDatabase
        self.scadaDB = ScadaDatabase(self.log, self.dPrm)

        self.send(self.open())
from scada_server_handler_test import dPrm
dPrm['NET_DATA_LOGGER'] = {'tcp_port': '34060', 'file': 'network_data_{}.log'}

from scada_net_datalogger import NetDeviceHandler
from scada_misc import createLog
netHdlr = NetDeviceHandler(dPrm, createLog('DEBUG'))


class TestNetDeviceHandler():
    def test_device_not_registered(self):
        assert netHdlr.get('/fake_device/9999')[:5] == 'ERROR'

    def test_device_one_data(self):
        from scada_var_type import ScadaDevice
        netHdlr.scadaDB.addDevice(
            ScadaDevice("TEST_DEVICE", 1, "Test device", "test_token"))
        assert netHdlr.get('/test_token/1.234')[:15] == '1 data recorded'


if __name__ == '__main__':
    method_list = [
        func for func in dir(TestNetDeviceHandler)
        if callable(getattr(TestNetDeviceHandler, func))
    ]
    test = TestNetDeviceHandler()
    for func in [func for func in method_list if func[:5] == 'test_']:
        getattr(test, func)()
Beispiel #5
0
def scadaNetDataLogger(dPrm):
    from scada_misc import createLog
    netHdlr = NetDeviceHandler(dPrm,
                               createLog(dPrm['NET_DATA_LOGGER']['log_level']))
    netHdlr.serve()
Beispiel #6
0
from scada_logger_arduino import ArduinoCommunication
from scada_misc import createLog

dPrmHard = {"test": "1", "test_maxval": "100", "nb_pins": "12"}

hc = ArduinoCommunication(createLog('DEBUG'), dPrmHard)


class TestHardCom():
    def test_get(self):
        assert len(hc.get([0, 1, 2, 3])) == 4

    def test_out_of_range0(self):
        assert "ERROR" not in hc.get([0, 1, 2, 3])

    def test_out_of_range(self):
        assert "ERROR" in hc.get([12, 13])

    def test_type_error(self):
        assert "ERROR" in hc.get("1")