source: EcnlProtoTool/trunk/webapp/webmrbc/Ecnl/EcnlAPIBlock.cs@ 270

Last change on this file since 270 was 270, checked in by coas-nagasima, 7 years ago

mruby版ECNLプロトタイピング・ツールを追加

  • Property svn:eol-style set to native
  • Property svn:keywords set to Id
  • Property svn:mime-type set to text/x-csharp
File size: 35.2 KB
Line 
1using System;
2using System.Collections.Generic;
3using System.Linq;
4using System.Text;
5using Bridge;
6using Bridge.Html5;
7
8namespace WebMrbc
9{
10 public class EcnlPropertyAttributeBlock : Block
11 {
12 public const string type_name = "property_attribute";
13
14 public EcnlPropertyAttributeBlock()
15 : base(type_name)
16 {
17
18 }
19
20 public void init()
21 {
22 this.appendDummyInput()
23 .appendField("プロパティ属性")
24 .appendField(new FieldDropdown(new [] {
25 new [] {"未設定", "EPC_NONE"},
26 new [] {"設定可", "EPC_RULE_SET"},
27 new [] {"取得可", "EPC_RULE_GET"},
28 new [] {"通知有り", "EPC_RULE_ANNO"},
29 new [] {"状態変化時通知", "EPC_ANNOUNCE"},
30 new [] {"可変長データ", "EPC_VARIABLE"}
31 }), "VALUE");
32 this.setOutput(true, "Number");
33 this.setColour(230);
34 this.setTooltip("");
35 this.setHelpUrl("http://www.example.com/");
36 }
37 }
38
39 public class EcnlServiceCodeBlock : Block
40 {
41 public const string type_name = "service_code";
42
43 public EcnlServiceCodeBlock()
44 : base(type_name)
45 {
46
47 }
48
49 public void init()
50 {
51 this.appendDummyInput()
52 .appendField("サービスコード")
53 .appendField(new FieldDropdown(new [] {
54 new [] {"プロパティ値書き込み要求(応答不要)", "ESV_SET_I"},
55 new [] {"プロパティ値書き込み要求(応答要)", "ESV_SET_C"},
56 new [] {"プロパティ値読み出し要求", "ESV_GET"},
57 new [] {"プロパティ値通知要求", "ESV_INF_REQ"},
58 new [] {"プロパティ値書き込み・読み出し要求", "ESV_SET_GET"},
59 new [] {"プロパティ値書き込み応答", "ESV_SET_RES"},
60 new [] {"プロパティ値読み出し応答", "ESV_GET_RES"},
61 new [] {"プロパティ値通知", "ESV_INF"},
62 new [] {"プロパティ値通知(応答要)", "ESV_INFC"},
63 new [] {"プロパティ値通知応答", "ESV_INFC_RES"},
64 new [] {"プロパティ値書き込み・読み出し応答", "ESV_SET_GET_RES"},
65 new [] {"プロパティ値書き込み要求不可応答", "ESV_SET_I_SNA"},
66 new [] {"プロパティ値書き込み要求不可応答", "ESV_SET_C_SNA"},
67 new [] {"プロパティ値読み出し不可応答", "ESV_GET_SNA"},
68 new [] {"プロパティ値通知不可応答", "ESV_INF_SNA"},
69 new [] {"プロパティ値書き込み・読み出し不可応答", "ESV_SET_GET_SNA"}
70 }), "VALUE");
71 this.setOutput(true, "Number");
72 this.setColour(230);
73 this.setTooltip("");
74 this.setHelpUrl("http://www.example.com/");
75 }
76 }
77
78 public class EcnlNodeIDBlock : Block
79 {
80 public const string type_name = "node_id";
81
82 public EcnlNodeIDBlock()
83 : base(type_name)
84 {
85
86 }
87
88 public void init()
89 {
90 this.appendDummyInput()
91 .appendField("ノードID")
92 .appendField(new FieldDropdown(new [] {
93 new [] {"アドレスID登録なし", "ENOD_NOT_MATCH_ID"},
94 new [] {"マルチキャストアドレスID", "ENOD_MULTICAST_ID"},
95 new [] {"自ノードアドレスID", "ENOD_LOCAL_ID"},
96 new [] {"APIアドレスID", "ENOD_API_ID"},
97 new [] {"他ノードID", "ENOD_REMOTE_ID"},
98 }), "VALUE");
99 this.setOutput(true, "Number");
100 this.setColour(230);
101 this.setTooltip("");
102 this.setHelpUrl("http://www.example.com/");
103 }
104 }
105
106 public class EcnlPropertyLocalBlock : Block
107 {
108 public EcnlPropertyLocalBlock(string type)
109 : base(type)
110 {
111 }
112
113 public string GetInputName()
114 {
115 var match = false;
116 Block prev, block = this;
117 for (;;) {
118 prev = block;
119 block = prev.getParent();
120 if (block == null)
121 break;
122
123 if ((block.type == EPropertyVarLenBlock.type_name)
124 || (block.type == EPropertyFixLenBlock.type_name)) {
125 match = true;
126 break;
127 }
128 }
129
130 if (!match)
131 return "";
132
133 for (var i = 0; i < block.inputList.Length; i++) {
134 var input = block.inputList[i];
135 if (input.connection == null)
136 continue;
137
138 var childBlock = input.connection.targetBlock();
139 if (childBlock != null && childBlock.id == prev.id) {
140 return input.name;
141 }
142 }
143
144 return "";
145 }
146 }
147
148 public class EcnlGetPropertyInfoBlock : EcnlPropertyLocalBlock
149 {
150 public const string type_name = "get_property_info";
151
152 public EcnlGetPropertyInfoBlock()
153 : base(type_name)
154 {
155 }
156
157 public void init()
158 {
159 this.appendDummyInput()
160 .appendField("プロパティ")
161 .appendField(new FieldDropdown(new [] {
162 new [] {"コード", "pcd"},
163 new [] {"属性", "atr"},
164 new [] {"サイズ", "sz"}
165 }), "MEMBER");
166 this.setOutput(true, "Number");
167 this.setColour(230);
168 this.setTooltip("");
169 this.setHelpUrl("http://www.example.com/");
170 }
171
172 public void onchange(object ev)
173 {
174 if (!String.IsNullOrEmpty(GetInputName())) {
175 setWarningText(null);
176 }
177 else {
178 setWarningText("プロパティアクセスブロックのみで使用します");
179 }
180 }
181 }
182
183 public class EcnlSaveReceivedPropertyBlock : EcnlPropertyLocalBlock
184 {
185 public const string type_name = "save_received_property";
186
187 public EcnlSaveReceivedPropertyBlock()
188 : base(type_name)
189 {
190 }
191
192 public void init()
193 {
194 this.appendDummyInput()
195 .appendField("受信プロパティを保存")
196 .appendField("", "ITEM");
197 this.setPreviousStatement(true, null);
198 this.setNextStatement(true, null);
199 this.setColour(230);
200 this.setTooltip("");
201 this.setHelpUrl("http://www.example.com/");
202 }
203
204 public void onchange(object ev)
205 {
206 if (!String.IsNullOrEmpty(GetInputName())) {
207 setWarningText(null);
208 }
209 else {
210 setWarningText("プロパティアクセスブロックのみで使用します");
211 }
212 }
213 }
214
215 public class EcnlGetSavedPropertyBlock : EcnlPropertyLocalBlock
216 {
217 public const string type_name = "get_saved_property";
218
219 public EcnlGetSavedPropertyBlock()
220 : base(type_name)
221 {
222 }
223
224 public void init()
225 {
226 this.appendDummyInput()
227 .appendField("保存してあるプロパティ値")
228 .appendField("", "ITEM");
229 this.setOutput(true, "String");
230 this.setColour(230);
231 this.setTooltip("");
232 this.setHelpUrl("http://www.example.com/");
233 }
234
235 public void onchange(object ev)
236 {
237 if (!String.IsNullOrEmpty(GetInputName())) {
238 setWarningText(null);
239 }
240 else {
241 setWarningText("プロパティアクセスブロックのみで使用します");
242 }
243 }
244 }
245
246 public class EcnlSetAnnounceRequestBlock : EcnlPropertyLocalBlock
247 {
248 public const string type_name = "set_announce_request";
249
250 public EcnlSetAnnounceRequestBlock()
251 : base(type_name)
252 {
253 }
254
255 public void init()
256 {
257 this.appendValueInput("DATA")
258 .setCheck("String")
259 .appendField("受信データと");
260 this.appendDummyInput()
261 .appendField("を比較し変化がある場合は通知要求");
262 this.setInputsInline(true);
263 this.setPreviousStatement(true, null);
264 this.setNextStatement(true, null);
265 this.setColour(230);
266 this.setTooltip("");
267 this.setHelpUrl("http://www.example.com/");
268 }
269
270 public void onchange(object ev)
271 {
272 if (GetInputName() == "SET") {
273 setWarningText(null);
274 }
275 else {
276 setWarningText("プロパティ設定ブロックのみで使用します");
277 }
278 }
279 }
280
281 public class EcnlDataToNumberBlock : EcnlPropertyLocalBlock
282 {
283 public const string type_name = "data_to_number";
284
285 public EcnlDataToNumberBlock()
286 : base(type_name)
287 {
288 }
289
290 public void init()
291 {
292 this.appendValueInput("POSITION")
293 .setCheck("Number")
294 .appendField("受信データの");
295 this.appendDummyInput()
296 .appendField("Byte目から")
297 .appendField(new FieldDropdown(new[] {
298 new [] { "1", "BYTE" },
299 new [] { "2", "SHORT" },
300 new [] { "4", "INT" }
301 }), "WIDTH")
302 .appendField("Byte分の数値");
303 this.setInputsInline(true);
304 this.setOutput(true, "Number");
305 this.setColour(230);
306 this.setTooltip("");
307 this.setHelpUrl("http://www.example.com/");
308 }
309
310 public void onchange(object ev)
311 {
312 if (GetInputName() == "SET") {
313 setWarningText(null);
314 }
315 else {
316 setWarningText("プロパティ設定ブロックのみで使用します");
317 }
318 }
319 }
320
321 public class EcnlNumberToDataBlock : EcnlPropertyLocalBlock
322 {
323 public const string type_name = "number_to_data";
324
325 public EcnlNumberToDataBlock()
326 : base(type_name)
327 {
328 }
329
330 public void init()
331 {
332 this.appendValueInput("POSITION")
333 .setCheck("Number")
334 .appendField("送信データの");
335 this.appendDummyInput()
336 .appendField("Byte目から")
337 .appendField(new FieldDropdown(new[] {
338 new [] { "1", "BYTE" },
339 new [] { "2", "SHORT" },
340 new [] { "4", "INT" }
341 }), "WIDTH")
342 .appendField("Byte分に");
343 this.appendValueInput("VALUE")
344 .setCheck("Number");
345 this.appendDummyInput()
346 .appendField("を書き込み");
347 this.setInputsInline(true);
348 this.setPreviousStatement(true, null);
349 this.setNextStatement(true, null);
350 this.setColour(230);
351 this.setTooltip("");
352 this.setHelpUrl("http://www.example.com/");
353 }
354
355 public void onchange(object ev)
356 {
357 if (GetInputName() == "GET") {
358 setWarningText(null);
359 }
360 else {
361 setWarningText("プロパティ取得アクセスブロックのみで使用します");
362 }
363 }
364 }
365
366 public class EcnlNoOpBlock : EcnlPropertyLocalBlock
367 {
368 public const string type_name = "no_op";
369
370 public EcnlNoOpBlock()
371 : base(type_name)
372 {
373 }
374
375 public void init()
376 {
377 this.appendDummyInput()
378 .appendField("処理無し");
379 this.setPreviousStatement(true, null);
380 this.setColour(230);
381 this.setTooltip("");
382 this.setHelpUrl("http://www.example.com/");
383 }
384
385 public void onchange(object ev)
386 {
387 if (!String.IsNullOrEmpty(GetInputName())) {
388 setWarningText(null);
389 }
390 else {
391 setWarningText("プロパティアクセスブロックのみで使用します");
392 }
393 }
394 }
395
396 public class EcnlReceivedDataBlock : EcnlPropertyLocalBlock
397 {
398 public const string type_name = "received_data";
399
400 public EcnlReceivedDataBlock()
401 : base(type_name)
402 {
403 }
404
405 public void init()
406 {
407 this.appendDummyInput()
408 .appendField("受信データ");
409 this.setOutput(true, "String");
410 this.setColour(230);
411 this.setTooltip("");
412 this.setHelpUrl("http://www.example.com/");
413 }
414
415 public void onchange(object ev)
416 {
417 if (GetInputName() == "SET") {
418 setWarningText(null);
419 }
420 else {
421 setWarningText("プロパティ設定ブロックのみで使用します");
422 }
423 }
424 }
425
426 public class EcnlReceivedDataSizeBlock : EcnlPropertyLocalBlock
427 {
428 public const string type_name = "received_data_size";
429
430 public EcnlReceivedDataSizeBlock()
431 : base(type_name)
432 {
433 }
434
435 public void init()
436 {
437 this.appendDummyInput()
438 .appendField("受信データサイズ");
439 this.setOutput(true, "Number");
440 this.setColour(230);
441 this.setTooltip("");
442 this.setHelpUrl("http://www.example.com/");
443 }
444
445 public void onchange(object ev)
446 {
447 if (!String.IsNullOrEmpty(GetInputName())) {
448 setWarningText(null);
449 }
450 else {
451 setWarningText("プロパティアクセスブロックのみで使用します");
452 }
453 }
454 }
455
456 public class DataJoinBlock : Block
457 {
458 public const string type_name = "data_join";
459 internal int itemCount_;
460
461 public DataJoinBlock()
462 : base(type_name)
463 {
464 }
465
466 public void init()
467 {
468 this.itemCount_ = 2;
469 this.updateShape_();
470 this.setOutput(true, "String");
471 this.setMutator(new Mutator(new[] { DataCreateJoinItemBlock.type_name }));
472 this.setColour(230);
473 this.setTooltip("");
474 this.setHelpUrl("http://www.example.com/");
475 }
476
477 public Element mutationToDom()
478 {
479 var container = Document.CreateElement("mutation");
480 container.SetAttribute("items", this.itemCount_.ToString());
481 return container;
482 }
483
484 public void domToMutation(Element xmlElement)
485 {
486 var count = xmlElement.GetAttribute("items");
487 this.itemCount_ = count == null ? 0 : Script.ParseInt(count, 10);
488 this.updateShape_();
489 }
490
491 public Block decompose(Workspace workspace)
492 {
493 var containerBlock = workspace.newBlock(DataCreateJoinContainerBlock.type_name);
494 containerBlock.initSvg();
495 var connection = containerBlock.getInput("STACK").connection;
496 for (var i = 0; i < this.itemCount_; i++) {
497 var itemBlock = workspace.newBlock(DataCreateJoinItemBlock.type_name);
498 itemBlock.initSvg();
499 connection.connect(itemBlock.previousConnection);
500 connection = itemBlock.nextConnection;
501 }
502 return containerBlock;
503 }
504
505 public void compose(Block containerBlock)
506 {
507 var itemBlock = (DataCreateJoinItemBlock)containerBlock.getInputTargetBlock("STACK");
508 var connections = new Connection[0];
509 while (itemBlock != null) {
510 connections.Push(itemBlock.valueConnection_);
511 itemBlock = (itemBlock.nextConnection != null) ?
512 (DataCreateJoinItemBlock)itemBlock.nextConnection.targetBlock() : null;
513 }
514 for (var i = 0; i < this.itemCount_; i++) {
515 var connection = this.getInput("ADD" + i).connection.targetConnection;
516 if (connection != null && Array.IndexOf(connections, connection) == -1) {
517 connection.disconnect();
518 }
519 }
520 this.itemCount_ = connections.Length;
521 this.updateShape_();
522 for (var i = 0; i < this.itemCount_; i++) {
523 Mutator.reconnect(connections[i], this, "ADD" + i);
524 }
525 }
526
527 public void saveConnections(Block containerBlock)
528 {
529 var itemBlock = (DataCreateJoinItemBlock)containerBlock.getInputTargetBlock("STACK");
530 var i = 0;
531 while (itemBlock != null) {
532 var input = this.getInput("ADD" + i);
533 itemBlock.valueConnection_ = (input != null) ?
534 input.connection.targetConnection : null;
535 i++;
536 itemBlock = (itemBlock.nextConnection != null) ?
537 (DataCreateJoinItemBlock)itemBlock.nextConnection.targetBlock() : null;
538 }
539 }
540
541 private void updateShape_()
542 {
543 if (this.itemCount_ != 0 && this.getInput("EMPTY") != null) {
544 this.removeInput("EMPTY");
545 }
546 else if (this.itemCount_ == 0 && this.getInput("EMPTY") == null) {
547 this.appendDummyInput("EMPTY")
548 .appendField("空のデータを作ります");
549 }
550 int i;
551 for (i = 0; i < this.itemCount_; i++) {
552 if (this.getInput("ADD" + i) == null) {
553 var input = this.appendValueInput("ADD" + i);
554 if (i == 0) {
555 input.appendField("データを作ります");
556 }
557 }
558 }
559 while (this.getInput("ADD" + i) != null) {
560 this.removeInput("ADD" + i);
561 i++;
562 }
563 }
564 }
565
566 public class DataCreateJoinContainerBlock : Block
567 {
568 public const string type_name = "data_create_join_container";
569
570 public DataCreateJoinContainerBlock()
571 : base(type_name)
572 {
573 }
574
575 public void init()
576 {
577 this.appendDummyInput()
578 .appendField("結合");
579 this.appendStatementInput("STACK");
580 this.setColour(230);
581 this.setTooltip("");
582 this.contextMenu = false;
583 }
584 }
585
586 [IgnoreCast]
587 public class DataCreateJoinItemBlock : Block
588 {
589 public const string type_name = "data_create_join_item";
590 public Connection valueConnection_;
591
592 public DataCreateJoinItemBlock()
593 : base(type_name)
594 {
595 }
596
597 public void init()
598 {
599 this.appendDummyInput()
600 .appendField("項目");
601 this.setPreviousStatement(true);
602 this.setNextStatement(true);
603 this.setColour(230);
604 this.setTooltip("");
605 this.contextMenu = false;
606 }
607 }
608
609
610 public class CreateEsvGetBlock : Block
611 {
612 public const string type_name = "create_esv_get";
613
614 public CreateEsvGetBlock()
615 : base(type_name)
616 {
617 }
618
619 public void init()
620 {
621 this.jsonInit(new {
622 message0 = "%1 電文の作成 %2 プロパティコード %3",
623 args0 = new object[] {
624 new {
625 type = "field_dropdown",
626 name = "TYPE",
627 options = new [] {
628 new [] { "読み出し要求", "esv_get" },
629 new [] { "通知要求", "esv_inf_req" }
630 }
631 },
632 new {
633 type = "input_dummy"
634 },
635 new {
636 type = "input_value",
637 name = "EPC",
638 check = "Number",
639 align = "RIGHT"
640 }
641 },
642 output = "EData",
643 colour = 230,
644 tooltip = "",
645 helpUrl = "http://www.example.com/"
646 });
647 }
648 }
649
650 public class CreateEsvSetBlock : Block
651 {
652 public const string type_name = "create_esv_set";
653
654 public CreateEsvSetBlock()
655 : base(type_name)
656 {
657 }
658
659 public void init()
660 {
661 this.jsonInit(new {
662 message0 = "%1 電文の作成 %2 プロパティコード %3 プロパティ値 %4",
663 args0 = new object[] {
664 new {
665 type = "field_dropdown",
666 name = "TYPE",
667 options = new [] {
668 new [] { "書き込み要求(応答不要)", "esv_set_i" },
669 new [] { "書き込み要求(応答要)", "esv_set_c" },
670 new [] { "書き込み・読み出し要求", "esv_set_get" },
671 new [] { "通知(応答要)", "esv_infc" }
672 }
673 },
674 new {
675 type = "input_dummy"
676 },
677 new {
678 type = "input_value",
679 name = "EPC",
680 check = "Number",
681 align = "RIGHT"
682 },
683 new {
684 type = "input_value",
685 name = "EDT",
686 check = "String",
687 align = "RIGHT"
688 }
689 },
690 output = "EData",
691 colour = 230,
692 tooltip = "",
693 helpUrl = "http://www.example.com/"
694 });
695 }
696 }
697
698 public class EsvAddEdtBlock : Block
699 {
700 public const string type_name = "esv_add_edt";
701
702 public EsvAddEdtBlock()
703 : base(type_name)
704 {
705 }
706
707 public void init()
708 {
709 this.jsonInit(new {
710 message0 = "%1 に %2 %3 として %4 %5 を追加",
711 args0 = new object[] {
712 new {
713 type = "field_variable",
714 name = "ESV",
715 variable = "item"
716 },
717 new {
718 type = "input_dummy"
719 },
720 new {
721 type = "input_value",
722 name = "EPC",
723 check = "Number"
724 },
725 new {
726 type = "input_dummy"
727 },
728 new {
729 type = "input_value",
730 name = "EDT",
731 check = "String"
732 }
733 },
734 previousStatement = (Union<string, string[]>)null,
735 nextStatement = (Union<string, string[]>)null,
736 colour = 230,
737 tooltip = "",
738 helpUrl = "http://www.example.com/"
739 });
740 }
741 }
742
743 public class EsvAddEpcBlock : Block
744 {
745 public const string type_name = "esv_add_epc";
746
747 public EsvAddEpcBlock()
748 : base(type_name)
749 {
750 }
751
752 public void init()
753 {
754 this.jsonInit(new {
755 message0 = "%1 に %2 %3 を追加",
756 args0 = new object[] {
757 new {
758 type = "field_variable",
759 name = "ESV",
760 variable = "item"
761 },
762 new {
763 type = "input_dummy"
764 },
765 new {
766 type = "input_value",
767 name = "EPC",
768 check = "Number"
769 }
770 },
771 previousStatement = (Union<string, string[]>)null,
772 nextStatement = (Union<string, string[]>)null,
773 colour = 230,
774 tooltip = "",
775 helpUrl = "http://www.example.com/"
776 });
777 }
778 }
779
780 public class SendEsvBlock : Block
781 {
782 public const string type_name = "send_esv";
783
784 public SendEsvBlock()
785 : base(type_name)
786 {
787 }
788
789 public void init()
790 {
791 this.jsonInit(new {
792 message0 = "%1 を送信",
793 args0 = new object[] {
794 new {
795 type = "field_variable",
796 name = "ESV",
797 variable = "item"
798 }
799 },
800 previousStatement = (Union<string, string[]>)null,
801 nextStatement = (Union<string, string[]>)null,
802 colour = 230,
803 tooltip = "",
804 helpUrl = "http://www.example.com/"
805 });
806 }
807 }
808
809 public class ReleaseEsvBlock : Block
810 {
811 public const string type_name = "release_esv";
812
813 public ReleaseEsvBlock()
814 : base(type_name)
815 {
816 }
817
818 public void init()
819 {
820 this.jsonInit(new {
821 message0 = "%1 を破棄",
822 args0 = new object[] {
823 new {
824 type = "field_variable",
825 name = "ESV",
826 variable = "item"
827 }
828 },
829 previousStatement = (Union<string, string[]>)null,
830 nextStatement = (Union<string, string[]>)null,
831 colour = 230,
832 tooltip = "",
833 helpUrl = "http://www.example.com/"
834 });
835 }
836 }
837
838 public class NotifyInitialEsvBlock : Block
839 {
840 public const string type_name = "notify_initial_esv";
841
842 public NotifyInitialEsvBlock()
843 : base(type_name)
844 {
845 }
846
847 public void init()
848 {
849 this.jsonInit(new {
850 message0 = "インスタンスリスト通知の送信",
851 previousStatement = (Union<string, string[]>)null,
852 nextStatement = (Union<string, string[]>)null,
853 colour = 230,
854 tooltip = "",
855 helpUrl = "http://www.example.com/"
856 });
857 }
858 }
859
860 public class EsvGetEsvBlock : Block
861 {
862 public const string type_name = "esv_get_esv";
863
864 public EsvGetEsvBlock()
865 : base(type_name)
866 {
867 }
868
869
870 public void init()
871 {
872 this.jsonInit(new {
873 message0 = "%1 のサービスコード",
874 args0 = new object[] {
875 new {
876 type = "field_variable",
877 name = "ESV",
878 variable = "item"
879 }
880 },
881 output = "Number",
882 colour = 230,
883 tooltip = "",
884 helpUrl = "http://www.example.com/"
885 });
886 }
887 }
888
889 public class EsvIterateBlock : Block
890 {
891 public const string type_name = "esv_iterate";
892
893 public EsvIterateBlock()
894 : base(type_name)
895 {
896 }
897
898 public void init()
899 {
900 this.jsonInit(new {
901 message0 = "%1 にある要素で繰り返し %2 %3",
902 args0 = new object[] {
903 new {
904 type = "field_variable",
905 name = "ESV",
906 variable = "item"
907 },
908 new {
909 type = "input_dummy"
910 },
911 new {
912 type = "input_statement",
913 name = "DO"
914 }
915 },
916 previousStatement = (Union<string, string[]>)null,
917 nextStatement = (Union<string, string[]>)null,
918 colour = 230,
919 tooltip = "",
920 helpUrl = "http://www.example.com/"
921 });
922 }
923 }
924
925 public class EsvIteratorBlock : Block
926 {
927 public const string type_name = "esv_iterator";
928
929 public EsvIteratorBlock()
930 : base(type_name)
931 {
932 }
933
934 public void init()
935 {
936 this.jsonInit(new {
937 message0 = "%1",
938 args0 = new object[] {
939 new {
940 type = "field_dropdown",
941 name = "ITEM",
942 options = new [] {
943 new [] { "プロパティコード", "epc" },
944 new [] { "プロパティ値", "edt" },
945 new [] { "要素の番号", "state" }
946 }
947 }
948 },
949 output = "Number",
950 colour = 230,
951 tooltip = "",
952 helpUrl = "http://www.example.com/"
953 });
954 }
955 }
956
957 public class SvctaskSetTimerBlock : Block
958 {
959 public const string type_name = "svctask_set_timer";
960
961 public SvctaskSetTimerBlock()
962 : base(type_name)
963 {
964 }
965
966 public void init()
967 {
968 this.jsonInit(new {
969 message0 = "%1 %2 のタイマーを %3 [ms]に設定",
970 args0 = new object[] {
971 new {
972 type = "field_variable",
973 name = "SVC",
974 variable = "item"
975 },
976 new {
977 type = "input_dummy"
978 },
979 new {
980 type = "input_value",
981 name = "TIMER",
982 check = "Number"
983 }
984 },
985 colour = 230,
986 tooltip = "",
987 helpUrl = "http://www.example.com/"
988 });
989 }
990 }
991
992 public class SvctaskTimerBlock : Block
993 {
994 public const string type_name = "svctask_timer";
995
996 public SvctaskTimerBlock()
997 : base(type_name)
998 {
999 }
1000
1001 public void init()
1002 {
1003 this.jsonInit(new {
1004 message0 = "%1 のタイマー値",
1005 args0 = new object[] {
1006 new {
1007 type = "field_variable",
1008 name = "SVC",
1009 variable = "item"
1010 }
1011 },
1012 output = "Number",
1013 colour = 230,
1014 tooltip = "",
1015 helpUrl = "http://www.example.com/"
1016 });
1017 }
1018 }
1019
1020 public class SvctaskProgressBlock : Block
1021 {
1022 public const string type_name = "svctask_progress";
1023
1024 public SvctaskProgressBlock()
1025 : base(type_name)
1026 {
1027 }
1028
1029 public void init()
1030 {
1031 this.jsonInit(new {
1032 message0 = "%1 %2 の時間を %3 [ms]経過させる",
1033 args0 = new object[] {
1034 new {
1035 type = "field_variable",
1036 name = "SVC",
1037 variable = "item"
1038 },
1039 new {
1040 type = "input_dummy"
1041 },
1042 new {
1043 type = "input_value",
1044 name = "ELAPSE",
1045 check = "Number"
1046 }
1047 },
1048 previousStatement = (Union<string, string[]>)null,
1049 nextStatement = (Union<string, string[]>)null,
1050 colour = 230,
1051 tooltip = "",
1052 helpUrl = "http://www.example.com/"
1053 });
1054 }
1055 }
1056
1057 public class SvctaskRecvMsgBlock : Block
1058 {
1059 public const string type_name = "svctask_recv_msg";
1060
1061 public SvctaskRecvMsgBlock()
1062 : base(type_name)
1063 {
1064 }
1065
1066 public void init()
1067 {
1068 this.jsonInit(new {
1069 message0 = "%1 に %2 通信端点 %3 からの %4 データ %5 を渡す",
1070 args0 = new object[] {
1071 new {
1072 type = "field_variable",
1073 name = "SVC",
1074 variable = "item"
1075 },
1076 new {
1077 type = "input_dummy"
1078 },
1079 new {
1080 type = "input_value",
1081 name = "ENDPOINT",
1082 check = "String"
1083 },
1084 new {
1085 type = "input_dummy"
1086 },
1087 new {
1088 type = "input_value",
1089 name = "DATA",
1090 check = "String"
1091 }
1092 },
1093 previousStatement = (Union<string, string[]>)null,
1094 nextStatement = (Union<string, string[]>)null,
1095 colour = 230,
1096 tooltip = "",
1097 helpUrl = "http://www.example.com/"
1098 });
1099 }
1100 }
1101
1102 public class SvctaskCallTimeoutBlock : Block
1103 {
1104 public const string type_name = "svctask_call_timeout";
1105
1106 public SvctaskCallTimeoutBlock()
1107 : base(type_name)
1108 {
1109 }
1110
1111 public void init()
1112 {
1113 this.jsonInit(new {
1114 message0 = "%1 のタイムアウト処理を行う",
1115 args0 = new object[] {
1116 new {
1117 type = "field_variable",
1118 name = "SVC",
1119 variable = "item"
1120 }
1121 },
1122 previousStatement = (Union<string, string[]>)null,
1123 nextStatement = (Union<string, string[]>)null,
1124 colour = 230,
1125 tooltip = "",
1126 helpUrl = "http://www.example.com/"
1127 });
1128 }
1129 }
1130
1131 public class SvctaskIsMatchBlock : Block
1132 {
1133 public const string type_name = "svctask_is_match";
1134
1135 public SvctaskIsMatchBlock()
1136 : base(type_name)
1137 {
1138 }
1139
1140 public void init()
1141 {
1142 this.jsonInit(new {
1143 message0 = "%1 で %2 ノード %3 は %4 通信端点 %5 と %6 電文 %7 に対応している",
1144 args0 = new object[] {
1145 new {
1146 type = "field_variable",
1147 name = "SVC",
1148 variable = "item"
1149 },
1150 new {
1151 type = "input_dummy"
1152 },
1153 new {
1154 type = "input_value",
1155 name = "NODE",
1156 check = "EObject"
1157 },
1158 new {
1159 type = "input_dummy"
1160 },
1161 new {
1162 type = "input_value",
1163 name = "ENDPOINT",
1164 check = "String"
1165 },
1166 new {
1167 type = "input_dummy"
1168 },
1169 new {
1170 type = "input_value",
1171 name = "EDTAT",
1172 check = "String"
1173 }
1174 },
1175 output = "Boolean",
1176 colour = 230,
1177 tooltip = "",
1178 helpUrl = "http://www.example.com/"
1179 });
1180 }
1181 }
1182
1183 partial class Ruby
1184 {
1185 public node property_attribute(EcnlPropertyAttributeBlock block)
1186 {
1187 var value = block.getFieldValue("VALUE");
1188 var ecnl = new const_node(this, intern("ECNL"));
1189 return new colon2_node(this, ecnl, intern(value));
1190 }
1191
1192 public node service_code(EcnlServiceCodeBlock block)
1193 {
1194 var value = block.getFieldValue("VALUE");
1195 var ecnl = new const_node(this, intern("ECNL"));
1196 return new colon2_node(this, ecnl, intern(value));
1197 }
1198
1199 public node node_id(EcnlNodeIDBlock block)
1200 {
1201 var value = block.getFieldValue("VALUE");
1202 var ecnl = new const_node(this, intern("ECNL"));
1203 return new colon2_node(this, ecnl, intern(value));
1204 }
1205
1206 public node get_property_info(EcnlGetPropertyInfoBlock block)
1207 {
1208 var member = block.getFieldValue("MEMBER");
1209 var prop = new lvar_node(this, local_add_f("prop"));
1210 return new call_node(this, prop, intern(member));
1211 }
1212
1213 public node save_received_property(EcnlSaveReceivedPropertyBlock block)
1214 {
1215 var src = new lvar_node(this, local_add_f("src"));
1216 var prop = new lvar_node(this, local_add_f("prop"));
1217 return new call_node(this, prop, intern("set_exinf"), new node[] { src });
1218 }
1219
1220 public node get_saved_property(EcnlGetSavedPropertyBlock block)
1221 {
1222 var prop = new lvar_node(this, local_add_f("prop"));
1223 return new call_node(this, prop, intern("exinf"));
1224 }
1225
1226 public node set_announce_request(EcnlSetAnnounceRequestBlock block)
1227 {
1228 // if (prop.anno)
1229 // prop.set_anno(data != src)
1230 // end
1231 var prop = new lvar_node(this, local_add_f("prop"));
1232 var cond = new call_node(this, prop, intern("anno"));
1233 var data = valueToCode(block, "DATA");
1234 var src = new lvar_node(this, local_add_f("src"));
1235 var arg = new call_node(this, data, intern("!="), src);
1236 var then = new call_node(this, prop, intern("set_exinf"), new node[] { arg });
1237 return new if_node(this, cond, then, null, false);
1238 }
1239
1240 public node data_to_number(EcnlDataToNumberBlock block)
1241 {
1242 var value_position = valueToCode(block, "POSITION");
1243 var dropdown_width = block.getFieldValue("WIDTH");
1244 var src = new lvar_node(this, local_add_f("src"));
1245
1246 switch (dropdown_width) {
1247 case "BYTE":
1248 return new call_node(this, src, intern("getbyte"), new node[] { value_position });
1249 case "SHORT":
1250 return new fcall_node(this, intern("ecnl_getshort"), new node[] { src, value_position });
1251 case "INT":
1252 return new fcall_node(this, intern("ecnl_getint"), new node[] { src, value_position });
1253 }
1254
1255 throw new NotImplementedException();
1256 }
1257
1258 public node number_to_data(EcnlNumberToDataBlock block)
1259 {
1260 var value_position = valueToCode(block, "POSITION");
1261 var dropdown_width = block.getFieldValue("WIDTH");
1262 var value_value = valueToCode(block, "VALUE");
1263 var src = new lvar_node(this, local_add_f("src"));
1264
1265 switch (dropdown_width) {
1266 case "BYTE":
1267 return new call_node(this, src, intern("setbyte"), new node[] { value_position, value_value });
1268 case "SHORT":
1269 return new fcall_node(this, intern("ecnl_setshort"), new node[] { src, value_position, value_value });
1270 case "INT":
1271 return new fcall_node(this, intern("ecnl_setint"), new node[] { src, value_position, value_value });
1272 }
1273
1274 throw new NotImplementedException();
1275 }
1276
1277 public node no_op(EcnlNoOpBlock block)
1278 {
1279 switch (block.GetInputName()) {
1280 case "SET":
1281 return new return_node(this, new int_node(this, 0));
1282 case "GET":
1283 return new return_node(this, new str_node(this, ""));
1284 }
1285 return new return_node(this, null);
1286 }
1287
1288 public node received_data(EcnlReceivedDataBlock block)
1289 {
1290 return new lvar_node(this, local_add_f("src"));
1291 }
1292
1293 public node received_data_size(EcnlReceivedDataSizeBlock block)
1294 {
1295 switch (block.GetInputName()) {
1296 case "SET":
1297 case "SET_RET":
1298 var src = new lvar_node(this, local_add_f("src"));
1299 return new call_node(this, src, intern("bytesize"));
1300 case "GET":
1301 return new lvar_node(this, local_add_f("size"));
1302 }
1303 return new int_node(this, 0);
1304 }
1305
1306 public node data_join(DataJoinBlock block)
1307 {
1308 if (block.itemCount_ == 0) {
1309 return new str_node(this, "");
1310 }
1311 else if (block.itemCount_ == 1) {
1312 var argument0 = valueToCode(block, "ADD0");
1313 if (argument0 == null) argument0 = new str_node(this, "");
1314 return new call_node(this, argument0, intern("chr"));
1315 }
1316 else if (block.itemCount_ == 2) {
1317 var argument0 = valueToCode(block, "ADD0");
1318 if (argument0 == null) argument0 = new str_node(this, "");
1319 argument0 = new call_node(this, argument0, intern("chr"));
1320 var argument1 = valueToCode(block, "ADD1");
1321 if (argument1 == null) argument1 = new str_node(this, "");
1322 argument1 = new call_node(this, argument1, intern("chr"));
1323 return new call_node(this, argument0, intern("+"), new node[] { argument1 });
1324 }
1325 else {
1326 var codes = valueToCode(block, "ADD0");
1327 var argument0 = codes;
1328 if (argument0 == null) argument0 = new str_node(this, "");
1329 argument0 = new call_node(this, argument0, intern("chr"));
1330 for (var n = 1; n < block.itemCount_; n++) {
1331 var argument1 = valueToCode(block, "ADD" + n);
1332 if (argument1 == null) argument1 = new str_node(this, "");
1333 argument1 = new call_node(this, argument1, intern("chr"));
1334 argument0 = new call_node(this, argument0, intern("+"), new node[] { argument1 });
1335 }
1336 return codes;
1337 }
1338 }
1339
1340 public node create_esv_get(CreateEsvGetBlock block)
1341 {
1342 var dropdown_type = block.getFieldValue("TYPE");
1343 var value_epc = valueToCode(block, "EPC");
1344 var nil = new nil_node(this);
1345 // nilにはリモートノードを指定できる
1346 return new fcall_node(this, intern(dropdown_type), new node[] { nil, value_epc });
1347 }
1348
1349 public node create_esv_set(CreateEsvSetBlock block)
1350 {
1351 var dropdown_type = block.getFieldValue("TYPE");
1352 var value_epc = valueToCode(block, "EPC");
1353 var value_edt = valueToCode(block, "EDT");
1354 var nil = new nil_node(this);
1355 // nilにはリモートノードを指定できる
1356 return new fcall_node(this, intern(dropdown_type), new node[] { nil, value_epc, value_edt });
1357 }
1358
1359 public node esv_add_edt(EsvAddEdtBlock block)
1360 {
1361 var variable_esv = new_var_node(get_var_name(block.getFieldValue("ESV")));
1362 var value_epc = valueToCode(block, "EPC");
1363 var value_edt = valueToCode(block, "EDT");
1364 return new call_node(this, variable_esv, intern("add_edt"), new node[] { value_epc, value_edt });
1365 }
1366
1367 public node esv_add_epc(EsvAddEpcBlock block)
1368 {
1369 var variable_esv = new_var_node(get_var_name(block.getFieldValue("ESV")));
1370 var value_epc = valueToCode(block, "EPC");
1371 return new call_node(this, variable_esv, intern("add_epc"), new node[] { value_epc });
1372 }
1373
1374 public node send_esv(SendEsvBlock block)
1375 {
1376 var variable_esv = new_var_node(get_var_name(block.getFieldValue("ESV")));
1377 return new fcall_node(this, intern("snd_esv"), new node[] { variable_esv });
1378 }
1379
1380 public node release_esv(ReleaseEsvBlock block)
1381 {
1382 var variable_esv = new_var_node(get_var_name(block.getFieldValue("ESV")));
1383 return new fcall_node(this, intern("rel_esv"), new node[] { variable_esv });
1384 }
1385
1386 public node notify_initial_esv(NotifyInitialEsvBlock block)
1387 {
1388 return new fcall_node(this, intern("ntf_inl"));
1389 }
1390
1391 public node esv_get_esv(EsvGetEsvBlock block)
1392 {
1393 var variable_esv = new_var_node(get_var_name(block.getFieldValue("ESV")));
1394 return new call_node(this, variable_esv, intern("esv"));
1395 }
1396
1397 public node esv_iterate(EsvIterateBlock block)
1398 {
1399 var variable_esv = new_var_node(get_var_name(block.getFieldValue("ESV")));
1400 local_nest();
1401 var statements_do = statementToCode(block, "DO");
1402 var itr = new arg_node(this, local_add_f("itr"));
1403 var proc = new block_node(this, new node[] { itr }, statements_do, false);
1404 local_unnest();
1405 return new fcall_node(this, intern("ecnl_esv_iterate"), new node[] { variable_esv }, proc);
1406 }
1407
1408 public node esv_iterator(EsvIteratorBlock block)
1409 {
1410 var dropdown_item = block.getFieldValue("ITEM");
1411 var itr = new lvar_node(this, local_add_f("itr"));
1412 return new call_node(this, itr, intern(dropdown_item));
1413 }
1414
1415 public node svctask_set_timer(SvctaskSetTimerBlock block)
1416 {
1417 var variable_svc = new_var_node(get_var_name(block.getFieldValue("SVC")));
1418 var value_timer = valueToCode(block, "TIMER");
1419 return new call_node(this, variable_svc, intern("set_timer"), new node[] { value_timer });
1420 }
1421
1422 public node svctask_timer(SvctaskTimerBlock block)
1423 {
1424 var variable_svc = new_var_node(get_var_name(block.getFieldValue("SVC")));
1425 return new call_node(this, variable_svc, intern("timer"));
1426 }
1427
1428 public node svctask_progress(SvctaskProgressBlock block)
1429 {
1430 var variable_svc = new_var_node(get_var_name(block.getFieldValue("SVC")));
1431 var value_elapse = valueToCode(block, "ELAPSE");
1432 return new call_node(this, variable_svc, intern("progress"), new node[] { value_elapse });
1433 }
1434
1435 public node svctask_recv_msg(SvctaskRecvMsgBlock block)
1436 {
1437 var variable_svc = new_var_node(get_var_name(block.getFieldValue("SVC")));
1438 var value_endpoint = valueToCode(block, "ENDPOINT");
1439 var value_data = valueToCode(block, "DATA");
1440 return new call_node(this, variable_svc, intern("recv_msg"), new node[] { value_endpoint, value_data });
1441 }
1442
1443 public node svctask_call_timeout(SvctaskCallTimeoutBlock block)
1444 {
1445 var variable_svc = new_var_node(get_var_name(block.getFieldValue("SVC")));
1446 return new call_node(this, variable_svc, intern("call_timeout"));
1447 }
1448
1449 public node svctask_is_match(SvctaskIsMatchBlock block)
1450 {
1451 var value_node = valueToCode(block, "NODE");
1452 var value_edtat = valueToCode(block, "EDTAT");
1453 var value_endpoint = valueToCode(block, "ENDPOINT");
1454 return new fcall_node(this, intern("is_match"), new node[] { value_node, value_edtat, value_endpoint });
1455 }
1456 }
1457}
Note: See TracBrowser for help on using the repository browser.