remove compiler warnings of new compilerversion /
[owTools.git] / src / owDevice.cpp
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