remove compiler warnings of new compilerversion /
authorTobias <tm@tm3d.de>
Mon, 8 Apr 2019 12:35:56 +0000 (14:35 +0200)
committerTobias <tm@tm3d.de>
Mon, 8 Apr 2019 12:35:56 +0000 (14:35 +0200)
add memory functions of DS2450 /
add 0xCC by command line

Makefile.am [changed mode: 0755->0644]
src/main.cpp
src/owCOMInterface.cpp
src/owDevice.cpp
src/owInterface.cpp
src/owInterface.h
src/owUSBInterface.cpp

old mode 100755 (executable)
new mode 100644 (file)
index c4e223d..51fd6c0 100644 (file)
@@ -129,6 +129,7 @@ printf("            [database]\n");
 printf("            [prefix] -> a prefix of all tables \n\n");
 printf("      -r Search every time for new Devices\n");
 printf("      -t [text_file] append comma separadet to text-file\n");
+printf("      -j Use 0xCC 0x44 to send convert temperature to all DS18B20 and DS2438\n");
 printf("   -f [hexfile]    flash new\n");
 printf("   -n [\"id as 64bit Hex\"] change id   \n");
 printf("               example: -n \"5D02160084D9A220\" \n");
@@ -318,11 +319,13 @@ void continuous(std::vector<owDevice*> *devices,int intervall,int headline,int s
 
                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);
