forked from vdudouyt/minipro
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathminipro-query-db.c
93 lines (83 loc) · 2.16 KB
/
minipro-query-db.c
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <strings.h>
#include <unistd.h>
#include "minipro.h"
#include "byte_utils.h"
#include "database.h"
#include "error.h"
void print_help_and_exit(const char *progname) {
fprintf(stderr, "Usage: %s [-s search] [<device>]\n", progname);
exit(-1);
}
void print_device_info(device_t *device) {
printf("Name: %s\n", device->name);
/* Memory shape */
printf("Memory: %d", device->code_memory_size / WORD_SIZE(device));
switch(device->opts4 & 0xFF000000) {
case 0x00000000:
printf(" Bytes");
break;
case 0x01000000:
printf(" Words");
break;
case 0x02000000:
printf(" Bits");
break;
default:
ERROR2("Unknown memory shape: 0x%x\n", device->opts4 & 0xFF000000);
}
if(device->data_memory_size) {
printf(" + %d Bytes", device->data_memory_size);
}
if(device->data_memory2_size) {
printf(" + %d Bytes", device->data_memory2_size);
}
printf("\n");
unsigned char package_details[4];
format_int(package_details, device->package_details, 4, MP_LITTLE_ENDIAN);
/* Package info */
printf("Package: ");
if(package_details[0]) {
printf("Adapter%03d.JPG\n", package_details[0]);
} else if(package_details[3]) {
printf("DIP%d\n", package_details[3] & 0x7F);
} else {
printf("ISP only\n");
}
/* ISP connection info */
printf("ISP: ");
if(package_details[1]) {
printf("ICP%03d.JPG\n", package_details[1]);
} else {
printf("-\n");
}
printf("Protocol: 0x%02x\n", device->protocol_id);
printf("Read buffer size: %d Bytes\n", device->read_buffer_size);
printf("Write buffer size: %d Bytes\n", device->write_buffer_size);
}
int main(int argc, char **argv) {
if(argc < 2) {
print_help_and_exit(argv[0]);
}
if(!strcmp(argv[1], "-s")) {
if(argc < 3) {
print_help_and_exit(argv[0]);
}
// Listing all devices that starts with argv[2]
device_t *device;
for(device = &(devices[0]); device[0].name; device = &(device[1])) {
if(!strncasecmp(device[0].name, argv[2], strlen(argv[2]))) {
printf("%s\n", device[0].name);
}
}
return(0);
}
device_t *device = get_device_by_name(argv[1]);
if(!device) {
ERROR("Unknown device");
}
print_device_info(device);
return(0);
}