X-Git-Url: http://git.smho.de/gw/?p=owSlave2.git;a=blobdiff_plain;f=tools_cmd%2FrwOW%2Fmain.cpp;fp=tools_cmd%2FrwOW%2Fmain.cpp;h=184ffd7f767a4a0b25d56811f42000a57d3d3fa2;hp=0000000000000000000000000000000000000000;hb=cd92472e6fd63693741f8e168123a4182802651b;hpb=0f5b4d994ac87afdd294f6fc79692bcf92e337de diff --git a/tools_cmd/rwOW/main.cpp b/tools_cmd/rwOW/main.cpp new file mode 100644 index 0000000..184ffd7 --- /dev/null +++ b/tools_cmd/rwOW/main.cpp @@ -0,0 +1,391 @@ +#define _CRT_SECURE_NO_WARNINGS 1 +extern "C" { +#include "ownet.h" +} +#include +#include +#include + +FILE *fio; +char s[100], fname[254]; + + +SMALLINT ReadDS2430(int portnum, uchar SerialNum[8]) { + uchar rt = FALSE; + uchar send_block[145]; + uchar send_cnt = 0, i; + int address; + char s[100]; + FILE *f; + 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]); + fprintf(fio, ">14\n"); + send_cnt = 0; + printf("Read Data MEM \n"); + if (!owAccess(portnum)) { printf("ERROR MATCH ROM \n"); return 1; } + send_block[send_cnt++] = 0xF0; + send_block[send_cnt++] = 0x00; + for (i = 0; i<32; i++) send_block[send_cnt++] = 0xFF; + if (!owBlock(portnum, FALSE, send_block, send_cnt)) { printf("ERROR RUN COMMAND \n"); return 1; } + for (i = 2; i TEST DS2433 \n"); + fprintf(fio, ">23\n"); + + send_cnt = 0; + printf("\nRead MEM ALL \n"); + if (!owAccess(portnum)) { printf("ERROR MATCH ROM \n"); return 1; } + send_block[send_cnt++] = 0xF0; + send_block[send_cnt++] = 0x00; + send_block[send_cnt++] = 0x00; + for (j = 0; j<16; j++) { + for (i = 0; i<32; i++) send_block[send_cnt++] = 0xFF; + if (!owBlock(portnum, FALSE, send_block, send_cnt)) { printf("ERROR RUN COMMAND \n"); return 1; } + for (i = j?0:3; i < send_cnt; i++) { printf("%02X ", send_block[i]); fprintf(fio, "%02X ", send_block[i]); } + send_cnt = 0; + printf("\n"); + fprintf(fio, "\n"); + } + +} + + +int findDev(uchar code) { + int find = 0; + fio = fopen(fname, "r"); + while (!feof(fio)) { + s[0] = fgetc(fio); + if (s[0] == '>') { + s[0] = fgetc(fio); + s[1] = fgetc(fio); + s[2] = 0; + uchar w = strtol(s, NULL, 16); + if (code ==w) return 1; + } + } + fclose(fio); + return 0; +} + + + +SMALLINT WriteDS2433(int portnum, uchar SerialNum[8]) { + uchar rt = FALSE; + uchar send_block[145]; + uchar send_cnt = 0, i, j; + int address; + send_cnt = 0; + printf("-----> TEST DS2433 \n"); + if (findDev(0x23)) { + for (j = 0; j < 16; j++) { + for (i = 0; i < 32; i++) { + fscanf(fio, "%02X", &send_block[i + 3]); + } + if (!owAccess(portnum)) { printf("ERROR MATCH ROM \n"); return 1; } + send_block[0] = 0x0F; + send_block[1] = j << 5; + send_block[2] = j >> 3; + if (!owBlock(portnum, FALSE, send_block, 32 + 3)) { printf("ERROR RUN COMMAND \n"); return 1; } + if (!owAccess(portnum)) { printf("ERROR MATCH ROM \n"); return 1; } + send_cnt = 0; + send_block[send_cnt++] = 0xAA; + for (i = 0; i < 32 + 3; i++) send_block[send_cnt++] = 0xFF; + if (!owBlock(portnum, FALSE, send_block, send_cnt)) { printf("ERROR RUN COMMAND \n"); return 1; } + for (i = 0; i < send_cnt; i++) { printf("%02X ", send_block[i]); } + if (!owAccess(portnum)) { printf("ERROR MATCH ROM \n"); return 1; } + send_cnt = 0; + send_block[send_cnt++] = 0x55; + send_cnt += 3; + if (!owBlock(portnum, FALSE, send_block, send_cnt)) { printf("ERROR RUN COMMAND \n"); return 1; } + msDelay(100); + printf("\n"); + } + + } + fclose(fio); + return 0; + + +} + + +SMALLINT WriteDS2430(int portnum, uchar SerialNum[8]) { + uchar rt = FALSE; + uchar send_block[145]; + uchar send_cnt = 0, i, j; + int address; + send_cnt = 0; + printf("-----> TEST DS2430 \n"); + if (findDev(0x14)) { + for (i = 0; i < 32; i++) { + fscanf(fio, "%02X", &send_block[i + 2]); + } + if (!owAccess(portnum)) { printf("ERROR MATCH ROM \n"); return 1; } + send_block[0] = 0x0F; + send_block[1] = 0; + if (!owBlock(portnum, FALSE, send_block, 32 + 2)) { printf("ERROR RUN COMMAND \n"); return 1; } + if (!owAccess(portnum)) { printf("ERROR MATCH ROM \n"); return 1; } + send_cnt = 0; + send_block[send_cnt++] = 0xAA; + send_block[send_cnt++] = 0x00; + for (i = 0; i < 32 + 2; i++) send_block[send_cnt++] = 0xFF; + if (!owBlock(portnum, FALSE, send_block, send_cnt)) { printf("ERROR RUN COMMAND \n"); return 1; } + for (i = 0; i < send_cnt; i++) { printf("%02X ", send_block[i]); } + if (!owAccess(portnum)) { printf("ERROR MATCH ROM \n"); return 1; } + send_cnt = 0; + send_block[send_cnt++] = 0x55; + send_block[send_cnt++] = 0xA5; + if (!owBlock(portnum, FALSE, send_block, send_cnt)) { printf("ERROR RUN COMMAND \n"); return 1; } + msDelay(100); + printf("\n"); + } + fclose(fio); + +} +/* +SMALLINT WriteDS2430(int portnum, uchar SerialNum[8], const char *fname) { + uchar rt = FALSE; + uchar send_block[145]; + uchar send_cnt = 0, i; + int address; + uchar readbl[64]; + FILE *f; + f = fopen(fname, "rb"); + fread(readbl, 1, 32 + 16, f); + fclose(f); + ResetDS2430(portnum, SerialNum); + msDelay(1000); + send_cnt = 0; + if (!owAccess(portnum)) { printf("ERROR MATCH ROM \n"); return 1; } + send_block[send_cnt++] = 0x0F; + send_block[send_cnt++] = 0x00; + for (i = 0; i<32; i++) send_block[send_cnt++] = readbl[i + 8]; + if (!owBlock(portnum, FALSE, send_block, send_cnt)) { printf("ERROR RUN COMMAND \n"); return 1; } + send_cnt = 0; + if (!owAccess(portnum)) { printf("ERROR MATCH ROM \n"); return 1; } + send_block[send_cnt++] = 0xAA; + send_block[send_cnt++] = 0x00; + for (i = 0; i<32; i++) send_block[send_cnt++] = 0xFF; + if (!owBlock(portnum, FALSE, send_block, send_cnt)) { printf("ERROR RUN COMMAND \n"); return 1; } + for (i = 0; i= '0') && (s[i] <= '9')) { + b += s[i] - '0'; + } else + if ((s[i] >= 'A') && (s[i] <= 'F')) { + b += s[i] - 'A'+10; + } else + if ((s[i] >= 'a') && (s[i] <= 'f')) { + b += s[i] - 'a'+10; + } + + } + return b; +} + +void strcpys(char *s, const char* d,bool up) { + if (strlen(d) > 7990) { + strncpy(s, d, 7990); + s[200] = 0; + } + else strcpy(s, d); + if (up) { + for (int i = 0; i= 'a') && (s[i] <= 'z')) + s[i] += 'A' - 'a'; + } +} + +int main(int argc, char *argv[]) { + uchar SNum[8]; + int rslt, cnt, i; + uchar send_block[256]; + uchar send_cnt = 0; + int portnum; + char adapter[20]; + int found = 0; + int rw = 0; + int err = 0; + char s[8000]; + int adt = 0; + int mod = 0; + if (argc >= 2) { + strcpys(s, argv[1],true); + + + if (strncmp(s,"USB",3)==0) {adt = 6;} + if (strncmp(s, "COM", 3) == 0) { adt = 5; } + if (adt != 0) { + strcpy(s, argv[1] + 3); + sprintf(adapter, "{%s,%i}\0",s,adt); + printf("Open Port %s\n", argv[1]); + if ((portnum = owAcquireEx(adapter)) < 0) { + printf("ERROR \n", adt); + } + else mod = 1; + + } + if ((argc == 2) && (mod == 1)) mod = 2; + if (argc > 2) { + strcpys(s, argv[2],true); + if (strncmp(s, "DC", 2) == 0) { + if (argc > 3) { + if (strlen(argv[3])>=16) + for (int i = 0; i < 16; i += 2) { + SNum[7 - (i / 2)] = conf2(argv[3] + i); + + } + 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]); + mod = 3; + } + + } + } + if ((mod == 3) && (argc>4)) { + strcpys(s, argv[4], true); + mod = 4; + } + + } + + if (mod == 2) { + rslt = owFirst(portnum, TRUE, FALSE); + cnt = 0; + while (rslt) { + cnt++; + owSerialNum(portnum, &SNum[0], TRUE); + 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]); + // 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]); +/* switch (SNum[0]) { + + + case 0x14: { + //TestDS2430(portnum,&SNum[0]); + //scanf("%i",&i); + //ResetDS2430(portnum,&SNum[0]); + //uchar id[]={0x14,0xF5 ,0xEA ,0x24 ,0x06 ,0x00 ,0x00 ,0x5E}; + //SetIDDS2430(portnum,&SNum[0],id); + if (rw) WriteDS2430(portnum, &SNum[0]); else ReadDS2430(portnum, &SNum[0]); + //WriteDS2430(portnum,&SNum[0],"5E00000624EAF514.bin"); + break; + } + case 0x23: { + //TestDS2433(portnum,&SNum[0]); + //TestDS2433_reset(portnum,&SNum[0]); + //scanf("%i",&i); + if (rw) WriteDS2433(portnum, &SNum[0]); else ReadDS2433(portnum, &SNum[0]); + break; + } + }*/ + rslt = owNext(portnum, TRUE, FALSE); + } + } + if (mod == 4) { + owSerialNum(portnum, SNum, FALSE); + strcat(s, "_R"); + int len = strlen(s); + int i = 0; + while (i < len) { + if (s[i] == '_') { + if (s[i + 1] == 'R') { + if (owAccess(portnum)) { + if (owBlock(portnum, FALSE, send_block, send_cnt)) { + for (int j = 0; j < send_cnt; j++) { + printf("%02X", send_block[j]); + } + printf("\n"); + } + else printf("ERROR RESET\n"); + } + else printf("ERROR SEND\n"); + send_cnt = 0; + } + if (s[i + 1] == 'P') { + if (i + 2 < len) { + i += 2; + msDelay(conf2(s + i)); + + } + } + } + else { + send_block[send_cnt++] = conf2(s + i); + } + i += 2; + + + } + } + if (mod>0) owRelease(portnum); + + return 0; +} \ No newline at end of file