Change Uemis debug code to test for bit values

This way individual pieces can be turned on and off.
The commit also adds code to read from a disk image (instead of the SDA)
without all the long timeouts.

Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
This commit is contained in:
Dirk Hohndel 2012-12-04 21:03:56 -08:00
parent 8562364bd9
commit 7383f7fe0a
2 changed files with 21 additions and 14 deletions

View file

@ -30,9 +30,16 @@
#define ERR_FS_SHORT_WRITE N_("Short write to req.txt file\nIs the Uemis Zurich plugged in correctly?") #define ERR_FS_SHORT_WRITE N_("Short write to req.txt file\nIs the Uemis Zurich plugged in correctly?")
#define BUFLEN 2048 #define BUFLEN 2048
#define NUM_PARAM_BUFS 10 #define NUM_PARAM_BUFS 10
#if UEMIS_DEBUG & 64 /* we are reading from a copy of the filesystem, not the device - no need to wait */
#define UEMIS_TIMEOUT 50 /* 50ns */
#define UEMIS_LONG_TIMEOUT 500 /* 500ns */
#define UEMIS_MAX_TIMEOUT 2000 /* 2ms */
#else
#define UEMIS_TIMEOUT 50000 /* 50ms */ #define UEMIS_TIMEOUT 50000 /* 50ms */
#define UEMIS_LONG_TIMEOUT 500000 /* 500ms */ #define UEMIS_LONG_TIMEOUT 500000 /* 500ms */
#define UEMIS_MAX_TIMEOUT 2000000 /* 2s */ #define UEMIS_MAX_TIMEOUT 2000000 /* 2s */
#endif
static char *param_buff[NUM_PARAM_BUFS]; static char *param_buff[NUM_PARAM_BUFS];
static char *reqtxt_path; static char *reqtxt_path;
@ -179,7 +186,7 @@ static gboolean uemis_init(const char *path)
reqtxt_path = g_build_filename(path, "/req.txt", NULL); reqtxt_path = g_build_filename(path, "/req.txt", NULL);
reqtxt_file = g_open(reqtxt_path, O_RDONLY, 0666); reqtxt_file = g_open(reqtxt_path, O_RDONLY, 0666);
if (!reqtxt_file) { if (!reqtxt_file) {
#if UEMIS_DEBUG #if UEMIS_DEBUG & 1
fprintf(debugfile, ":EE req.txt can't be opened\n"); fprintf(debugfile, ":EE req.txt can't be opened\n");
#endif #endif
return FALSE; return FALSE;
@ -188,7 +195,7 @@ static gboolean uemis_init(const char *path)
char tmp[6]; char tmp[6];
read(reqtxt_file, tmp, 5); read(reqtxt_file, tmp, 5);
tmp[5] = '\0'; tmp[5] = '\0';
#if UEMIS_DEBUG > 1 #if UEMIS_DEBUG & 2
fprintf(debugfile, "::r req.txt \"%s\"\n", tmp); fprintf(debugfile, "::r req.txt \"%s\"\n", tmp);
#endif #endif
if (sscanf(tmp + 1, "%d", &filenr) != 1) if (sscanf(tmp + 1, "%d", &filenr) != 1)
@ -196,7 +203,7 @@ static gboolean uemis_init(const char *path)
} }
else { else {
filenr = 0; filenr = 0;
#if UEMIS_DEBUG > 1 #if UEMIS_DEBUG & 2
fprintf(debugfile, "::r req.txt skipped as there were fewer than 5 bytes\n"); fprintf(debugfile, "::r req.txt skipped as there were fewer than 5 bytes\n");
#endif #endif
} }
@ -230,7 +237,7 @@ static void trigger_response(int file, char *command, int nr, long tailpos)
char fl[10]; char fl[10];
snprintf(fl, 8, "%s%04d", command, nr); snprintf(fl, 8, "%s%04d", command, nr);
#if UEMIS_DEBUG > 2 #if UEMIS_DEBUG & 4
fprintf(debugfile,":tr %s (after seeks)\n", fl); fprintf(debugfile,":tr %s (after seeks)\n", fl);
#endif #endif
lseek(file, 0, SEEK_SET); lseek(file, 0, SEEK_SET);
@ -299,7 +306,7 @@ static void buffer_add(char **buffer, int *buffer_size, char *buf)
*buffer = realloc(*buffer, *buffer_size); *buffer = realloc(*buffer, *buffer_size);
strcat(*buffer, buf); strcat(*buffer, buf);
} }
#if UEMIS_DEBUG > 5 #if UEMIS_DEBUG & 16
fprintf(debugfile,"added \"%s\" to buffer - new length %d\n", buf, *buffer_size); fprintf(debugfile,"added \"%s\" to buffer - new length %d\n", buf, *buffer_size);
#endif #endif
} }
@ -381,7 +388,7 @@ static gboolean uemis_get_answer(const char *path, char *request, int n_param_in
file_length = strlen(sb); file_length = strlen(sb);
snprintf(fl, 10, "%08d", file_length - 13); snprintf(fl, 10, "%08d", file_length - 13);
memcpy(sb + 5, fl, strlen(fl)); memcpy(sb + 5, fl, strlen(fl));
#ifdef UEMIS_DEBUG #if UEMIS_DEBUG & 1
fprintf(debugfile,"::w req.txt \"%s\"\n", sb); fprintf(debugfile,"::w req.txt \"%s\"\n", sb);
#endif #endif
if (write(reqtxt_file, sb, strlen(sb)) != strlen(sb)) { if (write(reqtxt_file, sb, strlen(sb)) != strlen(sb)) {
@ -405,10 +412,10 @@ static gboolean uemis_get_answer(const char *path, char *request, int n_param_in
ans_file = g_open(ans_path, O_RDONLY, 0666); ans_file = g_open(ans_path, O_RDONLY, 0666);
read(ans_file, tmp, 100); read(ans_file, tmp, 100);
close(ans_file); close(ans_file);
#if UEMIS_DEBUG > 3 #if UEMIS_DEBUG & 8
tmp[100]='\0'; tmp[100]='\0';
fprintf(debugfile, "::t %s \"%s\"\n", ans_path, tmp); fprintf(debugfile, "::t %s \"%s\"\n", ans_path, tmp);
#elif UEMIS_DEBUG > 1 #elif UEMIS_DEBUG & 2
char pbuf[4]; char pbuf[4];
pbuf[0] = tmp[0]; pbuf[0] = tmp[0];
pbuf[1] = tmp[1]; pbuf[1] = tmp[1];
@ -482,7 +489,7 @@ static gboolean uemis_get_answer(const char *path, char *request, int n_param_in
buf[size - 3] = '\0'; buf[size - 3] = '\0';
buffer_add(&mbuf, &mbuf_size, buf); buffer_add(&mbuf, &mbuf_size, buf);
show_progress(buf, what); show_progress(buf, what);
#if UEMIS_DEBUG > 3 #if UEMIS_DEBUG & 8
fprintf(debugfile, "::r %s \"%s\"\n", ans_path, buf); fprintf(debugfile, "::r %s \"%s\"\n", ans_path, buf);
#endif #endif
} }
@ -492,7 +499,7 @@ static gboolean uemis_get_answer(const char *path, char *request, int n_param_in
} else { } else {
ismulti = FALSE; ismulti = FALSE;
} }
#if UEMIS_DEBUG > 3 #if UEMIS_DEBUG & 8
fprintf(debugfile,":r: %s\n", buf); fprintf(debugfile,":r: %s\n", buf);
#endif #endif
if (!answer_in_mbuf) if (!answer_in_mbuf)
@ -501,7 +508,7 @@ static gboolean uemis_get_answer(const char *path, char *request, int n_param_in
found_answer = TRUE; found_answer = TRUE;
free(buf); free(buf);
} }
#if UEMIS_DEBUG #if UEMIS_DEBUG & 1
for (i = 0; i < n_param_out; i++) for (i = 0; i < n_param_out; i++)
fprintf(debugfile,"::: %d: %s\n", i, param_buff[i]); fprintf(debugfile,"::: %d: %s\n", i, param_buff[i]);
#endif #endif
@ -645,7 +652,7 @@ static void process_raw_buffer(int deviceid, char *inbuf, char **max_divenr)
/* this tells us the sections that will follow; the tag here /* this tells us the sections that will follow; the tag here
* is of the format dive-<section> */ * is of the format dive-<section> */
sections[nr_sections] = strchr(tag, '-') + 1; sections[nr_sections] = strchr(tag, '-') + 1;
#if UEMIS_DEBUG > 2 #if UEMIS_DEBUG & 4
fprintf(debugfile, "Expect to find section %s\n", sections[nr_sections]); fprintf(debugfile, "Expect to find section %s\n", sections[nr_sections]);
#endif #endif
if (nr_sections < sizeof(sections) - 1) if (nr_sections < sizeof(sections) - 1)
@ -768,7 +775,7 @@ static char *do_uemis_download(struct argument_block *args)
} }
if (sscanf(newmax, "%d", &end) != 1) if (sscanf(newmax, "%d", &end) != 1)
end = start; end = start;
#if UEMIS_DEBUG > 1 #if UEMIS_DEBUG & 2
fprintf(debugfile, "done: read from object_id %d to %d\n", start, end); fprintf(debugfile, "done: read from object_id %d to %d\n", start, end);
#endif #endif
free(newmax); free(newmax);

View file

@ -40,4 +40,4 @@ typedef struct {
uint8_t flags[8]; uint8_t flags[8];
} __attribute((packed)) uemis_sample_t; } __attribute((packed)) uemis_sample_t;
#endif /* DIVE_H */ #endif /* UEMIS_H */