From 7b29c5d43d06380c07694a9d051ff5e1cd911868 Mon Sep 17 00:00:00 2001 From: Jef Driesen Date: Wed, 6 Mar 2019 20:38:01 +0100 Subject: [PATCH] Detect Mares Quad with more flash memory The latest variant of the Mares Quad has 4 times more flash memory compared to the original variant (1M vs 256K). Therefore this variant supports a new command to read the size of the flash memory. At the moment, it's unknown whether the previous variant also supports this new command or not. Probably not, because none of the other compatible models seems to support it either. Hence we only attempt to read the flash memory size for the Quad, and a failure is not considered a fatal error. The disadvantage of this approach is that a temporary communication problem can result in a misdetection of the flash memory size. Reported-by: Janice McLaughlin --- src/mares_iconhd.c | 23 ++++++++++++++++++++++- 1 file changed, 22 insertions(+), 1 deletion(-) diff --git a/src/mares_iconhd.c b/src/mares_iconhd.c index 5d428a9..ec9a4eb 100644 --- a/src/mares_iconhd.c +++ b/src/mares_iconhd.c @@ -380,6 +380,20 @@ mares_iconhd_device_open (dc_device_t **out, dc_context_t *context, dc_iostream_ // Autodetect the model using the version packet. device->model = mares_iconhd_get_model (device); + // Read the size of the flash memory. + unsigned int memsize = 0; + if (device->model == QUAD) { + unsigned char cmd_flash[] = {0xB3, 0x16}; + unsigned char rsp_flash[4] = {0}; + status = mares_iconhd_transfer (device, cmd_flash, sizeof (cmd_flash), rsp_flash, sizeof (rsp_flash)); + if (status != DC_STATUS_SUCCESS) { + WARNING (context, "Failed to read the flash memory size."); + } else { + memsize = array_uint32_le (rsp_flash); + DEBUG (context, "Flash memory size is %u bytes.", memsize); + } + } + // Load the correct memory layout. switch (device->model) { case MATRIX: @@ -391,10 +405,17 @@ mares_iconhd_device_open (dc_device_t **out, dc_context_t *context, dc_iostream_ case NEMOWIDE2: case SMART: case SMARTAPNEA: - case QUAD: device->layout = &mares_nemowide2_layout; device->packetsize = 256; break; + case QUAD: + if (memsize > 0x40000) { + device->layout = &mares_iconhd_layout; + } else { + device->layout = &mares_nemowide2_layout; + } + device->packetsize = 256; + break; case QUADAIR: case SMARTAIR: device->layout = &mares_iconhdnet_layout;