agri-controller 0.0.0 → 0.0.8
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/ChangeLog.txt +36 -0
- data/LICENSE.txt +15 -0
- data/agri-controller.gemspec +36 -0
- data/gpl-2.0.txt +339 -0
- data/lib/agri-controller.rb +11 -33
- data/lib/agri-controller/bcc.rb +86 -53
- data/lib/agri-controller/bit.rb +158 -143
- data/lib/agri-controller/device.rb +7 -0
- data/lib/agri-controller/device/dacs.rb +148 -0
- data/lib/agri-controller/device/kr.rb +23 -0
- data/lib/agri-controller/device/ma.rb +92 -0
- data/lib/agri-controller/device/mch383.rb +178 -0
- data/lib/agri-controller/device/tr.rb +230 -0
- data/lib/agri-controller/device/wr1010.rb +314 -0
- data/lib/agri-controller/dt.rb +17 -0
- data/lib/agri-controller/error_caption.rb +67 -46
- data/lib/agri-controller/gruff.rb +7 -0
- data/lib/agri-controller/gruff/base.rb +88 -0
- data/lib/agri-controller/gruff/chdata.rb +64 -0
- data/lib/agri-controller/gruff/join_csv.rb +62 -0
- data/lib/agri-controller/gruff/rename_csv.rb +50 -0
- data/lib/agri-controller/{thermo_data_each_day.rb → gruff/thermo_data_each_day.rb} +67 -67
- data/lib/agri-controller/{thermo_gruff.rb → gruff/thermo_gruff.rb} +112 -109
- data/lib/agri-controller/gruff/thermo_gruff2.rb +161 -0
- data/lib/agri-controller/{thermo_gruff_generate.rb → gruff/thermo_gruff_generate.rb} +28 -28
- data/lib/agri-controller/gruff/thermo_gruff_loop.rb +42 -0
- data/lib/agri-controller/loger.rb +91 -51
- data/lib/agri-controller/main.rb +0 -0
- data/lib/agri-controller/main_linux.rb +282 -0
- data/lib/agri-controller/main_new.rb +401 -401
- data/lib/agri-controller/multiple_pulse_timer.rb +190 -169
- data/lib/agri-controller/n_dan_thermo.rb +156 -154
- data/lib/agri-controller/save_threads.rb +181 -172
- data/lib/agri-controller/setting_io.rb +53 -53
- data/lib/agri-controller/ttyUSB_watchdog.rb +43 -0
- data/lib/agri-controller/value_controller.rb +209 -167
- data/lib/agri-controller/version.rb +7 -5
- data/lib/agri-controller/web.rb +39 -39
- data/lib/agri-controller/webrick_test.rb +51 -46
- data/lib/agri-controller/wet_sensor.rb +92 -0
- data/test/tc_bit.rb +14 -3
- data/test/tc_trigger.rb +27 -0
- data/test/ts_agri-controller.rb +10 -10
- metadata +62 -202
- data/bin/main.bat +0 -2
- data/bin/main.bat /202/326/202/314/203V/203/207/201[/203g/203J/203b/203g.lnk +0 -0
- data/bin/main.rb +0 -23
- data/bin/memo.txt +0 -4
- data/bin/server.bat +0 -1
- data/bin/server.bat /202/326/202/314/203V/203/207/201[/203g/203J/203b/203g.lnk +0 -0
- data/bin/server.rb +0 -4
- data/bin/set_config.rb +0 -47
- data/bin/usual.rb +0 -3
- data/bin//203R/203}/203/223/203h /203v/203/215/203/223/203v/203g.lnk +0 -0
- data/lib/agri-controller/dacs.rb +0 -114
- data/lib/agri-controller/dircopy.rb +0 -30
- data/lib/agri-controller/kr.rb +0 -34
- data/lib/agri-controller/kr_2.rb +0 -78
- data/lib/agri-controller/serial.rb +0 -114
- data/lib/agri-controller/thermo_gruff_loop.rb +0 -35
- data/lib/agri-controller/wetsensor.rb +0 -119
- data/lib/agri-controller/wr1010.rb +0 -316
- data/lib/agri-controller/wr1010_2.rb +0 -0
- data/lib/cgi-bin/auto01.cgi +0 -0
- data/lib/cgi-bin/auto02.cgi +0 -0
- data/lib/cgi-bin/change_step.cgi +0 -42
- data/lib/cgi-bin/config/change_step +0 -4
- data/lib/cgi-bin/config/house1 +0 -20
- data/lib/cgi-bin/config/house2 +0 -8
- data/lib/cgi-bin/config/kr01_readable.txt +0 -2
- data/lib/cgi-bin/config/kr02_readable.txt +0 -2
- data/lib/cgi-bin/config/kr1_bit.txt +0 -2
- data/lib/cgi-bin/config/kr2_bit.txt +0 -2
- data/lib/cgi-bin/config/last_bit.txt +0 -1
- data/lib/cgi-bin/config/last_thermo_data +0 -22
- data/lib/cgi-bin/config/last_thermo_time +0 -2
- data/lib/cgi-bin/config/manual_bool01.txt +0 -2
- data/lib/cgi-bin/config/manual_bool02.txt +0 -2
- data/lib/cgi-bin/config/reload_flag +0 -2
- data/lib/cgi-bin/config/run_check +0 -2
- data/lib/cgi-bin/config/thermo_define.yml +0 -4
- data/lib/cgi-bin/config/time_array +0 -10
- data/lib/cgi-bin/config/wait_time +0 -2
- data/lib/cgi-bin/config/wet0 +0 -3
- data/lib/cgi-bin/config/wet0_drain +0 -2
- data/lib/cgi-bin/config/wet1 +0 -3
- data/lib/cgi-bin/config/wet1_drain +0 -2
- data/lib/cgi-bin/config/wet_input.txt +0 -1
- data/lib/cgi-bin/curtain_h1.cgi +0 -43
- data/lib/cgi-bin/curtain_h1_setting.cgi +0 -43
- data/lib/cgi-bin/curtain_h2.cgi +0 -43
- data/lib/cgi-bin/curtain_h2_setting.cgi +0 -43
- data/lib/cgi-bin/dacs_port.cgi +0 -43
- data/lib/cgi-bin/delay_time_0.cgi +0 -43
- data/lib/cgi-bin/delay_time_1.cgi +0 -43
- data/lib/cgi-bin/error_clear.cgi +0 -0
- data/lib/cgi-bin/house1.cgi +0 -42
- data/lib/cgi-bin/house1a.cgi +0 -43
- data/lib/cgi-bin/house2.cgi +0 -42
- data/lib/cgi-bin/house2b.cgi +0 -43
- data/lib/cgi-bin/house_n_dan_thermo1.cgi +0 -43
- data/lib/cgi-bin/house_n_dan_thermo2.cgi +0 -0
- data/lib/cgi-bin/keitai.cgi +0 -25
- data/lib/cgi-bin/kr01.cgi +0 -0
- data/lib/cgi-bin/kr01_readable.txt.cgi +0 -42
- data/lib/cgi-bin/kr02.cgi +0 -0
- data/lib/cgi-bin/kr02_readable.txt.cgi +0 -42
- data/lib/cgi-bin/kr1_bit.txt.cgi +0 -42
- data/lib/cgi-bin/kr2_bit.txt.cgi +0 -42
- data/lib/cgi-bin/kr_log.cgi +0 -18
- data/lib/cgi-bin/last_bit.txt.cgi +0 -42
- data/lib/cgi-bin/last_thermo_data.cgi +0 -42
- data/lib/cgi-bin/last_thermo_time.cgi +0 -42
- data/lib/cgi-bin/log.cgi +0 -19
- data/lib/cgi-bin/log/errors.txt +0 -1
- data/lib/cgi-bin/log/errors_.txt +0 -93
- data/lib/cgi-bin/log/kr_command_log.txt +0 -240
- data/lib/cgi-bin/log/log.txt +0 -441
- data/lib/cgi-bin/log/old_log/log_.txt +0 -15
- data/lib/cgi-bin/log/thermo/2010-05-22_thermo.csv +0 -1438
- data/lib/cgi-bin/log/thermo/2010-06-12_thermo.csv +0 -3
- data/lib/cgi-bin/log/thermo/2010-06-13_thermo.csv +0 -2
- data/lib/cgi-bin/log/thermo/2010-06-16_thermo.csv +0 -85
- data/lib/cgi-bin/log/thermo/2010-06-17_thermo.csv +0 -285
- data/lib/cgi-bin/log/thermo_data.csv +0 -643
- data/lib/cgi-bin/log/thermo_graph_loop.txt +0 -1
- data/lib/cgi-bin/main.cgi +0 -98
- data/lib/cgi-bin/manual_bool01.txt.cgi +0 -42
- data/lib/cgi-bin/manual_bool02.txt.cgi +0 -42
- data/lib/cgi-bin/post_change_step.cgi +0 -44
- data/lib/cgi-bin/post_house1.cgi +0 -44
- data/lib/cgi-bin/post_house2.cgi +0 -44
- data/lib/cgi-bin/post_kr01.cgi +0 -0
- data/lib/cgi-bin/post_kr01_readable.txt.cgi +0 -44
- data/lib/cgi-bin/post_kr02.cgi +0 -0
- data/lib/cgi-bin/post_kr02_readable.txt.cgi +0 -44
- data/lib/cgi-bin/post_kr1_bit.txt.cgi +0 -44
- data/lib/cgi-bin/post_kr2_bit.txt.cgi +0 -44
- data/lib/cgi-bin/post_last_bit.txt.cgi +0 -44
- data/lib/cgi-bin/post_last_thermo_data.cgi +0 -44
- data/lib/cgi-bin/post_last_thermo_time.cgi +0 -44
- data/lib/cgi-bin/post_manual_bool01.txt.cgi +0 -44
- data/lib/cgi-bin/post_manual_bool02.txt.cgi +0 -44
- data/lib/cgi-bin/post_reload_flag.cgi +0 -44
- data/lib/cgi-bin/post_run_check.cgi +0 -44
- data/lib/cgi-bin/post_thermo_define.yml.cgi +0 -44
- data/lib/cgi-bin/post_time_array.cgi +0 -44
- data/lib/cgi-bin/post_wait_time.cgi +0 -44
- data/lib/cgi-bin/post_wet0.cgi +0 -44
- data/lib/cgi-bin/post_wet0_drain.cgi +0 -44
- data/lib/cgi-bin/post_wet1.cgi +0 -44
- data/lib/cgi-bin/post_wet1_drain.cgi +0 -44
- data/lib/cgi-bin/post_wet_input.txt.cgi +0 -44
- data/lib/cgi-bin/reload_flag.cgi +0 -42
- data/lib/cgi-bin/reset_.cgi +0 -0
- data/lib/cgi-bin/run_check.cgi +0 -42
- data/lib/cgi-bin/set.cgi +0 -33
- data/lib/cgi-bin/set_post_yml_each.rb +0 -72
- data/lib/cgi-bin/set_yml_cgi_each.rb +0 -0
- data/lib/cgi-bin/setting.cgi +0 -0
- data/lib/cgi-bin/setting.cgi.1 +0 -0
- data/lib/cgi-bin/setting_io.rb +0 -53
- data/lib/cgi-bin/thermo_data_graphs.cgi +0 -0
- data/lib/cgi-bin/thermo_data_list.cgi +0 -0
- data/lib/cgi-bin/thermo_define.yml.cgi +0 -42
- data/lib/cgi-bin/thermo_graph.cgi +0 -0
- data/lib/cgi-bin/time_array.cgi +0 -42
- data/lib/cgi-bin/wait_time.cgi +0 -42
- data/lib/cgi-bin/web.rb +0 -39
- data/lib/cgi-bin/wet0.cgi +0 -42
- data/lib/cgi-bin/wet0_drain.cgi +0 -42
- data/lib/cgi-bin/wet1.cgi +0 -42
- data/lib/cgi-bin/wet1_drain.cgi +0 -42
- data/lib/cgi-bin/wet_input.txt.cgi +0 -42
- data/lib/htdocs/css/str.css +0 -89
- data/lib/htdocs/favicon.ico +0 -0
- data/lib/htdocs/thermo/thermo_data.jpg +0 -0
- data/lib/htdocs/thermo/thumb/thermo_data.jpg +0 -0
- data/test/tc_bit.rb.1 +0 -15
- data/test/tc_bit.rb.2 +0 -21
- data/test/ts_agri-controller.rb.1 +0 -8
@@ -0,0 +1,161 @@
|
|
1
|
+
#coding:utf-8
|
2
|
+
require 'rubygems'
|
3
|
+
require 'gruff'
|
4
|
+
require "date"
|
5
|
+
require "time"
|
6
|
+
require "rubygems"
|
7
|
+
require "agri-controller"
|
8
|
+
require "agri-controller/gruff"
|
9
|
+
module AgriController
|
10
|
+
#thrmo datas to jpg graph
|
11
|
+
def thermo_gruff2(output_filename="thermo_data.jpg",input_csv_data="thermo_data.csv",range=[1.0,1.0/3,1.0/100],legend=["degree","humidty(1/3)","ppm(1/100)"],view="640x480")
|
12
|
+
#data ini
|
13
|
+
data=File.read(input_csv_data)
|
14
|
+
#delete "#" comments
|
15
|
+
res=""
|
16
|
+
i=0
|
17
|
+
##
|
18
|
+
#day_data
|
19
|
+
data.each_line do |str|
|
20
|
+
i+=1
|
21
|
+
unless (str =~ /\s*#/)==0
|
22
|
+
#p str
|
23
|
+
unless str=="\n"
|
24
|
+
#p str
|
25
|
+
res+=str
|
26
|
+
end
|
27
|
+
end
|
28
|
+
end
|
29
|
+
|
30
|
+
#list delete if many
|
31
|
+
n2=view.split("x")[0].to_i
|
32
|
+
x=i/n2+2
|
33
|
+
x=1 if i<n2
|
34
|
+
data=res
|
35
|
+
thermo_data_hash={}
|
36
|
+
|
37
|
+
result=[]
|
38
|
+
range.size.times{|i| result[i]=[]}
|
39
|
+
|
40
|
+
title_day=""
|
41
|
+
line=0
|
42
|
+
title=0
|
43
|
+
label={}
|
44
|
+
hour=0
|
45
|
+
day=0
|
46
|
+
data.each_line do |str|
|
47
|
+
line+=1
|
48
|
+
if line%x==0
|
49
|
+
dat=str.chomp.split(",")
|
50
|
+
#delete if many array
|
51
|
+
while dat.size > range.size+1
|
52
|
+
dat.pop
|
53
|
+
end
|
54
|
+
#p dat[0]
|
55
|
+
begin
|
56
|
+
|
57
|
+
begin
|
58
|
+
time=Time.parse(dat[0]).localtime#DateTime
|
59
|
+
rescue
|
60
|
+
time=Time.iso8601(dat[0]).localtime#DateTime
|
61
|
+
end
|
62
|
+
#dat[0].inspect+","+time.to_s
|
63
|
+
title=title+1
|
64
|
+
rescue
|
65
|
+
line=line-1
|
66
|
+
next
|
67
|
+
end
|
68
|
+
|
69
|
+
#title_day
|
70
|
+
if title==1
|
71
|
+
title_day=time.year.to_s+"/"+time.month.to_s+"/"+time.day.to_s
|
72
|
+
end
|
73
|
+
|
74
|
+
#line if day change
|
75
|
+
time.hour
|
76
|
+
if time.day!=day #(day change)
|
77
|
+
day=time.day
|
78
|
+
label[line]=":"#time.month.to_s+"/"+day.to_s
|
79
|
+
elsif time.hour!=hour
|
80
|
+
hour=time.hour
|
81
|
+
label[title]="|"+hour.to_s
|
82
|
+
if time.hour==12
|
83
|
+
label[title]="|12"
|
84
|
+
end
|
85
|
+
else
|
86
|
+
end
|
87
|
+
p dat
|
88
|
+
dat.delete_at(0)
|
89
|
+
dat.each_index{|i|
|
90
|
+
begin
|
91
|
+
result[i] << dat[i].to_f
|
92
|
+
rescue
|
93
|
+
result[i] << 0
|
94
|
+
end
|
95
|
+
}
|
96
|
+
end
|
97
|
+
|
98
|
+
end
|
99
|
+
|
100
|
+
#p label
|
101
|
+
result.each_index{|i| result[i]=[ legend[i],result[i].map!{|x|
|
102
|
+
# x*range[i]
|
103
|
+
begin
|
104
|
+
if x > -50
|
105
|
+
x*range[i]
|
106
|
+
else
|
107
|
+
nil
|
108
|
+
end
|
109
|
+
rescue
|
110
|
+
nil
|
111
|
+
end
|
112
|
+
} ]}
|
113
|
+
|
114
|
+
# result.each_index{|i| result[i]=[ legend[i],result[i].map!{|x| x*range[i] rescue nil} ]}
|
115
|
+
#delete no_need data
|
116
|
+
legend.each_index do |i|
|
117
|
+
unless range[i]
|
118
|
+
result.delete_at(i)
|
119
|
+
#p "delete #{i}."
|
120
|
+
end
|
121
|
+
end
|
122
|
+
p result
|
123
|
+
#p result[0]
|
124
|
+
#p thermo_num
|
125
|
+
#=begin
|
126
|
+
#p label
|
127
|
+
#gruff main
|
128
|
+
g = Gruff::Line.new(view)
|
129
|
+
g.font = "/usr/share/fonts/vlgothic/VL-Gothic-Regular.ttf"
|
130
|
+
g.title="環境データ "+title_day
|
131
|
+
#g.title_font_size =24
|
132
|
+
g.theme_37signals
|
133
|
+
g.maximum_value = 40
|
134
|
+
g.minimum_value = 0
|
135
|
+
g.y_axis_increment =2
|
136
|
+
|
137
|
+
#g.baseline_value=9
|
138
|
+
#g.increment=5
|
139
|
+
#dataset
|
140
|
+
result.each do |data|
|
141
|
+
g.data(*data)
|
142
|
+
end
|
143
|
+
g.labels =label
|
144
|
+
# Default theme
|
145
|
+
#p g
|
146
|
+
g.write(output_filename)
|
147
|
+
#=end
|
148
|
+
end
|
149
|
+
end
|
150
|
+
|
151
|
+
if $0==__FILE__
|
152
|
+
#require "profile"
|
153
|
+
include AgriController
|
154
|
+
#p Dir.pwd
|
155
|
+
input_csv_data=ARGV[0] || "./cat.csv"
|
156
|
+
#if File.readable?(input_csv_data)
|
157
|
+
thermo_gruff2(output_filename="./thermo_data/thermo_data.jpg",input_csv_data, range=[1.0,nil,1.0/100],legend=["温度",nil,"CO2濃度ppm(1/100)"],view="480x480")
|
158
|
+
#thermo_gruff2(output_filename="./thermo_data/thermo_data.jpg",input_csv_data,range=[1.0,1.0/3,1.0,nil,1.0,nil,1.0,nil,1.0,nil],legend=["degree","humidty(1/3)","degree","humidty(1/3)","degree","humidty(1/3)","degree","humidty(1/3)","degree","humidty(1/3)"])
|
159
|
+
#p Time.now
|
160
|
+
#end
|
161
|
+
end
|
@@ -1,28 +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=
|
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
|
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=5)
|
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,42 @@
|
|
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=4,size1="480x420",size2="220x250",sec=120)
|
9
|
+
|
10
|
+
p "gruf_start:"+Time.now.iso8601 if verbose
|
11
|
+
|
12
|
+
p input_csv_data=dir_from+"/thermo_data.csv"#"data.tmp"
|
13
|
+
p output_filename=dir_to+"/thermo_data.jpg"
|
14
|
+
|
15
|
+
loop do
|
16
|
+
|
17
|
+
#bool=File.readable?(input_csv_data)
|
18
|
+
#p "thermo_data_readable:"+bool.inspect
|
19
|
+
#if bool
|
20
|
+
|
21
|
+
#p input_csv_data
|
22
|
+
|
23
|
+
thermo_gruff(output_filename,input_csv_data,num,size1)
|
24
|
+
thermo_gruff(dir_to+"/thumb/thermo_data.jpg",input_csv_data,num,size2)
|
25
|
+
|
26
|
+
Loger::loger(dir_from+"/thermo_graph_loop.txt",Time.now.iso8601,"w")
|
27
|
+
#end
|
28
|
+
|
29
|
+
#check 1day thermo_data and generate gruff(and small gruff) below
|
30
|
+
thermo_gruff_generate("./htdocs/thermo","./cgi-bin/log/thermo",num)
|
31
|
+
sleep sec
|
32
|
+
p "gruff_loop:"+Time.now.iso8601 if verbose
|
33
|
+
end
|
34
|
+
end
|
35
|
+
end
|
36
|
+
if $0==__FILE__
|
37
|
+
require "thermo_gruff"
|
38
|
+
require "thermo_gruff_generate"
|
39
|
+
include AgriController
|
40
|
+
|
41
|
+
thermo_gruff_loop
|
42
|
+
end
|
@@ -1,51 +1,91 @@
|
|
1
|
-
|
2
|
-
|
3
|
-
|
4
|
-
|
5
|
-
|
6
|
-
|
7
|
-
|
8
|
-
|
9
|
-
|
10
|
-
|
11
|
-
begin
|
12
|
-
x=open(log_file,mode) do |io|
|
13
|
-
io.puts data
|
14
|
-
end
|
15
|
-
|
16
|
-
#rename log_file if size too big
|
17
|
-
if File.size?(log_file)>=file_size
|
18
|
-
i=1
|
19
|
-
bool=true
|
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
|
-
|
1
|
+
require "logger"
|
2
|
+
#!ruby -Ku
|
3
|
+
#coding:utf-8
|
4
|
+
module AgriController
|
5
|
+
module Loger
|
6
|
+
module_function
|
7
|
+
def loger(log_file,data,mode="a",file_size=50000,log_dir2="./cgi-bin/log/old_log")
|
8
|
+
#add data to log_file
|
9
|
+
logger=Logger.new(log_file,'daily')
|
10
|
+
logger.formatter=proc{|severity,datetime,progname,msg| "#{msg}\n"}
|
11
|
+
begin
|
12
|
+
# x=open(log_file,mode) do |io|
|
13
|
+
# io.puts data
|
14
|
+
# end
|
15
|
+
logger.info(data)
|
16
|
+
#rename log_file if size too big
|
17
|
+
# if File.size?(log_file)>=file_size
|
18
|
+
# i=1
|
19
|
+
# bool=true
|
20
|
+
rescue => ex
|
21
|
+
str=ex.inspect
|
22
|
+
str2=$@.inspect
|
23
|
+
p "loger:error,#{str}"
|
24
|
+
#open(log_dir2+"/log_error.txt","a"){|io|
|
25
|
+
logger.error(Time.now.to_s+"|"+
|
26
|
+
log_file.to_s+"|"+
|
27
|
+
data.to_s+"|"+
|
28
|
+
mode.to_s+"|"+
|
29
|
+
file_size.to_s+"|"+
|
30
|
+
str+str2+"\n"
|
31
|
+
)
|
32
|
+
#}
|
33
|
+
false
|
34
|
+
return
|
35
|
+
end
|
36
|
+
nil
|
37
|
+
end
|
38
|
+
# alias logger loger
|
39
|
+
end
|
40
|
+
end
|
41
|
+
=begin
|
42
|
+
module AgriController
|
43
|
+
module Loger
|
44
|
+
module_function
|
45
|
+
def loger(log_file,data,mode="a",file_size=50000,log_dir2="./cgi-bin/log/old_log")
|
46
|
+
#add data to log_file
|
47
|
+
old_log_dir="/old_log"
|
48
|
+
dir = File.dirname(log_file)+old_log_dir
|
49
|
+
Dir.mkdir(dir) unless File.exist?(dir)
|
50
|
+
begin
|
51
|
+
x=open(log_file,mode) do |io|
|
52
|
+
io.puts data
|
53
|
+
end
|
54
|
+
|
55
|
+
#rename log_file if size too big
|
56
|
+
if File.size?(log_file)>=file_size
|
57
|
+
i=1
|
58
|
+
bool=true
|
59
|
+
while bool
|
60
|
+
dir=File.dirname(log_file)
|
61
|
+
name=File.basename(log_file,".*")
|
62
|
+
ext=File.extname(log_file)
|
63
|
+
new_name=dir+old_log_dir+"/"+name+i.to_s+ext
|
64
|
+
unless File.exist?(new_name)
|
65
|
+
File.rename(log_file,new_name)
|
66
|
+
bool=false
|
67
|
+
end
|
68
|
+
i+=1
|
69
|
+
end
|
70
|
+
end
|
71
|
+
rescue => ex
|
72
|
+
str=ex.inspect
|
73
|
+
str2=$@.inspect
|
74
|
+
p "loger:error,#{str}"
|
75
|
+
open(log_dir2+"/log_error.txt","a"){|io|
|
76
|
+
io.print Time.now.to_s+"|"
|
77
|
+
io.print log_file.to_s+"|"
|
78
|
+
io.print data.to_s+"|"
|
79
|
+
io.print mode.to_s+"|"
|
80
|
+
io.print file_size.to_s+"|"
|
81
|
+
io.print str+str2+"\n"
|
82
|
+
}
|
83
|
+
false
|
84
|
+
return
|
85
|
+
end
|
86
|
+
nil
|
87
|
+
end
|
88
|
+
# alias logger loger
|
89
|
+
end
|
90
|
+
end
|
91
|
+
=end
|
data/lib/agri-controller/main.rb
CHANGED
Binary file
|
@@ -0,0 +1,282 @@
|
|
1
|
+
#!ruby
|
2
|
+
#coding:utf-8
|
3
|
+
#$KCODE="u" if RUBY_VERSION < "1.9.0"
|
4
|
+
require "thread"
|
5
|
+
module AgriController
|
6
|
+
module_function
|
7
|
+
def thermo_read(ref="http://maru.selfip.com/cgi-bin/thermo.rb")
|
8
|
+
begin
|
9
|
+
uri=URI(ref)
|
10
|
+
dat=uri.read("Accept-Language" => "ja")
|
11
|
+
rescue
|
12
|
+
nil
|
13
|
+
end
|
14
|
+
end
|
15
|
+
|
16
|
+
#main_for_proto_house
|
17
|
+
def main_linux(log="./cgi-bin/log",config="./cgi-bin/config",docs="./htdocs/thermo",dacs_port="/dev/ttyUSB0")
|
18
|
+
log_time=Time.now
|
19
|
+
Thread.abort_on_exception=true
|
20
|
+
#dacs port
|
21
|
+
dacs_port="/dev/ttyUSB1"
|
22
|
+
|
23
|
+
#WR1010
|
24
|
+
#thermo_thread starts
|
25
|
+
yaml_file="last_thermo_data"
|
26
|
+
wr_port="/dev/ttyUSB0"
|
27
|
+
thermo_port=wr_port#8#6
|
28
|
+
thermo_N=4
|
29
|
+
|
30
|
+
th="thermo_define.yml"
|
31
|
+
yaml_db(th,[thermo_port,thermo_N],config+"/"+th)
|
32
|
+
|
33
|
+
#thermo_loop_thread(yaml_file,thermo_port,thermo_N,sec=30)
|
34
|
+
thermo_loop_thread(yaml_file,thermo_port,thermo_N,sec=30,"./cgi-bin/config")
|
35
|
+
|
36
|
+
#thermo_logger_thread starts
|
37
|
+
thermo_data_logger_thread(thermo_N,"./cgi-bin/config","./cgi-bin/log")
|
38
|
+
|
39
|
+
#reset manual bool
|
40
|
+
yaml_db("manual_bool01.txt",nil,config+"/manual_bool01.txt")
|
41
|
+
yaml_db("manual_bool02.txt",nil,config+"/manual_bool02.txt")
|
42
|
+
sleep 0.1
|
43
|
+
|
44
|
+
loop do
|
45
|
+
catch :reset_signal do
|
46
|
+
sleep 0.2
|
47
|
+
##
|
48
|
+
#Initialize basic DATA
|
49
|
+
manual_config =Bit.new(0)#15 & 9 => 9 (AND)
|
50
|
+
manual_bit=Bit.new(0)#15 | 9 => 15 (OR)
|
51
|
+
|
52
|
+
dacs=Serial.new("W0000000\r",dacs_port)
|
53
|
+
dacs.time_out=2
|
54
|
+
dacs.set
|
55
|
+
res=dacs.serial
|
56
|
+
unless res
|
57
|
+
res=dacs.serial
|
58
|
+
end
|
59
|
+
res_i=Dacs::toi(res)
|
60
|
+
|
61
|
+
wr=Serial.new(WR1010::send_sample,wr_port,9600,5)
|
62
|
+
wr.set
|
63
|
+
#thermo=toa(wr.serial)
|
64
|
+
#THERMO port
|
65
|
+
#wr1010 thrmo request
|
66
|
+
thermo=yaml_dbr("last_thermo_data",config+"/last_thermo_data")#WR1010::list(thermo_port,thermo_N)
|
67
|
+
|
68
|
+
#BIT SETTING
|
69
|
+
|
70
|
+
dacs_bit=Bit.new
|
71
|
+
in_bits=Bit.new(res_i) ##import signal(dacs)
|
72
|
+
change1=false
|
73
|
+
p house1_set=yaml_dbr("house1",config+"/house1")
|
74
|
+
house2_set=yaml_dbr("house2",config+"/house2")
|
75
|
+
house1=N_dan_thermo.new(house1_set,diff=1,1)
|
76
|
+
house2=N_dan_thermo.new(house2_set,diff=1,1)
|
77
|
+
|
78
|
+
a=Value_controller.new(steps=4,open_sec=5,#55
|
79
|
+
down_sec=3,#35,
|
80
|
+
sensitivity=2,set_value=20,dead_time=15)
|
81
|
+
p "house1 Starts at #{(a.up_sec*a.steps).to_s} sec later."
|
82
|
+
|
83
|
+
b=Value_controller.new(steps=4,open_sec=5,#55
|
84
|
+
down_sec=3,#35,
|
85
|
+
sensitivity=2,set_value=20,dead_time=15)
|
86
|
+
#p "house2 Starts at #{b.reset_time.to_s}(#{(b.up_sec*b.steps).to_s} sec later)."
|
87
|
+
|
88
|
+
#wet_sensor SETTING
|
89
|
+
line1=Wet_sensor.new
|
90
|
+
|
91
|
+
#illigate Time DEFINE[[10,7,6,3],["17:42"],["17:43"],["18:00"]]
|
92
|
+
time_array3=yaml_dbr("time_array",config+"/time_array")
|
93
|
+
puts "watering set:#{time_array3.inspect}"
|
94
|
+
wait_time=yaml_dbr("wait_time",config+"/wait_time")
|
95
|
+
|
96
|
+
#start
|
97
|
+
start=Time.now
|
98
|
+
|
99
|
+
#start time logging
|
100
|
+
dat="Start,"+Time.now.iso8601
|
101
|
+
Loger::loger(config+"/last_bit.txt",dat+"<br/>","w")#Start,#{Time.now}<br/>
|
102
|
+
Loger::loger(log+"/log.txt",dat)
|
103
|
+
|
104
|
+
#value_controller step change initialize
|
105
|
+
change_step=[false,false]
|
106
|
+
|
107
|
+
##
|
108
|
+
#MAIN LOOP (break if in_bit(22)==off)
|
109
|
+
run_save_flag=nil
|
110
|
+
|
111
|
+
loop do
|
112
|
+
t=Time.now
|
113
|
+
time=t.iso8601
|
114
|
+
if t.min!=run_save_flag
|
115
|
+
run_save_flag=t.min
|
116
|
+
#save_run_check_time
|
117
|
+
begin
|
118
|
+
yaml_db("run_check",t,config+"/run_check")
|
119
|
+
#retry if error.
|
120
|
+
rescue
|
121
|
+
sleep 0.1
|
122
|
+
yaml_db("run_check",t,config+"/run_check")
|
123
|
+
end
|
124
|
+
end
|
125
|
+
if yaml_dbr("reload_flag",config+"/reload_flag")==true
|
126
|
+
yaml_db("reload_flag",false,config+"/reload_flag")
|
127
|
+
p dat="reload signal:"
|
128
|
+
Loger::loger(log+"/log.txt",dat)
|
129
|
+
|
130
|
+
sleep 0.1
|
131
|
+
throw :reset_signal
|
132
|
+
end
|
133
|
+
|
134
|
+
#thermo DEFINE
|
135
|
+
thermo=nil
|
136
|
+
thermo=yaml_dbr("last_thermo_data",config+"/last_thermo_data")
|
137
|
+
#last_thermo_time
|
138
|
+
|
139
|
+
#illigate Timer
|
140
|
+
x=multiple_pulse_timer(time_array3,wait_time)
|
141
|
+
#p x
|
142
|
+
#x.bit =>Integer
|
143
|
+
|
144
|
+
#wet sensor work
|
145
|
+
|
146
|
+
#illigating check
|
147
|
+
dacs_bit.boolbit(x.on?(2),0)#signal switch
|
148
|
+
|
149
|
+
dacs_bit.boolbit(x.on?(0),1)#illigate line1
|
150
|
+
|
151
|
+
dacs_bit.boolbit(x.on?(2),2)#illigate line2 ##
|
152
|
+
dacs_bit.boolbit(x.on?(4),3)#illigate line3
|
153
|
+
|
154
|
+
dacs_bit.boolbit(x.on?(6),4)#illigate line4 ##
|
155
|
+
|
156
|
+
pomp = (x.on?(0)) | (x.on?(2)) | x.on?(4) | x.on?(6)#x.on?(0) | x.on?(2)
|
157
|
+
dacs_bit.boolbit(pomp,5)#pomp signal
|
158
|
+
|
159
|
+
|
160
|
+
#motor bit
|
161
|
+
step_str=""
|
162
|
+
if thermo.class==Array && thermo.size==thermo_N
|
163
|
+
|
164
|
+
#set_temp from N_dan_thermo
|
165
|
+
a.set_value=house1.set_now
|
166
|
+
b.set_value=house2.set_now
|
167
|
+
|
168
|
+
##
|
169
|
+
#Controll
|
170
|
+
bit1=a.value_controll(thermo[0][0]) if thermo[0][0] != nil
|
171
|
+
bit2=!a.switch
|
172
|
+
bit3=b.value_controll(thermo[1][0]) if thermo[1][0] != nil
|
173
|
+
bit4=!b.switch
|
174
|
+
check_step=[a.now_step,b.now_step]
|
175
|
+
|
176
|
+
if check_step != change_step
|
177
|
+
string=[a.set_value,b.set_value].inspect#+check_step.inspect
|
178
|
+
#p [bit1,bit2,bit3,bit4]
|
179
|
+
#p thermo
|
180
|
+
|
181
|
+
step_str=",step:"+a.now_step.to_s+","+"step:"+b.now_step.to_s+","+string
|
182
|
+
yaml_db("change_step",check_step,config+"/change_step")
|
183
|
+
|
184
|
+
change_step=check_step.dup
|
185
|
+
end
|
186
|
+
else
|
187
|
+
#2010.4.28 changed
|
188
|
+
|
189
|
+
##
|
190
|
+
#commonly open if thrmo error.
|
191
|
+
#house1
|
192
|
+
bit1=true #open signal
|
193
|
+
bit2=false#motor_off_trap
|
194
|
+
|
195
|
+
##
|
196
|
+
#commonly open if thrmo error.
|
197
|
+
#house2
|
198
|
+
bit3=true #open signal
|
199
|
+
bit4=false#motor_off_trap
|
200
|
+
|
201
|
+
#dat=Time.now.to_s+":thermo_error!! open full time."+thermo.inspect
|
202
|
+
end
|
203
|
+
#house1 motor
|
204
|
+
dacs_bit.boolbit(bit1,19)
|
205
|
+
dacs_bit.boolbit(bit2,20)
|
206
|
+
#house2 motor
|
207
|
+
dacs_bit.boolbit(bit3,21)
|
208
|
+
dacs_bit.boolbit(bit4,22)
|
209
|
+
|
210
|
+
##
|
211
|
+
#RESULT BIT OUTPUT IF CHANGED
|
212
|
+
#sum bits and check changes
|
213
|
+
#dacs_bit auto
|
214
|
+
#p change1
|
215
|
+
|
216
|
+
#p config+"/manual_bool01.txt"
|
217
|
+
#p yaml_dbr("manual_bool01.txt",config+"/manual_bool01.txt")
|
218
|
+
if yaml_dbr("manual_bool01.txt",config+"/manual_bool01.txt")==nil
|
219
|
+
|
220
|
+
(0..23).each do |x|
|
221
|
+
dacs_bit.bool_bit(manual_bit.on?,x) if manual_config.on?(x)
|
222
|
+
end
|
223
|
+
|
224
|
+
if change1 != dacs_bit.bit
|
225
|
+
change1=dacs_bit.bit
|
226
|
+
#p time
|
227
|
+
str=dacs_bit.tos(24,2)
|
228
|
+
if thermo!=nil
|
229
|
+
p data=str+","+time+","+
|
230
|
+
thermo[0][0].to_s+","+thermo[0][1].to_s+","+thermo[1][0].to_s+","+thermo[2][0].to_s
|
231
|
+
else
|
232
|
+
p data=str+" "+time
|
233
|
+
end
|
234
|
+
#logging thread
|
235
|
+
#Thread.start(data){|dat|
|
236
|
+
|
237
|
+
Loger::loger(config+"/last_bit.txt",data+"<br/>","w")
|
238
|
+
Loger::loger(log+"/log.txt",data)
|
239
|
+
#}
|
240
|
+
#str=bits.tos(24,2)
|
241
|
+
#str_size=str.size
|
242
|
+
|
243
|
+
##
|
244
|
+
#command output
|
245
|
+
hex0=str
|
246
|
+
hex=Bit.new(hex0.to_i(2)).tos(6,16)
|
247
|
+
|
248
|
+
command="W0"+hex+"\r"
|
249
|
+
dacs.command = (command)
|
250
|
+
|
251
|
+
res=nil
|
252
|
+
xx=0
|
253
|
+
10.times do
|
254
|
+
res=dacs.serial
|
255
|
+
break if res
|
256
|
+
if xx==9
|
257
|
+
raise "main_linux.rb __Dacs Fatal error__"
|
258
|
+
end
|
259
|
+
xx+=1
|
260
|
+
end
|
261
|
+
#p res
|
262
|
+
end
|
263
|
+
end
|
264
|
+
if log_time.hour != t.hour
|
265
|
+
log_time=t.dup
|
266
|
+
p "watchdog:"+time
|
267
|
+
end
|
268
|
+
|
269
|
+
sleep 0.8
|
270
|
+
#p Time.now-t
|
271
|
+
|
272
|
+
#p Thread.list
|
273
|
+
#raise
|
274
|
+
end #main_loop
|
275
|
+
end #catch reset_signal
|
276
|
+
|
277
|
+
end #reset_loop
|
278
|
+
#q.push nil
|
279
|
+
#queue.join
|
280
|
+
end
|
281
|
+
end
|
282
|
+
#AgriController::main_new
|