author | Edouard Tisserant <edouard@beremiz.fr> |
Thu, 04 Jul 2024 11:24:04 +0200 | |
changeset 3982 | 69d161fc2e08 |
parent 3981 | 74035ea6792c |
child 3984 | 883a85b9ebcc |
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 |
76295adcf940
WIP: Add skeleton for MQTT extension based on part of OPC-UA extension.
Edouard Tisserant <edouard@beremiz.fr>
parents:
diff
changeset
|
7 |
|
76295adcf940
WIP: Add skeleton for MQTT extension based on part of OPC-UA extension.
Edouard Tisserant <edouard@beremiz.fr>
parents:
diff
changeset
|
8 |
import wx |
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.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
|
10 |
|
3981
74035ea6792c
MQTT WIP: intermediate state, added perfect hash to map topic to variables
Edouard Tisserant <edouard@beremiz.fr>
parents:
3980
diff
changeset
|
11 |
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
|
12 |
|
76295adcf940
WIP: Add skeleton for MQTT extension based on part of OPC-UA extension.
Edouard Tisserant <edouard@beremiz.fr>
parents:
diff
changeset
|
13 |
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
|
14 |
# 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
|
15 |
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
|
16 |
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
|
17 |
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
|
18 |
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
|
19 |
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
|
20 |
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
|
21 |
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
|
22 |
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
|
23 |
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
|
24 |
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
|
25 |
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
|
26 |
) |
76295adcf940
WIP: Add skeleton for MQTT extension based on part of OPC-UA extension.
Edouard Tisserant <edouard@beremiz.fr>
parents:
diff
changeset
|
27 |
|
76295adcf940
WIP: Add skeleton for MQTT extension based on part of OPC-UA extension.
Edouard Tisserant <edouard@beremiz.fr>
parents:
diff
changeset
|
28 |
""" |
76295adcf940
WIP: Add skeleton for MQTT extension based on part of OPC-UA extension.
Edouard Tisserant <edouard@beremiz.fr>
parents:
diff
changeset
|
29 |
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
|
30 |
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
|
31 |
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
|
32 |
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
|
33 |
""" |
76295adcf940
WIP: Add skeleton for MQTT extension based on part of OPC-UA extension.
Edouard Tisserant <edouard@beremiz.fr>
parents:
diff
changeset
|
34 |
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
|
35 |
|
3980
96acfee19caf
MQTT WIP: intermediate state, implementing MQTT client C code generator.
Edouard Tisserant <edouard@beremiz.fr>
parents:
3979
diff
changeset
|
36 |
def boolean(v): |
96acfee19caf
MQTT WIP: intermediate state, implementing MQTT client C code generator.
Edouard Tisserant <edouard@beremiz.fr>
parents:
3979
diff
changeset
|
37 |
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
|
38 |
return False |
96acfee19caf
MQTT WIP: intermediate state, implementing MQTT client C code generator.
Edouard Tisserant <edouard@beremiz.fr>
parents:
3979
diff
changeset
|
39 |
else: |
96acfee19caf
MQTT WIP: intermediate state, implementing MQTT client C code generator.
Edouard Tisserant <edouard@beremiz.fr>
parents:
3979
diff
changeset
|
40 |
return bool(v) |
96acfee19caf
MQTT WIP: intermediate state, implementing MQTT client C code generator.
Edouard Tisserant <edouard@beremiz.fr>
parents:
3979
diff
changeset
|
41 |
|
96acfee19caf
MQTT WIP: intermediate state, implementing MQTT client C code generator.
Edouard Tisserant <edouard@beremiz.fr>
parents:
3979
diff
changeset
|
42 |
lstcolnames = [ "Topic", "QoS", "Retain", "Type", "Location"] |
96acfee19caf
MQTT WIP: intermediate state, implementing MQTT client C code generator.
Edouard Tisserant <edouard@beremiz.fr>
parents:
3979
diff
changeset
|
43 |
lstcolwidths = [ 100, 50, 100, 100, 50] |
96acfee19caf
MQTT WIP: intermediate state, implementing MQTT client C code generator.
Edouard Tisserant <edouard@beremiz.fr>
parents:
3979
diff
changeset
|
44 |
lstcoltypess = [ str, int, boolean, str, int] |
96acfee19caf
MQTT WIP: intermediate state, implementing MQTT client C code generator.
Edouard Tisserant <edouard@beremiz.fr>
parents:
3979
diff
changeset
|
45 |
lstcoldeflts = [ "a/b/c", "1", False, "DINT", "0"] |
3979
76295adcf940
WIP: Add skeleton for MQTT extension based on part of OPC-UA extension.
Edouard Tisserant <edouard@beremiz.fr>
parents:
diff
changeset
|
46 |
Location_column = lstcolnames.index("Location") |
76295adcf940
WIP: Add skeleton for MQTT extension based on part of OPC-UA extension.
Edouard Tisserant <edouard@beremiz.fr>
parents:
diff
changeset
|
47 |
|
76295adcf940
WIP: Add skeleton for MQTT extension based on part of OPC-UA extension.
Edouard Tisserant <edouard@beremiz.fr>
parents:
diff
changeset
|
48 |
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
|
49 |
|
76295adcf940
WIP: Add skeleton for MQTT extension based on part of OPC-UA extension.
Edouard Tisserant <edouard@beremiz.fr>
parents:
diff
changeset
|
50 |
authParams = { |
76295adcf940
WIP: Add skeleton for MQTT extension based on part of OPC-UA extension.
Edouard Tisserant <edouard@beremiz.fr>
parents:
diff
changeset
|
51 |
"x509":[ |
76295adcf940
WIP: Add skeleton for MQTT extension based on part of OPC-UA extension.
Edouard Tisserant <edouard@beremiz.fr>
parents:
diff
changeset
|
52 |
("Certificate", "certificate.der"), |
76295adcf940
WIP: Add skeleton for MQTT extension based on part of OPC-UA extension.
Edouard Tisserant <edouard@beremiz.fr>
parents:
diff
changeset
|
53 |
("PrivateKey", "private_key.pem")], |
76295adcf940
WIP: Add skeleton for MQTT extension based on part of OPC-UA extension.
Edouard Tisserant <edouard@beremiz.fr>
parents:
diff
changeset
|
54 |
"UserPassword":[ |
76295adcf940
WIP: Add skeleton for MQTT extension based on part of OPC-UA extension.
Edouard Tisserant <edouard@beremiz.fr>
parents:
diff
changeset
|
55 |
("User", None), |
76295adcf940
WIP: Add skeleton for MQTT extension based on part of OPC-UA extension.
Edouard Tisserant <edouard@beremiz.fr>
parents:
diff
changeset
|
56 |
("Password", None)]} |
76295adcf940
WIP: Add skeleton for MQTT extension based on part of OPC-UA extension.
Edouard Tisserant <edouard@beremiz.fr>
parents:
diff
changeset
|
57 |
|
3980
96acfee19caf
MQTT WIP: intermediate state, implementing MQTT client C code generator.
Edouard Tisserant <edouard@beremiz.fr>
parents:
3979
diff
changeset
|
58 |
class MQTTTopicListModel(dv.PyDataViewIndexListModel): |
3979
76295adcf940
WIP: Add skeleton for MQTT extension based on part of OPC-UA extension.
Edouard Tisserant <edouard@beremiz.fr>
parents:
diff
changeset
|
59 |
def __init__(self, data, log): |
76295adcf940
WIP: Add skeleton for MQTT extension based on part of OPC-UA extension.
Edouard Tisserant <edouard@beremiz.fr>
parents:
diff
changeset
|
60 |
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
|
61 |
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
|
62 |
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
|
63 |
|
76295adcf940
WIP: Add skeleton for MQTT extension based on part of OPC-UA extension.
Edouard Tisserant <edouard@beremiz.fr>
parents:
diff
changeset
|
64 |
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
|
65 |
return "string" |
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 |
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
|
68 |
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
|
69 |
|
76295adcf940
WIP: Add skeleton for MQTT extension based on part of OPC-UA extension.
Edouard Tisserant <edouard@beremiz.fr>
parents:
diff
changeset
|
70 |
# 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
|
71 |
def SetValueByRow(self, value, row, col): |
76295adcf940
WIP: Add skeleton for MQTT extension based on part of OPC-UA extension.
Edouard Tisserant <edouard@beremiz.fr>
parents:
diff
changeset
|
72 |
expectedtype = lstcoltypess[col] |
76295adcf940
WIP: Add skeleton for MQTT extension based on part of OPC-UA extension.
Edouard Tisserant <edouard@beremiz.fr>
parents:
diff
changeset
|
73 |
|
76295adcf940
WIP: Add skeleton for MQTT extension based on part of OPC-UA extension.
Edouard Tisserant <edouard@beremiz.fr>
parents:
diff
changeset
|
74 |
try: |
76295adcf940
WIP: Add skeleton for MQTT extension based on part of OPC-UA extension.
Edouard Tisserant <edouard@beremiz.fr>
parents:
diff
changeset
|
75 |
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
|
76 |
except ValueError: |
76295adcf940
WIP: Add skeleton for MQTT extension based on part of OPC-UA extension.
Edouard Tisserant <edouard@beremiz.fr>
parents:
diff
changeset
|
77 |
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
|
78 |
return False |
76295adcf940
WIP: Add skeleton for MQTT extension based on part of OPC-UA extension.
Edouard Tisserant <edouard@beremiz.fr>
parents:
diff
changeset
|
79 |
|
76295adcf940
WIP: Add skeleton for MQTT extension based on part of OPC-UA extension.
Edouard Tisserant <edouard@beremiz.fr>
parents:
diff
changeset
|
80 |
if col == lstcolnames.index("QoS") and v not in QoS_values: |
76295adcf940
WIP: Add skeleton for MQTT extension based on part of OPC-UA extension.
Edouard Tisserant <edouard@beremiz.fr>
parents:
diff
changeset
|
81 |
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
|
82 |
return False |
76295adcf940
WIP: Add skeleton for MQTT extension based on part of OPC-UA extension.
Edouard Tisserant <edouard@beremiz.fr>
parents:
diff
changeset
|
83 |
|
76295adcf940
WIP: Add skeleton for MQTT extension based on part of OPC-UA extension.
Edouard Tisserant <edouard@beremiz.fr>
parents:
diff
changeset
|
84 |
self.data[row][col] = v |
76295adcf940
WIP: Add skeleton for MQTT extension based on part of OPC-UA extension.
Edouard Tisserant <edouard@beremiz.fr>
parents:
diff
changeset
|
85 |
return True |
76295adcf940
WIP: Add skeleton for MQTT extension based on part of OPC-UA extension.
Edouard Tisserant <edouard@beremiz.fr>
parents:
diff
changeset
|
86 |
|
76295adcf940
WIP: Add skeleton for MQTT extension based on part of OPC-UA extension.
Edouard Tisserant <edouard@beremiz.fr>
parents:
diff
changeset
|
87 |
# 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
|
88 |
def GetColumnCount(self): |
76295adcf940
WIP: Add skeleton for MQTT extension based on part of OPC-UA extension.
Edouard Tisserant <edouard@beremiz.fr>
parents:
diff
changeset
|
89 |
return len(lstcolnames) |
76295adcf940
WIP: Add skeleton for MQTT extension based on part of OPC-UA extension.
Edouard Tisserant <edouard@beremiz.fr>
parents:
diff
changeset
|
90 |
|
76295adcf940
WIP: Add skeleton for MQTT extension based on part of OPC-UA extension.
Edouard Tisserant <edouard@beremiz.fr>
parents:
diff
changeset
|
91 |
# 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
|
92 |
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
|
93 |
#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
|
94 |
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
|
95 |
|
76295adcf940
WIP: Add skeleton for MQTT extension based on part of OPC-UA extension.
Edouard Tisserant <edouard@beremiz.fr>
parents:
diff
changeset
|
96 |
# 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
|
97 |
# 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
|
98 |
def GetAttrByRow(self, row, col, attr): |
76295adcf940
WIP: Add skeleton for MQTT extension based on part of OPC-UA extension.
Edouard Tisserant <edouard@beremiz.fr>
parents:
diff
changeset
|
99 |
if col == Location_column: |
76295adcf940
WIP: Add skeleton for MQTT extension based on part of OPC-UA extension.
Edouard Tisserant <edouard@beremiz.fr>
parents:
diff
changeset
|
100 |
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
|
101 |
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
|
102 |
return True |
76295adcf940
WIP: Add skeleton for MQTT extension based on part of OPC-UA extension.
Edouard Tisserant <edouard@beremiz.fr>
parents:
diff
changeset
|
103 |
return False |
76295adcf940
WIP: Add skeleton for MQTT extension based on part of OPC-UA extension.
Edouard Tisserant <edouard@beremiz.fr>
parents:
diff
changeset
|
104 |
|
76295adcf940
WIP: Add skeleton for MQTT extension based on part of OPC-UA extension.
Edouard Tisserant <edouard@beremiz.fr>
parents:
diff
changeset
|
105 |
|
76295adcf940
WIP: Add skeleton for MQTT extension based on part of OPC-UA extension.
Edouard Tisserant <edouard@beremiz.fr>
parents:
diff
changeset
|
106 |
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
|
107 |
# 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
|
108 |
# 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
|
109 |
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
|
110 |
|
76295adcf940
WIP: Add skeleton for MQTT extension based on part of OPC-UA extension.
Edouard Tisserant <edouard@beremiz.fr>
parents:
diff
changeset
|
111 |
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
|
112 |
# 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
|
113 |
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
|
114 |
# 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
|
115 |
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
|
116 |
|
76295adcf940
WIP: Add skeleton for MQTT extension based on part of OPC-UA extension.
Edouard Tisserant <edouard@beremiz.fr>
parents:
diff
changeset
|
117 |
|
76295adcf940
WIP: Add skeleton for MQTT extension based on part of OPC-UA extension.
Edouard Tisserant <edouard@beremiz.fr>
parents:
diff
changeset
|
118 |
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
|
119 |
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
|
120 |
# notify views |
76295adcf940
WIP: Add skeleton for MQTT extension based on part of OPC-UA extension.
Edouard Tisserant <edouard@beremiz.fr>
parents:
diff
changeset
|
121 |
self.RowAppended() |
76295adcf940
WIP: Add skeleton for MQTT extension based on part of OPC-UA extension.
Edouard Tisserant <edouard@beremiz.fr>
parents:
diff
changeset
|
122 |
|
76295adcf940
WIP: Add skeleton for MQTT extension based on part of OPC-UA extension.
Edouard Tisserant <edouard@beremiz.fr>
parents:
diff
changeset
|
123 |
def InsertDefaultRow(self, row): |
76295adcf940
WIP: Add skeleton for MQTT extension based on part of OPC-UA extension.
Edouard Tisserant <edouard@beremiz.fr>
parents:
diff
changeset
|
124 |
self.data.insert(row, lstcoldeflts[:]) |
76295adcf940
WIP: Add skeleton for MQTT extension based on part of OPC-UA extension.
Edouard Tisserant <edouard@beremiz.fr>
parents:
diff
changeset
|
125 |
# notify views |
76295adcf940
WIP: Add skeleton for MQTT extension based on part of OPC-UA extension.
Edouard Tisserant <edouard@beremiz.fr>
parents:
diff
changeset
|
126 |
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
|
127 |
|
76295adcf940
WIP: Add skeleton for MQTT extension based on part of OPC-UA extension.
Edouard Tisserant <edouard@beremiz.fr>
parents:
diff
changeset
|
128 |
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
|
129 |
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
|
130 |
|
3980
96acfee19caf
MQTT WIP: intermediate state, implementing MQTT client C code generator.
Edouard Tisserant <edouard@beremiz.fr>
parents:
3979
diff
changeset
|
131 |
class MQTTTopicListPanel(wx.Panel): |
3979
76295adcf940
WIP: Add skeleton for MQTT extension based on part of OPC-UA extension.
Edouard Tisserant <edouard@beremiz.fr>
parents:
diff
changeset
|
132 |
def __init__(self, parent, log, model, direction): |
76295adcf940
WIP: Add skeleton for MQTT extension based on part of OPC-UA extension.
Edouard Tisserant <edouard@beremiz.fr>
parents:
diff
changeset
|
133 |
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
|
134 |
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
|
135 |
|
76295adcf940
WIP: Add skeleton for MQTT extension based on part of OPC-UA extension.
Edouard Tisserant <edouard@beremiz.fr>
parents:
diff
changeset
|
136 |
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
|
137 |
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
|
138 |
| 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
|
139 |
| 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
|
140 |
| 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
|
141 |
| 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
|
142 |
) |
76295adcf940
WIP: Add skeleton for MQTT extension based on part of OPC-UA extension.
Edouard Tisserant <edouard@beremiz.fr>
parents:
diff
changeset
|
143 |
|
76295adcf940
WIP: Add skeleton for MQTT extension based on part of OPC-UA extension.
Edouard Tisserant <edouard@beremiz.fr>
parents:
diff
changeset
|
144 |
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
|
145 |
|
76295adcf940
WIP: Add skeleton for MQTT extension based on part of OPC-UA extension.
Edouard Tisserant <edouard@beremiz.fr>
parents:
diff
changeset
|
146 |
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
|
147 |
|
76295adcf940
WIP: Add skeleton for MQTT extension based on part of OPC-UA extension.
Edouard Tisserant <edouard@beremiz.fr>
parents:
diff
changeset
|
148 |
for idx,(colname,width) in enumerate(zip(lstcolnames,lstcolwidths)): |
76295adcf940
WIP: Add skeleton for MQTT extension based on part of OPC-UA extension.
Edouard Tisserant <edouard@beremiz.fr>
parents:
diff
changeset
|
149 |
self.dvc.AppendTextColumn(colname, idx, width=width, mode=dv.DATAVIEW_CELL_EDITABLE) |
76295adcf940
WIP: Add skeleton for MQTT extension based on part of OPC-UA extension.
Edouard Tisserant <edouard@beremiz.fr>
parents:
diff
changeset
|
150 |
|
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 |
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
|
153 |
|
76295adcf940
WIP: Add skeleton for MQTT extension based on part of OPC-UA extension.
Edouard Tisserant <edouard@beremiz.fr>
parents:
diff
changeset
|
154 |
self.direction = direction |
76295adcf940
WIP: Add skeleton for MQTT extension based on part of OPC-UA extension.
Edouard Tisserant <edouard@beremiz.fr>
parents:
diff
changeset
|
155 |
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
|
156 |
|
76295adcf940
WIP: Add skeleton for MQTT extension based on part of OPC-UA extension.
Edouard Tisserant <edouard@beremiz.fr>
parents:
diff
changeset
|
157 |
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
|
158 |
|
76295adcf940
WIP: Add skeleton for MQTT extension based on part of OPC-UA extension.
Edouard Tisserant <edouard@beremiz.fr>
parents:
diff
changeset
|
159 |
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
|
160 |
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
|
161 |
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
|
162 |
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
|
163 |
|
76295adcf940
WIP: Add skeleton for MQTT extension based on part of OPC-UA extension.
Edouard Tisserant <edouard@beremiz.fr>
parents:
diff
changeset
|
164 |
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
|
165 |
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
|
166 |
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
|
167 |
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
|
168 |
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
|
169 |
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
|
170 |
|
76295adcf940
WIP: Add skeleton for MQTT extension based on part of OPC-UA extension.
Edouard Tisserant <edouard@beremiz.fr>
parents:
diff
changeset
|
171 |
|
76295adcf940
WIP: Add skeleton for MQTT extension based on part of OPC-UA extension.
Edouard Tisserant <edouard@beremiz.fr>
parents:
diff
changeset
|
172 |
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
|
173 |
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
|
174 |
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
|
175 |
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
|
176 |
|
76295adcf940
WIP: Add skeleton for MQTT extension based on part of OPC-UA extension.
Edouard Tisserant <edouard@beremiz.fr>
parents:
diff
changeset
|
177 |
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
|
178 |
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
|
179 |
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
|
180 |
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
|
181 |
|
76295adcf940
WIP: Add skeleton for MQTT extension based on part of OPC-UA extension.
Edouard Tisserant <edouard@beremiz.fr>
parents:
diff
changeset
|
182 |
|
76295adcf940
WIP: Add skeleton for MQTT extension based on part of OPC-UA extension.
Edouard Tisserant <edouard@beremiz.fr>
parents:
diff
changeset
|
183 |
class MQTTClientPanel(wx.Panel): |
76295adcf940
WIP: Add skeleton for MQTT extension based on part of OPC-UA extension.
Edouard Tisserant <edouard@beremiz.fr>
parents:
diff
changeset
|
184 |
def __init__(self, parent, modeldata, log, config_getter): |
76295adcf940
WIP: Add skeleton for MQTT extension based on part of OPC-UA extension.
Edouard Tisserant <edouard@beremiz.fr>
parents:
diff
changeset
|
185 |
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
|
186 |
wx.Panel.__init__(self, parent) |
76295adcf940
WIP: Add skeleton for MQTT extension based on part of OPC-UA extension.
Edouard Tisserant <edouard@beremiz.fr>
parents:
diff
changeset
|
187 |
|
76295adcf940
WIP: Add skeleton for MQTT extension based on part of OPC-UA extension.
Edouard Tisserant <edouard@beremiz.fr>
parents:
diff
changeset
|
188 |
# TODO replace FlexGridSizer with a simpler one |
76295adcf940
WIP: Add skeleton for MQTT extension based on part of OPC-UA extension.
Edouard Tisserant <edouard@beremiz.fr>
parents:
diff
changeset
|
189 |
self.inout_sizer = wx.FlexGridSizer(cols=1, hgap=0, rows=2, vgap=0) |
76295adcf940
WIP: Add skeleton for MQTT extension based on part of OPC-UA extension.
Edouard Tisserant <edouard@beremiz.fr>
parents:
diff
changeset
|
190 |
self.inout_sizer.AddGrowableCol(0) |
76295adcf940
WIP: Add skeleton for MQTT extension based on part of OPC-UA extension.
Edouard Tisserant <edouard@beremiz.fr>
parents:
diff
changeset
|
191 |
self.inout_sizer.AddGrowableRow(0) |
76295adcf940
WIP: Add skeleton for MQTT extension based on part of OPC-UA extension.
Edouard Tisserant <edouard@beremiz.fr>
parents:
diff
changeset
|
192 |
|
76295adcf940
WIP: Add skeleton for MQTT extension based on part of OPC-UA extension.
Edouard Tisserant <edouard@beremiz.fr>
parents:
diff
changeset
|
193 |
self.config_getter = config_getter |
76295adcf940
WIP: Add skeleton for MQTT extension based on part of OPC-UA extension.
Edouard Tisserant <edouard@beremiz.fr>
parents:
diff
changeset
|
194 |
|
76295adcf940
WIP: Add skeleton for MQTT extension based on part of OPC-UA extension.
Edouard Tisserant <edouard@beremiz.fr>
parents:
diff
changeset
|
195 |
self.selected_splitter = wx.SplitterWindow(self, style=wx.SUNKEN_BORDER | wx.SP_3D) |
76295adcf940
WIP: Add skeleton for MQTT extension based on part of OPC-UA extension.
Edouard Tisserant <edouard@beremiz.fr>
parents:
diff
changeset
|
196 |
|
76295adcf940
WIP: Add skeleton for MQTT extension based on part of OPC-UA extension.
Edouard Tisserant <edouard@beremiz.fr>
parents:
diff
changeset
|
197 |
self.selected_datas = modeldata |
3980
96acfee19caf
MQTT WIP: intermediate state, implementing MQTT client C code generator.
Edouard Tisserant <edouard@beremiz.fr>
parents:
3979
diff
changeset
|
198 |
self.selected_models = { direction:MQTTTopicListModel(self.selected_datas[direction], log) for direction in directions } |
96acfee19caf
MQTT WIP: intermediate state, implementing MQTT client C code generator.
Edouard Tisserant <edouard@beremiz.fr>
parents:
3979
diff
changeset
|
199 |
self.selected_lists = { direction:MQTTTopicListPanel( |
3979
76295adcf940
WIP: Add skeleton for MQTT extension based on part of OPC-UA extension.
Edouard Tisserant <edouard@beremiz.fr>
parents:
diff
changeset
|
200 |
self.selected_splitter, log, |
76295adcf940
WIP: Add skeleton for MQTT extension based on part of OPC-UA extension.
Edouard Tisserant <edouard@beremiz.fr>
parents:
diff
changeset
|
201 |
self.selected_models[direction], direction) |
76295adcf940
WIP: Add skeleton for MQTT extension based on part of OPC-UA extension.
Edouard Tisserant <edouard@beremiz.fr>
parents:
diff
changeset
|
202 |
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
|
203 |
|
76295adcf940
WIP: Add skeleton for MQTT extension based on part of OPC-UA extension.
Edouard Tisserant <edouard@beremiz.fr>
parents:
diff
changeset
|
204 |
self.selected_splitter.SplitHorizontally(*[self.selected_lists[direction] for direction in directions]+[300]) |
76295adcf940
WIP: Add skeleton for MQTT extension based on part of OPC-UA extension.
Edouard Tisserant <edouard@beremiz.fr>
parents:
diff
changeset
|
205 |
|
76295adcf940
WIP: Add skeleton for MQTT extension based on part of OPC-UA extension.
Edouard Tisserant <edouard@beremiz.fr>
parents:
diff
changeset
|
206 |
self.inout_sizer.Add(self.selected_splitter, flag=wx.GROW) |
76295adcf940
WIP: Add skeleton for MQTT extension based on part of OPC-UA extension.
Edouard Tisserant <edouard@beremiz.fr>
parents:
diff
changeset
|
207 |
self.inout_sizer.Layout() |
76295adcf940
WIP: Add skeleton for MQTT extension based on part of OPC-UA extension.
Edouard Tisserant <edouard@beremiz.fr>
parents:
diff
changeset
|
208 |
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
|
209 |
self.SetSizer(self.inout_sizer) |
76295adcf940
WIP: Add skeleton for MQTT extension based on part of OPC-UA extension.
Edouard Tisserant <edouard@beremiz.fr>
parents:
diff
changeset
|
210 |
|
76295adcf940
WIP: Add skeleton for MQTT extension based on part of OPC-UA extension.
Edouard Tisserant <edouard@beremiz.fr>
parents:
diff
changeset
|
211 |
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
|
212 |
pass |
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 __del__(self): |
76295adcf940
WIP: Add skeleton for MQTT extension based on part of OPC-UA extension.
Edouard Tisserant <edouard@beremiz.fr>
parents:
diff
changeset
|
215 |
self.OnClose() |
76295adcf940
WIP: Add skeleton for MQTT extension based on part of OPC-UA extension.
Edouard Tisserant <edouard@beremiz.fr>
parents:
diff
changeset
|
216 |
|
76295adcf940
WIP: Add skeleton for MQTT extension based on part of OPC-UA extension.
Edouard Tisserant <edouard@beremiz.fr>
parents:
diff
changeset
|
217 |
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
|
218 |
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
|
219 |
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
|
220 |
|
76295adcf940
WIP: Add skeleton for MQTT extension based on part of OPC-UA extension.
Edouard Tisserant <edouard@beremiz.fr>
parents:
diff
changeset
|
221 |
|
76295adcf940
WIP: Add skeleton for MQTT extension based on part of OPC-UA extension.
Edouard Tisserant <edouard@beremiz.fr>
parents:
diff
changeset
|
222 |
class MQTTClientList(list): |
76295adcf940
WIP: Add skeleton for MQTT extension based on part of OPC-UA extension.
Edouard Tisserant <edouard@beremiz.fr>
parents:
diff
changeset
|
223 |
def __init__(self, log, change_callback): |
76295adcf940
WIP: Add skeleton for MQTT extension based on part of OPC-UA extension.
Edouard Tisserant <edouard@beremiz.fr>
parents:
diff
changeset
|
224 |
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
|
225 |
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
|
226 |
self.change_callback = change_callback |
76295adcf940
WIP: Add skeleton for MQTT extension based on part of OPC-UA extension.
Edouard Tisserant <edouard@beremiz.fr>
parents:
diff
changeset
|
227 |
|
76295adcf940
WIP: Add skeleton for MQTT extension based on part of OPC-UA extension.
Edouard Tisserant <edouard@beremiz.fr>
parents:
diff
changeset
|
228 |
def append(self, value): |
76295adcf940
WIP: Add skeleton for MQTT extension based on part of OPC-UA extension.
Edouard Tisserant <edouard@beremiz.fr>
parents:
diff
changeset
|
229 |
v = dict(list(zip(lstcolnames, value))) |
76295adcf940
WIP: Add skeleton for MQTT extension based on part of OPC-UA extension.
Edouard Tisserant <edouard@beremiz.fr>
parents:
diff
changeset
|
230 |
|
76295adcf940
WIP: Add skeleton for MQTT extension based on part of OPC-UA extension.
Edouard Tisserant <edouard@beremiz.fr>
parents:
diff
changeset
|
231 |
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
|
232 |
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
|
233 |
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
|
234 |
else: |
76295adcf940
WIP: Add skeleton for MQTT extension based on part of OPC-UA extension.
Edouard Tisserant <edouard@beremiz.fr>
parents:
diff
changeset
|
235 |
iecnums = set(zip(*self)[Location_column]) |
76295adcf940
WIP: Add skeleton for MQTT extension based on part of OPC-UA extension.
Edouard Tisserant <edouard@beremiz.fr>
parents:
diff
changeset
|
236 |
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
|
237 |
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
|
238 |
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
|
239 |
|
76295adcf940
WIP: Add skeleton for MQTT extension based on part of OPC-UA extension.
Edouard Tisserant <edouard@beremiz.fr>
parents:
diff
changeset
|
240 |
if v["QoS"] not in QoS_values: |
76295adcf940
WIP: Add skeleton for MQTT extension based on part of OPC-UA extension.
Edouard Tisserant <edouard@beremiz.fr>
parents:
diff
changeset
|
241 |
self.log("Unknown QoS\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
|
242 |
return False |
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 |
try: |
76295adcf940
WIP: Add skeleton for MQTT extension based on part of OPC-UA extension.
Edouard Tisserant <edouard@beremiz.fr>
parents:
diff
changeset
|
245 |
for t,n in zip(lstcoltypess, lstcolnames): |
76295adcf940
WIP: Add skeleton for MQTT extension based on part of OPC-UA extension.
Edouard Tisserant <edouard@beremiz.fr>
parents:
diff
changeset
|
246 |
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
|
247 |
except ValueError: |
76295adcf940
WIP: Add skeleton for MQTT extension based on part of OPC-UA extension.
Edouard Tisserant <edouard@beremiz.fr>
parents:
diff
changeset
|
248 |
self.log("MQTT topic {} (Location={}) has invalid type\n".format(v["Topic"],v["Location"])) |
76295adcf940
WIP: Add skeleton for MQTT extension based on part of OPC-UA extension.
Edouard Tisserant <edouard@beremiz.fr>
parents:
diff
changeset
|
249 |
return False |
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 |
if len(self)>0 and v["Topic"] in list(zip(*self))[lstcolnames.index("Topic")]: |
76295adcf940
WIP: Add skeleton for MQTT extension based on part of OPC-UA extension.
Edouard Tisserant <edouard@beremiz.fr>
parents:
diff
changeset
|
252 |
self.log("MQTT topic {} (Location={}) already in the list\n".format(v["Topic"],v["Location"])) |
76295adcf940
WIP: Add skeleton for MQTT extension based on part of OPC-UA extension.
Edouard Tisserant <edouard@beremiz.fr>
parents:
diff
changeset
|
253 |
return False |
76295adcf940
WIP: Add skeleton for MQTT extension based on part of OPC-UA extension.
Edouard Tisserant <edouard@beremiz.fr>
parents:
diff
changeset
|
254 |
|
76295adcf940
WIP: Add skeleton for MQTT extension based on part of OPC-UA extension.
Edouard Tisserant <edouard@beremiz.fr>
parents:
diff
changeset
|
255 |
list.append(self, [v[n] for n in lstcolnames]) |
76295adcf940
WIP: Add skeleton for MQTT extension based on part of OPC-UA extension.
Edouard Tisserant <edouard@beremiz.fr>
parents:
diff
changeset
|
256 |
|
76295adcf940
WIP: Add skeleton for MQTT extension based on part of OPC-UA extension.
Edouard Tisserant <edouard@beremiz.fr>
parents:
diff
changeset
|
257 |
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
|
258 |
|
76295adcf940
WIP: Add skeleton for MQTT extension based on part of OPC-UA extension.
Edouard Tisserant <edouard@beremiz.fr>
parents:
diff
changeset
|
259 |
return True |
76295adcf940
WIP: Add skeleton for MQTT extension based on part of OPC-UA extension.
Edouard Tisserant <edouard@beremiz.fr>
parents:
diff
changeset
|
260 |
|
76295adcf940
WIP: Add skeleton for MQTT extension based on part of OPC-UA extension.
Edouard Tisserant <edouard@beremiz.fr>
parents:
diff
changeset
|
261 |
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
|
262 |
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
|
263 |
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
|
264 |
|
76295adcf940
WIP: Add skeleton for MQTT extension based on part of OPC-UA extension.
Edouard Tisserant <edouard@beremiz.fr>
parents:
diff
changeset
|
265 |
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
|
266 |
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
|
267 |
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
|
268 |
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
|
269 |
self[direction] = MQTTClientList(log, change_callback) |
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 |
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
|
272 |
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
|
273 |
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
|
274 |
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
|
275 |
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
|
276 |
self[direction][:] = [] |
76295adcf940
WIP: Add skeleton for MQTT extension based on part of OPC-UA extension.
Edouard Tisserant <edouard@beremiz.fr>
parents:
diff
changeset
|
277 |
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
|
278 |
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
|
279 |
# avoids calling change callback when loading CSV |
76295adcf940
WIP: Add skeleton for MQTT extension based on part of OPC-UA extension.
Edouard Tisserant <edouard@beremiz.fr>
parents:
diff
changeset
|
280 |
list.append(self[direction],row[1:]) |
76295adcf940
WIP: Add skeleton for MQTT extension based on part of OPC-UA extension.
Edouard Tisserant <edouard@beremiz.fr>
parents:
diff
changeset
|
281 |
|
76295adcf940
WIP: Add skeleton for MQTT extension based on part of OPC-UA extension.
Edouard Tisserant <edouard@beremiz.fr>
parents:
diff
changeset
|
282 |
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
|
283 |
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
|
284 |
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
|
285 |
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
|
286 |
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
|
287 |
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
|
288 |
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
|
289 |
|
3981
74035ea6792c
MQTT WIP: intermediate state, added perfect hash to map topic to variables
Edouard Tisserant <edouard@beremiz.fr>
parents:
3980
diff
changeset
|
290 |
def _TopicsPerfectHash(self, topics): |
74035ea6792c
MQTT WIP: intermediate state, added perfect hash to map topic to variables
Edouard Tisserant <edouard@beremiz.fr>
parents:
3980
diff
changeset
|
291 |
template = """ |
74035ea6792c
MQTT WIP: intermediate state, added perfect hash to map topic to variables
Edouard Tisserant <edouard@beremiz.fr>
parents:
3980
diff
changeset
|
292 |
#define NK $NK /* number of keys */ |
74035ea6792c
MQTT WIP: intermediate state, added perfect hash to map topic to variables
Edouard Tisserant <edouard@beremiz.fr>
parents:
3980
diff
changeset
|
293 |
#define NG $NG /* number of vertices */ |
74035ea6792c
MQTT WIP: intermediate state, added perfect hash to map topic to variables
Edouard Tisserant <edouard@beremiz.fr>
parents:
3980
diff
changeset
|
294 |
#define NS $NS /* length of array T1 and T2 */ |
74035ea6792c
MQTT WIP: intermediate state, added perfect hash to map topic to variables
Edouard Tisserant <edouard@beremiz.fr>
parents:
3980
diff
changeset
|
295 |
|
74035ea6792c
MQTT WIP: intermediate state, added perfect hash to map topic to variables
Edouard Tisserant <edouard@beremiz.fr>
parents:
3980
diff
changeset
|
296 |
int S1[] = {$S1}; |
74035ea6792c
MQTT WIP: intermediate state, added perfect hash to map topic to variables
Edouard Tisserant <edouard@beremiz.fr>
parents:
3980
diff
changeset
|
297 |
int S2[] = {$S2}; |
74035ea6792c
MQTT WIP: intermediate state, added perfect hash to map topic to variables
Edouard Tisserant <edouard@beremiz.fr>
parents:
3980
diff
changeset
|
298 |
int G[] = {$G}; |
74035ea6792c
MQTT WIP: intermediate state, added perfect hash to map topic to variables
Edouard Tisserant <edouard@beremiz.fr>
parents:
3980
diff
changeset
|
299 |
char *K[] = {$K}; |
74035ea6792c
MQTT WIP: intermediate state, added perfect hash to map topic to variables
Edouard Tisserant <edouard@beremiz.fr>
parents:
3980
diff
changeset
|
300 |
""" |
74035ea6792c
MQTT WIP: intermediate state, added perfect hash to map topic to variables
Edouard Tisserant <edouard@beremiz.fr>
parents:
3980
diff
changeset
|
301 |
code = generate_code(topics, Hash=IntSaltHash, template=template) |
74035ea6792c
MQTT WIP: intermediate state, added perfect hash to map topic to variables
Edouard Tisserant <edouard@beremiz.fr>
parents:
3980
diff
changeset
|
302 |
code += """ |
74035ea6792c
MQTT WIP: intermediate state, added perfect hash to map topic to variables
Edouard Tisserant <edouard@beremiz.fr>
parents:
3980
diff
changeset
|
303 |
/* return index of key in K if key is found, -1 otherwise */ |
74035ea6792c
MQTT WIP: intermediate state, added perfect hash to map topic to variables
Edouard Tisserant <edouard@beremiz.fr>
parents:
3980
diff
changeset
|
304 |
int MQTT_Topic_index(const char *key) |
74035ea6792c
MQTT WIP: intermediate state, added perfect hash to map topic to variables
Edouard Tisserant <edouard@beremiz.fr>
parents:
3980
diff
changeset
|
305 |
{ |
74035ea6792c
MQTT WIP: intermediate state, added perfect hash to map topic to variables
Edouard Tisserant <edouard@beremiz.fr>
parents:
3980
diff
changeset
|
306 |
int i, f1 = 0, f2 = 0; |
74035ea6792c
MQTT WIP: intermediate state, added perfect hash to map topic to variables
Edouard Tisserant <edouard@beremiz.fr>
parents:
3980
diff
changeset
|
307 |
|
74035ea6792c
MQTT WIP: intermediate state, added perfect hash to map topic to variables
Edouard Tisserant <edouard@beremiz.fr>
parents:
3980
diff
changeset
|
308 |
for (i = 0; key[i] != '\\0' && i < NS; i++) { |
74035ea6792c
MQTT WIP: intermediate state, added perfect hash to map topic to variables
Edouard Tisserant <edouard@beremiz.fr>
parents:
3980
diff
changeset
|
309 |
f1 += S1[i] * key[i]; |
74035ea6792c
MQTT WIP: intermediate state, added perfect hash to map topic to variables
Edouard Tisserant <edouard@beremiz.fr>
parents:
3980
diff
changeset
|
310 |
f2 += S2[i] * key[i]; |
74035ea6792c
MQTT WIP: intermediate state, added perfect hash to map topic to variables
Edouard Tisserant <edouard@beremiz.fr>
parents:
3980
diff
changeset
|
311 |
f1 %= NG; |
74035ea6792c
MQTT WIP: intermediate state, added perfect hash to map topic to variables
Edouard Tisserant <edouard@beremiz.fr>
parents:
3980
diff
changeset
|
312 |
f2 %= NG; |
74035ea6792c
MQTT WIP: intermediate state, added perfect hash to map topic to variables
Edouard Tisserant <edouard@beremiz.fr>
parents:
3980
diff
changeset
|
313 |
} |
74035ea6792c
MQTT WIP: intermediate state, added perfect hash to map topic to variables
Edouard Tisserant <edouard@beremiz.fr>
parents:
3980
diff
changeset
|
314 |
i = (G[f1] + G[f2]) % NG; |
74035ea6792c
MQTT WIP: intermediate state, added perfect hash to map topic to variables
Edouard Tisserant <edouard@beremiz.fr>
parents:
3980
diff
changeset
|
315 |
if (i < NK && strcmp(key, K[i]) == 0) |
74035ea6792c
MQTT WIP: intermediate state, added perfect hash to map topic to variables
Edouard Tisserant <edouard@beremiz.fr>
parents:
3980
diff
changeset
|
316 |
return i; |
74035ea6792c
MQTT WIP: intermediate state, added perfect hash to map topic to variables
Edouard Tisserant <edouard@beremiz.fr>
parents:
3980
diff
changeset
|
317 |
|
74035ea6792c
MQTT WIP: intermediate state, added perfect hash to map topic to variables
Edouard Tisserant <edouard@beremiz.fr>
parents:
3980
diff
changeset
|
318 |
return -1; |
74035ea6792c
MQTT WIP: intermediate state, added perfect hash to map topic to variables
Edouard Tisserant <edouard@beremiz.fr>
parents:
3980
diff
changeset
|
319 |
} |
74035ea6792c
MQTT WIP: intermediate state, added perfect hash to map topic to variables
Edouard Tisserant <edouard@beremiz.fr>
parents:
3980
diff
changeset
|
320 |
""" |
74035ea6792c
MQTT WIP: intermediate state, added perfect hash to map topic to variables
Edouard Tisserant <edouard@beremiz.fr>
parents:
3980
diff
changeset
|
321 |
return code |
74035ea6792c
MQTT WIP: intermediate state, added perfect hash to map topic to variables
Edouard Tisserant <edouard@beremiz.fr>
parents:
3980
diff
changeset
|
322 |
|
3979
76295adcf940
WIP: Add skeleton for MQTT extension based on part of OPC-UA extension.
Edouard Tisserant <edouard@beremiz.fr>
parents:
diff
changeset
|
323 |
def GenerateC(self, path, locstr, config): |
76295adcf940
WIP: Add skeleton for MQTT extension based on part of OPC-UA extension.
Edouard Tisserant <edouard@beremiz.fr>
parents:
diff
changeset
|
324 |
template = """/* code generated by beremiz MQTT extension */ |
76295adcf940
WIP: Add skeleton for MQTT extension based on part of OPC-UA extension.
Edouard Tisserant <edouard@beremiz.fr>
parents:
diff
changeset
|
325 |
|
3980
96acfee19caf
MQTT WIP: intermediate state, implementing MQTT client C code generator.
Edouard Tisserant <edouard@beremiz.fr>
parents:
3979
diff
changeset
|
326 |
#include "MQTTAsync.h" |
96acfee19caf
MQTT WIP: intermediate state, implementing MQTT client C code generator.
Edouard Tisserant <edouard@beremiz.fr>
parents:
3979
diff
changeset
|
327 |
#include "MQTTClientPersistence.h" |
3979
76295adcf940
WIP: Add skeleton for MQTT extension based on part of OPC-UA extension.
Edouard Tisserant <edouard@beremiz.fr>
parents:
diff
changeset
|
328 |
|
76295adcf940
WIP: Add skeleton for MQTT extension based on part of OPC-UA extension.
Edouard Tisserant <edouard@beremiz.fr>
parents:
diff
changeset
|
329 |
#define _Log(level, ...) \\ |
76295adcf940
WIP: Add skeleton for MQTT extension based on part of OPC-UA extension.
Edouard Tisserant <edouard@beremiz.fr>
parents:
diff
changeset
|
330 |
{{ \\ |
76295adcf940
WIP: Add skeleton for MQTT extension based on part of OPC-UA extension.
Edouard Tisserant <edouard@beremiz.fr>
parents:
diff
changeset
|
331 |
char mstr[256]; \\ |
76295adcf940
WIP: Add skeleton for MQTT extension based on part of OPC-UA extension.
Edouard Tisserant <edouard@beremiz.fr>
parents:
diff
changeset
|
332 |
snprintf(mstr, 255, __VA_ARGS__); \\ |
76295adcf940
WIP: Add skeleton for MQTT extension based on part of OPC-UA extension.
Edouard Tisserant <edouard@beremiz.fr>
parents:
diff
changeset
|
333 |
LogMessage(level, mstr, strlen(mstr)); \\ |
76295adcf940
WIP: Add skeleton for MQTT extension based on part of OPC-UA extension.
Edouard Tisserant <edouard@beremiz.fr>
parents:
diff
changeset
|
334 |
}} |
76295adcf940
WIP: Add skeleton for MQTT extension based on part of OPC-UA extension.
Edouard Tisserant <edouard@beremiz.fr>
parents:
diff
changeset
|
335 |
|
76295adcf940
WIP: Add skeleton for MQTT extension based on part of OPC-UA extension.
Edouard Tisserant <edouard@beremiz.fr>
parents:
diff
changeset
|
336 |
#define LogInfo(...) _Log(LOG_INFO, __VA_ARGS__); |
76295adcf940
WIP: Add skeleton for MQTT extension based on part of OPC-UA extension.
Edouard Tisserant <edouard@beremiz.fr>
parents:
diff
changeset
|
337 |
#define LogError(...) _Log(LOG_CRITICAL, __VA_ARGS__); |
76295adcf940
WIP: Add skeleton for MQTT extension based on part of OPC-UA extension.
Edouard Tisserant <edouard@beremiz.fr>
parents:
diff
changeset
|
338 |
#define LogWarning(...) _Log(LOG_WARNING, __VA_ARGS__); |
76295adcf940
WIP: Add skeleton for MQTT extension based on part of OPC-UA extension.
Edouard Tisserant <edouard@beremiz.fr>
parents:
diff
changeset
|
339 |
|
3980
96acfee19caf
MQTT WIP: intermediate state, implementing MQTT client C code generator.
Edouard Tisserant <edouard@beremiz.fr>
parents:
3979
diff
changeset
|
340 |
static inline void* loadFile(const char *const path) {{ |
3979
76295adcf940
WIP: Add skeleton for MQTT extension based on part of OPC-UA extension.
Edouard Tisserant <edouard@beremiz.fr>
parents:
diff
changeset
|
341 |
|
76295adcf940
WIP: Add skeleton for MQTT extension based on part of OPC-UA extension.
Edouard Tisserant <edouard@beremiz.fr>
parents:
diff
changeset
|
342 |
FILE *fp = fopen(path, "rb"); |
76295adcf940
WIP: Add skeleton for MQTT extension based on part of OPC-UA extension.
Edouard Tisserant <edouard@beremiz.fr>
parents:
diff
changeset
|
343 |
if(!fp) {{ |
76295adcf940
WIP: Add skeleton for MQTT extension based on part of OPC-UA extension.
Edouard Tisserant <edouard@beremiz.fr>
parents:
diff
changeset
|
344 |
errno = 0; |
3980
96acfee19caf
MQTT WIP: intermediate state, implementing MQTT client C code generator.
Edouard Tisserant <edouard@beremiz.fr>
parents:
3979
diff
changeset
|
345 |
LogError("MQTT could not open %s", path); |
96acfee19caf
MQTT WIP: intermediate state, implementing MQTT client C code generator.
Edouard Tisserant <edouard@beremiz.fr>
parents:
3979
diff
changeset
|
346 |
return NULL; |
3979
76295adcf940
WIP: Add skeleton for MQTT extension based on part of OPC-UA extension.
Edouard Tisserant <edouard@beremiz.fr>
parents:
diff
changeset
|
347 |
}} |
76295adcf940
WIP: Add skeleton for MQTT extension based on part of OPC-UA extension.
Edouard Tisserant <edouard@beremiz.fr>
parents:
diff
changeset
|
348 |
|
76295adcf940
WIP: Add skeleton for MQTT extension based on part of OPC-UA extension.
Edouard Tisserant <edouard@beremiz.fr>
parents:
diff
changeset
|
349 |
fseek(fp, 0, SEEK_END); |
3980
96acfee19caf
MQTT WIP: intermediate state, implementing MQTT client C code generator.
Edouard Tisserant <edouard@beremiz.fr>
parents:
3979
diff
changeset
|
350 |
size_t length = (size_t)ftell(fp); |
96acfee19caf
MQTT WIP: intermediate state, implementing MQTT client C code generator.
Edouard Tisserant <edouard@beremiz.fr>
parents:
3979
diff
changeset
|
351 |
void* data = malloc(length); |
96acfee19caf
MQTT WIP: intermediate state, implementing MQTT client C code generator.
Edouard Tisserant <edouard@beremiz.fr>
parents:
3979
diff
changeset
|
352 |
if(data) {{ |
3979
76295adcf940
WIP: Add skeleton for MQTT extension based on part of OPC-UA extension.
Edouard Tisserant <edouard@beremiz.fr>
parents:
diff
changeset
|
353 |
fseek(fp, 0, SEEK_SET); |
3980
96acfee19caf
MQTT WIP: intermediate state, implementing MQTT client C code generator.
Edouard Tisserant <edouard@beremiz.fr>
parents:
3979
diff
changeset
|
354 |
size_t read = fread(data, 1, fileContents.length, fp); |
96acfee19caf
MQTT WIP: intermediate state, implementing MQTT client C code generator.
Edouard Tisserant <edouard@beremiz.fr>
parents:
3979
diff
changeset
|
355 |
if(read != length){{ |
96acfee19caf
MQTT WIP: intermediate state, implementing MQTT client C code generator.
Edouard Tisserant <edouard@beremiz.fr>
parents:
3979
diff
changeset
|
356 |
free(data); |
96acfee19caf
MQTT WIP: intermediate state, implementing MQTT client C code generator.
Edouard Tisserant <edouard@beremiz.fr>
parents:
3979
diff
changeset
|
357 |
LogError("MQTT could not read %s", path); |
3979
76295adcf940
WIP: Add skeleton for MQTT extension based on part of OPC-UA extension.
Edouard Tisserant <edouard@beremiz.fr>
parents:
diff
changeset
|
358 |
}} |
76295adcf940
WIP: Add skeleton for MQTT extension based on part of OPC-UA extension.
Edouard Tisserant <edouard@beremiz.fr>
parents:
diff
changeset
|
359 |
}} else {{ |
3980
96acfee19caf
MQTT WIP: intermediate state, implementing MQTT client C code generator.
Edouard Tisserant <edouard@beremiz.fr>
parents:
3979
diff
changeset
|
360 |
LogError("MQTT Not enough memoty to load %s", path); |
3979
76295adcf940
WIP: Add skeleton for MQTT extension based on part of OPC-UA extension.
Edouard Tisserant <edouard@beremiz.fr>
parents:
diff
changeset
|
361 |
}} |
76295adcf940
WIP: Add skeleton for MQTT extension based on part of OPC-UA extension.
Edouard Tisserant <edouard@beremiz.fr>
parents:
diff
changeset
|
362 |
fclose(fp); |
76295adcf940
WIP: Add skeleton for MQTT extension based on part of OPC-UA extension.
Edouard Tisserant <edouard@beremiz.fr>
parents:
diff
changeset
|
363 |
|
3980
96acfee19caf
MQTT WIP: intermediate state, implementing MQTT client C code generator.
Edouard Tisserant <edouard@beremiz.fr>
parents:
3979
diff
changeset
|
364 |
return data; |
3979
76295adcf940
WIP: Add skeleton for MQTT extension based on part of OPC-UA extension.
Edouard Tisserant <edouard@beremiz.fr>
parents:
diff
changeset
|
365 |
}} |
76295adcf940
WIP: Add skeleton for MQTT extension based on part of OPC-UA extension.
Edouard Tisserant <edouard@beremiz.fr>
parents:
diff
changeset
|
366 |
|
3980
96acfee19caf
MQTT WIP: intermediate state, implementing MQTT client C code generator.
Edouard Tisserant <edouard@beremiz.fr>
parents:
3979
diff
changeset
|
367 |
static MQTTClient client; |
96acfee19caf
MQTT WIP: intermediate state, implementing MQTT client C code generator.
Edouard Tisserant <edouard@beremiz.fr>
parents:
3979
diff
changeset
|
368 |
static MQTTClient_connectOptions conn_opts = MQTTClient_connectOptions_initializer; |
96acfee19caf
MQTT WIP: intermediate state, implementing MQTT client C code generator.
Edouard Tisserant <edouard@beremiz.fr>
parents:
3979
diff
changeset
|
369 |
|
96acfee19caf
MQTT WIP: intermediate state, implementing MQTT client C code generator.
Edouard Tisserant <edouard@beremiz.fr>
parents:
3979
diff
changeset
|
370 |
void trace_callback(enum MQTTASYNC_TRACE_LEVELS level, char* message) |
96acfee19caf
MQTT WIP: intermediate state, implementing MQTT client C code generator.
Edouard Tisserant <edouard@beremiz.fr>
parents:
3979
diff
changeset
|
371 |
{ |
96acfee19caf
MQTT WIP: intermediate state, implementing MQTT client C code generator.
Edouard Tisserant <edouard@beremiz.fr>
parents:
3979
diff
changeset
|
372 |
LogWarning("Paho MQTT Trace : %d, %s\n", level, message); |
96acfee19caf
MQTT WIP: intermediate state, implementing MQTT client C code generator.
Edouard Tisserant <edouard@beremiz.fr>
parents:
3979
diff
changeset
|
373 |
} |
3979
76295adcf940
WIP: Add skeleton for MQTT extension based on part of OPC-UA extension.
Edouard Tisserant <edouard@beremiz.fr>
parents:
diff
changeset
|
374 |
|
3981
74035ea6792c
MQTT WIP: intermediate state, added perfect hash to map topic to variables
Edouard Tisserant <edouard@beremiz.fr>
parents:
3980
diff
changeset
|
375 |
#define DECL_VAR(iec_type, C_type, c_loc_name) \\ |
3979
76295adcf940
WIP: Add skeleton for MQTT extension based on part of OPC-UA extension.
Edouard Tisserant <edouard@beremiz.fr>
parents:
diff
changeset
|
376 |
static C_type c_loc_name##_buf = 0; \\ |
76295adcf940
WIP: Add skeleton for MQTT extension based on part of OPC-UA extension.
Edouard Tisserant <edouard@beremiz.fr>
parents:
diff
changeset
|
377 |
C_type *c_loc_name = &c_loc_name##_buf; |
76295adcf940
WIP: Add skeleton for MQTT extension based on part of OPC-UA extension.
Edouard Tisserant <edouard@beremiz.fr>
parents:
diff
changeset
|
378 |
|
76295adcf940
WIP: Add skeleton for MQTT extension based on part of OPC-UA extension.
Edouard Tisserant <edouard@beremiz.fr>
parents:
diff
changeset
|
379 |
{decl} |
76295adcf940
WIP: Add skeleton for MQTT extension based on part of OPC-UA extension.
Edouard Tisserant <edouard@beremiz.fr>
parents:
diff
changeset
|
380 |
|
3981
74035ea6792c
MQTT WIP: intermediate state, added perfect hash to map topic to variables
Edouard Tisserant <edouard@beremiz.fr>
parents:
3980
diff
changeset
|
381 |
#define INIT_TOPIC(topic, iec_type, c_loc_name) \\ |
74035ea6792c
MQTT WIP: intermediate state, added perfect hash to map topic to variables
Edouard Tisserant <edouard@beremiz.fr>
parents:
3980
diff
changeset
|
382 |
{topic, &c_loc_name##_buf, iec_type##_ENUM}, |
74035ea6792c
MQTT WIP: intermediate state, added perfect hash to map topic to variables
Edouard Tisserant <edouard@beremiz.fr>
parents:
3980
diff
changeset
|
383 |
|
74035ea6792c
MQTT WIP: intermediate state, added perfect hash to map topic to variables
Edouard Tisserant <edouard@beremiz.fr>
parents:
3980
diff
changeset
|
384 |
ststic struct { |
74035ea6792c
MQTT WIP: intermediate state, added perfect hash to map topic to variables
Edouard Tisserant <edouard@beremiz.fr>
parents:
3980
diff
changeset
|
385 |
const char *topic; //null terminated topic string |
74035ea6792c
MQTT WIP: intermediate state, added perfect hash to map topic to variables
Edouard Tisserant <edouard@beremiz.fr>
parents:
3980
diff
changeset
|
386 |
void *pdata; //pointer to data |
74035ea6792c
MQTT WIP: intermediate state, added perfect hash to map topic to variables
Edouard Tisserant <edouard@beremiz.fr>
parents:
3980
diff
changeset
|
387 |
__IEC_types_enum vartype; |
74035ea6792c
MQTT WIP: intermediate state, added perfect hash to map topic to variables
Edouard Tisserant <edouard@beremiz.fr>
parents:
3980
diff
changeset
|
388 |
} topics [] = { |
74035ea6792c
MQTT WIP: intermediate state, added perfect hash to map topic to variables
Edouard Tisserant <edouard@beremiz.fr>
parents:
3980
diff
changeset
|
389 |
{topics} |
74035ea6792c
MQTT WIP: intermediate state, added perfect hash to map topic to variables
Edouard Tisserant <edouard@beremiz.fr>
parents:
3980
diff
changeset
|
390 |
} |
74035ea6792c
MQTT WIP: intermediate state, added perfect hash to map topic to variables
Edouard Tisserant <edouard@beremiz.fr>
parents:
3980
diff
changeset
|
391 |
|
3979
76295adcf940
WIP: Add skeleton for MQTT extension based on part of OPC-UA extension.
Edouard Tisserant <edouard@beremiz.fr>
parents:
diff
changeset
|
392 |
void __cleanup_{locstr}(void) |
76295adcf940
WIP: Add skeleton for MQTT extension based on part of OPC-UA extension.
Edouard Tisserant <edouard@beremiz.fr>
parents:
diff
changeset
|
393 |
{{ |
76295adcf940
WIP: Add skeleton for MQTT extension based on part of OPC-UA extension.
Edouard Tisserant <edouard@beremiz.fr>
parents:
diff
changeset
|
394 |
MQTT_Client_disconnect(client); |
76295adcf940
WIP: Add skeleton for MQTT extension based on part of OPC-UA extension.
Edouard Tisserant <edouard@beremiz.fr>
parents:
diff
changeset
|
395 |
MQTT_Client_delete(client); |
76295adcf940
WIP: Add skeleton for MQTT extension based on part of OPC-UA extension.
Edouard Tisserant <edouard@beremiz.fr>
parents:
diff
changeset
|
396 |
}} |
76295adcf940
WIP: Add skeleton for MQTT extension based on part of OPC-UA extension.
Edouard Tisserant <edouard@beremiz.fr>
parents:
diff
changeset
|
397 |
|
76295adcf940
WIP: Add skeleton for MQTT extension based on part of OPC-UA extension.
Edouard Tisserant <edouard@beremiz.fr>
parents:
diff
changeset
|
398 |
#define INIT_NoAuth() \\ |
3980
96acfee19caf
MQTT WIP: intermediate state, implementing MQTT client C code generator.
Edouard Tisserant <edouard@beremiz.fr>
parents:
3979
diff
changeset
|
399 |
LogInfo("MQTT Init no auth"); \\ |
3979
76295adcf940
WIP: Add skeleton for MQTT extension based on part of OPC-UA extension.
Edouard Tisserant <edouard@beremiz.fr>
parents:
diff
changeset
|
400 |
MQTT_ClientConfig_setDefault(cc); \\ |
76295adcf940
WIP: Add skeleton for MQTT extension based on part of OPC-UA extension.
Edouard Tisserant <edouard@beremiz.fr>
parents:
diff
changeset
|
401 |
retval = MQTT_Client_connect(client, uri); |
76295adcf940
WIP: Add skeleton for MQTT extension based on part of OPC-UA extension.
Edouard Tisserant <edouard@beremiz.fr>
parents:
diff
changeset
|
402 |
|
76295adcf940
WIP: Add skeleton for MQTT extension based on part of OPC-UA extension.
Edouard Tisserant <edouard@beremiz.fr>
parents:
diff
changeset
|
403 |
/* Note : Single policy is enforced here, by default open62541 client supports all policies */ |
76295adcf940
WIP: Add skeleton for MQTT extension based on part of OPC-UA extension.
Edouard Tisserant <edouard@beremiz.fr>
parents:
diff
changeset
|
404 |
#define INIT_x509(Policy, UpperCaseMode, PrivateKey, Certificate) \\ |
3980
96acfee19caf
MQTT WIP: intermediate state, implementing MQTT client C code generator.
Edouard Tisserant <edouard@beremiz.fr>
parents:
3979
diff
changeset
|
405 |
LogInfo("MQTT Init x509 %s,%s,%s,%s", #Policy, #UpperCaseMode, PrivateKey, Certificate); \\ |
3979
76295adcf940
WIP: Add skeleton for MQTT extension based on part of OPC-UA extension.
Edouard Tisserant <edouard@beremiz.fr>
parents:
diff
changeset
|
406 |
\\ |
76295adcf940
WIP: Add skeleton for MQTT extension based on part of OPC-UA extension.
Edouard Tisserant <edouard@beremiz.fr>
parents:
diff
changeset
|
407 |
MQTT_ByteString certificate = loadFile(Certificate); \\ |
76295adcf940
WIP: Add skeleton for MQTT extension based on part of OPC-UA extension.
Edouard Tisserant <edouard@beremiz.fr>
parents:
diff
changeset
|
408 |
MQTT_ByteString privateKey = loadFile(PrivateKey); \\ |
76295adcf940
WIP: Add skeleton for MQTT extension based on part of OPC-UA extension.
Edouard Tisserant <edouard@beremiz.fr>
parents:
diff
changeset
|
409 |
\\ |
76295adcf940
WIP: Add skeleton for MQTT extension based on part of OPC-UA extension.
Edouard Tisserant <edouard@beremiz.fr>
parents:
diff
changeset
|
410 |
cc->securityMode = MQTT_MESSAGESECURITYMODE_##UpperCaseMode; \\ |
76295adcf940
WIP: Add skeleton for MQTT extension based on part of OPC-UA extension.
Edouard Tisserant <edouard@beremiz.fr>
parents:
diff
changeset
|
411 |
\\ |
76295adcf940
WIP: Add skeleton for MQTT extension based on part of OPC-UA extension.
Edouard Tisserant <edouard@beremiz.fr>
parents:
diff
changeset
|
412 |
/* replacement for default behaviour */ \\ |
76295adcf940
WIP: Add skeleton for MQTT extension based on part of OPC-UA extension.
Edouard Tisserant <edouard@beremiz.fr>
parents:
diff
changeset
|
413 |
/* MQTT_ClientConfig_setDefaultEncryption(cc, certificate, privateKey, NULL, 0, NULL, 0); */ \\ |
76295adcf940
WIP: Add skeleton for MQTT extension based on part of OPC-UA extension.
Edouard Tisserant <edouard@beremiz.fr>
parents:
diff
changeset
|
414 |
do{{ \\ |
76295adcf940
WIP: Add skeleton for MQTT extension based on part of OPC-UA extension.
Edouard Tisserant <edouard@beremiz.fr>
parents:
diff
changeset
|
415 |
retval = MQTT_ClientConfig_setDefault(cc); \\ |
76295adcf940
WIP: Add skeleton for MQTT extension based on part of OPC-UA extension.
Edouard Tisserant <edouard@beremiz.fr>
parents:
diff
changeset
|
416 |
if(retval != MQTT_STATUSCODE_GOOD) \\ |
76295adcf940
WIP: Add skeleton for MQTT extension based on part of OPC-UA extension.
Edouard Tisserant <edouard@beremiz.fr>
parents:
diff
changeset
|
417 |
break; \\ |
76295adcf940
WIP: Add skeleton for MQTT extension based on part of OPC-UA extension.
Edouard Tisserant <edouard@beremiz.fr>
parents:
diff
changeset
|
418 |
\\ |
76295adcf940
WIP: Add skeleton for MQTT extension based on part of OPC-UA extension.
Edouard Tisserant <edouard@beremiz.fr>
parents:
diff
changeset
|
419 |
MQTT_SecurityPolicy *sp = (MQTT_SecurityPolicy*) \\ |
76295adcf940
WIP: Add skeleton for MQTT extension based on part of OPC-UA extension.
Edouard Tisserant <edouard@beremiz.fr>
parents:
diff
changeset
|
420 |
MQTT_realloc(cc->securityPolicies, sizeof(MQTT_SecurityPolicy) * 2); \\ |
76295adcf940
WIP: Add skeleton for MQTT extension based on part of OPC-UA extension.
Edouard Tisserant <edouard@beremiz.fr>
parents:
diff
changeset
|
421 |
if(!sp){{ \\ |
76295adcf940
WIP: Add skeleton for MQTT extension based on part of OPC-UA extension.
Edouard Tisserant <edouard@beremiz.fr>
parents:
diff
changeset
|
422 |
retval = MQTT_STATUSCODE_BADOUTOFMEMORY; \\ |
76295adcf940
WIP: Add skeleton for MQTT extension based on part of OPC-UA extension.
Edouard Tisserant <edouard@beremiz.fr>
parents:
diff
changeset
|
423 |
break; \\ |
76295adcf940
WIP: Add skeleton for MQTT extension based on part of OPC-UA extension.
Edouard Tisserant <edouard@beremiz.fr>
parents:
diff
changeset
|
424 |
}} \\ |
76295adcf940
WIP: Add skeleton for MQTT extension based on part of OPC-UA extension.
Edouard Tisserant <edouard@beremiz.fr>
parents:
diff
changeset
|
425 |
cc->securityPolicies = sp; \\ |
76295adcf940
WIP: Add skeleton for MQTT extension based on part of OPC-UA extension.
Edouard Tisserant <edouard@beremiz.fr>
parents:
diff
changeset
|
426 |
\\ |
76295adcf940
WIP: Add skeleton for MQTT extension based on part of OPC-UA extension.
Edouard Tisserant <edouard@beremiz.fr>
parents:
diff
changeset
|
427 |
retval = MQTT_SecurityPolicy_##Policy(&cc->securityPolicies[cc->securityPoliciesSize], \\ |
76295adcf940
WIP: Add skeleton for MQTT extension based on part of OPC-UA extension.
Edouard Tisserant <edouard@beremiz.fr>
parents:
diff
changeset
|
428 |
certificate, privateKey, &cc->logger); \\ |
76295adcf940
WIP: Add skeleton for MQTT extension based on part of OPC-UA extension.
Edouard Tisserant <edouard@beremiz.fr>
parents:
diff
changeset
|
429 |
if(retval != MQTT_STATUSCODE_GOOD) {{ \\ |
76295adcf940
WIP: Add skeleton for MQTT extension based on part of OPC-UA extension.
Edouard Tisserant <edouard@beremiz.fr>
parents:
diff
changeset
|
430 |
MQTT_LOG_WARNING(&cc->logger, MQTT_LOGCATEGORY_USERLAND, \\ |
76295adcf940
WIP: Add skeleton for MQTT extension based on part of OPC-UA extension.
Edouard Tisserant <edouard@beremiz.fr>
parents:
diff
changeset
|
431 |
"Could not add SecurityPolicy Policy with error code %s", \\ |
76295adcf940
WIP: Add skeleton for MQTT extension based on part of OPC-UA extension.
Edouard Tisserant <edouard@beremiz.fr>
parents:
diff
changeset
|
432 |
MQTT_StatusCode_name(retval)); \\ |
76295adcf940
WIP: Add skeleton for MQTT extension based on part of OPC-UA extension.
Edouard Tisserant <edouard@beremiz.fr>
parents:
diff
changeset
|
433 |
MQTT_free(cc->securityPolicies); \\ |
76295adcf940
WIP: Add skeleton for MQTT extension based on part of OPC-UA extension.
Edouard Tisserant <edouard@beremiz.fr>
parents:
diff
changeset
|
434 |
cc->securityPolicies = NULL; \\ |
76295adcf940
WIP: Add skeleton for MQTT extension based on part of OPC-UA extension.
Edouard Tisserant <edouard@beremiz.fr>
parents:
diff
changeset
|
435 |
break; \\ |
76295adcf940
WIP: Add skeleton for MQTT extension based on part of OPC-UA extension.
Edouard Tisserant <edouard@beremiz.fr>
parents:
diff
changeset
|
436 |
}} \\ |
76295adcf940
WIP: Add skeleton for MQTT extension based on part of OPC-UA extension.
Edouard Tisserant <edouard@beremiz.fr>
parents:
diff
changeset
|
437 |
\\ |
76295adcf940
WIP: Add skeleton for MQTT extension based on part of OPC-UA extension.
Edouard Tisserant <edouard@beremiz.fr>
parents:
diff
changeset
|
438 |
++cc->securityPoliciesSize; \\ |
76295adcf940
WIP: Add skeleton for MQTT extension based on part of OPC-UA extension.
Edouard Tisserant <edouard@beremiz.fr>
parents:
diff
changeset
|
439 |
}} while(0); \\ |
76295adcf940
WIP: Add skeleton for MQTT extension based on part of OPC-UA extension.
Edouard Tisserant <edouard@beremiz.fr>
parents:
diff
changeset
|
440 |
\\ |
76295adcf940
WIP: Add skeleton for MQTT extension based on part of OPC-UA extension.
Edouard Tisserant <edouard@beremiz.fr>
parents:
diff
changeset
|
441 |
retval = MQTT_Client_connect(client, uri); \\ |
76295adcf940
WIP: Add skeleton for MQTT extension based on part of OPC-UA extension.
Edouard Tisserant <edouard@beremiz.fr>
parents:
diff
changeset
|
442 |
\\ |
76295adcf940
WIP: Add skeleton for MQTT extension based on part of OPC-UA extension.
Edouard Tisserant <edouard@beremiz.fr>
parents:
diff
changeset
|
443 |
MQTT_ByteString_clear(&certificate); \\ |
76295adcf940
WIP: Add skeleton for MQTT extension based on part of OPC-UA extension.
Edouard Tisserant <edouard@beremiz.fr>
parents:
diff
changeset
|
444 |
MQTT_ByteString_clear(&privateKey); |
76295adcf940
WIP: Add skeleton for MQTT extension based on part of OPC-UA extension.
Edouard Tisserant <edouard@beremiz.fr>
parents:
diff
changeset
|
445 |
|
76295adcf940
WIP: Add skeleton for MQTT extension based on part of OPC-UA extension.
Edouard Tisserant <edouard@beremiz.fr>
parents:
diff
changeset
|
446 |
#define INIT_UserPassword(User, Password) \\ |
3980
96acfee19caf
MQTT WIP: intermediate state, implementing MQTT client C code generator.
Edouard Tisserant <edouard@beremiz.fr>
parents:
3979
diff
changeset
|
447 |
LogInfo("MQTT Init UserPassword %s,%s", User, Password); \\ |
3979
76295adcf940
WIP: Add skeleton for MQTT extension based on part of OPC-UA extension.
Edouard Tisserant <edouard@beremiz.fr>
parents:
diff
changeset
|
448 |
MQTT_ClientConfig_setDefault(cc); \\ |
76295adcf940
WIP: Add skeleton for MQTT extension based on part of OPC-UA extension.
Edouard Tisserant <edouard@beremiz.fr>
parents:
diff
changeset
|
449 |
retval = MQTT_Client_connectUsername(client, uri, User, Password); |
76295adcf940
WIP: Add skeleton for MQTT extension based on part of OPC-UA extension.
Edouard Tisserant <edouard@beremiz.fr>
parents:
diff
changeset
|
450 |
|
76295adcf940
WIP: Add skeleton for MQTT extension based on part of OPC-UA extension.
Edouard Tisserant <edouard@beremiz.fr>
parents:
diff
changeset
|
451 |
#define INIT_READ_VARIANT(ua_type, c_loc_name) \\ |
76295adcf940
WIP: Add skeleton for MQTT extension based on part of OPC-UA extension.
Edouard Tisserant <edouard@beremiz.fr>
parents:
diff
changeset
|
452 |
MQTT_Variant_init(&c_loc_name##_variant); |
76295adcf940
WIP: Add skeleton for MQTT extension based on part of OPC-UA extension.
Edouard Tisserant <edouard@beremiz.fr>
parents:
diff
changeset
|
453 |
|
76295adcf940
WIP: Add skeleton for MQTT extension based on part of OPC-UA extension.
Edouard Tisserant <edouard@beremiz.fr>
parents:
diff
changeset
|
454 |
#define INIT_WRITE_VARIANT(ua_type, ua_type_enum, c_loc_name) \\ |
76295adcf940
WIP: Add skeleton for MQTT extension based on part of OPC-UA extension.
Edouard Tisserant <edouard@beremiz.fr>
parents:
diff
changeset
|
455 |
MQTT_Variant_setScalar(&c_loc_name##_variant, (ua_type*)c_loc_name, &MQTT_TYPES[ua_type_enum]); |
76295adcf940
WIP: Add skeleton for MQTT extension based on part of OPC-UA extension.
Edouard Tisserant <edouard@beremiz.fr>
parents:
diff
changeset
|
456 |
|
76295adcf940
WIP: Add skeleton for MQTT extension based on part of OPC-UA extension.
Edouard Tisserant <edouard@beremiz.fr>
parents:
diff
changeset
|
457 |
int __init_{locstr}(int argc,char **argv) |
76295adcf940
WIP: Add skeleton for MQTT extension based on part of OPC-UA extension.
Edouard Tisserant <edouard@beremiz.fr>
parents:
diff
changeset
|
458 |
{{ |
76295adcf940
WIP: Add skeleton for MQTT extension based on part of OPC-UA extension.
Edouard Tisserant <edouard@beremiz.fr>
parents:
diff
changeset
|
459 |
char *uri = "{uri}"; |
3980
96acfee19caf
MQTT WIP: intermediate state, implementing MQTT client C code generator.
Edouard Tisserant <edouard@beremiz.fr>
parents:
3979
diff
changeset
|
460 |
char *clientID = "{clientID}"; |
96acfee19caf
MQTT WIP: intermediate state, implementing MQTT client C code generator.
Edouard Tisserant <edouard@beremiz.fr>
parents:
3979
diff
changeset
|
461 |
int rc; |
96acfee19caf
MQTT WIP: intermediate state, implementing MQTT client C code generator.
Edouard Tisserant <edouard@beremiz.fr>
parents:
3979
diff
changeset
|
462 |
conn_opts = MQTTClient_connectOptions_initializer; |
96acfee19caf
MQTT WIP: intermediate state, implementing MQTT client C code generator.
Edouard Tisserant <edouard@beremiz.fr>
parents:
3979
diff
changeset
|
463 |
|
96acfee19caf
MQTT WIP: intermediate state, implementing MQTT client C code generator.
Edouard Tisserant <edouard@beremiz.fr>
parents:
3979
diff
changeset
|
464 |
if ((rc = MQTTClient_create(&client, uri, clientID, |
96acfee19caf
MQTT WIP: intermediate state, implementing MQTT client C code generator.
Edouard Tisserant <edouard@beremiz.fr>
parents:
3979
diff
changeset
|
465 |
MQTTCLIENT_PERSISTENCE_NONE, NULL)) != MQTTCLIENT_SUCCESS) |
96acfee19caf
MQTT WIP: intermediate state, implementing MQTT client C code generator.
Edouard Tisserant <edouard@beremiz.fr>
parents:
3979
diff
changeset
|
466 |
{ |
96acfee19caf
MQTT WIP: intermediate state, implementing MQTT client C code generator.
Edouard Tisserant <edouard@beremiz.fr>
parents:
3979
diff
changeset
|
467 |
printf("Failed to create client, return code %d\n", rc); |
96acfee19caf
MQTT WIP: intermediate state, implementing MQTT client C code generator.
Edouard Tisserant <edouard@beremiz.fr>
parents:
3979
diff
changeset
|
468 |
rc = EXIT_FAILURE; |
96acfee19caf
MQTT WIP: intermediate state, implementing MQTT client C code generator.
Edouard Tisserant <edouard@beremiz.fr>
parents:
3979
diff
changeset
|
469 |
goto exit; |
96acfee19caf
MQTT WIP: intermediate state, implementing MQTT client C code generator.
Edouard Tisserant <edouard@beremiz.fr>
parents:
3979
diff
changeset
|
470 |
} |
96acfee19caf
MQTT WIP: intermediate state, implementing MQTT client C code generator.
Edouard Tisserant <edouard@beremiz.fr>
parents:
3979
diff
changeset
|
471 |
|
3979
76295adcf940
WIP: Add skeleton for MQTT extension based on part of OPC-UA extension.
Edouard Tisserant <edouard@beremiz.fr>
parents:
diff
changeset
|
472 |
{init} |
76295adcf940
WIP: Add skeleton for MQTT extension based on part of OPC-UA extension.
Edouard Tisserant <edouard@beremiz.fr>
parents:
diff
changeset
|
473 |
|
76295adcf940
WIP: Add skeleton for MQTT extension based on part of OPC-UA extension.
Edouard Tisserant <edouard@beremiz.fr>
parents:
diff
changeset
|
474 |
if(retval != MQTT_STATUSCODE_GOOD) {{ |
3980
96acfee19caf
MQTT WIP: intermediate state, implementing MQTT client C code generator.
Edouard Tisserant <edouard@beremiz.fr>
parents:
3979
diff
changeset
|
475 |
LogError("MQTT Init Failed %d", retval); |
3979
76295adcf940
WIP: Add skeleton for MQTT extension based on part of OPC-UA extension.
Edouard Tisserant <edouard@beremiz.fr>
parents:
diff
changeset
|
476 |
MQTT_Client_delete(client); |
76295adcf940
WIP: Add skeleton for MQTT extension based on part of OPC-UA extension.
Edouard Tisserant <edouard@beremiz.fr>
parents:
diff
changeset
|
477 |
return EXIT_FAILURE; |
76295adcf940
WIP: Add skeleton for MQTT extension based on part of OPC-UA extension.
Edouard Tisserant <edouard@beremiz.fr>
parents:
diff
changeset
|
478 |
}} |
76295adcf940
WIP: Add skeleton for MQTT extension based on part of OPC-UA extension.
Edouard Tisserant <edouard@beremiz.fr>
parents:
diff
changeset
|
479 |
return 0; |
76295adcf940
WIP: Add skeleton for MQTT extension based on part of OPC-UA extension.
Edouard Tisserant <edouard@beremiz.fr>
parents:
diff
changeset
|
480 |
}} |
76295adcf940
WIP: Add skeleton for MQTT extension based on part of OPC-UA extension.
Edouard Tisserant <edouard@beremiz.fr>
parents:
diff
changeset
|
481 |
|
76295adcf940
WIP: Add skeleton for MQTT extension based on part of OPC-UA extension.
Edouard Tisserant <edouard@beremiz.fr>
parents:
diff
changeset
|
482 |
#define READ_VALUE(ua_type, ua_type_enum, c_loc_name, ua_nodeid_type, ua_nsidx, ua_node_id) \\ |
76295adcf940
WIP: Add skeleton for MQTT extension based on part of OPC-UA extension.
Edouard Tisserant <edouard@beremiz.fr>
parents:
diff
changeset
|
483 |
retval = MQTT_Client_readValueAttribute( \\ |
76295adcf940
WIP: Add skeleton for MQTT extension based on part of OPC-UA extension.
Edouard Tisserant <edouard@beremiz.fr>
parents:
diff
changeset
|
484 |
client, ua_nodeid_type(ua_nsidx, ua_node_id), &c_loc_name##_variant); \\ |
76295adcf940
WIP: Add skeleton for MQTT extension based on part of OPC-UA extension.
Edouard Tisserant <edouard@beremiz.fr>
parents:
diff
changeset
|
485 |
if(retval == MQTT_STATUSCODE_GOOD && MQTT_Variant_isScalar(&c_loc_name##_variant) && \\ |
76295adcf940
WIP: Add skeleton for MQTT extension based on part of OPC-UA extension.
Edouard Tisserant <edouard@beremiz.fr>
parents:
diff
changeset
|
486 |
c_loc_name##_variant.type == &MQTT_TYPES[ua_type_enum]) {{ \\ |
76295adcf940
WIP: Add skeleton for MQTT extension based on part of OPC-UA extension.
Edouard Tisserant <edouard@beremiz.fr>
parents:
diff
changeset
|
487 |
c_loc_name##_buf = *(ua_type*)c_loc_name##_variant.data; \\ |
76295adcf940
WIP: Add skeleton for MQTT extension based on part of OPC-UA extension.
Edouard Tisserant <edouard@beremiz.fr>
parents:
diff
changeset
|
488 |
MQTT_Variant_clear(&c_loc_name##_variant); /* Unalloc requiered on each read ! */ \\ |
76295adcf940
WIP: Add skeleton for MQTT extension based on part of OPC-UA extension.
Edouard Tisserant <edouard@beremiz.fr>
parents:
diff
changeset
|
489 |
}} |
76295adcf940
WIP: Add skeleton for MQTT extension based on part of OPC-UA extension.
Edouard Tisserant <edouard@beremiz.fr>
parents:
diff
changeset
|
490 |
|
76295adcf940
WIP: Add skeleton for MQTT extension based on part of OPC-UA extension.
Edouard Tisserant <edouard@beremiz.fr>
parents:
diff
changeset
|
491 |
void __retrieve_{locstr}(void) |
76295adcf940
WIP: Add skeleton for MQTT extension based on part of OPC-UA extension.
Edouard Tisserant <edouard@beremiz.fr>
parents:
diff
changeset
|
492 |
{{ |
76295adcf940
WIP: Add skeleton for MQTT extension based on part of OPC-UA extension.
Edouard Tisserant <edouard@beremiz.fr>
parents:
diff
changeset
|
493 |
MQTT_StatusCode retval; |
76295adcf940
WIP: Add skeleton for MQTT extension based on part of OPC-UA extension.
Edouard Tisserant <edouard@beremiz.fr>
parents:
diff
changeset
|
494 |
{retrieve} |
76295adcf940
WIP: Add skeleton for MQTT extension based on part of OPC-UA extension.
Edouard Tisserant <edouard@beremiz.fr>
parents:
diff
changeset
|
495 |
}} |
76295adcf940
WIP: Add skeleton for MQTT extension based on part of OPC-UA extension.
Edouard Tisserant <edouard@beremiz.fr>
parents:
diff
changeset
|
496 |
|
76295adcf940
WIP: Add skeleton for MQTT extension based on part of OPC-UA extension.
Edouard Tisserant <edouard@beremiz.fr>
parents:
diff
changeset
|
497 |
#define WRITE_VALUE(ua_type, c_loc_name, ua_nodeid_type, ua_nsidx, ua_node_id) \\ |
76295adcf940
WIP: Add skeleton for MQTT extension based on part of OPC-UA extension.
Edouard Tisserant <edouard@beremiz.fr>
parents:
diff
changeset
|
498 |
MQTT_Client_writeValueAttribute( \\ |
76295adcf940
WIP: Add skeleton for MQTT extension based on part of OPC-UA extension.
Edouard Tisserant <edouard@beremiz.fr>
parents:
diff
changeset
|
499 |
client, ua_nodeid_type(ua_nsidx, ua_node_id), &c_loc_name##_variant); |
76295adcf940
WIP: Add skeleton for MQTT extension based on part of OPC-UA extension.
Edouard Tisserant <edouard@beremiz.fr>
parents:
diff
changeset
|
500 |
|
76295adcf940
WIP: Add skeleton for MQTT extension based on part of OPC-UA extension.
Edouard Tisserant <edouard@beremiz.fr>
parents:
diff
changeset
|
501 |
void __publish_{locstr}(void) |
76295adcf940
WIP: Add skeleton for MQTT extension based on part of OPC-UA extension.
Edouard Tisserant <edouard@beremiz.fr>
parents:
diff
changeset
|
502 |
{{ |
76295adcf940
WIP: Add skeleton for MQTT extension based on part of OPC-UA extension.
Edouard Tisserant <edouard@beremiz.fr>
parents:
diff
changeset
|
503 |
{publish} |
76295adcf940
WIP: Add skeleton for MQTT extension based on part of OPC-UA extension.
Edouard Tisserant <edouard@beremiz.fr>
parents:
diff
changeset
|
504 |
}} |
76295adcf940
WIP: Add skeleton for MQTT extension based on part of OPC-UA extension.
Edouard Tisserant <edouard@beremiz.fr>
parents:
diff
changeset
|
505 |
|
76295adcf940
WIP: Add skeleton for MQTT extension based on part of OPC-UA extension.
Edouard Tisserant <edouard@beremiz.fr>
parents:
diff
changeset
|
506 |
""" |
76295adcf940
WIP: Add skeleton for MQTT extension based on part of OPC-UA extension.
Edouard Tisserant <edouard@beremiz.fr>
parents:
diff
changeset
|
507 |
|
76295adcf940
WIP: Add skeleton for MQTT extension based on part of OPC-UA extension.
Edouard Tisserant <edouard@beremiz.fr>
parents:
diff
changeset
|
508 |
formatdict = dict( |
76295adcf940
WIP: Add skeleton for MQTT extension based on part of OPC-UA extension.
Edouard Tisserant <edouard@beremiz.fr>
parents:
diff
changeset
|
509 |
locstr = locstr, |
76295adcf940
WIP: Add skeleton for MQTT extension based on part of OPC-UA extension.
Edouard Tisserant <edouard@beremiz.fr>
parents:
diff
changeset
|
510 |
uri = config["URI"], |
3980
96acfee19caf
MQTT WIP: intermediate state, implementing MQTT client C code generator.
Edouard Tisserant <edouard@beremiz.fr>
parents:
3979
diff
changeset
|
511 |
clientID = config["clientID"], |
3979
76295adcf940
WIP: Add skeleton for MQTT extension based on part of OPC-UA extension.
Edouard Tisserant <edouard@beremiz.fr>
parents:
diff
changeset
|
512 |
decl = "", |
3981
74035ea6792c
MQTT WIP: intermediate state, added perfect hash to map topic to variables
Edouard Tisserant <edouard@beremiz.fr>
parents:
3980
diff
changeset
|
513 |
topics = "", |
3979
76295adcf940
WIP: Add skeleton for MQTT extension based on part of OPC-UA extension.
Edouard Tisserant <edouard@beremiz.fr>
parents:
diff
changeset
|
514 |
cleanup = "", |
76295adcf940
WIP: Add skeleton for MQTT extension based on part of OPC-UA extension.
Edouard Tisserant <edouard@beremiz.fr>
parents:
diff
changeset
|
515 |
init = "", |
76295adcf940
WIP: Add skeleton for MQTT extension based on part of OPC-UA extension.
Edouard Tisserant <edouard@beremiz.fr>
parents:
diff
changeset
|
516 |
retrieve = "", |
76295adcf940
WIP: Add skeleton for MQTT extension based on part of OPC-UA extension.
Edouard Tisserant <edouard@beremiz.fr>
parents:
diff
changeset
|
517 |
publish = "" |
76295adcf940
WIP: Add skeleton for MQTT extension based on part of OPC-UA extension.
Edouard Tisserant <edouard@beremiz.fr>
parents:
diff
changeset
|
518 |
) |
76295adcf940
WIP: Add skeleton for MQTT extension based on part of OPC-UA extension.
Edouard Tisserant <edouard@beremiz.fr>
parents:
diff
changeset
|
519 |
|
76295adcf940
WIP: Add skeleton for MQTT extension based on part of OPC-UA extension.
Edouard Tisserant <edouard@beremiz.fr>
parents:
diff
changeset
|
520 |
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
|
521 |
if AuthType == "x509": |
76295adcf940
WIP: Add skeleton for MQTT extension based on part of OPC-UA extension.
Edouard Tisserant <edouard@beremiz.fr>
parents:
diff
changeset
|
522 |
formatdict["init"] += """ |
76295adcf940
WIP: Add skeleton for MQTT extension based on part of OPC-UA extension.
Edouard Tisserant <edouard@beremiz.fr>
parents:
diff
changeset
|
523 |
INIT_x509("{PrivateKey}", "{Certificate}")""".format(**config) |
76295adcf940
WIP: Add skeleton for MQTT extension based on part of OPC-UA extension.
Edouard Tisserant <edouard@beremiz.fr>
parents:
diff
changeset
|
524 |
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
|
525 |
formatdict["init"] += """ |
76295adcf940
WIP: Add skeleton for MQTT extension based on part of OPC-UA extension.
Edouard Tisserant <edouard@beremiz.fr>
parents:
diff
changeset
|
526 |
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
|
527 |
else: |
76295adcf940
WIP: Add skeleton for MQTT extension based on part of OPC-UA extension.
Edouard Tisserant <edouard@beremiz.fr>
parents:
diff
changeset
|
528 |
formatdict["init"] += """ |
76295adcf940
WIP: Add skeleton for MQTT extension based on part of OPC-UA extension.
Edouard Tisserant <edouard@beremiz.fr>
parents:
diff
changeset
|
529 |
INIT_NoAuth()""" |
76295adcf940
WIP: Add skeleton for MQTT extension based on part of OPC-UA extension.
Edouard Tisserant <edouard@beremiz.fr>
parents:
diff
changeset
|
530 |
|
3981
74035ea6792c
MQTT WIP: intermediate state, added perfect hash to map topic to variables
Edouard Tisserant <edouard@beremiz.fr>
parents:
3980
diff
changeset
|
531 |
topics = OrderedDict() |
3979
76295adcf940
WIP: Add skeleton for MQTT extension based on part of OPC-UA extension.
Edouard Tisserant <edouard@beremiz.fr>
parents:
diff
changeset
|
532 |
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
|
533 |
iec_direction_prefix = {"input": "__I", "output": "__Q"}[direction] |
3981
74035ea6792c
MQTT WIP: intermediate state, added perfect hash to map topic to variables
Edouard Tisserant <edouard@beremiz.fr>
parents:
3980
diff
changeset
|
534 |
for row in data: |
74035ea6792c
MQTT WIP: intermediate state, added perfect hash to map topic to variables
Edouard Tisserant <edouard@beremiz.fr>
parents:
3980
diff
changeset
|
535 |
Topic, QoS, Retain, iec_type, iec_number = row |
74035ea6792c
MQTT WIP: intermediate state, added perfect hash to map topic to variables
Edouard Tisserant <edouard@beremiz.fr>
parents:
3980
diff
changeset
|
536 |
C_type, iec_size_prefix = MQTT_IEC_types[iec_type] |
74035ea6792c
MQTT WIP: intermediate state, added perfect hash to map topic to variables
Edouard Tisserant <edouard@beremiz.fr>
parents:
3980
diff
changeset
|
537 |
c_loc_name = iec_direction_prefix + iec_size_prefix + locstr + "_" + str(iec_number) |
74035ea6792c
MQTT WIP: intermediate state, added perfect hash to map topic to variables
Edouard Tisserant <edouard@beremiz.fr>
parents:
3980
diff
changeset
|
538 |
|
74035ea6792c
MQTT WIP: intermediate state, added perfect hash to map topic to variables
Edouard Tisserant <edouard@beremiz.fr>
parents:
3980
diff
changeset
|
539 |
formatdict["decl"] += """ |
74035ea6792c
MQTT WIP: intermediate state, added perfect hash to map topic to variables
Edouard Tisserant <edouard@beremiz.fr>
parents:
3980
diff
changeset
|
540 |
DECL_VAR({iec_type}, {C_type}, {c_loc_name})""".format(**locals()) |
74035ea6792c
MQTT WIP: intermediate state, added perfect hash to map topic to variables
Edouard Tisserant <edouard@beremiz.fr>
parents:
3980
diff
changeset
|
541 |
|
74035ea6792c
MQTT WIP: intermediate state, added perfect hash to map topic to variables
Edouard Tisserant <edouard@beremiz.fr>
parents:
3980
diff
changeset
|
542 |
formatdict["topics"] += """ |
74035ea6792c
MQTT WIP: intermediate state, added perfect hash to map topic to variables
Edouard Tisserant <edouard@beremiz.fr>
parents:
3980
diff
changeset
|
543 |
INIT_TOPIC({Topic}, {iec_type}, {c_loc_name})""".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
|
544 |
# |
76295adcf940
WIP: Add skeleton for MQTT extension based on part of OPC-UA extension.
Edouard Tisserant <edouard@beremiz.fr>
parents:
diff
changeset
|
545 |
# if direction == "input": |
76295adcf940
WIP: Add skeleton for MQTT extension based on part of OPC-UA extension.
Edouard Tisserant <edouard@beremiz.fr>
parents:
diff
changeset
|
546 |
# formatdict["init"] += """ |
76295adcf940
WIP: Add skeleton for MQTT extension based on part of OPC-UA extension.
Edouard Tisserant <edouard@beremiz.fr>
parents:
diff
changeset
|
547 |
# INIT_READ_VARIANT({ua_type}, {c_loc_name})""".format(**locals()) |
76295adcf940
WIP: Add skeleton for MQTT extension based on part of OPC-UA extension.
Edouard Tisserant <edouard@beremiz.fr>
parents:
diff
changeset
|
548 |
# formatdict["retrieve"] += """ |
76295adcf940
WIP: Add skeleton for MQTT extension based on part of OPC-UA extension.
Edouard Tisserant <edouard@beremiz.fr>
parents:
diff
changeset
|
549 |
# READ_VALUE({ua_type}, {ua_type_enum}, {c_loc_name}, {ua_nodeid_type}, {ua_nsidx}, {ua_node_id})""".format(**locals()) |
76295adcf940
WIP: Add skeleton for MQTT extension based on part of OPC-UA extension.
Edouard Tisserant <edouard@beremiz.fr>
parents:
diff
changeset
|
550 |
# |
76295adcf940
WIP: Add skeleton for MQTT extension based on part of OPC-UA extension.
Edouard Tisserant <edouard@beremiz.fr>
parents:
diff
changeset
|
551 |
# if direction == "output": |
76295adcf940
WIP: Add skeleton for MQTT extension based on part of OPC-UA extension.
Edouard Tisserant <edouard@beremiz.fr>
parents:
diff
changeset
|
552 |
# formatdict["init"] += """ |
76295adcf940
WIP: Add skeleton for MQTT extension based on part of OPC-UA extension.
Edouard Tisserant <edouard@beremiz.fr>
parents:
diff
changeset
|
553 |
# INIT_WRITE_VARIANT({ua_type}, {ua_type_enum}, {c_loc_name})""".format(**locals()) |
76295adcf940
WIP: Add skeleton for MQTT extension based on part of OPC-UA extension.
Edouard Tisserant <edouard@beremiz.fr>
parents:
diff
changeset
|
554 |
# formatdict["publish"] += """ |
76295adcf940
WIP: Add skeleton for MQTT extension based on part of OPC-UA extension.
Edouard Tisserant <edouard@beremiz.fr>
parents:
diff
changeset
|
555 |
# WRITE_VALUE({ua_type}, {c_loc_name}, {ua_nodeid_type}, {ua_nsidx}, {ua_node_id})""".format(**locals()) |
76295adcf940
WIP: Add skeleton for MQTT extension based on part of OPC-UA extension.
Edouard Tisserant <edouard@beremiz.fr>
parents:
diff
changeset
|
556 |
|
76295adcf940
WIP: Add skeleton for MQTT extension based on part of OPC-UA extension.
Edouard Tisserant <edouard@beremiz.fr>
parents:
diff
changeset
|
557 |
Ccode = template.format(**formatdict) |
76295adcf940
WIP: Add skeleton for MQTT extension based on part of OPC-UA extension.
Edouard Tisserant <edouard@beremiz.fr>
parents:
diff
changeset
|
558 |
|
76295adcf940
WIP: Add skeleton for MQTT extension based on part of OPC-UA extension.
Edouard Tisserant <edouard@beremiz.fr>
parents:
diff
changeset
|
559 |
return Ccode |
76295adcf940
WIP: Add skeleton for MQTT extension based on part of OPC-UA extension.
Edouard Tisserant <edouard@beremiz.fr>
parents:
diff
changeset
|
560 |
|
76295adcf940
WIP: Add skeleton for MQTT extension based on part of OPC-UA extension.
Edouard Tisserant <edouard@beremiz.fr>
parents:
diff
changeset
|
561 |
if __name__ == "__main__": |
76295adcf940
WIP: Add skeleton for MQTT extension based on part of OPC-UA extension.
Edouard Tisserant <edouard@beremiz.fr>
parents:
diff
changeset
|
562 |
|
76295adcf940
WIP: Add skeleton for MQTT extension based on part of OPC-UA extension.
Edouard Tisserant <edouard@beremiz.fr>
parents:
diff
changeset
|
563 |
import wx.lib.mixins.inspection as wit |
76295adcf940
WIP: Add skeleton for MQTT extension based on part of OPC-UA extension.
Edouard Tisserant <edouard@beremiz.fr>
parents:
diff
changeset
|
564 |
import sys,os |
76295adcf940
WIP: Add skeleton for MQTT extension based on part of OPC-UA extension.
Edouard Tisserant <edouard@beremiz.fr>
parents:
diff
changeset
|
565 |
|
76295adcf940
WIP: Add skeleton for MQTT extension based on part of OPC-UA extension.
Edouard Tisserant <edouard@beremiz.fr>
parents:
diff
changeset
|
566 |
app = wit.InspectableApp() |
76295adcf940
WIP: Add skeleton for MQTT extension based on part of OPC-UA extension.
Edouard Tisserant <edouard@beremiz.fr>
parents:
diff
changeset
|
567 |
|
76295adcf940
WIP: Add skeleton for MQTT extension based on part of OPC-UA extension.
Edouard Tisserant <edouard@beremiz.fr>
parents:
diff
changeset
|
568 |
frame = wx.Frame(None, -1, "MQTT Client Test App", size=(800,600)) |
76295adcf940
WIP: Add skeleton for MQTT extension based on part of OPC-UA extension.
Edouard Tisserant <edouard@beremiz.fr>
parents:
diff
changeset
|
569 |
|
76295adcf940
WIP: Add skeleton for MQTT extension based on part of OPC-UA extension.
Edouard Tisserant <edouard@beremiz.fr>
parents:
diff
changeset
|
570 |
argc = len(sys.argv) |
76295adcf940
WIP: Add skeleton for MQTT extension based on part of OPC-UA extension.
Edouard Tisserant <edouard@beremiz.fr>
parents:
diff
changeset
|
571 |
|
76295adcf940
WIP: Add skeleton for MQTT extension based on part of OPC-UA extension.
Edouard Tisserant <edouard@beremiz.fr>
parents:
diff
changeset
|
572 |
config={} |
3980
96acfee19caf
MQTT WIP: intermediate state, implementing MQTT client C code generator.
Edouard Tisserant <edouard@beremiz.fr>
parents:
3979
diff
changeset
|
573 |
config["URI"] = sys.argv[1] if argc>1 else "tcp://localhost:1883" |
96acfee19caf
MQTT WIP: intermediate state, implementing MQTT client C code generator.
Edouard Tisserant <edouard@beremiz.fr>
parents:
3979
diff
changeset
|
574 |
config["clientID"] = sys.argv[2] if argc>2 else "" |
3979
76295adcf940
WIP: Add skeleton for MQTT extension based on part of OPC-UA extension.
Edouard Tisserant <edouard@beremiz.fr>
parents:
diff
changeset
|
575 |
config["AuthType"] = None |
76295adcf940
WIP: Add skeleton for MQTT extension based on part of OPC-UA extension.
Edouard Tisserant <edouard@beremiz.fr>
parents:
diff
changeset
|
576 |
|
3980
96acfee19caf
MQTT WIP: intermediate state, implementing MQTT client C code generator.
Edouard Tisserant <edouard@beremiz.fr>
parents:
3979
diff
changeset
|
577 |
if argc > 3: |
96acfee19caf
MQTT WIP: intermediate state, implementing MQTT client C code generator.
Edouard Tisserant <edouard@beremiz.fr>
parents:
3979
diff
changeset
|
578 |
AuthType = sys.argv[3] |
3979
76295adcf940
WIP: Add skeleton for MQTT extension based on part of OPC-UA extension.
Edouard Tisserant <edouard@beremiz.fr>
parents:
diff
changeset
|
579 |
config["AuthType"] = AuthType |
3980
96acfee19caf
MQTT WIP: intermediate state, implementing MQTT client C code generator.
Edouard Tisserant <edouard@beremiz.fr>
parents:
3979
diff
changeset
|
580 |
for (name, default), value in zip_longest(authParams[AuthType], sys.argv[4:]): |
3979
76295adcf940
WIP: Add skeleton for MQTT extension based on part of OPC-UA extension.
Edouard Tisserant <edouard@beremiz.fr>
parents:
diff
changeset
|
581 |
if value is None: |
76295adcf940
WIP: Add skeleton for MQTT extension based on part of OPC-UA extension.
Edouard Tisserant <edouard@beremiz.fr>
parents:
diff
changeset
|
582 |
if default is None: |
76295adcf940
WIP: Add skeleton for MQTT extension based on part of OPC-UA extension.
Edouard Tisserant <edouard@beremiz.fr>
parents:
diff
changeset
|
583 |
raise Exception(name+" param expected") |
76295adcf940
WIP: Add skeleton for MQTT extension based on part of OPC-UA extension.
Edouard Tisserant <edouard@beremiz.fr>
parents:
diff
changeset
|
584 |
value = default |
76295adcf940
WIP: Add skeleton for MQTT extension based on part of OPC-UA extension.
Edouard Tisserant <edouard@beremiz.fr>
parents:
diff
changeset
|
585 |
config[name] = value |
76295adcf940
WIP: Add skeleton for MQTT extension based on part of OPC-UA extension.
Edouard Tisserant <edouard@beremiz.fr>
parents:
diff
changeset
|
586 |
|
76295adcf940
WIP: Add skeleton for MQTT extension based on part of OPC-UA extension.
Edouard Tisserant <edouard@beremiz.fr>
parents:
diff
changeset
|
587 |
test_panel = wx.Panel(frame) |
76295adcf940
WIP: Add skeleton for MQTT extension based on part of OPC-UA extension.
Edouard Tisserant <edouard@beremiz.fr>
parents:
diff
changeset
|
588 |
test_sizer = wx.FlexGridSizer(cols=1, hgap=0, rows=2, vgap=0) |
76295adcf940
WIP: Add skeleton for MQTT extension based on part of OPC-UA extension.
Edouard Tisserant <edouard@beremiz.fr>
parents:
diff
changeset
|
589 |
test_sizer.AddGrowableCol(0) |
76295adcf940
WIP: Add skeleton for MQTT extension based on part of OPC-UA extension.
Edouard Tisserant <edouard@beremiz.fr>
parents:
diff
changeset
|
590 |
test_sizer.AddGrowableRow(0) |
76295adcf940
WIP: Add skeleton for MQTT extension based on part of OPC-UA extension.
Edouard Tisserant <edouard@beremiz.fr>
parents:
diff
changeset
|
591 |
|
76295adcf940
WIP: Add skeleton for MQTT extension based on part of OPC-UA extension.
Edouard Tisserant <edouard@beremiz.fr>
parents:
diff
changeset
|
592 |
modeldata = MQTTClientModel(print) |
76295adcf940
WIP: Add skeleton for MQTT extension based on part of OPC-UA extension.
Edouard Tisserant <edouard@beremiz.fr>
parents:
diff
changeset
|
593 |
|
76295adcf940
WIP: Add skeleton for MQTT extension based on part of OPC-UA extension.
Edouard Tisserant <edouard@beremiz.fr>
parents:
diff
changeset
|
594 |
mqtttestpanel = MQTTClientPanel(test_panel, modeldata, print, lambda:config) |
76295adcf940
WIP: Add skeleton for MQTT extension based on part of OPC-UA extension.
Edouard Tisserant <edouard@beremiz.fr>
parents:
diff
changeset
|
595 |
|
76295adcf940
WIP: Add skeleton for MQTT extension based on part of OPC-UA extension.
Edouard Tisserant <edouard@beremiz.fr>
parents:
diff
changeset
|
596 |
def OnGenerate(evt): |
76295adcf940
WIP: Add skeleton for MQTT extension based on part of OPC-UA extension.
Edouard Tisserant <edouard@beremiz.fr>
parents:
diff
changeset
|
597 |
dlg = wx.FileDialog( |
76295adcf940
WIP: Add skeleton for MQTT extension based on part of OPC-UA extension.
Edouard Tisserant <edouard@beremiz.fr>
parents:
diff
changeset
|
598 |
frame, message="Generate file as ...", defaultDir=os.getcwd(), |
76295adcf940
WIP: Add skeleton for MQTT extension based on part of OPC-UA extension.
Edouard Tisserant <edouard@beremiz.fr>
parents:
diff
changeset
|
599 |
defaultFile="", |
76295adcf940
WIP: Add skeleton for MQTT extension based on part of OPC-UA extension.
Edouard Tisserant <edouard@beremiz.fr>
parents:
diff
changeset
|
600 |
wildcard="C (*.c)|*.c", style=wx.FD_SAVE | wx.FD_OVERWRITE_PROMPT |
76295adcf940
WIP: Add skeleton for MQTT extension based on part of OPC-UA extension.
Edouard Tisserant <edouard@beremiz.fr>
parents:
diff
changeset
|
601 |
) |
76295adcf940
WIP: Add skeleton for MQTT extension based on part of OPC-UA extension.
Edouard Tisserant <edouard@beremiz.fr>
parents:
diff
changeset
|
602 |
|
76295adcf940
WIP: Add skeleton for MQTT extension based on part of OPC-UA extension.
Edouard Tisserant <edouard@beremiz.fr>
parents:
diff
changeset
|
603 |
if dlg.ShowModal() == wx.ID_OK: |
76295adcf940
WIP: Add skeleton for MQTT extension based on part of OPC-UA extension.
Edouard Tisserant <edouard@beremiz.fr>
parents:
diff
changeset
|
604 |
path = dlg.GetPath() |
76295adcf940
WIP: Add skeleton for MQTT extension based on part of OPC-UA extension.
Edouard Tisserant <edouard@beremiz.fr>
parents:
diff
changeset
|
605 |
Ccode = """ |
76295adcf940
WIP: Add skeleton for MQTT extension based on part of OPC-UA extension.
Edouard Tisserant <edouard@beremiz.fr>
parents:
diff
changeset
|
606 |
/* |
76295adcf940
WIP: Add skeleton for MQTT extension based on part of OPC-UA extension.
Edouard Tisserant <edouard@beremiz.fr>
parents:
diff
changeset
|
607 |
In case open62541 was built just aside beremiz, you can build this test with: |
76295adcf940
WIP: Add skeleton for MQTT extension based on part of OPC-UA extension.
Edouard Tisserant <edouard@beremiz.fr>
parents:
diff
changeset
|
608 |
gcc %s -o %s \\ |
76295adcf940
WIP: Add skeleton for MQTT extension based on part of OPC-UA extension.
Edouard Tisserant <edouard@beremiz.fr>
parents:
diff
changeset
|
609 |
-I ../../open62541/plugins/include/ \\ |
76295adcf940
WIP: Add skeleton for MQTT extension based on part of OPC-UA extension.
Edouard Tisserant <edouard@beremiz.fr>
parents:
diff
changeset
|
610 |
-I ../../open62541/build/src_generated/ \\ |
76295adcf940
WIP: Add skeleton for MQTT extension based on part of OPC-UA extension.
Edouard Tisserant <edouard@beremiz.fr>
parents:
diff
changeset
|
611 |
-I ../../open62541/include/ \\ |
76295adcf940
WIP: Add skeleton for MQTT extension based on part of OPC-UA extension.
Edouard Tisserant <edouard@beremiz.fr>
parents:
diff
changeset
|
612 |
-I ../../open62541/arch/ ../../open62541/build/bin/libopen62541.a |
76295adcf940
WIP: Add skeleton for MQTT extension based on part of OPC-UA extension.
Edouard Tisserant <edouard@beremiz.fr>
parents:
diff
changeset
|
613 |
*/ |
76295adcf940
WIP: Add skeleton for MQTT extension based on part of OPC-UA extension.
Edouard Tisserant <edouard@beremiz.fr>
parents:
diff
changeset
|
614 |
|
76295adcf940
WIP: Add skeleton for MQTT extension based on part of OPC-UA extension.
Edouard Tisserant <edouard@beremiz.fr>
parents:
diff
changeset
|
615 |
"""%(path, path[:-2]) + modeldata.GenerateC(path, "test", config) + """ |
76295adcf940
WIP: Add skeleton for MQTT extension based on part of OPC-UA extension.
Edouard Tisserant <edouard@beremiz.fr>
parents:
diff
changeset
|
616 |
|
76295adcf940
WIP: Add skeleton for MQTT extension based on part of OPC-UA extension.
Edouard Tisserant <edouard@beremiz.fr>
parents:
diff
changeset
|
617 |
int LogMessage(uint8_t level, char* buf, uint32_t size){ |
76295adcf940
WIP: Add skeleton for MQTT extension based on part of OPC-UA extension.
Edouard Tisserant <edouard@beremiz.fr>
parents:
diff
changeset
|
618 |
printf("log level:%d message:'%.*s'\\n", level, size, buf); |
76295adcf940
WIP: Add skeleton for MQTT extension based on part of OPC-UA extension.
Edouard Tisserant <edouard@beremiz.fr>
parents:
diff
changeset
|
619 |
}; |
76295adcf940
WIP: Add skeleton for MQTT extension based on part of OPC-UA extension.
Edouard Tisserant <edouard@beremiz.fr>
parents:
diff
changeset
|
620 |
|
76295adcf940
WIP: Add skeleton for MQTT extension based on part of OPC-UA extension.
Edouard Tisserant <edouard@beremiz.fr>
parents:
diff
changeset
|
621 |
int main(int argc, char *argv[]) { |
76295adcf940
WIP: Add skeleton for MQTT extension based on part of OPC-UA extension.
Edouard Tisserant <edouard@beremiz.fr>
parents:
diff
changeset
|
622 |
|
76295adcf940
WIP: Add skeleton for MQTT extension based on part of OPC-UA extension.
Edouard Tisserant <edouard@beremiz.fr>
parents:
diff
changeset
|
623 |
__init_test(arc,argv); |
76295adcf940
WIP: Add skeleton for MQTT extension based on part of OPC-UA extension.
Edouard Tisserant <edouard@beremiz.fr>
parents:
diff
changeset
|
624 |
|
76295adcf940
WIP: Add skeleton for MQTT extension based on part of OPC-UA extension.
Edouard Tisserant <edouard@beremiz.fr>
parents:
diff
changeset
|
625 |
__retrieve_test(); |
76295adcf940
WIP: Add skeleton for MQTT extension based on part of OPC-UA extension.
Edouard Tisserant <edouard@beremiz.fr>
parents:
diff
changeset
|
626 |
|
76295adcf940
WIP: Add skeleton for MQTT extension based on part of OPC-UA extension.
Edouard Tisserant <edouard@beremiz.fr>
parents:
diff
changeset
|
627 |
__publish_test(); |
76295adcf940
WIP: Add skeleton for MQTT extension based on part of OPC-UA extension.
Edouard Tisserant <edouard@beremiz.fr>
parents:
diff
changeset
|
628 |
|
76295adcf940
WIP: Add skeleton for MQTT extension based on part of OPC-UA extension.
Edouard Tisserant <edouard@beremiz.fr>
parents:
diff
changeset
|
629 |
__cleanup_test(); |
76295adcf940
WIP: Add skeleton for MQTT extension based on part of OPC-UA extension.
Edouard Tisserant <edouard@beremiz.fr>
parents:
diff
changeset
|
630 |
|
76295adcf940
WIP: Add skeleton for MQTT extension based on part of OPC-UA extension.
Edouard Tisserant <edouard@beremiz.fr>
parents:
diff
changeset
|
631 |
return EXIT_SUCCESS; |
76295adcf940
WIP: Add skeleton for MQTT extension based on part of OPC-UA extension.
Edouard Tisserant <edouard@beremiz.fr>
parents:
diff
changeset
|
632 |
} |
76295adcf940
WIP: Add skeleton for MQTT extension based on part of OPC-UA extension.
Edouard Tisserant <edouard@beremiz.fr>
parents:
diff
changeset
|
633 |
""" |
76295adcf940
WIP: Add skeleton for MQTT extension based on part of OPC-UA extension.
Edouard Tisserant <edouard@beremiz.fr>
parents:
diff
changeset
|
634 |
|
76295adcf940
WIP: Add skeleton for MQTT extension based on part of OPC-UA extension.
Edouard Tisserant <edouard@beremiz.fr>
parents:
diff
changeset
|
635 |
with open(path, 'w') as Cfile: |
76295adcf940
WIP: Add skeleton for MQTT extension based on part of OPC-UA extension.
Edouard Tisserant <edouard@beremiz.fr>
parents:
diff
changeset
|
636 |
Cfile.write(Ccode) |
76295adcf940
WIP: Add skeleton for MQTT extension based on part of OPC-UA extension.
Edouard Tisserant <edouard@beremiz.fr>
parents:
diff
changeset
|
637 |
|
76295adcf940
WIP: Add skeleton for MQTT extension based on part of OPC-UA extension.
Edouard Tisserant <edouard@beremiz.fr>
parents:
diff
changeset
|
638 |
|
76295adcf940
WIP: Add skeleton for MQTT extension based on part of OPC-UA extension.
Edouard Tisserant <edouard@beremiz.fr>
parents:
diff
changeset
|
639 |
dlg.Destroy() |
76295adcf940
WIP: Add skeleton for MQTT extension based on part of OPC-UA extension.
Edouard Tisserant <edouard@beremiz.fr>
parents:
diff
changeset
|
640 |
|
76295adcf940
WIP: Add skeleton for MQTT extension based on part of OPC-UA extension.
Edouard Tisserant <edouard@beremiz.fr>
parents:
diff
changeset
|
641 |
def OnLoad(evt): |
76295adcf940
WIP: Add skeleton for MQTT extension based on part of OPC-UA extension.
Edouard Tisserant <edouard@beremiz.fr>
parents:
diff
changeset
|
642 |
dlg = wx.FileDialog( |
76295adcf940
WIP: Add skeleton for MQTT extension based on part of OPC-UA extension.
Edouard Tisserant <edouard@beremiz.fr>
parents:
diff
changeset
|
643 |
frame, message="Choose a file", |
76295adcf940
WIP: Add skeleton for MQTT extension based on part of OPC-UA extension.
Edouard Tisserant <edouard@beremiz.fr>
parents:
diff
changeset
|
644 |
defaultDir=os.getcwd(), |
76295adcf940
WIP: Add skeleton for MQTT extension based on part of OPC-UA extension.
Edouard Tisserant <edouard@beremiz.fr>
parents:
diff
changeset
|
645 |
defaultFile="", |
76295adcf940
WIP: Add skeleton for MQTT extension based on part of OPC-UA extension.
Edouard Tisserant <edouard@beremiz.fr>
parents:
diff
changeset
|
646 |
wildcard="CSV (*.csv)|*.csv", |
76295adcf940
WIP: Add skeleton for MQTT extension based on part of OPC-UA extension.
Edouard Tisserant <edouard@beremiz.fr>
parents:
diff
changeset
|
647 |
style=wx.FD_OPEN | wx.FD_CHANGE_DIR | wx.FD_FILE_MUST_EXIST ) |
76295adcf940
WIP: Add skeleton for MQTT extension based on part of OPC-UA extension.
Edouard Tisserant <edouard@beremiz.fr>
parents:
diff
changeset
|
648 |
|
76295adcf940
WIP: Add skeleton for MQTT extension based on part of OPC-UA extension.
Edouard Tisserant <edouard@beremiz.fr>
parents:
diff
changeset
|
649 |
if dlg.ShowModal() == wx.ID_OK: |
76295adcf940
WIP: Add skeleton for MQTT extension based on part of OPC-UA extension.
Edouard Tisserant <edouard@beremiz.fr>
parents:
diff
changeset
|
650 |
path = dlg.GetPath() |
76295adcf940
WIP: Add skeleton for MQTT extension based on part of OPC-UA extension.
Edouard Tisserant <edouard@beremiz.fr>
parents:
diff
changeset
|
651 |
modeldata.LoadCSV(path) |
76295adcf940
WIP: Add skeleton for MQTT extension based on part of OPC-UA extension.
Edouard Tisserant <edouard@beremiz.fr>
parents:
diff
changeset
|
652 |
mqtttestpanel.Reset() |
76295adcf940
WIP: Add skeleton for MQTT extension based on part of OPC-UA extension.
Edouard Tisserant <edouard@beremiz.fr>
parents:
diff
changeset
|
653 |
|
76295adcf940
WIP: Add skeleton for MQTT extension based on part of OPC-UA extension.
Edouard Tisserant <edouard@beremiz.fr>
parents:
diff
changeset
|
654 |
dlg.Destroy() |
76295adcf940
WIP: Add skeleton for MQTT extension based on part of OPC-UA extension.
Edouard Tisserant <edouard@beremiz.fr>
parents:
diff
changeset
|
655 |
|
76295adcf940
WIP: Add skeleton for MQTT extension based on part of OPC-UA extension.
Edouard Tisserant <edouard@beremiz.fr>
parents:
diff
changeset
|
656 |
def OnSave(evt): |
76295adcf940
WIP: Add skeleton for MQTT extension based on part of OPC-UA extension.
Edouard Tisserant <edouard@beremiz.fr>
parents:
diff
changeset
|
657 |
dlg = wx.FileDialog( |
76295adcf940
WIP: Add skeleton for MQTT extension based on part of OPC-UA extension.
Edouard Tisserant <edouard@beremiz.fr>
parents:
diff
changeset
|
658 |
frame, message="Save file as ...", defaultDir=os.getcwd(), |
76295adcf940
WIP: Add skeleton for MQTT extension based on part of OPC-UA extension.
Edouard Tisserant <edouard@beremiz.fr>
parents:
diff
changeset
|
659 |
defaultFile="", |
76295adcf940
WIP: Add skeleton for MQTT extension based on part of OPC-UA extension.
Edouard Tisserant <edouard@beremiz.fr>
parents:
diff
changeset
|
660 |
wildcard="CSV (*.csv)|*.csv", style=wx.FD_SAVE | wx.FD_OVERWRITE_PROMPT |
76295adcf940
WIP: Add skeleton for MQTT extension based on part of OPC-UA extension.
Edouard Tisserant <edouard@beremiz.fr>
parents:
diff
changeset
|
661 |
) |
76295adcf940
WIP: Add skeleton for MQTT extension based on part of OPC-UA extension.
Edouard Tisserant <edouard@beremiz.fr>
parents:
diff
changeset
|
662 |
|
76295adcf940
WIP: Add skeleton for MQTT extension based on part of OPC-UA extension.
Edouard Tisserant <edouard@beremiz.fr>
parents:
diff
changeset
|
663 |
if dlg.ShowModal() == wx.ID_OK: |
76295adcf940
WIP: Add skeleton for MQTT extension based on part of OPC-UA extension.
Edouard Tisserant <edouard@beremiz.fr>
parents:
diff
changeset
|
664 |
path = dlg.GetPath() |
76295adcf940
WIP: Add skeleton for MQTT extension based on part of OPC-UA extension.
Edouard Tisserant <edouard@beremiz.fr>
parents:
diff
changeset
|
665 |
modeldata.SaveCSV(path) |
76295adcf940
WIP: Add skeleton for MQTT extension based on part of OPC-UA extension.
Edouard Tisserant <edouard@beremiz.fr>
parents:
diff
changeset
|
666 |
|
76295adcf940
WIP: Add skeleton for MQTT extension based on part of OPC-UA extension.
Edouard Tisserant <edouard@beremiz.fr>
parents:
diff
changeset
|
667 |
dlg.Destroy() |
76295adcf940
WIP: Add skeleton for MQTT extension based on part of OPC-UA extension.
Edouard Tisserant <edouard@beremiz.fr>
parents:
diff
changeset
|
668 |
|
76295adcf940
WIP: Add skeleton for MQTT extension based on part of OPC-UA extension.
Edouard Tisserant <edouard@beremiz.fr>
parents:
diff
changeset
|
669 |
test_sizer.Add(mqtttestpanel, flag=wx.GROW|wx.EXPAND) |
76295adcf940
WIP: Add skeleton for MQTT extension based on part of OPC-UA extension.
Edouard Tisserant <edouard@beremiz.fr>
parents:
diff
changeset
|
670 |
|
76295adcf940
WIP: Add skeleton for MQTT extension based on part of OPC-UA extension.
Edouard Tisserant <edouard@beremiz.fr>
parents:
diff
changeset
|
671 |
testbt_sizer = 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
|
672 |
|
76295adcf940
WIP: Add skeleton for MQTT extension based on part of OPC-UA extension.
Edouard Tisserant <edouard@beremiz.fr>
parents:
diff
changeset
|
673 |
loadbt = wx.Button(test_panel, label="Load") |
76295adcf940
WIP: Add skeleton for MQTT extension based on part of OPC-UA extension.
Edouard Tisserant <edouard@beremiz.fr>
parents:
diff
changeset
|
674 |
test_panel.Bind(wx.EVT_BUTTON, OnLoad, loadbt) |
76295adcf940
WIP: Add skeleton for MQTT extension based on part of OPC-UA extension.
Edouard Tisserant <edouard@beremiz.fr>
parents:
diff
changeset
|
675 |
|
76295adcf940
WIP: Add skeleton for MQTT extension based on part of OPC-UA extension.
Edouard Tisserant <edouard@beremiz.fr>
parents:
diff
changeset
|
676 |
savebt = wx.Button(test_panel, label="Save") |
76295adcf940
WIP: Add skeleton for MQTT extension based on part of OPC-UA extension.
Edouard Tisserant <edouard@beremiz.fr>
parents:
diff
changeset
|
677 |
test_panel.Bind(wx.EVT_BUTTON, OnSave, savebt) |
76295adcf940
WIP: Add skeleton for MQTT extension based on part of OPC-UA extension.
Edouard Tisserant <edouard@beremiz.fr>
parents:
diff
changeset
|
678 |
|
76295adcf940
WIP: Add skeleton for MQTT extension based on part of OPC-UA extension.
Edouard Tisserant <edouard@beremiz.fr>
parents:
diff
changeset
|
679 |
genbt = wx.Button(test_panel, label="Generate") |
76295adcf940
WIP: Add skeleton for MQTT extension based on part of OPC-UA extension.
Edouard Tisserant <edouard@beremiz.fr>
parents:
diff
changeset
|
680 |
test_panel.Bind(wx.EVT_BUTTON, OnGenerate, genbt) |
76295adcf940
WIP: Add skeleton for MQTT extension based on part of OPC-UA extension.
Edouard Tisserant <edouard@beremiz.fr>
parents:
diff
changeset
|
681 |
|
76295adcf940
WIP: Add skeleton for MQTT extension based on part of OPC-UA extension.
Edouard Tisserant <edouard@beremiz.fr>
parents:
diff
changeset
|
682 |
testbt_sizer.Add(loadbt, 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
|
683 |
testbt_sizer.Add(savebt, 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
|
684 |
testbt_sizer.Add(genbt, 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
|
685 |
|
76295adcf940
WIP: Add skeleton for MQTT extension based on part of OPC-UA extension.
Edouard Tisserant <edouard@beremiz.fr>
parents:
diff
changeset
|
686 |
test_sizer.Add(testbt_sizer, flag=wx.GROW) |
76295adcf940
WIP: Add skeleton for MQTT extension based on part of OPC-UA extension.
Edouard Tisserant <edouard@beremiz.fr>
parents:
diff
changeset
|
687 |
test_sizer.Layout() |
76295adcf940
WIP: Add skeleton for MQTT extension based on part of OPC-UA extension.
Edouard Tisserant <edouard@beremiz.fr>
parents:
diff
changeset
|
688 |
test_panel.SetAutoLayout(True) |
76295adcf940
WIP: Add skeleton for MQTT extension based on part of OPC-UA extension.
Edouard Tisserant <edouard@beremiz.fr>
parents:
diff
changeset
|
689 |
test_panel.SetSizer(test_sizer) |
76295adcf940
WIP: Add skeleton for MQTT extension based on part of OPC-UA extension.
Edouard Tisserant <edouard@beremiz.fr>
parents:
diff
changeset
|
690 |
|
76295adcf940
WIP: Add skeleton for MQTT extension based on part of OPC-UA extension.
Edouard Tisserant <edouard@beremiz.fr>
parents:
diff
changeset
|
691 |
def OnClose(evt): |
76295adcf940
WIP: Add skeleton for MQTT extension based on part of OPC-UA extension.
Edouard Tisserant <edouard@beremiz.fr>
parents:
diff
changeset
|
692 |
mqtttestpanel.OnClose() |
76295adcf940
WIP: Add skeleton for MQTT extension based on part of OPC-UA extension.
Edouard Tisserant <edouard@beremiz.fr>
parents:
diff
changeset
|
693 |
evt.Skip() |
76295adcf940
WIP: Add skeleton for MQTT extension based on part of OPC-UA extension.
Edouard Tisserant <edouard@beremiz.fr>
parents:
diff
changeset
|
694 |
|
76295adcf940
WIP: Add skeleton for MQTT extension based on part of OPC-UA extension.
Edouard Tisserant <edouard@beremiz.fr>
parents:
diff
changeset
|
695 |
frame.Bind(wx.EVT_CLOSE, OnClose) |
76295adcf940
WIP: Add skeleton for MQTT extension based on part of OPC-UA extension.
Edouard Tisserant <edouard@beremiz.fr>
parents:
diff
changeset
|
696 |
|
76295adcf940
WIP: Add skeleton for MQTT extension based on part of OPC-UA extension.
Edouard Tisserant <edouard@beremiz.fr>
parents:
diff
changeset
|
697 |
frame.Show() |
76295adcf940
WIP: Add skeleton for MQTT extension based on part of OPC-UA extension.
Edouard Tisserant <edouard@beremiz.fr>
parents:
diff
changeset
|
698 |
|
76295adcf940
WIP: Add skeleton for MQTT extension based on part of OPC-UA extension.
Edouard Tisserant <edouard@beremiz.fr>
parents:
diff
changeset
|
699 |
app.MainLoop() |