-
Notifications
You must be signed in to change notification settings - Fork 0
/
PlayLog.lua
859 lines (795 loc) · 28.9 KB
/
PlayLog.lua
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
--[[
Jeti Log File Player
Warning
The application is designed to replay log files on the Jeti emulator to test new lua application against previous
recorded log files. The player is a development tool.
The application should never be used on a real device to to avoid any unpredictable behavior of a remote controlled device.
Description
The application is a development tool to test lua applications with previous recorded log file data.
A free selectable switch can control the player. The control switch is always taken from the emulator.
The player has four states:
- initialiesed
- reset/stopped
- playing
- finished
User feedback is given in the emulator debug window.
Usage
1. Install the player application parallel to the to-test-application
2. Select a log file from the "Log" folder
3. Select a switch to "start" or "reset" the log file player
4. The test application can retrieve values form the log file through the system calls:
- system.getSensors ()
- system.getSensorByID (sensor ID, sensor param)
- system.getSensorValueByID (sensor ID, sensor param)
- system.getInputs (Input1,...)
- system.getInputsVal (Input1,...)
- system.getTxTelemetry ()
Licence:
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program. If not, see <https://www.gnu.org/licenses/>.
]]
-- Todos / open topics / function limits
-- Requiers JETI SW Version 4.28 or higer
-- after first start or file change: type and decimal might not initialisied so time, date, gps are wrong
-- system.getTxTelemetry () : supports only receiver 1
-- ??? system.getSensors no check if log file and emulator provide the same sensors
-- only the first error message per block is stored
--
-- see '??? mark1'ware is provided as it is without any laibility or any warranty
-- the direct tx control values have a reduced resolution
-- system.getInputsVal: works only limited because getSwitchInfo properties are not complete
-- and the switchItem configuration is not part of the log file
--
--[[
version 0.44 initial release
0.45
- decimal correction for return values
- TX log parameter values labes must equal the switch or switchItem label
- TX log parameter <50 treated special: expect 0 to 100% output will be -1 to 1
- system.getInputsVal added, but limited function due to system.getSwitchInfo limits
0.46
- control switch is always taken from the emulator
0.47
- sensor.label staus "valid" is now treated like the other values
- the log file can now contain comment lines after the first logtime >0 line
- a comment line has to start with non number character
- display name changed
- init simplified
0.48
- valid return corrected: preset valid=false deleted
0.49
- added playTime, errorParse and state as variable
- added Telemetry Window to show basic info: file, model, state and playtime
- clean up and code sorted
- prepared for global data structure: globLogFilePlay
0.52
- check errorParse to avoid "nil" print
- sensor.valid handling changed
- system.getSensors returns now a sorted table to be more like jeti
- sensorName is now reintoduced
- default control button is now SA
0.53
- system.getTxTelemetry.RSSI converter
]]
-- limited good idea to make variables global,
-- an alternative would be to overwrite the FILE functions with <some> managemet overhead
--[[
globLogFilePlay={}
globLogFilePlay.file="" -- log file name string 12 Bytes
globLogFilePlay.model="" -- detected model name 10 Bytes
globLogFilePlay.status="" -- LP status init,play,stop,fini 4Bytes
globLogFilePlay.playT=0 -- current play time in ms
globLogFilePlay.error=false -- log file parsing status boolean, more details are provide in the debug window
--
]]
----
local appName="Log File Player"
local logPath="Log/"
local logFile="default.log"
local system_getTxTelemetry=system.getTxTelemetry
local system_getInputs=system.getInputs
local system_getInputsVal=system.getInputsVal
local system_getSensors=system.getSensors
local system_getSensorByID=system.getSensorByID
local system_getSensorValueByID=system.getSensorValueByID
local swReset -- switchItem to start or reset logPlayer
local state -- log file player status
local lpReset
local lpRun
local lpEnd
local lpNewFile -- newFile selected
local model -- log file read values
local sensors -- sensors[sid][sparam]{["label"],["unit"],["logTime"],["type"],["decimals"],["value"],["min"],["max"]}
local newSensors -- definition from the previous run
local logTime -- time of the line
local sid -- sensor ID
local sparam -- Sensor Value ID
local slabel -- Sensor Name
local sunit -- Senseor Unit
local logStartTime -- log file time offset
local systemStartTime -- system time offset
local playTime -- systemTime-systemStartTime
local tx -- lookup table for input values
local rx -- sensor id for txTel
local errorList -- [...]{etime, etype, evalue}
local errorParse
local file -- log file pointer
local line -- log file line
local sPos -- sub-string start position
local ePos -- sub-string end position
local rssiConvert = {1, 3, 6, 9, 12, 16, 20, 25, 31, 45}
--------------------------------------------------------------------
-- print status and error message
--------------------------------------------------------------------
local function printStatus(status)
-- return -- don't want any prints on the debug window enable return
if errorParse then
for entry, eList in pairs(errorList) do
print("Error- "..entry..": "..errorList[entry].etime.." - "..errorList[entry].etype.." . "..errorList[entry].evalue)
end
end
print(status)
end
--------------------------------------------------------------------
-- helper function
local function getDivisor(i,p)
local divisor=1.0
if not pcall(function()
local d=0
while d< sensors[i][p]["decimals"] do
divisor=divisor*10.0
d=d+1
end
end) then
divisor=1.0
end
return divisor
end
--------------------------------------------------------------------
-- telemetrie wreper function
--------------------------------------------------------------------
-- system.getTxTelemetry ()
-- supports only receiver 1
--------------------------------------------------------------------
system.getTxTelemetry=function(...)
local txTel=system_getTxTelemetry()
if rx then
if not pcall(function()
if rx["RxId"] then
for param in pairs(sensors[rx["RxId"]]) do
if sensors[rx["RxId"]][param]["label"] == "U Rx" then
txTel.rx1Voltage=sensors[rx["RxId"]][param]["value"]/getDivisor(rx["RxId"],param)
elseif sensors[rx["RxId"]][param]["label"] == "Q" then
txTel.rx1Percent=sensors[rx["RxId"]][param]["value"]/getDivisor(rx["RxId"],param)
elseif sensors[rx["RxId"]][param]["label"] == "A1" then
local p = (sensors[rx["RxId"]][param]["value"]/getDivisor(rx["RxId"],param))
p = math.max(0,math.min(p,9)) +1
txTel.RSSI[1]= rssiConvert[p]
elseif sensors[rx["RxId"]][param]["label"] == "A2" then
local p = (sensors[rx["RxId"]][param]["value"]/getDivisor(rx["RxId"],param))
p = math.max(0,math.min(p,9)) +1
txTel.RSSI[2]= rssiConvert[p]
end
end
end
end) then
if errorList["getTxTelemetry"]==nil then
errorList["getTxTelemetry"]={}
errorList["getTxTelemetry"]["etime"]=logTime
errorList["getTxTelemetry"]["etype"]="getTxTelemetry"
errorList["getTxTelemetry"]["evalue"]="unkown value"
errorParse=true
end
end
end
return txTel
end
--------------------------------------------------------------------
-- system.getInputs
--------------------------------------------------------------------
system.getInputs=function(...)
local r={}
local arg = {...}
r[1],r[2],r[3],r[4],r[5],r[6],r[7],r[8]=system_getInputs(...)
if tx then
if not pcall(function()
for i,input in pairs(arg) do -- replace original with log file data
if tx[input] then
if tx[input] >50 then -- handel value as "normal" sensor value
r[i]=sensors[tx["TxId"]][tx[input]]["value"]/getDivisor(tx["TxId"],tx[input])
else
r[i]=(sensors[tx["TxId"]][tx[input]]["value"] -50)/50 -- log is 0-100 system -1 to 0 to 1
end
end
end
end ) then
if errorList["getInputs"]==nil then
errorList["getInputs"]={}
errorList["getInputs"]["etime"]=logTime
errorList["getInputs"]["etype"]="getInputs"
errorList["getInputs"]["evalue"]="unkown value"
errorParse=true
end
end
end
return r[1],r[2],r[3],r[4],r[5],r[6],r[7],r[8]
end
--------------------------------------------------------------------
-- system.getInputsVal
--------------------------------------------------------------------
system.getInputsVal=function(...)
local r={}
local arg = {...}
r[1],r[2],r[3],r[4],r[5],r[6],r[7],r[8]=system_getInputsVal(...)
if tx then
if not pcall(function()
for i,input in pairs(arg) do -- replace original with log file data
local swItemTab=system.getSwitchInfo(input)
if tx[swItemTab.label] then
if tx[swItemTab.label] >50 then -- handel value as "normal" sensor value
r[i]=sensors[tx["TxId"]][tx[swItemTab.label]]["value"]/getDivisor(tx["TxId"],tx[swItemTab.label])
else
r[i]=(sensors[tx["TxId"]][tx[swItemTab.label]]["value"] -50)/50 -- log is 0-100 system -1 to 0 to 1
end
-- later convert value to the requeste properties from swItemTab=getSwitchInfo(input) :center, proportional, reverse
-- assuming the UNIT feld in the log file will contain the logded configuration default: log is always proportional
-- default could look somthing like that or check if something else is definfed in the "UNIT"
-- if not swItemTab.proportional then
-- if r[i] > 0.7 then r[i] =1
-- elseif r[i] < -0.7 then r[i] =-1
-- else r[i]=0
-- else
-- if not swItemTab.center then r[i]=(r[i]+1)/2 end
-- end
-- if swItemTab.reverse then r[i]=-1*r[i] end
end
end
end ) then
if errorList["getInputsVal"]==nil then
errorList["getInputsVal"]={}
errorList["getInputsVal"]["etime"]=logTime
errorList["getInputsVal"]["etype"]="getInputsVal"
errorList["getInputsVal"]["evalue"]="unkown value"
errorParse=true
end
end
end
return r[1],r[2],r[3],r[4],r[5],r[6],r[7],r[8]
end
--------------------------------------------------------------------
-- system.getSensors ()
-- system.getSensorByID (<sensor ID>, <sensor param>)
-- system.getSensorValueByID (<sensor ID>, <sensor param>)
--------------------------------------------------------------------
local function doParameter(fullData,id,param)
local s={}
if id==nil or param==nil then -- definition incomplete
return s
end
if sensors==nil or sensors[id]==nil or sensors[id][param]==nil then
return system_getSensorValueByID(id,param) -- sensor request is not part of the logfile
end
if fullData then
s["id"]=id -- sensors unique identifier
s["param"]=param -- parameter identifier
if param~=0 then
s["sensorName"]= sensors[id][0]["label"]
else
s["sensorName"]= ""
end
end
local svalue
for key,value in pairs(sensors[id][param]) do
if key=="value" then
svalue=value -- handle value later according spec
elseif key=="logTime" then
if (sensors[id][param]["logTime"]-logStartTime)+4000 >= system.getTimeCounter()-systemStartTime then
s["valid"]=true
else
s["valid"]=false
end
elseif fullData then
s[key]=value -- fill in all sensor values
elseif not fullData and (key=="min" or key=="max" or key=="type") then
s[key]=value -- fill in only selected sensor values
end
end
-- handle value
if svalue then
if (sensors[id][param]["logTime"]-logStartTime)+4000 >= system.getTimeCounter()-systemStartTime then
s["valid"]=true
else
s["valid"]=false
end
if s["type"]==5 then
if sensors[id][param]["decimals"]==0 then -- time
s["valSec"]=sensors[id][param]["value"]&0xFF
s["valMin"]=(sensors[id][param]["value"]>>8)&0xFF
s["valHour"]=(sensors[id][param]["value"]>>16)&0x1F
else -- date
s["valDay"]=(sensors[id][param]["value"]&0xFF)
s["valMonth"]=((sensors[id][param]["value"]>>8)&0xFF)
s["valYear"]=((sensors[id][param]["value"]>>16)&0x1F)+2000
end
elseif s["type"]==9 then -- gps
s["valGPS"]= sensors[id][param]["value"]
else
local divisor=getDivisor(id,param)
s["value"]=sensors[id][param]["value"] /divisor -- float
if sensors[id][param]["min"] then
s["min"]=sensors[id][param]["min"] /divisor
else
s["min"]=0.0
end
if sensors[id][param]["max"] then
s["max"]=sensors[id][param]["max"] /divisor
else
s["max"]=0.0
end
end
else
s["value"]=0.0
s["min"]=0.0
s["max"]=0.0
end
return s
end
--------------------------------------------------------------------
-- getSensors()
--------------------------------------------------------------------
system.getSensors=function(...)
-- value, min, max, valid, type
-- id, param, label, unit, decimals, sensorname
local sa={} -- sensor Array
local index=0; -- sensor index
sa=system_getSensors()
-- ??? check here if sensor Id is present in emulator and log file
for i in ipairs(sa) do -- find sensors end
if i>index then
index=i
end
end
if sensors then -- anything read from the log file
for id,sensor in pairs(sensors) do
if not (sensor[0]["label"]:sub(1,2)=="Tx" or sensor[0]["label"]:sub(1,2)=="Rx") then
local sl={}
for n,param in pairs(sensor) do table.insert(sl,n) end
table.sort(sl)
for i,sp in ipairs(sl) do
index=index+1
if sa[index]==nil then
sa[index]={}
end
sa[index]=doParameter(true,id,sp) -- add sensor subset to array
end
end
end
end
return sa
end
--------------------------------------------------------------------
-- getSensorByID (id,param)
--------------------------------------------------------------------
system.getSensorByID=function(...)
-- value, min, max, valid, type
-- id, param, label, unit, decimals, sensorName
local arg = {...}
local id
local param
for i,v in ipairs(arg) do
if i==1 then id=v end
if i==2 then param=tonumber(v) end
end
return doParameter(true,id,param)
end
--------------------------------------------------------------------
-- getSensorValueByID (id,param)
--------------------------------------------------------------------
system.getSensorValueByID=function(...)
-- value, min, max, valid, type
local arg = {...}
local id
local param
for i,v in ipairs(arg) do
if i==1 then id=v end
if i==2 then param=tonumber(v) end
end
return doParameter(false,id,param)
end
--------------------------------------------------------------------
-- log Player
--------------------------------------------------------------------
local function logPlayer()
local function findPos() -- find next data in line
sPos=ePos+1
ePos = line:find(";",sPos)
if ePos==nil then
ePos=0
end
local result =line:sub(sPos,ePos-1)
if result then
return result
else
return ""
end
end
if lpReset then -- read log from scretch
errorList={} -- reset error list
errorParse=false
if file then -- handle file init
io.close(file)
end
file = io.open(logPath..logFile,"r")
if file==nil then
if errorList["playerInit"]==nil then
errorList["playerInit"]={}
errorList["playerInit"]["etime"]=0
errorList["playerInit"]["etype"]="File error"
errorList["playerInit"]["evalue"]=logPath..logFile
errorParse=true
end
return
end
newSensors={} -- reset sensor table
tx={}
rx={}
logStartTime=0 -- reset time values
logTime=0
playTime=0
repeat -- register sensors
line = io.readline(file)
if line==nil then -- error?
io.close(file)
file=nil
if errorList["playerInit"]==nil then
errorList["playerInit"]={}
errorList["playerInit"]["etime"]=0
errorList["playerInit"]["etype"]="File no data"
errorList["playerInit"]["evalue"]=logPath..logFile
errorParse=true
end
return -- eof and now?
end
if 1==line:find("#") then -- model name
model=line:sub(3)
if model~=nil then
printStatus("LP: "..model)
end
else
ePos=0 -- new line
logTime=tonumber(findPos())
if logTime==nil then
logTime=0
io.close(file)
file=nil
if errorList["playerInit"]==nil then
errorList["playerInit"]={}
errorList["playerInit"]["etime"]=0
errorList["playerInit"]["etype"]="File no logtime"
errorList["playerInit"]["evalue"]=logPath..logFile
errorParse=true
end
return -- eof and now?
end
sid=(findPos())
if logTime==0 then -- sensor def
sparam=tonumber(findPos())
slabel=findPos()
sunit=findPos()
--print ("ID:"..sid..", "..sparam.." Label:"..slabel.." Unit:"..sunit)
if newSensors[sid]==nil then
newSensors[sid]={} --create sensor array
end
if newSensors[sid][sparam]==nil then
newSensors[sid][sparam]={} --create sensor Parameter
elseif errorList["InputControl"]==nil then
errorList["InputControl"]={}
errorList["InputControl"]["etime"]="0"
errorList["InputControl"]["etype"]="redefinition Parameter"
errorList["InputControl"]["evalue"]=sid..':'..sparam
errorParse=true
end
if sparam==0 and slabel:sub(1,2)=="Tx" then
tx["TxId"]=sid
elseif sparam==0 and slabel:sub(1,2)=="Rx" then
rx["RxId"]=sid
end
newSensors[sid][sparam]["label"]=slabel
newSensors[sid][sparam]["unit"]=sunit
newSensors[sid][sparam]["logTime"]=0 -- time => valid
newSensors[sid][sparam]["value"] =0 -- value
-- check for sensor type definition in previous sensors definition
if not pcall(function()
newSensors[sid][sparam]["type"]=sensors[sid][sparam]["type"]
newSensors[sid][sparam]["decimals"]=sensors[sid][sparam]["decimals"]
end) then
newSensors[sid][sparam]["type"]=0
newSensors[sid][sparam]["decimals"]=0
end
end
end
until logTime>0 -- read defenition done
sensors=newSensors;
if tx["TxId"] then -- create tx input, param table
for param,senPar in pairs(sensors[tx["TxId"]]) do
if param~=0 then -- not for label
if param>50 then -- user Logger?
if tx[senPar["label"]] or senPar["label"]=="TxId" then
if errorList["InputControl"]==nil then
errorList["InputControl"]={}
errorList["InputControl"]["etime"]="0;"..tx["TxId"]..';'..param
errorList["InputControl"]["etype"]="redefinition Input Control"
errorList["InputControl"]["evalue"]=senPar["label"]
errorParse=true
end
else
tx[senPar["label"]]=param
end
else -- tx input control
local pos = senPar["label"]:find(" ",1)
if pos then
local sw=senPar["label"]:sub(pos+1)
if sw then
if tx[sw] or sw=="TxId" then
if errorList["InputControl"]==nil then
errorList["InputControl"]={}
errorList["InputControl"]["etime"]="0;"..tx["TxId"]..';'..param
errorList["InputControl"]["etype"]="redefinition Input Control"
errorList["InputControl"]["evalue"]=sw
errorParse=true
end
else
tx[sw]=param
end
end
end
end
end
end
end
elseif lpRun then
if file==nil then -- file finished
return
end
if logStartTime==0 then -- set offset time values to sync logtime with systemtime
logStartTime=logTime
systemStartTime=system.getTimeCounter()
end
playTime=system.getTimeCounter()-systemStartTime
while logTime-logStartTime <= playTime do -- read log file data
if sid=="0000000000" then -- sensor value for undefind sensor
--print ("ALARM")
elseif sensors[sid]==nil then
if errorList["playerRun"]==nil then
errorList["playerRun"]={}
errorList["playerRun"]["etime"]=logTime
errorList["playerRun"]["etype"]="unknown ID"
errorList["playerRun"]["evalue"]=sid
errorParse=true
end
else
while ePos>0 do
sparam=tonumber(findPos()) -- param
if sparam==nil then -- line ends with ';'
break
end
if sensors[sid][sparam]==nil then
if errorList["playerRun"]==nil then
errorList["playerRun"]={}
errorList["playerRun"]["etime"]=logTime
errorList["playerRun"]["etype"]="unknown Parameter"
errorList["playerRun"]["evalue"]=sparam
errorParse=true
end
break
else -- store parameter set
sensors[sid][sparam]["logTime"] = logTime -- time
if sensors[sid][0]~=nil then
sensors[sid][0]["logTime"] = logTime -- sensorname also has a "valid" time
end
sensors[sid][sparam]["type"] = tonumber(findPos()) -- type
sensors[sid][sparam]["decimals"]= tonumber(findPos()) -- decimals
sensors[sid][sparam]["value"] = tonumber(findPos()) -- value
if not(sensors[sid][sparam]["type"]==5 or sensors[sid][sparam]["type"]==9) then
if sensors[sid][sparam]["min"]==nil then -- find min value
sensors[sid][sparam]["min"]=sensors[sid][sparam]["value"]
elseif sensors[sid][sparam]["min"]> sensors[sid][sparam]["value"] then
sensors[sid][sparam]["min"]= sensors[sid][sparam]["value"]
end
if sensors[sid][sparam]["max"]==nil then -- find max value
sensors[sid][sparam]["max"]=sensors[sid][sparam]["value"]
elseif sensors[sid][sparam]["max"] < sensors[sid][sparam]["value"] then
sensors[sid][sparam]["max"] = sensors[sid][sparam]["value"]
end
end
end
end --eol - next
end
repeat
line = io.readline(file)
if line==nil then
logTime=0
io.close(file)
file=nil
return -- eof - done
end
ePos=0
logTime= tonumber(findPos())
sid=(findPos())
until logTime~=nil -- jump over empty lines or comment lines
playTime=system.getTimeCounter()-systemStartTime
end -- eotime - return
elseif lpEnd then -- finished
if file then -- close file if not already done
io.close(file)
file=nil
end
else -- something went wrong
if file then -- close file if not already done
io.close(file)
file=nil
end
if errorList["playerState"]==nil then
errorList["playerState"]={}
errorList["playerState"]["etime"]=logTime
errorList["playerState"]["etype"]="Player State Mashine"
errorList["playerState"]["evalue"]="unknown State"
errorParse=true
end
end
end
--------------------------------------------------------------------
-- initForm functions
--------------------------------------------------------------------
local function initForm()
local logFiles={} -- file list
local fileIndex=0 -- selected file index
local i=1 -- number of files
local function swResetChanged(value) -- store configuration
swReset=value
system.pSave("swReset",value)
end
local function lfChanged(value)
logFile=logFiles[value]
system.pSave("logFile",logFile)
lpNewFile=true
end
fileIndex=0 -- read directory
for name, filetype in dir(logPath) do
if filetype=="file" then
local pos = name:find(".log")
if pos then
logFiles[i]=name
if logFile then
if name==logFile then -- index = previous selected file
fileIndex=i
end
end
i=i+1
end
end
end
if logFiles[1] then -- select log file
form.addRow(2)
form.addLabel({label="File"})
form.addSelectbox (logFiles, fileIndex, true ,lfChanged)
else
form.addRow(1)
form.addLabel({label="NO LOG-File!!"})
end
form.addRow(2) -- select Reset switch
form.addLabel({label="Player Reset"})
form.addInputbox(swReset,true,swResetChanged)
end
--------------------------------------------------------------------------------
-- draw Telemetry Window
--------------------------------------------------------------------------------
local function displayValues(width, height)
lcd.drawText(2,1,state)
if errorParse then
lcd.drawText(40,1,"parse",FONT_MINI)
lcd.drawText(40,11,"error",FONT_MINI)
else
-- i.e next logfile time could be placed here
lcd.drawText(38,6,string.format("%08.3f",((logTime-logStartTime)/1000)),FONT_MINI)
end
lcd.drawText(93,1,string.format("%07.1f",(playTime/1000)))
end
--------------------------------------------------------------------------------
-- register / rewrite Telemetrie window
--------------------------------------------------------------------------------
local function registerTeleDisplay()
local strF=logFile:sub(1,12)
strF=strF..string.rep(" ",(12-strF:len()))
local strM=model:sub(1,10)
strM=strM..string.rep(" ",(10-strM:len()))
system.registerTelemetry(1,string.format("LP: %s %s",strF,strM),1,displayValues)
end
--------------------------------------------------------------------
-- Runtime function
--------------------------------------------------------------------
local function loop()
if swReset~=nil then -- control switch defined?
local valReset = system_getInputsVal(swReset)
if valReset>0 then -- Restart log file?
if lpRun then
lpRun=false
lpEnd=true
logPlayer()
printStatus("LP: stopped")
state="stop"
end
if ((valReset>0 and lpNewFile) or not lpReset) and logFile then
lpReset=true
lpRun=false
lpEnd=false
lpNewFile=false
logPlayer() -- read log file until log time starts
printStatus("LP: initillised")
state="init"
registerTeleDisplay() -- rewrite Telemetry window name
end
else -- play file
if lpReset and not lpRun then
lpRun=true
lpReset=false
printStatus("LP: playing")
state="play"
end
if lpRun then
logPlayer() -- read log file until log time offset >= passed system time diff
if file==nil and not lpEnd then -- all done: reached end of file
lpEnd=true
lpRun=false
printStatus("LP: finished")
state="fini"
end
end
end
--[[
-- set globals
globLogFilePlay.file=logFile:sub(1,12)
globLogFilePlay.model=model:sub(1,10)
globLogFilePlay.status=state
globLogFilePlay.playT=playTime
globLogFilePlay.error=errorParse
--
]]
end
end
--------------------------------------------------------------------
-- Init function
--------------------------------------------------------------------
local function init(code)
local deviceName,deviceType=system.getDeviceType ()
if deviceType==1 then
system.registerForm(1,MENU_APPS,appName,initForm)
swReset = system.pLoad("swReset",system.createSwitch("SA", "S",1)) -- read old configuration
logFile= system.pLoad("logFile",logFile)
model="" -- preset Telemetry window
registerTeleDisplay()
lpReset=false -- state machine
lpRun=false
lpEnd=false
lpNewFile=false
sensors={}
errorList={} -- reset Error list
errorParse=false
systemStartTime=0 -- set player time
logStartTime=0
logTime=0
playTime=0
state="wait"
else
print ("Emulator usage ONLY!!!")
end
end
return {init=init, loop=loop, author="Andre", version="0.53",name=appName}