Skip to content

Commit e91f767

Browse files
committed
Modified ArduinoRobotEasyTransfer to conform with Arduino Library Spec 2.0
1 parent 4f42cc0 commit e91f767

File tree

13 files changed

+299
-432
lines changed

13 files changed

+299
-432
lines changed

avr/libraries/EasyTransfer/README.txt renamed to avr/libraries/ArduinoRobotEasyTransfer/README.txt

Lines changed: 37 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,7 @@
1-
/******************************************************************
1+
/*******************************************************************************
2+
* ArduinoRobotEasyTransfer library modified by Julian Sanin,
3+
* backported from:
4+
*
25
* EasyTransfer Arduino Library v2.1
36
* details and example sketch:
47
* http://www.billporter.info/easytransfer-arduino-library/
@@ -15,23 +18,30 @@
1518
* 1.0 Created
1619
* 1.1 Fixed dumb Copy-paste error in header file
1720
* Added a keyword file
18-
* 1.5 Forked lib into Software and Hardware Serial branches, I don't know a better way
19-
* added passing in of Serial port of different types
20-
* 1.6 Fixed bug where it wasn't clearing out the buffers if the CheckSum failed,
21-
* I'm good at dumb mistakes
22-
* 1.7 Fixed a bug where the receive function could block for too long and never process data correctly
23-
* Organized the examples to be Arduino IDE compatible
21+
* 1.5 Forked lib into Software and Hardware Serial branches, I don't know a
22+
* better way added passing in of Serial port of different types
23+
* 1.6 Fixed bug where it wasn't clearing out the buffers if the CheckSum
24+
* failed, I'm good at dumb mistakes
25+
* 1.7 Fixed a bug where the receive function could block for too long and
26+
* never process data correctly
27+
* Organized the examples to be Arduino IDE compatible
2428
* 1.8
25-
* Now Arduino 1.0 compatible!
29+
* Now Arduino 1.0 compatible!
2630
* 1.81
27-
* Made it more cross compatible. Man, They really made us work for this one.
31+
* Made it more cross compatible. Man, They really made us work for this
32+
* one.
2833
* 2.0
29-
* Combined SoftEasyTransfer with the other two to make everything one repo
30-
* Added EasyTransferVirtualWire library for use with Virtual Wire and cheap radios.
34+
* Combined SoftEasyTransfer with the other two to make everything one
35+
* repo
36+
* Added EasyTransferVirtualWire library for use with Virtual Wire and
37+
* cheap radios.
3138
* 2.0.1
32-
* VirtualWire version tested by garth@netram, bugs fixed.
39+
* VirtualWire version tested by garth@netram, bugs fixed.
3340
* 2.1
34-
* Changes RX parsing buffer to dynamic allocation to conserve RAM.
41+
* Changes RX parsing buffer to dynamic allocation to conserve RAM.
42+
* 3.0.0
43+
* Imported EasyTransfer library as ArduinoRobotEasyTransfer.
44+
* Backported ArduinoRobot modifications.
3545
*
3646
*
3747
* Limits of the Library
@@ -43,17 +53,21 @@
4353
* Header(0x06,0x85),SizeofPayload,Payload,Checksum
4454
*
4555
*
46-
*This program is free software: you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation, either version 3 of the License, or(at your option) any later version.
47-
This program is distributed in the hope that it will be useful,
48-
but WITHOUT ANY WARRANTY; without even the implied warranty of
49-
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
50-
GNU General Public License for more details.
51-
<http://www.gnu.org/licenses/>
56+
* This program is free software: you can redistribute it and/or modify it under
57+
* the terms of the GNU General Public License as published by the Free Software
58+
* Foundation, either version 3 of the License, or(at your option) any later
59+
* version.
60+
* This program is distributed in the hope that it will be useful,
61+
* but WITHOUT ANY WARRANTY; without even the implied warranty of
62+
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
63+
* GNU General Public License for more details.
64+
* <http://www.gnu.org/licenses/>
5265
*
53-
*This work is licensed under the Creative Commons Attribution-ShareAlike 3.0 Unported License.
54-
*To view a copy of this license, visit http://creativecommons.org/licenses/by-sa/3.0/ or
55-
*send a letter to Creative Commons, 444 Castro Street, Suite 900, Mountain View, California, 94041, USA.
56-
******************************************************************/
66+
* This work is licensed under the Creative Commons Attribution-ShareAlike 3.0
67+
* Unported License. To view a copy of this license, visit
68+
* http://creativecommons.org/licenses/by-sa/3.0/ or send a letter to Creative
69+
* Commons, 444 Castro Street, Suite 900, Mountain View, California, 94041, USA.
70+
*******************************************************************************/
5771

