New Devices
authorTobias <tm@tm3d.de>
Sun, 4 Nov 2018 20:30:24 +0000 (21:30 +0100)
committerTobias <tm@tm3d.de>
Sun, 4 Nov 2018 20:30:24 +0000 (21:30 +0100)
Log in Textfiles

src/main.cpp [changed mode: 0755->0644]
src/owDevice.cpp
src/owDeviceConfig.cpp
src/owInterface.cpp

old mode 100755 (executable)
new mode 100644 (file)
index 0a6ccbd..838b99e
@@ -44,6 +44,8 @@
 #ifdef WIN
 #include "Windows.h"
 #include "time.h"
+
+
 #endif
 
 #include <stdio.h>
@@ -57,6 +59,7 @@
 #include <fstream>
 #include <sstream> 
 
+
 #ifdef LINUX
 
 #define RB "\e(0\x6a\e(B" // 188 Right Bottom corner
@@ -112,6 +115,8 @@ 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("   -s \"id as 64bit Hex\" try to skip select menu with this id \n");
+printf("               example: -s \"5D02160084D9A220\" \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");
@@ -123,6 +128,7 @@ printf("            [password]\n");
 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("   -f [hexfile]    flash new\n");
 printf("   -n [\"id as 64bit Hex\"] change id   \n");
 printf("               example: -n \"5D02160084D9A220\" \n");
@@ -130,6 +136,7 @@ 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 information (2)\n");
 printf("   -m memory functions\n");
+printf("   -x write direct 1-Wire\n");
 
 
 
