dragonblanketsleep

This commit is contained in:
xenia 2021-06-22 06:00:32 -04:00
parent abdd82019a
commit ce699d3f32
1 changed files with 50 additions and 7 deletions

View File

@ -226,9 +226,14 @@ enum {
APP_INIT,
CAP_READY,
CAP_TRIGGERED,
CAP_READING
CAP_READING,
CAP_ENDED,
GEN_DOWNLOAD
} sq_state = APP_INIT;
size_t gen_downloaded = 0;
size_t gen_total = 0;
bool settings_init = false;
unsigned char sq_settings[24] = {0};
@ -281,22 +286,31 @@ FT_STATUS FT_ListDevices(PVOID pArg1, PVOID pArg2, DWORD flags) {
FT_STATUS FT_Open(int devno, FT_HANDLE* pHandle) {
/* TRACE("FT_Open"); */
*pHandle = malloc(20);
sq_state = APP_INIT;
return FT_OK;
}
FT_STATUS FT_OpenEx(PVOID pArg1, DWORD flags, FT_HANDLE* pHandle) {
TRACE("FT_OpenEx");
*pHandle = malloc(20);
sq_state = APP_INIT;
return FT_OK;
}
FT_STATUS FT_Read(FT_HANDLE ftHandle, LPVOID lpBuffer, DWORD dwBytesToRead, LPDWORD lpBytesReturned) {
/* TRACE("FT_Read"); */
/* printf("FT_Read of %lu\n", dwBytesToRead); */
size_t max_bytes = dwBytesToRead;
if (read_state.len - read_state.pos > max_bytes) {
max_bytes = read_state.len - read_state.pos;
}
if (max_bytes == 0) {
printf("ERROR: read is not ready\n");
}
/* printf("req size: %lu | state pos %lu state len %lu\n", max_bytes, */
/* read_state.pos, read_state.len); */
memcpy(lpBuffer, &read_state.data[read_state.pos], max_bytes);
@ -363,6 +377,20 @@ void print_bin(unsigned char b) {
FT_STATUS FT_Write(FT_HANDLE ftHandle, LPVOID lpBuffer, DWORD len, LPDWORD written) {
/* TRACE("FT_Write"); */
unsigned char* buffer = (unsigned char*) lpBuffer;
if (sq_state == GEN_DOWNLOAD) {
printf("downloading chunk len %lu\n", len);
gen_downloaded += len;
if (gen_downloaded > gen_total) {
ABORT("too much data downloaded!");
} else if (gen_downloaded == gen_total) {
printf("done downloading\n");
sq_state = CAP_READY;
}
*written = len;
return FT_OK;
}
switch (buffer[0]) {
case 0x94:
/* TRACE("bootloader reset"); */
@ -433,16 +461,21 @@ FT_STATUS FT_Write(FT_HANDLE ftHandle, LPVOID lpBuffer, DWORD len, LPDWORD writt
case 0x00:
/* printf("state -> ready\n"); */
if (sq_state == CAP_READING) {
printf("========= end capture =========\n");
sq_state = CAP_ENDED;
} else if (sq_state != CAP_READY) {
printf("========= start capture =========\n");
sq_state = CAP_READY;
}
sq_state = CAP_READY;
break;
case 0x01:
/* printf("wait for trigger command\n"); */
printf("=========== sending trigger =========== ...");
init_read_state("\x11\x00\x00\xdd", 4);
break;
case 0x02:
printf("generator generating forever\n");
break;
case 0x06:
/* printf("start read"); */
printf("=========== starting read ===========\n");
sq_state = CAP_READING;
read_state.len = 16384;
read_state.pos = 0;
@ -451,15 +484,25 @@ FT_STATUS FT_Write(FT_HANDLE ftHandle, LPVOID lpBuffer, DWORD len, LPDWORD writt
}
/* printf("sending to app"); */
break;
case 0x05:
printf("======== entering generator mode ======\n");
if (buffer[2] != 0xf3) {
dump(buffer, len);
ABORT("wrong byte 3 in generator sequence");
}
sq_state = GEN_DOWNLOAD;
gen_downloaded = 0;
gen_total = 500000; // TODO
break;
default:
printf("unknown capture cmd code\n");
dump(buffer, len);
printf("unknown capture cmd code (len %lu)\n", len);
ABORT("FT_Write");
}
break;
default:
printf("UNKNOWN write sequence!\n");
dump(buffer, len);
printf("UNKNOWN write sequence! (len %lu)\n", len);
ABORT("FT_Write");
}
*written = len;