5872

5973
********************To Install*************************************

avr/libraries/EasyTransfer/keywords.txt renamed to avr/libraries/ArduinoRobotEasyTransfer/keywords.txt

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,13 @@
11
#######################################
2-
# Syntax Coloring Map EasyTransfer
2+
# Syntax Coloring Map
3+
# ArduinoRobotEasyTransfer
34
#######################################
45

56
#######################################
67
# Datatypes (KEYWORD1)
78
#######################################
89

9-
EasyTransfer KEYWORD1
10+
ArduinoRobotEasyTransfer KEYWORD1
1011

1112
#######################################
1213
# Methods and Functions (KEYWORD2)
@@ -19,4 +20,3 @@ begin KEYWORD2
1920
#######################################
2021
# Constants (LITERAL1)
2122
#######################################
22-
details LITERAL1
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
name=ArduinoRobotEasyTransfer
2+
version=3.0.0
3+
author=Bill Porter <bill@billporter.info>, Julian Sanin <sanin89julian@gmail.com>
4+
maintainer=Julian Sanin <sanin89julian@gmail.com>
5+
sentence=A library to interface the Arduino Robot boards.
6+
paragraph=Supports Arduino Robot Control & Motor Board.
7+
category=Uncategorized
8+
url=https://github.com/j54n1n/arduinorobot
9+
architectures=avr
Lines changed: 157 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,157 @@
1+
/*******************************************************************************
2+
* ArduinoRobotEasyTransfer library modified by Julian Sanin,
3+
* backported from:
4+
*
5+
* EasyTransfer Arduino Library v2.1
6+
* details and example sketch:
7+
* http://www.billporter.info/easytransfer-arduino-library/
8+
*
9+
* Brought to you by:
10+
* Bill Porter
11+
* www.billporter.info
12+
*
13+
* Major props to Mathieu Alorent (kumy) for
14+
* I2C version and the pretty pictures.
15+
*
16+
*
17+
* Lib version history
18+
* 1.0 Created
19+
* 1.1 Fixed dumb Copy-paste error in header file
20+
* Added a keyword file
21+
* 1.5 Forked lib into Software and Hardware Serial branches, I don't know a
22+
* better way added passing in of Serial port of different types
23+
* 1.6 Fixed bug where it wasn't clearing out the buffers if the CheckSum
24+
* failed, I'm good at dumb mistakes
25+
* 1.7 Fixed a bug where the receive function could block for too long and
26+
* never process data correctly
27+
* Organized the examples to be Arduino IDE compatible
28+
* 1.8
29+
* Now Arduino 1.0 compatible!
30+
* 1.81
31+
* Made it more cross compatible. Man, They really made us work for this
32+
* one.
33+
* 2.0
34+
* Combined SoftEasyTransfer with the other two to make everything one
35+
* repo
36+
* Added EasyTransferVirtualWire library for use with Virtual Wire and
37+
* cheap radios.
38+
* 2.0.1
39+
* VirtualWire version tested by garth@netram, bugs fixed.
40+
* 2.1
41+
* Changes RX parsing buffer to dynamic allocation to conserve RAM.
42+
* 3.0
43+
* Imported EasyTransfer library as ArduinoRobotEasyTransfer.
44+
* Backported ArduinoRobot modifications.
45+
*
46+
*
47+
* Limits of the Library
48+
* You can change the Serial port,
49+
* but the Struct size must not pass 255 bytes
50+
* VirtualWire Version Struct can'e be bigger then 26 bytes
51+
*
52+
* The protcol is as follows:
53+
* Header(0x06,0x85),SizeofPayload,Payload,Checksum
54+
*
55+
*
56+
* This program is free software: you can redistribute it and/or modify it under
57+
* the terms of the GNU General Public License as published by the Free Software
58+
* Foundation, either version 3 of the License, or(at your option) any later
59+
* version.
60+
* This program is distributed in the hope that it will be useful,
61+
* but WITHOUT ANY WARRANTY; without even the implied warranty of
62+
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
63+
* GNU General Public License for more details.
64+
* <http://www.gnu.org/licenses/>
65+
*
66+
* This work is licensed under the Creative Commons Attribution-ShareAlike 3.0
67+
* Unported License. To view a copy of this license, visit
68+
* http://creativecommons.org/licenses/by-sa/3.0/ or send a letter to Creative
69+
* Commons, 444 Castro Street, Suite 900, Mountain View, California, 94041, USA.
70+
*******************************************************************************/
71+
#include "ArduinoRobotEasyTransfer.h"
72+
73+
74+
75+
76+
//Captures address and size of struct
77+
void ArduinoRobotEasyTransfer::begin(uint8_t * ptr, uint8_t length, Stream *theStream){
78+
address = ptr;
79+
size = length;
80+
_stream = theStream;
81+
82+
//dynamic creation of rx parsing buffer in RAM
83+
rx_buffer = (uint8_t*) malloc(size+1);
84+
}
85+
86+
//Sends out struct in binary, with header, length info and checksum
87+
void ArduinoRobotEasyTransfer::sendData(){
88+
uint8_t CS = size;
89+
_stream->write(0x06);
90+
_stream->write(0x85);
91+
_stream->write(size);
92+
for(int i = 0; i<size; i++){
93+
CS^=*(address+i);
94+
_stream->write(*(address+i));
95+
}
96+
_stream->write(CS);
97+
98+
}
99+
100+
boolean ArduinoRobotEasyTransfer::receiveData(){
101+
102+
//start off by looking for the header bytes. If they were already found in a previous call, skip it.
103+
if(rx_len == 0){
104+
//this size check may be redundant due to the size check below, but for now I'll leave it the way it is.
105+
if(_stream->available() >= 3){
106+
//this will block until a 0x06 is found or buffer size becomes less then 3.
107+
while(_stream->read() != 0x06) {
108+
//This will trash any preamble junk in the serial buffer
109+
//but we need to make sure there is enough in the buffer to process while we trash the rest
110+
//if the buffer becomes too empty, we will escape and try again on the next call
111+
if(_stream->available() < 3)
112+
return false;
113+
}
114+
if (_stream->read() == 0x85){
115+
rx_len = _stream->read();
116+
//make sure the binary structs on both Arduinos are the same size.
117+
if(rx_len != size){
118+
rx_len = 0;
119+
return false;
120+
}
121+
}
122+
}
123+
}
124+
125+
//we get here if we already found the header bytes, the struct size matched what we know, and now we are byte aligned.
126+
if(rx_len != 0){
127+
while(_stream->available() && rx_array_inx <= rx_len){
128+
rx_buffer[rx_array_inx++] = _stream->read();
129+
}
130+
131+
if(rx_len == (rx_array_inx-1)){
132+
//seem to have got whole message
133+
//last uint8_t is CS
134+
calc_CS = rx_len;
135+
for (int i = 0; i<rx_len; i++){
136+
calc_CS^=rx_buffer[i];
137+
}
138+
139+
if(calc_CS == rx_buffer[rx_array_inx-1]){//CS good
140+
memcpy(address,rx_buffer,size);
141+
rx_len = 0;
142+
rx_array_inx = 0;
143+
return true;
144+
}
145+
146+
else{
147+
//failed checksum, need to clear this out anyway
148+
rx_len = 0;
149+
rx_array_inx = 0;
150+
return false;
151+
}
152+
153+
}
154+
}
155+
156+
return false;
157+
}
Lines changed: 93 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,93 @@
1+
/*******************************************************************************
2+
* ArduinoRobotEasyTransfer library modified by Julian Sanin,
3+
* backported from:
4+
*
5+
* EasyTransfer Arduino Library v2.1
6+
* details and example sketch:
7+
* http://www.billporter.info/easytransfer-arduino-library/
8+
*
9+
* Brought to you by:
10+
* Bill Porter
11+
* www.billporter.info
12+
*
13+
* Major props to Mathieu Alorent (kumy) for
14+
* I2C version and the pretty pictures.
15+
*
16+
*
17+
* Lib version history
18+
* 1.0 Created
19+
* 1.1 Fixed dumb Copy-paste error in header file
20+
* Added a keyword file
21+
* 1.5 Forked lib into Software and Hardware Serial branches, I don't know a
22+
* better way added passing in of Serial port of different types
23+
* 1.6 Fixed bug where it wasn't clearing out the buffers if the CheckSum
24+
* failed, I'm good at dumb mistakes
25+
* 1.7 Fixed a bug where the receive function could block for too long and
26+
* never process data correctly
27+
* Organized the examples to be Arduino IDE compatible
28+
* 1.8
29+
* Now Arduino 1.0 compatible!
30+
* 1.81
31+
* Made it more cross compatible. Man, They really made us work for this
32+
* one.
33+
* 2.0
34+
* Combined SoftEasyTransfer with the other two to make everything one
35+
* repo
36+
* Added EasyTransferVirtualWire library for use with Virtual Wire and
37+
* cheap radios.
38+
* 2.0.1
39+
* VirtualWire version tested by garth@netram, bugs fixed.
40+
* 2.1
41+
* Changes RX parsing buffer to dynamic allocation to conserve RAM.
42+
* 3.0
43+
* Imported EasyTransfer library as ArduinoRobotEasyTransfer.
44+
* Backported ArduinoRobot modifications.
45+
*
46+
*
47+
* Limits of the Library
48+
* You can change the Serial port,
49+
* but the Struct size must not pass 255 bytes
50+
* VirtualWire Version Struct can'e be bigger then 26 bytes
51+
*
52+
* The protcol is as follows:
53+
* Header(0x06,0x85),SizeofPayload,Payload,Checksum
54+
*
55+
*
56+
* This program is free software: you can redistribute it and/or modify it under
57+
* the terms of the GNU General Public License as published by the Free Software
58+
* Foundation, either version 3 of the License, or(at your option) any later
59+
* version.
60+
* This program is distributed in the hope that it will be useful,
61+
* but WITHOUT ANY WARRANTY; without even the implied warranty of
62+
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
63+
* GNU General Public License for more details.
64+
* <http://www.gnu.org/licenses/>
65+
*
66+
* This work is licensed under the Creative Commons Attribution-ShareAlike 3.0
67+
* Unported License. To view a copy of this license, visit
68+
* http://creativecommons.org/licenses/by-sa/3.0/ or send a letter to Creative
69+
* Commons, 444 Castro Street, Suite 900, Mountain View, California, 94041, USA.
70+
*******************************************************************************/
71+
#ifndef ARDUINO_ROBOT_EASY_TRANSFER_H
72+
#define ARDUINO_ROBOT_EASY_TRANSFER_H
73+
74+
#include <Arduino.h>
75+
#include <Stream.h>
76+
77+
class ArduinoRobotEasyTransfer {
78+
public:
79+
void begin(uint8_t *, uint8_t, Stream *theStream);
80+
void sendData();
81+
boolean receiveData();
82+
private:
83+
Stream *_stream;
84+
//NewSoftSerial *_serial;
85+
uint8_t * address; //address of struct
86+
uint8_t size; //size of struct
87+
uint8_t * rx_buffer; //address for temporary storage and parsing buffer
88+
uint8_t rx_array_inx; //index for RX parsing buffer
89+
uint8_t rx_len; //RX packet length according to the packet
90+
uint8_t calc_CS; //calculated Chacksum
91+
};
92+
93+
#endif

0 commit comments

Comments
 (0)