RTnoV3 is a program which enables your device to communicate with RT-middleware world 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 06:00:22 2012 +0000
Revision:
0:f9b85e22404a
RTnoV3_Template first commit

Who changed what in which revision?

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