File tree Expand file tree Collapse file tree 7 files changed +46
-32
lines changed
Expand file tree Collapse file tree 7 files changed +46
-32
lines changed Original file line number Diff line number Diff line change 55
66// Captures address and size of struct
77void EasyTransfer::begin (uint8_t * ptr, uint8_t length, HardwareSerial *theSerial){
8- address = ptr;
9- size = length;
10- _serial = theSerial;
8+ address = ptr;
9+ size = length;
10+ _serial = theSerial;
11+
12+ // dynamic creation of rx parsing buffer in RAM
13+ rx_buffer = (uint8_t *) malloc (size);
1114}
1215
1316// Sends out struct in binary, with header, length info and checksum
@@ -52,19 +55,19 @@ boolean EasyTransfer::receiveData(){
5255 // we get here if we already found the header bytes, the struct size matched what we know, and now we are byte aligned.
5356 if (rx_len != 0 ){
5457 while (_serial->available () && rx_array_inx <= rx_len){
55- rx_array [rx_array_inx++] = _serial->read ();
58+ rx_buffer [rx_array_inx++] = _serial->read ();
5659 }
5760
5861 if (rx_len == (rx_array_inx-1 )){
5962 // seem to have got whole message
6063 // last uint8_t is CS
6164 calc_CS = rx_len;
6265 for (int i = 0 ; i<rx_len; i++){
63- calc_CS^=rx_array [i];
66+ calc_CS^=rx_buffer [i];
6467 }
6568
66- if (calc_CS == rx_array [rx_array_inx-1 ]){// CS good
67- memcpy (address,&rx_array ,size);
69+ if (calc_CS == rx_buffer [rx_array_inx-1 ]){// CS good
70+ memcpy (address,rx_buffer ,size);
6871 rx_len = 0 ;
6972 rx_array_inx = 0 ;
7073 return true ;
Original file line number Diff line number Diff line change @@ -52,9 +52,9 @@ HardwareSerial *_serial;
5252// NewSoftSerial *_serial;
5353uint8_t * address; // address of struct
5454uint8_t size; // size of struct
55- uint8_t rx_len; // RX packet length according to the packet
56- uint8_t rx_array[255 ]; // RX packet parsing buffer
55+ uint8_t * rx_buffer; // address for temporary storage and parsing buffer
5756uint8_t rx_array_inx; // index for RX parsing buffer
57+ uint8_t rx_len; // RX packet length according to the packet
5858uint8_t calc_CS; // calculated Chacksum
5959};
6060
Original file line number Diff line number Diff line change 55
66// Captures address and size of struct
77void EasyTransferI2C::begin (uint8_t * ptr, uint8_t length, TwoWire *theSerial){
8- address = ptr;
9- size = length;
10- _serial = theSerial;
8+ address = ptr;
9+ size = length;
10+ _serial = theSerial;
11+
12+ // dynamic creation of rx parsing buffer in RAM
13+ rx_buffer = (uint8_t *) malloc (size);
1114}
1215
1316// Sends out struct in binary, with header, length info and checksum
@@ -77,9 +80,9 @@ boolean EasyTransferI2C::receiveData(){
7780 if (rx_len != 0 ){
7881 while (_serial->available () && rx_array_inx <= rx_len){
7982#if ARDUINO >= 100
80- rx_array [rx_array_inx++] = _serial->read ();
83+ rx_buffer [rx_array_inx++] = _serial->read ();
8184#else
82- rx_array [rx_array_inx++] = _serial->receive ();
85+ rx_buffer [rx_array_inx++] = _serial->receive ();
8386#endif
8487 }
8588
@@ -88,11 +91,11 @@ boolean EasyTransferI2C::receiveData(){
8891 // last uint8_t is CS
8992 calc_CS = rx_len;
9093 for (int i = 0 ; i<rx_len; i++){
91- calc_CS^=rx_array [i];
94+ calc_CS^=rx_buffer [i];
9295 }
9396
94- if (calc_CS == rx_array [rx_array_inx-1 ]){// CS good
95- memcpy (address,&rx_array ,size);
97+ if (calc_CS == rx_buffer [rx_array_inx-1 ]){// CS good
98+ memcpy (address,rx_buffer ,size);
9699 rx_len = 0 ;
97100 rx_array_inx = 0 ;
98101 return true ;
Original file line number Diff line number Diff line change @@ -54,9 +54,9 @@ TwoWire *_serial;
5454// NewSoftSerial *_serial;
5555uint8_t * address; // address of struct
5656uint8_t size; // size of struct
57- uint8_t rx_len; // RX packet length according to the packet
58- uint8_t rx_array[255 ]; // RX packet parsing buffer
57+ uint8_t * rx_buffer; // address for temporary storage and parsing buffer
5958uint8_t rx_array_inx; // index for RX parsing buffer
59+ uint8_t rx_len; // RX packet length according to the packet
6060uint8_t calc_CS; // calculated Chacksum
6161};
6262
Original file line number Diff line number Diff line change 11/******************************************************************
2- * EasyTransfer Arduino Library v2.0. 1
2+ * EasyTransfer Arduino Library v2.1
33* details and example sketch:
44* http://www.billporter.info/easytransfer-arduino-library/
55*
3030* Added EasyTransferVirtualWire library for use with Virtual Wire and cheap radios.
3131* 2.0.1
3232* VirtualWire version tested by garth@netram, bugs fixed.
33+ * 2.1
34+ * Changes RX parsing buffer to dynamic allocation to conserve RAM.
3335*
3436*
3537* Limits of the Library
Original file line number Diff line number Diff line change 66#if ARDUINO > 22
77// Captures address and size of struct
88void SoftEasyTransfer::begin (uint8_t * ptr, uint8_t length, SoftwareSerial *theSerial){
9- address = ptr;
10- size = length;
11- _serial = theSerial;
9+ address = ptr;
10+ size = length;
11+ _serial = theSerial;
12+
13+ // dynamic creation of rx parsing buffer in RAM
14+ rx_buffer = (uint8_t *) malloc (size);
1215}
1316
1417#else
1518// Captures address and size of struct
1619void SoftEasyTransfer::begin (uint8_t * ptr, uint8_t length, NewSoftSerial *theSerial){
17- address = ptr;
18- size = length;
19- _serial = theSerial;
20+ address = ptr;
21+ size = length;
22+ _serial = theSerial;
23+
24+ // dynamic creation of rx parsing buffer in RAM
25+ rx_buffer = (uint8_t *) malloc (size);
2026}
2127
2228#endif
@@ -80,19 +86,19 @@ boolean SoftEasyTransfer::receiveData(){
8086
8187 if (rx_len != 0 ){
8288 while (_serial->available () && rx_array_inx <= rx_len){
83- rx_array [rx_array_inx++] = _serial->read ();
89+ rx_buffer [rx_array_inx++] = _serial->read ();
8490 }
8591
8692 if (rx_len == (rx_array_inx-1 )){
8793 // seem to have got whole message
8894 // last uint8_t is CS
8995 calc_CS = rx_len;
9096 for (int i = 0 ; i<rx_len; i++){
91- calc_CS^=rx_array [i];
97+ calc_CS^=rx_buffer [i];
9298 }
9399
94- if (calc_CS == rx_array [rx_array_inx-1 ]){// CS good
95- memcpy (address,&rx_array ,size);
100+ if (calc_CS == rx_buffer [rx_array_inx-1 ]){// CS good
101+ memcpy (address,rx_buffer ,size);
96102 rx_len = 0 ;
97103 rx_array_inx = 0 ;
98104 return true ;
Original file line number Diff line number Diff line change @@ -66,9 +66,9 @@ NewSoftSerial *_serial;
6666
6767uint8_t * address; // address of struct
6868uint8_t size; // size of struct
69- uint8_t rx_len; // RX packet length according to the packet
70- uint8_t rx_array[255 ]; // RX packet parsing buffer
69+ uint8_t * rx_buffer; // address for temporary storage and parsing buffer
7170uint8_t rx_array_inx; // index for RX parsing buffer
71+ uint8_t rx_len; // RX packet length according to the packet
7272uint8_t calc_CS; // calculated Chacksum
7373};
7474
You can’t perform that action at this time.
0 commit comments