New Config-Values
[owTools.git] / src / main.cpp
index 5595980..1d9e64f 100755 (executable)
 #endif
 
 void printhelp() {
-printf("owTools - Programm for reading und  controlling 1-Wire Devices from www.tm3d.de\n\n");
+printf("owTools - Program for reading and controlling 1-Wire Devices from www.tm3d.de\n\n");
 printf("run:  owTools -a [COMn|USBn|GPIOn] [options]\n\n");
 printf("    COMn -> Adapter DS9097 and compatible (e.g. LinkUSB)\n");
 printf("         n=1 -> Windows COM1 -> Linux /dev/ttyS1\n");
 printf("    USBn -> Adapter DS2490/DS9490 \n");
 printf("         n=1 -> first USB-Adapter \n");
-printf("    GPIOn -> port of RaspberrPI (port Name not Pin number)\n\n");
-printf("options:\n");
+printf("    GPIOn -> port of RaspberrPI (port Name not Pin number)\n\n");
+printf("Options:\n");
 printf("   -i interactive mode\n");
 printf("          select a device and get information about it\n");
 printf("   -c read and print all continuous\n");
 printf("      -p time in sec between readings\n");
-printf("      -d [config file] put all Data in mysql Database descripted in Config file\n");
+printf("      -d [config file] put all Data in mysql Database descripted in config file\n");
 printf("         Config file: \n");
 printf("            [server]\n");
 printf("            [port] -> 3306\n");
@@ -122,15 +122,18 @@ printf("            [user] \n");
 printf("            [password]\n");
 printf("            [database]\n");
 printf("            [prefix] -> a prefix of all tables \n\n");
-printf("      -r Search everytime for new Devices\n");
-printf("   -f hexfile  Flash new\n");
-printf("   -n change id   \n");
+printf("      -r Search every time for new Devices\n");
+printf("   -f [hexfile]    flash new\n");
+printf("   -n [\"id as 64bit Hex\"] change id   \n");
+printf("               example: -n \"5D02160084D9A220\" \n");
+printf("               no argument increments id by 256 (keep family code) \n");
 printf("      -g get from server\n");
-printf("   -w [1|2] show Warnings (1) or all Infos (2)\n");
+printf("   -w [1|2] show Warnings (1) or all information (2)\n");
 printf("   -m memory functions\n");
 
 
 
+
 }
 
 
@@ -281,6 +284,11 @@ void continuous(std::vector<owDevice*> *devices,int intervall,int headline,int s
                printf("%d-%02d-%02d %02d:%02d:%02d\t", tm.tm_year + 1900, tm.tm_mon + 1, tm.tm_mday, tm.tm_hour, tm.tm_min, tm.tm_sec);
                for (owDevice* dev :*devices) {
                        for(int k=0;k<owi->maxrepeat;k++){
+                               std::vector<uint8_t> data;
+                               //data.push_back(0xCC);
+                               //data.push_back(0x44);
+                               //owi->Reset();
+                               //owi->Communicate(&data, 2, 0);
                                dev->convertAll();
                                if (owi->log->last()<OWLOG_ERROR) break;
                                owi->log->clear();
@@ -462,7 +470,7 @@ int main(int argc, char *argv[]) {
        if(adapter.find("COM")!=std::string::npos) {
                owi=new owCOMInterface();
                int port=atoi(adapter.substr(adapter.find("COM")+3).c_str());
-               printf("Open /dev/ttyS%i\n",port);
+               printf("Open /dev/ttyUSB%i\n",port);
                owi->InitAdapter(port);
        } else 
        if(adapter.find("USB")!=std::string::npos) {
@@ -675,6 +683,7 @@ int main(int argc, char *argv[]) {
                sel-=1;
                
                snum_t snum=owi->devices[sel]->getNum();
+               
                if ((getArg("g"))=="1") {
                        printf("get ID from Server\n");
                        char s[255];
@@ -719,7 +728,18 @@ int main(int argc, char *argv[]) {
                                snum.num=isnum.num;
                        } else (printf("ERROR %i\n",err));
                } else {
-                       snum.num+=256;
+                       if (s=="1") {
+                               snum.num+=256;
+                       } else {
+                               unsigned long long l=strtol(s.c_str(),NULL,16);
+                               if ((snum.num&0xFF)!=(l&0xFF)) {
+                                       printf("ERROR: Family of Device 0x%02X->0x%02X can not be changed\n",(int)(snum.num&0xFF),(int)(l&0xFF));
+                                       exit(1);
+                               }
+                               snum.num=l;
+                               //printf("->%016llX\n",(unsigned long long)l);
+                       }
+                       
                }