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,5 @@
1
+ #!ruby
2
+ #coding:utf-8
3
+ module AgriController
4
+ VERSION = "0.0.0"
5
+ end
@@ -0,0 +1,39 @@
1
+ #!ruby
2
+ #coding:utf-8
3
+ module AgriController
4
+ module Web
5
+ module_function
6
+ def html_head(title="kansi_htm",tuika='')
7
+ head=<<EOS
8
+ <html>
9
+ <head>
10
+ <meta http-equiv="Content-Language" content="ja" />
11
+ <meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
12
+ #{tuika}
13
+ <link rel="stylesheet" type="text/css" href="../css/str.css" title="str"/>
14
+ <title>#{title}</title>
15
+ </head>
16
+ <body>
17
+ EOS
18
+ end
19
+
20
+ def html_end
21
+ _end='
22
+ </body>
23
+ </html>'
24
+ return _end
25
+ end
26
+
27
+ def html_head_refresh(title,time)
28
+ #time:should be able to convert Integer
29
+ str= <<eos
30
+ <META HTTP-EQUIV="Refresh" CONTENT="#{time.to_s};URL=./main.cgi">
31
+ eos
32
+ html_head(title,str)
33
+ end
34
+ end
35
+ end
36
+
37
+ if $0==__FILE__
38
+ print Web::html_end
39
+ end
@@ -0,0 +1,46 @@
1
+ #! ruby -Ku
2
+ #require 'pathname'
3
+ require 'webrick'
4
+ module AgriController
5
+ module WEBrick::HTTPServlet
6
+ FileHandler.add_handler('rb', CGIHandler)
7
+ end
8
+ module_function
9
+ def webrick_start(root=Dir.pwd,port=10080)
10
+ #p approot=Pathname.pwd.parent
11
+ app_root =root#File.expand_path(File.dirname(__FILE__) + '/..')
12
+
13
+ p document_root = app_root + '/htdocs'
14
+ p rubybin = 'c:/ruby187/bin/rubyw.exe'
15
+ #rubybin = 'ruby.exe'
16
+
17
+ server = WEBrick::HTTPServer.new({
18
+ :DocumentRoot => document_root,
19
+ :BindAddress => '127.0.0.1',
20
+ :CGIInterpreter => rubybin,
21
+ :Port => port
22
+ })
23
+
24
+ # App/cgi/
25
+ app_root + '/cgi-bin/*.{cgi,rb}'
26
+ cgilist = Dir.glob(app_root + '/cgi-bin/*.{cgi,rb}')
27
+
28
+ cgilist.each {|cgi_file|
29
+ p cgi_file_name = File.basename(cgi_file)
30
+
31
+ server.mount('/cgi-bin/' + cgi_file_name, WEBrick::HTTPServlet::CGIHandler, cgi_file)
32
+
33
+ }
34
+
35
+ ['INT', 'TERM'].each {|signal|
36
+ Signal.trap(signal){ server.shutdown }
37
+ }
38
+
39
+ server.start
40
+ end
41
+ end
42
+
43
+ if $0==__FILE__
44
+ $KCODE="s"
45
+ AgriController::webrick_start
46
+ end
@@ -0,0 +1,119 @@
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
@@ -0,0 +1,316 @@
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