+                               if (owCC_44_Temp>0) {
+                                       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();
@@ -610,6 +613,10 @@ int main(int argc, char *argv[]) {
                interactive(owi);       
        } else 
        if (getArg("c")=="1") {
+               if (getArg("j")=="1") {
+                       printf("Use 1-Wire command 0xCC 0x44 to send convert temperature to all DS18B20 and DS2438\n");
+                       owCC_44_Temp=1;
+               }
                int reload=(getArg("r")=="1");
                owi->Find();
                printf("\n");
@@ -829,8 +836,12 @@ int main(int argc, char *argv[]) {
                        } else {
                                unsigned long long l=strtoull(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);
+                                         printf("This command change family-fode of Device 0x%02X->0x%02X\n",(int)(snum.num&0xFF),(int)(l&0xFF));
+                                        int resetid=questionYesNo("Are you sure?");
+                                        if (resetid==0) {
+                                          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);
index 6b55e94..3bae680 100644 (file)
@@ -331,7 +331,7 @@ int owCOMInterface::ReadCOM( int inlen, uint8_t *inbuf)
       FD_SET(fd,&filedescr);
       // set timeout to 10ms
       tval.tv_sec = 0;
-      tval.tv_usec = 20000;
+      tval.tv_usec = 20000;  //TOOO CHECK!!!!!!!!!!!!!!!!!!
 
       // if byte available read or return bytes read
       if (select(fd+1,&filedescr,NULL,NULL,&tval) != 0)
index 5d3e99a..2c1ee64 100644 (file)
@@ -1,4 +1,4 @@
-// Copyright (c) 2017, Tobias Mueller tm(at)tm3d.de\r
+// Copyright (c) 2019, Tobias Mueller tm(at)tm3d.de\r
 // All rights reserved.\r
 //\r
 // Redistribution and use in source and binary forms, with or without\r
@@ -149,8 +149,8 @@ int owDevice::CommunicateShort(std::vector<uint8_t> *data, int scount, int rcoun
 void owDevice::changeID(snum_t nid) {\r
        int i;\r
        if (nid.byte[0] != snum.byte[0]) {\r
-               owi->log->set(OWLOG_ERROR,"Family ID should not be changed, no correct ID");\r
-               return;\r
+               owi->log->set(OWLOG_WARNING,"Family ID should not be changed, no correct ID");\r
+               //return;\r
        }\r
        std::vector<uint8_t> id;\r
        for(i=0;i<7;i++) id.push_back(nid.byte[i]);\r
@@ -231,10 +231,11 @@ int owDeviceDS18B20::readScratchpad(std::vector<uint8_t> *sp) {
 \r
 int owDeviceDS18B20::convertAll() {\r
        std::vector<uint8_t> sp;\r
-       sp.push_back(0x44);\r
-       Communicate(&sp, 1, 0); ///########################################################\r
-       usleep(750000);\r
-\r
+       if (owCC_44_Temp==0) {\r
+               sp.push_back(0x44);\r
+               Communicate(&sp, 1, 0); ///########################################################\r
+               usleep(750000);\r
+       }\r
        if (readScratchpad(&sp)) {\r
                int16_t tsht;\r
                tsht = sp[0] | ((int)sp[1] << 8);\r
@@ -242,7 +243,7 @@ int owDeviceDS18B20::convertAll() {
                        tsht |= 0xFFFFF0000;\r
                raw[0]=tsht;\r
                values[0]=config->calculateValue(0, raw);\r
-                       return 1;\r
+               return 1;\r
        }               \r
        return 0;\r
 }\r
@@ -375,10 +376,12 @@ inline int16_t ow_fconvert(uint8_t b1, uint16_t b2) {
 int owDeviceDS2438::convertAll() {\r
        for(int k=0;k<owi->maxrepeat;k++)  {\r
                std::vector<uint8_t> sp;\r
-               sp.push_back(0x44);\r
-               Communicate(&sp, 1, 0);///########################################################\r
-               if (owi->log->last()>=OWLOG_ERROR) continue;\r
-               usleep(100000);\r
+               if (owCC_44_Temp==0) {\r
+                       sp.push_back(0x44);\r
+                       Communicate(&sp, 1, 0);///########################################################\r
+                       if (owi->log->last()>=OWLOG_ERROR) continue;\r
+                       usleep(100000);\r
+               }\r
                if (setConfigByte(0x08)<=0) continue;\r
                for(int k=0;k<owi->maxrepeat;k++) {\r
                        sp.clear();\r
@@ -432,7 +435,7 @@ int owDeviceDS2450::convertAll() {
                return 0;\r
        }\r
        std::vector<uint8_t> sp;\r
-       readMemory(0,&sp);\r
+       readMemory(0,0,8,&sp);\r
        if (owi->log->last()>=OWLOG_WARNING) {\r
                return 0;\r
        }\r
@@ -447,7 +450,69 @@ int owDeviceDS2450::convertAll() {
 \r
 }\r
 \r
-void owDeviceDS2450::readMemory(uint8_t addr,std::vector<uint8_t> *sp) {\r
+int owDeviceDS2450::readMemory(int page,int start, int count,std::vector<uint8_t> *data) {\r
+       std::vector<uint8_t> cl;\r
+       cl.push_back(0xAA);\r
+       cl.push_back(page*8+start);\r
+       cl.push_back(0x00);\r
+       Communicate(&cl,3,10-start);\r
+       if (owi->log->last()>=OWLOG_WARNING) {\r
+               return 0;\r
+       }\r
+       if (!owi->testCRC16(cl)) {\r
+               for (uint8_t v :cl) printf("%02X ",v);\r
+               printf("\n");\r
+               owi->log->set(OWLOG_ERROR,"CRC ERROR Reading Memory of DS2450");\r
+               return 0;\r
+       }\r
+       data->clear();\r
+       data->insert(data->begin(),cl.begin()+3,cl.end()-2);\r
+       return count;\r
+}\r
+int owDeviceDS2450::writeMemory(int page,int start, int count,std::vector<uint8_t> *data) {\r
+       std::vector<uint8_t> cl;\r
+       cl.push_back(0x55);\r
+       cl.push_back(page*8+start);\r
+       cl.push_back(0x00);\r
+       owi->MatchRom(snum);\r
+       if (owi->log->last()>=OWLOG_WARNING) {\r
+               return 0;\r
+       }\r
+       int i=0;\r
+       for(uint8_t b: (*data)) {\r
+               cl.push_back(b);\r
+               owi->Communicate(&cl,cl.size(),2);\r
+               if (owi->log->last()>=OWLOG_WARNING) {\r
+                       return 0;\r
+               }\r
+               if (i>0) {\r
+                       if (!owi->testCRC16(cl,i+page*8+start)) {\r
+                               owi->log->set(OWLOG_ERROR,"CRC ERROR Writing Memory of DS2450");\r
+                               return 0;\r
+                       }\r
+               } else {\r
+                       if (!owi->testCRC16(cl)) {\r
+                               owi->log->set(OWLOG_ERROR,"CRC ERROR Writing Memory of DS2450");\r
+                               return 0;\r
+                       }\r
+               }\r
+               cl.clear();\r
+               owi->Communicate(&cl, 0, 1);\r
+               if (owi->log->last()>=OWLOG_WARNING) {\r
+                       return 0;\r
+               }\r
+               if (cl[0] != b) {\r
+                       owi->log->set(OWLOG_ERROR,"ERROR Writing Memory of DS2450");\r
+                       return 0;\r
+               }\r
+               cl.clear();\r
+               i++;\r
+       }\r
+       return count;\r
+}\r
+\r
+\r
+void owDeviceDS2450::readMemory_int(uint8_t addr,std::vector<uint8_t> *sp) {\r
        std::vector<uint8_t> cl;\r
        cl.push_back(0xAA);\r
        cl.push_back(addr);\r
@@ -466,7 +531,7 @@ void owDeviceDS2450::readMemory(uint8_t addr,std::vector<uint8_t> *sp) {
        sp->insert(sp->begin(),cl.begin()+3,cl.end()-2);\r
 }\r
 \r
-void owDeviceDS2450::writeMemory(uint8_t addr,std::vector<uint8_t> *sp) {\r
+void owDeviceDS2450::writeMemory_int(uint8_t addr,std::vector<uint8_t> *sp) {\r
        std::vector<uint8_t> cl;\r
        cl.push_back(0x55);\r
        cl.push_back(addr);\r
index b4d5d93..3da8460 100644 (file)
@@ -38,6 +38,7 @@
 #include <math.h>\r
 #include "hexfile.h"\r
 \r
+uint8_t owCC_44_Temp=0;\r
 \r
 #ifdef WIN\r
 void usleep(__int64 usec)\r
@@ -118,6 +119,16 @@ uint16_t owInterface::calcCRC16(std::vector<uint8_t> data) {
 int owInterface::testCRC16(std::vector<uint8_t> data)  {\r
        return calcCRC16(data)==0xB001;\r
 }\r
+\r
+int owInterface::testCRC16(std::vector<uint8_t> data,uint16_t load) {\r
+       crc16=load;\r
+       for(uint8_t v:data) {\r
+               docrc16(v);\r
+       }\r
+       return crc16==0xB001;\r
+\r
+}\r
+\r
                \r
 void owInterface::resetFlasher(uint64_t id) { // go back from Bootloader\r
        std::vector<uint8_t> data;\r
index 7e1edb0..0a568df 100644 (file)
@@ -107,6 +107,8 @@ class owDeviceConfig;
 
 #endif
 
+extern uint8_t owCC_44_Temp;
+
 class owLog {
        int lcount;
        std::string logtext;
@@ -231,6 +233,7 @@ public:
        uint8_t calcCRC8(std::vector<uint8_t> data);
        uint16_t calcCRC16(std::vector<uint8_t> data);
        int testCRC16(std::vector<uint8_t> data);
+       int testCRC16(std::vector<uint8_t> data,uint16_t load);
                
        void resetFlasher(uint64_t id);
        void resetID(uint64_t id);
@@ -320,8 +323,10 @@ public:
 
        virtual void setDefaultConfig();
        virtual int convertAll();
-       void readMemory(uint8_t addr,std::vector<uint8_t> *sp);
-       void writeMemory(uint8_t addr,std::vector<uint8_t> *sp);
+       virtual int readMemory(int page,int start, int count,std::vector<uint8_t> *data);
+       virtual int writeMemory(int page,int start, int count,std::vector<uint8_t> *data);
+       void readMemory_int(uint8_t addr,std::vector<uint8_t> *sp);
+       void writeMemory_int(uint8_t addr,std::vector<uint8_t> *sp);
        void convert(uint8_t mask, uint8_t preset); 
        virtual int getPageSize() {return 8;}
 
index 0aa82d4..8768663 100644 (file)
@@ -284,7 +284,7 @@ uint8_t owUSBInterface::sendrecivBit(uint8_t bit) {
       // success, read the result
       nBytes = 1;
       if (DS2490Read(hDevice, buf, &nBytes)) {
-               usleep(70);
+               usleep(200);
          return buf[0];
        }
       else