|
|
@ -12,6 +12,9 @@ using namespace iflytop; |
|
|
|
#define SECTOR_NUM (2 * 8)
|
|
|
|
#define MAX_SIZE (SECTOR_SIZE * SECTOR_NUM) // 2k
|
|
|
|
|
|
|
|
#define READ_SECTOR_SIZE (32)
|
|
|
|
#define READ_SECTOR_NUM (2 * 8 * 4)
|
|
|
|
|
|
|
|
#define TAG "EEPROMService"
|
|
|
|
|
|
|
|
/*******************************************************************************
|
|
|
@ -164,17 +167,18 @@ void EEPROMService::detect_online() { |
|
|
|
int32_t EEPROMService::a8000_idcard_reader_read_raw(int32_t index, uint8_t* data, int32_t* len) { |
|
|
|
zlock_guard guard(m_mutex); |
|
|
|
if (!m_nowonline) return err::kdevice_offline; |
|
|
|
if (*len < SECTOR_SIZE) return err::kbuffer_not_enough; |
|
|
|
ZLOGI(TAG, "read: %d", index); |
|
|
|
|
|
|
|
uint16_t add = index * SECTOR_SIZE; |
|
|
|
*len = SECTOR_SIZE; |
|
|
|
if (*len < READ_SECTOR_SIZE) return err::kbuffer_not_enough; |
|
|
|
int readlen = *len; |
|
|
|
|
|
|
|
if (add >= MAX_SIZE) { |
|
|
|
*len = 0; |
|
|
|
uint16_t add = index * readlen; |
|
|
|
*len = readlen; |
|
|
|
if (*len + add > MAX_SIZE) { |
|
|
|
*len = MAX_SIZE - add; |
|
|
|
} |
|
|
|
if (*len <= 0) { |
|
|
|
return 0; |
|
|
|
} |
|
|
|
|
|
|
|
ZLOGI(TAG, "read: %d", index); |
|
|
|
memcpy(data, m_idcardcache + add, *len); |
|
|
|
return 0; |
|
|
|
} |
|
|
|