@@ -181,6 +188,10 @@ int getArgi(std::string flag) {
 int database=0;
 mySensorDB *sdb=NULL;
 #endif
+int textfile=0;
+std::string textfilename;
+
+
 /*
 snum_t getArgsnum(std::string flag) {
        snum_t snum;
@@ -218,9 +229,25 @@ void setLogMode() {
 
 }
 
+int appendTextFile(std::string line) {
+       std::ofstream file;
+    file.open(textfilename, std::ios::out | std::ios::app);
+    if (file.fail()) {
+               owi->log->set(OWLOG_ERROR,"Can not open outputfile for text output");
+               return -1;
+       }
+   
+
+    file << line << std::endl;
+    file.close();
+    return 0;
+}
+
 
 void continuous(std::vector<owDevice*> *devices,int intervall,int headline,int searchrom) {
        int first=1;
+       char valbuf[100];
+       std::string tfl;
        while (1) {
                if (searchrom) {
                        owi->log->clear();
@@ -281,14 +308,28 @@ void continuous(std::vector<owDevice*> *devices,int intervall,int headline,int s
                struct tm tm;
                localtime_s(&tm,&t);
 #endif
+
                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);
+               if (textfile) {
+                       snprintf(valbuf,100,"%d-%02d-%02d %02d:%02d:%02d", tm.tm_year + 1900, tm.tm_mon + 1, tm.tm_mday, tm.tm_hour, tm.tm_min, tm.tm_sec);
+                       tfl=valbuf;
+               }
+
+
                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);
+=======
                                std::vector<uint8_t> data;
                                data.push_back(0xCC);
                                data.push_back(0x44);
                                owi->Reset();
                                owi->Communicate(&data, 2, 0);
+>>>>>>> origin/master
                                dev->convertAll();
                                if (owi->log->last()<OWLOG_ERROR) break;
                                owi->log->clear();
@@ -310,6 +351,10 @@ void continuous(std::vector<owDevice*> *devices,int intervall,int headline,int s
                                                        else
                                                                printf("%0.1f \t",dev->values[i]);
                                                        fflush(stdout);
+                                                       if (textfile) {
+                                                               snprintf(valbuf,100,",%0.4f",dev->values[i]);
+                                                               tfl.append(valbuf);
+                                                       }
                                                }
                                        }
                                }
@@ -327,6 +372,9 @@ void continuous(std::vector<owDevice*> *devices,int intervall,int headline,int s
                
                }
                printf("\n");
+               if (textfile) {
+                       appendTextFile(tfl);
+               }
                while (((int)time(NULL)) < (st + intervall)) {
 #ifdef LINUX
                        sleep(1);
@@ -382,8 +430,23 @@ void device_menu(owDevice* d) {
 }
 
 int selectDevice() {
+       std::string s;
        owi->Find();
-       int i=0;
+       int i = 0;
+       char *end;
+       unsigned long long l = 0;
+       if ((s = getArg("s")) != "") {
+               l = strtoull(s.c_str(), &end, 16);
+               for (owDevice* dev : owi->devices) {
+                       i++;
+                       snum_t snum = dev->getNum();
+                       if (l == snum.num) return i;
+
+               }
+               printf("Number not found -> Select one or exit!\n");
+       }
+
+       i=0;
        for (owDevice* dev :owi->devices) {
                i++;
                snum_t snum=dev->getNum();
@@ -582,7 +645,15 @@ int main(int argc, char *argv[]) {
                        database=1;
                }
 #endif
+<<<<<<< HEAD
+               if      ((s=getArg("t")) !="")  {
+                       textfile=1;
+                       printf("Write values to textfile %s\n",s.c_str());
+                       textfilename=s;
+               }
+=======
                        
+>>>>>>> origin/master
                
                continuous(&(owi->devices),pause,1,reload);     
        } else 
@@ -618,9 +689,50 @@ int main(int argc, char *argv[]) {
                dev->Communicate(&cl,4,0);
        } else 
        //------------------------------------------------------------------------------------------
+       // --------------------- Direct Write
+       //------------------------------------------------------------------------------------------
+       
+       if ((s=getArg("x"))!="") {
+               std::vector<uint8_t> v;
+               int sp=0;
+               std::string ts="";
+               for ( std::string::iterator  it = s.begin() ; it < s.end(); it++ ,sp++) {
+                       if (isxdigit(*it)) {
+                               char c=(*it);
+                               ts.append(1,c);
+                               if (ts.length()>=2) {
+                                       v.push_back(strtoul(ts.c_str(),NULL, 16));
+                                       ts="";
+                               }
+                       }
+               }
+               if (ts.length()!=0) {
+                       v.push_back(strtoul(ts.c_str(),NULL, 16));
+               }
+               printf("Send ");
+               for (uint8_t val :v) printf("%02X ",val);
+               printf(" to selected Device\n");
+               int sel=selectDevice();
+               if (sel==0) exit(0);
+               sel-=1;
+               owDevice* dev=owi->devices[sel];
+               dev->Communicate(&v,v.size(),0);
+               for (uint8_t val :v) printf("%02X ",val);
+               printf("\n");
+               exit(0);
+               
+               
+       }
+
+       //------------------------------------------------------------------------------------------
+       // --------------------- Memory functions
+       //------------------------------------------------------------------------------------------
+       
+=======
        // --------------------- Memory functions
        //------------------------------------------------------------------------------------------
        
+>>>>>>> origin/master
        if ((s=getArg("m"))!="") {
                int pnr=0;
                std::vector<uint8_t> mem;
@@ -709,7 +821,11 @@ int main(int argc, char *argv[]) {
                                                if (c=='x') br=1;
                                        } else {
                                                if ((c==',')|(c=='}')) {
+<<<<<<< HEAD
+                                                       isnum.byte[i]=(uint8_t)strtoull(s, NULL, 16);
+=======
                                                        isnum.byte[i]=(uint8_t)strtol(s, NULL, 16);
+>>>>>>> origin/master
                                                        //printf("%x\n",strtol(s, NULL, 16));
                                                        i++;
                                                        br=0;
@@ -731,7 +847,11 @@ int main(int argc, char *argv[]) {
                        if (s=="1") {
                                snum.num+=256;
                        } else {
+<<<<<<< HEAD
+                               unsigned long long l=strtoull(s.c_str(),NULL,16);
+=======
                                unsigned long long l=strtol(s.c_str(),NULL,16);
+>>>>>>> origin/master
                                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);
index bdb54a9..de5c52e 100755 (executable)
@@ -1,3 +1,43 @@
+<<<<<<< HEAD
+// Copyright (c) 2017, Tobias Mueller tm(at)tm3d.de\r
+// All rights reserved.\r
+//\r
+// Redistribution and use in source and binary forms, with or without\r
+// modification, are permitted provided that the following conditions are\r
+// met:\r
+//\r
+//  * Redistributions of source code must retain the above copyright\r
+//    notice, this list of conditions and the following disclaimer.\r
+//  * Redistributions in binary form must reproduce the above copyright\r
+//    notice, this list of conditions and the following disclaimer in the\r
+//    documentation and/or other materials provided with the\r
+//    distribution.\r
+//  * All advertising materials mentioning features or use of this\r
+//    software must display the following acknowledgement: This product\r
+//    includes software developed by tm3d.de and its contributors.\r
+//  * Neither the name of tm3d.de nor the names of its contributors may\r
+//    be used to endorse or promote products derived from this software\r
+//    without specific prior written permission.\r
+//\r
+// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS\r
+// "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT\r
+// LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR\r
+// A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT\r
+// OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,\r
+// SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT\r
+// LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,\r
+// DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY\r
+// THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT\r
+// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE\r
+// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.\r
+\r
+\r
+#include "owInterface.h"\r
+#ifdef LINUX\r
+#include <unistd.h>\r
+#endif\r
+#ifdef WIN\r
+=======
 // Copyright (c) 2017, Tobias Mueller tm(at)tm3d.de
 // All rights reserved.
 //
@@ -36,6 +76,7 @@
 #include <unistd.h>
 #endif
 #ifdef WIN
+>>>>>>> origin/master
 void usleep(int waitTime) {\r
        __int64 time1 = 0, time2 = 0, freq = 0;\r
 \r
@@ -45,6 +86,569 @@ void usleep(int waitTime) {
        do {\r
                QueryPerformanceCounter((LARGE_INTEGER *)&time2);\r
        } while ((time2 - time1) < waitTime);\r
+<<<<<<< HEAD
+}\r
+#endif\r
+owDevice::owDevice(owInterface *owi_,snum_t num) {\r
+               snum=num;\r
+               owi=owi_;\r
+               config=new owDeviceConfig;\r
+               configstate=OWDCS_NONE;\r
+               raw.insert(raw.begin(),4,0);\r
+               values.insert(values.begin(),4,0);\r
+               lastfound=0;\r
+       }\r
+       \r
+void owDevice::setDefaultConfig() {\r
+               config->setInvalid();\r
+       }\r
+       \r
+std::vector<std::string> owDevice::getFamilyInfo() {\r
+               return owDeviceConfig::getFamilyInfo(snum.byte[0]);\r
+       }\r
+int owDevice::readConfig() {\r
+       std::vector<uint8_t> cl;\r
+       int r=owi->maxrepeat+1;\r
+       setDefaultConfig();\r
+       int conf16=0;\r
+       do {\r
+               owi->log->clear();\r
+               cl.clear();\r
+               cl.push_back(0x85);\r
+               Communicate(&cl, 1, 26);\r
+               //for (uint8_t v:cl) printf("%02X ",v); \r
+               if ((cl[1]==0xFF)||(cl[2]==0xFF)) {\r
+                       owi->log->set(OWLOG_INFO,"Get Config not work, maybe not a emulation from www.tm3d.de");\r
+                       return 0;\r
+               }\r
+               int oldInfo=1;\r
+               //all Code pos +1 \r
+               for(int i=19;i<27;i++) if (cl[i]!=0xFF) {oldInfo=0;break;} \r
+               if (oldInfo) {\r
+                       owi->log->set(OWLOG_INFO,"Old 16 Byte Config");\r
+                       if (cl[18]==0xFF) { \r
+                               if (!owi->calcCRC8(std::vector<uint8_t>(cl.begin()+1,cl.begin()+17))) {\r
+                                       owi->log->set(OWLOG_WARNING,"CRC8 ERROR Reading Config");\r
+                               }\r
+                       } else {\r
+                               if (!owi->testCRC16(cl)) {\r
+                                       owi->log->set(OWLOG_WARNING,"CRC16 ERROR Reading Config ");\r
+                               }\r
+                       }\r
+                       if (owi->log->last()<OWLOG_WARNING) {\r
+                               cl[9]=2; //Attiny84A\r
+                               for(int i=0;i<7;i++) {cl[18+i]=cl[10+i];cl[10+i]=0;} //Move OWID2 Set Sensor to 0\r
+                               conf16=1;\r
+\r
+                       }\r
+               } else { //New CRC\r
+                       if (cl[26]==0xFF) { \r
+                               if (!owi->calcCRC8(std::vector<uint8_t>(cl.begin()+1,cl.begin()+25))) {\r
+                                       owi->log->set(OWLOG_WARNING,"CRC8 ERROR Reading Config");\r
+                               }\r
+                       } else {\r
+                               if (!owi->testCRC16(cl)) {\r
+                                       owi->log->set(OWLOG_WARNING,"CRC16 ERROR Reading Config ");\r
+                               }\r
+                       }\r
+               }               \r
+               r--;\r
+       }\r
+       while ((owi->log->last()>=OWLOG_WARNING)&&(r>0));\r
+       if (r==0) {\r
+               owi->log->set(OWLOG_ERROR,"To much Errors while read config");\r
+               return -1;\r
+       }\r
+       config->setConfig(std::vector<uint8_t>(cl.begin()+1,cl.begin()+25));\r
+       if (config->valid) {\r
+               if (conf16) configstate=OWDCS_16; else configstate=OWDCS_24;\r
+       } else configstate=OWDCS_NONE;\r
+       return 1;\r
+}\r
+\r
+\r
+int owDevice::Communicate(std::vector<uint8_t> *data, int scount, int rcount) {\r
+       owi->Wait_Free();\r
+       owi->MatchRom(snum);\r
+       if (owi->log->last()==OWLOG_ERROR) {owi->Free();return 0;}\r
+       owi->Communicate(data, scount, rcount);  \r
+       if (owi->log->last()==OWLOG_ERROR) {owi->Free();return 0;}\r
+       owi->Free();\r
+       return 1;\r
+}\r
+\r
+int owDevice::CommunicateShort(std::vector<uint8_t> *data, int scount, int rcount) {\r
+       owi->Wait_Free();\r
+       owi->Reset();\r
+       if (owi->log->last()==OWLOG_ERROR) {owi->Free();return 0;}\r
+       owi->Communicate(data, scount, rcount);\r
+       if (owi->log->last()==OWLOG_ERROR) {owi->Free();return 0;}\r
+       owi->Free();\r
+       return 1;\r
+}\r
+\r
+\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
+       }\r
+       std::vector<uint8_t> id;\r
+       for(i=0;i<7;i++) id.push_back(nid.byte[i]);\r
+       id.push_back(owi->calcCRC8(id));\r
+       std::vector<uint8_t> cl;\r
+       int r=owi->maxrepeat+1;\r
+       do {\r
+               owi->log->clear();\r
+               cl.clear();\r
+               cl.push_back(0x75);\r
+               cl.insert(cl.begin()+1,id.begin(),id.end());\r
+               Communicate(&cl, 9,0);\r
+               if (owi->log->last()==OWLOG_ERROR) {r--;continue;}\r
+               cl.clear();\r
+               cl.push_back(0xA7);\r
+               Communicate(&cl, 1, 8);\r
+               if (owi->log->last()==OWLOG_ERROR) {r--;continue;}\r
+               for (i = 0; i < 8; i++) {\r
+                       if (cl[i + 1] != id[i]) {\r
+                               owi->log->set(OWLOG_WARNING,"changeID Comunication ERROR");\r
+                               break;\r
+                       }\r
+               }\r
+               r--;\r
+       }\r
+       while ((owi->log->last()>=OWLOG_WARNING)&&(r>0));\r
+       if (r==0) {\r
+               owi->log->set(OWLOG_ERROR,"Can not change ID");\r
+               return;\r
+       }       \r
+       cl.clear();\r
+       cl.push_back(0x79);\r
+       cl.push_back(snum.byte[1]);\r
+       cl.push_back(snum.byte[5]);\r
+       cl.push_back(snum.byte[6]);\r
+       Communicate(&cl, 4, 0);\r
+       usleep(50000);  \r
+}\r
+\r
+void owDevice::runFlasher() {\r
+       std::vector<uint8_t> cl;\r
+       cl.push_back(0x88);\r
+       this->Communicate(&cl, 1, 0);\r
+       this->Communicate(&cl, 1, 0);\r
+       this->Communicate(&cl, 1, 0);\r
+}\r
+\r
+\r
+\r
+\r
+\r
+\r
+\r
+\r
+\r
+void owDeviceDS18B20::setDefaultConfig() {\r
+       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});\r
+       configstate=OWDCS_DEFAULT;\r
+};\r
+\r
+int owDeviceDS18B20::readScratchpad(std::vector<uint8_t> *sp) {\r
+       std::vector<uint8_t> cl;\r
+       int r=owi->maxrepeat+1;\r
+       do {\r
+               cl.clear();\r
+               cl.push_back(0xBE);\r
+               Communicate(&cl, 1, 9);\r
+               if (owi->log->last()>=OWLOG_ERROR) return -1;\r
+               sp->clear();\r
+               sp->insert(sp->begin(),cl.begin()+1,cl.end());\r
+               if (owi->calcCRC8(*sp)==0) return 1;\r
+               owi->log->set(OWLOG_WARNING,"CRC ERROR reading DS18B20 Scrachpad");\r
+               r--;\r
+       } while ((owi->log->last()>=OWLOG_WARNING)&&(r>0));\r
+                       \r
+       return 0;\r
+}\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 (readScratchpad(&sp)) {\r
+               int16_t tsht;\r
+               tsht = sp[0] | ((int)sp[1] << 8);\r
+               if (sp[1] & 0x080)\r
+                       tsht |= 0xFFFFF0000;\r
+               raw[0]=tsht;\r
+               values[0]=config->calculateValue(0, raw);\r
+                       return 1;\r
+       }               \r
+       return 0;\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
+       configstate=OWDCS_DEFAULT;\r
+}\r
+\r
+\r
+int owDeviceDS2438::readScratchpad(std::vector<uint8_t> *sp, uint8_t page, int recall) {\r
+       std::vector<uint8_t> cl;\r
+       int r=owi->maxrepeat+1;\r
+       do {\r
+               if (recall) {\r
+                       cl.clear();\r
+                       cl.push_back(0xB8); //recall\r
+                       cl.push_back(page);\r
+                       Communicate(&cl, 2, 0);\r
+                       if (owi->log->last()>=OWLOG_ERROR) return -1;\r
+               }\r
+               cl.clear();\r
+               cl.push_back(0xBE);\r
+               cl.push_back(page);\r
+               Communicate(&cl, 2, 9);\r
+               if (owi->log->last()>=OWLOG_ERROR) return -1;\r
+               sp->clear();\r
+               sp->insert(sp->begin(),cl.begin()+2,cl.end());\r
+               if (owi->calcCRC8(*sp)==0) return 1;\r
+               owi->log->set(OWLOG_WARNING,"CRC ERROR reading DS2438 Scrachpad");\r
+               r--;\r
+       } while ((owi->log->last()>=OWLOG_WARNING)&&(r>0));\r
+                       \r
+       return 0;\r
+}\r
+\r
+int owDeviceDS2438::readMemory(int page,int start, int count,std::vector<uint8_t> *data) {\r
+       if ((page>7)||(page<0)||(start>7)||(start<0)||(start+count>8)) return 0;\r
+       std::vector<uint8_t> cl;\r
+       cl.clear();\r
+       cl.push_back(0xB8); //recall\r
+       cl.push_back(page);\r
+       Communicate(&cl, 2, 0);\r
+       if (owi->log->last()>=OWLOG_ERROR) return -1;\r
+       cl.clear();\r
+       cl.push_back(0xBE);\r
+       cl.push_back(page);\r
+       Communicate(&cl, 2, 9);\r
+       if (owi->log->last()>=OWLOG_ERROR) return -1;\r
+       cl.erase(cl.begin());\r
+       cl.erase(cl.begin());\r
+       if (owi->calcCRC8(cl)!=0) {\r
+               owi->log->set(OWLOG_WARNING,"CRC ERROR reading DS2438 Scrachpad");\r
+       }\r
+       data->clear();\r
+       data->insert(data->begin(),cl.begin()+start,cl.begin()+start+count);\r
+       return count;\r
+}\r
+int owDeviceDS2438::writeMemory(int page,int start, int count,std::vector<uint8_t> *data) {\r
+       if ((page>7)||(page<0)||(start>7)||(start<0)||(start+count>8)) return 0;\r
+       std::vector<uint8_t> sp;\r
+       if ((start>0)||(count<8)) {\r
+               readMemory(page,0,8,&sp);\r
+       }\r
+       std::vector<uint8_t> cl;\r
+       cl.push_back(0x4E); \r
+       cl.push_back(page);\r
+       int j=0;\r
+       for(int i=0;i<8;i++) {\r
+               if ((i<start)||(i>=start+count)) cl.push_back(sp[i]); else {cl.push_back((*data)[j]);j++;}\r
+       }\r
+       Communicate(&cl, 10,0);\r
+       if (owi->log->last()>=OWLOG_ERROR) return -1;\r
+       std::vector<uint8_t> cl1;\r
+       cl1.push_back(0xBE);\r
+       cl1.push_back(page);\r
+       Communicate(&cl1, 2, 9);\r
+       if (owi->log->last()>=OWLOG_ERROR) return -1;\r
+       cl1.erase(cl1.begin());\r
+       cl1.erase(cl1.begin());\r
+       if (owi->calcCRC8(cl1)!=0) {\r
+               owi->log->set(OWLOG_WARNING,"CRC ERROR rereading DS2438 Scrachpad");\r
+       }\r
+       for(int i=0;i<8;i++) {\r
+               if (cl1[i]!=cl[i+2]) {\r
+                       owi->log->set(OWLOG_ERROR,"Reread not equal, nothing copied");\r
+                       return 0; \r
+               }\r
+       }\r
+       cl.clear();\r
+       cl.push_back(0x48);\r
+       cl.push_back(page);\r
+       Communicate(&cl, 2, 0);\r
+       if (owi->log->last()>=OWLOG_ERROR) return -1;\r
+       return 1;\r
+}\r
+\r
+\r
+\r
+int owDeviceDS2438::setConfigByte(uint8_t cb) {\r
+       std::vector<uint8_t> sp;\r
+       int k;\r
+       for(k=0;k<owi->maxrepeat;k++) {\r
+               owi->log->clear();\r
+               sp.clear();\r
+               sp.push_back(0x4E);\r
+               sp.push_back(0x00);\r
+               sp.push_back(cb);\r
+               Communicate(&sp,3,0);\r
+               if (owi->log->last()>=OWLOG_ERROR) return -1;\r
+               sp.clear();\r
+               readScratchpad(&sp,0,0);\r
+               if (owi->log->last()>=OWLOG_ERROR) return -2;\r
+               if (cb==sp[0]) return 1;\r
+               owi->log->set(OWLOG_WARNING,"ERROR set config byte of DS2438");\r
+       }\r
+       owi->log->set(OWLOG_WARNING,"Config of DS2438 byte not set");\r
+       return 0;\r
+}\r
+\r
+inline int16_t ow_fconvert(uint8_t b1, uint16_t b2) {\r
+  int tsht;\r
+  tsht=b1  |((int)b2<<8);\r
+  if (b2 & 0x080)\r
+       tsht |= 0xFFFFF0000;\r
+  return tsht;\r
+}\r
+\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 (setConfigByte(0x08)<=0) continue;\r
+               for(int k=0;k<owi->maxrepeat;k++) {\r
+                       sp.clear();\r
+                       sp.push_back(0xB4);\r
+                       Communicate(&sp, 1, 0);\r
+               }\r
+               if (owi->log->last()>=OWLOG_ERROR) continue;\r
+               usleep(100000);\r
+\r
+\r
+               readScratchpad(&sp,0,1);\r
+               int temp=ow_fconvert(sp[1],sp[2]);\r
+               int VDD=ow_fconvert(sp[3],sp[4]);\r
+               if (setConfigByte(0x00)<=0) continue;\r
+\r
+               for(int k=0;k<owi->maxrepeat;k++) {\r
+                       sp.clear();\r
+                       sp.push_back(0xB4);\r
+                       Communicate(&sp, 1, 0);\r
+               }\r
+               if (owi->log->last()>=OWLOG_ERROR) continue;\r
+\r
+               usleep(100000);\r
+\r
+\r
+\r
+               readScratchpad(&sp,0,1);\r
+               if (owi->log->last()>=OWLOG_ERROR) continue;\r
+               int I=ow_fconvert(sp[5],sp[6]);\r
+               int VAD=ow_fconvert(sp[3],sp[4]);\r
+               raw[0]=temp;\r
+               raw[1]=VDD;\r
+               raw[2]=VAD;\r
+               raw[3]=I;\r
+               for(int i=0;i<4;i++) values[i]=config->calculateValue(i, raw);\r
+               break;\r
+       }\r
+       if (owi->log->last()>=OWLOG_ERROR) return 0;\r
+       return 1;\r
+}\r
+\r
+\r
+void owDeviceDS2450::setDefaultConfig() {\r
+       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});\r
+       configstate=OWDCS_DEFAULT;\r
+}\r
+\r
+int owDeviceDS2450::convertAll() {\r
+       convert(0x0F,0);\r
+       if (owi->log->last()>=OWLOG_WARNING) {\r
+               return 0;\r
+       }\r
+       std::vector<uint8_t> sp;\r
+       readMemory(0,&sp);\r
+       if (owi->log->last()>=OWLOG_WARNING) {\r
+               return 0;\r
+       }\r
+\r
+       for(int i=0;i<4;i++) {\r
+               raw[i]=(sp[2 * i] | sp[2 * i + 1] << 8);\r
+       }\r
+       for(int i=0;i<4;i++) {\r
+               values[i]=config->calculateValue(i, raw);\r
+       }\r
+       return 1;\r
+\r
+}\r
+\r
+void owDeviceDS2450::readMemory(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
+       cl.push_back(0x00);\r
+       Communicate(&cl,3,10-addr);\r
+       if (owi->log->last()>=OWLOG_WARNING) {\r
+               return;\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;\r
+       }\r
+       sp->clear();\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
+       std::vector<uint8_t> cl;\r
+       cl.push_back(0x55);\r
+       cl.push_back(addr);\r
+       cl.push_back(0x00);\r
+       owi->MatchRom(snum);\r
+       if (owi->log->last()>=OWLOG_WARNING) {\r
+               return;\r
+       }\r
+       for(uint8_t b: (*sp)) {\r
+               cl.push_back(b);\r
+               owi->Communicate(&cl,cl.size(),2);\r
+               if (owi->log->last()>=OWLOG_WARNING) {\r
+                       return;\r
+               }\r
+               if (!owi->testCRC16(cl)) {\r
+                       owi->log->set(OWLOG_ERROR,"CRC ERROR Writing Memory of DS2450");\r
+                       return;\r
+               }\r
+               cl.clear();\r
+               owi->Communicate(&cl, 0, 1);\r
+               if (owi->log->last()>=OWLOG_WARNING) {\r
+                       return;\r
+               }\r
+               if (cl[0] != b) {\r
+                       owi->log->set(OWLOG_ERROR,"ERROR Writing Memory of DS2450");\r
+                       return;\r
+               }\r
+               cl.clear();\r
+       }\r
+}\r
+       \r
+void owDeviceDS2450::convert(uint8_t mask, uint8_t preset) {\r
+       std::vector<uint8_t> cl;\r
+       cl.push_back(0x3C);\r
+       cl.push_back(mask);\r
+       cl.push_back(preset);\r
+       Communicate(&cl, 3, 2);\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 Convert Command of DS2450");\r
+               return;\r
+       }\r
+       usleep(10000);\r
+}\r
+\r
+\r
+\r
+\r
+\r
+\r
+\r
+\r
+\r
+\r
+\r
+void owDeviceDS2423::setDefaultConfig() {\r
+       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});\r
+       configstate=OWDCS_DEFAULT;\r
+}\r
+\r
+int owDeviceDS2423::convertAll() {\r
+       for(uint8_t i=12;i<16;i++) {\r
+               raw[i-12]=readCounter(i);\r
+       }\r
+       for(int i=0;i<4;i++) {\r
+               values[i]=config->calculateValue(i, raw);\r
+       }\r
+       return 1;\r
+}\r
+uint32_t owDeviceDS2423::readCounter(uint8_t page) {\r
+       std::vector<uint8_t> cl;\r
+       cl.push_back(0xA5);\r
+       uint16_t addr=(page<<5)+31;\r
+       cl.push_back(addr&0xFF);\r
+       cl.push_back(addr>>8);\r
+       Communicate(&cl,3,11);\r
+       //for (uint8_t v :cl) printf("%02X ",v);\r
+       //printf("\n");\r
+       if (!owi->testCRC16(cl)) {\r
+               owi->log->set(OWLOG_ERROR,"CRC ERROR Reading Counter of DS2423");\r
+               return 0;\r
+       }\r
+       uint32_t ret=0;\r
+        \r
+       for(size_t i=cl.size()-7;i>cl.size()-11;i--) {\r
+               ret<<=8;\r
+               ret|=cl[i];\r
+               \r
+       }\r
+       return ret;\r
+}\r
+\r
+\r
+int owDeviceDS2423::readMemory(int page,int start, int count,std::vector<uint8_t> *data){\r
+       std::vector<uint8_t> cl;\r
+       cl.push_back(0xF0);\r
+       uint16_t adr=page<<5;\r
+       cl.push_back(adr&0xFF);\r
+       cl.push_back((adr>>8)&0xFF);\r
+       Communicate(&cl, 3, 32);\r
+       //No CRC \r
+       data->clear();\r
+       data->insert(data->begin(),cl.begin()+3+start,cl.begin()+start+3+count);\r
+       return count;   \r
+\r
+}\r
+int owDeviceDS2423::writeMemory(int page,int start, int count,std::vector<uint8_t> *data) {\r
+       std::vector<uint8_t> cl;\r
+       cl.push_back(0x0F);\r
+       uint16_t adr=(page<<5)+start;\r
+       cl.push_back(adr&0xFF);\r
+       cl.push_back(adr>>8);\r
+       if (count > (int)(*data).size()) count = (*data).size();\r
+       for(int i=0;i<count;i++) {\r
+               cl.push_back((*data)[i]);\r
+       }\r
+       Communicate(&cl, 3+count, 0);\r
+       for (uint8_t v :cl) printf("%02X ",v);printf("\n");\r
+       cl.clear();\r
+       cl.push_back(0xAA);\r
+       Communicate(&cl, 1, 36);\r
+       //for (uint8_t v :cl) printf("%02X ",v);;printf("\n");\r
+       cl[0]=0x5A;\r
+       Communicate(&cl, 4, 1);\r
+       usleep(100000);\r
+       if (cl[4]!=0xAA) {\r
+               for (uint8_t v :cl) printf("%02X ",v);;printf("\n");\r
+               owi->log->set(OWLOG_ERROR,"DS2423 Copy from Scratchpad to Memmory Error");\r
+               //return 0;\r
+       }\r
+       return count;\r
+}\r
+\r
+\r
+\r
+\r
+\r
+\r
+=======
 }
 #endif
 owDevice::owDevice(owInterface *owi_,snum_t num) {
@@ -606,3 +1210,4 @@ int owDeviceDS2423::writeMemory(int page,int start, int count,std::vector<uint8_
 
 
 
+>>>>>>> origin/master
index 1703957..5c86c05 100644 (file)
@@ -284,6 +284,11 @@ double owDeviceConfig::calculateValueFromNumber(int code, int vn, std::vector<in
                        case 24:return V[vn]*1.1/1024.0;break;
                        case 25:return V[vn]*3.0/1024.0;break;
                        case 26:return V[vn]*5.0/1024.0;break;
+<<<<<<< HEAD
+                       case 27:return ((double)V[2]+(double)V[1]/1000.0)/8.0;break;
+                       case 28:return exp(V[vn]/2560.0);break;
+=======
+>>>>>>> origin/master
                        default:return V[vn];
                }
 }
index b02c047..0b189fa 100755 (executable)
@@ -476,7 +476,11 @@ int owInterface::owSearch() {
                }\r
                while(rom_byte_number < 8);  // loop until through all ROM bytes 0-7\r
                // if the search was successful then\r
+<<<<<<< HEAD
+               if (!((id_bit_number < 65) || (crc8 != 0)))              {\r
+=======
                if (!((id_bit_number < 65) || (crc8 != 0))) {\r
+>>>>>>> origin/master
                        // search successful so set LastDiscrepancy,LastDeviceFlag,search_result\r
                        LastDiscrepancy = last_zero;\r
                        // check for last device\r