10 toolstr="/home/muto/owtools/src/owtools USB1 DC "
24 bl.append(int(s[i2:i2+2],16))
28 def calculateValues(code, V, vn):
34 return V[vn]*0.2 + 700;
36 return math.exp(V[vn] / 160.0);
38 return V[vn]*62.5 + 55000;
43 return ((float(V[2]) / float(V[1]) - 0.16) / 0.0062) / (1.0546 - 0.00216*V[0]/256.0);
49 return V[vn] / 65535.0*5.1;
51 return V[vn] / 65535.0*2.55;
53 return V[vn] / 65535.0*1.1;
59 return (V[vn] - 32767.0) / 100.0;
61 return math.exp((V[vn]-32767.0)/1000.0);
69 return ["Temperatur","C"]
71 return ["Druck","hPa"]
73 return ["Beleuchtungsstaerke","lux"]
75 return ["Luftfeuchte","%%"]
77 return ["Konstante",""]
79 return ["Spannung","V"]
89 def owCom(dev,send,rcount):
90 cmd=toolstr+id2string(dev)
92 # cmd=cmd+"%02X" %(dev[7-i])
96 for i in range(rcount):
98 print(cmd.split(' '));
99 p = subprocess.Popen(cmd.split(' '), shell=False, bufsize=14000, stdin=subprocess.PIPE, stdout=subprocess.PIPE)
101 s=p.stdout.read().decode("utf-8")
105 for i in range(int(len(l[2])/2)):
107 bl.append(int(l[2][i2:i2+2],16))
110 def owComStr(dev,sendstr):
111 cmd=toolstr+id2string(dev)
113 # cmd=cmd+"%02X" %(dev[7-i])
115 p = subprocess.Popen(cmd.split(' '), shell=False, bufsize=14000, stdin=subprocess.PIPE, stdout=subprocess.PIPE)
117 s=p.stdout.read().decode("utf-8")
123 for i in range(int(len(l)/2)):
125 bl.append(int(l[i2:i2+2],16))
134 p = subprocess.Popen(["./owtools","USB1"], shell=False, bufsize=14000, stdin=subprocess.PIPE, stdout=subprocess.PIPE)
146 bl.append(int(d[i2:i2+2],16))
149 config=owCom(bl,[0x85],18)
151 dev.append(config[1:])
156 #print("Test_configs")
159 #print("c",dv[1][9:16])
161 if dv[1][9:16]==bl[0:7]:
162 print("Double Device")
171 voc_marker.append(vm)
172 #print("devlist",devlist)
175 def getProperties(dev,voc):
178 pl=["Temperatur","Spannung","Luftfeuchte","Strom"]
182 name=getName(dev[1][i*2])
186 #R0,VS,Corr,cmode,RS,RSR0,VOC1,VOC2
200 name=getName(dev[1][i*2])
205 def getValues(dev,voc):
207 #print(id2string(dev[0]),voc)
211 sbl=owComStr(dev[0],"4E000F_RB4_R_P7044_R_P70B800_RBE00FFFFFFFFFFFFFFFFFF_R4E0000_RB4_R_P70B800_RBE00FFFFFFFFFFFFFFFFFF_RBE03FFFFFFFFFFFFFFFFFF")
214 VDD=(sb[5]+sb[6]*256)
216 VAD=(sb[5]+sb[6]*256)
217 Temp=(sb[3]+sb[4]*256)
221 vals=[Temp,VDD,VAD,curr]
226 if (dev[1][i*2+1])!=0:
227 formellist.append(dev[1][i*2+1])
231 for i in range(len(formellist)):
232 cvals.append(calculateValues(formellist[i],vals,i))
239 #R0,VS,Corr,cmode,RS,RSR0,VOC1,VOC2
241 R0=(sb[2]+sb[3]*256)/100.0
242 VS=(sb[4]+sb[5]*256)/10000.0
243 Corr=(sb[7]+sb[8]*256)/1000.0
259 sbl=owComStr(dev[0],"44_R_PFF_PFF_PFF_PFFBEFFFFFFFFFFFFFFFFFF")
260 Temp=sbl[1][1]+sbl[1][2]*256
261 if (sbl[1][2] & 0x80):
264 return [calculateValues(dev[1][1],[Temp],0)]
266 return [calculateValues(1,[Temp],0)]
272 def gp_makefile(name,i):
273 f=open("gpscript%i.dem" %(i),"w")
274 #f.write("set decimalsign ','\n")
275 f.write('set decimalsign locale\n')
276 f.write('set timefmt "%d.%m.%Y %H:%M:%S"\n')
277 f.write('set xdata time\n')
278 f.write('set datafile separator "\\t" \n')
279 f.write('set terminal png size 1024,600\n')
280 f.write('set format x "%d.%m\\n%H:%M"\n')
281 f.write("set output '%s'\n" % (name))
282 f.write("set grid ytics\n")
283 f.write("set terminal postscript landscape\n")
284 f.write('set object 1 rectangle from screen 0,0 to screen 1,1 fillcolor rgb"#FFFFFF" behind\n')
285 #set output 'Temperatur.ps'
290 rl=["Temperatur","Luftfeuchte","Druck","VOC","Beleuchtungsstaerke"]
294 for i in range(len(rl)):
295 rlf.append("") #begin of plotline
296 rls.append('') #plotline
297 rllc.append('') #lineconfig
300 for i in range(len(rl)):
304 rls[i]=rls[i]+" %s using 1:%i with linespoints ls %i title \"%s\" ," % (rlf[i],c[1],li,cl[0])
305 rllc[i]=rllc[i]+ "set style line %i %s\n" % (li,cl[1])
307 for i in range(len(rl)):
308 f=gp_makefile(rl[i]+".ps",i)
310 f.write('plot "log22.txt" '+rls[i]+"\n")
311 f.write("set output '%s'\n" % (rl[i]+"_l.ps"))
312 f.write('plot "< tail -n 100 log22.txt" '+rls[i]+"\n")
314 p = subprocess.Popen(["gnuplot","gpscript%i.dem" %(i)], shell=False, bufsize=14000, stdin=subprocess.PIPE, stdout=subprocess.PIPE, stderr=subprocess.PIPE)
316 cmd="convert -size 2048x1600 -depth 8 %s.ps -rotate 90 -resize 1024x800 -depth 8 %s.png" %(rl[i],rl[i])
317 p = subprocess.Popen(cmd.split(" "), shell=False, bufsize=14000, stdin=subprocess.PIPE, stdout=subprocess.PIPE, stderr=subprocess.PIPE)
319 cmd="convert -size 2048x1600 -depth 8 %s_l.ps -rotate 90 -resize 1024x800 -depth 8 %s_l.png" %(rl[i],rl[i])
321 p = subprocess.Popen(cmd.split(" "), shell=False, bufsize=14000, stdin=subprocess.PIPE, stdout=subprocess.PIPE, stderr=subprocess.PIPE)
323 shutil.copyfile(rl[i]+".png","/var/www/html/"+rl[i]+".png")
324 shutil.copyfile(rl[i]+"_l.png","/var/www/html/"+rl[i]+"_l.png")
332 f=open("DEVLIST.txt","r")
333 for l in f.readlines():
336 devdict[ls[0]]=l.replace("\n","")
337 devwholist.append(ls[0])
351 if id2string(dd[0])==d:
352 print("->",id2string(dd[0]))
355 voc_marker1.append(voc_marker[i])
363 voc_marker=voc_marker1
374 prop=getProperties(d,voc_marker[i])
376 tline1=tline1+id2string(d[0])
384 gplist.append((p,col,dn))
387 prop=getProperties(d[2:],voc_marker[i])
388 tline1=tline1+id2string(d[2])
396 gplist.append((p,col,dn))
399 #if os.path.exists("log22.txt"):
400 # lt = time.localtime()
401 # ts=time.strftime("%Y%m%d%H%M%S", lt)
402 # os.rename("log22.txt","log22_"+ts+".txt")
404 f=open("log22h.txt","a")
412 lt = time.localtime()
413 vline=time.strftime("%d#%m#%Y %H:%M:%S\t", lt)
417 vals=getValues(d,voc_marker[i])
419 vline=vline+"%0.5f\t" % (v)
421 vals=getValues(d[2:],voc_marker[i])
423 vline=vline+"%0.5f\t" % (v)
426 f=open("log22.txt","a")
427 f.write(vline.replace('.',',').replace('#','.')+"\n")
436 id=[0x26,0xA3,0xD9,0x84,0x00,0x16,0x05,0x67]
437 print("VDD\tVAD\tTemp\tHum\tR0\tVS\tCorr\tcm\tRS\tRSR0\tVOC1\tVOC2");
438 print(owComStr(id,"85FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF"));
439 #print(owComStr(id,"4E000F_RB4_R_P7044_R_P70B8_RBE00FFFFFFFFFFFFFFFFFF_R4E0000_RB4_R_P70BE00FFFFFFFFFFFFFFFFFF_RBE03FFFFFFFFFFFFFFFFFF"))
442 sbl=owComStr(id,"4E000F_RB4_R_P7044_R_P70B8_RBE00FFFFFFFFFFFFFFFFFF_R4E0000_RB4_R_P70BE00FFFFFFFFFFFFFFFFFF_RBE03FFFFFFFFFFFFFFFFFF")
443 #owCom(id,[0x4E,0x00,0x0F],0)
449 #sb=owCom(id,[0xBE,0x00],11)
451 VDD=(sb[5]+sb[6]*256)/100.0
452 #owCom(id,[0x4E,0x00,0x00],0)
456 #sb=owCom(id,[0xBE,0x00],11)
458 VAD=(sb[5]+sb[6]*256)/100.0
459 Temp=(sb[3]+sb[4]*256)/256.0
460 #sb=owCom(id,[0xBE,0x03],11)
462 R0=(sb[2]+sb[3]*256)/100.0
463 VS=(sb[4]+sb[5]*256)/10000.0
464 Corr=(sb[7]+sb[8]*256)/1000.0
470 Hum=(VAD/VDD-0.16)/0.0062
471 Hum=(Hum)/(1.0546-0.00216*(Temp))
472 f=open("log.txt","a")
473 print("%0.3f\t%0.3f\t%0.3f\t%0.3f\t%0.3f\t%0.3f\t%0.3f\t%i\t%0.3f\t%0.3f\t%0.3f\t%0.3f" %(VDD,VAD,Temp,Hum,R0,VS,Corr,cmode,RS,RSR0,VOC1,VOC2))
474 f.write("%0.3f\t%0.3f\t%0.3f\t%0.3f\t%0.3f\t%0.3f\t%0.3f\t%i\t%0.3f\t%0.3f\t%0.3f\t%0.3f\n" %(VDD,VAD,Temp,Hum,R0,VS,Corr,cmode,RS,RSR0,VOC1,VOC2))
478 #cmd="owtools.exe usb1 DC 6705160084D9A326 BE00FFFFFFFFFFFFFFFFFFFF"
479 #print(owCom([0x26,0xA3,0xD9,0x84,0x00,0x16,0x05,0x67],[0xBE,0x00],11))