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.
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
@@ -1,35 +0,0 @@
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
@@ -1,119 +0,0 @@
1
- #require "Setting_io"
2
- #require "wet_sensor"
3
- module AgriController
4
- class WetSensor #< Wet_sensor
5
-
6
- #include Setting_io
7
- attr_reader :name
8
-
9
- def initialize( delay=1 , name="x")
10
- @name=name
11
-
12
- @keep=false
13
- @delay=delay
14
- @time=on
15
- @command=false
16
- @wet_read=yaml_db("wet_read",false, name)
17
- @wet_sensor=yaml_db("wet_sensor", false,name)
18
- @weted=false
19
- end
20
-
21
- def on
22
- @time=Time.now+@delay
23
- end
24
- def time?
25
- Time.now > @time
26
- end
27
- def commander
28
- if @command==true
29
- yield
30
- @command=false
31
- return true
32
- else
33
- return false
34
- end
35
- end
36
- def run(bit,name=@name)
37
- ##illigating check
38
- #���������H
39
- if bit
40
- #print "1"
41
- #flag read
42
- @wet_read =yaml_dbr("wet_read",name)
43
- @wet_sensor=yaml_dbr("wet_sensor",name)
44
- #���m�ォ�H
45
- if @weted
46
- #print "2"
47
- #���m��̓Z���T�[�̊��m�������Ȃ�
48
- return !time?
49
- #���m���Ă��Ȃ�
50
- else
51
- #�Z���T�[���m(true)
52
- if @wet_sensor
53
- #�X�g�b�v����
54
- p "#{name} detect:#{Time.now.to_s}"
55
- @weted=true
56
- #���؏���
57
- on
58
- #�Z���T�[�s���m
59
- else
60
- #print "4"
61
- #�Z���T�[�̒l�ǂݍ���
62
- if @wet_read==false
63
- #print "5"
64
- #�₢���킹����
65
- @command=true
66
- @wet_read=yaml_db("wet_read",true,name)
67
- # =>�Ԏ��ɂ����sensor���ύX
68
- else
69
- #wet_read==true
70
- #�҂����킹��
71
- #print "6"
72
- end
73
- end
74
- #�������s
75
- return true
76
- end
77
- #�������Ă��Ȃ��Ƃ�
78
- else
79
- #print "."
80
- if @wet_sensor
81
- @wet_sensor=yaml_db("wet_sensor",false,name)
82
- end
83
-
84
- if @wet_read
85
- @wet_read=yaml_db("wet_read",false,name)
86
- end
87
- @weted=false
88
-
89
- return bit
90
- end
91
- end
92
- end
93
- end
94
-
95
- if $0==__FILE__
96
- require "setting_io"
97
- include AgriController
98
- include Setting_io
99
-
100
- name="bit"
101
- time=Time.now
102
- bool=false
103
- bit=WetSensor.new(3,name)
104
- loop do
105
- break if Time.now >(time+10)
106
-
107
- p bit.run(true)
108
-
109
- if Time.now>(time+2) && (bool==false)
110
- p Time.now
111
- p "detected"
112
- yaml_db("wet_sensor",true,name)
113
- yaml_db("wet_read",false,name)
114
- bool=true
115
- end#p yaml_dbr("wet_read","bit")
116
- sleep 0.9
117
- end
118
-
119
- end
@@ -1,316 +0,0 @@
1
- module AgriController
2
- ##
3
- #module WR1010
4
- # before using,you must check COM_port of WR1010,and set same config.
5
- #
6
- # How to use
7
- # require "wr1010"
8
- # include WR1010
9
- #
10
- # list(com_port=7,child_thermo_numbers=4)
11
- # # =>[[25.9, 36, 36, "10100001000", 5],
12
- # [26.7, false, 21, "10100001000", 5],
13
- # [26.1, false, 3, "10100001000", 5],
14
- # [26.1, false, 51, "10100001000", 5]]
15
- # or nil
16
- #
17
- # data meaning
18
- # [Degree,Humidity,Seconds since recorded,status bit,radio(1-5)or errors of status.]
19
- # if fail communicate , returns nil.
20
- module WR1010
21
- module_function
22
- ##
23
- #communication setting is very important.please check .
24
- # icomno COMNO 1-
25
- # idcbflags 0:binariy
26
- # 1:parity_on
27
- # 2:CTS output flow controll
28
- # b:no check Null char
29
- # c,d:RTS output flow controll
30
- # ibaud rate 110,300,600,1200,2400,4800,9600,14400,19200,38400
31
- # ibyte 1byte_length 4,5,6,7,8
32
- # iparity PARITY 0:none 1:odd 2:even
33
- # istopbits STPBIT 0:1bit
34
- # 1:1.5bit
35
- # 2:2bit
36
- # irecbuf,isenbuf BUFFERSIZE(recieve,send)
37
- # return nil:ok
38
- #open(icomno,idcbflags,ibaud,ibyte,iparity,istopbits,irecbuf,isenbuf)
39
- #WRexport(com_port,send_port="01",number_of_address="00003",bcc_sum="**",sleep_t=0.05)
40
- # =>"%01$RD0C0129002E000f051301FFFF1E0007040E01FFFF030006023201FFFF020001001A\r" (example.)
41
- def WRexport(com_port,send_port="01",number_of_address="00003",bcc_sum="**",sleep_t=0.05)
42
- a=Serial.new
43
- if a.open(com_port,1,57600,8,0,0,8,10) != -1#108,324)!=-1
44
- command="%#{send_port}#RDD00000#{number_of_address}#{bcc_sum}\r"
45
-
46
- yield command if block_given?
47
- #p command
48
- a.send(command)
49
-
50
- sleep sleep_t
51
- receive=a.receive
52
- a.close
53
- return receive
54
- else
55
- return false
56
- end
57
- nil
58
- end
59
-
60
- ##
61
- #returns address number of child thermos(5 chars)
62
- #child_thermo(1)# =>"00003"
63
- #child_thermo(4)# =>"00015"
64
- #child_thermo(56)# =>"00223"
65
- def child_thermo(n)
66
- begin
67
- x=n*4-1
68
- y=x.to_s
69
- (5-y.size).times{y="0"+y}
70
- rescue
71
- raise "method child_thermo(#{n}):error"
72
- end
73
- return y
74
- end
75
- #thermo_data(recieve_value)# =>["0ff0fffff500ffff","1f00ffffff000000"](ex.)
76
- def thermo_data(recieve_value)#ex# =>["0ff0fffff500ffff","1f00ffffff000000"]
77
- begin
78
- if recieve_value
79
- str=recieve_value[6..(-4)]
80
- size=str.size
81
- if (size)%16 ==0
82
- array=[]
83
- (size/16).times do |i|
84
- array[i]=str.slice!(0..15)
85
- end
86
- array
87
- else
88
- nil
89
- end
90
- else
91
- nil
92
- end
93
- rescue
94
- return nil
95
- end
96
- end
97
-
98
- def thrmo_array(str)
99
- begin
100
- result=[]
101
- str.each do |data|
102
- #p data ;p data.size
103
- result_1=[]
104
- (data.size/4).times do |i|
105
- result_1 << data.slice((i*4),4)
106
- end
107
- result << anaryze(result_1)
108
- end
109
- return result
110
- rescue
111
- return nil
112
- end
113
- end
114
-
115
- def anaryze(data)#["0201", "2C00", "2400", "0805"]
116
- result=[]
117
- #result[0]
118
- x=thermo_hex_to_i(data[0])
119
- result << judge(x).to_f/10
120
- #result[1]
121
- x2 = thermo_hex_to_i(data[1])
122
- if x2==65535
123
- result << false
124
- elsif x2<=32766
125
- if x2<=100
126
- result << x2
127
- elsif
128
- result << 100
129
- end
130
- else
131
- #p thermo_hex_to_i(data[1])
132
- result << false
133
- end
134
- #result[2]
135
- result << thermo_hex_to_i(data[2])
136
- #result[3]
137
- result << thermo_hex_to_i(data[3]).to_s(2)
138
- result
139
- end
140
-
141
- def errors(bit_str)#"10100001000"
142
- error_list=[]
143
- #if bit_str
144
-
145
- bit=Bit.new(Integer("0b"+bit_str))
146
- #p bit.bit
147
- if bit.on?(0)
148
- error_list << "bit0:causion:battery. "
149
- end
150
-
151
- if bit.on?(1)
152
- error_list << "bit1:Error:sensor cable. "
153
- end
154
- if bit.on?(2)
155
- error_list << "bit2:causion:Temp is too High or Low. "
156
- end
157
- if bit.off?(3)
158
- error_list << "bit3:Error:FATAL ERROR.needs maintainance. "
159
- end
160
- #p error_list
161
-
162
- #radio power
163
- size=bit_str.size*-1
164
- #p bit_str
165
- #p bit_str.slice((size..-9))
166
- radio_power=Integer("0b"+bit_str.slice((size..-9)))
167
-
168
- if error_list==[]
169
- begin
170
-
171
- return radio_power
172
- rescue
173
- return nil
174
- end
175
- end
176
- #else
177
- # nil
178
- #end
179
- error_list << radio_power
180
- end
181
- #+-tempereture judge function
182
- def judge(x)
183
- begin
184
- bit=Bit.new(x)
185
- unless bit.on?(15)
186
- return x
187
- else
188
- res= x-65535
189
-
190
- #under -100 'c (degrees Celsius)
191
- #thermo must be error 35536 => "1000101011010000" => -2999.9
192
- unless res< -1000
193
- return res
194
- else
195
- return nil
196
- end
197
- end
198
- rescue
199
- nil
200
- end
201
- end
202
-
203
- def thermo_hex_to_i(data)
204
- #hex="f100" # =>241
205
- x=data.slice(0..1)
206
- y=data.slice(2..3)
207
- result=((y+x).to_i(16))
208
- end
209
-
210
- def list(com_port=7,thermo=4,sleep_t=0.05)
211
- result=[]
212
- send_port="01"
213
- bcc_sum="**"
214
- number_of_address=child_thermo(thermo)
215
- recieve_value=WRexport(com_port,send_port,number_of_address,bcc_sum,sleep_t)
216
- if recieve_value
217
- ret=thermo_data(recieve_value)
218
- if ret
219
- x=thrmo_array(ret)
220
- if x
221
- x.each do |data|
222
- ret=errors(data[3])
223
- data << ret#"10100001000"
224
- result << data
225
- end
226
- return result
227
- end
228
- end
229
- end
230
- nil
231
- end
232
-
233
- def to_log(log_file,data)
234
- #add data to log_file
235
- if data.class!=nil
236
- open(log_file,"a") do |io|
237
- io.print Time.now
238
- io.print "\n"
239
-
240
- data.each do |str|
241
- res=""
242
- str.each do |str2|
243
- res+=str2.to_s+","
244
- end
245
- io.print res.chop+"\n"
246
- end
247
- io.print("\n")
248
- end
249
-
250
- #rename log_file if size too big
251
- if File.size?(log_file)>=100000
252
- i=1
253
- bool=true
254
- while bool
255
- new_name=i.to_s+log_file
256
- unless File.exist?(new_name)
257
- File.rename(log_file,new_name)
258
- bool=false
259
- end
260
- i+=1
261
- end
262
- end
263
- nil
264
- end
265
- end
266
- def help
267
- '##
268
- #module WR1010
269
- # before using,you must check COM_port of WR1010,and set same config.
270
- #
271
- # How to use
272
- # require "wr1010"
273
- # include WR1010
274
- #
275
- # list(com_port=7,child_thermo_numbers=4)
276
- # # =>[[25.9, 36, 36, "10100001000", 5],
277
- # [26.7, false, 21, "10100001000", 5],
278
- # [26.1, false, 3, "10100001000", 5],
279
- # [26.1, false, 51, "10100001000", 5]]
280
- # or nil
281
- #
282
- # data meaning
283
- # [Degree,Humidity,Seconds since recorded,status bit,radio(1-5)or errors of status.]
284
- # if fail communicate , returns nil.'
285
- end
286
-
287
- alias status errors
288
- alias com list
289
- alias save to_log
290
- end
291
- end
292
-
293
- if $0==__FILE__
294
- #p $KCODE=""
295
- include WR1010
296
- #com_port=7
297
- #send_port="01"
298
- #number_of_address="00015"
299
- #bcc_sum="**"
300
-
301
- #p recieve_value=WRexport(com_port,send_port,number_of_address,bcc_sum)
302
- #p ret=thermo_data(recieve_value)
303
- #p x=thrmo_array(ret)
304
- p x=list(8,4)
305
- #p judge(65534).to_f/10
306
- #p thermo_data(nil)
307
- #thrmo_array(ret)
308
- #p judge 65535
309
- p child_thermo(4)
310
- =begin
311
- sample="%01$RD0C0129002E000f051301FFFF1E0007040E01FFFF030006023201FFFF020001001A\r"
312
- #sample=["0D0129000C000f05", "1401FFFF38000804", "0E01FFFF09000802", "3901FFFF1C000900"]
313
- p ret=thermo_data(sample)
314
- =end
315
- #save("foo.txt",list(4))
316
- end