lpcmanager

cc9644b8e7e2
Parents 0892985090bd
Children 7c1c9a104bb3
Use eRPC's extendedCalls for "CheckProductID" and "GetVersions".
--- a/LPCExtension.py Tue Oct 29 10:59:04 2024 +0100
+++ b/LPCExtension.py Mon Nov 11 15:33:01 2024 +0100
@@ -7,7 +7,7 @@
#
import features
-from POULibrary import SimplePOULibraryFactory
+from POULibrary import SimplePOULibraryFactory, UserAddressedException
from LPCArch import GetLPCProduct, GetLPCSOM, WX_GOT_modules, SOM28_modules, SOM6_modules, SVG_GOT_modules, GetLPCArch, PREEMPTSOM6_modules
# _lpcmanager_path, arch, etc are defined here because
@@ -64,6 +64,27 @@
return WAMP._WAMP_connector_factory(WampSession, *args, **kwargs)
connectors.connectors["WAMP"] = lambda:CustomWAMPFactory
+
+from erpc_interface.erpc_PLCObject.client import BeremizPLCObjectServiceClient
+import json
+
+def JsonMethodProxyFactory(ExtendedCallName):
+ def JsonMethodProxy(self, *args, **kwargs):
+ outputbin = self.ExtendedCall(ExtendedCallName, json.dumps([args, kwargs]).encode())
+ jsonoutput = json.loads(outputbin)
+ if type(jsonoutput) == list and len(jsonoutput) == 2:
+ result, error = jsonoutput
+ if type(error) == str:
+ raise UserAddressedException(error)
+ else:
+ return result
+ raise Exception("Invalid input for " + ExtendedCallName)
+ return JsonMethodProxy
+
+LPCManagerExtendedCalls = ["CheckProductID", "GetVersions"]
+for ExtendedCall in LPCManagerExtendedCalls:
+ setattr(BeremizPLCObjectServiceClient, ExtendedCall, JsonMethodProxyFactory(ExtendedCall))
+
# TODO
# from LPCconnector import LPC_connector_factory
# connectors.connectors["LPC"] = lambda: LPC_connector_factory