![](/media/cache/profiles/94aef38441efa3380a3bed3faf1f9d5d.50x50_q85.jpg)
RTno/SendPacket.cpp@0:3c49891bc39d, 2011-07-29 (annotated)
- Committer:
- nucho
- Date:
- Fri Jul 29 11:23:44 2011 +0000
- Revision:
- 0:3c49891bc39d
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
nucho | 0:3c49891bc39d | 1 | /******************************************* |
nucho | 0:3c49891bc39d | 2 | * SendPacket.cpp |
nucho | 0:3c49891bc39d | 3 | * @author Yuki Suga |
nucho | 0:3c49891bc39d | 4 | * @copyright Yuki Suga (ysuga.net) Nov, 10th, 2010. |
nucho | 0:3c49891bc39d | 5 | * @license LGPLv3 |
nucho | 0:3c49891bc39d | 6 | *****************************************/ |
nucho | 0:3c49891bc39d | 7 | /******************************************** |
nucho | 0:3c49891bc39d | 8 | It changed a little for mbed. |
nucho | 0:3c49891bc39d | 9 | The serial buffer is not used. |
nucho | 0:3c49891bc39d | 10 | 2011/7/27 @nucho |
nucho | 0:3c49891bc39d | 11 | ********************************************/ |
nucho | 0:3c49891bc39d | 12 | #include "Packet.h" |
nucho | 0:3c49891bc39d | 13 | //#include <HardwareSerial.h> |
nucho | 0:3c49891bc39d | 14 | //#include <WConstants.h> |
nucho | 0:3c49891bc39d | 15 | #include "Serial.h" |
nucho | 0:3c49891bc39d | 16 | |
nucho | 0:3c49891bc39d | 17 | int SendPacket(const char interface, const char data_length, const char* packet_data) { |
nucho | 0:3c49891bc39d | 18 | unsigned char sum = 0; |
nucho | 0:3c49891bc39d | 19 | |
nucho | 0:3c49891bc39d | 20 | pc.putc(interface); |
nucho | 0:3c49891bc39d | 21 | sum += interface; |
nucho | 0:3c49891bc39d | 22 | |
nucho | 0:3c49891bc39d | 23 | pc.putc(data_length); |
nucho | 0:3c49891bc39d | 24 | sum += data_length; |
nucho | 0:3c49891bc39d | 25 | for(int i = 0;i < data_length;i++) { |
nucho | 0:3c49891bc39d | 26 | sum += packet_data[i]; |
nucho | 0:3c49891bc39d | 27 | pc.putc(packet_data[i]); |
nucho | 0:3c49891bc39d | 28 | } |
nucho | 0:3c49891bc39d | 29 | // if(data_length != 0) { |
nucho | 0:3c49891bc39d | 30 | //n Serial.write((const uint8_t*)packet_data, data_length); |
nucho | 0:3c49891bc39d | 31 | // } |
nucho | 0:3c49891bc39d | 32 | //sum = 32; |
nucho | 0:3c49891bc39d | 33 | pc.putc(sum); |
nucho | 0:3c49891bc39d | 34 | return PACKET_HEADER_SIZE + data_length + 1; |
nucho | 0:3c49891bc39d | 35 | } |