agri-controller 0.0.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (158) hide show
  1. data/bin/main.bat +2 -0
  2. data/bin/main.bat /202/326/202/314/203V/203/207/201[/203g/203J/203b/203g.lnk +0 -0
  3. data/bin/main.rb +23 -0
  4. data/bin/memo.txt +4 -0
  5. data/bin/server.bat +1 -0
  6. data/bin/server.bat /202/326/202/314/203V/203/207/201[/203g/203J/203b/203g.lnk +0 -0
  7. data/bin/server.rb +4 -0
  8. data/bin/set_config.rb +47 -0
  9. data/bin/usual.rb +3 -0
  10. data/bin//203R/203}/203/223/203h /203v/203/215/203/223/203v/203g.lnk +0 -0
  11. data/lib/agri-controller.rb +33 -0
  12. data/lib/agri-controller/bcc.rb +53 -0
  13. data/lib/agri-controller/bit.rb +143 -0
  14. data/lib/agri-controller/dacs.rb +114 -0
  15. data/lib/agri-controller/dircopy.rb +30 -0
  16. data/lib/agri-controller/error_caption.rb +46 -0
  17. data/lib/agri-controller/kr.rb +34 -0
  18. data/lib/agri-controller/kr_2.rb +78 -0
  19. data/lib/agri-controller/loger.rb +51 -0
  20. data/lib/agri-controller/main.rb +0 -0
  21. data/lib/agri-controller/main_new.rb +401 -0
  22. data/lib/agri-controller/multiple_pulse_timer.rb +169 -0
  23. data/lib/agri-controller/n_dan_thermo.rb +154 -0
  24. data/lib/agri-controller/save_threads.rb +172 -0
  25. data/lib/agri-controller/serial.rb +114 -0
  26. data/lib/agri-controller/setting_io.rb +53 -0
  27. data/lib/agri-controller/thermo_data_each_day.rb +67 -0
  28. data/lib/agri-controller/thermo_gruff.rb +109 -0
  29. data/lib/agri-controller/thermo_gruff_generate.rb +28 -0
  30. data/lib/agri-controller/thermo_gruff_loop.rb +35 -0
  31. data/lib/agri-controller/value_controller.rb +167 -0
  32. data/lib/agri-controller/version.rb +5 -0
  33. data/lib/agri-controller/web.rb +39 -0
  34. data/lib/agri-controller/webrick_test.rb +46 -0
  35. data/lib/agri-controller/wetsensor.rb +119 -0
  36. data/lib/agri-controller/wr1010.rb +316 -0
  37. data/lib/agri-controller/wr1010_2.rb +0 -0
  38. data/lib/cgi-bin/auto01.cgi +0 -0
  39. data/lib/cgi-bin/auto02.cgi +0 -0
  40. data/lib/cgi-bin/change_step.cgi +42 -0
  41. data/lib/cgi-bin/config/change_step +4 -0
  42. data/lib/cgi-bin/config/house1 +20 -0
  43. data/lib/cgi-bin/config/house2 +8 -0
  44. data/lib/cgi-bin/config/kr01_readable.txt +2 -0
  45. data/lib/cgi-bin/config/kr02_readable.txt +2 -0
  46. data/lib/cgi-bin/config/kr1_bit.txt +2 -0
  47. data/lib/cgi-bin/config/kr2_bit.txt +2 -0
  48. data/lib/cgi-bin/config/last_bit.txt +1 -0
  49. data/lib/cgi-bin/config/last_thermo_data +22 -0
  50. data/lib/cgi-bin/config/last_thermo_time +2 -0
  51. data/lib/cgi-bin/config/manual_bool01.txt +2 -0
  52. data/lib/cgi-bin/config/manual_bool02.txt +2 -0
  53. data/lib/cgi-bin/config/reload_flag +2 -0
  54. data/lib/cgi-bin/config/run_check +2 -0
  55. data/lib/cgi-bin/config/thermo_define.yml +4 -0
  56. data/lib/cgi-bin/config/time_array +10 -0
  57. data/lib/cgi-bin/config/wait_time +2 -0
  58. data/lib/cgi-bin/config/wet0 +3 -0
  59. data/lib/cgi-bin/config/wet0_drain +2 -0
  60. data/lib/cgi-bin/config/wet1 +3 -0
  61. data/lib/cgi-bin/config/wet1_drain +2 -0
  62. data/lib/cgi-bin/config/wet_input.txt +1 -0
  63. data/lib/cgi-bin/curtain_h1.cgi +43 -0
  64. data/lib/cgi-bin/curtain_h1_setting.cgi +43 -0
  65. data/lib/cgi-bin/curtain_h2.cgi +43 -0
  66. data/lib/cgi-bin/curtain_h2_setting.cgi +43 -0
  67. data/lib/cgi-bin/dacs_port.cgi +43 -0
  68. data/lib/cgi-bin/delay_time_0.cgi +43 -0
  69. data/lib/cgi-bin/delay_time_1.cgi +43 -0
  70. data/lib/cgi-bin/error_clear.cgi +0 -0
  71. data/lib/cgi-bin/house1.cgi +42 -0
  72. data/lib/cgi-bin/house1a.cgi +43 -0
  73. data/lib/cgi-bin/house2.cgi +42 -0
  74. data/lib/cgi-bin/house2b.cgi +43 -0
  75. data/lib/cgi-bin/house_n_dan_thermo1.cgi +43 -0
  76. data/lib/cgi-bin/house_n_dan_thermo2.cgi +0 -0
  77. data/lib/cgi-bin/keitai.cgi +25 -0
  78. data/lib/cgi-bin/kr01.cgi +0 -0
  79. data/lib/cgi-bin/kr01_readable.txt.cgi +42 -0
  80. data/lib/cgi-bin/kr02.cgi +0 -0
  81. data/lib/cgi-bin/kr02_readable.txt.cgi +42 -0
  82. data/lib/cgi-bin/kr1_bit.txt.cgi +42 -0
  83. data/lib/cgi-bin/kr2_bit.txt.cgi +42 -0
  84. data/lib/cgi-bin/kr_log.cgi +18 -0
  85. data/lib/cgi-bin/last_bit.txt.cgi +42 -0
  86. data/lib/cgi-bin/last_thermo_data.cgi +42 -0
  87. data/lib/cgi-bin/last_thermo_time.cgi +42 -0
  88. data/lib/cgi-bin/log.cgi +19 -0
  89. data/lib/cgi-bin/log/errors.txt +1 -0
  90. data/lib/cgi-bin/log/errors_.txt +93 -0
  91. data/lib/cgi-bin/log/kr_command_log.txt +240 -0
  92. data/lib/cgi-bin/log/log.txt +441 -0
  93. data/lib/cgi-bin/log/old_log/log_.txt +15 -0
  94. data/lib/cgi-bin/log/thermo/2010-05-22_thermo.csv +1438 -0
  95. data/lib/cgi-bin/log/thermo/2010-06-12_thermo.csv +3 -0
  96. data/lib/cgi-bin/log/thermo/2010-06-13_thermo.csv +2 -0
  97. data/lib/cgi-bin/log/thermo/2010-06-16_thermo.csv +85 -0
  98. data/lib/cgi-bin/log/thermo/2010-06-17_thermo.csv +285 -0
  99. data/lib/cgi-bin/log/thermo_data.csv +643 -0
  100. data/lib/cgi-bin/log/thermo_graph_loop.txt +1 -0
  101. data/lib/cgi-bin/main.cgi +98 -0
  102. data/lib/cgi-bin/manual_bool01.txt.cgi +42 -0
  103. data/lib/cgi-bin/manual_bool02.txt.cgi +42 -0
  104. data/lib/cgi-bin/post_change_step.cgi +44 -0
  105. data/lib/cgi-bin/post_house1.cgi +44 -0
  106. data/lib/cgi-bin/post_house2.cgi +44 -0
  107. data/lib/cgi-bin/post_kr01.cgi +0 -0
  108. data/lib/cgi-bin/post_kr01_readable.txt.cgi +44 -0
  109. data/lib/cgi-bin/post_kr02.cgi +0 -0
  110. data/lib/cgi-bin/post_kr02_readable.txt.cgi +44 -0
  111. data/lib/cgi-bin/post_kr1_bit.txt.cgi +44 -0
  112. data/lib/cgi-bin/post_kr2_bit.txt.cgi +44 -0
  113. data/lib/cgi-bin/post_last_bit.txt.cgi +44 -0
  114. data/lib/cgi-bin/post_last_thermo_data.cgi +44 -0
  115. data/lib/cgi-bin/post_last_thermo_time.cgi +44 -0
  116. data/lib/cgi-bin/post_manual_bool01.txt.cgi +44 -0
  117. data/lib/cgi-bin/post_manual_bool02.txt.cgi +44 -0
  118. data/lib/cgi-bin/post_reload_flag.cgi +44 -0
  119. data/lib/cgi-bin/post_run_check.cgi +44 -0
  120. data/lib/cgi-bin/post_thermo_define.yml.cgi +44 -0
  121. data/lib/cgi-bin/post_time_array.cgi +44 -0
  122. data/lib/cgi-bin/post_wait_time.cgi +44 -0
  123. data/lib/cgi-bin/post_wet0.cgi +44 -0
  124. data/lib/cgi-bin/post_wet0_drain.cgi +44 -0
  125. data/lib/cgi-bin/post_wet1.cgi +44 -0
  126. data/lib/cgi-bin/post_wet1_drain.cgi +44 -0
  127. data/lib/cgi-bin/post_wet_input.txt.cgi +44 -0
  128. data/lib/cgi-bin/reload_flag.cgi +42 -0
  129. data/lib/cgi-bin/reset_.cgi +0 -0
  130. data/lib/cgi-bin/run_check.cgi +42 -0
  131. data/lib/cgi-bin/set.cgi +33 -0
  132. data/lib/cgi-bin/set_post_yml_each.rb +72 -0
  133. data/lib/cgi-bin/set_yml_cgi_each.rb +0 -0
  134. data/lib/cgi-bin/setting.cgi +0 -0
  135. data/lib/cgi-bin/setting.cgi.1 +0 -0
  136. data/lib/cgi-bin/setting_io.rb +53 -0
  137. data/lib/cgi-bin/thermo_data_graphs.cgi +0 -0
  138. data/lib/cgi-bin/thermo_data_list.cgi +0 -0
  139. data/lib/cgi-bin/thermo_define.yml.cgi +42 -0
  140. data/lib/cgi-bin/thermo_graph.cgi +0 -0
  141. data/lib/cgi-bin/time_array.cgi +42 -0
  142. data/lib/cgi-bin/wait_time.cgi +42 -0
  143. data/lib/cgi-bin/web.rb +39 -0
  144. data/lib/cgi-bin/wet0.cgi +42 -0
  145. data/lib/cgi-bin/wet0_drain.cgi +42 -0
  146. data/lib/cgi-bin/wet1.cgi +42 -0
  147. data/lib/cgi-bin/wet1_drain.cgi +42 -0
  148. data/lib/cgi-bin/wet_input.txt.cgi +42 -0
  149. data/lib/htdocs/css/str.css +89 -0
  150. data/lib/htdocs/favicon.ico +0 -0
  151. data/lib/htdocs/thermo/thermo_data.jpg +0 -0
  152. data/lib/htdocs/thermo/thumb/thermo_data.jpg +0 -0
  153. data/test/tc_bit.rb +15 -0
  154. data/test/tc_bit.rb.1 +15 -0
  155. data/test/tc_bit.rb.2 +21 -0
  156. data/test/ts_agri-controller.rb +10 -0
  157. data/test/ts_agri-controller.rb.1 +8 -0
  158. metadata +229 -0
@@ -0,0 +1,114 @@
1
+ #!ruby
2
+ #coding:utf-8
3
+ module AgriController
4
+ require "Win32API"
5
+ class Serial
6
+ GENERIC_READ = 0x80000000
7
+ GENERIC_WRITE = 0x40000000
8
+ OPEN_EXISTING = 3
9
+ FILE_ATTRIBUTE_NORMAL = 0x00000080
10
+ FILE_FLAG_OVERLAPPED = 0x40000000
11
+ PURGE_TXABORT = 1
12
+ PURGE_RXABORT = 2
13
+ PURGE_TXCLEAR = 4
14
+ PURGE_RXCLEAR = 8
15
+
16
+ @@iniflg = 0
17
+ def initialize
18
+ if @@iniflg != 1
19
+ @@wcreatefile = Win32API.new('kernel32','CreateFile','PIIPIII','I');
20
+ @@wclosehandle = Win32API.new('kernel32','CloseHandle','I','I')
21
+ @@wSetupComm = Win32API.new('kernel32','SetupComm','III','I')
22
+ @@wPurgeComm = Win32API.new('kernel32','PurgeComm','II','I')
23
+ @@wSetCommTimeouts = Win32API.new('kernel32','SetCommTimeouts','IP','I')
24
+ @@wGetCommState = Win32API.new('kernel32','GetCommState','IP','I')
25
+ @@wSetCommState = Win32API.new('kernel32','SetCommState','IP','I')
26
+ @@wEscapeCommFunction = Win32API.new('kernel32','EscapeCommFunction','II','I')
27
+ @@wClearCommError = Win32API.new('kernel32','ClearCommError','IPP','I')
28
+ @@wWriteFile = Win32API.new('kernel32','WriteFile','IPIPP','I')
29
+ @@wReadFile = Win32API.new('kernel32','ReadFile','IPIPP','I')
30
+ @@iniflg = 1
31
+ end
32
+ @wcrecv = "\x0" * 512
33
+ @iinvstep = 1
34
+ end
35
+
36
+ def send(schar)
37
+ ilen = schar.length
38
+ wpwadd = [0].pack("I")
39
+ soverlapped = [0,0,0,0,0].pack("I*")
40
+ @@wWriteFile.call(@iht,schar,ilen,wpwadd,soverlapped)
41
+ end
42
+
43
+ def receive
44
+ dwerr = [0].pack("I")
45
+ statcom = [0,0,0].pack("I*")
46
+ bi = @@wClearCommError.call(@iht,dwerr,statcom)
47
+ if bi != 0
48
+ wstatcom = statcom.unpack("I*")
49
+ if wstatcom[1] > 0
50
+ ilen = wstatcom[1]
51
+ dreadsize = [0].pack("I")
52
+ roverlapped = [0,0,0,0,0].pack("I*")
53
+ @@wReadFile.call(@iht,@wcrecv,ilen,dreadsize,roverlapped)
54
+ irlen = dreadsize.unpack("I")
55
+ rcvchar = @wcrecv.unpack("a#{irlen[0]}")[0]
56
+ end
57
+ end
58
+ return rcvchar
59
+ end
60
+
61
+ def open(icomno,idcbflags,ibaud,ibyte,iparity,istopbits,irecbuf,isenbuf)
62
+ comno = "COM#{icomno}\0"
63
+ @iht = @@wcreatefile.call(comno,GENERIC_READ | GENERIC_WRITE,0,nil,
64
+ OPEN_EXISTING,FILE_ATTRIBUTE_NORMAL | FILE_FLAG_OVERLAPPED,0)
65
+ ir = nil
66
+ if @iht != -1
67
+ ir = catch(:exit){
68
+ bi = @@wSetupComm.call(@iht,irecbuf,isenbuf) #送受信バッファ
69
+ throw :exit, -2 if bi == 0
70
+ bi = @@wPurgeComm.call(@iht,PURGE_TXABORT | PURGE_RXABORT | PURGE_TXCLEAR | PURGE_RXCLEAR)
71
+ throw :exit, -3 if bi == 0 #バッファクリアー
72
+ readIntervalTimeout = 1000
73
+ readTotalTimeoutMultiplier = 0
74
+ readTotalTimeoutConstant = 0
75
+ writeTotalTimeoutMultiplier = 20
76
+ writeTotalTimeoutConstant = 1000
77
+ commTimeout = [readIntervalTimeout,readTotalTimeoutMultiplier,readTotalTimeoutConstant,
78
+ writeTotalTimeoutMultiplier,writeTotalTimeoutConstant]
79
+ wCommTimeout = commTimeout.pack("i*")
80
+ bi = @@wSetCommTimeouts.call(@iht,wCommTimeout);#time out
81
+ throw :exit, -4 if bi == 0
82
+ wDCB = ' ' * 8 * 3 + ' ' * 2 * 3 + ' ' * 1 * 8 + ' ' * 2
83
+ bi = @@wGetCommState.call(@iht,wDCB) #状態取得
84
+ throw :exit, -5 if bi == 0
85
+ dFMT = "IIISSSCCCCCCCCS" #DCB構造体
86
+ dcb = wDCB.unpack(dFMT)
87
+ dcb[2] = idcbflags
88
+ dcb[1] = ibaud
89
+ dcb[6] = ibyte
90
+ dcb[7] = iparity
91
+ dcb[8] = istopbits
92
+ wDCB = dcb.pack(dFMT)
93
+ bi = @@wSetCommState.call(@iht,wDCB) #状態セット
94
+ throw :exit, -6 if bi == 0
95
+ setdtr = 5
96
+ bi = @@wEscapeCommFunction.call(@iht,setdtr) #DTR ON
97
+ throw :exit, -7 if bi == 0
98
+ }
99
+ else
100
+ ir = -1
101
+ end
102
+ return ir
103
+ end
104
+
105
+ def close
106
+ if @iht != -1
107
+ clrdtr = 6
108
+ bi = @@wEscapeCommFunction.call(@iht,clrdtr) #DTR OFF
109
+ @@wclosehandle.call(@iht)
110
+ end
111
+ end
112
+
113
+ end
114
+ end
@@ -0,0 +1,53 @@
1
+ #!ruby
2
+ require "yaml"
3
+ require "yaml/store"
4
+
5
+ module AgriController
6
+ module_function
7
+ #module Setting_io
8
+ module_function
9
+ def yaml_db(name,value,file=name)#"db.yaml")
10
+ #p name
11
+ db=YAML::Store.new(file)
12
+ db.transaction do
13
+ db[name.to_s]=value
14
+ end
15
+ end
16
+
17
+ def yaml_dbr(name,file=name)#"db.yaml")
18
+ #p file
19
+ db=YAML::Store.new(file)
20
+ db.transaction(:read_only) do
21
+ db[name.to_s]
22
+ end
23
+ end
24
+ def yaml_key(file)
25
+ db=YAML::Store.new(file)
26
+ db.transaction(:read_only) do
27
+ db.roots.sort
28
+ end
29
+ end
30
+
31
+ def yaml_dump(data,filename="setting_io.yml")
32
+ yaml_db(name=filename,value=data,"db.yaml")
33
+ end
34
+
35
+ def yaml_load(filename="setting_io.yml")
36
+ res=yaml_dbr(name=filename)#,"db.yaml")
37
+ if res == nil
38
+ if File.exist?(filename)
39
+ a=File.read(filename)
40
+ if a
41
+ x=YAML.load(a)
42
+ yaml_db(name=filename,x,name)
43
+ end
44
+
45
+ return x
46
+ else
47
+ return nil
48
+ end
49
+ else
50
+ return res
51
+ end
52
+ end
53
+ end
@@ -0,0 +1,67 @@
1
+ require "time"
2
+ module AgriController
3
+ def thermo_data_each_day(file)
4
+ if File.exist?(file)
5
+ dat=File.read(file)
6
+ else
7
+ dat=file
8
+ end
9
+ x=[]
10
+ y=[]
11
+ line=0
12
+ file_num=0
13
+ last_day_data=0
14
+ change=nil
15
+ date=Time.now
16
+ begin
17
+ dat.each_line do |str|
18
+ line+=1
19
+ #split day data
20
+ #p str
21
+ if str!=""
22
+ data=str.chomp.split(",")
23
+ date=Time.parse(data[0])
24
+ last_day_data=date.day
25
+ change=date if change==nil
26
+ end
27
+ #not change
28
+ if change.day==last_day_data
29
+ #day change
30
+ elsif change.day!=last_day_data
31
+ y[file_num] = change
32
+ change=date
33
+ file_num+=1
34
+ else
35
+ p "??"
36
+ end
37
+ x[file_num]="" if x[file_num]==nil
38
+ x[file_num]+=str
39
+
40
+ #normal end
41
+
42
+ end
43
+ y[file_num]=date
44
+ end
45
+ #return split array
46
+ ret=[x,y]
47
+ return ret
48
+ end
49
+ def save_each_day(file="_thermo_data.csv")
50
+ p result=thermo_data_each_day(file)
51
+ x=0
52
+ result[1].each do |date|
53
+ i=date.year.to_s
54
+ j=date.month.to_s
55
+ k=date.day.to_s
56
+ #save_each_day
57
+ filename="./thermo_data/"+i+"-"+j+"-"+k+"_thermo.csv"
58
+ open(filename,"w"){|io| io.print result[0][x]}
59
+
60
+ x+=1
61
+ end
62
+ end
63
+ end
64
+
65
+ if $0==__FILE__
66
+ save_each_day(file="_thermo_data.csv")
67
+ end
@@ -0,0 +1,109 @@
1
+ require 'rubygems'
2
+ require 'gruff'
3
+ require "date"
4
+
5
+ module AgriController
6
+ #thrmo datas to jpg graph
7
+ def thermo_gruff(output_filename="thermo_data.jpg",input_csv_data="thermo_data.csv",thermo_num=3,view="500x420")
8
+ #data ini
9
+ data=File.read(input_csv_data)
10
+ thermo_data_hash={}
11
+
12
+ result=[]
13
+ #arrays generate
14
+ (2*thermo_num).times do
15
+ result << []
16
+ end
17
+ result
18
+ title_day=""
19
+ line=0
20
+ label={}
21
+ hour=0
22
+ day=0
23
+ data.each_line do |str|
24
+ line+=1#line+=
25
+ dat=str.chomp.split(",")
26
+ #p dat[0]
27
+ begin
28
+ time=DateTime.parse(dat[0])
29
+ rescue
30
+ line=line-1
31
+ next
32
+ end
33
+ #title_day
34
+ if line==1
35
+ title_day=time.year.to_s+"/"+time.month.to_s+"/"+time.day.to_s
36
+ end
37
+ #line if day change
38
+ if time.day!=day #(day change)
39
+ day=time.day
40
+ label[line]=":"#time.month.to_s+"/"+day.to_s
41
+ elsif time.hour!=hour
42
+ hour=time.hour
43
+ label[line]="|"+hour.to_s
44
+ if time.hour==12
45
+ label[line]="|12"
46
+ end
47
+ else
48
+ end
49
+
50
+ #set thermo datas
51
+ thermo_num.times do |n|
52
+ begin
53
+ x=dat[n*2+1].to_f
54
+ if x>-100
55
+ result[n*2] << x
56
+ else
57
+ result[n*2] << nil
58
+ end
59
+ rescue
60
+ result[n*2] << nil
61
+ end
62
+ #Judge nil data
63
+ if dat[n*2+2]!="false"
64
+ result[n*2+1] << dat[n*2+2].to_f/3
65
+ else
66
+ result[n*2+1] << nil
67
+ end
68
+ end
69
+ end
70
+ #p result
71
+ #p label
72
+ #gruff main
73
+ g = Gruff::Line.new(view)
74
+ g.title="Thermo data since "+title_day
75
+ #g.title_font_size =24
76
+ g.theme_37signals
77
+ g.maximum_value = 35
78
+ g.minimum_value = 5
79
+ g.y_axis_increment = 1
80
+ #g.baseline_value=9
81
+ #g.increment=5
82
+ #dataset
83
+ datasets=[]
84
+ thermo_num.times do |i|
85
+ x=i+1
86
+ datasets[i*2 ]=[("'C:"+x.to_s).intern,result[i*2]]
87
+ datasets[i*2+1]=[("%/3:"+x.to_s).intern,result[i*2+1]]
88
+ end
89
+ #% humidity data delete
90
+ [7,5,3].each{|i| datasets.delete_at(i)}
91
+
92
+ #dataset
93
+ datasets.each do |data|
94
+ g.data(*data)
95
+ end
96
+ g.labels =label
97
+ # Default theme
98
+ g.write(output_filename)
99
+ end
100
+ end
101
+
102
+ if $0==__FILE__
103
+ p Dir.pwd
104
+ input_csv_data="./thermo_data/2009-11-21_thermo.csv"
105
+ if File.readable?(input_csv_data)
106
+ thermo_gruff(output_filename="../htdocs/thermo/2009-11-21.jpg",input_csv_data,thermo_num=2,"480x420")
107
+ p Time.now
108
+ end
109
+ end
@@ -0,0 +1,28 @@
1
+ #!ruby
2
+ #coding:utf-8
3
+ module AgriController
4
+
5
+ def thermo_gruff_generate(dir_to="./htdocs/thermo",dir_from="./cgi-bin/log/thermo",num=3)
6
+ dir=dir_from+"/*_thermo.csv"
7
+ list=Dir.glob(dir)
8
+
9
+ list.each do |file|
10
+ #p file
11
+ name=File.basename(file).split(/_/)[0]
12
+ new_name=dir_to+"/"+name+".jpg"
13
+
14
+ #p name
15
+ #p new_name
16
+
17
+ unless File.exist?(new_name)
18
+ thermo_gruff(new_name,file,thermo_num=num,"480x420")
19
+ end
20
+
21
+ new_name=dir_to+"/thumb/"+name+"_s.jpg"
22
+ unless File.exist?(new_name)
23
+ thermo_gruff(new_name,file,thermo_num=num,"240x320")
24
+ end
25
+ #p Time.now
26
+ end
27
+ end
28
+ end
@@ -0,0 +1,35 @@
1
+ #!ruby
2
+ #coding:utf-8
3
+
4
+ #require "thermo_gruff"
5
+ #require "thermo_gruff_generate"
6
+ module AgriController
7
+ module_function
8
+ def thermo_gruff_loop(verbose=false,dir_to="./htdocs/thermo",dir_from="./cgi-bin/log",num=3)
9
+ p "gruf_start:"+Time.now.to_s if verbose
10
+ loop do
11
+ input_csv_data=dir_from+"/thermo_data.csv"#"data.tmp"
12
+ if File.readable?(input_csv_data)
13
+ output_filename=dir_to+"/thermo_data.jpg"
14
+ input_csv_data
15
+
16
+ thermo_gruff(output_filename=dir_to+"/thermo_data.jpg",input_csv_data,thermo_num=num,"480x420")
17
+ thermo_gruff(output_filename=dir_to+"/thumb/thermo_data.jpg",input_csv_data,thermo_num=num,"220x250")
18
+
19
+ Loger::loger(dir_from+"/thermo_graph_loop.txt",Time.now.to_s,"w")
20
+ end
21
+
22
+ #check 1day thermo_data and generate gruff(and small gruff) below
23
+ thermo_gruff_generate
24
+ sleep 120
25
+ p "gruff_loop:"+Time.now.to_s if verbose
26
+ end
27
+ end
28
+ end
29
+ if $0==__FILE__
30
+ require "thermo_gruff"
31
+ require "thermo_gruff_generate"
32
+ include AgriController
33
+
34
+ thermo_gruff_loop
35
+ end
@@ -0,0 +1,167 @@
1
+ #!ruby
2
+ #coding:utf-8
3
+
4
+ module AgriController
5
+ class Value_controller
6
+ attr_accessor:steps,:now_step,:up_sec,:down_sec,:acting
7
+ attr_accessor:set_value,:controll_bool,:reset_time
8
+
9
+ def initialize(steps=5,up_sec=60,down_sec=open_sec,sensitivity=1,set_value=20,dead_time=2,verbose=false)
10
+ @bit=0
11
+
12
+ @steps =steps #多段制御>=1
13
+ @up_sec=up_sec
14
+ @down_sec=down_sec #閉時動作時間(秒)
15
+ @sensitivity =sensitivity #感度
16
+ @set_value =set_value #設定値
17
+ @dead_time =dead_time #不感時間
18
+ @dead_bool =false
19
+ @now_step=@steps #現在の段(2010.5.23変更)
20
+
21
+ @controll_bool=false #割り込みswitch(0n,0ff)
22
+ @time=Time.now
23
+ @acting=false
24
+ @bool=false #true(on) false(off)方向
25
+ @verbose=verbose
26
+ @reset_time=Time.now+@up_sec*@steps+3
27
+ p "Value_controller initialized at #{@reset_time}" if @verbose
28
+ end
29
+
30
+ def switch
31
+ if @now_step==0 or @now_step==@steps
32
+ return true
33
+ else
34
+ return @controll_bool
35
+ end
36
+ end
37
+
38
+ def switch_on
39
+ @controll_bool = true
40
+ end
41
+
42
+ def switch_off
43
+ @controll_bool = false
44
+ end
45
+
46
+ def value_controll(now_value)
47
+ if Time.now < @reset_time
48
+ return true
49
+ #return false #common open when initialize
50
+ end
51
+ if @acting==false
52
+ #now_value:nil or tempareture
53
+ if now_value != nil
54
+ high=(now_value <=> @set_value+@sensitivity*(@now_step+1))
55
+ low =(now_value <=> (@set_value+@sensitivity*(@now_step))-2)
56
+ else
57
+ high=1#温度を下げる方向へセット
58
+ low=0 #そのまま
59
+ p Time.now.inspect+" :"+now_value.inspect
60
+ raise "value_controller.rb:68 error!!"
61
+ end
62
+
63
+ #もし動作中なら、そのときの温度に関係なく動作続行(下記の判定は読みとばす)
64
+ #動作してなくて、且つステップの範囲内でstep_up , step_downさせる
65
+ if @dead_bool==false
66
+ if high==1 && @now_step<@steps
67
+ #且つ、スイッチがオフ
68
+ if @controll_bool == false
69
+ #時間
70
+ @time=Time.now
71
+ switch_on#スイッチオン
72
+ @bool=true#return true
73
+ #タイマー時間設定
74
+ step_up
75
+ end
76
+ elsif low==-1 && @now_step>0
77
+ #且つ、スイッチがオフ
78
+ if @controll_bool == false
79
+ #時間
80
+ @time=Time.now
81
+ switch_on#スイッチオン
82
+ @bool=false#return true
83
+ #タイマー時間設定
84
+ step_down
85
+ end
86
+ elsif high==1 && @now_step==@steps
87
+ @bool=true
88
+ elsif low==-1 && @now_step==0
89
+ @bool=false
90
+ else
91
+ #
92
+ end
93
+ end
94
+ end
95
+
96
+ ##
97
+ #時刻設定
98
+ #スイッチがオン
99
+ #時間までタイマーオン
100
+ #時間になったらスイッチオフ
101
+ #デッドタイム処理
102
+ #スイッチオフ
103
+ #value_controllもnil
104
+ if @bool==true
105
+ x=pulse_timer([@time,@up_sec])
106
+ y=pulse_timer([@time,@up_sec+@dead_time])
107
+ else #@bool==false
108
+ x=pulse_timer([@time,@down_sec])
109
+ y=pulse_timer([@time,@down_sec+@dead_time])
110
+ end
111
+ if y==true
112
+ @acting=true
113
+ else
114
+ @acting=false
115
+ end
116
+
117
+ if x==true
118
+ elsif x==false && y==true
119
+ switch_off
120
+ @dead_bool = true
121
+ else
122
+ @dead_bool = false
123
+ end
124
+ return @bool
125
+ end
126
+
127
+ def step_up
128
+ @now_step+=1 if @now_step < @steps
129
+ return @now_step
130
+ end
131
+
132
+ def step_down
133
+ @now_step=now_step-1 if @now_step > 0
134
+ return @now_step
135
+ end
136
+ end
137
+ end
138
+
139
+ if $0==__FILE__
140
+ require "multiple_pulse_timer"
141
+ require "setting_io"
142
+ include AgriController
143
+ p a=Value_controller.new(
144
+ name="house1a.yml",
145
+ steps=5,
146
+ open_sec=4,
147
+ down_sec=3,
148
+ sensitivity=2,
149
+ set_value=5,
150
+ dead_time=1.5)
151
+ require "setting_io"
152
+ require "n_dan_thermo"
153
+ house1=N_dan_thermo.new(Setting_io::yaml_load("house_n_dan_thermo1.yml"),diff=4,300)
154
+ p house1.set_now
155
+ p a.set_value
156
+ p a.value_controll(house1.set_now)
157
+ p a.switch
158
+
159
+ 60.times do |x|
160
+ sleep 1
161
+ p a if x%10==0
162
+ if x>30
163
+ a.set_value=25
164
+ end
165
+ p a.value_controll(house1.set_now).to_s+","+a.switch.to_s+","+a.now_step.to_s
166
+ end
167
+ end