diff --git a/EasyTransfer/EasyTransfer.cpp b/EasyTransfer/EasyTransfer.cpp index 67b1f18..4d9d672 100644 --- a/EasyTransfer/EasyTransfer.cpp +++ b/EasyTransfer/EasyTransfer.cpp @@ -5,9 +5,12 @@ //Captures address and size of struct void EasyTransfer::begin(uint8_t * ptr, uint8_t length, HardwareSerial *theSerial){ -address = ptr; -size = length; -_serial = theSerial; + address = ptr; + size = length; + _serial = theSerial; + + //dynamic creation of rx parsing buffer in RAM + rx_buffer = (uint8_t*) malloc(size); } //Sends out struct in binary, with header, length info and checksum @@ -52,7 +55,7 @@ boolean EasyTransfer::receiveData(){ //we get here if we already found the header bytes, the struct size matched what we know, and now we are byte aligned. if(rx_len != 0){ while(_serial->available() && rx_array_inx <= rx_len){ - rx_array[rx_array_inx++] = _serial->read(); + rx_buffer[rx_array_inx++] = _serial->read(); } if(rx_len == (rx_array_inx-1)){ @@ -60,11 +63,11 @@ boolean EasyTransfer::receiveData(){ //last uint8_t is CS calc_CS = rx_len; for (int i = 0; iavailable() && rx_array_inx <= rx_len){ #if ARDUINO >= 100 - rx_array[rx_array_inx++] = _serial->read(); + rx_buffer[rx_array_inx++] = _serial->read(); #else - rx_array[rx_array_inx++] = _serial->receive(); + rx_buffer[rx_array_inx++] = _serial->receive(); #endif } @@ -88,11 +91,11 @@ boolean EasyTransferI2C::receiveData(){ //last uint8_t is CS calc_CS = rx_len; for (int i = 0; i 22 //Captures address and size of struct void SoftEasyTransfer::begin(uint8_t * ptr, uint8_t length, SoftwareSerial *theSerial){ -address = ptr; -size = length; -_serial = theSerial; + address = ptr; + size = length; + _serial = theSerial; + + //dynamic creation of rx parsing buffer in RAM + rx_buffer = (uint8_t*) malloc(size); } #else //Captures address and size of struct void SoftEasyTransfer::begin(uint8_t * ptr, uint8_t length, NewSoftSerial *theSerial){ -address = ptr; -size = length; -_serial = theSerial; + address = ptr; + size = length; + _serial = theSerial; + + //dynamic creation of rx parsing buffer in RAM + rx_buffer = (uint8_t*) malloc(size); } #endif @@ -80,7 +86,7 @@ boolean SoftEasyTransfer::receiveData(){ if(rx_len != 0){ while(_serial->available() && rx_array_inx <= rx_len){ - rx_array[rx_array_inx++] = _serial->read(); + rx_buffer[rx_array_inx++] = _serial->read(); } if(rx_len == (rx_array_inx-1)){ @@ -88,11 +94,11 @@ boolean SoftEasyTransfer::receiveData(){ //last uint8_t is CS calc_CS = rx_len; for (int i = 0; i