-<<<<<<< HEAD
-// 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
#include <unistd.h>\r
#endif\r
#ifdef WIN\r
-=======
-// Copyright (c) 2017, Tobias Mueller tm(at)tm3d.de
-// All rights reserved.
-//
-// Redistribution and use in source and binary forms, with or without
-// modification, are permitted provided that the following conditions are
-// met:
-//
-// * Redistributions of source code must retain the above copyright
-// notice, this list of conditions and the following disclaimer.
-// * Redistributions in binary form must reproduce the above copyright
-// notice, this list of conditions and the following disclaimer in the
-// documentation and/or other materials provided with the
-// distribution.
-// * All advertising materials mentioning features or use of this
-// software must display the following acknowledgement: This product
-// includes software developed by tm3d.de and its contributors.
-// * Neither the name of tm3d.de nor the names of its contributors may
-// be used to endorse or promote products derived from this software
-// without specific prior written permission.
-//
-// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
-// "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
-// LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
-// A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
-// OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
-// SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
-// LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
-// DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
-// THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
-// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
-// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
-
-
-#include "owInterface.h"
-#ifdef LINUX
-#include <unistd.h>
-#endif
-#ifdef WIN
->>>>>>> origin/master
void usleep(int waitTime) {\r
__int64 time1 = 0, time2 = 0, freq = 0;\r
\r
do {\r
QueryPerformanceCounter((LARGE_INTEGER *)&time2);\r
} while ((time2 - time1) < waitTime);\r
-<<<<<<< HEAD
}\r
#endif\r
owDevice::owDevice(owInterface *owi_,snum_t num) {\r
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
\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
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
\r
+int owDeviceDS18B20::readMemory(int page,int start, int count,std::vector<uint8_t> *data) {\r
+ std::vector<uint8_t> d;\r
+ readScratchpad(&d);\r
+ data->insert(data->begin(),d.begin()+start,d.end());\r
+ return 8;\r
+}\r
+\r
\r
void owDeviceDS2438::setDefaultConfig() {\r
config->setConfig({1,6, 6,8, 4,7, 6,17, 0,2,3,12,4,0,0,0,0,0,0,0,0,0,0,0});\r
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
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
\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
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
\r
\r
\r
+void owDeviceDS2408::setDefaultConfig() {\r
+ config->setConfig({0,13, 0,13, 0,13, 0,13, 2,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0});\r
+ configstate=OWDCS_DEFAULT;\r
+}\r
+int owDeviceDS2408::convertAll() {\r
+ std::vector<uint8_t> da;\r
+ /*da.push_back(0x11);\r
+ da.push_back(0x22);\r
+ da.push_back(0x34);\r
+ writeMemory(0,0x8b,3,&da);\r
+ readMemory(0,0x88,10,&da);\r
+ printf("\n____________________________\n");\r
+ readChannelAccess(80,&da);\r
+ owi->log->clear();\r
+ da.clear();\r
+ da.push_back(0x11);\r
+ da.push_back(0x12);\r
+ da.push_back(0x31);\r
+ da.push_back(0x14);\r
+ da.push_back(0x55);\r
+ da.push_back(0x63);\r
+ da.push_back(0x70);\r
+ owi->log->clear();\r
+ \r
+ writeChannelAccess(7,&da);*/\r
+ return 1;\r
+}\r
+int owDeviceDS2408::readMemory(int page,int start, int count,std::vector<uint8_t> *data) {\r
+ std::vector<uint8_t> cl;\r
+ cl.push_back(0xF0);\r
+ cl.push_back(start&0xFF);\r
+ cl.push_back(start>>8);\r
+ if (start>=0x90) {\r
+ owi->log->set(OWLOG_WARNING,"DS2408 reading Register. Address value to hight");\r
+ return 0;\r
+ }\r
+ count=0x90-start;\r
+ \r
+ Communicate(&cl, 3,count+2 );\r
+ for (uint8_t v :cl) printf("%02X ",v);;printf("\n");\r
+ if (!owi->testCRC16(cl)) {\r
+ owi->log->set(OWLOG_ERROR,"CRC ERROR Reading Register of DS2408");\r
+ return 0;\r
+ }\r
+ data->clear();\r
+ data->insert(data->begin(),cl.begin()+3+start,cl.begin()+start+3+count);\r
+ return count;\r
+ \r
+}\r
+\r
+int owDeviceDS2408::writeMemory(int page,int start, int count,std::vector<uint8_t> *data) {\r
+ std::vector<uint8_t> cl;\r
+ cl.push_back(0xCC);\r
+ cl.push_back(start&0xFF);\r
+ cl.push_back(start>>8);\r
+ if ((start<0x8b)&&(start>0x8b)) {\r
+ owi->log->set(OWLOG_WARNING,"DS2408 writing Register. Address value not match 0x8B 0x8C 0x8D");\r
+ return 0;\r
+ }\r
+ if ((142-start)<count)\r
+ count=142-start;\r
+ for(int i=0;i<count;i++) {\r
+ cl.push_back((*data)[i]);\r
+ }\r
+ printf("count: %i\n",count);\r
+ for (uint8_t v :cl) printf("%02X ",v);;printf("\n");\r
+ Communicate(&cl, 3+count,0 );\r
+ \r
+ return count;\r
+}\r
+\r
+\r
+\r
+\r
+int owDeviceDS2408::readChannelAccess(int count,std::vector<uint8_t> *data) {\r
+ std::vector<uint8_t> cl;\r
+ cl.push_back(0xF5);\r
+ Communicate(&cl, 1,34 );\r
+ int read=0;\r
+ for (uint8_t v :cl) printf("%02X ",v);;printf("\n");\r
+ if (!owi->testCRC16(cl)) {\r
+ owi->log->set(OWLOG_ERROR,"CRC ERROR Reading Register of DS2408");\r
+ return 0;\r
+ }\r
+ read=32;\r
+ data->clear();\r
+ data->insert(data->begin(),cl.begin()+1,cl.begin()+33);\r
+\r
+ while (read<count) {\r
+ cl.clear();\r
+ owi->Communicate(&cl,0,34);\r
+ for (uint8_t v :cl) printf("%02X ",v);;printf("\n");\r
+ if (!owi->testCRC16(cl)) {\r
+ owi->log->set(OWLOG_ERROR,"CRC ERROR Reading Register of DS2408");\r
+ return read;\r
+ }\r
+ data->insert(data->begin()+read,cl.begin(),cl.begin()+32);\r
+ read+=32;\r
+\r
+ }\r
+ \r
+\r
+ return read;\r
+}\r
+int owDeviceDS2408::writeChannelAccess(int count, std::vector<uint8_t> *data) {\r
+ std::vector<uint8_t> cl;\r
+ cl.push_back(0x5A);\r
+ Communicate(&cl, 1,0 );\r
+ for(int i=0;i<count;i++) {\r
+ cl.clear();\r
+ uint8_t v=(*data)[i];\r
+ cl.push_back(v);\r
+ cl.push_back(~v);\r
+ owi->Communicate(&cl,2,2);\r
+ for (uint8_t v :cl) printf("%02X ",v);;printf("\n");\r
+ }\r
+ return count;\r
+}\r
+int owDeviceDS2408::resetActivityLatches() {\r
+ return 1;\r
+}\r
+\r
+\r
+\r
+\r
\r
\r
-=======
-}
-#endif
-owDevice::owDevice(owInterface *owi_,snum_t num) {
- snum=num;
- owi=owi_;
- config=new owDeviceConfig;
- configstate=OWDCS_NONE;
- raw.insert(raw.begin(),4,0);
- values.insert(values.begin(),4,0);
- lastfound=0;
- }
-
-void owDevice::setDefaultConfig() {
- config->setInvalid();
- }
-
-std::vector<std::string> owDevice::getFamilyInfo() {
- return owDeviceConfig::getFamilyInfo(snum.byte[0]);
- }
-int owDevice::readConfig() {
- std::vector<uint8_t> cl;
- int r=owi->maxrepeat+1;
- setDefaultConfig();
- int conf16=0;
- do {
- owi->log->clear();
- cl.clear();
- cl.push_back(0x85);
- Communicate(&cl, 1, 26);
- //for (uint8_t v:cl) printf("%02X ",v);
- if ((cl[1]==0xFF)||(cl[2]==0xFF)) {
- owi->log->set(OWLOG_INFO,"Get Config not work, maybe not a emulation from www.tm3d.de");
- return 0;
- }
- int oldInfo=1;
- //all Code pos +1
- for(int i=19;i<27;i++) if (cl[i]!=0xFF) {oldInfo=0;break;}
- if (oldInfo) {
- owi->log->set(OWLOG_INFO,"Old 16 Byte Config");
- if (cl[18]==0xFF) {
- if (!owi->calcCRC8(std::vector<uint8_t>(cl.begin()+1,cl.begin()+17))) {
- owi->log->set(OWLOG_WARNING,"CRC8 ERROR Reading Config");
- }
- } else {
- if (!owi->testCRC16(cl)) {
- owi->log->set(OWLOG_WARNING,"CRC16 ERROR Reading Config ");
- }
- }
- if (owi->log->last()<OWLOG_WARNING) {
- cl[9]=2; //Attiny84A
- for(int i=0;i<7;i++) {cl[18+i]=cl[10+i];cl[10+i]=0;} //Move OWID2 Set Sensor to 0
- conf16=1;
-
- }
- } else { //New CRC
- if (cl[26]==0xFF) {
- if (!owi->calcCRC8(std::vector<uint8_t>(cl.begin()+1,cl.begin()+25))) {
- owi->log->set(OWLOG_WARNING,"CRC8 ERROR Reading Config");
- }
- } else {
- if (!owi->testCRC16(cl)) {
- owi->log->set(OWLOG_WARNING,"CRC16 ERROR Reading Config ");
- }
- }
- }
- r--;
- }
- while ((owi->log->last()>=OWLOG_WARNING)&&(r>0));
- if (r==0) {
- owi->log->set(OWLOG_ERROR,"To much Errors while read config");
- return -1;
- }
- config->setConfig(std::vector<uint8_t>(cl.begin()+1,cl.begin()+25));
- if (config->valid) {
- if (conf16) configstate=OWDCS_16; else configstate=OWDCS_24;
- } else configstate=OWDCS_NONE;
- return 1;
-}
-
-
-int owDevice::Communicate(std::vector<uint8_t> *data, int scount, int rcount) {
- owi->Wait_Free();
- owi->MatchRom(snum);
- if (owi->log->last()==OWLOG_ERROR) {owi->Free();return 0;}
- owi->Communicate(data, scount, rcount);
- if (owi->log->last()==OWLOG_ERROR) {owi->Free();return 0;}
- owi->Free();
- return 1;
-}
-
-int owDevice::CommunicateShort(std::vector<uint8_t> *data, int scount, int rcount) {
- owi->Wait_Free();
- owi->Reset();
- if (owi->log->last()==OWLOG_ERROR) {owi->Free();return 0;}
- owi->Communicate(data, scount, rcount);
- if (owi->log->last()==OWLOG_ERROR) {owi->Free();return 0;}
- owi->Free();
- return 1;
-}
-
-
-void owDevice::changeID(snum_t nid) {
- int i;
- if (nid.byte[0] != snum.byte[0]) {
- owi->log->set(OWLOG_ERROR,"Family ID should not be changed, no correct ID");
- return;
- }
- std::vector<uint8_t> id;
- for(i=0;i<7;i++) id.push_back(nid.byte[i]);
- id.push_back(owi->calcCRC8(id));
- std::vector<uint8_t> cl;
- int r=owi->maxrepeat+1;
- do {
- owi->log->clear();
- cl.clear();
- cl.push_back(0x75);
- cl.insert(cl.begin()+1,id.begin(),id.end());
- Communicate(&cl, 9,0);
- if (owi->log->last()==OWLOG_ERROR) {r--;continue;}
- cl.clear();
- cl.push_back(0xA7);
- Communicate(&cl, 1, 8);
- if (owi->log->last()==OWLOG_ERROR) {r--;continue;}
- for (i = 0; i < 8; i++) {
- if (cl[i + 1] != id[i]) {
- owi->log->set(OWLOG_WARNING,"changeID Comunication ERROR");
- break;
- }
- }
- r--;
- }
- while ((owi->log->last()>=OWLOG_WARNING)&&(r>0));
- if (r==0) {
- owi->log->set(OWLOG_ERROR,"Can not change ID");
- return;
- }
- cl.clear();
- cl.push_back(0x79);
- cl.push_back(snum.byte[1]);
- cl.push_back(snum.byte[5]);
- cl.push_back(snum.byte[6]);
- Communicate(&cl, 4, 0);
- usleep(50000);
-}
-
-void owDevice::runFlasher() {
- std::vector<uint8_t> cl;
- cl.push_back(0x88);
- this->Communicate(&cl, 1, 0);
- this->Communicate(&cl, 1, 0);
- this->Communicate(&cl, 1, 0);
-}
-
-
-
-
-
-
-
-
-
-void owDeviceDS18B20::setDefaultConfig() {
- config->setConfig({1,1, 0,0, 0,0, 0,0, 0,1,0,0,0,0,0,0,0,0,0,0,0,0,0,0});
- configstate=OWDCS_DEFAULT;
-};
-
-int owDeviceDS18B20::readScratchpad(std::vector<uint8_t> *sp) {
- std::vector<uint8_t> cl;
- int r=owi->maxrepeat+1;
- do {
- cl.clear();
- cl.push_back(0xBE);
- Communicate(&cl, 1, 9);
- if (owi->log->last()>=OWLOG_ERROR) return -1;
- sp->clear();
- sp->insert(sp->begin(),cl.begin()+1,cl.end());
- if (owi->calcCRC8(*sp)==0) return 1;
- owi->log->set(OWLOG_WARNING,"CRC ERROR reading DS18B20 Scrachpad");
- r--;
- } while ((owi->log->last()>=OWLOG_WARNING)&&(r>0));
-
- return 0;
-}
-
-int owDeviceDS18B20::convertAll() {
- std::vector<uint8_t> sp;
- //sp.push_back(0x44);
- //communicate(&sp, 1, 0); ///########################################################
- usleep(750000);
-
- if (readScratchpad(&sp)) {
- int16_t tsht;
- tsht = sp[0] | ((int)sp[1] << 8);
- if (sp[1] & 0x080)
- tsht |= 0xFFFFF0000;
- raw[0]=tsht;
- values[0]=config->calculateValue(0, raw);
- return 1;
- }
- return 0;
-}
-
-
-void owDeviceDS2438::setDefaultConfig() {
- config->setConfig({1,6, 6,8, 4,7, 6,17, 0,2,3,12,4,0,0,0,0,0,0,0,0,0,0,0});
- configstate=OWDCS_DEFAULT;
-}
-
-
-int owDeviceDS2438::readScratchpad(std::vector<uint8_t> *sp, uint8_t page, int recall) {
- std::vector<uint8_t> cl;
- int r=owi->maxrepeat+1;
- do {
- if (recall) {
- cl.clear();
- cl.push_back(0xB8); //recall
- cl.push_back(page);
- Communicate(&cl, 2, 0);
- if (owi->log->last()>=OWLOG_ERROR) return -1;
- }
- cl.clear();
- cl.push_back(0xBE);
- cl.push_back(page);
- Communicate(&cl, 2, 9);
- if (owi->log->last()>=OWLOG_ERROR) return -1;
- sp->clear();
- sp->insert(sp->begin(),cl.begin()+2,cl.end());
- if (owi->calcCRC8(*sp)==0) return 1;
- owi->log->set(OWLOG_WARNING,"CRC ERROR reading DS2438 Scrachpad");
- r--;
- } while ((owi->log->last()>=OWLOG_WARNING)&&(r>0));
-
- return 0;
-}
-
-int owDeviceDS2438::readMemory(int page,int start, int count,std::vector<uint8_t> *data) {
- if ((page>7)||(page<0)||(start>7)||(start<0)||(start+count>8)) return 0;
- std::vector<uint8_t> cl;
- cl.clear();
- cl.push_back(0xB8); //recall
- cl.push_back(page);
- Communicate(&cl, 2, 0);
- if (owi->log->last()>=OWLOG_ERROR) return -1;
- cl.clear();
- cl.push_back(0xBE);
- cl.push_back(page);
- Communicate(&cl, 2, 9);
- if (owi->log->last()>=OWLOG_ERROR) return -1;
- cl.erase(cl.begin());
- cl.erase(cl.begin());
- if (owi->calcCRC8(cl)!=0) {
- owi->log->set(OWLOG_WARNING,"CRC ERROR reading DS2438 Scrachpad");
- }
- data->clear();
- data->insert(data->begin(),cl.begin()+start,cl.begin()+start+count);
- return count;
-}
-int owDeviceDS2438::writeMemory(int page,int start, int count,std::vector<uint8_t> *data) {
- if ((page>7)||(page<0)||(start>7)||(start<0)||(start+count>8)) return 0;
- std::vector<uint8_t> sp;
- if ((start>0)||(count<8)) {
- readMemory(page,0,8,&sp);
- }
- std::vector<uint8_t> cl;
- cl.push_back(0x4E);
- cl.push_back(page);
- int j=0;
- for(int i=0;i<8;i++) {
- if ((i<start)||(i>=start+count)) cl.push_back(sp[i]); else {cl.push_back((*data)[j]);j++;}
- }
- Communicate(&cl, 10,0);
- if (owi->log->last()>=OWLOG_ERROR) return -1;
- std::vector<uint8_t> cl1;
- cl1.push_back(0xBE);
- cl1.push_back(page);
- Communicate(&cl1, 2, 9);
- if (owi->log->last()>=OWLOG_ERROR) return -1;
- cl1.erase(cl1.begin());
- cl1.erase(cl1.begin());
- if (owi->calcCRC8(cl1)!=0) {
- owi->log->set(OWLOG_WARNING,"CRC ERROR rereading DS2438 Scrachpad");
- }
- for(int i=0;i<8;i++) {
- if (cl1[i]!=cl[i+2]) {
- owi->log->set(OWLOG_ERROR,"Reread not equal, nothing copied");
- return 0;
- }
- }
- cl.clear();
- cl.push_back(0x48);
- cl.push_back(page);
- Communicate(&cl, 2, 0);
- if (owi->log->last()>=OWLOG_ERROR) return -1;
- return 1;
-}
-
-
-
-int owDeviceDS2438::setConfigByte(uint8_t cb) {
- std::vector<uint8_t> sp;
- int k;
- for(k=0;k<owi->maxrepeat;k++) {
- owi->log->clear();
- sp.clear();
- sp.push_back(0x4E);
- sp.push_back(0x00);
- sp.push_back(cb);
- Communicate(&sp,3,0);
- if (owi->log->last()>=OWLOG_ERROR) return -1;
- sp.clear();
- readScratchpad(&sp,0,0);
- if (owi->log->last()>=OWLOG_ERROR) return -2;
- if (cb==sp[0]) return 1;
- owi->log->set(OWLOG_WARNING,"ERROR set config byte of DS2438");
- }
- owi->log->set(OWLOG_WARNING,"Config of DS2438 byte not set");
- return 0;
-}
-
-inline int16_t ow_fconvert(uint8_t b1, uint16_t b2) {
- int tsht;
- tsht=b1 |((int)b2<<8);
- if (b2 & 0x080)
- tsht |= 0xFFFFF0000;
- return tsht;
-}
-
-int owDeviceDS2438::convertAll() {
- for(int k=0;k<owi->maxrepeat;k++) {
- std::vector<uint8_t> sp;
- //sp.push_back(0x44);
- //Communicate(&sp, 1, 0);///########################################################
- if (owi->log->last()>=OWLOG_ERROR) continue;
- usleep(100000);
- if (setConfigByte(0x08)<=0) continue;
- for(int k=0;k<owi->maxrepeat;k++) {
- sp.clear();
- sp.push_back(0xB4);
- Communicate(&sp, 1, 0);
- }
- if (owi->log->last()>=OWLOG_ERROR) continue;
- usleep(100000);
-
-
- readScratchpad(&sp,0,1);
- int temp=ow_fconvert(sp[1],sp[2]);
- int VDD=ow_fconvert(sp[3],sp[4]);
- if (setConfigByte(0x00)<=0) continue;
-
- for(int k=0;k<owi->maxrepeat;k++) {
- sp.clear();
- sp.push_back(0xB4);
- Communicate(&sp, 1, 0);
- }
- if (owi->log->last()>=OWLOG_ERROR) continue;
-
- usleep(100000);
-
-
-
- readScratchpad(&sp,0,1);
- if (owi->log->last()>=OWLOG_ERROR) continue;
- int I=ow_fconvert(sp[5],sp[6]);
- int VAD=ow_fconvert(sp[3],sp[4]);
- raw[0]=temp;
- raw[1]=VDD;
- raw[2]=VAD;
- raw[3]=I;
- for(int i=0;i<4;i++) values[i]=config->calculateValue(i, raw);
- break;
- }
- if (owi->log->last()>=OWLOG_ERROR) return 0;
- return 1;
-}
-
-
-void owDeviceDS2450::setDefaultConfig() {
- config->setConfig({6,9, 6,9, 6,9, 6,9, 0,5,5,5,5,0,0,0,0,0,0,0,0,0,0,0});
- configstate=OWDCS_DEFAULT;
-}
-
-int owDeviceDS2450::convertAll() {
- convert(0x0F,0);
- if (owi->log->last()>=OWLOG_WARNING) {
- return 0;
- }
- std::vector<uint8_t> sp;
- readMemory(0,&sp);
- if (owi->log->last()>=OWLOG_WARNING) {
- return 0;
- }
-
- for(int i=0;i<4;i++) {
- raw[i]=(sp[2 * i] | sp[2 * i + 1] << 8);
- }
- for(int i=0;i<4;i++) {
- values[i]=config->calculateValue(i, raw);
- }
- return 1;
-
-}
-
-void owDeviceDS2450::readMemory(uint8_t addr,std::vector<uint8_t> *sp) {
- std::vector<uint8_t> cl;
- cl.push_back(0xAA);
- cl.push_back(addr);
- cl.push_back(0x00);
- Communicate(&cl,3,10-addr);
- if (owi->log->last()>=OWLOG_WARNING) {
- return;
- }
- if (!owi->testCRC16(cl)) {
- for (uint8_t v :cl) printf("%02X ",v);
- printf("\n");
- owi->log->set(OWLOG_ERROR,"CRC ERROR Reading Memory of DS2450");
- return;
- }
- sp->clear();
- sp->insert(sp->begin(),cl.begin()+3,cl.end()-2);
-}
-
-void owDeviceDS2450::writeMemory(uint8_t addr,std::vector<uint8_t> *sp) {
- std::vector<uint8_t> cl;
- cl.push_back(0x55);
- cl.push_back(addr);
- cl.push_back(0x00);
- owi->MatchRom(snum);
- if (owi->log->last()>=OWLOG_WARNING) {
- return;
- }
- for(uint8_t b: (*sp)) {
- cl.push_back(b);
- owi->Communicate(&cl,cl.size(),2);
- if (owi->log->last()>=OWLOG_WARNING) {
- return;
- }
- if (!owi->testCRC16(cl)) {
- owi->log->set(OWLOG_ERROR,"CRC ERROR Writing Memory of DS2450");
- return;
- }
- cl.clear();
- owi->Communicate(&cl, 0, 1);
- if (owi->log->last()>=OWLOG_WARNING) {
- return;
- }
- if (cl[0] != b) {
- owi->log->set(OWLOG_ERROR,"ERROR Writing Memory of DS2450");
- return;
- }
- cl.clear();
- }
-}
-
-void owDeviceDS2450::convert(uint8_t mask, uint8_t preset) {
- std::vector<uint8_t> cl;
- cl.push_back(0x3C);
- cl.push_back(mask);
- cl.push_back(preset);
- Communicate(&cl, 3, 2);
- if (!owi->testCRC16(cl)) {
- for (uint8_t v :cl) printf("%02X ",v);
- printf("\n");
- owi->log->set(OWLOG_ERROR,"CRC ERROR Convert Command of DS2450");
- return;
- }
- usleep(10000);
-}
-
-
-
-
-
-
-
-
-
-
-
-void owDeviceDS2423::setDefaultConfig() {
- config->setConfig({9,13, 9,13, 9,13, 9,13, 0,19,19,19,19,0,0,0,0,0,0,0,0,0,0,0});
- configstate=OWDCS_DEFAULT;
-}
-
-int owDeviceDS2423::convertAll() {
- for(uint8_t i=12;i<16;i++) {
- raw[i-12]=readCounter(i);
- }
- for(int i=0;i<4;i++) {
- values[i]=config->calculateValue(i, raw);
- }
- return 1;
-}
-uint32_t owDeviceDS2423::readCounter(uint8_t page) {
- std::vector<uint8_t> cl;
- cl.push_back(0xA5);
- uint16_t addr=(page<<5)+31;
- cl.push_back(addr&0xFF);
- cl.push_back(addr>>8);
- Communicate(&cl,3,11);
- //for (uint8_t v :cl) printf("%02X ",v);
- //printf("\n");
- if (!owi->testCRC16(cl)) {
- owi->log->set(OWLOG_ERROR,"CRC ERROR Reading Counter of DS2423");
- return 0;
- }
- uint32_t ret=0;
-
- for(size_t i=cl.size()-8;i>cl.size()-11;i--) {
- ret<<=8;
- ret|=cl[i];
-
- }
-
- return ret;
-}
-
-
-int owDeviceDS2423::readMemory(int page,int start, int count,std::vector<uint8_t> *data){
- std::vector<uint8_t> cl;
- cl.push_back(0xF0);
- uint16_t adr=page<<5;
- cl.push_back(adr&0xFF);
- cl.push_back((adr>>8)&0xFF);
- Communicate(&cl, 3, 32);
- //No CRC
- data->clear();
- data->insert(data->begin(),cl.begin()+3+start,cl.begin()+start+3+count);
- return count;
-
-}
-int owDeviceDS2423::writeMemory(int page,int start, int count,std::vector<uint8_t> *data) {
- std::vector<uint8_t> cl;
- cl.push_back(0x0F);
- uint16_t adr=(page<<5)+start;
- cl.push_back(adr&0xFF);
- cl.push_back(adr>>8);
- for(int i=0;i<count;i++) {
- cl.push_back((*data)[i]);
- }
- Communicate(&cl, 3+count, 0);
- for (uint8_t v :cl) printf("%02X ",v);printf("\n");
- cl.clear();
- cl.push_back(0xAA);
- Communicate(&cl, 1, 36);
- //for (uint8_t v :cl) printf("%02X ",v);;printf("\n");
- cl[0]=0x5A;
- Communicate(&cl, 4, 1);
- usleep(100000);
- if (cl[4]!=0xAA) {
- for (uint8_t v :cl) printf("%02X ",v);;printf("\n");
- owi->log->set(OWLOG_ERROR,"DS2423 Copy from Scratchpad to Memmory Error");
- //return 0;
- }
- return count;
-}
-
-
-
-
-
-
->>>>>>> origin/master