1 | # TOPPERSããã¸ã§ã¯ã
|
---|
2 | $MAKER_CODE = "\x00\x00\xB3"
|
---|
3 |
|
---|
4 | # ãã¼ããããã¡ã¤ã«ãªãã¸ã§ã¯ã
|
---|
5 | class LocalNode < ECNL::ENode
|
---|
6 | def initialize(eojx3)
|
---|
7 | # åä½ç¶æ
|
---|
8 |
|
---|
9 | @operation_status = "\x30"
|
---|
10 | # Vï½
|
---|
11 | ï½ï½ï½ï½ï½æ
|
---|
12 | å ±
|
---|
13 | @version_information = "\x01\x0A\x01\x00"
|
---|
14 | # èå¥çªå·
|
---|
15 | @identification_number =
|
---|
16 | # ä¸ä½é信層IDãã£ã¼ã«ã
|
---|
17 | "\xFE" +
|
---|
18 | # ã¡ã¼ã«ã¼ã³ã¼ã
|
---|
19 | $MAKER_CODE +
|
---|
20 | # ã¦ãã¼ã¯IDé¨(ã¡ã¼ã«ã¼ç¬èª)
|
---|
21 | "\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00"
|
---|
22 | # ç°å¸¸å
|
---|
23 | 容
|
---|
24 | @fault_content = "\x00\x00"
|
---|
25 | # ã¡ã¼ã«ã¼ã³ã¼ã
|
---|
26 | @manufacturer_code = $MAKER_CODE
|
---|
27 |
|
---|
28 | # ã¤ã³ã¹ã¿ã³ã¹æ°
|
---|
29 | @inst_count = "\x00\x00\x01"
|
---|
30 | # ã¯ã©ã¹æ°
|
---|
31 | @class_count = "\x00\x02"
|
---|
32 | # ã¤ã³ã¹ã¿ã³ã¹ãªã¹ã
|
---|
33 | @inst_list = "\x01\x05\xff\x01"
|
---|
34 | # ã¯ã©ã¹ãªã¹ã
|
---|
35 | @class_list = "\x01\x05\xff"
|
---|
36 | # ã¢ãã¦ã³ã¹ããããã£ããã
|
---|
37 | @anno_prpmap = "\x01\xd5"
|
---|
38 | # SETããããã£ããã
|
---|
39 | @set_prpmap = "\x01\x80"
|
---|
40 | # GETããããã£ããã
|
---|
41 | @get_prpmap = "\x0c\x80\x82\x83\x89\x8a\x9d\x9e\x9f\xd3\xd4\xd6\xd7"
|
---|
42 | # ããããã£å®ç¾©
|
---|
43 | eprpinib_table = [
|
---|
44 | ECNL::EProperty.new(0x80, (ECNL::EPC_RULE_SET | ECNL::EPC_RULE_GET), @operation_status.length, :@operation_status, :onoff_prop_set, :data_prop_get),
|
---|
45 | ECNL::EProperty.new(0x82, (ECNL::EPC_RULE_GET), @version_information.length, :@version_information, :data_prop_set, :data_prop_get),
|
---|
46 | ECNL::EProperty.new(0x83, (ECNL::EPC_RULE_GET), @identification_number.length, :@identification_number, :data_prop_set, :data_prop_get),
|
---|
47 | ECNL::EProperty.new(0x89, (ECNL::EPC_RULE_GET), @fault_content.length, :fault_content, :@node_profile_object_fault_content_set, :data_prop_get),
|
---|
48 | ECNL::EProperty.new(0x8A, (ECNL::EPC_RULE_GET), @manufacturer_code.length, :@manufacturer_code, :data_prop_set, :data_prop_get),
|
---|
49 | ECNL::EProperty.new(0x9D, (ECNL::EPC_RULE_GET), @anno_prpmap.length, :@anno_prpmap, nil, :data_prop_get),
|
---|
50 | ECNL::EProperty.new(0x9E, (ECNL::EPC_RULE_GET), @set_prpmap.length, :@set_prpmap, nil, :data_prop_get),
|
---|
51 | ECNL::EProperty.new(0x9F, (ECNL::EPC_RULE_GET), @get_prpmap.length, :@get_prpmap, nil, :data_prop_get),
|
---|
52 | ECNL::EProperty.new(0xD3, (ECNL::EPC_RULE_GET), @inst_count.length, :@inst_count, nil, :data_prop_get),
|
---|
53 | ECNL::EProperty.new(0xD4, (ECNL::EPC_RULE_GET), @class_count.length, :@class_count, nil, :data_prop_get),
|
---|
54 | ECNL::EProperty.new(0xD5, (ECNL::EPC_RULE_ANNO), @inst_list.length, :@inst_list, nil, :data_prop_get),
|
---|
55 | ECNL::EProperty.new(0xD6, (ECNL::EPC_RULE_GET), @inst_list.length, :@inst_list, nil, :data_prop_get),
|
---|
56 | ECNL::EProperty.new(0xD7, (ECNL::EPC_RULE_GET), @class_list.length, :@class_list, nil, :data_prop_get)
|
---|
57 | ]
|
---|
58 |
|
---|
59 | super(eojx3, eprpinib_table)
|
---|
60 | end
|
---|
61 |
|
---|
62 | # ç°å¸¸å
|
---|
63 | 容è¨å®é¢æ°
|
---|
64 | def node_profile_object_fault_content_set(prop, src)
|
---|
65 | # ãµã¤ãºã2以å¤ã¯åãä»ããªã
|
---|
66 | if (src.bytesize != 2) then
|
---|
67 | return 0
|
---|
68 | end
|
---|
69 |
|
---|
70 | if (prop.anno) then
|
---|
71 | prop.set_anno(prop.exinf != src)
|
---|
72 | end
|
---|
73 |
|
---|
74 | val = src.getbyte(0) << 8 | src.getbyte(1)
|
---|
75 |
|
---|
76 | if ((val >= 0x0) && (val <= 0x3ec)) then
|
---|
77 | prop.set_exinf(val)
|
---|
78 | # TODO: ãã®ã®å ´åã®å¦ç
|
---|
79 | # ä¸è¨ä»¥å¤ã¯åãä»ããªã
|
---|
80 | else
|
---|
81 | return 0
|
---|
82 | end
|
---|
83 |
|
---|
84 | return 2
|
---|
85 | end
|
---|
86 |
|
---|
87 | # åä½ç¶æ
|
---|
88 | ON/OFFè¨å®é¢æ°ï¼0x30, 0x31ã®ã¿åãä»ãï¼
|
---|
89 | def onoff_prop_set(prop, src)
|
---|
90 | return 0
|
---|
91 | end
|
---|
92 | end
|
---|
93 |
|
---|
94 | # ã³ã³ããã¼ã©ã¼ã¯ã©ã¹
|
---|
95 | class ControllerObj < ECNL::EObject
|
---|
96 | def initialize(eojx3, enod)
|
---|
97 | # åä½ç¶æ
|
---|
98 |
|
---|
99 | @operation_status = "\x30"
|
---|
100 | # è¨ç½®å ´æ
|
---|
101 | @installation_location = "\x01\x0A\x01\x00"
|
---|
102 | # è¦æ ¼ï¼¶ï½
|
---|
103 | ï½ï½ï½ï½ï½æ
|
---|
104 | å ±
|
---|
105 | @standard_version_information = "\x00\x00C\x00"
|
---|
106 | # ç°å¸¸çºçç¶æ
|
---|
107 |
|
---|
108 | @fault_status = "\x41"
|
---|
109 | # ã¡ã¼ã«ã¼ã³ã¼ã
|
---|
110 | @manufacturer_code = $MAKER_CODE
|
---|
111 |
|
---|
112 | # ã¢ãã¦ã³ã¹ããããã£ããã
|
---|
113 | @anno_prpmap = "\x03\x80\x81\x88"
|
---|
114 | # SETããããã£ããã
|
---|
115 | @set_prpmap = "\x04\x80\x81\x97\x98"
|
---|
116 | # GETããããã£ããã
|
---|
117 | @get_prpmap = "\x0a\x80\x81\x82\x88\x8a\x97\x98\x9d\x9e\x9f"
|
---|
118 | # ããããã£å®ç¾©
|
---|
119 | eprpinib_table = [
|
---|
120 | ECNL::EProperty.new(0x80, (ECNL::EPC_RULE_SET | ECNL::EPC_RULE_GET | ECNL::EPC_ANNOUNCE), @operation_status.length, :@operation_status, :onoff_prop_set, :data_prop_get),
|
---|
121 | ECNL::EProperty.new(0x81, (ECNL::EPC_RULE_SET | ECNL::EPC_RULE_GET | ECNL::EPC_ANNOUNCE), @installation_location.length, :@installation_location, :data_prop_set, :data_prop_get),
|
---|
122 | ECNL::EProperty.new(0x82, (ECNL::EPC_RULE_GET), @standard_version_information.length, :@standard_version_information, :data_prop_set, :data_prop_get),
|
---|
123 | ECNL::EProperty.new(0x88, (ECNL::EPC_RULE_GET | ECNL::EPC_ANNOUNCE), @fault_status.length, :@fault_status, :alarm_prop_set, :data_prop_get),
|
---|
124 | ECNL::EProperty.new(0x8A, (ECNL::EPC_RULE_GET), @manufacturer_code.length, :@manufacturer_code, :data_prop_set, :data_prop_get),
|
---|
125 | ECNL::EProperty.new(0x97, (ECNL::EPC_RULE_SET | ECNL::EPC_RULE_GET), (2), nil, :time_prop_set, :time_prop_get),
|
---|
126 | ECNL::EProperty.new(0x98, (ECNL::EPC_RULE_SET | ECNL::EPC_RULE_GET), (4), nil, :date_prop_set, :date_prop_get),
|
---|
127 | ECNL::EProperty.new(0x9D, (ECNL::EPC_RULE_GET), @anno_prpmap.length, :@anno_prpmap, nil, :data_prop_get),
|
---|
128 | ECNL::EProperty.new(0x9E, (ECNL::EPC_RULE_GET), @set_prpmap.length, :@set_prpmap, nil, :data_prop_get),
|
---|
129 | ECNL::EProperty.new(0x9F, (ECNL::EPC_RULE_GET), @get_prpmap.length, :@get_prpmap, nil, :data_prop_get)
|
---|
130 | ]
|
---|
131 |
|
---|
132 | super(0x05, 0xFF, eojx3, enod, eprpinib_table)
|
---|
133 | end
|
---|
134 |
|
---|
135 | # åä½ç¶æ
|
---|
136 | ON/OFFè¨å®é¢æ°ï¼0x30, 0x31ã®ã¿åãä»ãï¼
|
---|
137 | def onoff_prop_set(prop, src)
|
---|
138 | # ãµã¤ãºãï¼ä»¥å¤ã¯åãä»ããªã
|
---|
139 | if (src.bytesize != 1) then
|
---|
140 | return 0
|
---|
141 | end
|
---|
142 |
|
---|
143 | if (prop.anno) then
|
---|
144 | prop.set_anno(prop.exinf != src)
|
---|
145 | end
|
---|
146 |
|
---|
147 | case (src.getbyte(0))
|
---|
148 | # ONã®å ´å
|
---|
149 | when 0x30 then
|
---|
150 | prop.set_exinf(src)
|
---|
151 | # LEDã®"."ãON
|
---|
152 | digitalWrite(1, 1)
|
---|
153 | # OFFã®å ´å
|
---|
154 | when 0x31 then
|
---|
155 | prop.set_exinf(src)
|
---|
156 | # LEDã®"."ãOFF
|
---|
157 | digitalWrite(1, 0)
|
---|
158 | # 0x30ã0x31以å¤ã¯åãä»ããªã
|
---|
159 | else
|
---|
160 | return 0
|
---|
161 | end
|
---|
162 |
|
---|
163 | return 1
|
---|
164 | end
|
---|
165 |
|
---|
166 | # ç°å¸¸çºçç¶æ
|
---|
167 | è¨å®é¢æ°ï¼0x41, 0x42ã®ã¿åãä»ãï¼
|
---|
168 | def alarm_prop_set(prop, src)
|
---|
169 | # ãµã¤ãºãï¼ä»¥å¤ã¯åãä»ããªã
|
---|
170 | if (src.bytesize != 1) then
|
---|
171 | return 0
|
---|
172 | end
|
---|
173 |
|
---|
174 | if (prop.anno) then
|
---|
175 | prop.set_anno(prop.exinf != src)
|
---|
176 | end
|
---|
177 |
|
---|
178 | case (src.getbyte(0))
|
---|
179 | # ç°å¸¸çºçãã/ãªãã®å ´å
|
---|
180 | when 0x41,0x42 then
|
---|
181 | prop.set_exinf(src)
|
---|
182 | # 0x41ã0x42以å¤ã¯åãä»ããªã
|
---|
183 | else
|
---|
184 | return 0
|
---|
185 | end
|
---|
186 |
|
---|
187 | return 1
|
---|
188 | end
|
---|
189 |
|
---|
190 | # ç¾å¨å¹´ææ¥åå¾é¢æ°
|
---|
191 | def date_prop_get(prop, size)
|
---|
192 | # ãµã¤ãºãï¼ä»¥å¤ã¯åãä»ããªã
|
---|
193 | if (size != 4) then
|
---|
194 | return 0
|
---|
195 | end
|
---|
196 |
|
---|
197 | time = Rtc.getTime
|
---|
198 |
|
---|
199 | return ((time[0] & 0xFF00) >> 8).chr + (time[0] & 0xFF).chr + time[1].chr + time[2].chr
|
---|
200 | end
|
---|
201 |
|
---|
202 | # ç¾å¨å¹´ææ¥è¨å®é¢æ°
|
---|
203 | def date_prop_set(prop, src)
|
---|
204 | # ãµã¤ãºãï¼ä»¥å¤ã¯åãä»ããªã
|
---|
205 | if (src.bytesize != 4) then
|
---|
206 | return 0
|
---|
207 | end
|
---|
208 |
|
---|
209 | time = Rtc.getTime
|
---|
210 | time[0] = (src.getbyte(0) << 8) | src.getbyte(1)
|
---|
211 | time[1] = src.getbyte(2)
|
---|
212 | time[2] = src.getbyte(3)
|
---|
213 | Rtc.setTime time
|
---|
214 |
|
---|
215 | return 4
|
---|
216 | end
|
---|
217 |
|
---|
218 | # ç¾å¨æå»åå¾é¢æ°
|
---|
219 | def time_prop_get(prop, size)
|
---|
220 | # ãµã¤ãºãï¼ä»¥å¤ã¯åãä»ããªã
|
---|
221 | if (size != 2) then
|
---|
222 | return 0
|
---|
223 | end
|
---|
224 |
|
---|
225 | time = Rtc.getTime
|
---|
226 |
|
---|
227 | return time[3].chr + time[4].chr
|
---|
228 | end
|
---|
229 |
|
---|
230 | # ç¾å¨æå»è¨å®é¢æ°
|
---|
231 | def time_prop_set(prop, src)
|
---|
232 | # ãµã¤ãºãï¼ä»¥å¤ã¯åãä»ããªã
|
---|
233 | if (src.bytesize != 2) then
|
---|
234 | return 0
|
---|
235 | end
|
---|
236 |
|
---|
237 | time = Rtc.getTime
|
---|
238 | time[3] = src.getbyte(0)
|
---|
239 | time[4] = src.getbyte(1)
|
---|
240 | Rtc.setTime time
|
---|
241 |
|
---|
242 | return 2
|
---|
243 | end
|
---|
244 | end
|
---|
245 |
|
---|
246 | class Controller < ECNL::SvcTask
|
---|
247 | def initialize()
|
---|
248 | @profile = LocalNode.new(0x01)
|
---|
249 | @devices = [ ControllerObj.new(0x01, @profile) ]
|
---|
250 | @enodadrb_table = []
|
---|
251 |
|
---|
252 | super()
|
---|
253 |
|
---|
254 | # LEDãOFF
|
---|
255 | digitalWrite(2, 0)
|
---|
256 |
|
---|
257 | set_timer(1000)
|
---|
258 | end
|
---|
259 |
|
---|
260 | def recv_esv(esv)
|
---|
261 | if (esv.esv != ECNL::ESV_GET_RES) && (esv.esv != ECNL::ESV_GET_SNA) then
|
---|
262 | return
|
---|
263 | end
|
---|
264 |
|
---|
265 | itr = esv.itr_ini()
|
---|
266 | itr.itr_nxt()
|
---|
267 | until itr.is_eof do
|
---|
268 | if itr.epc == 0xD6 then
|
---|
269 | # LEDãON
|
---|
270 | digitalWrite(2, 1)
|
---|
271 | end
|
---|
272 | itr.itr_nxt()
|
---|
273 | end
|
---|
274 | end
|
---|
275 |
|
---|
276 | def break_wait(data)
|
---|
277 | end
|
---|
278 |
|
---|
279 | def timeout()
|
---|
280 | esv = esv_get(nil, 0xD6)
|
---|
281 | snd_esv(esv)
|
---|
282 |
|
---|
283 | set_timer(10000)
|
---|
284 | end
|
---|
285 |
|
---|
286 | def snd_msg(ep, data)
|
---|
287 | # éä¿¡ã¬ã¤ã¤ã¼ã¸éä¿¡
|
---|
288 | TargetBoard::snd_msg(ep, data)
|
---|
289 | end
|
---|
290 |
|
---|
291 | def is_local_addr(ep)
|
---|
292 | TargetBoard::is_local_addr(ep)
|
---|
293 | end
|
---|
294 |
|
---|
295 | def is_multicast_addr(ep)
|
---|
296 | TargetBoard::is_multicast_addr(ep)
|
---|
297 | end
|
---|
298 |
|
---|
299 | def is_valid_addrid(id)
|
---|
300 | (id >= 0) && ((id - ECNL::ENOD_REMOTE_ID) < @enodadrb_table.length)
|
---|
301 | end
|
---|
302 |
|
---|
303 | def get_local_addr()
|
---|
304 | TargetBoard::get_local_addr()
|
---|
305 | end
|
---|
306 |
|
---|
307 | def get_multicast_addr()
|
---|
308 | TargetBoard::get_multicast_addr()
|
---|
309 | end
|
---|
310 |
|
---|
311 | def get_remote_addr(id)
|
---|
312 | index = id - ECNL::ENOD_REMOTE_ID
|
---|
313 | if (index < 0) || (index >= @enodadrb_table.length)
|
---|
314 | nil
|
---|
315 | else
|
---|
316 | @enodadrb_table[index]
|
---|
317 | end
|
---|
318 | end
|
---|
319 |
|
---|
320 | # éä¿¡ã¬ã¤ã¤ã¼ã¢ãã¬ã¹ã®åããã®ãæ¤ç´¢
|
---|
321 | def get_remote_id(ep)
|
---|
322 | id = ECNL::ENOD_REMOTE_ID - 1
|
---|
323 | for ea in @enodadrb_table do
|
---|
324 | id += 1
|
---|
325 | if !ea then
|
---|
326 | next
|
---|
327 | end
|
---|
328 | if !TargetBoard::equals_addr(ea, ep) then
|
---|
329 | next
|
---|
330 | end
|
---|
331 |
|
---|
332 | return id
|
---|
333 | end
|
---|
334 |
|
---|
335 | return ECNL::ENOD_NOT_MATCH_ID
|
---|
336 | end
|
---|
337 |
|
---|
338 | # 対å¿ãããªã¢ã¼ããã¼ããæ¤ç´¢
|
---|
339 | def set_remote_addr(edata, ep)
|
---|
340 | id = ECNL::ENOD_REMOTE_ID - 1
|
---|
341 | for ea in @enodadrb_table do
|
---|
342 | id += 1
|
---|
343 | if !ea then
|
---|
344 | next
|
---|
345 | end
|
---|
346 | if !is_match(svc, edata, ep) then
|
---|
347 | next
|
---|
348 | end
|
---|
349 |
|
---|
350 | # 対å¿ãããªã¢ã¼ããã¼ããããã°éä¿¡ã¬ã¤ã¤ã¼ã¢ãã¬ã¹ãè¨å®
|
---|
351 | @enodadrb_table[id - ECNL::ENOD_REMOTE_ID] = ep
|
---|
352 |
|
---|
353 | return id
|
---|
354 | end
|
---|
355 |
|
---|
356 | return ECNL::ENOD_NOT_MATCH_ID
|
---|
357 | end
|
---|
358 |
|
---|
359 | # 空ãé åãæ¢ãã¦èªåç»é²
|
---|
360 | def add_remote_addr(edata, ep)
|
---|
361 | id = ECNL::ENOD_REMOTE_ID - 1
|
---|
362 | for ea in @enodadrb_table do
|
---|
363 | id += 1
|
---|
364 | if ea then
|
---|
365 | next
|
---|
366 | end
|
---|
367 |
|
---|
368 | @enodadrb_table[id - ECNL::ENOD_REMOTE_ID] = ep
|
---|
369 |
|
---|
370 | return id
|
---|
371 | end
|
---|
372 |
|
---|
373 | if @enodadrb_table.length >= 100 then
|
---|
374 | return ECNL::ENOD_NOT_MATCH_ID
|
---|
375 | end
|
---|
376 |
|
---|
377 | id = @enodadrb_table.length;
|
---|
378 | @enodadrb_table[id] = ep
|
---|
379 |
|
---|
380 | return id + ECNL::ENOD_REMOTE_ID
|
---|
381 | end
|
---|
382 | end
|
---|
383 |
|
---|
384 | ctrl = Controller.new()
|
---|
385 |
|
---|
386 | # ã¡ã¤ã³ã«ã¼ã
|
---|
387 | while (true) do
|
---|
388 | # ã¡ãã»ã¼ã¸å¾
|
---|
389 | ã¡
|
---|
390 | ret = TargetBoard::wait_msg(ctrl.timer)
|
---|
391 | if !ret then
|
---|
392 | break;
|
---|
393 | end
|
---|
394 |
|
---|
395 | # çµéæéã®è¨ç®
|
---|
396 | ctrl.progress ret[0]
|
---|
397 |
|
---|
398 | # æ»ãå¤ãï¼ã¤ãªã
|
---|
399 | if ret.length == 2 then
|
---|
400 | # å
|
---|
401 | é¨ã¤ãã³ã
|
---|
402 | case (ret[1])
|
---|
403 | when 1 then
|
---|
404 | TargetBoard::restart
|
---|
405 | when 2 then
|
---|
406 | ctrl.ntf_inl
|
---|
407 | end
|
---|
408 | # æ»ãå¤ãï¼ã¤ãªã
|
---|
409 | elsif ret.length == 3 then
|
---|
410 | # éä¿¡ã¬ã¤ã¤ã¼ããã®ã¡ãã»ã¼ã¸ï¼é信端ç¹ã¨é»æï¼
|
---|
411 | ctrl.recv_msg(ret[1], ret[2])
|
---|
412 | end
|
---|
413 |
|
---|
414 | # ã¿ã¤ã ã¢ã¦ãã®å¦çãããã°è¡ã
|
---|
415 | ctrl.call_timeout
|
---|
416 | end
|
---|