Config Change.... 0xCC for temp measurement DS2438/DS18B20
authorTobias <tm@tm3d.de>
Fri, 29 Dec 2017 22:06:11 +0000 (23:06 +0100)
committerTobias <tm@tm3d.de>
Fri, 29 Dec 2017 22:06:11 +0000 (23:06 +0100)
src/main.cpp
src/owDevice.cpp
src/owDeviceConfig.cpp
src/owInterface.cpp

index 1d9e64f..de17078 100755 (executable)
@@ -285,10 +285,10 @@ 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);
+                               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();
index e710102..60a8e99 100755 (executable)
@@ -231,8 +231,8 @@ int owDeviceDS18B20::readScratchpad(std::vector<uint8_t> *sp) {
 
 int owDeviceDS18B20::convertAll() {
        std::vector<uint8_t> sp;
-       sp.push_back(0x44);
-       Communicate(&sp, 1, 0);
+       //sp.push_back(0x44);
+       //communicate(&sp, 1, 0); ///########################################################
        usleep(750000);
 
        if (readScratchpad(&sp)) {
@@ -375,8 +375,8 @@ inline int16_t ow_fconvert(uint8_t b1, uint16_t b2) {
 int owDeviceDS2438::convertAll() {
        for(int k=0;k<owi->maxrepeat;k++)  {
                std::vector<uint8_t> sp;
-               sp.push_back(0x44);
-               Communicate(&sp, 1, 0);
+               //sp.push_back(0x44);
+               //Communicate(&sp, 1, 0);///########################################################
                if (owi->log->last()>=OWLOG_ERROR) continue;
                usleep(100000);
                if (setConfigByte(0x08)<=0) continue;
@@ -457,6 +457,8 @@ void owDeviceDS2450::readMemory(uint8_t addr,std::vector<uint8_t> *sp) {
                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;
        }
@@ -503,6 +505,8 @@ void owDeviceDS2450::convert(uint8_t mask, uint8_t preset) {
        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;
        }
index 66bc9df..33f9769 100644 (file)
@@ -279,7 +279,8 @@ double owDeviceConfig::calculateValueFromNumber(int code, int vn, std::vector<in
                        case 19:return V[vn]/500.0*14.0;break;  //Test
                        case 20:return V[vn]*0.5+700;break;  
                        case 21:return V[vn]+1280; break;  
-                       default:return 0;
+                       case 22:return V[vn]*10;break;
+                       default:return V[vn];
                }
 }
 
index c08ea2d..b02c047 100755 (executable)
@@ -119,12 +119,12 @@ int owInterface::testCRC16(std::vector<uint8_t> data)  {
        return calcCRC16(data)==0xB001;\r
 }\r
                \r
-void owInterface::resetFlasher() { // go back from Bootloader\r
+void owInterface::resetFlasher(uint64_t id) { // go back from Bootloader\r
        std::vector<uint8_t> data;\r
        data.push_back(0x89);\r
        Wait_Free();\r
        snum_t snum;\r
-       snum.num=0xfa55aa55aa55aaa3;\r
+       snum.num=id;\r
        MatchRom(snum);\r
        if (log->last()==OWLOG_ERROR) {Free(); return;}\r
        Communicate(&data, 1, 0);\r
@@ -134,21 +134,21 @@ void owInterface::resetFlasher() { // go back from Bootloader
        usleep(50);     \r
 }\r
 \r
-void owInterface::resetID() {\r
+void owInterface::resetID(uint64_t id) {\r
        std::vector<uint8_t> data;\r
        data.push_back(0x8B);\r
        Wait_Free();\r
        snum_t snum;\r
-       snum.num=0xfa55aa55aa55aaa3;\r
+       snum.num=id;\r
        MatchRom(snum);\r
        if (log->last()==OWLOG_ERROR) {Free(); return;}\r
        Communicate(&data, 1, 0);\r
        Free();\r
 }\r
 \r
-int owInterface::programmPage(int pagenr, std::vector<uint8_t> page, int pagesize) {\r
+int owInterface::programmPage(uint64_t id,int pagenr, std::vector<uint8_t> page, int pagesize) {\r
        snum_t snum;\r
-       snum.num=0xfa55aa55aa55aaa3;\r
+       snum.num=id;\r
 //     printf("programm page %i",pagenr);\r
        \r
        \r
@@ -249,11 +249,7 @@ int owInterface::flashHEXFile(std::string filename,snum_t dev,int resetid,int pr
        if (hf->lastError==1) {log->set(OWLOG_ERROR,"CRC Error in HEX-File %s",filename.c_str());return -1;}\r
        if (hf->lastError==2) {log->set(OWLOG_ERROR,"Error interpreting  HEX-File %s",filename.c_str());return -2;}\r
        if (hf->lastError==3) {log->set(OWLOG_ERROR,"File could not be opened: %s",filename.c_str());return -3;}\r
-       unsigned int blcount=hf->getBlockCount(64);\r
-       if (blcount>118) {\r
-               log->set(OWLOG_ERROR,"Code to big, max 7552 Byte allowed (118 Pages). Code has %i pages!",blcount);\r
-               return -5;\r
-       }\r
+       \r
        log->set(OWLOG_INFO,"Try to start Bootloader on device %llX",dev.num);\r
        int r=maxrepeat+1;\r
        int found;\r
@@ -283,6 +279,10 @@ int owInterface::flashHEXFile(std::string filename,snum_t dev,int resetid,int pr
                                found=1;\r
                                break;\r
                        }       \r
+                       if (dev->getNum().num==0x8A57AA57AA57AAA3) {\r
+                               found=2;\r
+                               break;\r
+                       }       \r
                }\r
                if (found==0) log->set(OWLOG_WARNING,"Bootloader not found");\r
                r--;\r
@@ -291,16 +291,43 @@ int owInterface::flashHEXFile(std::string filename,snum_t dev,int resetid,int pr
                log->set(OWLOG_ERROR,"Can not start Bootloader on this device %llX",dev.num);\r
                return -4;\r
        }\r
+       \r
+       unsigned int blcount=0;\r
+       \r
+       int blsize=64;\r
+       uint64_t id=0;\r
+       \r
+       if (found==1) {\r
+               log->set(OWLOG_INFO,"Bootloader on ATtiny84A found. Pagesize = 64 bytes");\r
+               blsize=64;\r
+               blcount=hf->getBlockCount(64);\r
+               id=0xfa55aa55aa55aaa3;\r
+               if (blcount>118) {\r
+                       log->set(OWLOG_ERROR,"Code to big, max 7552 Byte allowed (118 Pages). Code has %i pages!",blcount);\r
+                       return -5;\r
+               }\r
+       }\r
+       if (found==2) {\r
+               log->set(OWLOG_INFO,"Bootloader on ATmega328PB found. Pagesize = 128 bytes");\r
+               blsize=128; \r
+               blcount=hf->getBlockCount(128);\r
+               id=0x8A57AA57AA57AAA3;\r
+               if (blcount>248) {\r
+                       log->set(OWLOG_ERROR,"Code to big, max 31744 Byte allowed (248 Pages). Code has %i pages!",blcount);\r
+                       return -5;\r
+               }\r
+               \r
+       }\r
        log->set(OWLOG_INFO,"Start Programm %i Pages",blcount);\r
        int rp=0;\r
        int er=0;\r
        unsigned int i =0;\r
        for ( i= 0; i < blcount; i++) {\r
-               std::vector<uint8_t> blk = hf->getBlock(i*64, 64);\r
+               std::vector<uint8_t> blk = hf->getBlock(i*blsize, blsize);\r
                int errc = maxrepeat*5;\r
                while (errc != 0) {\r
                        log->clear();\r
-                       if (programmPage(i, blk, 64) >= 0) {\r
+                       if (programmPage(id,i, blk,blsize) >= 0) {\r
                                if (progress) {printf("#");fflush(stdout);} \r
                                break;\r
                        }\r
@@ -322,14 +349,14 @@ int owInterface::flashHEXFile(std::string filename,snum_t dev,int resetid,int pr
        } else {\r
                if (resetid) {\r
                        log->set(OWLOG_INFO,"Set 1-Wire ID to ID in hexfile...",blcount); \r
-                       resetID();\r
+                       resetID(id);\r
 #ifdef LINUX\r
                        sleep(3);\r
 #endif\r
 #ifdef WIN\r
                        Sleep(3000);\r
 #endif\r
-                       resetID();      \r
+                       resetID( id);   \r
 #ifdef LINUX\r
                        sleep(3);\r
 #endif\r
@@ -342,14 +369,14 @@ int owInterface::flashHEXFile(std::string filename,snum_t dev,int resetid,int pr
        log->set(OWLOG_INFO,"Back from bootloader to normal device...",blcount); \r
        \r
        \r
-       resetFlasher();\r
+       resetFlasher(id);\r
 #ifdef LINUX\r
        sleep(1);       \r
 #endif\r
 #ifdef WIN\r
        Sleep(1000);\r
 #endif\r
-       resetFlasher();\r
+       resetFlasher(id);\r
 #ifdef LINUX\r
        sleep(3);\r
 #endif\r