-
Notifications
You must be signed in to change notification settings - Fork 1
/
CSVLogger.xml
1093 lines (1086 loc) · 34.1 KB
/
CSVLogger.xml
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
<?xml version="1.0" encoding="UTF-8"?>
<microprocessor name="CSV Logger" description="Sends numbers to external program to create logs in CSV format. Source and binnaries available at https://github.com/Fernir2000/" hide_in_inventory="false" width="2" length="2" id_counter="243" id_counter_node="4" transform_index="0" sym0="0" sym1="0" sym2="7644" sym3="5444" sym4="1348" sym5="1348" sym6="7620" sym7="0" sym8="2248" sym9="2324" sym10="5252" sym11="5204" sym12="5512" sym13="0" sym14="0" sym15="0">
<nodes>
<n id="1" component_id="2" built_slot_index="0">
<node orientation="0" label="Data" mode="1" type="5" description="Input data, number channels 1..32 will be sent to the log acording to settings in properties." flags="0">
<position x="0" y="0" z="0"/>
</node>
</n>
<n id="2" component_id="6" built_slot_index="0">
<node orientation="0" label="Status Display" mode="0" type="6" description="2x2 screen displaying logger status." flags="0">
<position x="1" y="0" z="0"/>
</node>
</n>
<n id="3" component_id="11" built_slot_index="0">
<node orientation="0" label="Transmit" mode="1" type="0" description="Enables logging if connection is established." flags="0">
<position x="0" y="0" z="1"/>
</node>
</n>
<n id="4" component_id="14" built_slot_index="0">
<node orientation="0" label="Reconnect" mode="1" type="0" description="Will attempt to initiate connection on off to on transition." flags="0">
<position x="1" y="0" z="1"/>
</node>
</n>
</nodes>
<group id="0">
<pos x="0" y="0"/>
<data type="1936269312" name="" desc="">
<inputs/>
<outputs/>
</data>
<components>
<c type="56">
<object id="7" script='--[[
Input
Number channnel 1..32 - data to be logged
Boolean channel 1 - transmit data
Boolean channel 2 - reconnect 1 tick impulse will start reconnect sequence as long as controller is in CONNECTED_IDLE or NO_RESPONSE state
Number Property "Sampling frequency Hz" - sampling frequency, resulting sampling frequency might be higher if 60/frequency is not a natural number
Number Property "Data format" - number format 0-"%g" 1-"%.17g" 2-"%a" 3-Custom
Text Property "Custom format string" - printf like decription of value format must take at most one value and be valid format string
Text Property "chanel n name" - channel name that will be put in CSV header line, n in 1..32
Boolean Property "chanel n" - channel active if true/on channel is enabled, n in 1..32
Output
Video current status sized for 2x2 screen
]]--
State="INIT"
PORT=18080
headerSent=false
channelEnabled={}
channelName={}
lastResp=""
channelCount=0
busy=false
lineCount=0
formats={}
formats[0]="%g"
formats[1]="%.17g"
formats[2]="%a"
formats[3]=property.getText("Custom format string")
counter=0
function onTick()
if State=="CONNECTED_IDLE" and headerSent and input.getBool(1) then State="TRANSMIT" end
if State=="INIT" and not busy then
async.httpGet(PORT,"REQC")
busy=true
State="WAIT_FOR_CONNECTION"
for i=1,32 do
channelEnabled[i]=property.getBool(string.format("channel %d",i))
if (channelEnabled[i])then channelCount=channelCount+1 end
channelName[i]=(property.getText(string.format("channel %d name",i)) or "")
end
elseif State=="CONNECTED_IDLE" and not headerSent and not busy then
State="SENDING_HEADER"
msg="HEAD "..channelCount.."\n"
for i=1,32 do
if channelEnabled[i] then
msg=msg..channelName[i].."\n"
end
end
lastResp=msg.."\n---"
async.httpGet(PORT,msg)
busy=true
elseif State=="TRANSMIT" or State=="TRANSMIT_LAST" then
if not input.getBool(1) then State="TRANSMIT_LAST" end
counter=(counter+1)%(math.max(1,math.floor(60/(property.getNumber("Sampling frequency Hz")))))
if counter==0 then
msg=msg.."LINE "..channelCount.."\n"
for i=1,32 do
if channelEnabled[i] then
msg=msg..formats[property.getNumber("Data format")]:format(input.getNumber(i)).."\n"
end
end
lineCount=lineCount+1
lastResp=msg.."\n---"
if not busy then
msg="DATA "..lineCount.."\n"..msg
if State=="TRANSMIT_LAST" then msg=msg.."END\n" end
async.httpGet(PORT,msg)
lineCount=0
busy=true
msg=""
if State=="TRANSMIT_LAST" then State="CONNECTED_IDLE" end
end
end
end
if input.getBool(2) and (State=="NO_RESPONSE" or State=="CONNECTED_IDLE") then
State="INIT"
headerSent=false
busy=false
channelEnabled={}
channelName={}
channelCount=0
end
end
function onDraw()
if State=="NO_RESPONSE" then
statusMsg="No connection"
elseif State=="CONNECTED_IDLE" then
statusMsg="Connected"
elseif State=="TRANSMIT" then
statusMsg="Transmitting"
elseif State=="TRANSMIT_LAST" then
statusMsg="Finishing\ntransmission"
elseif State=="INIT" or State=="WAIT_FOR_CONNECTION" then
statusMsg="Connecting"
elseif State=="SENDING_HEADER" then
statusMsg="Sending header"
else statusMsg="Invalid state:\n"..Status
end
screen.drawTextBox(0,0,64,64,statusMsg,0,0)
end
function httpReply(port, request_body, response_body)
lastResp=request_body.."\n---\n"..response_body.."\n---"
if PORT~=port then return -1 end
busy=false
if request_body=="REQC" then
if response_body=="READY" then
State="CONNECTED_IDLE"
else
State="NO_RESPONSE"
end
elseif request_body:sub(1,4)=="HEAD" then
if response_body=="READY" then
headerSent=true
State="CONNECTED_IDLE"
else
State="NO_RESPONSE"
end
elseif request_body:sub(1,4)=="DATA" then
if response_body=="READY" then
else
State="NO_RESPONSE"
end
end
end'>
<pos x="2.75" y="0.75"/>
<in1 component_id="10" node_index="0">
<v bools="0" 01="263" 02="0" 03="0" 04="0" 05="0" 06="0" 07="0" 08="0" 09="0" 10="0" 11="0" 12="0" 13="0" 14="0" 15="0" 16="0" 17="0" 18="0" 19="0" 20="0" 21="0" 22="0" 23="0" 24="0" 25="0" 26="0" 27="0" 28="0" 29="0" 30="0" 31="0" 32="0"/>
</in1>
<in2 component_id="0" node_index="0">
<v/>
</in2>
<out1>
<v bools="0" 01="0" 02="0" 03="0" 04="0" 05="0" 06="0" 07="0" 08="0" 09="0" 10="0" 11="0" 12="0" 13="0" 14="0" 15="0" 16="0" 17="0" 18="0" 19="0" 20="0" 21="0" 22="0" 23="0" 24="0" 25="0" 26="0" 27="0" 28="0" 29="0" 30="0" 31="0" 32="0"/>
</out1>
<out2>
<v/>
</out2>
</object>
</c>
<c type="41">
<object id="10" count="2" offset="0">
<pos x="1.5" y="0.5"/>
<inc component_id="12" node_index="0">
<v bools="0" 01="264" 02="0" 03="0" 04="0" 05="0" 06="0" 07="0" 08="0" 09="0" 10="0" 11="0" 12="0" 13="0" 14="0" 15="0" 16="0" 17="0" 18="0" 19="0" 20="0" 21="0" 22="0" 23="0" 24="0" 25="0" 26="0" 27="0" 28="0" 29="0" 30="0" 31="0" 32="0"/>
</inc>
<in1 component_id="11" node_index="0" v="false"/>
<in2 component_id="15" node_index="0" v="false"/>
<out1>
<v bools="0" 01="264" 02="0" 03="0" 04="0" 05="0" 06="0" 07="0" 08="0" 09="0" 10="0" 11="0" 12="0" 13="0" 14="0" 15="0" 16="0" 17="0" 18="0" 19="0" 20="0" 21="0" 22="0" 23="0" 24="0" 25="0" 26="0" 27="0" 28="0" 29="0" 30="0" 31="0" 32="0"/>
</out1>
</object>
</c>
<c type="40">
<object id="12" count="1" offset="0">
<pos x="0.25" y="0.75"/>
<inc component_id="2" node_index="0">
<v bools="0" 01="0" 02="0" 03="0" 04="0" 05="0" 06="0" 07="0" 08="0" 09="0" 10="0" 11="0" 12="0" 13="0" 14="0" 15="0" 16="0" 17="0" 18="0" 19="0" 20="0" 21="0" 22="0" 23="0" 24="0" 25="0" 26="0" 27="0" 28="0" 29="0" 30="0" 31="0" 32="0"/>
</inc>
<in1 component_id="13" node_index="0" v="265"/>
<out1>
<v bools="0" 01="265" 02="0" 03="0" 04="0" 05="0" 06="0" 07="0" 08="0" 09="0" 10="0" 11="0" 12="0" 13="0" 14="0" 15="0" 16="0" 17="0" 18="0" 19="0" 20="0" 21="0" 22="0" 23="0" 24="0" 25="0" 26="0" 27="0" 28="0" 29="0" 30="0" 31="0" 32="0"/>
</out1>
</object>
</c>
<c type="45">
<object id="13" e="x+1">
<pos x="-1.5" y="0.5"/>
<in1 component_id="13" node_index="0" v="265"/>
<out1 v="266"/>
</object>
</c>
<c type="48">
<object id="15" m="1" p="false">
<pos x="0.25" y="-0.25"/>
<in1 component_id="14" node_index="0" v="false"/>
<out1 v="false"/>
</object>
</c>
<c type="20">
<object id="47" name="Data format" v="3" i="3">
<pos x="-5" y="2.5"/>
<out1 v="3"/>
<items>
<i l="Human readable short">
<v text="0" value="0"/>
</i>
<i l="Human readable long ">
<v text="1" value="1"/>
</i>
<i l="Hexadecimal double">
<v text="2" value="2"/>
</i>
<i l="Custom">
<v text="3" value="3"/>
</i>
</items>
</object>
</c>
<c type="34">
<object id="114" n="Sampling frequency Hz">
<pos x="-5" y="1.5"/>
<out1 v="60"/>
<v text="60" value="60"/>
</object>
</c>
<c type="58">
<object id="115" n="Custom format string" v="%.10g">
<pos x="-5" y="2"/>
</object>
</c>
<c type="33">
<object id="180" n="channel 1" on="Enabled" off="Disabled" v="true">
<pos x="-7.75" y="-0.25"/>
<out1 v="true"/>
</object>
</c>
<c type="58">
<object id="181" n="channel 1 name" v="Test Value">
<pos x="-7.75" y="0.25"/>
</object>
</c>
<c type="33">
<object id="182" n="channel 2" on="Enabled" off="Disabled" v="false">
<pos x="-7.75" y="-1.25"/>
<out1 v="false"/>
</object>
</c>
<c type="58">
<object id="183" n="channel 2 name" v="Test Value 2">
<pos x="-7.75" y="-0.75"/>
</object>
</c>
<c type="33">
<object id="184" n="channel 3" on="Enabled" off="Disabled" v="false">
<pos x="-7.75" y="-2.25"/>
<out1 v="false"/>
</object>
</c>
<c type="58">
<object id="185" n="channel 3 name" v="Test Value 3">
<pos x="-7.75" y="-1.75"/>
</object>
</c>
<c type="33">
<object id="186" n="channel 4" on="Enabled" off="Disabled" v="false">
<pos x="-7.75" y="-3.25"/>
<out1 v="false"/>
</object>
</c>
<c type="58">
<object id="187" n="channel 4 name" v="Test Value 4">
<pos x="-7.75" y="-2.75"/>
</object>
</c>
<c type="33">
<object id="188" n="channel 5" on="Enabled" off="Disabled" v="false">
<pos x="-7.75" y="-4.25"/>
<out1 v="false"/>
</object>
</c>
<c type="58">
<object id="189" n="channel 5 name" v="Test Value 5">
<pos x="-7.75" y="-3.75"/>
</object>
</c>
<c type="33">
<object id="190" n="channel 6" on="Enabled" off="Disabled" v="false">
<pos x="-7.75" y="-5.25"/>
<out1 v="false"/>
</object>
</c>
<c type="58">
<object id="191" n="channel 6 name" v="Test Value 6">
<pos x="-7.75" y="-4.75"/>
</object>
</c>
<c type="33">
<object id="192" n="channel 7" on="Enabled" off="Disabled" v="false">
<pos x="-7.75" y="-6.25"/>
<out1 v="false"/>
</object>
</c>
<c type="58">
<object id="193" n="channel 7 name" v="Test Value 7">
<pos x="-7.75" y="-5.75"/>
</object>
</c>
<c type="33">
<object id="194" n="channel 8" on="Enabled" off="Disabled" v="false">
<pos x="-7.75" y="-7.25"/>
<out1 v="false"/>
</object>
</c>
<c type="58">
<object id="195" n="channel 8 name" v="Test Value 8">
<pos x="-7.75" y="-6.75"/>
</object>
</c>
<c type="33">
<object id="196" n="channel 9" on="Enabled" off="Disabled" v="false">
<pos x="-6.5" y="-0.25"/>
<out1 v="false"/>
</object>
</c>
<c type="58">
<object id="197" n="channel 9 name" v="Test Value 9">
<pos x="-6.5" y="0.25"/>
</object>
</c>
<c type="33">
<object id="198" n="channel 10" on="Enabled" off="Disabled" v="false">
<pos x="-6.5" y="-1.25"/>
<out1 v="false"/>
</object>
</c>
<c type="58">
<object id="199" n="channel 10 name" v="Test Value 10">
<pos x="-6.5" y="-0.75"/>
</object>
</c>
<c type="33">
<object id="200" n="channel 11" on="Enabled" off="Disabled" v="false">
<pos x="-6.5" y="-2.25"/>
<out1 v="false"/>
</object>
</c>
<c type="58">
<object id="201" n="channel 11 name" v="Test Value 11">
<pos x="-6.5" y="-1.75"/>
</object>
</c>
<c type="33">
<object id="202" n="channel 12" on="Enabled" off="Disabled" v="false">
<pos x="-6.5" y="-3.25"/>
<out1 v="false"/>
</object>
</c>
<c type="58">
<object id="203" n="channel 12 name" v="Test Value 12">
<pos x="-6.5" y="-2.75"/>
</object>
</c>
<c type="33">
<object id="204" n="channel 13" on="Enabled" off="Disabled" v="false">
<pos x="-6.5" y="-4.25"/>
<out1 v="false"/>
</object>
</c>
<c type="58">
<object id="205" n="channel 13 name" v="Test Value 13">
<pos x="-6.5" y="-3.75"/>
</object>
</c>
<c type="33">
<object id="206" n="channel 14" on="Enabled" off="Disabled" v="false">
<pos x="-6.5" y="-5.25"/>
<out1 v="false"/>
</object>
</c>
<c type="58">
<object id="207" n="channel 14 name" v="Test Value 14">
<pos x="-6.5" y="-4.75"/>
</object>
</c>
<c type="33">
<object id="208" n="channel 15" on="Enabled" off="Disabled" v="false">
<pos x="-6.5" y="-6.25"/>
<out1 v="false"/>
</object>
</c>
<c type="58">
<object id="209" n="channel 15 name" v="Test Value 15">
<pos x="-6.5" y="-5.75"/>
</object>
</c>
<c type="33">
<object id="210" n="channel 16" on="Enabled" off="Disabled" v="false">
<pos x="-6.5" y="-7.25"/>
<out1 v="false"/>
</object>
</c>
<c type="58">
<object id="211" n="channel 16 name" v="Test Value 16">
<pos x="-6.5" y="-6.75"/>
</object>
</c>
<c type="33">
<object id="212" n="channel 17" on="Enabled" off="Disabled" v="false">
<pos x="-5.25" y="-0.25"/>
<out1 v="false"/>
</object>
</c>
<c type="58">
<object id="213" n="channel 17 name" v="Test Value 17">
<pos x="-5.25" y="0.25"/>
</object>
</c>
<c type="33">
<object id="214" n="channel 18" on="Enabled" off="Disabled" v="false">
<pos x="-5.25" y="-1.25"/>
<out1 v="false"/>
</object>
</c>
<c type="58">
<object id="215" n="channel 18 name" v="Test Value 18">
<pos x="-5.25" y="-0.75"/>
</object>
</c>
<c type="33">
<object id="216" n="channel 19" on="Enabled" off="Disabled" v="false">
<pos x="-5.25" y="-2.25"/>
<out1 v="false"/>
</object>
</c>
<c type="58">
<object id="217" n="channel 19 name" v="Test Value 19">
<pos x="-5.25" y="-1.75"/>
</object>
</c>
<c type="33">
<object id="218" n="channel 20" on="Enabled" off="Disabled" v="false">
<pos x="-5.25" y="-3.25"/>
<out1 v="false"/>
</object>
</c>
<c type="58">
<object id="219" n="channel 20 name" v="Test Value 20">
<pos x="-5.25" y="-2.75"/>
</object>
</c>
<c type="33">
<object id="220" n="channel 21" on="Enabled" off="Disabled" v="false">
<pos x="-5.25" y="-4.25"/>
<out1 v="false"/>
</object>
</c>
<c type="58">
<object id="221" n="channel 21 name" v="Test Value 21">
<pos x="-5.25" y="-3.75"/>
</object>
</c>
<c type="33">
<object id="222" n="channel 22" on="Enabled" off="Disabled" v="false">
<pos x="-5.25" y="-5.25"/>
<out1 v="false"/>
</object>
</c>
<c type="58">
<object id="223" n="channel 22 name" v="Test Value 22">
<pos x="-5.25" y="-4.75"/>
</object>
</c>
<c type="33">
<object id="224" n="channel 23" on="Enabled" off="Disabled" v="false">
<pos x="-5.25" y="-6.25"/>
<out1 v="false"/>
</object>
</c>
<c type="58">
<object id="225" n="channel 23 name" v="Test Value 23">
<pos x="-5.25" y="-5.75"/>
</object>
</c>
<c type="33">
<object id="226" n="channel 24" on="Enabled" off="Disabled" v="false">
<pos x="-5.25" y="-7.25"/>
<out1 v="false"/>
</object>
</c>
<c type="58">
<object id="227" n="channel 24 name" v="Test Value 24">
<pos x="-5.25" y="-6.75"/>
</object>
</c>
<c type="33">
<object id="228" n="channel 25" on="Enabled" off="Disabled" v="false">
<pos x="-4" y="-0.25"/>
<out1 v="false"/>
</object>
</c>
<c type="58">
<object id="229" n="channel 25 name" v="Test Value 25">
<pos x="-4" y="0.25"/>
</object>
</c>
<c type="33">
<object id="230" n="channel 26" on="Enabled" off="Disabled" v="false">
<pos x="-4" y="-1.25"/>
<out1 v="false"/>
</object>
</c>
<c type="58">
<object id="231" n="channel 26 name" v="Test Value 26">
<pos x="-4" y="-0.75"/>
</object>
</c>
<c type="33">
<object id="232" n="channel 27" on="Enabled" off="Disabled" v="false">
<pos x="-4" y="-2.25"/>
<out1 v="false"/>
</object>
</c>
<c type="58">
<object id="233" n="channel 27 name" v="Test Value 27">
<pos x="-4" y="-1.75"/>
</object>
</c>
<c type="33">
<object id="234" n="channel 28" on="Enabled" off="Disabled" v="false">
<pos x="-4" y="-3.25"/>
<out1 v="false"/>
</object>
</c>
<c type="58">
<object id="235" n="channel 28 name" v="Test Value 28">
<pos x="-4" y="-2.75"/>
</object>
</c>
<c type="33">
<object id="236" n="channel 29" on="Enabled" off="Disabled" v="false">
<pos x="-4" y="-4.25"/>
<out1 v="false"/>
</object>
</c>
<c type="58">
<object id="237" n="channel 29 name" v="Test Value 29">
<pos x="-4" y="-3.75"/>
</object>
</c>
<c type="33">
<object id="238" n="channel 30" on="Enabled" off="Disabled" v="false">
<pos x="-4" y="-5.25"/>
<out1 v="false"/>
</object>
</c>
<c type="58">
<object id="239" n="channel 30 name" v="Test Value 30">
<pos x="-4" y="-4.75"/>
</object>
</c>
<c type="33">
<object id="240" n="channel 31" on="Enabled" off="Disabled" v="false">
<pos x="-4" y="-6.25"/>
<out1 v="false"/>
</object>
</c>
<c type="58">
<object id="241" n="channel 31 name" v="Test Value 31">
<pos x="-4" y="-5.75"/>
</object>
</c>
<c type="33">
<object id="242" n="channel 32" on="Enabled" off="Disabled" v="false">
<pos x="-4" y="-7.25"/>
<out1 v="false"/>
</object>
</c>
<c type="58">
<object id="243" n="channel 32 name" v="Test Value 32">
<pos x="-4" y="-6.75"/>
</object>
</c>
</components>
<components_bridge>
<c type="4">
<object id="2">
<pos x="-1.5" y="1"/>
<in1 component_id="0" node_index="0">
<v bools="0" 01="0" 02="0" 03="0" 04="0" 05="0" 06="0" 07="0" 08="0" 09="0" 10="0" 11="0" 12="0" 13="0" 14="0" 15="0" 16="0" 17="0" 18="0" 19="0" 20="0" 21="0" 22="0" 23="0" 24="0" 25="0" 26="0" 27="0" 28="0" 29="0" 30="0" 31="0" 32="0"/>
</in1>
<out1>
<v bools="0" 01="0" 02="0" 03="0" 04="0" 05="0" 06="0" 07="0" 08="0" 09="0" 10="0" 11="0" 12="0" 13="0" 14="0" 15="0" 16="0" 17="0" 18="0" 19="0" 20="0" 21="0" 22="0" 23="0" 24="0" 25="0" 26="0" 27="0" 28="0" 29="0" 30="0" 31="0" 32="0"/>
</out1>
</object>
</c>
<c type="7">
<object id="6">
<pos x="4" y="0.75"/>
<in1 component_id="7" node_index="1">
<v/>
</in1>
<out1>
<v/>
</out1>
</object>
</c>
<c type="0">
<object id="11">
<pos x="0.25" y="0.25"/>
<in1 component_id="0" node_index="0" v="false"/>
<out1 v="false"/>
</object>
</c>
<c type="0">
<object id="14">
<pos x="-1" y="-0.25"/>
<in1 component_id="0" node_index="0" v="false"/>
<out1 v="false"/>
</object>
</c>
</components_bridge>
<groups/>
<component_states>
<c0 id="7" script='--[[
Input
Number channnel 1..32 - data to be logged
Boolean channel 1 - transmit data
Boolean channel 2 - reconnect 1 tick impulse will start reconnect sequence as long as controller is in CONNECTED_IDLE or NO_RESPONSE state
Number Property "Sampling frequency Hz" - sampling frequency, resulting sampling frequency might be higher if 60/frequency is not a natural number
Number Property "Data format" - number format 0-"%g" 1-"%.17g" 2-"%a" 3-Custom
Text Property "Custom format string" - printf like decription of value format must take at most one value and be valid format string
Text Property "chanel n name" - channel name that will be put in CSV header line, n in 1..32
Boolean Property "chanel n" - channel active if true/on channel is enabled, n in 1..32
Output
Video current status sized for 2x2 screen
]]--
State="INIT"
PORT=18080
headerSent=false
channelEnabled={}
channelName={}
lastResp=""
channelCount=0
busy=false
lineCount=0
formats={}
formats[0]="%g"
formats[1]="%.17g"
formats[2]="%a"
formats[3]=property.getText("Custom format string")
counter=0
function onTick()
if State=="CONNECTED_IDLE" and headerSent and input.getBool(1) then State="TRANSMIT" end
if State=="INIT" and not busy then
async.httpGet(PORT,"REQC")
busy=true
State="WAIT_FOR_CONNECTION"
for i=1,32 do
channelEnabled[i]=property.getBool(string.format("channel %d",i))
if (channelEnabled[i])then channelCount=channelCount+1 end
channelName[i]=(property.getText(string.format("channel %d name",i)) or "")
end
elseif State=="CONNECTED_IDLE" and not headerSent and not busy then
State="SENDING_HEADER"
msg="HEAD "..channelCount.."\n"
for i=1,32 do
if channelEnabled[i] then
msg=msg..channelName[i].."\n"
end
end
lastResp=msg.."\n---"
async.httpGet(PORT,msg)
busy=true
elseif State=="TRANSMIT" or State=="TRANSMIT_LAST" then
if not input.getBool(1) then State="TRANSMIT_LAST" end
counter=(counter+1)%(math.max(1,math.floor(60/(property.getNumber("Sampling frequency Hz")))))
if counter==0 then
msg=msg.."LINE "..channelCount.."\n"
for i=1,32 do
if channelEnabled[i] then
msg=msg..formats[property.getNumber("Data format")]:format(input.getNumber(i)).."\n"
end
end
lineCount=lineCount+1
lastResp=msg.."\n---"
if not busy then
msg="DATA "..lineCount.."\n"..msg
if State=="TRANSMIT_LAST" then msg=msg.."END\n" end
async.httpGet(PORT,msg)
lineCount=0
busy=true
msg=""
if State=="TRANSMIT_LAST" then State="CONNECTED_IDLE" end
end
end
end
if input.getBool(2) and (State=="NO_RESPONSE" or State=="CONNECTED_IDLE") then
State="INIT"
headerSent=false
busy=false
channelEnabled={}
channelName={}
channelCount=0
end
end
function onDraw()
if State=="NO_RESPONSE" then
statusMsg="No connection"
elseif State=="CONNECTED_IDLE" then
statusMsg="Connected"
elseif State=="TRANSMIT" then
statusMsg="Transmitting"
elseif State=="TRANSMIT_LAST" then
statusMsg="Finishing\ntransmission"
elseif State=="INIT" or State=="WAIT_FOR_CONNECTION" then
statusMsg="Connecting"
elseif State=="SENDING_HEADER" then
statusMsg="Sending header"
else statusMsg="Invalid state:\n"..Status
end
screen.drawTextBox(0,0,64,64,statusMsg,0,0)
end
function httpReply(port, request_body, response_body)
lastResp=request_body.."\n---\n"..response_body.."\n---"
if PORT~=port then return -1 end
busy=false
if request_body=="REQC" then
if response_body=="READY" then
State="CONNECTED_IDLE"
else
State="NO_RESPONSE"
end
elseif request_body:sub(1,4)=="HEAD" then
if response_body=="READY" then
headerSent=true
State="CONNECTED_IDLE"
else
State="NO_RESPONSE"
end
elseif request_body:sub(1,4)=="DATA" then
if response_body=="READY" then
else
State="NO_RESPONSE"
end
end
end'>
<pos x="2.75" y="0.75"/>
<in1 component_id="10" node_index="0">
<v bools="0" 01="263" 02="0" 03="0" 04="0" 05="0" 06="0" 07="0" 08="0" 09="0" 10="0" 11="0" 12="0" 13="0" 14="0" 15="0" 16="0" 17="0" 18="0" 19="0" 20="0" 21="0" 22="0" 23="0" 24="0" 25="0" 26="0" 27="0" 28="0" 29="0" 30="0" 31="0" 32="0"/>
</in1>
<in2 component_id="0" node_index="0">
<v/>
</in2>
<out1>
<v bools="0" 01="0" 02="0" 03="0" 04="0" 05="0" 06="0" 07="0" 08="0" 09="0" 10="0" 11="0" 12="0" 13="0" 14="0" 15="0" 16="0" 17="0" 18="0" 19="0" 20="0" 21="0" 22="0" 23="0" 24="0" 25="0" 26="0" 27="0" 28="0" 29="0" 30="0" 31="0" 32="0"/>
</out1>
<out2>
<v/>
</out2>
</c0>
<c1 id="10" count="2" offset="0">
<pos x="1.5" y="0.5"/>
<inc component_id="12" node_index="0">
<v bools="0" 01="264" 02="0" 03="0" 04="0" 05="0" 06="0" 07="0" 08="0" 09="0" 10="0" 11="0" 12="0" 13="0" 14="0" 15="0" 16="0" 17="0" 18="0" 19="0" 20="0" 21="0" 22="0" 23="0" 24="0" 25="0" 26="0" 27="0" 28="0" 29="0" 30="0" 31="0" 32="0"/>
</inc>
<in1 component_id="11" node_index="0" v="false"/>
<in2 component_id="15" node_index="0" v="false"/>
<out1>
<v bools="0" 01="264" 02="0" 03="0" 04="0" 05="0" 06="0" 07="0" 08="0" 09="0" 10="0" 11="0" 12="0" 13="0" 14="0" 15="0" 16="0" 17="0" 18="0" 19="0" 20="0" 21="0" 22="0" 23="0" 24="0" 25="0" 26="0" 27="0" 28="0" 29="0" 30="0" 31="0" 32="0"/>
</out1>
</c1>
<c2 id="12" count="1" offset="0">
<pos x="0.25" y="0.75"/>
<inc component_id="2" node_index="0">
<v bools="0" 01="0" 02="0" 03="0" 04="0" 05="0" 06="0" 07="0" 08="0" 09="0" 10="0" 11="0" 12="0" 13="0" 14="0" 15="0" 16="0" 17="0" 18="0" 19="0" 20="0" 21="0" 22="0" 23="0" 24="0" 25="0" 26="0" 27="0" 28="0" 29="0" 30="0" 31="0" 32="0"/>
</inc>
<in1 component_id="13" node_index="0" v="265"/>
<out1>
<v bools="0" 01="265" 02="0" 03="0" 04="0" 05="0" 06="0" 07="0" 08="0" 09="0" 10="0" 11="0" 12="0" 13="0" 14="0" 15="0" 16="0" 17="0" 18="0" 19="0" 20="0" 21="0" 22="0" 23="0" 24="0" 25="0" 26="0" 27="0" 28="0" 29="0" 30="0" 31="0" 32="0"/>
</out1>
</c2>
<c3 id="13" e="x+1">
<pos x="-1.5" y="0.5"/>
<in1 component_id="13" node_index="0" v="265"/>
<out1 v="266"/>
</c3>
<c4 id="15" m="1" p="false">
<pos x="0.25" y="-0.25"/>
<in1 component_id="14" node_index="0" v="false"/>
<out1 v="false"/>
</c4>
<c5 id="47" name="Data format" v="3" i="3">
<pos x="-5" y="2.5"/>
<out1 v="3"/>
<items>
<i l="Human readable short">
<v text="0" value="0"/>
</i>
<i l="Human readable long ">
<v text="1" value="1"/>
</i>
<i l="Hexadecimal double">
<v text="2" value="2"/>
</i>
<i l="Custom">
<v text="3" value="3"/>
</i>
</items>
</c5>
<c6 id="114" n="Sampling frequency Hz">
<pos x="-5" y="1.5"/>
<out1 v="60"/>
<v text="60" value="60"/>
</c6>
<c7 id="115" n="Custom format string" v="%.10g">
<pos x="-5" y="2"/>
</c7>
<c8 id="180" n="channel 1" on="Enabled" off="Disabled" v="true">
<pos x="-7.75" y="-0.25"/>
<out1 v="true"/>
</c8>
<c9 id="181" n="channel 1 name" v="Test Value">
<pos x="-7.75" y="0.25"/>
</c9>
<c10 id="182" n="channel 2" on="Enabled" off="Disabled" v="false">
<pos x="-7.75" y="-1.25"/>
<out1 v="false"/>
</c10>
<c11 id="183" n="channel 2 name" v="Test Value 2">
<pos x="-7.75" y="-0.75"/>
</c11>
<c12 id="184" n="channel 3" on="Enabled" off="Disabled" v="false">
<pos x="-7.75" y="-2.25"/>
<out1 v="false"/>
</c12>
<c13 id="185" n="channel 3 name" v="Test Value 3">
<pos x="-7.75" y="-1.75"/>
</c13>
<c14 id="186" n="channel 4" on="Enabled" off="Disabled" v="false">
<pos x="-7.75" y="-3.25"/>
<out1 v="false"/>
</c14>
<c15 id="187" n="channel 4 name" v="Test Value 4">
<pos x="-7.75" y="-2.75"/>
</c15>
<c16 id="188" n="channel 5" on="Enabled" off="Disabled" v="false">
<pos x="-7.75" y="-4.25"/>
<out1 v="false"/>
</c16>
<c17 id="189" n="channel 5 name" v="Test Value 5">
<pos x="-7.75" y="-3.75"/>
</c17>
<c18 id="190" n="channel 6" on="Enabled" off="Disabled" v="false">
<pos x="-7.75" y="-5.25"/>
<out1 v="false"/>
</c18>
<c19 id="191" n="channel 6 name" v="Test Value 6">
<pos x="-7.75" y="-4.75"/>
</c19>
<c20 id="192" n="channel 7" on="Enabled" off="Disabled" v="false">
<pos x="-7.75" y="-6.25"/>
<out1 v="false"/>
</c20>
<c21 id="193" n="channel 7 name" v="Test Value 7">
<pos x="-7.75" y="-5.75"/>
</c21>
<c22 id="194" n="channel 8" on="Enabled" off="Disabled" v="false">
<pos x="-7.75" y="-7.25"/>
<out1 v="false"/>
</c22>
<c23 id="195" n="channel 8 name" v="Test Value 8">
<pos x="-7.75" y="-6.75"/>
</c23>
<c24 id="196" n="channel 9" on="Enabled" off="Disabled" v="false">
<pos x="-6.5" y="-0.25"/>
<out1 v="false"/>
</c24>
<c25 id="197" n="channel 9 name" v="Test Value 9">
<pos x="-6.5" y="0.25"/>
</c25>
<c26 id="198" n="channel 10" on="Enabled" off="Disabled" v="false">
<pos x="-6.5" y="-1.25"/>
<out1 v="false"/>
</c26>
<c27 id="199" n="channel 10 name" v="Test Value 10">
<pos x="-6.5" y="-0.75"/>
</c27>
<c28 id="200" n="channel 11" on="Enabled" off="Disabled" v="false">
<pos x="-6.5" y="-2.25"/>
<out1 v="false"/>
</c28>
<c29 id="201" n="channel 11 name" v="Test Value 11">
<pos x="-6.5" y="-1.75"/>
</c29>
<c30 id="202" n="channel 12" on="Enabled" off="Disabled" v="false">
<pos x="-6.5" y="-3.25"/>
<out1 v="false"/>
</c30>
<c31 id="203" n="channel 12 name" v="Test Value 12">
<pos x="-6.5" y="-2.75"/>
</c31>
<c32 id="204" n="channel 13" on="Enabled" off="Disabled" v="false">
<pos x="-6.5" y="-4.25"/>
<out1 v="false"/>
</c32>
<c33 id="205" n="channel 13 name" v="Test Value 13">
<pos x="-6.5" y="-3.75"/>
</c33>
<c34 id="206" n="channel 14" on="Enabled" off="Disabled" v="false">
<pos x="-6.5" y="-5.25"/>
<out1 v="false"/>
</c34>
<c35 id="207" n="channel 14 name" v="Test Value 14">
<pos x="-6.5" y="-4.75"/>
</c35>
<c36 id="208" n="channel 15" on="Enabled" off="Disabled" v="false">
<pos x="-6.5" y="-6.25"/>
<out1 v="false"/>
</c36>
<c37 id="209" n="channel 15 name" v="Test Value 15">
<pos x="-6.5" y="-5.75"/>
</c37>
<c38 id="210" n="channel 16" on="Enabled" off="Disabled" v="false">
<pos x="-6.5" y="-7.25"/>
<out1 v="false"/>
</c38>
<c39 id="211" n="channel 16 name" v="Test Value 16">
<pos x="-6.5" y="-6.75"/>
</c39>
<c40 id="212" n="channel 17" on="Enabled" off="Disabled" v="false">
<pos x="-5.25" y="-0.25"/>
<out1 v="false"/>
</c40>
<c41 id="213" n="channel 17 name" v="Test Value 17">
<pos x="-5.25" y="0.25"/>
</c41>
<c42 id="214" n="channel 18" on="Enabled" off="Disabled" v="false">
<pos x="-5.25" y="-1.25"/>
<out1 v="false"/>
</c42>
<c43 id="215" n="channel 18 name" v="Test Value 18">
<pos x="-5.25" y="-0.75"/>
</c43>
<c44 id="216" n="channel 19" on="Enabled" off="Disabled" v="false">
<pos x="-5.25" y="-2.25"/>
<out1 v="false"/>
</c44>
<c45 id="217" n="channel 19 name" v="Test Value 19">
<pos x="-5.25" y="-1.75"/>
</c45>
<c46 id="218" n="channel 20" on="Enabled" off="Disabled" v="false">
<pos x="-5.25" y="-3.25"/>
<out1 v="false"/>
</c46>
<c47 id="219" n="channel 20 name" v="Test Value 20">
<pos x="-5.25" y="-2.75"/>
</c47>
<c48 id="220" n="channel 21" on="Enabled" off="Disabled" v="false">
<pos x="-5.25" y="-4.25"/>
<out1 v="false"/>
</c48>
<c49 id="221" n="channel 21 name" v="Test Value 21">
<pos x="-5.25" y="-3.75"/>
</c49>
<c50 id="222" n="channel 22" on="Enabled" off="Disabled" v="false">
<pos x="-5.25" y="-5.25"/>
<out1 v="false"/>
</c50>
<c51 id="223" n="channel 22 name" v="Test Value 22">
<pos x="-5.25" y="-4.75"/>
</c51>
<c52 id="224" n="channel 23" on="Enabled" off="Disabled" v="false">
<pos x="-5.25" y="-6.25"/>
<out1 v="false"/>
</c52>
<c53 id="225" n="channel 23 name" v="Test Value 23">
<pos x="-5.25" y="-5.75"/>
</c53>
<c54 id="226" n="channel 24" on="Enabled" off="Disabled" v="false">
<pos x="-5.25" y="-7.25"/>
<out1 v="false"/>
</c54>
<c55 id="227" n="channel 24 name" v="Test Value 24">