44
55
66// 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 ){
88 address = ptr;
99 size = length;
10- _serial = theSerial ;
10+ _stream = theStream ;
1111
1212 // dynamic creation of rx parsing buffer in RAM
1313 rx_buffer = (uint8_t *) malloc (size);
@@ -16,14 +16,14 @@ void EasyTransfer::begin(uint8_t * ptr, uint8_t length, HardwareSerial *theSeria
1616// Sends out struct in binary, with header, length info and checksum
1717void EasyTransfer::sendData (){
1818 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);
2222 for (int i = 0 ; i<size; i++){
2323 CS^=*(address+i);
24- _serial ->write (*(address+i));
24+ _stream ->write (*(address+i));
2525 }
26- _serial ->write (CS);
26+ _stream ->write (CS);
2727
2828}
2929
@@ -32,17 +32,17 @@ boolean EasyTransfer::receiveData(){
3232 // start off by looking for the header bytes. If they were already found in a previous call, skip it.
3333 if (rx_len == 0 ){
3434 // 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 ){
3636 // 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 ) {
3838 // This will trash any preamble junk in the serial buffer
3939 // but we need to make sure there is enough in the buffer to process while we trash the rest
4040 // 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 )
4242 return false ;
4343 }
44- if (_serial ->read () == 0x85 ){
45- rx_len = _serial ->read ();
44+ if (_stream ->read () == 0x85 ){
45+ rx_len = _stream ->read ();
4646 // make sure the binary structs on both Arduinos are the same size.
4747 if (rx_len != size){
4848 rx_len = 0 ;
@@ -54,8 +54,8 @@ boolean EasyTransfer::receiveData(){
5454
5555 // we get here if we already found the header bytes, the struct size matched what we know, and now we are byte aligned.
5656 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 ();
5959 }
6060
6161 if (rx_len == (rx_array_inx-1 )){
0 commit comments