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:
Thu Aug 29 05:29:55 2013 +0000
Revision:
7:6c7af1d50fb3
Parent:
1:f74116b37bc9
update v5

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 1:f74116b37bc9 4
ysuga 0:5f7bc45bc2e8 5 #include "Transport.h"
ysuga 0:5f7bc45bc2e8 6 #include "Packet.h"
ysuga 0:5f7bc45bc2e8 7
ysuga 0:5f7bc45bc2e8 8 int8_t Transport_init()
ysuga 0:5f7bc45bc2e8 9 {
ysuga 0:5f7bc45bc2e8 10 return 0;
ysuga 0:5f7bc45bc2e8 11 }
ysuga 0:5f7bc45bc2e8 12
ysuga 0:5f7bc45bc2e8 13
ysuga 0:5f7bc45bc2e8 14 int8_t Transport_SendPacket(const char interface, const uint8_t data_length, const int8_t* packet_data) {
ysuga 1:f74116b37bc9 15 uint8_t sum = 0;//0x0a + 0x0a;
ysuga 1:f74116b37bc9 16
ysuga 1:f74116b37bc9 17 uint8_t header[2] = {0x0a, 0x0a};
ysuga 1:f74116b37bc9 18 SerialDevice_putc(header[0]);
ysuga 1:f74116b37bc9 19 SerialDevice_putc(header[1]);
ysuga 1:f74116b37bc9 20
ysuga 0:5f7bc45bc2e8 21 SerialDevice_putc(interface);
ysuga 0:5f7bc45bc2e8 22 sum += interface;
ysuga 0:5f7bc45bc2e8 23 SerialDevice_putc(data_length);
ysuga 0:5f7bc45bc2e8 24 sum += data_length;
ysuga 0:5f7bc45bc2e8 25
ysuga 1:f74116b37bc9 26 //uint8_t sender[4] = {'U', 'A', 'R', 'T'};
ysuga 1:f74116b37bc9 27 //for(uint8_t i = 0;i < 4;i++) {
ysuga 1:f74116b37bc9 28 //sum += sender[i];
ysuga 1:f74116b37bc9 29 // SerialDevice_putc(sender[i]);
ysuga 1:f74116b37bc9 30 //}
ysuga 0:5f7bc45bc2e8 31
ysuga 0:5f7bc45bc2e8 32 for(uint8_t i = 0;i < data_length;i++) {
ysuga 0:5f7bc45bc2e8 33 sum += packet_data[i];
ysuga 0:5f7bc45bc2e8 34 SerialDevice_putc(packet_data[i]);
ysuga 0:5f7bc45bc2e8 35 }
ysuga 0:5f7bc45bc2e8 36 SerialDevice_putc(sum);
ysuga 0:5f7bc45bc2e8 37 return PACKET_HEADER_SIZE + data_length + 1;
ysuga 0:5f7bc45bc2e8 38 }
ysuga 0:5f7bc45bc2e8 39
ysuga 1:f74116b37bc9 40 /**
ysuga 1:f74116b37bc9 41 * Transport_ReceivePacket
ysuga 1:f74116b37bc9 42 * ¥arg packet
ysuga 1:f74116b37bc9 43 * ¥arg timeout
ysuga 1:f74116b37bc9 44 */
ysuga 1:f74116b37bc9 45 int8_t Transport_ReceivePacket(uint8_t* packet, const uint32_t& timeout) {
ysuga 0:5f7bc45bc2e8 46 uint8_t counter = 0;
ysuga 1:f74116b37bc9 47 uint8_t buf;
ysuga 1:f74116b37bc9 48 int8_t ret;
ysuga 1:f74116b37bc9 49 while(1) {
ysuga 1:f74116b37bc9 50 if((ret=SerialDevice_read(&buf, 1, timeout)) < 0) {
ysuga 1:f74116b37bc9 51 return 0;
ysuga 0:5f7bc45bc2e8 52 }
ysuga 1:f74116b37bc9 53 if (buf != PACKET_STARTING_CHARACTOR_0) {
ysuga 1:f74116b37bc9 54 counter++;
ysuga 1:f74116b37bc9 55 continue;
ysuga 1:f74116b37bc9 56 }
ysuga 1:f74116b37bc9 57 if((ret=SerialDevice_read(&buf, 1, timeout)) < 0) {
ysuga 1:f74116b37bc9 58 return 0;
ysuga 0:5f7bc45bc2e8 59 }
ysuga 1:f74116b37bc9 60 if (buf != PACKET_STARTING_CHARACTOR_1) {
ysuga 0:5f7bc45bc2e8 61 counter++;
ysuga 1:f74116b37bc9 62 continue;
ysuga 0:5f7bc45bc2e8 63 }
ysuga 1:f74116b37bc9 64 break;
ysuga 0:5f7bc45bc2e8 65 }
ysuga 0:5f7bc45bc2e8 66
ysuga 1:f74116b37bc9 67
ysuga 1:f74116b37bc9 68 if((ret=SerialDevice_read(packet, PACKET_HEADER_SIZE, timeout)) < 0) {
ysuga 1:f74116b37bc9 69 return ret;
ysuga 1:f74116b37bc9 70 }
ysuga 1:f74116b37bc9 71
ysuga 1:f74116b37bc9 72 //if((ret=SerialDevice_read(packet+PACKET_HEADER_SIZE,
ysuga 1:f74116b37bc9 73 // 4,
ysuga 1:f74116b37bc9 74 // timeout)) < 0) {
ysuga 1:f74116b37bc9 75 // return ret;
ysuga 1:f74116b37bc9 76 //}
ysuga 1:f74116b37bc9 77
ysuga 1:f74116b37bc9 78 if((ret=SerialDevice_read(packet+PACKET_HEADER_SIZE,
ysuga 1:f74116b37bc9 79 packet[DATA_LENGTH],
ysuga 1:f74116b37bc9 80 timeout)) < 0) {
ysuga 1:f74116b37bc9 81 return ret;
ysuga 0:5f7bc45bc2e8 82 }
ysuga 1:f74116b37bc9 83
ysuga 1:f74116b37bc9 84 if((ret=SerialDevice_read(&buf, 1, timeout)) < 0) {
ysuga 1:f74116b37bc9 85 return ret;
ysuga 1:f74116b37bc9 86 }
ysuga 0:5f7bc45bc2e8 87
ysuga 1:f74116b37bc9 88 uint8_t sum = 0;//PACKET_STARTING_CHARACTOR_0 + PACKET_STARTING_CHARACTOR_1;
ysuga 1:f74116b37bc9 89 for(uint8_t i = 0;i < PACKET_HEADER_SIZE+packet[DATA_LENGTH];i++) {
ysuga 1:f74116b37bc9 90 sum += packet[i];
ysuga 1:f74116b37bc9 91 }
ysuga 1:f74116b37bc9 92 if(buf != sum) {
ysuga 0:5f7bc45bc2e8 93 return -CHECKSUM_ERROR;
ysuga 0:5f7bc45bc2e8 94 }
ysuga 1:f74116b37bc9 95 return PACKET_HEADER_SIZE + packet[DATA_LENGTH];
ysuga 0:5f7bc45bc2e8 96 }