File tree 7 files changed +46
-32
lines changed
7 files changed +46
-32
lines changed Original file line number Diff line number Diff line change 5
5
6
6
// Captures address and size of struct
7
7
void 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);
11
14
}
12
15
13
16
// Sends out struct in binary, with header, length info and checksum
@@ -52,19 +55,19 @@ boolean EasyTransfer::receiveData(){
52
55
// we get here if we already found the header bytes, the struct size matched what we know, and now we are byte aligned.
53
56
if (rx_len != 0 ){
54
57
while (_serial->available () && rx_array_inx <= rx_len){
55
- rx_array [rx_array_inx++] = _serial->read ();
58
+ rx_buffer [rx_array_inx++] = _serial->read ();
56
59
}
57
60
58
61
if (rx_len == (rx_array_inx-1 )){
59
62
// seem to have got whole message
60
63
// last uint8_t is CS
61
64
calc_CS = rx_len;
62
65
for (int i = 0 ; i<rx_len; i++){
63
- calc_CS^=rx_array [i];
66
+ calc_CS^=rx_buffer [i];
64
67
}
65
68
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);
68
71
rx_len = 0 ;
69
72
rx_array_inx = 0 ;
70
73
return true ;
Original file line number Diff line number Diff line change @@ -52,9 +52,9 @@ HardwareSerial *_serial;
52
52
// NewSoftSerial *_serial;
53
53
uint8_t * address; // address of struct
54
54
uint8_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
57
56
uint8_t rx_array_inx; // index for RX parsing buffer
57
+ uint8_t rx_len; // RX packet length according to the packet
58
58
uint8_t calc_CS; // calculated Chacksum
59
59
};
60
60
Original file line number Diff line number Diff line change 5
5
6
6
// Captures address and size of struct
7
7
void 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);
11
14
}
12
15
13
16
// Sends out struct in binary, with header, length info and checksum
@@ -77,9 +80,9 @@ boolean EasyTransferI2C::receiveData(){
77
80
if (rx_len != 0 ){
78
81
while (_serial->available () && rx_array_inx <= rx_len){
79
82
#if ARDUINO >= 100
80
- rx_array [rx_array_inx++] = _serial->read ();
83
+ rx_buffer [rx_array_inx++] = _serial->read ();
81
84
#else
82
- rx_array [rx_array_inx++] = _serial->receive ();
85
+ rx_buffer [rx_array_inx++] = _serial->receive ();
83
86
#endif
84
87
}
85
88
@@ -88,11 +91,11 @@ boolean EasyTransferI2C::receiveData(){
88
91
// last uint8_t is CS
89
92
calc_CS = rx_len;
90
93
for (int i = 0 ; i<rx_len; i++){
91
- calc_CS^=rx_array [i];
94
+ calc_CS^=rx_buffer [i];
92
95
}
93
96
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);
96
99
rx_len = 0 ;
97
100
rx_array_inx = 0 ;
98
101
return true ;
Original file line number Diff line number Diff line change @@ -54,9 +54,9 @@ TwoWire *_serial;
54
54
// NewSoftSerial *_serial;
55
55
uint8_t * address; // address of struct
56
56
uint8_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
59
58
uint8_t rx_array_inx; // index for RX parsing buffer
59
+ uint8_t rx_len; // RX packet length according to the packet
60
60
uint8_t calc_CS; // calculated Chacksum
61
61
};
62
62
Original file line number Diff line number Diff line change 1
1
/******************************************************************
2
- * EasyTransfer Arduino Library v2.0. 1
2
+ * EasyTransfer Arduino Library v2.1
3
3
* details and example sketch:
4
4
* http://www.billporter.info/easytransfer-arduino-library/
5
5
*
30
30
* Added EasyTransferVirtualWire library for use with Virtual Wire and cheap radios.
31
31
* 2.0.1
32
32
* VirtualWire version tested by garth@netram, bugs fixed.
33
+ * 2.1
34
+ * Changes RX parsing buffer to dynamic allocation to conserve RAM.
33
35
*
34
36
*
35
37
* Limits of the Library
Original file line number Diff line number Diff line change 6
6
#if ARDUINO > 22
7
7
// Captures address and size of struct
8
8
void 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);
12
15
}
13
16
14
17
#else
15
18
// Captures address and size of struct
16
19
void 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);
20
26
}
21
27
22
28
#endif
@@ -80,19 +86,19 @@ boolean SoftEasyTransfer::receiveData(){
80
86
81
87
if (rx_len != 0 ){
82
88
while (_serial->available () && rx_array_inx <= rx_len){
83
- rx_array [rx_array_inx++] = _serial->read ();
89
+ rx_buffer [rx_array_inx++] = _serial->read ();
84
90
}
85
91
86
92
if (rx_len == (rx_array_inx-1 )){
87
93
// seem to have got whole message
88
94
// last uint8_t is CS
89
95
calc_CS = rx_len;
90
96
for (int i = 0 ; i<rx_len; i++){
91
- calc_CS^=rx_array [i];
97
+ calc_CS^=rx_buffer [i];
92
98
}
93
99
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);
96
102
rx_len = 0 ;
97
103
rx_array_inx = 0 ;
98
104
return true ;
Original file line number Diff line number Diff line change @@ -66,9 +66,9 @@ NewSoftSerial *_serial;
66
66
67
67
uint8_t * address; // address of struct
68
68
uint8_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
71
70
uint8_t rx_array_inx; // index for RX parsing buffer
71
+ uint8_t rx_len; // RX packet length according to the packet
72
72
uint8_t calc_CS; // calculated Chacksum
73
73
};
74
74
You can’t perform that action at this time.
0 commit comments