author | Edouard Tisserant <edouard@beremiz.fr> |
Thu, 19 Sep 2024 12:06:53 +0200 | |
changeset 4016 | 9e4a3a3ea5c0 |
parent 4014 | da52eabd0e6d |
child 4017 | 3977d55217ec |
permissions | -rw-r--r-- |
3979
76295adcf940
WIP: Add skeleton for MQTT extension based on part of OPC-UA extension.
Edouard Tisserant <edouard@beremiz.fr>
parents:
diff
changeset
|
1 |
from __future__ import print_function |
76295adcf940
WIP: Add skeleton for MQTT extension based on part of OPC-UA extension.
Edouard Tisserant <edouard@beremiz.fr>
parents:
diff
changeset
|
2 |
from __future__ import absolute_import |
76295adcf940
WIP: Add skeleton for MQTT extension based on part of OPC-UA extension.
Edouard Tisserant <edouard@beremiz.fr>
parents:
diff
changeset
|
3 |
|
76295adcf940
WIP: Add skeleton for MQTT extension based on part of OPC-UA extension.
Edouard Tisserant <edouard@beremiz.fr>
parents:
diff
changeset
|
4 |
import csv |
76295adcf940
WIP: Add skeleton for MQTT extension based on part of OPC-UA extension.
Edouard Tisserant <edouard@beremiz.fr>
parents:
diff
changeset
|
5 |
import functools |
76295adcf940
WIP: Add skeleton for MQTT extension based on part of OPC-UA extension.
Edouard Tisserant <edouard@beremiz.fr>
parents:
diff
changeset
|
6 |
from threading import Thread |
4012
6337c9c2c379
MQTT: add JSON payload corresponding to IEC Structured types
Edouard Tisserant <edouard@beremiz.fr>
parents:
4011
diff
changeset
|
7 |
from collections import OrderedDict as OD |
3979
76295adcf940
WIP: Add skeleton for MQTT extension based on part of OPC-UA extension.
Edouard Tisserant <edouard@beremiz.fr>
parents:
diff
changeset
|
8 |
|
76295adcf940
WIP: Add skeleton for MQTT extension based on part of OPC-UA extension.
Edouard Tisserant <edouard@beremiz.fr>
parents:
diff
changeset
|
9 |
import wx |
76295adcf940
WIP: Add skeleton for MQTT extension based on part of OPC-UA extension.
Edouard Tisserant <edouard@beremiz.fr>
parents:
diff
changeset
|
10 |
import wx.dataview as dv |
76295adcf940
WIP: Add skeleton for MQTT extension based on part of OPC-UA extension.
Edouard Tisserant <edouard@beremiz.fr>
parents:
diff
changeset
|
11 |
|
3995
84a668564748
MQTT: take C part away from python code for readability.
Edouard Tisserant <edouard@beremiz.fr>
parents:
3994
diff
changeset
|
12 |
import util.paths as paths |
84a668564748
MQTT: take C part away from python code for readability.
Edouard Tisserant <edouard@beremiz.fr>
parents:
3994
diff
changeset
|
13 |
|
3984
883a85b9ebcc
MQTT: still WIP, generated C code builds and link.
Edouard Tisserant <edouard@beremiz.fr>
parents:
3981
diff
changeset
|
14 |
# from perfect_hash import generate_code, IntSaltHash |
3979
76295adcf940
WIP: Add skeleton for MQTT extension based on part of OPC-UA extension.
Edouard Tisserant <edouard@beremiz.fr>
parents:
diff
changeset
|
15 |
|
76295adcf940
WIP: Add skeleton for MQTT extension based on part of OPC-UA extension.
Edouard Tisserant <edouard@beremiz.fr>
parents:
diff
changeset
|
16 |
MQTT_IEC_types = dict( |
76295adcf940
WIP: Add skeleton for MQTT extension based on part of OPC-UA extension.
Edouard Tisserant <edouard@beremiz.fr>
parents:
diff
changeset
|
17 |
# IEC61131| C type | sz |
76295adcf940
WIP: Add skeleton for MQTT extension based on part of OPC-UA extension.
Edouard Tisserant <edouard@beremiz.fr>
parents:
diff
changeset
|
18 |
BOOL = ("uint8_t" , "X"), |
76295adcf940
WIP: Add skeleton for MQTT extension based on part of OPC-UA extension.
Edouard Tisserant <edouard@beremiz.fr>
parents:
diff
changeset
|
19 |
SINT = ("int8_t" , "B"), |
76295adcf940
WIP: Add skeleton for MQTT extension based on part of OPC-UA extension.
Edouard Tisserant <edouard@beremiz.fr>
parents:
diff
changeset
|
20 |
USINT = ("uint8_t" , "B"), |
76295adcf940
WIP: Add skeleton for MQTT extension based on part of OPC-UA extension.
Edouard Tisserant <edouard@beremiz.fr>
parents:
diff
changeset
|
21 |
INT = ("int16_t" , "W"), |
76295adcf940
WIP: Add skeleton for MQTT extension based on part of OPC-UA extension.
Edouard Tisserant <edouard@beremiz.fr>
parents:
diff
changeset
|
22 |
UINT = ("uint16_t", "W"), |
76295adcf940
WIP: Add skeleton for MQTT extension based on part of OPC-UA extension.
Edouard Tisserant <edouard@beremiz.fr>
parents:
diff
changeset
|
23 |
DINT = ("uint32_t", "D"), |
76295adcf940
WIP: Add skeleton for MQTT extension based on part of OPC-UA extension.
Edouard Tisserant <edouard@beremiz.fr>
parents:
diff
changeset
|
24 |
UDINT = ("int32_t" , "D"), |
76295adcf940
WIP: Add skeleton for MQTT extension based on part of OPC-UA extension.
Edouard Tisserant <edouard@beremiz.fr>
parents:
diff
changeset
|
25 |
LINT = ("int64_t" , "L"), |
76295adcf940
WIP: Add skeleton for MQTT extension based on part of OPC-UA extension.
Edouard Tisserant <edouard@beremiz.fr>
parents:
diff
changeset
|
26 |
ULINT = ("uint64_t", "L"), |
76295adcf940
WIP: Add skeleton for MQTT extension based on part of OPC-UA extension.
Edouard Tisserant <edouard@beremiz.fr>
parents:
diff
changeset
|
27 |
REAL = ("float" , "D"), |
76295adcf940
WIP: Add skeleton for MQTT extension based on part of OPC-UA extension.
Edouard Tisserant <edouard@beremiz.fr>
parents:
diff
changeset
|
28 |
LREAL = ("double" , "L"), |
76295adcf940
WIP: Add skeleton for MQTT extension based on part of OPC-UA extension.
Edouard Tisserant <edouard@beremiz.fr>
parents:
diff
changeset
|
29 |
) |
76295adcf940
WIP: Add skeleton for MQTT extension based on part of OPC-UA extension.
Edouard Tisserant <edouard@beremiz.fr>
parents:
diff
changeset
|
30 |
|
76295adcf940
WIP: Add skeleton for MQTT extension based on part of OPC-UA extension.
Edouard Tisserant <edouard@beremiz.fr>
parents:
diff
changeset
|
31 |
""" |
76295adcf940
WIP: Add skeleton for MQTT extension based on part of OPC-UA extension.
Edouard Tisserant <edouard@beremiz.fr>
parents:
diff
changeset
|
32 |
QoS - Quality of Service |
76295adcf940
WIP: Add skeleton for MQTT extension based on part of OPC-UA extension.
Edouard Tisserant <edouard@beremiz.fr>
parents:
diff
changeset
|
33 |
0 : "At most one delivery" |
76295adcf940
WIP: Add skeleton for MQTT extension based on part of OPC-UA extension.
Edouard Tisserant <edouard@beremiz.fr>
parents:
diff
changeset
|
34 |
1 : "At least one delivery" |
76295adcf940
WIP: Add skeleton for MQTT extension based on part of OPC-UA extension.
Edouard Tisserant <edouard@beremiz.fr>
parents:
diff
changeset
|
35 |
2 : "Exactly one delivery" |
76295adcf940
WIP: Add skeleton for MQTT extension based on part of OPC-UA extension.
Edouard Tisserant <edouard@beremiz.fr>
parents:
diff
changeset
|
36 |
""" |
76295adcf940
WIP: Add skeleton for MQTT extension based on part of OPC-UA extension.
Edouard Tisserant <edouard@beremiz.fr>
parents:
diff
changeset
|
37 |
QoS_values = [0, 1, 2] |
76295adcf940
WIP: Add skeleton for MQTT extension based on part of OPC-UA extension.
Edouard Tisserant <edouard@beremiz.fr>
parents:
diff
changeset
|
38 |
|
3980
96acfee19caf
MQTT WIP: intermediate state, implementing MQTT client C code generator.
Edouard Tisserant <edouard@beremiz.fr>
parents:
3979
diff
changeset
|
39 |
def boolean(v): |
96acfee19caf
MQTT WIP: intermediate state, implementing MQTT client C code generator.
Edouard Tisserant <edouard@beremiz.fr>
parents:
3979
diff
changeset
|
40 |
if v in ["False","0"]: |
96acfee19caf
MQTT WIP: intermediate state, implementing MQTT client C code generator.
Edouard Tisserant <edouard@beremiz.fr>
parents:
3979
diff
changeset
|
41 |
return False |
96acfee19caf
MQTT WIP: intermediate state, implementing MQTT client C code generator.
Edouard Tisserant <edouard@beremiz.fr>
parents:
3979
diff
changeset
|
42 |
else: |
96acfee19caf
MQTT WIP: intermediate state, implementing MQTT client C code generator.
Edouard Tisserant <edouard@beremiz.fr>
parents:
3979
diff
changeset
|
43 |
return bool(v) |
96acfee19caf
MQTT WIP: intermediate state, implementing MQTT client C code generator.
Edouard Tisserant <edouard@beremiz.fr>
parents:
3979
diff
changeset
|
44 |
|
3988
150599d9073f
MQTT: WIP, subscibed topics have no "Retained" attribute.
Edouard Tisserant <edouard@beremiz.fr>
parents:
3987
diff
changeset
|
45 |
_lstcolnames = [ "Topic", "QoS", "Retained", "Type", "Location"] |
150599d9073f
MQTT: WIP, subscibed topics have no "Retained" attribute.
Edouard Tisserant <edouard@beremiz.fr>
parents:
3987
diff
changeset
|
46 |
_lstcolwidths = [ 100, 50, 100, 100, 50] |
150599d9073f
MQTT: WIP, subscibed topics have no "Retained" attribute.
Edouard Tisserant <edouard@beremiz.fr>
parents:
3987
diff
changeset
|
47 |
_lstcoltypess = [ str, int, boolean, str, int] |
150599d9073f
MQTT: WIP, subscibed topics have no "Retained" attribute.
Edouard Tisserant <edouard@beremiz.fr>
parents:
3987
diff
changeset
|
48 |
_lstcoldeflts = [ "a/b/c", "1", False, "DINT", "0"] |
150599d9073f
MQTT: WIP, subscibed topics have no "Retained" attribute.
Edouard Tisserant <edouard@beremiz.fr>
parents:
3987
diff
changeset
|
49 |
|
150599d9073f
MQTT: WIP, subscibed topics have no "Retained" attribute.
Edouard Tisserant <edouard@beremiz.fr>
parents:
3987
diff
changeset
|
50 |
subsublist = lambda l : l[0:2] + l[3:5] |
150599d9073f
MQTT: WIP, subscibed topics have no "Retained" attribute.
Edouard Tisserant <edouard@beremiz.fr>
parents:
3987
diff
changeset
|
51 |
|
150599d9073f
MQTT: WIP, subscibed topics have no "Retained" attribute.
Edouard Tisserant <edouard@beremiz.fr>
parents:
3987
diff
changeset
|
52 |
lstcoldsc = { |
150599d9073f
MQTT: WIP, subscibed topics have no "Retained" attribute.
Edouard Tisserant <edouard@beremiz.fr>
parents:
3987
diff
changeset
|
53 |
"input" : type("",(),dict( |
150599d9073f
MQTT: WIP, subscibed topics have no "Retained" attribute.
Edouard Tisserant <edouard@beremiz.fr>
parents:
3987
diff
changeset
|
54 |
lstcolnames = subsublist(_lstcolnames), |
150599d9073f
MQTT: WIP, subscibed topics have no "Retained" attribute.
Edouard Tisserant <edouard@beremiz.fr>
parents:
3987
diff
changeset
|
55 |
lstcolwidths = subsublist(_lstcolwidths), |
150599d9073f
MQTT: WIP, subscibed topics have no "Retained" attribute.
Edouard Tisserant <edouard@beremiz.fr>
parents:
3987
diff
changeset
|
56 |
lstcoltypess = subsublist(_lstcoltypess), |
150599d9073f
MQTT: WIP, subscibed topics have no "Retained" attribute.
Edouard Tisserant <edouard@beremiz.fr>
parents:
3987
diff
changeset
|
57 |
lstcoldeflts = subsublist(_lstcoldeflts), |
150599d9073f
MQTT: WIP, subscibed topics have no "Retained" attribute.
Edouard Tisserant <edouard@beremiz.fr>
parents:
3987
diff
changeset
|
58 |
Location_column = 3)), |
150599d9073f
MQTT: WIP, subscibed topics have no "Retained" attribute.
Edouard Tisserant <edouard@beremiz.fr>
parents:
3987
diff
changeset
|
59 |
"output" : type("",(),dict( |
150599d9073f
MQTT: WIP, subscibed topics have no "Retained" attribute.
Edouard Tisserant <edouard@beremiz.fr>
parents:
3987
diff
changeset
|
60 |
lstcolnames = _lstcolnames, |
150599d9073f
MQTT: WIP, subscibed topics have no "Retained" attribute.
Edouard Tisserant <edouard@beremiz.fr>
parents:
3987
diff
changeset
|
61 |
lstcolwidths = _lstcolwidths, |
150599d9073f
MQTT: WIP, subscibed topics have no "Retained" attribute.
Edouard Tisserant <edouard@beremiz.fr>
parents:
3987
diff
changeset
|
62 |
lstcoltypess = _lstcoltypess, |
150599d9073f
MQTT: WIP, subscibed topics have no "Retained" attribute.
Edouard Tisserant <edouard@beremiz.fr>
parents:
3987
diff
changeset
|
63 |
lstcoldeflts = _lstcoldeflts, |
150599d9073f
MQTT: WIP, subscibed topics have no "Retained" attribute.
Edouard Tisserant <edouard@beremiz.fr>
parents:
3987
diff
changeset
|
64 |
Location_column = 4)), |
150599d9073f
MQTT: WIP, subscibed topics have no "Retained" attribute.
Edouard Tisserant <edouard@beremiz.fr>
parents:
3987
diff
changeset
|
65 |
} |
3979
76295adcf940
WIP: Add skeleton for MQTT extension based on part of OPC-UA extension.
Edouard Tisserant <edouard@beremiz.fr>
parents:
diff
changeset
|
66 |
|
76295adcf940
WIP: Add skeleton for MQTT extension based on part of OPC-UA extension.
Edouard Tisserant <edouard@beremiz.fr>
parents:
diff
changeset
|
67 |
directions = ["input", "output"] |
76295adcf940
WIP: Add skeleton for MQTT extension based on part of OPC-UA extension.
Edouard Tisserant <edouard@beremiz.fr>
parents:
diff
changeset
|
68 |
|
4005
482452574fb4
MQTT: add SSL support
Edouard Tisserant <edouard@beremiz.fr>
parents:
3999
diff
changeset
|
69 |
# expected configuration entries with internal default value |
3979
76295adcf940
WIP: Add skeleton for MQTT extension based on part of OPC-UA extension.
Edouard Tisserant <edouard@beremiz.fr>
parents:
diff
changeset
|
70 |
authParams = { |
76295adcf940
WIP: Add skeleton for MQTT extension based on part of OPC-UA extension.
Edouard Tisserant <edouard@beremiz.fr>
parents:
diff
changeset
|
71 |
"x509":[ |
4005
482452574fb4
MQTT: add SSL support
Edouard Tisserant <edouard@beremiz.fr>
parents:
3999
diff
changeset
|
72 |
("Verify", True), |
482452574fb4
MQTT: add SSL support
Edouard Tisserant <edouard@beremiz.fr>
parents:
3999
diff
changeset
|
73 |
("KeyStore", None), |
482452574fb4
MQTT: add SSL support
Edouard Tisserant <edouard@beremiz.fr>
parents:
3999
diff
changeset
|
74 |
("TrustStore", None)], |
3979
76295adcf940
WIP: Add skeleton for MQTT extension based on part of OPC-UA extension.
Edouard Tisserant <edouard@beremiz.fr>
parents:
diff
changeset
|
75 |
"UserPassword":[ |
76295adcf940
WIP: Add skeleton for MQTT extension based on part of OPC-UA extension.
Edouard Tisserant <edouard@beremiz.fr>
parents:
diff
changeset
|
76 |
("User", None), |
76295adcf940
WIP: Add skeleton for MQTT extension based on part of OPC-UA extension.
Edouard Tisserant <edouard@beremiz.fr>
parents:
diff
changeset
|
77 |
("Password", None)]} |
76295adcf940
WIP: Add skeleton for MQTT extension based on part of OPC-UA extension.
Edouard Tisserant <edouard@beremiz.fr>
parents:
diff
changeset
|
78 |
|
3980
96acfee19caf
MQTT WIP: intermediate state, implementing MQTT client C code generator.
Edouard Tisserant <edouard@beremiz.fr>
parents:
3979
diff
changeset
|
79 |
class MQTTTopicListModel(dv.PyDataViewIndexListModel): |
3988
150599d9073f
MQTT: WIP, subscibed topics have no "Retained" attribute.
Edouard Tisserant <edouard@beremiz.fr>
parents:
3987
diff
changeset
|
80 |
def __init__(self, data, log, direction): |
3979
76295adcf940
WIP: Add skeleton for MQTT extension based on part of OPC-UA extension.
Edouard Tisserant <edouard@beremiz.fr>
parents:
diff
changeset
|
81 |
dv.PyDataViewIndexListModel.__init__(self, len(data)) |
76295adcf940
WIP: Add skeleton for MQTT extension based on part of OPC-UA extension.
Edouard Tisserant <edouard@beremiz.fr>
parents:
diff
changeset
|
82 |
self.data = data |
76295adcf940
WIP: Add skeleton for MQTT extension based on part of OPC-UA extension.
Edouard Tisserant <edouard@beremiz.fr>
parents:
diff
changeset
|
83 |
self.log = log |
3988
150599d9073f
MQTT: WIP, subscibed topics have no "Retained" attribute.
Edouard Tisserant <edouard@beremiz.fr>
parents:
3987
diff
changeset
|
84 |
self.dsc = lstcoldsc[direction] |
3979
76295adcf940
WIP: Add skeleton for MQTT extension based on part of OPC-UA extension.
Edouard Tisserant <edouard@beremiz.fr>
parents:
diff
changeset
|
85 |
|
76295adcf940
WIP: Add skeleton for MQTT extension based on part of OPC-UA extension.
Edouard Tisserant <edouard@beremiz.fr>
parents:
diff
changeset
|
86 |
def GetColumnType(self, col): |
76295adcf940
WIP: Add skeleton for MQTT extension based on part of OPC-UA extension.
Edouard Tisserant <edouard@beremiz.fr>
parents:
diff
changeset
|
87 |
return "string" |
76295adcf940
WIP: Add skeleton for MQTT extension based on part of OPC-UA extension.
Edouard Tisserant <edouard@beremiz.fr>
parents:
diff
changeset
|
88 |
|
76295adcf940
WIP: Add skeleton for MQTT extension based on part of OPC-UA extension.
Edouard Tisserant <edouard@beremiz.fr>
parents:
diff
changeset
|
89 |
def GetValueByRow(self, row, col): |
76295adcf940
WIP: Add skeleton for MQTT extension based on part of OPC-UA extension.
Edouard Tisserant <edouard@beremiz.fr>
parents:
diff
changeset
|
90 |
return str(self.data[row][col]) |
76295adcf940
WIP: Add skeleton for MQTT extension based on part of OPC-UA extension.
Edouard Tisserant <edouard@beremiz.fr>
parents:
diff
changeset
|
91 |
|
76295adcf940
WIP: Add skeleton for MQTT extension based on part of OPC-UA extension.
Edouard Tisserant <edouard@beremiz.fr>
parents:
diff
changeset
|
92 |
# This method is called when the user edits a data item in the view. |
76295adcf940
WIP: Add skeleton for MQTT extension based on part of OPC-UA extension.
Edouard Tisserant <edouard@beremiz.fr>
parents:
diff
changeset
|
93 |
def SetValueByRow(self, value, row, col): |
3988
150599d9073f
MQTT: WIP, subscibed topics have no "Retained" attribute.
Edouard Tisserant <edouard@beremiz.fr>
parents:
3987
diff
changeset
|
94 |
expectedtype = self.dsc.lstcoltypess[col] |
3979
76295adcf940
WIP: Add skeleton for MQTT extension based on part of OPC-UA extension.
Edouard Tisserant <edouard@beremiz.fr>
parents:
diff
changeset
|
95 |
|
76295adcf940
WIP: Add skeleton for MQTT extension based on part of OPC-UA extension.
Edouard Tisserant <edouard@beremiz.fr>
parents:
diff
changeset
|
96 |
try: |
76295adcf940
WIP: Add skeleton for MQTT extension based on part of OPC-UA extension.
Edouard Tisserant <edouard@beremiz.fr>
parents:
diff
changeset
|
97 |
v = expectedtype(value) |
76295adcf940
WIP: Add skeleton for MQTT extension based on part of OPC-UA extension.
Edouard Tisserant <edouard@beremiz.fr>
parents:
diff
changeset
|
98 |
except ValueError: |
76295adcf940
WIP: Add skeleton for MQTT extension based on part of OPC-UA extension.
Edouard Tisserant <edouard@beremiz.fr>
parents:
diff
changeset
|
99 |
self.log("String {} is invalid for type {}\n".format(value,expectedtype.__name__)) |
76295adcf940
WIP: Add skeleton for MQTT extension based on part of OPC-UA extension.
Edouard Tisserant <edouard@beremiz.fr>
parents:
diff
changeset
|
100 |
return False |
76295adcf940
WIP: Add skeleton for MQTT extension based on part of OPC-UA extension.
Edouard Tisserant <edouard@beremiz.fr>
parents:
diff
changeset
|
101 |
|
3988
150599d9073f
MQTT: WIP, subscibed topics have no "Retained" attribute.
Edouard Tisserant <edouard@beremiz.fr>
parents:
3987
diff
changeset
|
102 |
if col == self.dsc.lstcolnames.index("QoS") and v not in QoS_values: |
3979
76295adcf940
WIP: Add skeleton for MQTT extension based on part of OPC-UA extension.
Edouard Tisserant <edouard@beremiz.fr>
parents:
diff
changeset
|
103 |
self.log("{} is invalid for IdType\n".format(value)) |
76295adcf940
WIP: Add skeleton for MQTT extension based on part of OPC-UA extension.
Edouard Tisserant <edouard@beremiz.fr>
parents:
diff
changeset
|
104 |
return False |
76295adcf940
WIP: Add skeleton for MQTT extension based on part of OPC-UA extension.
Edouard Tisserant <edouard@beremiz.fr>
parents:
diff
changeset
|
105 |
|
3999
1479acf750e2
MQTT: WIP fix modified status not being set when adding and modifying topics or attributes.
Edouard Tisserant <edouard@beremiz.fr>
parents:
3998
diff
changeset
|
106 |
line = self.data[row] |
1479acf750e2
MQTT: WIP fix modified status not being set when adding and modifying topics or attributes.
Edouard Tisserant <edouard@beremiz.fr>
parents:
3998
diff
changeset
|
107 |
line[col] = v |
1479acf750e2
MQTT: WIP fix modified status not being set when adding and modifying topics or attributes.
Edouard Tisserant <edouard@beremiz.fr>
parents:
3998
diff
changeset
|
108 |
self.data[row] = line |
3979
76295adcf940
WIP: Add skeleton for MQTT extension based on part of OPC-UA extension.
Edouard Tisserant <edouard@beremiz.fr>
parents:
diff
changeset
|
109 |
return True |
76295adcf940
WIP: Add skeleton for MQTT extension based on part of OPC-UA extension.
Edouard Tisserant <edouard@beremiz.fr>
parents:
diff
changeset
|
110 |
|
76295adcf940
WIP: Add skeleton for MQTT extension based on part of OPC-UA extension.
Edouard Tisserant <edouard@beremiz.fr>
parents:
diff
changeset
|
111 |
# Report how many columns this model provides data for. |
76295adcf940
WIP: Add skeleton for MQTT extension based on part of OPC-UA extension.
Edouard Tisserant <edouard@beremiz.fr>
parents:
diff
changeset
|
112 |
def GetColumnCount(self): |
3988
150599d9073f
MQTT: WIP, subscibed topics have no "Retained" attribute.
Edouard Tisserant <edouard@beremiz.fr>
parents:
3987
diff
changeset
|
113 |
return len(self.dsc.lstcolnames) |
3979
76295adcf940
WIP: Add skeleton for MQTT extension based on part of OPC-UA extension.
Edouard Tisserant <edouard@beremiz.fr>
parents:
diff
changeset
|
114 |
|
76295adcf940
WIP: Add skeleton for MQTT extension based on part of OPC-UA extension.
Edouard Tisserant <edouard@beremiz.fr>
parents:
diff
changeset
|
115 |
# Report the number of rows in the model |
76295adcf940
WIP: Add skeleton for MQTT extension based on part of OPC-UA extension.
Edouard Tisserant <edouard@beremiz.fr>
parents:
diff
changeset
|
116 |
def GetCount(self): |
76295adcf940
WIP: Add skeleton for MQTT extension based on part of OPC-UA extension.
Edouard Tisserant <edouard@beremiz.fr>
parents:
diff
changeset
|
117 |
#self.log.write('GetCount') |
76295adcf940
WIP: Add skeleton for MQTT extension based on part of OPC-UA extension.
Edouard Tisserant <edouard@beremiz.fr>
parents:
diff
changeset
|
118 |
return len(self.data) |
76295adcf940
WIP: Add skeleton for MQTT extension based on part of OPC-UA extension.
Edouard Tisserant <edouard@beremiz.fr>
parents:
diff
changeset
|
119 |
|
76295adcf940
WIP: Add skeleton for MQTT extension based on part of OPC-UA extension.
Edouard Tisserant <edouard@beremiz.fr>
parents:
diff
changeset
|
120 |
# Called to check if non-standard attributes should be used in the |
76295adcf940
WIP: Add skeleton for MQTT extension based on part of OPC-UA extension.
Edouard Tisserant <edouard@beremiz.fr>
parents:
diff
changeset
|
121 |
# cell at (row, col) |
76295adcf940
WIP: Add skeleton for MQTT extension based on part of OPC-UA extension.
Edouard Tisserant <edouard@beremiz.fr>
parents:
diff
changeset
|
122 |
def GetAttrByRow(self, row, col, attr): |
3988
150599d9073f
MQTT: WIP, subscibed topics have no "Retained" attribute.
Edouard Tisserant <edouard@beremiz.fr>
parents:
3987
diff
changeset
|
123 |
if col == self.dsc.Location_column: |
3979
76295adcf940
WIP: Add skeleton for MQTT extension based on part of OPC-UA extension.
Edouard Tisserant <edouard@beremiz.fr>
parents:
diff
changeset
|
124 |
attr.SetColour('blue') |
76295adcf940
WIP: Add skeleton for MQTT extension based on part of OPC-UA extension.
Edouard Tisserant <edouard@beremiz.fr>
parents:
diff
changeset
|
125 |
attr.SetBold(True) |
76295adcf940
WIP: Add skeleton for MQTT extension based on part of OPC-UA extension.
Edouard Tisserant <edouard@beremiz.fr>
parents:
diff
changeset
|
126 |
return True |
76295adcf940
WIP: Add skeleton for MQTT extension based on part of OPC-UA extension.
Edouard Tisserant <edouard@beremiz.fr>
parents:
diff
changeset
|
127 |
return False |
76295adcf940
WIP: Add skeleton for MQTT extension based on part of OPC-UA extension.
Edouard Tisserant <edouard@beremiz.fr>
parents:
diff
changeset
|
128 |
|
76295adcf940
WIP: Add skeleton for MQTT extension based on part of OPC-UA extension.
Edouard Tisserant <edouard@beremiz.fr>
parents:
diff
changeset
|
129 |
|
76295adcf940
WIP: Add skeleton for MQTT extension based on part of OPC-UA extension.
Edouard Tisserant <edouard@beremiz.fr>
parents:
diff
changeset
|
130 |
def DeleteRows(self, rows): |
76295adcf940
WIP: Add skeleton for MQTT extension based on part of OPC-UA extension.
Edouard Tisserant <edouard@beremiz.fr>
parents:
diff
changeset
|
131 |
# make a copy since we'll be sorting(mutating) the list |
76295adcf940
WIP: Add skeleton for MQTT extension based on part of OPC-UA extension.
Edouard Tisserant <edouard@beremiz.fr>
parents:
diff
changeset
|
132 |
# use reverse order so the indexes don't change as we remove items |
76295adcf940
WIP: Add skeleton for MQTT extension based on part of OPC-UA extension.
Edouard Tisserant <edouard@beremiz.fr>
parents:
diff
changeset
|
133 |
rows = sorted(rows, reverse=True) |
76295adcf940
WIP: Add skeleton for MQTT extension based on part of OPC-UA extension.
Edouard Tisserant <edouard@beremiz.fr>
parents:
diff
changeset
|
134 |
|
76295adcf940
WIP: Add skeleton for MQTT extension based on part of OPC-UA extension.
Edouard Tisserant <edouard@beremiz.fr>
parents:
diff
changeset
|
135 |
for row in rows: |
76295adcf940
WIP: Add skeleton for MQTT extension based on part of OPC-UA extension.
Edouard Tisserant <edouard@beremiz.fr>
parents:
diff
changeset
|
136 |
# remove it from our data structure |
76295adcf940
WIP: Add skeleton for MQTT extension based on part of OPC-UA extension.
Edouard Tisserant <edouard@beremiz.fr>
parents:
diff
changeset
|
137 |
del self.data[row] |
76295adcf940
WIP: Add skeleton for MQTT extension based on part of OPC-UA extension.
Edouard Tisserant <edouard@beremiz.fr>
parents:
diff
changeset
|
138 |
# notify the view(s) using this model that it has been removed |
76295adcf940
WIP: Add skeleton for MQTT extension based on part of OPC-UA extension.
Edouard Tisserant <edouard@beremiz.fr>
parents:
diff
changeset
|
139 |
self.RowDeleted(row) |
76295adcf940
WIP: Add skeleton for MQTT extension based on part of OPC-UA extension.
Edouard Tisserant <edouard@beremiz.fr>
parents:
diff
changeset
|
140 |
|
76295adcf940
WIP: Add skeleton for MQTT extension based on part of OPC-UA extension.
Edouard Tisserant <edouard@beremiz.fr>
parents:
diff
changeset
|
141 |
|
76295adcf940
WIP: Add skeleton for MQTT extension based on part of OPC-UA extension.
Edouard Tisserant <edouard@beremiz.fr>
parents:
diff
changeset
|
142 |
def AddRow(self, value): |
76295adcf940
WIP: Add skeleton for MQTT extension based on part of OPC-UA extension.
Edouard Tisserant <edouard@beremiz.fr>
parents:
diff
changeset
|
143 |
if self.data.append(value): |
76295adcf940
WIP: Add skeleton for MQTT extension based on part of OPC-UA extension.
Edouard Tisserant <edouard@beremiz.fr>
parents:
diff
changeset
|
144 |
# notify views |
76295adcf940
WIP: Add skeleton for MQTT extension based on part of OPC-UA extension.
Edouard Tisserant <edouard@beremiz.fr>
parents:
diff
changeset
|
145 |
self.RowAppended() |
76295adcf940
WIP: Add skeleton for MQTT extension based on part of OPC-UA extension.
Edouard Tisserant <edouard@beremiz.fr>
parents:
diff
changeset
|
146 |
|
76295adcf940
WIP: Add skeleton for MQTT extension based on part of OPC-UA extension.
Edouard Tisserant <edouard@beremiz.fr>
parents:
diff
changeset
|
147 |
def InsertDefaultRow(self, row): |
3988
150599d9073f
MQTT: WIP, subscibed topics have no "Retained" attribute.
Edouard Tisserant <edouard@beremiz.fr>
parents:
3987
diff
changeset
|
148 |
self.data.insert(row, self.dsc.lstcoldeflts[:]) |
3979
76295adcf940
WIP: Add skeleton for MQTT extension based on part of OPC-UA extension.
Edouard Tisserant <edouard@beremiz.fr>
parents:
diff
changeset
|
149 |
# notify views |
76295adcf940
WIP: Add skeleton for MQTT extension based on part of OPC-UA extension.
Edouard Tisserant <edouard@beremiz.fr>
parents:
diff
changeset
|
150 |
self.RowInserted(row) |
76295adcf940
WIP: Add skeleton for MQTT extension based on part of OPC-UA extension.
Edouard Tisserant <edouard@beremiz.fr>
parents:
diff
changeset
|
151 |
|
76295adcf940
WIP: Add skeleton for MQTT extension based on part of OPC-UA extension.
Edouard Tisserant <edouard@beremiz.fr>
parents:
diff
changeset
|
152 |
def ResetData(self): |
76295adcf940
WIP: Add skeleton for MQTT extension based on part of OPC-UA extension.
Edouard Tisserant <edouard@beremiz.fr>
parents:
diff
changeset
|
153 |
self.Reset(len(self.data)) |
76295adcf940
WIP: Add skeleton for MQTT extension based on part of OPC-UA extension.
Edouard Tisserant <edouard@beremiz.fr>
parents:
diff
changeset
|
154 |
|
3980
96acfee19caf
MQTT WIP: intermediate state, implementing MQTT client C code generator.
Edouard Tisserant <edouard@beremiz.fr>
parents:
3979
diff
changeset
|
155 |
class MQTTTopicListPanel(wx.Panel): |
4010
3779356cca8f
MQTT: add dropdown to select type assigned to a topic
Edouard Tisserant <edouard@beremiz.fr>
parents:
4005
diff
changeset
|
156 |
def __init__(self, parent, log, model, direction, types_getter): |
3979
76295adcf940
WIP: Add skeleton for MQTT extension based on part of OPC-UA extension.
Edouard Tisserant <edouard@beremiz.fr>
parents:
diff
changeset
|
157 |
self.log = log |
76295adcf940
WIP: Add skeleton for MQTT extension based on part of OPC-UA extension.
Edouard Tisserant <edouard@beremiz.fr>
parents:
diff
changeset
|
158 |
wx.Panel.__init__(self, parent, -1) |
76295adcf940
WIP: Add skeleton for MQTT extension based on part of OPC-UA extension.
Edouard Tisserant <edouard@beremiz.fr>
parents:
diff
changeset
|
159 |
|
76295adcf940
WIP: Add skeleton for MQTT extension based on part of OPC-UA extension.
Edouard Tisserant <edouard@beremiz.fr>
parents:
diff
changeset
|
160 |
self.dvc = dv.DataViewCtrl(self, |
76295adcf940
WIP: Add skeleton for MQTT extension based on part of OPC-UA extension.
Edouard Tisserant <edouard@beremiz.fr>
parents:
diff
changeset
|
161 |
style=wx.BORDER_THEME |
76295adcf940
WIP: Add skeleton for MQTT extension based on part of OPC-UA extension.
Edouard Tisserant <edouard@beremiz.fr>
parents:
diff
changeset
|
162 |
| dv.DV_ROW_LINES |
76295adcf940
WIP: Add skeleton for MQTT extension based on part of OPC-UA extension.
Edouard Tisserant <edouard@beremiz.fr>
parents:
diff
changeset
|
163 |
| dv.DV_HORIZ_RULES |
76295adcf940
WIP: Add skeleton for MQTT extension based on part of OPC-UA extension.
Edouard Tisserant <edouard@beremiz.fr>
parents:
diff
changeset
|
164 |
| dv.DV_VERT_RULES |
76295adcf940
WIP: Add skeleton for MQTT extension based on part of OPC-UA extension.
Edouard Tisserant <edouard@beremiz.fr>
parents:
diff
changeset
|
165 |
| dv.DV_MULTIPLE |
76295adcf940
WIP: Add skeleton for MQTT extension based on part of OPC-UA extension.
Edouard Tisserant <edouard@beremiz.fr>
parents:
diff
changeset
|
166 |
) |
76295adcf940
WIP: Add skeleton for MQTT extension based on part of OPC-UA extension.
Edouard Tisserant <edouard@beremiz.fr>
parents:
diff
changeset
|
167 |
|
76295adcf940
WIP: Add skeleton for MQTT extension based on part of OPC-UA extension.
Edouard Tisserant <edouard@beremiz.fr>
parents:
diff
changeset
|
168 |
self.model = model |
76295adcf940
WIP: Add skeleton for MQTT extension based on part of OPC-UA extension.
Edouard Tisserant <edouard@beremiz.fr>
parents:
diff
changeset
|
169 |
|
76295adcf940
WIP: Add skeleton for MQTT extension based on part of OPC-UA extension.
Edouard Tisserant <edouard@beremiz.fr>
parents:
diff
changeset
|
170 |
self.dvc.AssociateModel(self.model) |
76295adcf940
WIP: Add skeleton for MQTT extension based on part of OPC-UA extension.
Edouard Tisserant <edouard@beremiz.fr>
parents:
diff
changeset
|
171 |
|
4014
da52eabd0e6d
MQTT: Update available type choices when data types are changed in the IDE
Edouard Tisserant <edouard@beremiz.fr>
parents:
4013
diff
changeset
|
172 |
self.types_getter = types_getter |
da52eabd0e6d
MQTT: Update available type choices when data types are changed in the IDE
Edouard Tisserant <edouard@beremiz.fr>
parents:
4013
diff
changeset
|
173 |
self.direction = direction |
da52eabd0e6d
MQTT: Update available type choices when data types are changed in the IDE
Edouard Tisserant <edouard@beremiz.fr>
parents:
4013
diff
changeset
|
174 |
self.CreateDVCColumns() |
3979
76295adcf940
WIP: Add skeleton for MQTT extension based on part of OPC-UA extension.
Edouard Tisserant <edouard@beremiz.fr>
parents:
diff
changeset
|
175 |
|
76295adcf940
WIP: Add skeleton for MQTT extension based on part of OPC-UA extension.
Edouard Tisserant <edouard@beremiz.fr>
parents:
diff
changeset
|
176 |
self.Sizer = wx.BoxSizer(wx.VERTICAL) |
76295adcf940
WIP: Add skeleton for MQTT extension based on part of OPC-UA extension.
Edouard Tisserant <edouard@beremiz.fr>
parents:
diff
changeset
|
177 |
|
76295adcf940
WIP: Add skeleton for MQTT extension based on part of OPC-UA extension.
Edouard Tisserant <edouard@beremiz.fr>
parents:
diff
changeset
|
178 |
titlestr = direction + " variables" |
76295adcf940
WIP: Add skeleton for MQTT extension based on part of OPC-UA extension.
Edouard Tisserant <edouard@beremiz.fr>
parents:
diff
changeset
|
179 |
|
76295adcf940
WIP: Add skeleton for MQTT extension based on part of OPC-UA extension.
Edouard Tisserant <edouard@beremiz.fr>
parents:
diff
changeset
|
180 |
title = wx.StaticText(self, label = titlestr) |
76295adcf940
WIP: Add skeleton for MQTT extension based on part of OPC-UA extension.
Edouard Tisserant <edouard@beremiz.fr>
parents:
diff
changeset
|
181 |
|
76295adcf940
WIP: Add skeleton for MQTT extension based on part of OPC-UA extension.
Edouard Tisserant <edouard@beremiz.fr>
parents:
diff
changeset
|
182 |
addbt = wx.Button(self, label="Add") |
76295adcf940
WIP: Add skeleton for MQTT extension based on part of OPC-UA extension.
Edouard Tisserant <edouard@beremiz.fr>
parents:
diff
changeset
|
183 |
self.Bind(wx.EVT_BUTTON, self.OnAddRow, addbt) |
76295adcf940
WIP: Add skeleton for MQTT extension based on part of OPC-UA extension.
Edouard Tisserant <edouard@beremiz.fr>
parents:
diff
changeset
|
184 |
delbt = wx.Button(self, label="Delete") |
76295adcf940
WIP: Add skeleton for MQTT extension based on part of OPC-UA extension.
Edouard Tisserant <edouard@beremiz.fr>
parents:
diff
changeset
|
185 |
self.Bind(wx.EVT_BUTTON, self.OnDeleteRows, delbt) |
76295adcf940
WIP: Add skeleton for MQTT extension based on part of OPC-UA extension.
Edouard Tisserant <edouard@beremiz.fr>
parents:
diff
changeset
|
186 |
|
76295adcf940
WIP: Add skeleton for MQTT extension based on part of OPC-UA extension.
Edouard Tisserant <edouard@beremiz.fr>
parents:
diff
changeset
|
187 |
topsizer = wx.BoxSizer(wx.HORIZONTAL) |
76295adcf940
WIP: Add skeleton for MQTT extension based on part of OPC-UA extension.
Edouard Tisserant <edouard@beremiz.fr>
parents:
diff
changeset
|
188 |
topsizer.Add(title, 1, wx.ALIGN_CENTER_VERTICAL|wx.LEFT|wx.RIGHT, 5) |
76295adcf940
WIP: Add skeleton for MQTT extension based on part of OPC-UA extension.
Edouard Tisserant <edouard@beremiz.fr>
parents:
diff
changeset
|
189 |
topsizer.Add(addbt, 0, wx.LEFT|wx.RIGHT, 5) |
76295adcf940
WIP: Add skeleton for MQTT extension based on part of OPC-UA extension.
Edouard Tisserant <edouard@beremiz.fr>
parents:
diff
changeset
|
190 |
topsizer.Add(delbt, 0, wx.LEFT|wx.RIGHT, 5) |
76295adcf940
WIP: Add skeleton for MQTT extension based on part of OPC-UA extension.
Edouard Tisserant <edouard@beremiz.fr>
parents:
diff
changeset
|
191 |
self.Sizer.Add(topsizer, 0, wx.EXPAND|wx.TOP|wx.BOTTOM, 5) |
76295adcf940
WIP: Add skeleton for MQTT extension based on part of OPC-UA extension.
Edouard Tisserant <edouard@beremiz.fr>
parents:
diff
changeset
|
192 |
self.Sizer.Add(self.dvc, 1, wx.EXPAND) |
76295adcf940
WIP: Add skeleton for MQTT extension based on part of OPC-UA extension.
Edouard Tisserant <edouard@beremiz.fr>
parents:
diff
changeset
|
193 |
|
76295adcf940
WIP: Add skeleton for MQTT extension based on part of OPC-UA extension.
Edouard Tisserant <edouard@beremiz.fr>
parents:
diff
changeset
|
194 |
|
4014
da52eabd0e6d
MQTT: Update available type choices when data types are changed in the IDE
Edouard Tisserant <edouard@beremiz.fr>
parents:
4013
diff
changeset
|
195 |
def CreateDVCColumns(self): |
da52eabd0e6d
MQTT: Update available type choices when data types are changed in the IDE
Edouard Tisserant <edouard@beremiz.fr>
parents:
4013
diff
changeset
|
196 |
dsc = lstcoldsc[self.direction] |
da52eabd0e6d
MQTT: Update available type choices when data types are changed in the IDE
Edouard Tisserant <edouard@beremiz.fr>
parents:
4013
diff
changeset
|
197 |
for idx,(colname,width) in enumerate(zip(dsc.lstcolnames,dsc.lstcolwidths)): |
da52eabd0e6d
MQTT: Update available type choices when data types are changed in the IDE
Edouard Tisserant <edouard@beremiz.fr>
parents:
4013
diff
changeset
|
198 |
if colname == "Type": |
da52eabd0e6d
MQTT: Update available type choices when data types are changed in the IDE
Edouard Tisserant <edouard@beremiz.fr>
parents:
4013
diff
changeset
|
199 |
choice_DV_render = dv.DataViewChoiceRenderer(self.types_getter()) |
da52eabd0e6d
MQTT: Update available type choices when data types are changed in the IDE
Edouard Tisserant <edouard@beremiz.fr>
parents:
4013
diff
changeset
|
200 |
choice_DV_col = dv.DataViewColumn(colname, choice_DV_render, idx, width=width) |
da52eabd0e6d
MQTT: Update available type choices when data types are changed in the IDE
Edouard Tisserant <edouard@beremiz.fr>
parents:
4013
diff
changeset
|
201 |
self.dvc.AppendColumn(choice_DV_col) |
da52eabd0e6d
MQTT: Update available type choices when data types are changed in the IDE
Edouard Tisserant <edouard@beremiz.fr>
parents:
4013
diff
changeset
|
202 |
else: |
da52eabd0e6d
MQTT: Update available type choices when data types are changed in the IDE
Edouard Tisserant <edouard@beremiz.fr>
parents:
4013
diff
changeset
|
203 |
self.dvc.AppendTextColumn(colname, idx, width=width, mode=dv.DATAVIEW_CELL_EDITABLE) |
da52eabd0e6d
MQTT: Update available type choices when data types are changed in the IDE
Edouard Tisserant <edouard@beremiz.fr>
parents:
4013
diff
changeset
|
204 |
|
da52eabd0e6d
MQTT: Update available type choices when data types are changed in the IDE
Edouard Tisserant <edouard@beremiz.fr>
parents:
4013
diff
changeset
|
205 |
def ResetDVCColumns(self): |
da52eabd0e6d
MQTT: Update available type choices when data types are changed in the IDE
Edouard Tisserant <edouard@beremiz.fr>
parents:
4013
diff
changeset
|
206 |
self.dvc.ClearColumns() |
da52eabd0e6d
MQTT: Update available type choices when data types are changed in the IDE
Edouard Tisserant <edouard@beremiz.fr>
parents:
4013
diff
changeset
|
207 |
self.CreateDVCColumns() |
da52eabd0e6d
MQTT: Update available type choices when data types are changed in the IDE
Edouard Tisserant <edouard@beremiz.fr>
parents:
4013
diff
changeset
|
208 |
|
3979
76295adcf940
WIP: Add skeleton for MQTT extension based on part of OPC-UA extension.
Edouard Tisserant <edouard@beremiz.fr>
parents:
diff
changeset
|
209 |
def OnAddRow(self, evt): |
76295adcf940
WIP: Add skeleton for MQTT extension based on part of OPC-UA extension.
Edouard Tisserant <edouard@beremiz.fr>
parents:
diff
changeset
|
210 |
items = self.dvc.GetSelections() |
76295adcf940
WIP: Add skeleton for MQTT extension based on part of OPC-UA extension.
Edouard Tisserant <edouard@beremiz.fr>
parents:
diff
changeset
|
211 |
row = self.model.GetRow(items[0]) if items else 0 |
76295adcf940
WIP: Add skeleton for MQTT extension based on part of OPC-UA extension.
Edouard Tisserant <edouard@beremiz.fr>
parents:
diff
changeset
|
212 |
self.model.InsertDefaultRow(row) |
76295adcf940
WIP: Add skeleton for MQTT extension based on part of OPC-UA extension.
Edouard Tisserant <edouard@beremiz.fr>
parents:
diff
changeset
|
213 |
|
76295adcf940
WIP: Add skeleton for MQTT extension based on part of OPC-UA extension.
Edouard Tisserant <edouard@beremiz.fr>
parents:
diff
changeset
|
214 |
def OnDeleteRows(self, evt): |
76295adcf940
WIP: Add skeleton for MQTT extension based on part of OPC-UA extension.
Edouard Tisserant <edouard@beremiz.fr>
parents:
diff
changeset
|
215 |
items = self.dvc.GetSelections() |
76295adcf940
WIP: Add skeleton for MQTT extension based on part of OPC-UA extension.
Edouard Tisserant <edouard@beremiz.fr>
parents:
diff
changeset
|
216 |
rows = [self.model.GetRow(item) for item in items] |
76295adcf940
WIP: Add skeleton for MQTT extension based on part of OPC-UA extension.
Edouard Tisserant <edouard@beremiz.fr>
parents:
diff
changeset
|
217 |
self.model.DeleteRows(rows) |
76295adcf940
WIP: Add skeleton for MQTT extension based on part of OPC-UA extension.
Edouard Tisserant <edouard@beremiz.fr>
parents:
diff
changeset
|
218 |
|
76295adcf940
WIP: Add skeleton for MQTT extension based on part of OPC-UA extension.
Edouard Tisserant <edouard@beremiz.fr>
parents:
diff
changeset
|
219 |
|
3992
056657cd1484
MQTT: Fix overkill use of wx sizer
Edouard Tisserant <edouard@beremiz.fr>
parents:
3990
diff
changeset
|
220 |
class MQTTClientPanel(wx.SplitterWindow): |
4010
3779356cca8f
MQTT: add dropdown to select type assigned to a topic
Edouard Tisserant <edouard@beremiz.fr>
parents:
4005
diff
changeset
|
221 |
def __init__(self, parent, modeldata, log, types_getter): |
3979
76295adcf940
WIP: Add skeleton for MQTT extension based on part of OPC-UA extension.
Edouard Tisserant <edouard@beremiz.fr>
parents:
diff
changeset
|
222 |
self.log = log |
3992
056657cd1484
MQTT: Fix overkill use of wx sizer
Edouard Tisserant <edouard@beremiz.fr>
parents:
3990
diff
changeset
|
223 |
wx.SplitterWindow.__init__(self, parent, style=wx.SUNKEN_BORDER | wx.SP_3D) |
3979
76295adcf940
WIP: Add skeleton for MQTT extension based on part of OPC-UA extension.
Edouard Tisserant <edouard@beremiz.fr>
parents:
diff
changeset
|
224 |
|
76295adcf940
WIP: Add skeleton for MQTT extension based on part of OPC-UA extension.
Edouard Tisserant <edouard@beremiz.fr>
parents:
diff
changeset
|
225 |
self.selected_datas = modeldata |
3988
150599d9073f
MQTT: WIP, subscibed topics have no "Retained" attribute.
Edouard Tisserant <edouard@beremiz.fr>
parents:
3987
diff
changeset
|
226 |
self.selected_models = { direction:MQTTTopicListModel( |
150599d9073f
MQTT: WIP, subscibed topics have no "Retained" attribute.
Edouard Tisserant <edouard@beremiz.fr>
parents:
3987
diff
changeset
|
227 |
self.selected_datas[direction], log, direction) for direction in directions } |
3980
96acfee19caf
MQTT WIP: intermediate state, implementing MQTT client C code generator.
Edouard Tisserant <edouard@beremiz.fr>
parents:
3979
diff
changeset
|
228 |
self.selected_lists = { direction:MQTTTopicListPanel( |
3992
056657cd1484
MQTT: Fix overkill use of wx sizer
Edouard Tisserant <edouard@beremiz.fr>
parents:
3990
diff
changeset
|
229 |
self, log, |
4010
3779356cca8f
MQTT: add dropdown to select type assigned to a topic
Edouard Tisserant <edouard@beremiz.fr>
parents:
4005
diff
changeset
|
230 |
self.selected_models[direction], direction, types_getter) |
3979
76295adcf940
WIP: Add skeleton for MQTT extension based on part of OPC-UA extension.
Edouard Tisserant <edouard@beremiz.fr>
parents:
diff
changeset
|
231 |
for direction in directions } |
76295adcf940
WIP: Add skeleton for MQTT extension based on part of OPC-UA extension.
Edouard Tisserant <edouard@beremiz.fr>
parents:
diff
changeset
|
232 |
|
3992
056657cd1484
MQTT: Fix overkill use of wx sizer
Edouard Tisserant <edouard@beremiz.fr>
parents:
3990
diff
changeset
|
233 |
self.SplitHorizontally(*[self.selected_lists[direction] for direction in directions]+[300]) |
056657cd1484
MQTT: Fix overkill use of wx sizer
Edouard Tisserant <edouard@beremiz.fr>
parents:
3990
diff
changeset
|
234 |
|
3979
76295adcf940
WIP: Add skeleton for MQTT extension based on part of OPC-UA extension.
Edouard Tisserant <edouard@beremiz.fr>
parents:
diff
changeset
|
235 |
self.SetAutoLayout(True) |
76295adcf940
WIP: Add skeleton for MQTT extension based on part of OPC-UA extension.
Edouard Tisserant <edouard@beremiz.fr>
parents:
diff
changeset
|
236 |
|
4014
da52eabd0e6d
MQTT: Update available type choices when data types are changed in the IDE
Edouard Tisserant <edouard@beremiz.fr>
parents:
4013
diff
changeset
|
237 |
def RefreshView(self): |
da52eabd0e6d
MQTT: Update available type choices when data types are changed in the IDE
Edouard Tisserant <edouard@beremiz.fr>
parents:
4013
diff
changeset
|
238 |
for direction in directions: |
da52eabd0e6d
MQTT: Update available type choices when data types are changed in the IDE
Edouard Tisserant <edouard@beremiz.fr>
parents:
4013
diff
changeset
|
239 |
self.selected_lists[direction].ResetDVCColumns() |
da52eabd0e6d
MQTT: Update available type choices when data types are changed in the IDE
Edouard Tisserant <edouard@beremiz.fr>
parents:
4013
diff
changeset
|
240 |
|
3979
76295adcf940
WIP: Add skeleton for MQTT extension based on part of OPC-UA extension.
Edouard Tisserant <edouard@beremiz.fr>
parents:
diff
changeset
|
241 |
def OnClose(self): |
76295adcf940
WIP: Add skeleton for MQTT extension based on part of OPC-UA extension.
Edouard Tisserant <edouard@beremiz.fr>
parents:
diff
changeset
|
242 |
pass |
76295adcf940
WIP: Add skeleton for MQTT extension based on part of OPC-UA extension.
Edouard Tisserant <edouard@beremiz.fr>
parents:
diff
changeset
|
243 |
|
76295adcf940
WIP: Add skeleton for MQTT extension based on part of OPC-UA extension.
Edouard Tisserant <edouard@beremiz.fr>
parents:
diff
changeset
|
244 |
def __del__(self): |
76295adcf940
WIP: Add skeleton for MQTT extension based on part of OPC-UA extension.
Edouard Tisserant <edouard@beremiz.fr>
parents:
diff
changeset
|
245 |
self.OnClose() |
76295adcf940
WIP: Add skeleton for MQTT extension based on part of OPC-UA extension.
Edouard Tisserant <edouard@beremiz.fr>
parents:
diff
changeset
|
246 |
|
76295adcf940
WIP: Add skeleton for MQTT extension based on part of OPC-UA extension.
Edouard Tisserant <edouard@beremiz.fr>
parents:
diff
changeset
|
247 |
def Reset(self): |
76295adcf940
WIP: Add skeleton for MQTT extension based on part of OPC-UA extension.
Edouard Tisserant <edouard@beremiz.fr>
parents:
diff
changeset
|
248 |
for direction in directions: |
76295adcf940
WIP: Add skeleton for MQTT extension based on part of OPC-UA extension.
Edouard Tisserant <edouard@beremiz.fr>
parents:
diff
changeset
|
249 |
self.selected_models[direction].ResetData() |
76295adcf940
WIP: Add skeleton for MQTT extension based on part of OPC-UA extension.
Edouard Tisserant <edouard@beremiz.fr>
parents:
diff
changeset
|
250 |
|
76295adcf940
WIP: Add skeleton for MQTT extension based on part of OPC-UA extension.
Edouard Tisserant <edouard@beremiz.fr>
parents:
diff
changeset
|
251 |
|
76295adcf940
WIP: Add skeleton for MQTT extension based on part of OPC-UA extension.
Edouard Tisserant <edouard@beremiz.fr>
parents:
diff
changeset
|
252 |
class MQTTClientList(list): |
3988
150599d9073f
MQTT: WIP, subscibed topics have no "Retained" attribute.
Edouard Tisserant <edouard@beremiz.fr>
parents:
3987
diff
changeset
|
253 |
def __init__(self, log, change_callback, direction): |
3979
76295adcf940
WIP: Add skeleton for MQTT extension based on part of OPC-UA extension.
Edouard Tisserant <edouard@beremiz.fr>
parents:
diff
changeset
|
254 |
super(MQTTClientList, self).__init__(self) |
76295adcf940
WIP: Add skeleton for MQTT extension based on part of OPC-UA extension.
Edouard Tisserant <edouard@beremiz.fr>
parents:
diff
changeset
|
255 |
self.log = log |
76295adcf940
WIP: Add skeleton for MQTT extension based on part of OPC-UA extension.
Edouard Tisserant <edouard@beremiz.fr>
parents:
diff
changeset
|
256 |
self.change_callback = change_callback |
3988
150599d9073f
MQTT: WIP, subscibed topics have no "Retained" attribute.
Edouard Tisserant <edouard@beremiz.fr>
parents:
3987
diff
changeset
|
257 |
self.dsc = lstcoldsc[direction] |
3979
76295adcf940
WIP: Add skeleton for MQTT extension based on part of OPC-UA extension.
Edouard Tisserant <edouard@beremiz.fr>
parents:
diff
changeset
|
258 |
|
3999
1479acf750e2
MQTT: WIP fix modified status not being set when adding and modifying topics or attributes.
Edouard Tisserant <edouard@beremiz.fr>
parents:
3998
diff
changeset
|
259 |
def _filter_line(self, value): |
3988
150599d9073f
MQTT: WIP, subscibed topics have no "Retained" attribute.
Edouard Tisserant <edouard@beremiz.fr>
parents:
3987
diff
changeset
|
260 |
v = dict(list(zip(self.dsc.lstcolnames, value))) |
3979
76295adcf940
WIP: Add skeleton for MQTT extension based on part of OPC-UA extension.
Edouard Tisserant <edouard@beremiz.fr>
parents:
diff
changeset
|
261 |
|
76295adcf940
WIP: Add skeleton for MQTT extension based on part of OPC-UA extension.
Edouard Tisserant <edouard@beremiz.fr>
parents:
diff
changeset
|
262 |
if type(v["Location"]) != int: |
76295adcf940
WIP: Add skeleton for MQTT extension based on part of OPC-UA extension.
Edouard Tisserant <edouard@beremiz.fr>
parents:
diff
changeset
|
263 |
if len(self) == 0: |
76295adcf940
WIP: Add skeleton for MQTT extension based on part of OPC-UA extension.
Edouard Tisserant <edouard@beremiz.fr>
parents:
diff
changeset
|
264 |
v["Location"] = 0 |
76295adcf940
WIP: Add skeleton for MQTT extension based on part of OPC-UA extension.
Edouard Tisserant <edouard@beremiz.fr>
parents:
diff
changeset
|
265 |
else: |
3988
150599d9073f
MQTT: WIP, subscibed topics have no "Retained" attribute.
Edouard Tisserant <edouard@beremiz.fr>
parents:
3987
diff
changeset
|
266 |
iecnums = set(zip(*self)[self.dsc.Location_column]) |
3979
76295adcf940
WIP: Add skeleton for MQTT extension based on part of OPC-UA extension.
Edouard Tisserant <edouard@beremiz.fr>
parents:
diff
changeset
|
267 |
greatest = max(iecnums) |
76295adcf940
WIP: Add skeleton for MQTT extension based on part of OPC-UA extension.
Edouard Tisserant <edouard@beremiz.fr>
parents:
diff
changeset
|
268 |
holes = set(range(greatest)) - iecnums |
76295adcf940
WIP: Add skeleton for MQTT extension based on part of OPC-UA extension.
Edouard Tisserant <edouard@beremiz.fr>
parents:
diff
changeset
|
269 |
v["Location"] = min(holes) if holes else greatest+1 |
76295adcf940
WIP: Add skeleton for MQTT extension based on part of OPC-UA extension.
Edouard Tisserant <edouard@beremiz.fr>
parents:
diff
changeset
|
270 |
|
76295adcf940
WIP: Add skeleton for MQTT extension based on part of OPC-UA extension.
Edouard Tisserant <edouard@beremiz.fr>
parents:
diff
changeset
|
271 |
try: |
3988
150599d9073f
MQTT: WIP, subscibed topics have no "Retained" attribute.
Edouard Tisserant <edouard@beremiz.fr>
parents:
3987
diff
changeset
|
272 |
for t,n in zip(self.dsc.lstcoltypess, self.dsc.lstcolnames): |
3979
76295adcf940
WIP: Add skeleton for MQTT extension based on part of OPC-UA extension.
Edouard Tisserant <edouard@beremiz.fr>
parents:
diff
changeset
|
273 |
v[n] = t(v[n]) |
76295adcf940
WIP: Add skeleton for MQTT extension based on part of OPC-UA extension.
Edouard Tisserant <edouard@beremiz.fr>
parents:
diff
changeset
|
274 |
except ValueError: |
76295adcf940
WIP: Add skeleton for MQTT extension based on part of OPC-UA extension.
Edouard Tisserant <edouard@beremiz.fr>
parents:
diff
changeset
|
275 |
self.log("MQTT topic {} (Location={}) has invalid type\n".format(v["Topic"],v["Location"])) |
3999
1479acf750e2
MQTT: WIP fix modified status not being set when adding and modifying topics or attributes.
Edouard Tisserant <edouard@beremiz.fr>
parents:
3998
diff
changeset
|
276 |
return None |
1479acf750e2
MQTT: WIP fix modified status not being set when adding and modifying topics or attributes.
Edouard Tisserant <edouard@beremiz.fr>
parents:
3998
diff
changeset
|
277 |
|
1479acf750e2
MQTT: WIP fix modified status not being set when adding and modifying topics or attributes.
Edouard Tisserant <edouard@beremiz.fr>
parents:
3998
diff
changeset
|
278 |
if v["QoS"] not in QoS_values: |
1479acf750e2
MQTT: WIP fix modified status not being set when adding and modifying topics or attributes.
Edouard Tisserant <edouard@beremiz.fr>
parents:
3998
diff
changeset
|
279 |
self.log("Unknown QoS\n".format(value)) |
1479acf750e2
MQTT: WIP fix modified status not being set when adding and modifying topics or attributes.
Edouard Tisserant <edouard@beremiz.fr>
parents:
3998
diff
changeset
|
280 |
return None |
3979
76295adcf940
WIP: Add skeleton for MQTT extension based on part of OPC-UA extension.
Edouard Tisserant <edouard@beremiz.fr>
parents:
diff
changeset
|
281 |
|
3988
150599d9073f
MQTT: WIP, subscibed topics have no "Retained" attribute.
Edouard Tisserant <edouard@beremiz.fr>
parents:
3987
diff
changeset
|
282 |
if len(self)>0 and v["Topic"] in list(zip(*self))[self.dsc.lstcolnames.index("Topic")]: |
3979
76295adcf940
WIP: Add skeleton for MQTT extension based on part of OPC-UA extension.
Edouard Tisserant <edouard@beremiz.fr>
parents:
diff
changeset
|
283 |
self.log("MQTT topic {} (Location={}) already in the list\n".format(v["Topic"],v["Location"])) |
3999
1479acf750e2
MQTT: WIP fix modified status not being set when adding and modifying topics or attributes.
Edouard Tisserant <edouard@beremiz.fr>
parents:
3998
diff
changeset
|
284 |
return None |
1479acf750e2
MQTT: WIP fix modified status not being set when adding and modifying topics or attributes.
Edouard Tisserant <edouard@beremiz.fr>
parents:
3998
diff
changeset
|
285 |
|
1479acf750e2
MQTT: WIP fix modified status not being set when adding and modifying topics or attributes.
Edouard Tisserant <edouard@beremiz.fr>
parents:
3998
diff
changeset
|
286 |
return [v[n] for n in self.dsc.lstcolnames] |
1479acf750e2
MQTT: WIP fix modified status not being set when adding and modifying topics or attributes.
Edouard Tisserant <edouard@beremiz.fr>
parents:
3998
diff
changeset
|
287 |
|
1479acf750e2
MQTT: WIP fix modified status not being set when adding and modifying topics or attributes.
Edouard Tisserant <edouard@beremiz.fr>
parents:
3998
diff
changeset
|
288 |
def insert(self, row, value): |
1479acf750e2
MQTT: WIP fix modified status not being set when adding and modifying topics or attributes.
Edouard Tisserant <edouard@beremiz.fr>
parents:
3998
diff
changeset
|
289 |
v = self._filter_line(value) |
1479acf750e2
MQTT: WIP fix modified status not being set when adding and modifying topics or attributes.
Edouard Tisserant <edouard@beremiz.fr>
parents:
3998
diff
changeset
|
290 |
if v is not None: |
1479acf750e2
MQTT: WIP fix modified status not being set when adding and modifying topics or attributes.
Edouard Tisserant <edouard@beremiz.fr>
parents:
3998
diff
changeset
|
291 |
list.insert(self, row, v) |
1479acf750e2
MQTT: WIP fix modified status not being set when adding and modifying topics or attributes.
Edouard Tisserant <edouard@beremiz.fr>
parents:
3998
diff
changeset
|
292 |
self.change_callback() |
1479acf750e2
MQTT: WIP fix modified status not being set when adding and modifying topics or attributes.
Edouard Tisserant <edouard@beremiz.fr>
parents:
3998
diff
changeset
|
293 |
return True |
1479acf750e2
MQTT: WIP fix modified status not being set when adding and modifying topics or attributes.
Edouard Tisserant <edouard@beremiz.fr>
parents:
3998
diff
changeset
|
294 |
return False |
1479acf750e2
MQTT: WIP fix modified status not being set when adding and modifying topics or attributes.
Edouard Tisserant <edouard@beremiz.fr>
parents:
3998
diff
changeset
|
295 |
|
1479acf750e2
MQTT: WIP fix modified status not being set when adding and modifying topics or attributes.
Edouard Tisserant <edouard@beremiz.fr>
parents:
3998
diff
changeset
|
296 |
def append(self, value): |
1479acf750e2
MQTT: WIP fix modified status not being set when adding and modifying topics or attributes.
Edouard Tisserant <edouard@beremiz.fr>
parents:
3998
diff
changeset
|
297 |
v = self._filter_line(value) |
1479acf750e2
MQTT: WIP fix modified status not being set when adding and modifying topics or attributes.
Edouard Tisserant <edouard@beremiz.fr>
parents:
3998
diff
changeset
|
298 |
if v is not None: |
1479acf750e2
MQTT: WIP fix modified status not being set when adding and modifying topics or attributes.
Edouard Tisserant <edouard@beremiz.fr>
parents:
3998
diff
changeset
|
299 |
list.append(self, v) |
1479acf750e2
MQTT: WIP fix modified status not being set when adding and modifying topics or attributes.
Edouard Tisserant <edouard@beremiz.fr>
parents:
3998
diff
changeset
|
300 |
self.change_callback() |
1479acf750e2
MQTT: WIP fix modified status not being set when adding and modifying topics or attributes.
Edouard Tisserant <edouard@beremiz.fr>
parents:
3998
diff
changeset
|
301 |
return True |
1479acf750e2
MQTT: WIP fix modified status not being set when adding and modifying topics or attributes.
Edouard Tisserant <edouard@beremiz.fr>
parents:
3998
diff
changeset
|
302 |
return False |
1479acf750e2
MQTT: WIP fix modified status not being set when adding and modifying topics or attributes.
Edouard Tisserant <edouard@beremiz.fr>
parents:
3998
diff
changeset
|
303 |
|
1479acf750e2
MQTT: WIP fix modified status not being set when adding and modifying topics or attributes.
Edouard Tisserant <edouard@beremiz.fr>
parents:
3998
diff
changeset
|
304 |
def __setitem__(self, index, value): |
1479acf750e2
MQTT: WIP fix modified status not being set when adding and modifying topics or attributes.
Edouard Tisserant <edouard@beremiz.fr>
parents:
3998
diff
changeset
|
305 |
list.__setitem__(self, index, value) |
3979
76295adcf940
WIP: Add skeleton for MQTT extension based on part of OPC-UA extension.
Edouard Tisserant <edouard@beremiz.fr>
parents:
diff
changeset
|
306 |
self.change_callback() |
76295adcf940
WIP: Add skeleton for MQTT extension based on part of OPC-UA extension.
Edouard Tisserant <edouard@beremiz.fr>
parents:
diff
changeset
|
307 |
|
76295adcf940
WIP: Add skeleton for MQTT extension based on part of OPC-UA extension.
Edouard Tisserant <edouard@beremiz.fr>
parents:
diff
changeset
|
308 |
def __delitem__(self, index): |
76295adcf940
WIP: Add skeleton for MQTT extension based on part of OPC-UA extension.
Edouard Tisserant <edouard@beremiz.fr>
parents:
diff
changeset
|
309 |
list.__delitem__(self, index) |
76295adcf940
WIP: Add skeleton for MQTT extension based on part of OPC-UA extension.
Edouard Tisserant <edouard@beremiz.fr>
parents:
diff
changeset
|
310 |
self.change_callback() |
76295adcf940
WIP: Add skeleton for MQTT extension based on part of OPC-UA extension.
Edouard Tisserant <edouard@beremiz.fr>
parents:
diff
changeset
|
311 |
|
3999
1479acf750e2
MQTT: WIP fix modified status not being set when adding and modifying topics or attributes.
Edouard Tisserant <edouard@beremiz.fr>
parents:
3998
diff
changeset
|
312 |
|
3979
76295adcf940
WIP: Add skeleton for MQTT extension based on part of OPC-UA extension.
Edouard Tisserant <edouard@beremiz.fr>
parents:
diff
changeset
|
313 |
class MQTTClientModel(dict): |
76295adcf940
WIP: Add skeleton for MQTT extension based on part of OPC-UA extension.
Edouard Tisserant <edouard@beremiz.fr>
parents:
diff
changeset
|
314 |
def __init__(self, log, change_callback = lambda : None): |
76295adcf940
WIP: Add skeleton for MQTT extension based on part of OPC-UA extension.
Edouard Tisserant <edouard@beremiz.fr>
parents:
diff
changeset
|
315 |
super(MQTTClientModel, self).__init__() |
76295adcf940
WIP: Add skeleton for MQTT extension based on part of OPC-UA extension.
Edouard Tisserant <edouard@beremiz.fr>
parents:
diff
changeset
|
316 |
for direction in directions: |
3988
150599d9073f
MQTT: WIP, subscibed topics have no "Retained" attribute.
Edouard Tisserant <edouard@beremiz.fr>
parents:
3987
diff
changeset
|
317 |
self[direction] = MQTTClientList(log, change_callback, direction) |
3979
76295adcf940
WIP: Add skeleton for MQTT extension based on part of OPC-UA extension.
Edouard Tisserant <edouard@beremiz.fr>
parents:
diff
changeset
|
318 |
|
76295adcf940
WIP: Add skeleton for MQTT extension based on part of OPC-UA extension.
Edouard Tisserant <edouard@beremiz.fr>
parents:
diff
changeset
|
319 |
def LoadCSV(self,path): |
76295adcf940
WIP: Add skeleton for MQTT extension based on part of OPC-UA extension.
Edouard Tisserant <edouard@beremiz.fr>
parents:
diff
changeset
|
320 |
with open(path, 'r') as csvfile: |
76295adcf940
WIP: Add skeleton for MQTT extension based on part of OPC-UA extension.
Edouard Tisserant <edouard@beremiz.fr>
parents:
diff
changeset
|
321 |
reader = csv.reader(csvfile, delimiter=',', quotechar='"') |
76295adcf940
WIP: Add skeleton for MQTT extension based on part of OPC-UA extension.
Edouard Tisserant <edouard@beremiz.fr>
parents:
diff
changeset
|
322 |
buf = {direction:[] for direction, _model in self.iteritems()} |
76295adcf940
WIP: Add skeleton for MQTT extension based on part of OPC-UA extension.
Edouard Tisserant <edouard@beremiz.fr>
parents:
diff
changeset
|
323 |
for direction, model in self.iteritems(): |
76295adcf940
WIP: Add skeleton for MQTT extension based on part of OPC-UA extension.
Edouard Tisserant <edouard@beremiz.fr>
parents:
diff
changeset
|
324 |
self[direction][:] = [] |
76295adcf940
WIP: Add skeleton for MQTT extension based on part of OPC-UA extension.
Edouard Tisserant <edouard@beremiz.fr>
parents:
diff
changeset
|
325 |
for row in reader: |
76295adcf940
WIP: Add skeleton for MQTT extension based on part of OPC-UA extension.
Edouard Tisserant <edouard@beremiz.fr>
parents:
diff
changeset
|
326 |
direction = row[0] |
76295adcf940
WIP: Add skeleton for MQTT extension based on part of OPC-UA extension.
Edouard Tisserant <edouard@beremiz.fr>
parents:
diff
changeset
|
327 |
# avoids calling change callback when loading CSV |
3999
1479acf750e2
MQTT: WIP fix modified status not being set when adding and modifying topics or attributes.
Edouard Tisserant <edouard@beremiz.fr>
parents:
3998
diff
changeset
|
328 |
l = self[direction] |
1479acf750e2
MQTT: WIP fix modified status not being set when adding and modifying topics or attributes.
Edouard Tisserant <edouard@beremiz.fr>
parents:
3998
diff
changeset
|
329 |
v = l._filter_line(row[1:]) |
1479acf750e2
MQTT: WIP fix modified status not being set when adding and modifying topics or attributes.
Edouard Tisserant <edouard@beremiz.fr>
parents:
3998
diff
changeset
|
330 |
if v is not None: |
1479acf750e2
MQTT: WIP fix modified status not being set when adding and modifying topics or attributes.
Edouard Tisserant <edouard@beremiz.fr>
parents:
3998
diff
changeset
|
331 |
list.append(l,v) |
1479acf750e2
MQTT: WIP fix modified status not being set when adding and modifying topics or attributes.
Edouard Tisserant <edouard@beremiz.fr>
parents:
3998
diff
changeset
|
332 |
# TODO be verbose in case of malformed CSV |
3979
76295adcf940
WIP: Add skeleton for MQTT extension based on part of OPC-UA extension.
Edouard Tisserant <edouard@beremiz.fr>
parents:
diff
changeset
|
333 |
|
76295adcf940
WIP: Add skeleton for MQTT extension based on part of OPC-UA extension.
Edouard Tisserant <edouard@beremiz.fr>
parents:
diff
changeset
|
334 |
def SaveCSV(self,path): |
76295adcf940
WIP: Add skeleton for MQTT extension based on part of OPC-UA extension.
Edouard Tisserant <edouard@beremiz.fr>
parents:
diff
changeset
|
335 |
with open(path, 'w') as csvfile: |
76295adcf940
WIP: Add skeleton for MQTT extension based on part of OPC-UA extension.
Edouard Tisserant <edouard@beremiz.fr>
parents:
diff
changeset
|
336 |
for direction, data in self.items(): |
76295adcf940
WIP: Add skeleton for MQTT extension based on part of OPC-UA extension.
Edouard Tisserant <edouard@beremiz.fr>
parents:
diff
changeset
|
337 |
writer = csv.writer(csvfile, delimiter=',', |
76295adcf940
WIP: Add skeleton for MQTT extension based on part of OPC-UA extension.
Edouard Tisserant <edouard@beremiz.fr>
parents:
diff
changeset
|
338 |
quotechar='"', quoting=csv.QUOTE_MINIMAL) |
76295adcf940
WIP: Add skeleton for MQTT extension based on part of OPC-UA extension.
Edouard Tisserant <edouard@beremiz.fr>
parents:
diff
changeset
|
339 |
for row in data: |
76295adcf940
WIP: Add skeleton for MQTT extension based on part of OPC-UA extension.
Edouard Tisserant <edouard@beremiz.fr>
parents:
diff
changeset
|
340 |
writer.writerow([direction] + row) |
76295adcf940
WIP: Add skeleton for MQTT extension based on part of OPC-UA extension.
Edouard Tisserant <edouard@beremiz.fr>
parents:
diff
changeset
|
341 |
|
4012
6337c9c2c379
MQTT: add JSON payload corresponding to IEC Structured types
Edouard Tisserant <edouard@beremiz.fr>
parents:
4011
diff
changeset
|
342 |
def GenerateC(self, path, locstr, config, datatype_info_getter): |
3995
84a668564748
MQTT: take C part away from python code for readability.
Edouard Tisserant <edouard@beremiz.fr>
parents:
3994
diff
changeset
|
343 |
c_template_filepath = paths.AbsNeighbourFile(__file__, "mqtt_template.c") |
84a668564748
MQTT: take C part away from python code for readability.
Edouard Tisserant <edouard@beremiz.fr>
parents:
3994
diff
changeset
|
344 |
c_template_file = open(c_template_filepath , 'rb') |
84a668564748
MQTT: take C part away from python code for readability.
Edouard Tisserant <edouard@beremiz.fr>
parents:
3994
diff
changeset
|
345 |
c_template = c_template_file.read() |
84a668564748
MQTT: take C part away from python code for readability.
Edouard Tisserant <edouard@beremiz.fr>
parents:
3994
diff
changeset
|
346 |
c_template_file.close() |
3986
98bd0bb33ce4
MQTT: WIP, now connects to broker. Added MQTT 3 support and protocol version selection in IDE.
Edouard Tisserant <edouard@beremiz.fr>
parents:
3984
diff
changeset
|
347 |
|
4012
6337c9c2c379
MQTT: add JSON payload corresponding to IEC Structured types
Edouard Tisserant <edouard@beremiz.fr>
parents:
4011
diff
changeset
|
348 |
json_types = OD() |
6337c9c2c379
MQTT: add JSON payload corresponding to IEC Structured types
Edouard Tisserant <edouard@beremiz.fr>
parents:
4011
diff
changeset
|
349 |
|
3979
76295adcf940
WIP: Add skeleton for MQTT extension based on part of OPC-UA extension.
Edouard Tisserant <edouard@beremiz.fr>
parents:
diff
changeset
|
350 |
formatdict = dict( |
3989
987c69b1582f
MQTT: WIP, added publish thread waking-up when published variables change.
Edouard Tisserant <edouard@beremiz.fr>
parents:
3988
diff
changeset
|
351 |
locstr = locstr, |
987c69b1582f
MQTT: WIP, added publish thread waking-up when published variables change.
Edouard Tisserant <edouard@beremiz.fr>
parents:
3988
diff
changeset
|
352 |
uri = config["URI"], |
987c69b1582f
MQTT: WIP, added publish thread waking-up when published variables change.
Edouard Tisserant <edouard@beremiz.fr>
parents:
3988
diff
changeset
|
353 |
clientID = config["clientID"], |
987c69b1582f
MQTT: WIP, added publish thread waking-up when published variables change.
Edouard Tisserant <edouard@beremiz.fr>
parents:
3988
diff
changeset
|
354 |
decl = "", |
987c69b1582f
MQTT: WIP, added publish thread waking-up when published variables change.
Edouard Tisserant <edouard@beremiz.fr>
parents:
3988
diff
changeset
|
355 |
topics = "", |
987c69b1582f
MQTT: WIP, added publish thread waking-up when published variables change.
Edouard Tisserant <edouard@beremiz.fr>
parents:
3988
diff
changeset
|
356 |
cleanup = "", |
987c69b1582f
MQTT: WIP, added publish thread waking-up when published variables change.
Edouard Tisserant <edouard@beremiz.fr>
parents:
3988
diff
changeset
|
357 |
init = "", |
3998
0145c60b9560
MQTT: WIP, PLC starts even if MQTT client can't connect broker, and publish+subscribe again when reconnecting.
Edouard Tisserant <edouard@beremiz.fr>
parents:
3995
diff
changeset
|
358 |
init_pubsub = "", |
3989
987c69b1582f
MQTT: WIP, added publish thread waking-up when published variables change.
Edouard Tisserant <edouard@beremiz.fr>
parents:
3988
diff
changeset
|
359 |
retrieve = "", |
987c69b1582f
MQTT: WIP, added publish thread waking-up when published variables change.
Edouard Tisserant <edouard@beremiz.fr>
parents:
3988
diff
changeset
|
360 |
publish = "", |
4012
6337c9c2c379
MQTT: add JSON payload corresponding to IEC Structured types
Edouard Tisserant <edouard@beremiz.fr>
parents:
4011
diff
changeset
|
361 |
publish_changes = "", |
6337c9c2c379
MQTT: add JSON payload corresponding to IEC Structured types
Edouard Tisserant <edouard@beremiz.fr>
parents:
4011
diff
changeset
|
362 |
json_decl = "" |
3979
76295adcf940
WIP: Add skeleton for MQTT extension based on part of OPC-UA extension.
Edouard Tisserant <edouard@beremiz.fr>
parents:
diff
changeset
|
363 |
) |
76295adcf940
WIP: Add skeleton for MQTT extension based on part of OPC-UA extension.
Edouard Tisserant <edouard@beremiz.fr>
parents:
diff
changeset
|
364 |
|
3986
98bd0bb33ce4
MQTT: WIP, now connects to broker. Added MQTT 3 support and protocol version selection in IDE.
Edouard Tisserant <edouard@beremiz.fr>
parents:
3984
diff
changeset
|
365 |
|
98bd0bb33ce4
MQTT: WIP, now connects to broker. Added MQTT 3 support and protocol version selection in IDE.
Edouard Tisserant <edouard@beremiz.fr>
parents:
3984
diff
changeset
|
366 |
# Use Config's "MQTTVersion" to switch between protocol version at build time |
98bd0bb33ce4
MQTT: WIP, now connects to broker. Added MQTT 3 support and protocol version selection in IDE.
Edouard Tisserant <edouard@beremiz.fr>
parents:
3984
diff
changeset
|
367 |
if config["UseMQTT5"]: |
98bd0bb33ce4
MQTT: WIP, now connects to broker. Added MQTT 3 support and protocol version selection in IDE.
Edouard Tisserant <edouard@beremiz.fr>
parents:
3984
diff
changeset
|
368 |
formatdict["decl"] += """ |
98bd0bb33ce4
MQTT: WIP, now connects to broker. Added MQTT 3 support and protocol version selection in IDE.
Edouard Tisserant <edouard@beremiz.fr>
parents:
3984
diff
changeset
|
369 |
#define USE_MQTT_5""".format(**config) |
98bd0bb33ce4
MQTT: WIP, now connects to broker. Added MQTT 3 support and protocol version selection in IDE.
Edouard Tisserant <edouard@beremiz.fr>
parents:
3984
diff
changeset
|
370 |
|
3979
76295adcf940
WIP: Add skeleton for MQTT extension based on part of OPC-UA extension.
Edouard Tisserant <edouard@beremiz.fr>
parents:
diff
changeset
|
371 |
AuthType = config["AuthType"] |
76295adcf940
WIP: Add skeleton for MQTT extension based on part of OPC-UA extension.
Edouard Tisserant <edouard@beremiz.fr>
parents:
diff
changeset
|
372 |
if AuthType == "x509": |
4005
482452574fb4
MQTT: add SSL support
Edouard Tisserant <edouard@beremiz.fr>
parents:
3999
diff
changeset
|
373 |
for k in ["KeyStore","TrustStore"]: |
482452574fb4
MQTT: add SSL support
Edouard Tisserant <edouard@beremiz.fr>
parents:
3999
diff
changeset
|
374 |
config[k] = '"'+config[k]+'"' if config[k] else "NULL" |
3979
76295adcf940
WIP: Add skeleton for MQTT extension based on part of OPC-UA extension.
Edouard Tisserant <edouard@beremiz.fr>
parents:
diff
changeset
|
375 |
formatdict["init"] += """ |
4005
482452574fb4
MQTT: add SSL support
Edouard Tisserant <edouard@beremiz.fr>
parents:
3999
diff
changeset
|
376 |
INIT_x509({Verify:d}, {KeyStore}, {TrustStore})""".format(**config) |
482452574fb4
MQTT: add SSL support
Edouard Tisserant <edouard@beremiz.fr>
parents:
3999
diff
changeset
|
377 |
if AuthType == "PSK": |
482452574fb4
MQTT: add SSL support
Edouard Tisserant <edouard@beremiz.fr>
parents:
3999
diff
changeset
|
378 |
formatdict["init"] += """ |
482452574fb4
MQTT: add SSL support
Edouard Tisserant <edouard@beremiz.fr>
parents:
3999
diff
changeset
|
379 |
INIT_PSK("{Secret}", "{ID}")""".format(**config) |
3979
76295adcf940
WIP: Add skeleton for MQTT extension based on part of OPC-UA extension.
Edouard Tisserant <edouard@beremiz.fr>
parents:
diff
changeset
|
380 |
elif AuthType == "UserPassword": |
76295adcf940
WIP: Add skeleton for MQTT extension based on part of OPC-UA extension.
Edouard Tisserant <edouard@beremiz.fr>
parents:
diff
changeset
|
381 |
formatdict["init"] += """ |
76295adcf940
WIP: Add skeleton for MQTT extension based on part of OPC-UA extension.
Edouard Tisserant <edouard@beremiz.fr>
parents:
diff
changeset
|
382 |
INIT_UserPassword("{User}", "{Password}")""".format(**config) |
76295adcf940
WIP: Add skeleton for MQTT extension based on part of OPC-UA extension.
Edouard Tisserant <edouard@beremiz.fr>
parents:
diff
changeset
|
383 |
else: |
76295adcf940
WIP: Add skeleton for MQTT extension based on part of OPC-UA extension.
Edouard Tisserant <edouard@beremiz.fr>
parents:
diff
changeset
|
384 |
formatdict["init"] += """ |
76295adcf940
WIP: Add skeleton for MQTT extension based on part of OPC-UA extension.
Edouard Tisserant <edouard@beremiz.fr>
parents:
diff
changeset
|
385 |
INIT_NoAuth()""" |
76295adcf940
WIP: Add skeleton for MQTT extension based on part of OPC-UA extension.
Edouard Tisserant <edouard@beremiz.fr>
parents:
diff
changeset
|
386 |
|
3990
24656e0e8732
MQTT: WIP. Added handling of received messages (subscriptions)
Edouard Tisserant <edouard@beremiz.fr>
parents:
3989
diff
changeset
|
387 |
for row in self["output"]: |
24656e0e8732
MQTT: WIP. Added handling of received messages (subscriptions)
Edouard Tisserant <edouard@beremiz.fr>
parents:
3989
diff
changeset
|
388 |
Topic, QoS, _Retained, iec_type, iec_number = row |
24656e0e8732
MQTT: WIP. Added handling of received messages (subscriptions)
Edouard Tisserant <edouard@beremiz.fr>
parents:
3989
diff
changeset
|
389 |
Retained = 1 if _Retained=="True" else 0 |
4011
fdbb3c4ebbf6
MQTT: WIP supporting structured types : do not crash when generating C code if using location with no size
Edouard Tisserant <edouard@beremiz.fr>
parents:
4010
diff
changeset
|
390 |
if iec_type in MQTT_IEC_types: |
fdbb3c4ebbf6
MQTT: WIP supporting structured types : do not crash when generating C code if using location with no size
Edouard Tisserant <edouard@beremiz.fr>
parents:
4010
diff
changeset
|
391 |
C_type, iec_size_prefix = MQTT_IEC_types[iec_type] |
fdbb3c4ebbf6
MQTT: WIP supporting structured types : do not crash when generating C code if using location with no size
Edouard Tisserant <edouard@beremiz.fr>
parents:
4010
diff
changeset
|
392 |
c_loc_name = "__Q" + iec_size_prefix + locstr + "_" + str(iec_number) |
4012
6337c9c2c379
MQTT: add JSON payload corresponding to IEC Structured types
Edouard Tisserant <edouard@beremiz.fr>
parents:
4011
diff
changeset
|
393 |
encoding = "SIMPLE" |
4011
fdbb3c4ebbf6
MQTT: WIP supporting structured types : do not crash when generating C code if using location with no size
Edouard Tisserant <edouard@beremiz.fr>
parents:
4010
diff
changeset
|
394 |
else: |
fdbb3c4ebbf6
MQTT: WIP supporting structured types : do not crash when generating C code if using location with no size
Edouard Tisserant <edouard@beremiz.fr>
parents:
4010
diff
changeset
|
395 |
C_type = iec_type.upper(); |
fdbb3c4ebbf6
MQTT: WIP supporting structured types : do not crash when generating C code if using location with no size
Edouard Tisserant <edouard@beremiz.fr>
parents:
4010
diff
changeset
|
396 |
c_loc_name = "__Q" + locstr + "_" + str(iec_number) |
4012
6337c9c2c379
MQTT: add JSON payload corresponding to IEC Structured types
Edouard Tisserant <edouard@beremiz.fr>
parents:
4011
diff
changeset
|
397 |
json_types.setdefault(iec_type,OD()).setdefault("OUTPUT",[]).append(c_loc_name) |
6337c9c2c379
MQTT: add JSON payload corresponding to IEC Structured types
Edouard Tisserant <edouard@beremiz.fr>
parents:
4011
diff
changeset
|
398 |
encoding = "JSON" |
4011
fdbb3c4ebbf6
MQTT: WIP supporting structured types : do not crash when generating C code if using location with no size
Edouard Tisserant <edouard@beremiz.fr>
parents:
4010
diff
changeset
|
399 |
|
3990
24656e0e8732
MQTT: WIP. Added handling of received messages (subscriptions)
Edouard Tisserant <edouard@beremiz.fr>
parents:
3989
diff
changeset
|
400 |
|
24656e0e8732
MQTT: WIP. Added handling of received messages (subscriptions)
Edouard Tisserant <edouard@beremiz.fr>
parents:
3989
diff
changeset
|
401 |
formatdict["decl"] += """ |
3981
74035ea6792c
MQTT WIP: intermediate state, added perfect hash to map topic to variables
Edouard Tisserant <edouard@beremiz.fr>
parents:
3980
diff
changeset
|
402 |
DECL_VAR({iec_type}, {C_type}, {c_loc_name})""".format(**locals()) |
3998
0145c60b9560
MQTT: WIP, PLC starts even if MQTT client can't connect broker, and publish+subscribe again when reconnecting.
Edouard Tisserant <edouard@beremiz.fr>
parents:
3995
diff
changeset
|
403 |
formatdict["init_pubsub"] += """ |
4012
6337c9c2c379
MQTT: add JSON payload corresponding to IEC Structured types
Edouard Tisserant <edouard@beremiz.fr>
parents:
4011
diff
changeset
|
404 |
INIT_PUBLICATION({encoding}, {Topic}, {QoS}, {C_type}, {c_loc_name}, {Retained})""".format(**locals()) |
3990
24656e0e8732
MQTT: WIP. Added handling of received messages (subscriptions)
Edouard Tisserant <edouard@beremiz.fr>
parents:
3989
diff
changeset
|
405 |
formatdict["publish"] += """ |
24656e0e8732
MQTT: WIP. Added handling of received messages (subscriptions)
Edouard Tisserant <edouard@beremiz.fr>
parents:
3989
diff
changeset
|
406 |
WRITE_VALUE({c_loc_name}, {C_type})""".format(**locals()) |
24656e0e8732
MQTT: WIP. Added handling of received messages (subscriptions)
Edouard Tisserant <edouard@beremiz.fr>
parents:
3989
diff
changeset
|
407 |
formatdict["publish_changes"] += """ |
4012
6337c9c2c379
MQTT: add JSON payload corresponding to IEC Structured types
Edouard Tisserant <edouard@beremiz.fr>
parents:
4011
diff
changeset
|
408 |
PUBLISH_CHANGE({encoding}, {Topic}, {QoS}, {C_type}, {c_loc_name}, {Retained})""".format(**locals()) |
3990
24656e0e8732
MQTT: WIP. Added handling of received messages (subscriptions)
Edouard Tisserant <edouard@beremiz.fr>
parents:
3989
diff
changeset
|
409 |
|
24656e0e8732
MQTT: WIP. Added handling of received messages (subscriptions)
Edouard Tisserant <edouard@beremiz.fr>
parents:
3989
diff
changeset
|
410 |
# inputs need to be sorted for bisection search |
24656e0e8732
MQTT: WIP. Added handling of received messages (subscriptions)
Edouard Tisserant <edouard@beremiz.fr>
parents:
3989
diff
changeset
|
411 |
for row in sorted(self["input"]): |
24656e0e8732
MQTT: WIP. Added handling of received messages (subscriptions)
Edouard Tisserant <edouard@beremiz.fr>
parents:
3989
diff
changeset
|
412 |
Topic, QoS, iec_type, iec_number = row |
4011
fdbb3c4ebbf6
MQTT: WIP supporting structured types : do not crash when generating C code if using location with no size
Edouard Tisserant <edouard@beremiz.fr>
parents:
4010
diff
changeset
|
413 |
if iec_type in MQTT_IEC_types: |
fdbb3c4ebbf6
MQTT: WIP supporting structured types : do not crash when generating C code if using location with no size
Edouard Tisserant <edouard@beremiz.fr>
parents:
4010
diff
changeset
|
414 |
C_type, iec_size_prefix = MQTT_IEC_types[iec_type] |
fdbb3c4ebbf6
MQTT: WIP supporting structured types : do not crash when generating C code if using location with no size
Edouard Tisserant <edouard@beremiz.fr>
parents:
4010
diff
changeset
|
415 |
c_loc_name = "__I" + iec_size_prefix + locstr + "_" + str(iec_number) |
4012
6337c9c2c379
MQTT: add JSON payload corresponding to IEC Structured types
Edouard Tisserant <edouard@beremiz.fr>
parents:
4011
diff
changeset
|
416 |
init_topic_call = "INIT_TOPIC" |
4011
fdbb3c4ebbf6
MQTT: WIP supporting structured types : do not crash when generating C code if using location with no size
Edouard Tisserant <edouard@beremiz.fr>
parents:
4010
diff
changeset
|
417 |
else: |
fdbb3c4ebbf6
MQTT: WIP supporting structured types : do not crash when generating C code if using location with no size
Edouard Tisserant <edouard@beremiz.fr>
parents:
4010
diff
changeset
|
418 |
C_type = iec_type.upper(); |
fdbb3c4ebbf6
MQTT: WIP supporting structured types : do not crash when generating C code if using location with no size
Edouard Tisserant <edouard@beremiz.fr>
parents:
4010
diff
changeset
|
419 |
c_loc_name = "__I" + locstr + "_" + str(iec_number) |
4012
6337c9c2c379
MQTT: add JSON payload corresponding to IEC Structured types
Edouard Tisserant <edouard@beremiz.fr>
parents:
4011
diff
changeset
|
420 |
init_topic_call = "INIT_JSON_TOPIC" |
6337c9c2c379
MQTT: add JSON payload corresponding to IEC Structured types
Edouard Tisserant <edouard@beremiz.fr>
parents:
4011
diff
changeset
|
421 |
json_types.setdefault(iec_type,OD()).setdefault("INPUT",[]).append(c_loc_name) |
4011
fdbb3c4ebbf6
MQTT: WIP supporting structured types : do not crash when generating C code if using location with no size
Edouard Tisserant <edouard@beremiz.fr>
parents:
4010
diff
changeset
|
422 |
|
3990
24656e0e8732
MQTT: WIP. Added handling of received messages (subscriptions)
Edouard Tisserant <edouard@beremiz.fr>
parents:
3989
diff
changeset
|
423 |
formatdict["decl"] += """ |
24656e0e8732
MQTT: WIP. Added handling of received messages (subscriptions)
Edouard Tisserant <edouard@beremiz.fr>
parents:
3989
diff
changeset
|
424 |
DECL_VAR({iec_type}, {C_type}, {c_loc_name})""".format(**locals()) |
24656e0e8732
MQTT: WIP. Added handling of received messages (subscriptions)
Edouard Tisserant <edouard@beremiz.fr>
parents:
3989
diff
changeset
|
425 |
formatdict["topics"] += """ |
4012
6337c9c2c379
MQTT: add JSON payload corresponding to IEC Structured types
Edouard Tisserant <edouard@beremiz.fr>
parents:
4011
diff
changeset
|
426 |
{init_topic_call}({Topic}, {iec_type}, {c_loc_name})""".format(**locals()) |
3998
0145c60b9560
MQTT: WIP, PLC starts even if MQTT client can't connect broker, and publish+subscribe again when reconnecting.
Edouard Tisserant <edouard@beremiz.fr>
parents:
3995
diff
changeset
|
427 |
formatdict["init_pubsub"] += """ |
3984
883a85b9ebcc
MQTT: still WIP, generated C code builds and link.
Edouard Tisserant <edouard@beremiz.fr>
parents:
3981
diff
changeset
|
428 |
INIT_SUBSCRIPTION({Topic}, {QoS})""".format(**locals()) |
3990
24656e0e8732
MQTT: WIP. Added handling of received messages (subscriptions)
Edouard Tisserant <edouard@beremiz.fr>
parents:
3989
diff
changeset
|
429 |
formatdict["retrieve"] += """ |
24656e0e8732
MQTT: WIP. Added handling of received messages (subscriptions)
Edouard Tisserant <edouard@beremiz.fr>
parents:
3989
diff
changeset
|
430 |
READ_VALUE({c_loc_name}, {C_type})""".format(**locals()) |
3979
76295adcf940
WIP: Add skeleton for MQTT extension based on part of OPC-UA extension.
Edouard Tisserant <edouard@beremiz.fr>
parents:
diff
changeset
|
431 |
|
4012
6337c9c2c379
MQTT: add JSON payload corresponding to IEC Structured types
Edouard Tisserant <edouard@beremiz.fr>
parents:
4011
diff
changeset
|
432 |
def recurseJsonTypes(datatype, basetypes): |
6337c9c2c379
MQTT: add JSON payload corresponding to IEC Structured types
Edouard Tisserant <edouard@beremiz.fr>
parents:
4011
diff
changeset
|
433 |
basetypes.append(datatype) |
6337c9c2c379
MQTT: add JSON payload corresponding to IEC Structured types
Edouard Tisserant <edouard@beremiz.fr>
parents:
4011
diff
changeset
|
434 |
# add derivated type first fo we can expect the list to be sorted |
6337c9c2c379
MQTT: add JSON payload corresponding to IEC Structured types
Edouard Tisserant <edouard@beremiz.fr>
parents:
4011
diff
changeset
|
435 |
# with base types in last position |
6337c9c2c379
MQTT: add JSON payload corresponding to IEC Structured types
Edouard Tisserant <edouard@beremiz.fr>
parents:
4011
diff
changeset
|
436 |
infos = datatype_info_getter(datatype) |
6337c9c2c379
MQTT: add JSON payload corresponding to IEC Structured types
Edouard Tisserant <edouard@beremiz.fr>
parents:
4011
diff
changeset
|
437 |
for element in infos["elements"]: |
6337c9c2c379
MQTT: add JSON payload corresponding to IEC Structured types
Edouard Tisserant <edouard@beremiz.fr>
parents:
4011
diff
changeset
|
438 |
field_datatype = element["Type"] |
6337c9c2c379
MQTT: add JSON payload corresponding to IEC Structured types
Edouard Tisserant <edouard@beremiz.fr>
parents:
4011
diff
changeset
|
439 |
if field_datatype not in MQTT_IEC_types: |
6337c9c2c379
MQTT: add JSON payload corresponding to IEC Structured types
Edouard Tisserant <edouard@beremiz.fr>
parents:
4011
diff
changeset
|
440 |
recurseJsonTypes(field_datatype, basetypes) |
6337c9c2c379
MQTT: add JSON payload corresponding to IEC Structured types
Edouard Tisserant <edouard@beremiz.fr>
parents:
4011
diff
changeset
|
441 |
|
6337c9c2c379
MQTT: add JSON payload corresponding to IEC Structured types
Edouard Tisserant <edouard@beremiz.fr>
parents:
4011
diff
changeset
|
442 |
print(json_types) |
6337c9c2c379
MQTT: add JSON payload corresponding to IEC Structured types
Edouard Tisserant <edouard@beremiz.fr>
parents:
4011
diff
changeset
|
443 |
|
6337c9c2c379
MQTT: add JSON payload corresponding to IEC Structured types
Edouard Tisserant <edouard@beremiz.fr>
parents:
4011
diff
changeset
|
444 |
# collect all type dependencies |
6337c9c2c379
MQTT: add JSON payload corresponding to IEC Structured types
Edouard Tisserant <edouard@beremiz.fr>
parents:
4011
diff
changeset
|
445 |
basetypes=[] # use a list to keep them ordered |
6337c9c2c379
MQTT: add JSON payload corresponding to IEC Structured types
Edouard Tisserant <edouard@beremiz.fr>
parents:
4011
diff
changeset
|
446 |
for iec_type,_instances in json_types.items(): |
6337c9c2c379
MQTT: add JSON payload corresponding to IEC Structured types
Edouard Tisserant <edouard@beremiz.fr>
parents:
4011
diff
changeset
|
447 |
recurseJsonTypes(iec_type, basetypes) |
6337c9c2c379
MQTT: add JSON payload corresponding to IEC Structured types
Edouard Tisserant <edouard@beremiz.fr>
parents:
4011
diff
changeset
|
448 |
|
6337c9c2c379
MQTT: add JSON payload corresponding to IEC Structured types
Edouard Tisserant <edouard@beremiz.fr>
parents:
4011
diff
changeset
|
449 |
done_types = set() |
6337c9c2c379
MQTT: add JSON payload corresponding to IEC Structured types
Edouard Tisserant <edouard@beremiz.fr>
parents:
4011
diff
changeset
|
450 |
# go backard to get most derivated type definition last |
6337c9c2c379
MQTT: add JSON payload corresponding to IEC Structured types
Edouard Tisserant <edouard@beremiz.fr>
parents:
4011
diff
changeset
|
451 |
# so that CPP can always find base type deinition before |
6337c9c2c379
MQTT: add JSON payload corresponding to IEC Structured types
Edouard Tisserant <edouard@beremiz.fr>
parents:
4011
diff
changeset
|
452 |
for iec_type in reversed(basetypes): |
6337c9c2c379
MQTT: add JSON payload corresponding to IEC Structured types
Edouard Tisserant <edouard@beremiz.fr>
parents:
4011
diff
changeset
|
453 |
# avoid repeating type definition |
6337c9c2c379
MQTT: add JSON payload corresponding to IEC Structured types
Edouard Tisserant <edouard@beremiz.fr>
parents:
4011
diff
changeset
|
454 |
if iec_type in done_types: |
6337c9c2c379
MQTT: add JSON payload corresponding to IEC Structured types
Edouard Tisserant <edouard@beremiz.fr>
parents:
4011
diff
changeset
|
455 |
continue |
6337c9c2c379
MQTT: add JSON payload corresponding to IEC Structured types
Edouard Tisserant <edouard@beremiz.fr>
parents:
4011
diff
changeset
|
456 |
done_types.add(iec_type) |
6337c9c2c379
MQTT: add JSON payload corresponding to IEC Structured types
Edouard Tisserant <edouard@beremiz.fr>
parents:
4011
diff
changeset
|
457 |
|
6337c9c2c379
MQTT: add JSON payload corresponding to IEC Structured types
Edouard Tisserant <edouard@beremiz.fr>
parents:
4011
diff
changeset
|
458 |
C_type = iec_type.upper() |
6337c9c2c379
MQTT: add JSON payload corresponding to IEC Structured types
Edouard Tisserant <edouard@beremiz.fr>
parents:
4011
diff
changeset
|
459 |
json_decl = "#define TYPE_" + C_type + "(_P, _A) \\\n" |
6337c9c2c379
MQTT: add JSON payload corresponding to IEC Structured types
Edouard Tisserant <edouard@beremiz.fr>
parents:
4011
diff
changeset
|
460 |
|
6337c9c2c379
MQTT: add JSON payload corresponding to IEC Structured types
Edouard Tisserant <edouard@beremiz.fr>
parents:
4011
diff
changeset
|
461 |
infos = datatype_info_getter(iec_type) |
6337c9c2c379
MQTT: add JSON payload corresponding to IEC Structured types
Edouard Tisserant <edouard@beremiz.fr>
parents:
4011
diff
changeset
|
462 |
|
6337c9c2c379
MQTT: add JSON payload corresponding to IEC Structured types
Edouard Tisserant <edouard@beremiz.fr>
parents:
4011
diff
changeset
|
463 |
elements = infos["elements"] |
6337c9c2c379
MQTT: add JSON payload corresponding to IEC Structured types
Edouard Tisserant <edouard@beremiz.fr>
parents:
4011
diff
changeset
|
464 |
last = len(elements) - 1 |
6337c9c2c379
MQTT: add JSON payload corresponding to IEC Structured types
Edouard Tisserant <edouard@beremiz.fr>
parents:
4011
diff
changeset
|
465 |
for idx, element in enumerate(elements): |
6337c9c2c379
MQTT: add JSON payload corresponding to IEC Structured types
Edouard Tisserant <edouard@beremiz.fr>
parents:
4011
diff
changeset
|
466 |
field_iec_type = element["Type"] |
6337c9c2c379
MQTT: add JSON payload corresponding to IEC Structured types
Edouard Tisserant <edouard@beremiz.fr>
parents:
4011
diff
changeset
|
467 |
field_C_type = field_iec_type.upper() |
6337c9c2c379
MQTT: add JSON payload corresponding to IEC Structured types
Edouard Tisserant <edouard@beremiz.fr>
parents:
4011
diff
changeset
|
468 |
field_name = element["Name"].upper() |
6337c9c2c379
MQTT: add JSON payload corresponding to IEC Structured types
Edouard Tisserant <edouard@beremiz.fr>
parents:
4011
diff
changeset
|
469 |
if field_iec_type in MQTT_IEC_types: |
6337c9c2c379
MQTT: add JSON payload corresponding to IEC Structured types
Edouard Tisserant <edouard@beremiz.fr>
parents:
4011
diff
changeset
|
470 |
decl_type = "SIMPLE" |
6337c9c2c379
MQTT: add JSON payload corresponding to IEC Structured types
Edouard Tisserant <edouard@beremiz.fr>
parents:
4011
diff
changeset
|
471 |
else: |
6337c9c2c379
MQTT: add JSON payload corresponding to IEC Structured types
Edouard Tisserant <edouard@beremiz.fr>
parents:
4011
diff
changeset
|
472 |
decl_type = "OBJECT" |
6337c9c2c379
MQTT: add JSON payload corresponding to IEC Structured types
Edouard Tisserant <edouard@beremiz.fr>
parents:
4011
diff
changeset
|
473 |
|
6337c9c2c379
MQTT: add JSON payload corresponding to IEC Structured types
Edouard Tisserant <edouard@beremiz.fr>
parents:
4011
diff
changeset
|
474 |
json_decl += " _P##_"+decl_type+"(" + field_C_type + ", " + field_name + ", _A)" |
6337c9c2c379
MQTT: add JSON payload corresponding to IEC Structured types
Edouard Tisserant <edouard@beremiz.fr>
parents:
4011
diff
changeset
|
475 |
if idx != last: |
6337c9c2c379
MQTT: add JSON payload corresponding to IEC Structured types
Edouard Tisserant <edouard@beremiz.fr>
parents:
4011
diff
changeset
|
476 |
json_decl += " _P##_separator \\" |
6337c9c2c379
MQTT: add JSON payload corresponding to IEC Structured types
Edouard Tisserant <edouard@beremiz.fr>
parents:
4011
diff
changeset
|
477 |
else: |
6337c9c2c379
MQTT: add JSON payload corresponding to IEC Structured types
Edouard Tisserant <edouard@beremiz.fr>
parents:
4011
diff
changeset
|
478 |
json_decl += "\n" |
6337c9c2c379
MQTT: add JSON payload corresponding to IEC Structured types
Edouard Tisserant <edouard@beremiz.fr>
parents:
4011
diff
changeset
|
479 |
json_decl += "\n" |
6337c9c2c379
MQTT: add JSON payload corresponding to IEC Structured types
Edouard Tisserant <edouard@beremiz.fr>
parents:
4011
diff
changeset
|
480 |
|
6337c9c2c379
MQTT: add JSON payload corresponding to IEC Structured types
Edouard Tisserant <edouard@beremiz.fr>
parents:
4011
diff
changeset
|
481 |
|
6337c9c2c379
MQTT: add JSON payload corresponding to IEC Structured types
Edouard Tisserant <edouard@beremiz.fr>
parents:
4011
diff
changeset
|
482 |
formatdict["json_decl"] += json_decl |
6337c9c2c379
MQTT: add JSON payload corresponding to IEC Structured types
Edouard Tisserant <edouard@beremiz.fr>
parents:
4011
diff
changeset
|
483 |
|
6337c9c2c379
MQTT: add JSON payload corresponding to IEC Structured types
Edouard Tisserant <edouard@beremiz.fr>
parents:
4011
diff
changeset
|
484 |
for iec_type, instances in json_types.items(): |
6337c9c2c379
MQTT: add JSON payload corresponding to IEC Structured types
Edouard Tisserant <edouard@beremiz.fr>
parents:
4011
diff
changeset
|
485 |
C_type = iec_type.upper() |
6337c9c2c379
MQTT: add JSON payload corresponding to IEC Structured types
Edouard Tisserant <edouard@beremiz.fr>
parents:
4011
diff
changeset
|
486 |
for direction, instance_list in instances.items(): |
6337c9c2c379
MQTT: add JSON payload corresponding to IEC Structured types
Edouard Tisserant <edouard@beremiz.fr>
parents:
4011
diff
changeset
|
487 |
for c_loc_name in instance_list: |
6337c9c2c379
MQTT: add JSON payload corresponding to IEC Structured types
Edouard Tisserant <edouard@beremiz.fr>
parents:
4011
diff
changeset
|
488 |
formatdict["json_decl"] += "DECL_JSON_"+direction+"("+C_type+", "+c_loc_name+")\n" |
6337c9c2c379
MQTT: add JSON payload corresponding to IEC Structured types
Edouard Tisserant <edouard@beremiz.fr>
parents:
4011
diff
changeset
|
489 |
|
3995
84a668564748
MQTT: take C part away from python code for readability.
Edouard Tisserant <edouard@beremiz.fr>
parents:
3994
diff
changeset
|
490 |
Ccode = c_template.format(**formatdict) |
3986
98bd0bb33ce4
MQTT: WIP, now connects to broker. Added MQTT 3 support and protocol version selection in IDE.
Edouard Tisserant <edouard@beremiz.fr>
parents:
3984
diff
changeset
|
491 |
|
3979
76295adcf940
WIP: Add skeleton for MQTT extension based on part of OPC-UA extension.
Edouard Tisserant <edouard@beremiz.fr>
parents:
diff
changeset
|
492 |
return Ccode |
76295adcf940
WIP: Add skeleton for MQTT extension based on part of OPC-UA extension.
Edouard Tisserant <edouard@beremiz.fr>
parents:
diff
changeset
|
493 |