add: support for reading flashmem

This commit is contained in:
iceman1001 2018-05-22 12:09:17 +02:00
commit 501c29f76d

View file

@ -22,6 +22,8 @@
#include "BigBuf.h" #include "BigBuf.h"
#include "mifareutil.h" #include "mifareutil.h"
#define DEBUG 1
#ifdef WITH_LCD #ifdef WITH_LCD
#include "LCD.h" #include "LCD.h"
#endif #endif
@ -98,12 +100,16 @@ void print_result(char *name, uint8_t *buf, size_t len) {
//============================================================================= //=============================================================================
void DbpStringEx(char *str, uint32_t cmd) { void DbpStringEx(char *str, uint32_t cmd) {
#if DEBUG
byte_t len = strlen(str); byte_t len = strlen(str);
cmd_send(CMD_DEBUG_PRINT_STRING, len, cmd, 0, (byte_t*)str, len); cmd_send(CMD_DEBUG_PRINT_STRING, len, cmd, 0, (byte_t*)str, len);
#endif
} }
void DbpString(char *str) { void DbpString(char *str) {
#if DEBUG
DbpStringEx(str, 0); DbpStringEx(str, 0);
#endif
} }
#if 0 #if 0
@ -112,6 +118,7 @@ void DbpIntegers(int x1, int x2, int x3) {
} }
#endif #endif
void DbprintfEx(uint32_t cmd, const char *fmt, ...) { void DbprintfEx(uint32_t cmd, const char *fmt, ...) {
#if DEBUG
// should probably limit size here; oh well, let's just use a big buffer // should probably limit size here; oh well, let's just use a big buffer
char output_string[128] = {0x00}; char output_string[128] = {0x00};
va_list ap; va_list ap;
@ -120,9 +127,11 @@ void DbprintfEx(uint32_t cmd, const char *fmt, ...) {
va_end(ap); va_end(ap);
DbpStringEx(output_string, cmd); DbpStringEx(output_string, cmd);
#endif
} }
void Dbprintf(const char *fmt, ...) { void Dbprintf(const char *fmt, ...) {
#if DEBUG
// should probably limit size here; oh well, let's just use a big buffer // should probably limit size here; oh well, let's just use a big buffer
char output_string[128] = {0x00}; char output_string[128] = {0x00};
va_list ap; va_list ap;
@ -132,10 +141,12 @@ void Dbprintf(const char *fmt, ...) {
va_end(ap); va_end(ap);
DbpString(output_string); DbpString(output_string);
#endif
} }
// prints HEX & ASCII // prints HEX & ASCII
void Dbhexdump(int len, uint8_t *d, bool bAsci) { void Dbhexdump(int len, uint8_t *d, bool bAsci) {
#if DEBUG
int l=0, i; int l=0, i;
char ascii[9]; char ascii[9];
@ -161,6 +172,7 @@ void Dbhexdump(int len, uint8_t *d, bool bAsci) {
len -= 8; len -= 8;
d += 8; d += 8;
} }
#endif
} }
//----------------------------------------------------------------------------- //-----------------------------------------------------------------------------
@ -1097,19 +1109,20 @@ void UsbPacketReceived(uint8_t *packet, int len) {
break; break;
#ifdef WITH_FLASH #ifdef WITH_FLASH
case CMD_READ_FLASH_MEM: { case CMD_READ_FLASH_MEM: {
/*
LED_B_ON(); LED_B_ON();
uint16_t isok = 0; uint16_t isok = 0;
size_t len = 0;
uint32_t startidx = c->arg[0]; uint32_t startidx = c->arg[0];
uint16_t numofbytes = c->arg[1]; uint16_t len = c->arg[1];
Dbprintf("FlashMem read | %d - %d", startidx, numofbytes); Dbprintf("FlashMem read | %d - %d", startidx, len);
uint8_t *mem = BigBuf_malloc(USB_CMD_DATA_SIZE); size_t size = MIN(USB_CMD_DATA_SIZE, len);
for(size_t i = 0; i < numofbytes; i += USB_CMD_DATA_SIZE) { uint8_t *mem = BigBuf_malloc(size);
len = MIN((numofbytes - i), USB_CMD_DATA_SIZE);
for(size_t i = 0; i < len; i += size) {
len = MIN((len - i), size);
Dbprintf("FlashMem reading | %d | %d | %d", startidx + i, i, len); Dbprintf("FlashMem reading | %d | %d | %d", startidx + i, i, len);
@ -1121,9 +1134,7 @@ void UsbPacketReceived(uint8_t *packet, int len) {
break; break;
} }
} }
cmd_send(CMD_ACK, 1, 0, 0, 0, 0);
LED_B_OFF(); LED_B_OFF();
*/
break; break;
} }
case CMD_WRITE_FLASH_MEM: { case CMD_WRITE_FLASH_MEM: {