RTnoV3 is a program which enables your device to communicate with RT-middleware world This is an example of RTnoV3 with Ethernet Connection. To know RT-middleware, visit: http://www.openrtm.org To know more about RTno, visit: http://ysuga.net/robot_e/rtm_e/rtc_e/1065?lang=en

Dependencies:   EthernetNetIf mbed RTnoV3

Committer:
ysuga
Date:
Thu Feb 09 09:45:13 2012 +0000
Revision:
0:51b3b7776199
This is first publish of RTno V3 Ethernet

Who changed what in which revision?

UserRevisionLine numberNew contents of line
ysuga 0:51b3b7776199 1 #include "mbed.h"
ysuga 0:51b3b7776199 2
ysuga 0:51b3b7776199 3
ysuga 0:51b3b7776199 4
ysuga 0:51b3b7776199 5 /**
ysuga 0:51b3b7776199 6 * RTno_Template.pde
ysuga 0:51b3b7776199 7 * RTno is RT-middleware and arduino.
ysuga 0:51b3b7776199 8 *
ysuga 0:51b3b7776199 9 * Using RTno, arduino device can communicate any RT-components
ysuga 0:51b3b7776199 10 * through the RTno-proxy component which is launched in PC.
ysuga 0:51b3b7776199 11 * Connect arduino with USB, and program with RTno library.
ysuga 0:51b3b7776199 12 * You do not have to define any protocols to establish communication
ysuga 0:51b3b7776199 13 * between arduino and PC.
ysuga 0:51b3b7776199 14 *
ysuga 0:51b3b7776199 15 * Using RTno, you must not define the function "setup" and "loop".
ysuga 0:51b3b7776199 16 * Those functions are automatically defined in the RTno libarary.
ysuga 0:51b3b7776199 17 * You, developers, must define following functions:
ysuga 0:51b3b7776199 18 * int onInitialize(void);
ysuga 0:51b3b7776199 19 * int onActivated(void);
ysuga 0:51b3b7776199 20 * int onDeactivated(void);
ysuga 0:51b3b7776199 21 * int onExecute(void);
ysuga 0:51b3b7776199 22 * int onError(void);
ysuga 0:51b3b7776199 23 * int onReset(void);
ysuga 0:51b3b7776199 24 * These functions are spontaneously called by the RTno-proxy
ysuga 0:51b3b7776199 25 * RT-component which is launched in the PC.
ysuga 0:51b3b7776199 26 * @author Yuki Suga
ysuga 0:51b3b7776199 27 * This code is written/distributed for public-domain.
ysuga 0:51b3b7776199 28 */
ysuga 0:51b3b7776199 29
ysuga 0:51b3b7776199 30 #include <RTno.h>
ysuga 0:51b3b7776199 31
ysuga 0:51b3b7776199 32 /**
ysuga 0:51b3b7776199 33 * This function is called at first.
ysuga 0:51b3b7776199 34 * conf._default.baudrate: baudrate of serial communication
ysuga 0:51b3b7776199 35 * exec_cxt.periodic.type: reserved but not used.
ysuga 0:51b3b7776199 36 */
ysuga 0:51b3b7776199 37 void rtcconf(config_str& conf, exec_cxt_str& exec_cxt) {
ysuga 0:51b3b7776199 38 conf._default.connection_type = ConnectionTypeEtherTcp;
ysuga 0:51b3b7776199 39 conf._default.port = 23;
ysuga 0:51b3b7776199 40 conf._default.mac_address = MACaddr(0xDE, 0xAD, 0xBE, 0xEF, 0xFE, 0xED);
ysuga 0:51b3b7776199 41 conf._default.ip_address = IPaddr(192,168,42,100);
ysuga 0:51b3b7776199 42 conf._default.subnet_mask = IPaddr(255,255,255,0);
ysuga 0:51b3b7776199 43 conf._default.default_gateway = IPaddr(192,168,42,254);
ysuga 0:51b3b7776199 44 // exec_cxt.periodic.type = ProxySynchronousExecutionContext;
ysuga 0:51b3b7776199 45 exec_cxt.periodic.type = Timer1ExecutionContext; // onExecute is called by Timer1. Period must be specified by 'rate' option.
ysuga 0:51b3b7776199 46 exec_cxt.periodic.rate = 100; // [Hz] This option is indispensable when type is Timer*ExecutionContext.
ysuga 0:51b3b7776199 47 }
ysuga 0:51b3b7776199 48
ysuga 0:51b3b7776199 49
ysuga 0:51b3b7776199 50 /**
ysuga 0:51b3b7776199 51 * Declaration Division:
ysuga 0:51b3b7776199 52 *
ysuga 0:51b3b7776199 53 * DataPort and Data Buffer should be placed here.
ysuga 0:51b3b7776199 54 *
ysuga 0:51b3b7776199 55 * available data types are as follows:
ysuga 0:51b3b7776199 56 * TimedLong
ysuga 0:51b3b7776199 57 * TimedDouble
ysuga 0:51b3b7776199 58 * TimedFloat
ysuga 0:51b3b7776199 59 * TimedLongSeq
ysuga 0:51b3b7776199 60 * TimedDoubleSeq
ysuga 0:51b3b7776199 61 * TimedFloatSeq
ysuga 0:51b3b7776199 62 *
ysuga 0:51b3b7776199 63 * Please refer following comments. If you need to use some ports,
ysuga 0:51b3b7776199 64 * uncomment the line you want to declare.
ysuga 0:51b3b7776199 65 **/
ysuga 0:51b3b7776199 66 TimedLong in0;
ysuga 0:51b3b7776199 67 InPort<TimedLong> in0In("in0", in0);
ysuga 0:51b3b7776199 68
ysuga 0:51b3b7776199 69 TimedLong out0;
ysuga 0:51b3b7776199 70 OutPort<TimedLong> out0Out("out0", out0);
ysuga 0:51b3b7776199 71
ysuga 0:51b3b7776199 72 //////////////////////////////////////////
ysuga 0:51b3b7776199 73 // on_initialize
ysuga 0:51b3b7776199 74 //
ysuga 0:51b3b7776199 75 // This function is called in the initialization
ysuga 0:51b3b7776199 76 // sequence. The sequence is triggered by the
ysuga 0:51b3b7776199 77 // PC. When the RTnoRTC is launched in the PC,
ysuga 0:51b3b7776199 78 // then, this function is remotely called
ysuga 0:51b3b7776199 79 // through the USB cable.
ysuga 0:51b3b7776199 80 // In on_initialize, usually DataPorts are added.
ysuga 0:51b3b7776199 81 //
ysuga 0:51b3b7776199 82 //////////////////////////////////////////
ysuga 0:51b3b7776199 83 int RTno::onInitialize() {
ysuga 0:51b3b7776199 84 /* Data Ports are added in this section.
ysuga 0:51b3b7776199 85 */
ysuga 0:51b3b7776199 86 addInPort(in0In);
ysuga 0:51b3b7776199 87 addOutPort(out0Out);
ysuga 0:51b3b7776199 88
ysuga 0:51b3b7776199 89 // Some initialization (like port direction setting)
ysuga 0:51b3b7776199 90 // int LED = 13;
ysuga 0:51b3b7776199 91 return RTC_OK;
ysuga 0:51b3b7776199 92 }
ysuga 0:51b3b7776199 93
ysuga 0:51b3b7776199 94 ////////////////////////////////////////////
ysuga 0:51b3b7776199 95 // on_activated
ysuga 0:51b3b7776199 96 // This function is called when the RTnoRTC
ysuga 0:51b3b7776199 97 // is activated. When the activation, the RTnoRTC
ysuga 0:51b3b7776199 98 // sends message to call this function remotely.
ysuga 0:51b3b7776199 99 // If this function is failed (return value
ysuga 0:51b3b7776199 100 // is RTC_ERROR), RTno will enter ERROR condition.
ysuga 0:51b3b7776199 101 ////////////////////////////////////////////
ysuga 0:51b3b7776199 102 int RTno::onActivated() {
ysuga 0:51b3b7776199 103 // Write here initialization code.
ysuga 0:51b3b7776199 104 return RTC_OK;
ysuga 0:51b3b7776199 105 }
ysuga 0:51b3b7776199 106
ysuga 0:51b3b7776199 107 /////////////////////////////////////////////
ysuga 0:51b3b7776199 108 // on_deactivated
ysuga 0:51b3b7776199 109 // This function is called when the RTnoRTC
ysuga 0:51b3b7776199 110 // is deactivated.
ysuga 0:51b3b7776199 111 /////////////////////////////////////////////
ysuga 0:51b3b7776199 112 int RTno::onDeactivated()
ysuga 0:51b3b7776199 113 {
ysuga 0:51b3b7776199 114 // Write here finalization code.
ysuga 0:51b3b7776199 115 return RTC_OK;
ysuga 0:51b3b7776199 116 }
ysuga 0:51b3b7776199 117
ysuga 0:51b3b7776199 118 //////////////////////////////////////////////
ysuga 0:51b3b7776199 119 // This function is repeatedly called when the
ysuga 0:51b3b7776199 120 // RTno is in the ACTIVE condition.
ysuga 0:51b3b7776199 121 // If this function is failed (return value is
ysuga 0:51b3b7776199 122 // RTC_ERROR), RTno immediately enter into the
ysuga 0:51b3b7776199 123 // ERROR condition.r
ysuga 0:51b3b7776199 124 //////////////////////////////////////////////
ysuga 0:51b3b7776199 125 int RTno::onExecute() {
ysuga 0:51b3b7776199 126 /**
ysuga 0:51b3b7776199 127 * Usage of InPort with premitive type.
ysuga 0:51b3b7776199 128 */
ysuga 0:51b3b7776199 129
ysuga 0:51b3b7776199 130 if(in0In.isNew()) {
ysuga 0:51b3b7776199 131 in0In.read();
ysuga 0:51b3b7776199 132 out0.data = in0.data;
ysuga 0:51b3b7776199 133 out0Out.write();
ysuga 0:51b3b7776199 134 }
ysuga 0:51b3b7776199 135
ysuga 0:51b3b7776199 136
ysuga 0:51b3b7776199 137 return RTC_OK;
ysuga 0:51b3b7776199 138 }
ysuga 0:51b3b7776199 139
ysuga 0:51b3b7776199 140
ysuga 0:51b3b7776199 141 //////////////////////////////////////
ysuga 0:51b3b7776199 142 // on_error
ysuga 0:51b3b7776199 143 // This function is repeatedly called when
ysuga 0:51b3b7776199 144 // the RTno is in the ERROR condition.
ysuga 0:51b3b7776199 145 // The ERROR condition can be recovered,
ysuga 0:51b3b7776199 146 // when the RTno is reset.
ysuga 0:51b3b7776199 147 ///////////////////////////////////////
ysuga 0:51b3b7776199 148 int RTno::onError()
ysuga 0:51b3b7776199 149 {
ysuga 0:51b3b7776199 150 return RTC_OK;
ysuga 0:51b3b7776199 151 }
ysuga 0:51b3b7776199 152
ysuga 0:51b3b7776199 153 ////////////////////////////////////////
ysuga 0:51b3b7776199 154 // This function is called when
ysuga 0:51b3b7776199 155 // the RTno is reset. If on_reset is
ysuga 0:51b3b7776199 156 // succeeded, the RTno will enter into
ysuga 0:51b3b7776199 157 // the INACTIVE condition. If failed
ysuga 0:51b3b7776199 158 // (return value is RTC_ERROR), RTno
ysuga 0:51b3b7776199 159 // will stay in ERROR condition.ec
ysuga 0:51b3b7776199 160 ///////////////////////////////////////
ysuga 0:51b3b7776199 161 int RTno::onReset()
ysuga 0:51b3b7776199 162 {
ysuga 0:51b3b7776199 163 return RTC_OK;
ysuga 0:51b3b7776199 164 }