4
4
5
5
6
6
// Captures address and size of struct
7
- void EasyTransfer::begin (uint8_t * ptr, uint8_t length, HardwareSerial *theSerial ){
7
+ void EasyTransfer::begin (uint8_t * ptr, uint8_t length, Stream *theStream ){
8
8
address = ptr;
9
9
size = length;
10
- _serial = theSerial ;
10
+ _stream = theStream ;
11
11
12
12
// dynamic creation of rx parsing buffer in RAM
13
13
rx_buffer = (uint8_t *) malloc (size);
@@ -16,14 +16,14 @@ void EasyTransfer::begin(uint8_t * ptr, uint8_t length, HardwareSerial *theSeria
16
16
// Sends out struct in binary, with header, length info and checksum
17
17
void EasyTransfer::sendData (){
18
18
uint8_t CS = size;
19
- _serial ->write (0x06 );
20
- _serial ->write (0x85 );
21
- _serial ->write (size);
19
+ _stream ->write (0x06 );
20
+ _stream ->write (0x85 );
21
+ _stream ->write (size);
22
22
for (int i = 0 ; i<size; i++){
23
23
CS^=*(address+i);
24
- _serial ->write (*(address+i));
24
+ _stream ->write (*(address+i));
25
25
}
26
- _serial ->write (CS);
26
+ _stream ->write (CS);
27
27
28
28
}
29
29
@@ -32,17 +32,17 @@ boolean EasyTransfer::receiveData(){
32
32
// start off by looking for the header bytes. If they were already found in a previous call, skip it.
33
33
if (rx_len == 0 ){
34
34
// this size check may be redundant due to the size check below, but for now I'll leave it the way it is.
35
- if (_serial ->available () >= 3 ){
35
+ if (_stream ->available () >= 3 ){
36
36
// this will block until a 0x06 is found or buffer size becomes less then 3.
37
- while (_serial ->read () != 0x06 ) {
37
+ while (_stream ->read () != 0x06 ) {
38
38
// This will trash any preamble junk in the serial buffer
39
39
// but we need to make sure there is enough in the buffer to process while we trash the rest
40
40
// if the buffer becomes too empty, we will escape and try again on the next call
41
- if (_serial ->available () < 3 )
41
+ if (_stream ->available () < 3 )
42
42
return false ;
43
43
}
44
- if (_serial ->read () == 0x85 ){
45
- rx_len = _serial ->read ();
44
+ if (_stream ->read () == 0x85 ){
45
+ rx_len = _stream ->read ();
46
46
// make sure the binary structs on both Arduinos are the same size.
47
47
if (rx_len != size){
48
48
rx_len = 0 ;
@@ -54,8 +54,8 @@ boolean EasyTransfer::receiveData(){
54
54
55
55
// we get here if we already found the header bytes, the struct size matched what we know, and now we are byte aligned.
56
56
if (rx_len != 0 ){
57
- while (_serial ->available () && rx_array_inx <= rx_len){
58
- rx_buffer[rx_array_inx++] = _serial ->read ();
57
+ while (_stream ->available () && rx_array_inx <= rx_len){
58
+ rx_buffer[rx_array_inx++] = _stream ->read ();
59
59
}
60
60
61
61
if (rx_len == (rx_array_inx-1 )){
0 commit comments