RTno is communicating library and framework which allows you to make your embedded device capable of communicating with RT-middleware world. RT-middleware is a platform software to realize Robotic system. In RTM, robots are developed by constructing robotics technologies\' elements (components) named RT-component. Therefore, the RTno helps you to create your own RT-component with your mbed and arduino. To know how to use your RTno device, visit here: http://ysuga.net/robot_e/rtm_e/rtc_e/1065?lang=en To know about RT-middleware and RT-component, visit http://www.openrtm.org

Dependencies:   EthernetInterface mbed-rtos

Committer:
ysuga
Date:
Mon Jun 24 06:42:11 2013 +0000
Revision:
0:5f7bc45bc2e8
Child:
1:f74116b37bc9
[mbed] converted /RTnoV3/RTnoV3

Who changed what in which revision?

UserRevisionLine numberNew contents of line
ysuga 0:5f7bc45bc2e8 1 #define RTNO_SUBMODULE_DEFINE
ysuga 0:5f7bc45bc2e8 2 #include <stdint.h>
ysuga 0:5f7bc45bc2e8 3 #include "mbed.h"
ysuga 0:5f7bc45bc2e8 4 #include "Transport.h"
ysuga 0:5f7bc45bc2e8 5 #include "Packet.h"
ysuga 0:5f7bc45bc2e8 6
ysuga 0:5f7bc45bc2e8 7 int8_t Transport_init()
ysuga 0:5f7bc45bc2e8 8 {
ysuga 0:5f7bc45bc2e8 9 return 0;
ysuga 0:5f7bc45bc2e8 10 }
ysuga 0:5f7bc45bc2e8 11
ysuga 0:5f7bc45bc2e8 12
ysuga 0:5f7bc45bc2e8 13 int8_t Transport_SendPacket(const char interface, const uint8_t data_length, const int8_t* packet_data) {
ysuga 0:5f7bc45bc2e8 14 uint8_t sum = 0;
ysuga 0:5f7bc45bc2e8 15 uint8_t sender[4] = {'U', 'A', 'R', 'T'};
ysuga 0:5f7bc45bc2e8 16 SerialDevice_putc(interface);
ysuga 0:5f7bc45bc2e8 17 sum += interface;
ysuga 0:5f7bc45bc2e8 18 SerialDevice_putc(data_length);
ysuga 0:5f7bc45bc2e8 19 sum += data_length;
ysuga 0:5f7bc45bc2e8 20
ysuga 0:5f7bc45bc2e8 21 for(uint8_t i = 0;i < 4;i++) {
ysuga 0:5f7bc45bc2e8 22 sum += sender[i];
ysuga 0:5f7bc45bc2e8 23 SerialDevice_putc(sender[i]);
ysuga 0:5f7bc45bc2e8 24 }
ysuga 0:5f7bc45bc2e8 25
ysuga 0:5f7bc45bc2e8 26 for(uint8_t i = 0;i < data_length;i++) {
ysuga 0:5f7bc45bc2e8 27 sum += packet_data[i];
ysuga 0:5f7bc45bc2e8 28 SerialDevice_putc(packet_data[i]);
ysuga 0:5f7bc45bc2e8 29 }
ysuga 0:5f7bc45bc2e8 30 SerialDevice_putc(sum);
ysuga 0:5f7bc45bc2e8 31 return PACKET_HEADER_SIZE + data_length + 1;
ysuga 0:5f7bc45bc2e8 32 }
ysuga 0:5f7bc45bc2e8 33
ysuga 0:5f7bc45bc2e8 34 int8_t Transport_ReceivePacket(int8_t* packet) {
ysuga 0:5f7bc45bc2e8 35 uint8_t counter = 0;
ysuga 0:5f7bc45bc2e8 36 uint8_t sum = 0;
ysuga 0:5f7bc45bc2e8 37
ysuga 0:5f7bc45bc2e8 38 if(SerialDevice_available() == 0) {
ysuga 0:5f7bc45bc2e8 39 return 0;
ysuga 0:5f7bc45bc2e8 40 }
ysuga 0:5f7bc45bc2e8 41
ysuga 0:5f7bc45bc2e8 42 while(SerialDevice_available() < PACKET_HEADER_SIZE) {
ysuga 0:5f7bc45bc2e8 43 wait(PACKET_WAITING_DELAY/1000.0);
ysuga 0:5f7bc45bc2e8 44 counter++;
ysuga 0:5f7bc45bc2e8 45 if(counter == PACKET_WAITING_COUNT) {
ysuga 0:5f7bc45bc2e8 46 return -TIMEOUT;
ysuga 0:5f7bc45bc2e8 47 }
ysuga 0:5f7bc45bc2e8 48 }
ysuga 0:5f7bc45bc2e8 49 packet[INTERFACE] = SerialDevice_getc();
ysuga 0:5f7bc45bc2e8 50 sum += packet[INTERFACE];
ysuga 0:5f7bc45bc2e8 51 packet[DATA_LENGTH] = SerialDevice_getc();
ysuga 0:5f7bc45bc2e8 52 sum += packet[DATA_LENGTH];
ysuga 0:5f7bc45bc2e8 53
ysuga 0:5f7bc45bc2e8 54 counter = 0;
ysuga 0:5f7bc45bc2e8 55 while(SerialDevice_available() < 4) {
ysuga 0:5f7bc45bc2e8 56 wait(PACKET_WAITING_DELAY/1000.0);
ysuga 0:5f7bc45bc2e8 57 counter++;
ysuga 0:5f7bc45bc2e8 58 if(counter == PACKET_WAITING_COUNT) {
ysuga 0:5f7bc45bc2e8 59 return -TIMEOUT;
ysuga 0:5f7bc45bc2e8 60 }
ysuga 0:5f7bc45bc2e8 61 }
ysuga 0:5f7bc45bc2e8 62 for(uint8_t i = 0;i < 4;i++) {
ysuga 0:5f7bc45bc2e8 63 uint8_t val = SerialDevice_getc();
ysuga 0:5f7bc45bc2e8 64 sum += val;
ysuga 0:5f7bc45bc2e8 65 }
ysuga 0:5f7bc45bc2e8 66
ysuga 0:5f7bc45bc2e8 67 for(uint8_t i = 0;i < packet[DATA_LENGTH];i++) {
ysuga 0:5f7bc45bc2e8 68 counter = 0;
ysuga 0:5f7bc45bc2e8 69 while(SerialDevice_available() == 0) {
ysuga 0:5f7bc45bc2e8 70 wait(PACKET_WAITING_DELAY/1000.0);
ysuga 0:5f7bc45bc2e8 71 counter++;
ysuga 0:5f7bc45bc2e8 72 if(counter == PACKET_WAITING_COUNT) {
ysuga 0:5f7bc45bc2e8 73 return -DATA_TIMEOUT;
ysuga 0:5f7bc45bc2e8 74 }
ysuga 0:5f7bc45bc2e8 75 }
ysuga 0:5f7bc45bc2e8 76 packet[PACKET_HEADER_SIZE+i] = SerialDevice_getc();
ysuga 0:5f7bc45bc2e8 77 sum += packet[PACKET_HEADER_SIZE+i];
ysuga 0:5f7bc45bc2e8 78 }
ysuga 0:5f7bc45bc2e8 79
ysuga 0:5f7bc45bc2e8 80 while(SerialDevice_available() == 0) {
ysuga 0:5f7bc45bc2e8 81 ;
ysuga 0:5f7bc45bc2e8 82 }
ysuga 0:5f7bc45bc2e8 83 uint8_t checksum = SerialDevice_getc();
ysuga 0:5f7bc45bc2e8 84
ysuga 0:5f7bc45bc2e8 85 if(sum != checksum) {
ysuga 0:5f7bc45bc2e8 86 return -CHECKSUM_ERROR;
ysuga 0:5f7bc45bc2e8 87 }
ysuga 0:5f7bc45bc2e8 88 return PACKET_HEADER_SIZE + packet[DATA_LENGTH] + 1;
ysuga 0:5f7bc45bc2e8 89 }