@@ -141,9 +141,19 @@ cressi_edy_packet (cressi_edy_device_t *device, const unsigned char command[], u
141
141
ERROR (abstract -> context , "Failed to receive the answer." );
142
142
return status ;
143
143
}
144
+ }
145
+
146
+ if (trailer ) {
147
+ // Receive the trailer byte.
148
+ unsigned char end = 0 ;
149
+ status = dc_iostream_read (device -> iostream , & end , 1 , NULL );
150
+ if (status != DC_STATUS_SUCCESS ) {
151
+ ERROR (abstract -> context , "Failed to receive the answer." );
152
+ return status ;
153
+ }
144
154
145
155
// Verify the trailer of the packet.
146
- if (trailer && answer [ asize - 1 ] != 0x45 ) {
156
+ if (end != 0x45 ) {
147
157
ERROR (abstract -> context , "Unexpected answer trailer byte." );
148
158
return DC_STATUS_PROTOCOL ;
149
159
}
@@ -203,9 +213,8 @@ static dc_status_t
203
213
cressi_edy_init3 (cressi_edy_device_t * device )
204
214
{
205
215
unsigned char command [1 ] = {0x0C };
206
- unsigned char answer [1 ] = {0 };
207
216
208
- return cressi_edy_transfer (device , command , sizeof (command ), answer , sizeof ( answer ) , 1 );
217
+ return cressi_edy_transfer (device , command , sizeof (command ), NULL , 0 , 1 );
209
218
}
210
219
211
220
@@ -324,6 +333,7 @@ cressi_edy_device_close (dc_device_t *abstract)
324
333
static dc_status_t
325
334
cressi_edy_device_read (dc_device_t * abstract , unsigned int address , unsigned char data [], unsigned int size )
326
335
{
336
+ dc_status_t status = DC_STATUS_SUCCESS ;
327
337
cressi_edy_device_t * device = (cressi_edy_device_t * ) abstract ;
328
338
329
339
if ((address % SZ_PAGE != 0 ) ||
@@ -334,22 +344,18 @@ cressi_edy_device_read (dc_device_t *abstract, unsigned int address, unsigned ch
334
344
while (nbytes < size ) {
335
345
// Read the package.
336
346
unsigned int number = address / SZ_PAGE ;
337
- unsigned char answer [SZ_PACKET + 1 ] = {0 };
338
347
unsigned char command [3 ] = {0x52 ,
339
348
(number >> 8 ) & 0xFF , // high
340
349
(number ) & 0xFF }; // low
341
- dc_status_t rc = cressi_edy_transfer (device , command , sizeof (command ), answer , sizeof (answer ), 1 );
342
- if (rc != DC_STATUS_SUCCESS )
343
- return rc ;
344
-
345
- memcpy (data , answer , SZ_PACKET );
350
+ status = cressi_edy_transfer (device , command , sizeof (command ), data + nbytes , SZ_PACKET , 1 );
351
+ if (status != DC_STATUS_SUCCESS )
352
+ return status ;
346
353
347
354
nbytes += SZ_PACKET ;
348
355
address += SZ_PACKET ;
349
- data += SZ_PACKET ;
350
356
}
351
357
352
- return DC_STATUS_SUCCESS ;
358
+ return status ;
353
359
}
354
360
355
361
0 commit comments