agri-controller 0.0.0 → 0.0.8

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (182) hide show
  1. checksums.yaml +7 -0
  2. data/ChangeLog.txt +36 -0
  3. data/LICENSE.txt +15 -0
  4. data/agri-controller.gemspec +36 -0
  5. data/gpl-2.0.txt +339 -0
  6. data/lib/agri-controller.rb +11 -33
  7. data/lib/agri-controller/bcc.rb +86 -53
  8. data/lib/agri-controller/bit.rb +158 -143
  9. data/lib/agri-controller/device.rb +7 -0
  10. data/lib/agri-controller/device/dacs.rb +148 -0
  11. data/lib/agri-controller/device/kr.rb +23 -0
  12. data/lib/agri-controller/device/ma.rb +92 -0
  13. data/lib/agri-controller/device/mch383.rb +178 -0
  14. data/lib/agri-controller/device/tr.rb +230 -0
  15. data/lib/agri-controller/device/wr1010.rb +314 -0
  16. data/lib/agri-controller/dt.rb +17 -0
  17. data/lib/agri-controller/error_caption.rb +67 -46
  18. data/lib/agri-controller/gruff.rb +7 -0
  19. data/lib/agri-controller/gruff/base.rb +88 -0
  20. data/lib/agri-controller/gruff/chdata.rb +64 -0
  21. data/lib/agri-controller/gruff/join_csv.rb +62 -0
  22. data/lib/agri-controller/gruff/rename_csv.rb +50 -0
  23. data/lib/agri-controller/{thermo_data_each_day.rb → gruff/thermo_data_each_day.rb} +67 -67
  24. data/lib/agri-controller/{thermo_gruff.rb → gruff/thermo_gruff.rb} +112 -109
  25. data/lib/agri-controller/gruff/thermo_gruff2.rb +161 -0
  26. data/lib/agri-controller/{thermo_gruff_generate.rb → gruff/thermo_gruff_generate.rb} +28 -28
  27. data/lib/agri-controller/gruff/thermo_gruff_loop.rb +42 -0
  28. data/lib/agri-controller/loger.rb +91 -51
  29. data/lib/agri-controller/main.rb +0 -0
  30. data/lib/agri-controller/main_linux.rb +282 -0
  31. data/lib/agri-controller/main_new.rb +401 -401
  32. data/lib/agri-controller/multiple_pulse_timer.rb +190 -169
  33. data/lib/agri-controller/n_dan_thermo.rb +156 -154
  34. data/lib/agri-controller/save_threads.rb +181 -172
  35. data/lib/agri-controller/setting_io.rb +53 -53
  36. data/lib/agri-controller/ttyUSB_watchdog.rb +43 -0
  37. data/lib/agri-controller/value_controller.rb +209 -167
  38. data/lib/agri-controller/version.rb +7 -5
  39. data/lib/agri-controller/web.rb +39 -39
  40. data/lib/agri-controller/webrick_test.rb +51 -46
  41. data/lib/agri-controller/wet_sensor.rb +92 -0
  42. data/test/tc_bit.rb +14 -3
  43. data/test/tc_trigger.rb +27 -0
  44. data/test/ts_agri-controller.rb +10 -10
  45. metadata +62 -202
  46. data/bin/main.bat +0 -2
  47. data/bin/main.bat /202/326/202/314/203V/203/207/201[/203g/203J/203b/203g.lnk +0 -0
  48. data/bin/main.rb +0 -23
  49. data/bin/memo.txt +0 -4
  50. data/bin/server.bat +0 -1
  51. data/bin/server.bat /202/326/202/314/203V/203/207/201[/203g/203J/203b/203g.lnk +0 -0
  52. data/bin/server.rb +0 -4
  53. data/bin/set_config.rb +0 -47
  54. data/bin/usual.rb +0 -3
  55. data/bin//203R/203}/203/223/203h /203v/203/215/203/223/203v/203g.lnk +0 -0
  56. data/lib/agri-controller/dacs.rb +0 -114
  57. data/lib/agri-controller/dircopy.rb +0 -30
  58. data/lib/agri-controller/kr.rb +0 -34
  59. data/lib/agri-controller/kr_2.rb +0 -78
  60. data/lib/agri-controller/serial.rb +0 -114
  61. data/lib/agri-controller/thermo_gruff_loop.rb +0 -35
  62. data/lib/agri-controller/wetsensor.rb +0 -119
  63. data/lib/agri-controller/wr1010.rb +0 -316
  64. data/lib/agri-controller/wr1010_2.rb +0 -0
  65. data/lib/cgi-bin/auto01.cgi +0 -0
  66. data/lib/cgi-bin/auto02.cgi +0 -0
  67. data/lib/cgi-bin/change_step.cgi +0 -42
  68. data/lib/cgi-bin/config/change_step +0 -4
  69. data/lib/cgi-bin/config/house1 +0 -20
  70. data/lib/cgi-bin/config/house2 +0 -8
  71. data/lib/cgi-bin/config/kr01_readable.txt +0 -2
  72. data/lib/cgi-bin/config/kr02_readable.txt +0 -2
  73. data/lib/cgi-bin/config/kr1_bit.txt +0 -2
  74. data/lib/cgi-bin/config/kr2_bit.txt +0 -2
  75. data/lib/cgi-bin/config/last_bit.txt +0 -1
  76. data/lib/cgi-bin/config/last_thermo_data +0 -22
  77. data/lib/cgi-bin/config/last_thermo_time +0 -2
  78. data/lib/cgi-bin/config/manual_bool01.txt +0 -2
  79. data/lib/cgi-bin/config/manual_bool02.txt +0 -2
  80. data/lib/cgi-bin/config/reload_flag +0 -2
  81. data/lib/cgi-bin/config/run_check +0 -2
  82. data/lib/cgi-bin/config/thermo_define.yml +0 -4
  83. data/lib/cgi-bin/config/time_array +0 -10
  84. data/lib/cgi-bin/config/wait_time +0 -2
  85. data/lib/cgi-bin/config/wet0 +0 -3
  86. data/lib/cgi-bin/config/wet0_drain +0 -2
  87. data/lib/cgi-bin/config/wet1 +0 -3
  88. data/lib/cgi-bin/config/wet1_drain +0 -2
  89. data/lib/cgi-bin/config/wet_input.txt +0 -1
  90. data/lib/cgi-bin/curtain_h1.cgi +0 -43
  91. data/lib/cgi-bin/curtain_h1_setting.cgi +0 -43
  92. data/lib/cgi-bin/curtain_h2.cgi +0 -43
  93. data/lib/cgi-bin/curtain_h2_setting.cgi +0 -43
  94. data/lib/cgi-bin/dacs_port.cgi +0 -43
  95. data/lib/cgi-bin/delay_time_0.cgi +0 -43
  96. data/lib/cgi-bin/delay_time_1.cgi +0 -43
  97. data/lib/cgi-bin/error_clear.cgi +0 -0
  98. data/lib/cgi-bin/house1.cgi +0 -42
  99. data/lib/cgi-bin/house1a.cgi +0 -43
  100. data/lib/cgi-bin/house2.cgi +0 -42
  101. data/lib/cgi-bin/house2b.cgi +0 -43
  102. data/lib/cgi-bin/house_n_dan_thermo1.cgi +0 -43
  103. data/lib/cgi-bin/house_n_dan_thermo2.cgi +0 -0
  104. data/lib/cgi-bin/keitai.cgi +0 -25
  105. data/lib/cgi-bin/kr01.cgi +0 -0
  106. data/lib/cgi-bin/kr01_readable.txt.cgi +0 -42
  107. data/lib/cgi-bin/kr02.cgi +0 -0
  108. data/lib/cgi-bin/kr02_readable.txt.cgi +0 -42
  109. data/lib/cgi-bin/kr1_bit.txt.cgi +0 -42
  110. data/lib/cgi-bin/kr2_bit.txt.cgi +0 -42
  111. data/lib/cgi-bin/kr_log.cgi +0 -18
  112. data/lib/cgi-bin/last_bit.txt.cgi +0 -42
  113. data/lib/cgi-bin/last_thermo_data.cgi +0 -42
  114. data/lib/cgi-bin/last_thermo_time.cgi +0 -42
  115. data/lib/cgi-bin/log.cgi +0 -19
  116. data/lib/cgi-bin/log/errors.txt +0 -1
  117. data/lib/cgi-bin/log/errors_.txt +0 -93
  118. data/lib/cgi-bin/log/kr_command_log.txt +0 -240
  119. data/lib/cgi-bin/log/log.txt +0 -441
  120. data/lib/cgi-bin/log/old_log/log_.txt +0 -15
  121. data/lib/cgi-bin/log/thermo/2010-05-22_thermo.csv +0 -1438
  122. data/lib/cgi-bin/log/thermo/2010-06-12_thermo.csv +0 -3
  123. data/lib/cgi-bin/log/thermo/2010-06-13_thermo.csv +0 -2
  124. data/lib/cgi-bin/log/thermo/2010-06-16_thermo.csv +0 -85
  125. data/lib/cgi-bin/log/thermo/2010-06-17_thermo.csv +0 -285
  126. data/lib/cgi-bin/log/thermo_data.csv +0 -643
  127. data/lib/cgi-bin/log/thermo_graph_loop.txt +0 -1
  128. data/lib/cgi-bin/main.cgi +0 -98
  129. data/lib/cgi-bin/manual_bool01.txt.cgi +0 -42
  130. data/lib/cgi-bin/manual_bool02.txt.cgi +0 -42
  131. data/lib/cgi-bin/post_change_step.cgi +0 -44
  132. data/lib/cgi-bin/post_house1.cgi +0 -44
  133. data/lib/cgi-bin/post_house2.cgi +0 -44
  134. data/lib/cgi-bin/post_kr01.cgi +0 -0
  135. data/lib/cgi-bin/post_kr01_readable.txt.cgi +0 -44
  136. data/lib/cgi-bin/post_kr02.cgi +0 -0
  137. data/lib/cgi-bin/post_kr02_readable.txt.cgi +0 -44
  138. data/lib/cgi-bin/post_kr1_bit.txt.cgi +0 -44
  139. data/lib/cgi-bin/post_kr2_bit.txt.cgi +0 -44
  140. data/lib/cgi-bin/post_last_bit.txt.cgi +0 -44
  141. data/lib/cgi-bin/post_last_thermo_data.cgi +0 -44
  142. data/lib/cgi-bin/post_last_thermo_time.cgi +0 -44
  143. data/lib/cgi-bin/post_manual_bool01.txt.cgi +0 -44
  144. data/lib/cgi-bin/post_manual_bool02.txt.cgi +0 -44
  145. data/lib/cgi-bin/post_reload_flag.cgi +0 -44
  146. data/lib/cgi-bin/post_run_check.cgi +0 -44
  147. data/lib/cgi-bin/post_thermo_define.yml.cgi +0 -44
  148. data/lib/cgi-bin/post_time_array.cgi +0 -44
  149. data/lib/cgi-bin/post_wait_time.cgi +0 -44
  150. data/lib/cgi-bin/post_wet0.cgi +0 -44
  151. data/lib/cgi-bin/post_wet0_drain.cgi +0 -44
  152. data/lib/cgi-bin/post_wet1.cgi +0 -44
  153. data/lib/cgi-bin/post_wet1_drain.cgi +0 -44
  154. data/lib/cgi-bin/post_wet_input.txt.cgi +0 -44
  155. data/lib/cgi-bin/reload_flag.cgi +0 -42
  156. data/lib/cgi-bin/reset_.cgi +0 -0
  157. data/lib/cgi-bin/run_check.cgi +0 -42
  158. data/lib/cgi-bin/set.cgi +0 -33
  159. data/lib/cgi-bin/set_post_yml_each.rb +0 -72
  160. data/lib/cgi-bin/set_yml_cgi_each.rb +0 -0
  161. data/lib/cgi-bin/setting.cgi +0 -0
  162. data/lib/cgi-bin/setting.cgi.1 +0 -0
  163. data/lib/cgi-bin/setting_io.rb +0 -53
  164. data/lib/cgi-bin/thermo_data_graphs.cgi +0 -0
  165. data/lib/cgi-bin/thermo_data_list.cgi +0 -0
  166. data/lib/cgi-bin/thermo_define.yml.cgi +0 -42
  167. data/lib/cgi-bin/thermo_graph.cgi +0 -0
  168. data/lib/cgi-bin/time_array.cgi +0 -42
  169. data/lib/cgi-bin/wait_time.cgi +0 -42
  170. data/lib/cgi-bin/web.rb +0 -39
  171. data/lib/cgi-bin/wet0.cgi +0 -42
  172. data/lib/cgi-bin/wet0_drain.cgi +0 -42
  173. data/lib/cgi-bin/wet1.cgi +0 -42
  174. data/lib/cgi-bin/wet1_drain.cgi +0 -42
  175. data/lib/cgi-bin/wet_input.txt.cgi +0 -42
  176. data/lib/htdocs/css/str.css +0 -89
  177. data/lib/htdocs/favicon.ico +0 -0
  178. data/lib/htdocs/thermo/thermo_data.jpg +0 -0
  179. data/lib/htdocs/thermo/thumb/thermo_data.jpg +0 -0
  180. data/test/tc_bit.rb.1 +0 -15
  181. data/test/tc_bit.rb.2 +0 -21
  182. data/test/ts_agri-controller.rb.1 +0 -8
@@ -0,0 +1,314 @@
1
+ module AgriController
2
+ ##
3
+ #module WR1010
4
+ # before using,you must check COM_port of WR1010,and set same config.
5
+ #WINDOWS
6
+ # How to use
7
+ # require "agri"
8
+ # include Agri
9
+ #
10
+ ##########################################################################
11
+ #
12
+ # Communicate with WR1010(is RS232c Wireless Thermo Recorder,Panasonic.) responce below
13
+ #
14
+ # WR::help # => Usage string
15
+ #
16
+ # WR::send_sample(3) # => "%01#RDD0000000011**r" #command_sample
17
+ #
18
+ # res=WR::sample # => "%01$RD0C0129002E000f051301FFFF1E0007040E01FFFF030006023201FFFF020001001A\r" #response sample
19
+ #
20
+ # WR::toa(res)#=>[[25.9, 36, 36, "10100001000", 5],
21
+ # [26.7, false, 21, "10100001000", 5],
22
+ # [26.1, false, 3, "10100001000", 5],
23
+ # [26.1, false, 51, "10100001000", 5]
24
+ # ]
25
+ # DATA meaning:
26
+ # [temperature(celsius degrees), humidity(%RH) if defined , past_sec , conditon Flags , Messages and Radio strength]
27
+ #
28
+ module WR1010
29
+ module_function
30
+ ##
31
+ #returns address number of child thermos(5 chars)
32
+ #child_thermo(1)# =>"00003"
33
+ #child_thermo(4)# =>"00015"
34
+ #child_thermo(56)# =>"00223"
35
+ def child_thermo(n)
36
+ if n==0
37
+ y="00000"
38
+ else
39
+ x=n*4-1
40
+ y=x.to_s
41
+ (5-y.size).times{y="0"+y}
42
+ end
43
+ return y
44
+ end
45
+ #thermo_data(recieve_value)# =>["0ff0fffff500ffff","1f00ffffff000000"](ex.)
46
+ def thermo_data(recieve_value)#ex# =>["0ff0fffff500ffff","1f00ffffff000000"]
47
+ begin
48
+ if recieve_value
49
+ str=recieve_value[6..(-4)]
50
+ size=str.size
51
+ if (size)%16 ==0
52
+ array=[]
53
+ (size/16).times do |i|
54
+ array[i]=str.slice!(0..15)
55
+ end
56
+ array
57
+ else
58
+ nil
59
+ end
60
+ else
61
+ nil
62
+ end
63
+ rescue
64
+ return nil
65
+ end
66
+ end
67
+
68
+ def thrmo_array(str)
69
+ begin
70
+ result=[]
71
+ str.each do |data|
72
+ #p data ;p data.size
73
+ result_1=[]
74
+ (data.size/4).times do |i|
75
+ result_1 << data.slice((i*4),4)
76
+ end
77
+ result << anaryze(result_1)
78
+ end
79
+ return result
80
+ rescue
81
+ return nil
82
+ end
83
+ end
84
+
85
+ def anaryze(data)#["0201", "2C00", "2400", "0805"]
86
+ result=[]
87
+ #result[0]
88
+ x=thermo_hex_to_i(data[0])
89
+ result << judge(x).to_f/10
90
+ #result[1]
91
+ x2 = thermo_hex_to_i(data[1])
92
+ if x2==65535
93
+ result << false
94
+ elsif x2<=32766
95
+ if x2<=100
96
+ result << x2
97
+ elsif
98
+ result << 100
99
+ end
100
+ else
101
+ #p thermo_hex_to_i(data[1])
102
+ result << false
103
+ end
104
+ #result[2]
105
+ result << thermo_hex_to_i(data[2])
106
+ #result[3]
107
+ result << thermo_hex_to_i(data[3]).to_s(2)
108
+ result
109
+ end
110
+
111
+ def errors(bit_str)#"10100001000"
112
+ error_list=[]
113
+ #if bit_str
114
+ #p bit_str
115
+ bit=Bit.new(Integer("0b"+bit_str))
116
+ #p bit.bit
117
+ if bit.on?(0)
118
+ error_list << "bit0:causion:battery. "
119
+ end
120
+
121
+ if bit.on?(1)
122
+ error_list << "bit1:Error:sensor cable. "
123
+ end
124
+ if bit.on?(2)
125
+ error_list << "bit2:causion:Temp is too High or Low. "
126
+ end
127
+ if bit.off?(3)
128
+
129
+ error_list << "bit3:Error:FATAL ERROR.child thermo Non-defined. "
130
+ end
131
+
132
+ #if bit.on?(4)
133
+ # error_list << "R-on "#"Reray-unit On. "
134
+ #end
135
+
136
+ #p error_list
137
+
138
+ #radio power
139
+ size=bit_str.size*-1
140
+ #p bit_str
141
+ #p bit_str.slice((size..-9))
142
+ begin
143
+ radio_power=Integer("0b"+bit_str.slice((size..-9)))
144
+ rescue#if battery empty bit_str="00FFFF0000"
145
+ radio_power=0
146
+ end
147
+
148
+ if error_list==[]
149
+ begin
150
+
151
+ return radio_power
152
+ rescue
153
+ return nil
154
+ end
155
+ end
156
+ #else
157
+ # nil
158
+ #end
159
+ error_list << radio_power
160
+ end
161
+
162
+ #+-tempereture judge function
163
+ def judge(x)
164
+ begin
165
+ bit=Bit.new(x)
166
+ unless bit.on?(15)
167
+ return x
168
+ else
169
+ res= x-65535
170
+
171
+ #under -100 'c (degrees Celsius)
172
+ #thermo must be error 35536 => "1000101011010000" => -2999.9
173
+ unless res< -1000
174
+ return res
175
+ else
176
+ return nil
177
+ end
178
+ end
179
+ rescue
180
+ nil
181
+ end
182
+ end
183
+
184
+ def thermo_hex_to_i(data)
185
+ #hex="f100" # =>241
186
+ x=data.slice(0..1)
187
+ y=data.slice(2..3)
188
+ result=((y+x).to_i(16))
189
+ end
190
+
191
+ def toa(recieve_value)
192
+ result=[]
193
+ #begin
194
+ if recieve_value
195
+ ret=thermo_data(recieve_value)
196
+ if ret
197
+ x=thrmo_array(ret)
198
+ if x
199
+ x.each do |data|
200
+ ret=errors(data[3])
201
+ data << ret#"10100001000"
202
+ result << data
203
+ end
204
+ return result
205
+ end
206
+ end
207
+ end
208
+ #rescue
209
+ nil
210
+ #end
211
+ end
212
+
213
+ def parse(recieve_value)
214
+ toa(recieve_value)
215
+ end
216
+
217
+ def help
218
+ '##
219
+ # ++module WR1010
220
+ # +Communicate with WR1010(is RS232c Wireless Thermo Recorder,Panasonic.) responce below
221
+ # before using,you must check port of WR1010,and set same config.
222
+ #
223
+ # +How to use
224
+ # require "agri"
225
+ # include Agri
226
+ #
227
+ # WR::help # => Usage string
228
+ #
229
+ # WR::send_sample(3) # => "%01#RDD0000000011**r" #command_sample
230
+ #
231
+ # res=WR::sample # => "%01$RD0C0129002E000f051301FFFF1E0007040E01FFFF030006023201FFFF020001001A\r" #response sample
232
+ #
233
+ # WR::toa(res)#=>[[25.9, 36, 36, "10100001000", 5],
234
+ # [26.7, false, 21, "10100001000", 5],
235
+ # [26.1, false, 3, "10100001000", 5],
236
+ # [26.1, false, 51, "10100001000", 5]
237
+ # ]
238
+ # DATA meaning:
239
+ # [temperature(celsius degrees), humidity(%RH) if defined , past_sec , conditon Flags , Messages and Radio strength]
240
+ #'
241
+ end
242
+
243
+ def sample
244
+ "%01$RD0C0129002E000f051301FFFF1E0007040E01FFFF030006023201FFFF020001001A\r"
245
+ end
246
+
247
+ def send_sample(n=4)
248
+ #child_thermo(1)# =>"00003"
249
+ channel="01"
250
+ "%"+channel+"#RDD00000"+child_thermo(n)+"**\r"
251
+ end
252
+
253
+ def send_from_to(a,b)
254
+ channel="01"
255
+ "%"+channel+"#RDD"+child_thermo(a)+child_thermo(b)+"**\r"
256
+ end
257
+ ##This require "serialport"
258
+ #WR1010::read(port="/dev/ttyUSB0",speed=57600,_to=3,from=0)
259
+ # [_to,from]:[1,0] means 1st thermo only,[3,1] means 2nd 3rd thermo
260
+ # *usualy
261
+ # WR1010::read(port,speed,thermo_num)
262
+ #
263
+ # *often
264
+ # WR1010::read(port="/dev/ttyUSB0",speed=57600,_to_addreess=3,from_address=0)
265
+ def read(port="/dev/ttyUSB0",speed=57600,_to__address=1,from_address=0)
266
+ require "rubygems"
267
+ require "serialport"
268
+ #require "timeout"
269
+ command=send_from_to(from_address,_to__address)
270
+ begin
271
+ #timeout(1.5) do
272
+ sp=SerialPort.new(port,speed,8,1,0)#port,baud,byte,stopbit,parityNONE
273
+ sp.write(command)
274
+ res=sp.gets
275
+
276
+ #end
277
+ rescue Timeout::Error
278
+ res=nil
279
+ rescue
280
+ res=false
281
+ ensure
282
+ sp.close if sp
283
+ end
284
+ return res
285
+ end
286
+
287
+ end
288
+ end
289
+
290
+ if $0==__FILE__
291
+ require "./bit"
292
+ include AgriController
293
+ #$:.unshift("../lib")
294
+
295
+ require 'test/unit'
296
+
297
+ #require "agri-controller"
298
+
299
+ class TC_Agri< Test::Unit::TestCase
300
+ include AgriController
301
+ def setup
302
+ @res=WR1010::sample
303
+ end
304
+
305
+ def test_WR1010
306
+ p WR1010::send_sample(3) # =>
307
+ p WR1010::sample # =>
308
+ p WR1010::toa(WR1010::sample) #=>
309
+ p x=WR1010::read("/dev/ttyUSB0",speed=57600,_to_address=3,from_adress=0)#[1,0] means 1st thermoonly,[3,1] means 2nd 3rd thermo
310
+ p WR1010::parse(x)
311
+ end
312
+ end
313
+
314
+ end
@@ -0,0 +1,17 @@
1
+ require "time"
2
+ module AgriController
3
+ module_function
4
+ def dt(t1=Time.now,t2=nil)
5
+ begin
6
+ unless t2
7
+ yield if block_given?
8
+ return Time.now-t1
9
+ else
10
+ return t2-t1
11
+ end
12
+ rescue
13
+ return nil
14
+ end
15
+ end
16
+ end
17
+
@@ -1,46 +1,67 @@
1
- module AgriController
2
- ##
3
- #=use block when functions must be caption if encountered error.
4
- # record error(file)
5
- # *error_caption(file="error_ex"){/RubyScripts/}
6
- #
7
- #and retry function.
8
- #=infinite loop
9
- #*loop{error_caption(file){/RubyScripts/}}
10
- def error_caption(file="error_ex")
11
- begin
12
- #p "initialize"
13
-
14
- #main program
15
- yield
16
- rescue => ex
17
- #Error handling
18
- x0=ex.class.to_s
19
- x1=ex.message
20
- x2=ex.backtrace.to_s
21
-
22
- p x="MAIN :"+Time.now.to_s+","+x0+x1+x2
23
- Loger::loger(file+".txt",x+"<br/>")
24
- Loger::loger(file+"_.txt",x+"<br/>")
25
- sleep 5
26
- #retry
27
- #ensure
28
- end
29
- end
30
- end
31
- ##
32
- #�{�̂̃���
33
- #�f�[�^�x�[�X�𗘗p����
34
- #���i�T�[���ɂ�����
35
- #�i�K�̕\��
36
-
37
- if $0==__FILE__
38
- #�g����
39
- require "error_caption"
40
- include AgriController
41
- #p "error_caption"
42
- error_caption("error"){
43
- require "main"
44
- }
45
- end
46
-
1
+ #!ruby
2
+ #coding:utf-8
3
+ module AgriController
4
+ ##
5
+ #=use block when functions must be caption if encountered error.
6
+ # record error(file)
7
+ # *error_caption(file="error_ex"){/RubyScripts/}
8
+ #
9
+ #and retry function.
10
+ #=infinite loop
11
+ #*loop{error_caption(file){/RubyScripts/}}
12
+ def error_caption(file="error_ex")
13
+ begin
14
+ #p "initialize"
15
+
16
+ #main program
17
+ yield
18
+ rescue => ex
19
+ #Error handling
20
+ x0=ex.class.to_s
21
+ x1=ex.message
22
+ x2=ex.backtrace.to_s
23
+
24
+ p x="MAIN :"+Time.now.to_s+","+x0+x1+x2
25
+ Loger::loger(file+".txt",x+"<br/>")
26
+ Loger::loger(file+"_.txt",x+"<br/>")
27
+ sleep 5
28
+ #retry
29
+ #ensure
30
+ end
31
+ end
32
+
33
+ def error_catch(file="error_log.txt", sleep_sec=5 , cr_code= '</br>')
34
+ begin
35
+ yield
36
+ rescue => ex
37
+ #Error handling
38
+ x0=ex.class.to_s
39
+ x1=ex.message
40
+ x2=ex.backtrace.to_s
41
+
42
+ p x="MAIN :"+Time.now.to_s+","+x0+x1+x2
43
+ file.each do |f|
44
+ Loger::loger(f,x+cr_code)
45
+ end
46
+ sleep sleep_sec
47
+ #retry
48
+ #ensure
49
+ end
50
+ end
51
+ end
52
+ ##
53
+ #本体のメモ
54
+ #データベースを利用する
55
+ #n段サーモにおける
56
+ #段階の表示
57
+
58
+ if $0==__FILE__
59
+ #使い方
60
+ require "./error_caption"
61
+ include AgriController
62
+ #p "error_caption"
63
+ error_caption("error"){
64
+ p "foo"#require "main"
65
+ }
66
+ end
67
+
@@ -0,0 +1,7 @@
1
+ #!ruby
2
+ #coding:utf-8
3
+ $KCODE="u" if RUBY_VERSION < "1.9.0"
4
+
5
+ Dir.glob(File.dirname(__FILE__)+"/gruff/*.rb").each do |file|
6
+ require file
7
+ end