X-Git-Url: http://git.smho.de/gw/?a=blobdiff_plain;f=src%2FowDevice.cpp;h=e710102a437195c1bab59b906ce690bdbf63e8cc;hb=df91f0af6eb853d1fd572da66c7fee753a8ebd64;hp=840a0b2ca0857d304fbc37568d8cc3f9b672e97b;hpb=c7561c5e50f1df4015c0c250bdbaa2efbb95a3bd;p=owTools.git diff --git a/src/owDevice.cpp b/src/owDevice.cpp index 840a0b2..e710102 100755 --- a/src/owDevice.cpp +++ b/src/owDevice.cpp @@ -32,8 +32,21 @@ #include "owInterface.h" +#ifdef LINUX #include - +#endif +#ifdef WIN +void usleep(int waitTime) { + __int64 time1 = 0, time2 = 0, freq = 0; + + QueryPerformanceCounter((LARGE_INTEGER *)&time1); + QueryPerformanceFrequency((LARGE_INTEGER *)&freq); + + do { + QueryPerformanceCounter((LARGE_INTEGER *)&time2); + } while ((time2 - time1) < waitTime); +} +#endif owDevice::owDevice(owInterface *owi_,snum_t num) { snum=num; owi=owi_; @@ -236,7 +249,7 @@ int owDeviceDS18B20::convertAll() { void owDeviceDS2438::setDefaultConfig() { - config->setConfig({1,6, 6,8, 4,7, 7,17, 0,2,3,12,4,0,0,0,0,0,0,0,0,0,0,0}); + 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; } @@ -267,6 +280,69 @@ int owDeviceDS2438::readScratchpad(std::vector *sp, uint8_t page, int r return 0; } +int owDeviceDS2438::readMemory(int page,int start, int count,std::vector *data) { + if ((page>7)||(page<0)||(start>7)||(start<0)||(start+count>8)) return 0; + std::vector 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 *data) { + if ((page>7)||(page<0)||(start>7)||(start<0)||(start+count>8)) return 0; + std::vector sp; + if ((start>0)||(count<8)) { + readMemory(page,0,8,&sp); + } + std::vector cl; + cl.push_back(0x4E); + cl.push_back(page); + int j=0; + for(int i=0;i<8;i++) { + if ((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 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 sp; int k;