summaryrefslogtreecommitdiff
path: root/test-cli/test/helpers/plc.py
diff options
context:
space:
mode:
Diffstat (limited to 'test-cli/test/helpers/plc.py')
-rw-r--r--test-cli/test/helpers/plc.py82
1 files changed, 82 insertions, 0 deletions
diff --git a/test-cli/test/helpers/plc.py b/test-cli/test/helpers/plc.py
new file mode 100644
index 0000000..069058d
--- /dev/null
+++ b/test-cli/test/helpers/plc.py
@@ -0,0 +1,82 @@
+import sh
+from sh import flashcp
+from sh import flash_eraseall
+from sh import ErrorReturnCode
+from sh import Command
+from test.helpers.gpio import gpio
+import time
+
+
+class dcpPLC(object):
+ __nReset = None
+ __Phy = None
+ __Plc = None
+ __mtd_device = None
+ __factool = None
+ __myConfigTool = None
+
+ def __init__(self, plcfactool, mtd_device):
+ # default save firmware
+ self.__nRest = gpio('75', 'out', '0')
+ self.__nRest = gpio('69', 'out', '0')
+ self.__nRest = gpio('78', 'out', '1')
+ self.__factool = plcfactool
+ self.__mtd_device = mtd_device
+ self.__myConfigTool = Command(self.__factool)
+
+ def setSaveFirmwareMode(self):
+ self.__nRest = gpio('75', 'out', '0')
+ self.__nRest = gpio('69', 'out', '0')
+ self.__nRest = gpio('78', 'out', '1')
+
+ def setBootMode(self):
+ self.__nRest = gpio('78', 'out', '0')
+ self.__nRest = gpio('75', 'out', '1')
+ self.__nRest = gpio('69', 'out', '1')
+
+ def setPLCReset(self):
+ self.__nRest = gpio('75', 'out', '0')
+ self.__nRest = gpio('69', 'out', '0')
+ time.sleep(1)
+ self.__nRest = gpio('69', 'out', '1')
+ self.__nRest = gpio('75', 'out', '1')
+
+ def SaveFirmware(self, firmare):
+ self.setSaveFirmwareMode()
+ try:
+ flash_eraseall(self.__mtd_device)
+ flashcp(firmare, self.__mtd_device)
+ except ErrorReturnCode as Error:
+ return False, "plc flash firmware failed {} ".format(Error.exit_code)
+ return True, ''
+
+ def set_plc(self, var, value, password):
+ try:
+ res = self.__myConfigTool("-o", "SET", "-p", "{}={}".format(var, value), "-w", "{}".format(password))
+ print(res)
+ except ErrorReturnCode as Error:
+ return False, "set var failed {} {}".format(var, Error.exit_code)
+ return True, ''
+
+ def set_plc2(self, var1, value1, var2, value2, password):
+ try:
+ res = self.__myConfigTool("-o", "SET", "-p", "{}={}".format(var1, value1), "-p",
+ "{}={}".format(var2, value2), "-w", "{}".format(password))
+ print(res)
+ except ErrorReturnCode as Error:
+ return False, "set var failed {}".format(Error.exit_code)
+ return True, ''
+
+ def get_plc(self, var, value, password):
+ try:
+ self.__myConfigTool("-o", "GET", "-p", "{}".format(var), '{}'.format(value), "-w", "{}".format(password))
+ except ErrorReturnCode as Error:
+ return False, "set var failed {} {}".format(var, Error.exit_code)
+ return True, ''
+
+ def discover(self):
+ try:
+ self.__myConfigTool("-o", "DISCOVER")
+ except ErrorReturnCode:
+ return False
+ return True