--- a/mqtt/mqtt_client_gen.py Fri Jun 14 15:56:12 2024 +0200
+++ b/mqtt/mqtt_client_gen.py Wed Jul 03 11:44:01 2024 +0200
@@ -8,6 +8,7 @@
+from perfect_hash import generate_code, IntSaltHash @@ -286,6 +287,39 @@
writer.writerow([direction] + row)
+ def _TopicsPerfectHash(self, topics): +#define NK $NK /* number of keys */ +#define NG $NG /* number of vertices */ +#define NS $NS /* length of array T1 and T2 */ + code = generate_code(topics, Hash=IntSaltHash, template=template) +/* return index of key in K if key is found, -1 otherwise */ +int MQTT_Topic_index(const char *key) + for (i = 0; key[i] != '\\0' && i < NS; i++) { + i = (G[f1] + G[f2]) % NG; + if (i < NK && strcmp(key, K[i]) == 0) def GenerateC(self, path, locstr, config):
template = """/* code generated by beremiz MQTT extension */
@@ -338,13 +372,23 @@
LogWarning("Paho MQTT Trace : %d, %s\n", level, message);
-#define DECL_VAR(ua_type, C_type, c_loc_name) \\
-static MQTT_Variant c_loc_name##_variant; \\
+#define DECL_VAR(iec_type, C_type, c_loc_name) \\ static C_type c_loc_name##_buf = 0; \\
C_type *c_loc_name = &c_loc_name##_buf;
+#define INIT_TOPIC(topic, iec_type, c_loc_name) \\ +{topic, &c_loc_name##_buf, iec_type##_ENUM}, + const char *topic; //null terminated topic string + void *pdata; //pointer to data + __IEC_types_enum vartype; void __cleanup_{locstr}(void)
MQTT_Client_disconnect(client);
@@ -466,6 +510,7 @@
clientID = config["clientID"],
@@ -483,17 +528,19 @@
formatdict["init"] += """
for direction, data in self.items():
iec_direction_prefix = {"input": "__I", "output": "__Q"}[direction]
-# name, ua_nsidx, ua_nodeid_type, _ua_node_id, ua_type, iec_number = row
-# iec_type, C_type, iec_size_prefix, ua_type_enum, ua_type = MQTT_IEC_types[ua_type]
-# c_loc_name = iec_direction_prefix + iec_size_prefix + locstr + "_" + str(iec_number)
-# ua_nodeid_type, id_formating = MQTT_NODE_ID_types[ua_nodeid_type]
-# ua_node_id = id_formating.format(_ua_node_id)
-# formatdict["decl"] += """
-#DECL_VAR({ua_type}, {C_type}, {c_loc_name})""".format(**locals())
+ Topic, QoS, Retain, iec_type, iec_number = row + C_type, iec_size_prefix = MQTT_IEC_types[iec_type] + c_loc_name = iec_direction_prefix + iec_size_prefix + locstr + "_" + str(iec_number) + formatdict["decl"] += """ +DECL_VAR({iec_type}, {C_type}, {c_loc_name})""".format(**locals()) + formatdict["topics"] += """ +INIT_TOPIC({Topic}, {iec_type}, {c_loc_name})""".format(**locals()) # if direction == "input":
# formatdict["init"] += """