@@ -201,32 +201,50 @@ def diff_time(_time=0):
201
201
# Transmit picode
202
202
def tx_picode (picode = "" ):
203
203
204
- picode_dict = picode_parse (picode )
204
+ # Search for picode sequences
205
+ picode_list = find_picode (picode )
205
206
206
- if not picode_dict :
207
+ if not len ( picode_list ) > 0 :
207
208
return ("Error(422) Unprocessable Entity picode string parse" ,422 )
209
+
210
+ # Checks picode list and stores it to a dict of lists
211
+ picode_dict_list = list ()
212
+
213
+ for picode_string in picode_list :
214
+ picode_parsed = picode_parse (picode_string )
215
+ if picode_parsed :
216
+ if "t" in picode_parsed and len (picode_list )> 1 :
217
+ return ("Error(422) Unprocessable Entity 't' param not allowed in multiline picode" ,422 )
218
+ elif not "r" in picode_parsed and len (picode_list )> 1 :
219
+ # Add param {"r":1} in multiline picode
220
+ picode_parsed ["r" ]= 1
221
+ picode_dict_list .append (picode_parsed )
222
+ else :
223
+ return ("Error(422) Unprocessable Entity picode string list parse" ,422 )
208
224
225
+ # Parse first list of dict
226
+ picode_dict = picode_dict_list [0 ]
209
227
pulse_list = picode_pulselist (picode_dict )
210
228
211
229
if not pulse_list :
212
230
return ("Error(422) Unprocessable Entity picode pulse list" ,422 )
213
231
232
+ # Check if picode is timed
214
233
timed = 0
215
- repeats = DEFAULT_REPEATS
216
-
217
234
if "t" in picode_dict .keys ():
218
235
timed = picode_dict ["t" ]
219
- elif "r" in picode_dict .keys ():
220
- repeats = picode_dict ["r" ]
236
+ elif not "r" in picode_dict .keys ():
237
+ picode_dict ["r" ] = DEFAULT_REPEATS
221
238
239
+ # If timed picode
222
240
if timed > 0 :
223
241
# Begin RF TX (timed)
224
242
initial = time .time_ns ()
225
243
final = initial + timed * (10 ** 9 )
226
244
227
245
while time .time_ns () < final :
228
246
try :
229
- result = wiringpiook .tx (config ['tx_gpio' ],pulse_list , repeats )
247
+ result = wiringpiook .tx (config ['tx_gpio' ],pulse_list )
230
248
except Exception as err :
231
249
return ("Error(424) %s" % err ,424 )
232
250
if result < 0 :
@@ -239,23 +257,42 @@ def tx_picode(picode=""):
239
257
240
258
else :
241
259
# Begin RF TX (repeats)
242
- try :
243
- result = wiringpiook .tx (config ['tx_gpio' ],pulse_list ,repeats )
244
- except Exception as err :
245
- return ("Error(424) %s" % err ,424 )
260
+ total_tx_time = 0
261
+ pulse_index = 0
262
+ while pulse_index < len (picode_list ):
263
+ try :
264
+ result = wiringpiook .tx (config ['tx_gpio' ],pulse_list ,picode_dict ["r" ])
265
+ except Exception as err :
266
+ return ("Error(424) %s" % err ,424 )
246
267
247
- if result < 0 :
248
- return ("ERROR (%d)" % result ,424 )
268
+ if result < 0 :
269
+ return ("ERROR (%d)" % result ,424 )
249
270
250
- if result > MAX_TX_TIME :
251
- dropped = "TX dropped!"
252
- else :
253
- dropped = "OK"
271
+ total_tx_time = total_tx_time + result
272
+
273
+ if total_tx_time > MAX_TX_TIME :
274
+ dropped = "TX dropped!"
275
+ # Force loop break
276
+ pulse_index = len (picode_list )
277
+ else :
278
+ dropped = "OK"
279
+
280
+ pulse_index = pulse_index + 1
281
+
282
+ # Parse next picode in the list if available
283
+ if pulse_index < len (picode_list ):
284
+ picode_dict = picode_dict_list [pulse_index ]
285
+ if picode_dict :
286
+ pulse_list = picode_pulselist (picode_dict )
287
+ else :
288
+ dropped = "ERROR"
289
+ # Force loop break
290
+ pulse_index = len (picode_list )
254
291
255
292
status ["tx_count" ] += 1
256
293
status ["last_tx" ] = time .strftime ("%Y-%m-%d %H:%M:%S" ,time .localtime ())
257
294
258
- return ("RF TX sent picode in %d ms %s" % (result ,dropped ) ,202 )
295
+ return ("RF TX sent picode in %d ms %s" % (total_tx_time ,dropped ) ,202 )
259
296
260
297
# --------------------------------------------------------------------------- #
261
298
# Route to landing page
0 commit comments