1 #define _CRT_SECURE_NO_WARNINGS 1
10 char s[100], fname[254];
13 SMALLINT ReadDS2430(int portnum, uchar SerialNum[8]) {
15 uchar send_block[145];
16 uchar send_cnt = 0, i;
20 sprintf(s, "%02X%02X%02X%02X%02X%02X%02X%02X.bin", SerialNum[7], SerialNum[6], SerialNum[5], SerialNum[4], SerialNum[3], SerialNum[2], SerialNum[1], SerialNum[0]);
21 fprintf(fio, ">14\n");
23 printf("Read Data MEM \n");
24 if (!owAccess(portnum)) { printf("ERROR MATCH ROM \n"); return 1; }
25 send_block[send_cnt++] = 0xF0;
26 send_block[send_cnt++] = 0x00;
27 for (i = 0; i<32; i++) send_block[send_cnt++] = 0xFF;
28 if (!owBlock(portnum, FALSE, send_block, send_cnt)) { printf("ERROR RUN COMMAND \n"); return 1; }
29 for (i = 2; i<send_cnt; i++) { printf("%02X ", send_block[i]); fprintf(fio,"%02X ", send_block[i]); }
33 printf("Read App MEM \n");
34 if (!owAccess(portnum)) { printf("ERROR MATCH ROM \n"); return 1; }
35 send_block[send_cnt++] = 0xC3;
36 send_block[send_cnt++] = 0x00;
37 for (i = 0; i<8; i++) send_block[send_cnt++] = 0xFF;
38 if (!owBlock(portnum, FALSE, send_block, send_cnt)) { printf("ERROR RUN COMMAND \n"); return 1; }
39 for (i = 2; i<send_cnt; i++) { printf("%02X ", send_block[i]); fprintf(fio, "%02X ", send_block[i]); }
44 printf("Read App State \n");
45 if (!owAccess(portnum)) { printf("ERROR MATCH ROM \n"); return 1; }
46 send_block[send_cnt++] = 0x66;
47 for (i = 0; i<1; i++) send_block[send_cnt++] = 0xFF;
48 if (!owBlock(portnum, FALSE, send_block, send_cnt)) { printf("ERROR RUN COMMAND \n"); return 1; }
49 for (i = 1; i<send_cnt; i++) { printf("%02X ", send_block[i]); fprintf(fio, "%02X ", send_block[i]); }
55 SMALLINT ReadDS2433(int portnum, uchar SerialNum[8]) {
57 uchar send_block[145];
58 uchar send_cnt = 0, i, j;
61 printf("-----> TEST DS2433 \n");
62 fprintf(fio, ">23\n");
65 printf("\nRead MEM ALL \n");
66 if (!owAccess(portnum)) { printf("ERROR MATCH ROM \n"); return 1; }
67 send_block[send_cnt++] = 0xF0;
68 send_block[send_cnt++] = 0x00;
69 send_block[send_cnt++] = 0x00;
70 for (j = 0; j<16; j++) {
71 for (i = 0; i<32; i++) send_block[send_cnt++] = 0xFF;
72 if (!owBlock(portnum, FALSE, send_block, send_cnt)) { printf("ERROR RUN COMMAND \n"); return 1; }
73 for (i = j?0:3; i < send_cnt; i++) { printf("%02X ", send_block[i]); fprintf(fio, "%02X ", send_block[i]); }
82 int findDev(uchar code) {
84 fio = fopen(fname, "r");
91 uchar w = strtol(s, NULL, 16);
92 if (code ==w) return 1;
101 SMALLINT WriteDS2433(int portnum, uchar SerialNum[8]) {
103 uchar send_block[145];
104 uchar send_cnt = 0, i, j;
107 printf("-----> TEST DS2433 \n");
109 for (j = 0; j < 16; j++) {
110 for (i = 0; i < 32; i++) {
111 fscanf(fio, "%02X", &send_block[i + 3]);
113 if (!owAccess(portnum)) { printf("ERROR MATCH ROM \n"); return 1; }
114 send_block[0] = 0x0F;
115 send_block[1] = j << 5;
116 send_block[2] = j >> 3;
117 if (!owBlock(portnum, FALSE, send_block, 32 + 3)) { printf("ERROR RUN COMMAND \n"); return 1; }
118 if (!owAccess(portnum)) { printf("ERROR MATCH ROM \n"); return 1; }
120 send_block[send_cnt++] = 0xAA;
121 for (i = 0; i < 32 + 3; i++) send_block[send_cnt++] = 0xFF;
122 if (!owBlock(portnum, FALSE, send_block, send_cnt)) { printf("ERROR RUN COMMAND \n"); return 1; }
123 for (i = 0; i < send_cnt; i++) { printf("%02X ", send_block[i]); }
124 if (!owAccess(portnum)) { printf("ERROR MATCH ROM \n"); return 1; }
126 send_block[send_cnt++] = 0x55;
128 if (!owBlock(portnum, FALSE, send_block, send_cnt)) { printf("ERROR RUN COMMAND \n"); return 1; }
141 SMALLINT WriteDS2430(int portnum, uchar SerialNum[8]) {
143 uchar send_block[145];
144 uchar send_cnt = 0, i, j;
147 printf("-----> TEST DS2430 \n");
149 for (i = 0; i < 32; i++) {
150 fscanf(fio, "%02X", &send_block[i + 2]);
152 if (!owAccess(portnum)) { printf("ERROR MATCH ROM \n"); return 1; }
153 send_block[0] = 0x0F;
155 if (!owBlock(portnum, FALSE, send_block, 32 + 2)) { printf("ERROR RUN COMMAND \n"); return 1; }
156 if (!owAccess(portnum)) { printf("ERROR MATCH ROM \n"); return 1; }
158 send_block[send_cnt++] = 0xAA;
159 send_block[send_cnt++] = 0x00;
160 for (i = 0; i < 32 + 2; i++) send_block[send_cnt++] = 0xFF;
161 if (!owBlock(portnum, FALSE, send_block, send_cnt)) { printf("ERROR RUN COMMAND \n"); return 1; }
162 for (i = 0; i < send_cnt; i++) { printf("%02X ", send_block[i]); }
163 if (!owAccess(portnum)) { printf("ERROR MATCH ROM \n"); return 1; }
165 send_block[send_cnt++] = 0x55;
166 send_block[send_cnt++] = 0xA5;
167 if (!owBlock(portnum, FALSE, send_block, send_cnt)) { printf("ERROR RUN COMMAND \n"); return 1; }
175 SMALLINT WriteDS2430(int portnum, uchar SerialNum[8], const char *fname) {
177 uchar send_block[145];
178 uchar send_cnt = 0, i;
182 f = fopen(fname, "rb");
183 fread(readbl, 1, 32 + 16, f);
185 ResetDS2430(portnum, SerialNum);
188 if (!owAccess(portnum)) { printf("ERROR MATCH ROM \n"); return 1; }
189 send_block[send_cnt++] = 0x0F;
190 send_block[send_cnt++] = 0x00;
191 for (i = 0; i<32; i++) send_block[send_cnt++] = readbl[i + 8];
192 if (!owBlock(portnum, FALSE, send_block, send_cnt)) { printf("ERROR RUN COMMAND \n"); return 1; }
194 if (!owAccess(portnum)) { printf("ERROR MATCH ROM \n"); return 1; }
195 send_block[send_cnt++] = 0xAA;
196 send_block[send_cnt++] = 0x00;
197 for (i = 0; i<32; i++) send_block[send_cnt++] = 0xFF;
198 if (!owBlock(portnum, FALSE, send_block, send_cnt)) { printf("ERROR RUN COMMAND \n"); return 1; }
199 for (i = 0; i<send_cnt; i++) { printf("%02X ", send_block[i]); if ((i - 1) % 16 == 0) printf("\n"); }
202 if (!owAccess(portnum)) { printf("ERROR MATCH ROM \n"); return 1; }
203 send_block[send_cnt++] = 0x55;
204 send_block[send_cnt++] = 0xA5;
205 if (!owBlock(portnum, FALSE, send_block, send_cnt)) { printf("ERROR RUN COMMAND \n"); return 1; }
209 if (!owAccess(portnum)) { printf("ERROR MATCH ROM \n"); return 1; }
210 send_block[send_cnt++] = 0xF0;
211 send_block[send_cnt++] = 0x00;
212 for (i = 0; i<32; i++) send_block[send_cnt++] = 0xFF;
213 if (!owBlock(portnum, FALSE, send_block, send_cnt)) { printf("ERROR RUN COMMAND \n"); return 1; }
214 for (i = 0; i<send_cnt; i++) { printf("%02X ", send_block[i]); if ((i - 1) % 16 == 0) printf("\n"); }
217 if (!owAccess(portnum)) { printf("ERROR MATCH ROM \n"); return 1; }
218 send_block[send_cnt++] = 0x99;
219 send_block[send_cnt++] = 0x00;
220 for (i = 0; i<8; i++) send_block[send_cnt++] = readbl[i + 8 + 32];
221 if (!owBlock(portnum, FALSE, send_block, send_cnt)) { printf("ERROR RUN COMMAND \n"); return 1; }
224 if (!owAccess(portnum)) { printf("ERROR MATCH ROM \n"); return 1; }
225 send_block[send_cnt++] = 0x5A;
226 send_block[send_cnt++] = 0xA5;
227 if (!owBlock(portnum, FALSE, send_block, send_cnt)) { printf("ERROR RUN COMMAND \n"); return 1; }
229 SetIDDS2430(portnum, SerialNum, readbl);
237 unsigned char conf2(const char *s) {
239 for (int i = 0; i < 2; i++) {
241 if ((s[i] >= '0') && (s[i] <= '9')) {
244 if ((s[i] >= 'A') && (s[i] <= 'F')) {
247 if ((s[i] >= 'a') && (s[i] <= 'f')) {
255 void strcpys(char *s, const char* d,bool up) {
256 if (strlen(d) > 7990) {
262 for (int i = 0; i<strlen(s); i++)
263 if ((s[i] >= 'a') && (s[i] <= 'z'))
268 int main(int argc, char *argv[]) {
271 uchar send_block[256];
282 strcpys(s, argv[1],true);
285 if (strncmp(s,"USB",3)==0) {adt = 6;}
286 if (strncmp(s, "COM", 3) == 0) { adt = 5; }
288 strcpy(s, argv[1] + 3);
289 sprintf(adapter, "{%s,%i}\0",s,adt);
290 printf("Open Port %s\n", argv[1]);
291 if ((portnum = owAcquireEx(adapter)) < 0) {
292 printf("ERROR \n", adt);
297 if ((argc == 2) && (mod == 1)) mod = 2;
299 strcpys(s, argv[2],true);
300 if (strncmp(s, "DC", 2) == 0) {
302 if (strlen(argv[3])>=16)
303 for (int i = 0; i < 16; i += 2) {
304 SNum[7 - (i / 2)] = conf2(argv[3] + i);
307 printf("Select: %02X%02X%02X%02X%02X%02X%02X%02X\n", SNum[7], SNum[6], SNum[5], SNum[4], SNum[3], SNum[2], SNum[1], SNum[0]);
313 if ((mod == 3) && (argc>4)) {
314 strcpys(s, argv[4], true);
321 rslt = owFirst(portnum, TRUE, FALSE);
325 owSerialNum(portnum, &SNum[0], TRUE);
326 printf("%02X%02X%02X%02X%02X%02X%02X%02X\n", SNum[7], SNum[6], SNum[5], SNum[4], SNum[3], SNum[2], SNum[1], SNum[0]);
327 // fprintf(ft,"%02X%02X%02X%02X%02X%02X%02X%02X\n",SNum[7],SNum[6],SNum[5],SNum[4],SNum[3],SNum[2],SNum[1],SNum[0]);
328 /* switch (SNum[0]) {
332 //TestDS2430(portnum,&SNum[0]);
334 //ResetDS2430(portnum,&SNum[0]);
335 //uchar id[]={0x14,0xF5 ,0xEA ,0x24 ,0x06 ,0x00 ,0x00 ,0x5E};
336 //SetIDDS2430(portnum,&SNum[0],id);
337 if (rw) WriteDS2430(portnum, &SNum[0]); else ReadDS2430(portnum, &SNum[0]);
338 //WriteDS2430(portnum,&SNum[0],"5E00000624EAF514.bin");
342 //TestDS2433(portnum,&SNum[0]);
343 //TestDS2433_reset(portnum,&SNum[0]);
345 if (rw) WriteDS2433(portnum, &SNum[0]); else ReadDS2433(portnum, &SNum[0]);
349 rslt = owNext(portnum, TRUE, FALSE);
353 owSerialNum(portnum, SNum, FALSE);
359 if (s[i + 1] == 'R') {
360 if (owAccess(portnum)) {
361 if (owBlock(portnum, FALSE, send_block, send_cnt)) {
362 for (int j = 0; j < send_cnt; j++) {
363 printf("%02X", send_block[j]);
367 else printf("ERROR RESET\n");
369 else printf("ERROR SEND\n");
372 if (s[i + 1] == 'P') {
375 msDelay(conf2(s + i));
381 send_block[send_cnt++] = conf2(s + i);
388 if (mod>0) owRelease(portnum);