-
Notifications
You must be signed in to change notification settings - Fork 8
/
Notes_on_wpl.txt
398 lines (350 loc) · 11.5 KB
/
Notes_on_wpl.txt
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
Notes on the wpl format
WPL files are organized in records, each containing a piece of information.
First byte of the record is the content lenght: record lenght is content lenght+3
Second and third bytes define the record type (note that not all are defined, only the one I fould useful)
06 03 is title (each byte is an ascii character)
04 55 is the maximum inclination in percent multiplied by 10 (3.5% is coded 35)
04 59 is the maximum velocity in miles/hours multiplied by 10 (3.1 m/h is coded 31)
04 10 is the total time in seconds
04 13 is the total time in seconds (differs from previous only in the checksum)
04 108 is the total distance in miles multiplied by 1,000
04 58 is the total distance in miles multiplied by 1,000 (same as previous)
04 106 are the calories
04 114 is the vertical distance in feet
04 47 is the set velocity in miles/hours multiplied by 10
04 45 is the set inclination in percent multiplied by 10
11 14 is the set end-of-time in seconds
Last byte is a checksum: the total of all record should always be a multiple of 256, otherwise the record is rejected
Two consecutive records of [02 13 02 01 238] indicate the beginning of the workout.
At the end of the workout the system is instructed to go to velocity 0 and inclination 0; this is normally done twice for safety.
To create a new workout, the records after [02 13 02 01 238] must be re-written with the set goals:
set velocity
set inclination
until end-of-time
and closing with
set velocity=0
set inclination=0
set velocity=0
set inclination=0
and the added bytes of unknown origin: [00, 41, 215, 00, 02, 254]
-------------------------------------------------------------
Here the breakout of CLTXGK6V.wpl
12 6 3 73 110 116 101 110 115 105 116 121 32 49 211
12 6 7 73 110 116 101 110 115 105 116 121 32 49 207
9 6 2 67 76 84 88 71 75 54 86 150
13 44 1 80 76 84 88 71 75 54 86 46 99 105 102 0
13 44 4 66 76 84 88 71 75 54 86 46 99 105 102 11
13 44 2 70 76 84 88 71 75 54 86 46 99 105 102 9
9 47 2 0 0 0 1 0 61 0 14 122
10 48 2 14 0 0 0 0 0 0 4 176 2
5 4 65 0 0 0 0 182
5 4 55 0 0 0 80 112
5 4 59 0 0 0 35 153
5 4 28 0 0 0 28 191
5 4 10 0 0 4 176 57
5 4 13 0 0 4 176 54
5 4 108 0 0 4 29 106
5 4 58 0 0 4 29 156
5 4 106 0 0 0 186 211
5 4 114 0 0 1 12 120
5 4 14 0 0 0 0 233
5 4 35 0 0 0 0 212
2 13 3 0 238
12 14 86 85 49 68 80 48 70 72 46 119 97 118 60
2 13 3 0 238
12 14 88 57 74 77 49 84 66 77 46 119 97 118 46
2 13 2 1 238
2 13 2 1 238
5 4 47 0 0 0 28 172
5 4 45 0 0 0 10 192
6 11 14 0 0 0 60 4 161
5 4 47 0 0 0 30 170
5 4 45 0 0 0 20 182
6 11 14 0 0 0 120 4 101
5 4 47 0 0 0 32 168
5 4 45 0 0 0 30 172
6 11 14 0 0 0 180 4 41
5 4 47 0 0 0 35 165
5 4 45 0 0 0 80 122
6 11 14 0 0 1 164 4 56
5 4 45 0 0 0 40 162
6 11 14 0 0 1 224 4 252
5 4 45 0 0 0 80 122
6 11 14 0 0 2 208 4 11
5 4 45 0 0 0 40 162
6 11 14 0 0 3 12 4 206
5 4 45 0 0 0 80 122
6 11 14 0 0 3 252 4 222
5 4 47 0 0 0 32 168
5 4 45 0 0 0 30 172
6 11 14 0 0 4 56 4 161
5 4 47 0 0 0 30 170
5 4 45 0 0 0 20 182
6 11 14 0 0 4 116 4 101
5 4 47 0 0 0 28 172
5 4 45 0 0 0 10 192
6 11 14 0 0 4 176 4 41
5 4 47 0 0 0 0 200
5 4 45 0 0 0 0 202
5 4 47 0 0 0 0 200
5 4 45 0 0 0 0 202
-----------------------------------------------------------------------------
Here a code that reads the wpl and re-write it with a new set of values. Values are read out from the file Inputchange.txt
; program to scan through the workout file
; Stefano 20151211
pro Scan_tread_files
!p.multi=0
if !d.name eq 'WIN' then begin
device,decompose=0 & loadct,39
; window,xsize=1100,ysize=850
endif else begin
loadct,39
endelse
cd,'C:\privat\Treadmill\Input'
file='14 - CLTXGK6V'+'.wpl'
file=dialog_pickfile(filter='*.wpl') ; this picks up the file to be opened and used as master file
close,1 & openr,1,file
info=fstat(1)
sss=info.size ; reads file length
allbytes=bytarr(sss)
readu,1,allbytes ; reads all bytes
ind=0
rind=-1
set_v=0.0
set_i=0.0
vvv=fltarr(10000) & iii=vvv & ttt=vvv
print,' '
print,'File: ',file,' size:',sss
newrec: ; works one record at a time
;stop
len=allbytes(ind)
if len eq 0 then begin
print,'Len = 0'
goto,done
endif
typ=allbytes(ind+1)
rec=allbytes(ind+3:ind+len+1)
chksum=total(allbytes(ind:ind+len+2)) mod 256
if chksum ne 0 then begin
print,allbytes(ind:ind+len+2)
print,'Checksum error'
close,/all
stop
endif
;print,allbytes(ind:ind+len+2)
; from here reads values stored in the header. Some are not understood and will be left alone
; Some will need update
if allbytes(ind) gt 3 and allbytes(ind+2) eq 3 then begin
print,'Title: ',string(rec)
endif
if allbytes(ind+2) eq 55 then begin
print,'Max Inclination :',allbytes(ind+len+1)/10.
indmaxin=ind
endif
if allbytes(ind+2) eq 59 then begin
print,'Max Velocity :',allbytes(ind+len+1)/10.
indmaxvel=ind
endif
if allbytes(ind+2) eq 28 then begin
print,'Misterious number :',allbytes(ind+len+1)
endif
if allbytes(ind+2) eq 10 then begin
print,'Total time :',allbytes(ind+len)*256+allbytes(ind+len+1),' sec'
print,'Total time :',(allbytes(ind+len)*256+allbytes(ind+len+1))/60,' min'
indtottim=ind
endif
if allbytes(ind+2) eq 13 then begin
indtottim2=ind
endif
if allbytes(ind+2) eq 108 then begin
print,'Distance :',(allbytes(ind+len)*256+allbytes(ind+len+1))/1000.,' miles'
indtotdis=ind
endif
if allbytes(ind+2) eq 58 then begin
indtotdis2=ind
endif
if allbytes(ind+2) eq 106 then begin
print,'Calories :',(allbytes(ind+len)*256+allbytes(ind+len+1))
indtotcal=ind
endif
if allbytes(ind+2) eq 114 then begin
print,'Vertical :',(allbytes(ind+len)*256+allbytes(ind+len+1)),' feet'
indtotver=ind
endif
; end of header. Start of exercise
if allbytes(ind+1) eq 4 and allbytes(ind+2) eq 47 then begin
set_v=allbytes(ind+len+1)/10.
endif
if allbytes(ind+1) eq 4 and allbytes(ind+2) eq 45 then begin
set_i=allbytes(ind+len+1)/10.
endif
if allbytes(ind+1) eq 11 and allbytes(ind+2) eq 14 then begin
rind=rind+1
set_t=allbytes(ind+len-1)*256+allbytes(ind+len)
print,'V:',set_v,' I:',set_i,' until time:',set_t
vvv(rind)=set_v
iii(rind)=set_i
ttt(rind)=set_t
endif
if ind+len+3 lt sss then begin
ind=ind+len+3
goto,newrec
endif
done: ; end of reading the existing file
;stop
vvv=vvv(0:rind)
iii=iii(0:rind)
ttt=ttt(0:rind)
fff=vvv*(ttt-[0,ttt(0:n_elements(ttt)-2)])/3600.*5280*iii/100.
lll=vvv*(ttt-[0,ttt(0:n_elements(ttt)-2)])/3600.
; calories calculation
;mhr=208-(0.7*60)
;rhr=85.
;vo2max=15.3*(mhr/rhr)
; derived CFF: 1.07
ccc=(((0.05*iii)+0.95)*90+0)*(lll*1.609)*1.07
print,'Total feet up:',floor(total(fff))
print,'Total effective lenght:',total(lll),' miles'
print,'Total calories:',floor(total(ccc))
plot,ttt/60.,vvv,yrange=[0,12],psym=10
oplot,ttt/60.,iii,color=250,psym=10
close,/all
; from here start creating the new file
print,'Proceed with the correction? [1:yes, else:no]'
read,icont
if icont ne 1 then goto,exitt
close,14 & openr,14,'Inputchange.txt'
close,15 & openr,15,file
close,16 & openw,16,'out.wpl' ; this will be the new exercise file
; look for the end of the header
iset=-1
for i=0,sss-5 do begin
if ( (allbytes(i) eq 2) and (allbytes(i+1) eq 13) and (allbytes(i+2) eq 2) and $
(allbytes(i+3) eq 1) and (allbytes(i+4) eq 238) ) then begin
print,'Here is a sync',i
iset = i
endif
endfor
iset=iset+5
;stop
outbytes=allbytes(0:iset-1) ; leaves the first records untouched. Maximums and totals will be re-written
rind=-1
vvv=fltarr(10000) & iii=vvv & ttt=vvv
while not eof(14) do begin
readf,14,vvv_,iii_,ttt_ ; values are in a text file
rind=rind+1
vvv(rind)=vvv_
iii(rind)=iii_
ttt(rind)=ttt_
endwhile
vvv=vvv(0:rind)
iii=iii(0:rind)
ttt=ttt(0:rind)
fff=vvv*(ttt-[0,ttt(0:n_elements(ttt)-2)])/3600.*5280*iii/100.
lll=vvv*(ttt-[0,ttt(0:n_elements(ttt)-2)])/3600.
ccc=(((0.05*iii)+0.95)*90+0)*(lll*1.609)*1.07
fff_=floor(total(fff))
lll_=floor(total(lll)*1000)
ccc_=floor(total(ccc))
maxv=floor(max(vvv))
maxi=floor(max(iii))
maxt=floor(max(ttt))
; rewrite the conditions
; max inclination
maxinc=floor(maxi*10)
outbytes(indmaxin+outbytes(indmaxin)+1)=maxinc
qqq=floor(total(outbytes(indmaxin:indmaxin+outbytes(indmaxin)+1)))
qqq=256-qqq
outbytes(indmaxin+outbytes(indmaxin)+2)=qqq
; max velocity
maxvel=floor(maxv*10)
outbytes(indmaxvel+outbytes(indmaxvel)+1)=maxvel
qqq=floor(total(outbytes(indmaxvel:indmaxvel+outbytes(indmaxvel)+1)))
qqq=256-qqq
outbytes(indmaxvel+outbytes(indmaxvel)+2)=qqq
; total time
b4=maxt-256*(maxt/256)
outbytes(indtottim+outbytes(indtottim)+1)=b4
outbytes(indtottim2+outbytes(indtottim2)+1)=b4
b3=maxt/256
outbytes(indtottim+outbytes(indtottim)+0)=b3
outbytes(indtottim2+outbytes(indtottim2)+0)=b3
qqq=floor(total(outbytes(indtottim:indtottim+outbytes(indtottim)+1)))
qqq=256-qqq
outbytes(indtottim+outbytes(indtottim)+2)=qqq
qqq=floor(total(outbytes(indtottim2:indtottim2+outbytes(indtottim2)+1)))
qqq=256-qqq
outbytes(indtottim2+outbytes(indtottim2)+2)=qqq
; total distance
totdis=floor(lll_)
b4=totdis-256*(totdis/256)
outbytes(indtotdis+outbytes(indtotdis)+1)=b4
outbytes(indtotdis2+outbytes(indtotdis2)+1)=b4
b3=maxt/256
outbytes(indtotdis+outbytes(indtotdis)+0)=b3
outbytes(indtotdis2+outbytes(indtotdis2)+0)=b3
qqq=floor(total(outbytes(indtotdis:indtotdis+outbytes(indtotdis)+1)))
qqq=256-qqq
outbytes(indtotdis+outbytes(indtotdis)+2)=qqq
qqq=floor(total(outbytes(indtotdis2:indtotdis2+outbytes(indtotdis2)+1)))
qqq=256-qqq
outbytes(indtotdis2+outbytes(indtotdis2)+2)=qqq
; total calories
totcal=floor(ccc_)
b4=totcal-256*(totcal/256)
outbytes(indtotcal+outbytes(indtotcal)+1)=b4
b3=totcal/256
outbytes(indtotcal+outbytes(indtotcal)+0)=b3
qqq=floor(total(outbytes(indtotcal:indtotcal+outbytes(indtotcal)+1)))
qqq=256-qqq
outbytes(indtotcal+outbytes(indtotcal)+2)=qqq
; total feet
totfeet=floor(fff_)
b4=totfeet-256*(totfeet/256)
outbytes(indtotver+outbytes(indtotver)+1)=b4
b3=totfeet/256
outbytes(indtotver+outbytes(indtotver)+0)=b3
qqq=floor(total(outbytes(indtotver:indtotver+outbytes(indtotver)+1)))
qqq=256-qqq
outbytes(indtotver+outbytes(indtotver)+2)=qqq
; now update the file with the new values
for i=0,n_elements(vvv)-1 do begin
rec=byte([5,4,47,0,0,0,byte(floor(vvv(i)*10))])
srec=byte(256-(total(rec) mod 256))
rec=[rec,byte(srec)]
outbytes=[outbytes,rec]
rec=byte([5,4,45,0,0,0,byte(floor(iii(i)*10))])
srec=byte(256-(total(rec) mod 256))
rec=[rec,byte(srec)]
outbytes=[outbytes,rec]
b4=byte(ttt(i)-256*(floor(ttt(i))/256))
b3=byte(ttt(i)/256)
rec=byte([6,11,14,0,0,b3,b4,4])
srec=byte(256-(total(rec) mod 256))
rec=[rec,byte(srec)]
outbytes=[outbytes,rec]
; stop
endfor
rec=byte([5,4,47,0,0,0,0])
srec=byte(256-(total(rec) mod 256))
rec=[rec,byte(srec)]
outbytes=[outbytes,rec]
rec=byte([5,4,45,0,0,0,0])
srec=byte(256-(total(rec) mod 256))
rec=[rec,byte(srec)]
outbytes=[outbytes,rec]
rec=byte([5,4,47,0,0,0,0])
srec=byte(256-(total(rec) mod 256))
rec=[rec,byte(srec)]
outbytes=[outbytes,rec]
rec=byte([5,4,45,0,0,0,0])
srec=byte(256-(total(rec) mod 256))
rec=[rec,byte(srec)]
outbytes=[outbytes,rec]
rec=byte([0,41,215,0,2,254])
outbytes=[outbytes,rec] ; final 6 bytes = signature?
writeu,16,outbytes
exitt:
close,/all
stop
end