- OWINIT save Register used in C
authorTobias <tm@tm3d.de>
Sun, 1 May 2016 12:28:57 +0000 (14:28 +0200)
committerTobias <tm@tm3d.de>
Sun, 1 May 2016 12:28:57 +0000 (14:28 +0200)
- Convert with freq. of reading
- VOC optimization
- HIH9121 as DS2438

65 files changed:
Attiny84A nur Feuchte.pdf [new file with mode: 0644]
DS18B20_BMP280_DS2438_SHT/DS18B20.pdf [new file with mode: 0644]
DS18B20_BMP280_DS2438_SHT/DS18B20_BMP280_DS2438_SHT.cproj
DS18B20_BMP280_DS2438_SHT/DS18B20_DS2438.c
DS18B20_MAX44009_DS2438_SHT/DS18B20.pdf [new file with mode: 0644]
DS18B20_MAX44009_DS2438_SHT/DS18B20_DS2438.c
DS18B20_VOC/DS18B20.pdf [new file with mode: 0644]
DS18B20_VOC_DS2438_SHT/DS18B20.pdf [new file with mode: 0644]
DS18B20_VOC_DS2438_SHT/DS18B20_DS2438.c
DS18B20_VOC_DS2438_SHT/DS18B20_VOC_DS2438_SHT.cproj
DS2423/DS2423.c
DS2423/DS2423.cproj
DS2423/OWDS2423.S [deleted file]
DS2438_DHT22/DS2438_DHT22 - Kopie.c [new file with mode: 0644]
DS2438_DHT22/DS2438_DHT22.cproj
DS2438_HIH9121/DS2438_9121.atsln [new file with mode: 0644]
DS2438_HIH9121/DS2438_HIH9121.c [new file with mode: 0644]
DS2438_HIH9121/DS2438_HIH9121.cproj [new file with mode: 0644]
DS2438_SHT2X/DS2438_SHT2X.c
DS2450/DS2450.cproj
DS2450/DS2450.pdf [deleted file]
DS2450_SHT2X_BMP280_MAX44009/DS2450.pdf [new file with mode: 0644]
common/OWDS18B20_DS2438.S
common/OWRomFunctions.s
common/OWRomFunctionsDual.s
common/OWSet_ATTINYX4.s
common/calibr.c [new file with mode: 0644]
common/calibr.h [new file with mode: 0644]
programmer/flash/flashp 2.7.bat [new file with mode: 0644]
programmer/flash/flashp.bat
stest/fdiff.py [new file with mode: 0644]
stest/find.py [new file with mode: 0644]
stest/log_all.py [new file with mode: 0644]
stest/log_all1.py [new file with mode: 0644]
stest/main.cpp [new file with mode: 0644]
stest/separate1.py [new file with mode: 0644]
tools_cmd/IB10E64.dll [new file with mode: 0644]
tools_cmd/IB97E64.dll [new file with mode: 0644]
tools_cmd/IB97U64.dll [new file with mode: 0644]
tools_cmd/IBFS64.dll [new file with mode: 0644]
tools_cmd/IBUSB64.dll [new file with mode: 0644]
tools_cmd/bin/ib90usb.dll [new file with mode: 0644]
tools_cmd/bin/ib97e32.dll [new file with mode: 0644]
tools_cmd/bin/ib97u32.dll [new file with mode: 0644]
tools_cmd/bin/ibfs32.dll [new file with mode: 0644]
tools_cmd/bin/ibusb32.dll [new file with mode: 0644]
tools_cmd/ib90usb.dll [new file with mode: 0644]
tools_cmd/ib97e32.dll [new file with mode: 0644]
tools_cmd/ib97u32.dll [new file with mode: 0644]
tools_cmd/ibfs32.dll [new file with mode: 0644]
tools_cmd/ibtmjava.dll [new file with mode: 0644]
tools_cmd/ibtmjava64.dll [new file with mode: 0644]
tools_cmd/ibusb32.dll [new file with mode: 0644]
tools_cmd/owtools.sdf [new file with mode: 0644]
tools_cmd/owtools.sln [new file with mode: 0644]
tools_cmd/rwOW/crcutil.c [new file with mode: 0644]
tools_cmd/rwOW/ibfs32.lib [new file with mode: 0644]
tools_cmd/rwOW/ibtmexcw.h [new file with mode: 0644]
tools_cmd/rwOW/main.cpp [new file with mode: 0644]
tools_cmd/rwOW/owerr.c [new file with mode: 0644]
tools_cmd/rwOW/ownet.h [new file with mode: 0644]
tools_cmd/rwOW/tmexlnk.c [new file with mode: 0644]
tools_cmd/rwOW/tmexnet.c [new file with mode: 0644]
tools_cmd/rwOW/tmexses.c [new file with mode: 0644]
tools_cmd/rwOW/tmextran.c [new file with mode: 0644]

diff --git a/Attiny84A nur Feuchte.pdf b/Attiny84A nur Feuchte.pdf
new file mode 100644 (file)
index 0000000..c783249
Binary files /dev/null and b/Attiny84A nur Feuchte.pdf differ
diff --git a/DS18B20_BMP280_DS2438_SHT/DS18B20.pdf b/DS18B20_BMP280_DS2438_SHT/DS18B20.pdf
new file mode 100644 (file)
index 0000000..a942d79
Binary files /dev/null and b/DS18B20_BMP280_DS2438_SHT/DS18B20.pdf differ
index fe91bf9..971060d 100644 (file)
     <BootSegment>2</BootSegment>
     <eraseonlaunchrule>1</eraseonlaunchrule>
     <AsfFrameworkConfig>
-      <framework-data xmlns="">
+      <framework-data>
         <options />
         <configurations />
         <files />
         <documentation help="" />
         <offline-documentation help="" />
         <dependencies>
-          <content-extension eid="atmel.asf" uuidref="Atmel.ASF" version="3.19.0" />
+          <content-extension eid="atmel.asf" uuidref="Atmel.ASF" version="3.21.0" />
         </dependencies>
       </framework-data>
     </AsfFrameworkConfig>
@@ -46,7 +46,7 @@
         <InterfaceName>debugWIRE</InterfaceName>
       </ToolOptions>
       <ToolType>com.atmel.avrdbg.tool.atmelice</ToolType>
-      <ToolNumber>J41800000779</ToolNumber>
+      <ToolNumber>J41800000789</ToolNumber>
       <ToolName>Atmel-ICE</ToolName>
     </com_atmel_avrdbg_tool_atmelice>
     <avrtoolinterface>debugWIRE</avrtoolinterface>
@@ -63,6 +63,8 @@
       <ToolName>Simulator</ToolName>
     </com_atmel_avrdbg_tool_simulator>
     <ExternalProgrammingToolCommand />
+    <avrtoolserialnumber>J41800000789</avrtoolserialnumber>
+    <avrdeviceexpectedsignature>0x1E930C</avrdeviceexpectedsignature>
   </PropertyGroup>
   <PropertyGroup Condition=" '$(Configuration)' == 'Release' ">
     <ToolchainSettings>
       <SubType>compile</SubType>
       <Link>SHT2x.c</Link>
     </Compile>
+    <Compile Include="D:\oc\dev\owSlave2\common\calibr.c">
+      <SubType>compile</SubType>
+      <Link>calibr.c</Link>
+    </Compile>
     <Compile Include="D:\oc\dev\owSlave2\common\I2C\BMP280.c">
       <SubType>compile</SubType>
       <Link>BMP280.c</Link>
index b4b62d0..d8b04bd 100644 (file)
@@ -40,7 +40,7 @@
 #include "../common/I2C/USI_TWI_Master.h"
 #include "../common/I2C/SHT2x.h"
 #include "../common/I2C/BMP280.h"
-
+#include "../common/calibr.h"
 
 extern void OWINIT();
 extern void EXTERN_SLEEP();
@@ -64,8 +64,9 @@ volatile uint8_t wdcounter=3;
 
 #if  defined(__AVR_ATtiny24__)||defined(__AVR_ATtiny44__)  || defined(__AVR_ATtiny84__) || defined(__AVR_ATtiny24A__)||defined(__AVR_ATtiny44A__)  || defined(__AVR_ATtiny84A__)
 ISR(WATCHDOG_vect) {
-#else
-ISR(WDT_vect) {
+       #else
+       ISR(WDT_vect) {
+       
 #endif 
        //sleep_disable();          // Disable Sleep on Wakeup
        wdcounter++;
@@ -180,7 +181,7 @@ int main(void){
        ACSR|=(1<<ACD);  //Disable Comparator
        ADCSRB|=(1<<ACME); //Disable Analog multiplexer
        MCUCR &=~(1<<PUD); //All Pins Pullup...
-       MCUCR |=(1<<BODS);
+       //MCUCR &=~(1<<BODS);
 
        
        WDTCSR |= ((1<<WDCE) );   // Enable the WD Change Bit//| (1<<WDE)
@@ -195,36 +196,51 @@ int main(void){
 
        MCUSR=0;
        USI_TWI_Master_Initialise();
-       bmp280Init();
+       
        SHT2x_SoftReset();
        SHT2x_ReadUserRegister(userRegister);
        //(userRegister & ~SHT2x_RES_MASK) | SHT2x_RES_10_13BIT;
        SHT2x_WriteUserRegister(userRegister); //write changed user reg
        // --- measure humidity with "Hold Master Mode (HM)" ---
-       SHT2x_MeasurePoll(HUMIDITY, &sRH);
+       //SHT2x_MeasurePoll(HUMIDITY, &sRH);
        // --- measure temperature with "Polling Mode" (no hold master) ---
-       SHT2x_MeasurePoll(TEMP, &sT);
+       //SHT2x_MeasurePoll(TEMP, &sT);
        //-- calculate humidity and temperature --
-       temperatureC = SHT2x_CalcTemperatureC(sT);
-       humidityRH = SHT2x_CalcRH(sRH);
-       
+       //temperatureC = SHT2x_CalcTemperatureC(sT);
+       //humidityRH = SHT2x_CalcRH(sRH);
+       bmp280Init();
        gcontrol=1;
        sei();
     while(1)   {
-               if ((gcontrol==2)||(gcontrol==3)) {
+               if (gcontrol) {
                        wdcounter=3;
-                       gcontrol=0;
-               }               
-               if (wdcounter>3) {
+                       
+               }
+
+               if (wdcounter>2) {
                        SHT2x_MeasurePoll(HUMIDITY, &sRH);
                        // --- measure temperature with "Polling Mode" (no hold master) ---
                        SHT2x_MeasurePoll(TEMP, &sT);
                        //-- calculate humidity and temperature --
-                       temperatureC = SHT2x_CalcTemperatureC(sT)*10.0;
-                       humidityRH = SHT2x_CalcRH(sRH)*10.0;
-                       double hhum=(1.0546-0.000216*temperatureC)*(humidityRH);
-                       am2302_hum=0.318*hhum +76.0;
-                       am2302_temp=temperatureC*25.6;
+                       temperatureC = SHT2x_CalcTemperatureC(sT);
+                       humidityRH = SHT2x_CalcRH(sRH);
+                       humidityRH=calibr_hum(temperatureC,-0.45,humidityRH)*10.0;
+                       temperatureC=temperatureC*10.0-4.5;
+                        if (testSW()) {
+                                am2302_hum= humidityRH*10.0;
+                                am2302_temp=temperatureC*25.6;
+                                am2302_temp=am2302_temp-20;
+                                config_info2[5]=8;
+                                
+                                }else{
+                                
+                                double hhum=(1.0546-0.000216*temperatureC)*(humidityRH);
+                                //am2302_hum=0.318*hhum +76.0;
+                                am2302_hum=0.31*hhum +80;
+                                am2302_temp=temperatureC*25.6;
+                                am2302_temp=am2302_temp-20;
+                                config_info2[5]=7;
+                        }
                        wdcounter=0;
                }
        
@@ -243,9 +259,13 @@ int main(void){
                                //pack.temp++;
                                alarmflag=af;
                                sei();
+                               gcontrol=0;
                                EXTERN_SLEEP(); 
                }
-               
+               if (gcontrol) {
+                       gcontrol=0;
+                       
+               }
 
                
 #if  defined(__AVR_ATtiny25__)||defined(__AVR_ATtiny45__)  || defined(__AVR_ATtiny85__)
diff --git a/DS18B20_MAX44009_DS2438_SHT/DS18B20.pdf b/DS18B20_MAX44009_DS2438_SHT/DS18B20.pdf
new file mode 100644 (file)
index 0000000..a942d79
Binary files /dev/null and b/DS18B20_MAX44009_DS2438_SHT/DS18B20.pdf differ
index 3cdc7ec..affc509 100644 (file)
@@ -60,7 +60,7 @@ extern uint8_t mode;
 extern uint8_t gcontrol;
 extern uint8_t reset_indicator;
 extern uint8_t alarmflag;
-volatile uint8_t wdcounter;
+volatile uint8_t wdcounter=5;
 
 
 #if  defined(__AVR_ATtiny24__)||defined(__AVR_ATtiny44__)  || defined(__AVR_ATtiny84__) || defined(__AVR_ATtiny24A__)||defined(__AVR_ATtiny44A__)  || defined(__AVR_ATtiny84A__)
@@ -82,6 +82,26 @@ ISR(WDT_vect) {
 
 }
 
+int testSW(void) {
+       uint8_t r;
+       DDRB&=~(1<<PORTB0);  //Eingang
+       __asm__ __volatile__ ("nop");
+       PORTB|=(1<<PORTB0); //Pullup
+       __asm__ __volatile__ ("nop");
+       __asm__ __volatile__ ("nop");
+       __asm__ __volatile__ ("nop");
+       __asm__ __volatile__ ("nop");
+       __asm__ __volatile__ ("nop");
+       r=PINB&(1<<PORTB0);
+       __asm__ __volatile__ ("nop");
+       PORTB&=~(1<<PORTB0);
+       __asm__ __volatile__ ("nop");
+       DDRB|=(1<<PORTB0);  //Eingang
+       return (r==0);
+       
+       
+}
+
 
 typedef union {
        volatile uint8_t bytes[8];
@@ -159,8 +179,12 @@ int main(void){
 
        WDTCSR |= ((1<<WDCE) );   // Enable the WD Change Bit//| (1<<WDE)
        WDTCSR |=   (1<<WDIE) |              // Enable WDT Interrupt
-       (1<<WDP2) | (1<<WDP1);   // Set Timeout to ~1 seconds
-
+       (1<<WDP3) | (1<<WDP0);   // Set Timeout to ~8 seconds
+       if (testSW()) {
+               config_info2[5]=8;
+               }else{
+               config_info2[5]=7;
+       }
        MCUSR=0;
        USI_TWI_Master_Initialise();
        if (checkMAX44009(0)) max_adr=0; else max_adr=1 ;
@@ -173,29 +197,48 @@ int main(void){
        // --- measure temperature with "Polling Mode" (no hold master) ---
        SHT2x_MeasurePoll(TEMP, &sT);
        //-- calculate humidity and temperature --
-       temperatureC = SHT2x_CalcTemperatureC(sT);
-       humidityRH = SHT2x_CalcRH(sRH);
+       //temperatureC = SHT2x_CalcTemperatureC(sT);
+       //humidityRH = SHT2x_CalcRH(sRH);
        
        gcontrol=1;
        sei();
        //DDRB|=(1<<PINB1);
     while(1)   {
-               if (wdcounter>0) {
+               if ((gcontrol==2)||(gcontrol==3)) {
+                       wdcounter=3;
+                       gcontrol=0;
+                       
+               }
+               
+               if (wdcounter>2) {
                        //PORTB|=(1<<PINB1); //Dauer 440ms
                        SHT2x_MeasurePoll(HUMIDITY, &sRH);
                        // --- measure temperature with "Polling Mode" (no hold master) ---
                        SHT2x_MeasurePoll(TEMP, &sT);
                        //-- calculate humidity and temperature --
-                       temperatureC = SHT2x_CalcTemperatureC(sT)*10.0;
-                       humidityRH = SHT2x_CalcRH(sRH)*10.0;
-                       double hhum=(1.0546-0.000216*temperatureC)*(humidityRH);
-                       am2302_hum=0.318*hhum +76.0;
-                       am2302_temp=temperatureC*25.6;
-                       //PORTB&=~(1<<PINB1);
+                       temperatureC = SHT2x_CalcTemperatureC(sT)*10.0-4;
+                       humidityRH = SHT2x_CalcRH(sRH)*10.0+5;
+                       if (humidityRH>1000) humidityRH=1000;
+                       if (testSW()) {
+                               am2302_hum= humidityRH*10.0;
+                               am2302_temp=temperatureC*25.6;
+                               //
+                               config_info2[5]=8;
+                               
+                       }else{
+                               
+                               double hhum=(1.0546-0.000216*temperatureC)*(humidityRH);
+                               //am2302_hum=0.318*hhum +76.0;
+                               am2302_hum=0.31*hhum +80;
+                               am2302_temp=temperatureC*25.6;
+                               //am2302_temp=am2302_temp-45;
+                               config_info2[5]=7;
+                       }
                        wdcounter=0;
                }
        
                if (gcontrol==1) {
+                       gcontrol=0;
                        l=MAX44009getlux(max_adr);              
                        if (l<0.030) l=0.030; //Darf nicht 0 sein. minimum -35°C Sensor minimum 0.045
                        //double l=1000;
@@ -212,10 +255,7 @@ int main(void){
                        sei();                  
                        EXTERN_SLEEP();         
                }
-               if ((gcontrol==2)||(gcontrol==3)) {
-                       gcontrol=0;
-                       
-               }
+               
 
                
 #if  defined(__AVR_ATtiny25__)||defined(__AVR_ATtiny45__)  || defined(__AVR_ATtiny85__)
diff --git a/DS18B20_VOC/DS18B20.pdf b/DS18B20_VOC/DS18B20.pdf
new file mode 100644 (file)
index 0000000..a942d79
Binary files /dev/null and b/DS18B20_VOC/DS18B20.pdf differ
diff --git a/DS18B20_VOC_DS2438_SHT/DS18B20.pdf b/DS18B20_VOC_DS2438_SHT/DS18B20.pdf
new file mode 100644 (file)
index 0000000..a942d79
Binary files /dev/null and b/DS18B20_VOC_DS2438_SHT/DS18B20.pdf differ
index 5a0094e..0e9ae0a 100644 (file)
 #include "../common/I2C/USI_TWI_Master.h"
 #include "../common/I2C/MAX1164x.h"
 #include "../common/I2C/SHT2x.h"
-#include <avr/pgmspace.h>
+#include "../common/calibr.h"
 
 extern void OWINIT();
 extern void EXTERN_SLEEP();
 
 
-const int16_t hl[5] PROGMEM = {0,400,650,850,1000};  //H*10
-
-//log values *1000
-const int16_t il[5][5] PROGMEM= {
-{470,  247,    140,    77,     49},
-{336,  104,    0,      -62,    -83},
-{207,  -20,    -139,   -198,   -223},
-{86,   -139,   -248,   -315,   -342},
-{-30,  -248,   -371,   -431,   -462}};
-
-
-
-
-extern void OWINIT();
-extern void EXTERN_SLEEP();
-
 
-uint8_t owid1[8]={0x28, 0xA3, 0xD9, 0x84, 0x00, 0x16, 0x05, 0x18};/**/
-uint8_t owid2[8]={0x26, 0xA3, 0xD9, 0x84, 0x00, 0x16, 0x05, 0x67};/**/
-uint8_t config_info1[16]={0x08,0x01, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x01,0x00,0x00,0x00,0x00,0x00,0x00,0x00};        
-uint8_t config_info2[16]={0x01,0x06, 0x05,0x08, 0x04,0x07, 0x07,0x08, 0x01,0x00,0x00,0x00,0x00,0x00,0x00,0x00};        
+volatile uint8_t owid1[8]={0x28, 0xA3, 0xD9, 0x84, 0x00, 0x16, 0x05, 0x18};/**/
+volatile uint8_t owid2[8]={0x26, 0xA3, 0xD9, 0x84, 0x00, 0x16, 0x05, 0x67};/**/
+volatile uint8_t config_info1[16]={0x08,0x01, 0x00,0x00, 0x00,0x00, 0x00,0x00, 0x01,0x00,0x00,0x00,0x00,0x00,0x00,0x00};       
+volatile uint8_t config_info2[16]={0x01,0x06, 0x05,0x08, 0x04,0x07, 0x07,0x08, 0x01,0x00,0x00,0x00,0x00,0x00,0x00,0x00};       
        
 #if (owid>128) 
 #error "Variable not correct"
@@ -146,8 +130,8 @@ volatile uint16_t am2302_hum;
 
 uint8_t userRegister[1];
 int16_t sRH,sT;
-volatile double temperatureC,humidityRH;
-volatile double l;
+double temperatureC,humidityRH,hhum;
+double l;
 
 uint8_t max_adr=0;
 #define CH0_M MAX1164x_C_SCAN0|MAX1164x_C_SGL
@@ -155,44 +139,25 @@ uint8_t max_adr=0;
 #define CH0_CH1 MAX1164x_C_SCAN0
 //|MAX1164x_C_CS0
 
-//T und H mit 10 multipliziert
-
-double interp(int16_t t, int16_t h) {
-double ya,yb;
-uint8_t h1,h2,t1,t2;
-int16_t x1,x2,y1_,y2;
-       h1=0;
-       h2=0;
-       for(uint8_t i=0;i<5;i++) {
-               int16_t hlw=pgm_read_word(&(hl[i]));
-               if (h>hlw) h1=i;
-       }
-       h2=h1+1;
-       if (h2>4) {h2=4;h1=3;}
-       t2=((uint8_t)t/100); //t mit 10 multipliziert
-       if (t2<1) t2=1;
-       t1=t2-1;
-       x1=pgm_read_word(&(hl[h1]));
-       x2=pgm_read_word(&(hl[h2]));
-       y1_=pgm_read_word(&(il[t1][h1]));
-       y2=pgm_read_word(&(il[t1][h2]));
-       double d=(double)(h-x1)/(x2-x1);
-       ya=y1_+(y2-y1_)*d;
-       y1_=pgm_read_word(&(il[t2][h1]));
-       y2=pgm_read_word(&(il[t2][h2]));
-       yb=y1_+(y2-y1_)*d;
-       x1=(t1+1)*100;
-       x2=x1+100;
-       return exp((ya+(yb-ya)/(double)(x2-x1)*(t-x1))/1000.0);
-       
+
+inline double interp(double t, double h) {
+       double h2;
+        double t2;
+       h2=h*h;
+       t2=t*t;
+       return 4.76111e-9*h2*t2-3.96956e-7*h2*t+0.0000408889*h2-1.07132e-6*h*t2+0.000115968*h*t-0.0101333*h+0.000163806*t2-0.0241179*t+1.80591;
 }
+
 uint8_t cmode=0;
 double R0=0;
 int16_t hr;
 uint8_t startup=5;
 uint8_t reset_R0=0;
+int16_t mr;
+double ip;
 
 int main(void){
+       //volatile double test=calibr_hum(20,1,20);
     PRR|=(1<<PRADC);  // adc for save Power
        pack1.temp=0x0550;
        pack1.config=0x7F;
@@ -228,18 +193,11 @@ int main(void){
        }
 
        
-       /*volatile double test=interp(0,800);
-       test=interp(100,900);
-       test=interp(110,400);
-       test=interp(300,200);
-       test=interp(300,210);
-       test=interp(280,600);
-       test=interp(100,900);
-       */
 
        WDTCSR |= ((1<<WDCE) );   // Enable the WD Change Bit//| (1<<WDE)
        WDTCSR |=   (1<<WDIE) |              // Enable WDT Interrupt
-       (1<<WDP3) | (1<<WDP0);    // Set Timeout to ~8 seconds
+       (1<<WDP0) |(1<<WDP2) | (1<<WDP1);    // Set Timeout to ~2 seconds
+       //(1<<WDP3) | (1<<WDP0);    // Set Timeout to ~8 seconds
 
        MCUSR=0;
        USI_TWI_Master_Initialise();
@@ -249,12 +207,12 @@ int main(void){
        //(userRegister & ~SHT2x_RES_MASK) | SHT2x_RES_10_13BIT;
        SHT2x_WriteUserRegister(userRegister); //write changed user reg
        // --- measure humidity with "Hold Master Mode (HM)" ---
-       SHT2x_MeasurePoll(HUMIDITY, &sRH);
+       //SHT2x_MeasurePoll(HUMIDITY, &sRH);
        // --- measure temperature with "Polling Mode" (no hold master) ---
-       SHT2x_MeasurePoll(TEMP, &sT);
+       //SHT2x_MeasurePoll(TEMP, &sT);
        //-- calculate humidity and temperature --
-       temperatureC = SHT2x_CalcTemperatureC(sT);
-       humidityRH = SHT2x_CalcRH(sRH);
+       //temperatureC = SHT2x_CalcTemperatureC(sT);
+       //humidityRH = SHT2x_CalcRH(sRH);
        MAX1164x_config(MAX1164x_S_SEL2|MAX1164x_S_SEL0,CH0_M);//#define MAX1164x_C_CS0
        _delay_ms(30); //Internal Referenz start
        //2970 -> 1,5V  
@@ -292,29 +250,43 @@ int main(void){
                        // --- measure temperature with "Polling Mode" (no hold master) ---
                        SHT2x_MeasurePoll(TEMP, &sT);
                        //-- calculate humidity and temperature --
-                       temperatureC = SHT2x_CalcTemperatureC(sT)*10.0;
-                       humidityRH = SHT2x_CalcRH(sRH)*10.0;
-                       double hhum=(1.0546-0.000216*temperatureC)*(humidityRH);
+                       temperatureC = SHT2x_CalcTemperatureC(sT);
+                       humidityRH = SHT2x_CalcRH(sRH);
+                       ip=interp(temperatureC,humidityRH);
+                       humidityRH=calibr_hum(temperatureC,-1,humidityRH)*10.0;
+                       //humidityRH=humidityRH*10.0;
+                       temperatureC =temperatureC *10.0-10;
+                       hhum=(1.0546-0.000216*temperatureC)*(humidityRH);
                        am2302_hum=0.318*hhum +76.0;
                        am2302_temp=temperatureC*25.6;
                        //PORTB&=~(1<<PINB1);
+                       mr=0;
+//Kritische Sektion !______________________________
                        PORTB&=~(1<<PINB1);
-                       _delay_us(500);
-                       l=MAX1164x_read();
+                       _delay_us(150);
+                       mr+=MAX1164x_read();
+                       _delay_us(150);
+                       mr+=MAX1164x_read();
+                       
                        PORTB|=(1<<PINB1);
+//ENDE Kritische Sektion !______________________________
+                       //l=mr/2.0*2.048/4096; 
+                       // l maximal 2  mr max 4096  //mr 2V=8000 
+                       
                        if (cmode) {
-                               l=l*2.048/4096+1.5; //Spannung real
-                       } else {
-                               l=l*2.048/4096; //Spannung real
-                       }
-                       if (l>1.8) {
+                               //l+=1.5; //Spannung real
+                               mr+=6000;
+                       } 
+                       //if (l>1.8) {
+                       if (mr>7200) {                          
                                if (cmode==0) {
                                        MAX1164x_config(MAX1164x_S_SEL2|MAX1164x_S_SEL0,CH0_CH1);
                                        cmode=1;
                                        pack2.page3[4]=cmode;
                                }
                        }
-                       if (l<1.6) {
+                       //if (l<1.6) {
+                       if (mr<6400) {  
                                if (cmode==1) {
                                        MAX1164x_config(MAX1164x_S_SEL2|MAX1164x_S_SEL0,CH0_M);
                                        cmode=0;
@@ -323,12 +295,14 @@ int main(void){
                                
                                
                        }
-                       hr=l*10000.0;
+                       //hr=l*10000.0;
+                       hr=mr*5/2;
                        pack2.page3[2]=hr&0xFF;
                        pack2.page3[3]=(hr>>8)&0xFF;
-                       l=( 3/l- 1) *27;
+                       l=mr/4000.0;
+                       l=( 3/l- 1) *30;
                        pack2.current=l*100;
-                       float ip=interp(temperatureC,humidityRH);
+                       //ip=interp(temperatureC,humidityRH);
                        hr=ip*1000;
                        pack2.page3[5]=hr&0xFF;
                        pack2.page3[6]=(hr>>8)&0xFF;
@@ -360,6 +334,9 @@ int main(void){
                         l=l/R0;
                        l=log(1/l);
                        l=l*160*4; //fuer DS18B20
+                       if (l>500) {
+                               l=100;
+                       }
                        wdcounter=0;
                        
                }
index cc461cb..d6e98e5 100644 (file)
   <PropertyGroup Condition=" '$(Configuration)' == 'Release' ">
     <ToolchainSettings>
       <AvrGcc>
-        <avrgcc.common.Device>-mmcu=attiny84a -B "%24(PackRepoDir)\atmel\ATtiny_DFP\1.0.68\gcc\dev\attiny84a"</avrgcc.common.Device>
-        <avrgcc.common.outputfiles.hex>True</avrgcc.common.outputfiles.hex>
-        <avrgcc.common.outputfiles.lss>True</avrgcc.common.outputfiles.lss>
-        <avrgcc.common.outputfiles.eep>True</avrgcc.common.outputfiles.eep>
-        <avrgcc.common.outputfiles.srec>True</avrgcc.common.outputfiles.srec>
-        <avrgcc.common.outputfiles.usersignatures>False</avrgcc.common.outputfiles.usersignatures>
-        <avrgcc.compiler.general.ChangeDefaultCharTypeUnsigned>True</avrgcc.compiler.general.ChangeDefaultCharTypeUnsigned>
-        <avrgcc.compiler.general.ChangeDefaultBitFieldUnsigned>True</avrgcc.compiler.general.ChangeDefaultBitFieldUnsigned>
-        <avrgcc.compiler.symbols.DefSymbols>
-          <ListValues>
-            <Value>DEBUG</Value>
-          </ListValues>
-        </avrgcc.compiler.symbols.DefSymbols>
-        <avrgcc.compiler.directories.IncludePaths>
-          <ListValues>
-            <Value>%24(PackRepoDir)\atmel\ATtiny_DFP\1.0.68\include</Value>
-          </ListValues>
-        </avrgcc.compiler.directories.IncludePaths>
-        <avrgcc.compiler.optimization.level>Optimize (-O1)</avrgcc.compiler.optimization.level>
-        <avrgcc.compiler.optimization.PackStructureMembers>True</avrgcc.compiler.optimization.PackStructureMembers>
-        <avrgcc.compiler.optimization.AllocateBytesNeededForEnum>True</avrgcc.compiler.optimization.AllocateBytesNeededForEnum>
-        <avrgcc.compiler.optimization.DebugLevel>Default (-g2)</avrgcc.compiler.optimization.DebugLevel>
-        <avrgcc.compiler.warnings.AllWarnings>True</avrgcc.compiler.warnings.AllWarnings>
-        <avrgcc.linker.libraries.Libraries>
-          <ListValues>
-            <Value>libm</Value>
-          </ListValues>
-        </avrgcc.linker.libraries.Libraries>
-        <avrgcc.assembler.debugging.DebugLevel>Default (-Wa,-g)</avrgcc.assembler.debugging.DebugLevel>
-      </AvrGcc>
+  <avrgcc.common.Device>-mmcu=attiny84a -B "%24(PackRepoDir)\atmel\ATtiny_DFP\1.0.68\gcc\dev\attiny84a"</avrgcc.common.Device>
+  <avrgcc.common.outputfiles.hex>True</avrgcc.common.outputfiles.hex>
+  <avrgcc.common.outputfiles.lss>True</avrgcc.common.outputfiles.lss>
+  <avrgcc.common.outputfiles.eep>True</avrgcc.common.outputfiles.eep>
+  <avrgcc.common.outputfiles.srec>True</avrgcc.common.outputfiles.srec>
+  <avrgcc.common.outputfiles.usersignatures>False</avrgcc.common.outputfiles.usersignatures>
+  <avrgcc.compiler.general.ChangeDefaultCharTypeUnsigned>True</avrgcc.compiler.general.ChangeDefaultCharTypeUnsigned>
+  <avrgcc.compiler.general.ChangeDefaultBitFieldUnsigned>True</avrgcc.compiler.general.ChangeDefaultBitFieldUnsigned>
+  <avrgcc.compiler.symbols.DefSymbols>
+    <ListValues>
+      <Value>DEBUG</Value>
+    </ListValues>
+  </avrgcc.compiler.symbols.DefSymbols>
+  <avrgcc.compiler.directories.IncludePaths>
+    <ListValues>
+      <Value>%24(PackRepoDir)\atmel\ATtiny_DFP\1.0.68\include</Value>
+    </ListValues>
+  </avrgcc.compiler.directories.IncludePaths>
+  <avrgcc.compiler.optimization.level>Optimize (-O1)</avrgcc.compiler.optimization.level>
+  <avrgcc.compiler.optimization.PackStructureMembers>True</avrgcc.compiler.optimization.PackStructureMembers>
+  <avrgcc.compiler.optimization.AllocateBytesNeededForEnum>True</avrgcc.compiler.optimization.AllocateBytesNeededForEnum>
+  <avrgcc.compiler.optimization.DebugLevel>Default (-g2)</avrgcc.compiler.optimization.DebugLevel>
+  <avrgcc.compiler.warnings.AllWarnings>True</avrgcc.compiler.warnings.AllWarnings>
+  <avrgcc.linker.libraries.Libraries>
+    <ListValues>
+      <Value>libm</Value>
+    </ListValues>
+  </avrgcc.linker.libraries.Libraries>
+  <avrgcc.assembler.debugging.DebugLevel>Default (-Wa,-g)</avrgcc.assembler.debugging.DebugLevel>
+</AvrGcc>
     </ToolchainSettings>
   </PropertyGroup>
   <PropertyGroup Condition=" '$(Configuration)' == 'Debug' ">
     </ToolchainSettings>
   </PropertyGroup>
   <ItemGroup>
+    <Compile Include="..\common\calibr.c">
+      <SubType>compile</SubType>
+      <Link>calibr.c</Link>
+    </Compile>
     <Compile Include="..\common\I2C\SHT2x.c">
       <SubType>compile</SubType>
       <Link>SHT2x.c</Link>
index 73cb3b6..89b07db 100644 (file)
@@ -32,8 +32,8 @@
 // OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
 
 #define _4_COUNTERS_
-#define _EEPROM_SAVE_
-//#define _CPULLUP_
+//#define _EEPROM_SAVE_
+#define _CPULLUP_
 
 #define F_CPU 8000000UL
 #include <avr/io.h>
@@ -155,10 +155,10 @@ int main(void){
        OWINIT();
        
        pack.zero=0;
-       counters.c32[0]=223433;
-       counters.c32[2]=233;
-       counters.c32[1]=3433;
-       counters.c32[3]=22433;
+       counters.c32[0]=0;
+       counters.c32[2]=0;
+       counters.c32[1]=0;
+       counters.c32[3]=0;
        ACSR|=(1<<ACD);  //Disable Comparator
        ADCSRB|=(1<<ACME); //Disable Analog multiplexer
        MCUCR &=~(1<<PUD); //All Pins Pullup...
@@ -215,6 +215,8 @@ int main(void){
                |(1<<PCINT6)|(1<<PCINT7)
 #endif
        ;
+       
+       
 #ifdef _EEPROM_SAVE_
        DDRA&=~(1<<PINA0);
        PCMSK0|=(1<<PCINT0);
index d86cc1e..fc6996c 100644 (file)
   <PropertyGroup Condition=" '$(Configuration)' == 'Release' ">
     <ToolchainSettings>
       <AvrGcc>
-  <avrgcc.common.Device>-mmcu=attiny84a -B "%24(PackRepoDir)\atmel\ATtiny_DFP\1.0.68\gcc\dev\attiny84a"</avrgcc.common.Device>
-  <avrgcc.common.outputfiles.hex>True</avrgcc.common.outputfiles.hex>
-  <avrgcc.common.outputfiles.lss>True</avrgcc.common.outputfiles.lss>
-  <avrgcc.common.outputfiles.eep>True</avrgcc.common.outputfiles.eep>
-  <avrgcc.common.outputfiles.srec>True</avrgcc.common.outputfiles.srec>
-  <avrgcc.common.outputfiles.usersignatures>False</avrgcc.common.outputfiles.usersignatures>
-  <avrgcc.compiler.general.ChangeDefaultCharTypeUnsigned>True</avrgcc.compiler.general.ChangeDefaultCharTypeUnsigned>
-  <avrgcc.compiler.general.ChangeDefaultBitFieldUnsigned>True</avrgcc.compiler.general.ChangeDefaultBitFieldUnsigned>
-  <avrgcc.compiler.symbols.DefSymbols>
-    <ListValues>
-      <Value>DEBUG</Value>
-    </ListValues>
-  </avrgcc.compiler.symbols.DefSymbols>
-  <avrgcc.compiler.directories.IncludePaths>
-    <ListValues>
-      <Value>%24(PackRepoDir)\atmel\ATtiny_DFP\1.0.68\include</Value>
-    </ListValues>
-  </avrgcc.compiler.directories.IncludePaths>
-  <avrgcc.compiler.optimization.level>Optimize (-O1)</avrgcc.compiler.optimization.level>
-  <avrgcc.compiler.optimization.PackStructureMembers>True</avrgcc.compiler.optimization.PackStructureMembers>
-  <avrgcc.compiler.optimization.AllocateBytesNeededForEnum>True</avrgcc.compiler.optimization.AllocateBytesNeededForEnum>
-  <avrgcc.compiler.optimization.DebugLevel>Default (-g2)</avrgcc.compiler.optimization.DebugLevel>
-  <avrgcc.compiler.warnings.AllWarnings>True</avrgcc.compiler.warnings.AllWarnings>
-  <avrgcc.linker.libraries.Libraries>
-    <ListValues>
-      <Value>libm</Value>
-    </ListValues>
-  </avrgcc.linker.libraries.Libraries>
-  <avrgcc.assembler.debugging.DebugLevel>Default (-Wa,-g)</avrgcc.assembler.debugging.DebugLevel>
-</AvrGcc>
+        <avrgcc.common.Device>-mmcu=attiny84a -B "%24(PackRepoDir)\atmel\ATtiny_DFP\1.0.68\gcc\dev\attiny84a"</avrgcc.common.Device>
+        <avrgcc.common.outputfiles.hex>True</avrgcc.common.outputfiles.hex>
+        <avrgcc.common.outputfiles.lss>True</avrgcc.common.outputfiles.lss>
+        <avrgcc.common.outputfiles.eep>True</avrgcc.common.outputfiles.eep>
+        <avrgcc.common.outputfiles.srec>True</avrgcc.common.outputfiles.srec>
+        <avrgcc.common.outputfiles.usersignatures>False</avrgcc.common.outputfiles.usersignatures>
+        <avrgcc.compiler.general.ChangeDefaultCharTypeUnsigned>True</avrgcc.compiler.general.ChangeDefaultCharTypeUnsigned>
+        <avrgcc.compiler.general.ChangeDefaultBitFieldUnsigned>True</avrgcc.compiler.general.ChangeDefaultBitFieldUnsigned>
+        <avrgcc.compiler.symbols.DefSymbols>
+          <ListValues>
+            <Value>DEBUG</Value>
+          </ListValues>
+        </avrgcc.compiler.symbols.DefSymbols>
+        <avrgcc.compiler.directories.IncludePaths>
+          <ListValues>
+            <Value>%24(PackRepoDir)\atmel\ATtiny_DFP\1.0.68\include</Value>
+          </ListValues>
+        </avrgcc.compiler.directories.IncludePaths>
+        <avrgcc.compiler.optimization.level>Optimize (-O1)</avrgcc.compiler.optimization.level>
+        <avrgcc.compiler.optimization.PackStructureMembers>True</avrgcc.compiler.optimization.PackStructureMembers>
+        <avrgcc.compiler.optimization.AllocateBytesNeededForEnum>True</avrgcc.compiler.optimization.AllocateBytesNeededForEnum>
+        <avrgcc.compiler.optimization.DebugLevel>Default (-g2)</avrgcc.compiler.optimization.DebugLevel>
+        <avrgcc.compiler.warnings.AllWarnings>True</avrgcc.compiler.warnings.AllWarnings>
+        <avrgcc.linker.libraries.Libraries>
+          <ListValues>
+            <Value>libm</Value>
+          </ListValues>
+        </avrgcc.linker.libraries.Libraries>
+        <avrgcc.assembler.debugging.DebugLevel>Default (-Wa,-g)</avrgcc.assembler.debugging.DebugLevel>
+      </AvrGcc>
     </ToolchainSettings>
   </PropertyGroup>
   <PropertyGroup Condition=" '$(Configuration)' == 'Debug' ">
     <ToolchainSettings>
       <AvrGcc>
-  <avrgcc.common.Device>-mmcu=attiny84a -B "%24(PackRepoDir)\atmel\ATtiny_DFP\1.0.68\gcc\dev\attiny84a"</avrgcc.common.Device>
-  <avrgcc.common.outputfiles.hex>True</avrgcc.common.outputfiles.hex>
-  <avrgcc.common.outputfiles.lss>True</avrgcc.common.outputfiles.lss>
-  <avrgcc.common.outputfiles.eep>True</avrgcc.common.outputfiles.eep>
-  <avrgcc.common.outputfiles.srec>True</avrgcc.common.outputfiles.srec>
-  <avrgcc.common.outputfiles.usersignatures>False</avrgcc.common.outputfiles.usersignatures>
-  <avrgcc.compiler.general.ChangeDefaultCharTypeUnsigned>True</avrgcc.compiler.general.ChangeDefaultCharTypeUnsigned>
-  <avrgcc.compiler.general.ChangeDefaultBitFieldUnsigned>True</avrgcc.compiler.general.ChangeDefaultBitFieldUnsigned>
-  <avrgcc.compiler.symbols.DefSymbols>
-    <ListValues>
-      <Value>DEBUG</Value>
-    </ListValues>
-  </avrgcc.compiler.symbols.DefSymbols>
-  <avrgcc.compiler.directories.IncludePaths>
-    <ListValues>
-      <Value>%24(PackRepoDir)\atmel\ATtiny_DFP\1.0.68\include</Value>
-    </ListValues>
-  </avrgcc.compiler.directories.IncludePaths>
-  <avrgcc.compiler.optimization.level>Optimize (-O1)</avrgcc.compiler.optimization.level>
-  <avrgcc.compiler.optimization.PackStructureMembers>True</avrgcc.compiler.optimization.PackStructureMembers>
-  <avrgcc.compiler.optimization.AllocateBytesNeededForEnum>True</avrgcc.compiler.optimization.AllocateBytesNeededForEnum>
-  <avrgcc.compiler.optimization.DebugLevel>Default (-g2)</avrgcc.compiler.optimization.DebugLevel>
-  <avrgcc.compiler.warnings.AllWarnings>True</avrgcc.compiler.warnings.AllWarnings>
-  <avrgcc.linker.libraries.Libraries>
-    <ListValues>
-      <Value>libm</Value>
-    </ListValues>
-  </avrgcc.linker.libraries.Libraries>
-  <avrgcc.assembler.debugging.DebugLevel>Default (-Wa,-g)</avrgcc.assembler.debugging.DebugLevel>
-</AvrGcc>
+        <avrgcc.common.Device>-mmcu=attiny84a -B "%24(PackRepoDir)\atmel\ATtiny_DFP\1.0.68\gcc\dev\attiny84a"</avrgcc.common.Device>
+        <avrgcc.common.outputfiles.hex>True</avrgcc.common.outputfiles.hex>
+        <avrgcc.common.outputfiles.lss>True</avrgcc.common.outputfiles.lss>
+        <avrgcc.common.outputfiles.eep>True</avrgcc.common.outputfiles.eep>
+        <avrgcc.common.outputfiles.srec>True</avrgcc.common.outputfiles.srec>
+        <avrgcc.common.outputfiles.usersignatures>False</avrgcc.common.outputfiles.usersignatures>
+        <avrgcc.compiler.general.ChangeDefaultCharTypeUnsigned>True</avrgcc.compiler.general.ChangeDefaultCharTypeUnsigned>
+        <avrgcc.compiler.general.ChangeDefaultBitFieldUnsigned>True</avrgcc.compiler.general.ChangeDefaultBitFieldUnsigned>
+        <avrgcc.compiler.symbols.DefSymbols>
+          <ListValues>
+            <Value>DEBUG</Value>
+          </ListValues>
+        </avrgcc.compiler.symbols.DefSymbols>
+        <avrgcc.compiler.directories.IncludePaths>
+          <ListValues>
+            <Value>%24(PackRepoDir)\atmel\ATtiny_DFP\1.0.68\include</Value>
+          </ListValues>
+        </avrgcc.compiler.directories.IncludePaths>
+        <avrgcc.compiler.optimization.level>Optimize (-O1)</avrgcc.compiler.optimization.level>
+        <avrgcc.compiler.optimization.PackStructureMembers>True</avrgcc.compiler.optimization.PackStructureMembers>
+        <avrgcc.compiler.optimization.AllocateBytesNeededForEnum>True</avrgcc.compiler.optimization.AllocateBytesNeededForEnum>
+        <avrgcc.compiler.optimization.DebugLevel>Default (-g2)</avrgcc.compiler.optimization.DebugLevel>
+        <avrgcc.compiler.warnings.AllWarnings>True</avrgcc.compiler.warnings.AllWarnings>
+        <avrgcc.linker.libraries.Libraries>
+          <ListValues>
+            <Value>libm</Value>
+          </ListValues>
+        </avrgcc.linker.libraries.Libraries>
+        <avrgcc.assembler.debugging.DebugLevel>Default (-Wa,-g)</avrgcc.assembler.debugging.DebugLevel>
+      </AvrGcc>
     </ToolchainSettings>
   </PropertyGroup>
   <ItemGroup>
-    <Compile Include="DS2423.c">
+    <Compile Include="..\common\OWDS2423.S">
       <SubType>compile</SubType>
+      <Link>OWDS2423.S</Link>
     </Compile>
-    <Compile Include="OWDS2423.S">
+    <Compile Include="DS2423.c">
       <SubType>compile</SubType>
     </Compile>
   </ItemGroup>
diff --git a/DS2423/OWDS2423.S b/DS2423/OWDS2423.S
deleted file mode 100644 (file)
index 47737ca..0000000
+++ /dev/null
@@ -1,337 +0,0 @@
-
-// Copyright (c) 2015, 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. 
-
-#define  _CHANGEABLE_ID_
-#include "../common/OWConfig.s"
-#include "../common/OWCRC16.s"
-
-.extern pack,45
-.extern counters,8
-
-.macro CHIP_INIT       
-.endm
-
-.macro COMMAND_TABLE
-               rjmp h_writescratchpad
-               rjmp h_writescratchpad_crc
-               rjmp h_readscratchpad
-               rjmp h_copyscratchpad
-               rjmp h_readmemory_addr
-               rjmp h_readmemory
-               rjmp h_readmemorycounter_addr
-               rjmp h_readmemorycounter
-               rjmp h_readmemorycounter_ex
-.endm
-
-#include "../common/OWRomFunctions.s"
-#include "../common/OWTimerInterrupt.s"
-
-
-
-; Ab hier Geraeteabhaenging
-#define OW_WRITE_SCRATCHPAD OW_FIRST_COMMAND+0
-#define OW_WRITE_SCRATCHPAD_CRC OW_FIRST_COMMAND+1
-#define OW_READ_SCRATCHPAD OW_FIRST_COMMAND+2
-#define OW_COPY_SCRATCHPAD OW_FIRST_COMMAND+3
-#define OW_READ_MEMORY_ADDR OW_FIRST_COMMAND+4
-#define OW_READ_MEMORY OW_FIRST_COMMAND+5
-#define OW_READ_MEMORYCOUNTER_ADDR OW_FIRST_COMMAND+6
-#define OW_READ_MEMORYCOUNTER OW_FIRST_COMMAND+7
-#define OW_READ_MEMORYCOUNTER_EX OW_FIRST_COMMAND+8
-
-;---------------------------------------------------
-;      READ COMMAND and start operation
-;---------------------------------------------------
-
-
-h_readcommand:
-       clr r_bytep
-#ifndef _DIS_FLASH_
-       FLASH_COMMANDS ; muss zu erst sein....
-#endif
-       cset 0x0F,OW_WRITE_SCRATCHPAD
-       cjmp 0xAA,hrc_set_readscratchpad
-       cset 0x5A,OW_COPY_SCRATCHPAD
-       cset 0xF0,OW_READ_MEMORY_ADDR
-       cset 0xA5,OW_READ_MEMORYCOUNTER_ADDR
-       FW_CONFIG_INFO
-#ifdef _CHANGEABLE_ID_
-       CHANGE_ID_COMMANDS
-#endif
-       ldi r_mode,OW_SLEEP
-       rjmp handle_end
-
-hrc_set_readscratchpad:
-       ldi r_mode,OW_READ_SCRATCHPAD
-       ldi r_sendflag,1
-       rjmp h_readscratchpad
-
-h_writescratchpad:
-       configZ pack,r_bytep
-       inc  r_bytep
-       st   Z,r_rwbyte
-       cpi  r_bytep,2
-       breq h_writescratchpad_block
-       brsh h_writescratchpad_set_eoffset ;;33
-       rjmp handle_end  ;handle_end zu weit entfernt fuer br...
-h_writescratchpad_set_eoffset:
-       cpi  r_bytep,35
-       breq h_writescratchpad_setcrc
-       mov r_temp,r_bytep
-       subi r_temp,4
-       sts pack+2,r_temp ;AA und PF cleared
-       rjmp handle_end
-;Start writeing to 32 Byte Block ; skip status byte    
-h_writescratchpad_block:
-       lds r_temp,pack ; Adresse low byte
-       andi r_temp,0x1F ;32 byte
-       add r_bytep,r_temp ;Zur angegebenen Startadresse springen
-       ;ori r_temp,0x20 ; Set PF flag
-       sts pack+2,r_temp  ;E4:E0 vorher setzen
-       ; Byte 3 ueberspringen
-       rjmp handle_end_inc
-
-h_writescratchpad_setcrc:
-       ;copy crc to pack
-       lds r_temp,crc
-       com r_temp
-       sts pack+43,r_temp
-       lds r_temp,crc+1
-       com r_temp ; invertieren , komischer name.....
-       sts pack+44,r_temp
-       ldi  r_mode,OW_WRITE_SCRATCHPAD_CRC
-       ldi r_sendflag,1
-       ldi r_bytep,43
-h_writescratchpad_crc:
-       cpi r_bytep,45
-       breq h_writescratchpad_crc_end
-       configZ pack,r_bytep
-       ld r_rwbyte,Z
-       rjmp handle_end_inc
-h_writescratchpad_crc_end:
-       rjmp handle_end_sleep
-       
-       
-h_readscratchpad:
-       cpi r_bytep,35
-       breq h_readscratchpad_end
-       cpi r_bytep,3
-       brne h_readscratchpad_read_byte
-h_readscratchpad_set_offset:
-       lds r_temp,pack
-       andi r_temp,0x1F
-       ldi r_temp2,3
-       add r_temp,r_temp2
-       mov r_bytep,r_temp
-h_readscratchpad_read_byte:
-       configZ pack,r_bytep
-       ld r_rwbyte,Z
-       rjmp handle_end_inc
-h_readscratchpad_end:
-       rjmp handle_end_sleep
-
-
-
-h_copyscratchpad:
-       cpi  r_bytep,3
-       brsh h_copyscratchpad_ok
-       configZ pack,r_bytep
-       inc  r_bytep
-       ld   r_temp,Z
-       cp r_temp,r_rwbyte
-       brne h_copyscratchpad_nok
-       cpi  r_bytep,3
-       breq h_copyscratchpad_ok
-       ldi  r_bcount,1 
-       rjmp handle_end
-h_copyscratchpad_ok:
-       ldi r_rwbyte,0xAA
-       ldi r_sendflag,1
-       rjmp handle_end
-h_copyscratchpad_nok:
-       lds r_temp,pack+3
-       andi r_temp,~0x80
-       sts pack+3,r_temp
-       rjmp handle_end_sleep
-
-
-h_readmemory_addr:
-       cpi r_bytep,0
-       brne h_readmrmory_addr_byte1
-       sts pack,r_rwbyte
-       rjmp handle_end_inc
-h_readmrmory_addr_byte1:
-       sts pack+1,r_rwbyte
-       ldi r_mode,OW_READ_MEMORY
-       ldi r_sendflag,1
-       clr r_bytep
-       rjmp h_readmemory2
-h_readmemory:
-       lds r_bytep,pack
-       lds r_temp2,pack+1
-       inc r_bytep
-       clr r_temp
-       adc r_temp2,r_temp
-       sbrc r_temp2,1
-       rjmp h_readmemory_end
-       sts pack+1,r_temp
-       sts pack,r_bytep
-h_readmemory2:
-       lds r_bytep,pack
-       andi r_bytep,0x1F
-       configZ pack+3,r_bytep
-       ld   r_rwbyte,Z
-       rjmp handle_end
-h_readmemory_end:
-       rjmp handle_end_sleep
-
-
-
-
-
-
-
-
-h_readmemorycounter_addr:
-       cpi r_bytep,0
-       brne h_readmrmorycounter_addr_byte1
-       sts pack,r_rwbyte
-       inc r_bytep
-       ;ldi r_bcount,1
-       rjmp handle_end
-h_readmrmorycounter_addr_byte1:
-       sts pack+1,r_rwbyte
-       ldi r_mode,OW_READ_MEMORYCOUNTER
-       ;ldi r_bcount,1 
-       ldi r_sendflag,1
-       clr r_bytep
-       rjmp h_readmemorycounter2
-h_readmemorycounter:
-       lds r_bytep,pack
-       lds r_temp2,pack+1
-       ldi r_temp,1  ;inc leider kein c flag
-       add r_bytep,r_temp
-       clr r_temp
-       adc r_temp2,r_temp
-       mov r_temp,r_bytep
-       andi r_temp,0x1F
-       breq h_readmemorycounter_next
-       sts pack+1,r_temp2
-       sts pack,r_bytep
-h_readmemorycounter2:  ;Lesen von dem worauf die erstenzwei bytes zeigen
-       lds r_bytep,pack
-       andi r_bytep,0x1F
-       configZ pack+3,r_bytep
-       ld   r_rwbyte,Z
-       ;ldi r_bcount,1
-       rjmp handle_end
-//h_readmemorycounter_end:
-//     ldi  r_mode,OW_SLEEP
-//     clr r_sendflag
-//     rjmp handle_end
-h_readmemorycounter_next:  ; rest lesen
-       ldi  r_mode,OW_READ_MEMORYCOUNTER_EX
-       ldi r_bytep,34
-       lds r_temp2,pack
-       lds r_temp,pack+1
-       //lsr r_temp
-       //ror r_temp2
-
-       lsl r_temp2
-       rol r_temp
-       cpi r_temp,3
-       brne h_readmemorycounter_cFF
-       andi r_temp2,0xC0
-       swap r_temp2
-
-       ;cpi r_temp,0xE0
-
-       configZ counters,r_temp2
-       ld r_temp,Z+
-       sts pack+35,r_temp      
-       ld r_temp,Z+
-       sts pack+36,r_temp      
-       ld r_temp,Z+
-       sts pack+37,r_temp      
-       ld r_temp,Z+
-       sts pack+38,r_temp      
-       rjmp h_readmemorycounter_ex
-h_readmemorycounter_cFF:
-       ldi r_temp,0xFF
-       sts pack+35,r_temp      
-       sts pack+36,r_temp      
-       sts pack+37,r_temp      
-       sts pack+38,r_temp      
-
-h_readmemorycounter_ex:
-       inc r_bytep
-       cpi r_bytep,45
-       breq h_readmemorycounter_ex_end
-       cpi r_bytep,43
-       brne h_readmemorycounter_ex2
-       lds r_temp,crc
-       com r_temp
-       sts pack+43,r_temp
-       lds r_temp,crc+1
-       com r_temp
-       sts pack+44,r_temp
-h_readmemorycounter_ex2:
-       ;ldi r_bcount,1
-       configZ pack,r_bytep
-       ld   r_rwbyte,Z
-       rjmp handle_end
-h_readmemorycounter_ex_end:
-       lds r_bytep,pack
-       lds r_temp2,pack+1
-       ldi r_temp,1  ;inc leider kein c flag
-       add r_bytep,r_temp
-       clr r_temp
-       adc r_temp2,r_temp
-       sbrc r_temp2,1 ;am ene von allem 
-       rjmp h_readmemorycounter_ex_sleep
-       CRCInit1
-       ldi  r_mode,OW_READ_MEMORYCOUNTER
-       sts pack+1,r_temp2
-       sts pack,r_bytep
-       rjmp h_readmemorycounter2
-h_readmemorycounter_ex_sleep:
-       ldi r_mode,OW_SLEEP
-       clr r_sendflag
-       rjmp handle_end
-
-
-
-       
-
-#include "../common/OWPinInterrupt.s"
-.end
\ No newline at end of file
diff --git a/DS2438_DHT22/DS2438_DHT22 - Kopie.c b/DS2438_DHT22/DS2438_DHT22 - Kopie.c
new file mode 100644 (file)
index 0000000..bbd175c
--- /dev/null
@@ -0,0 +1,444 @@
+// Copyright (c) 2015, 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.
+
+
+#define F_CPU 8000000UL
+#define FP_CALC
+#include <avr/io.h>
+#include <avr/interrupt.h>
+#include <util/delay.h>
+#include <avr/wdt.h>
+#include <avr/sleep.h>
+
+extern void OWINIT();
+
+
+uint8_t owid[8]={0x26, 0xA2, 0xD9, 0x84, 0xDD, 0xDD, 0x05, 0xCE};/**/
+uint8_t config_info[16]={0x01,0x06, 0x05,0x08, 0x04,0x07, 0x00,0x00, 0x01,0x00,0x00,0x00,0x00,0x00,0x00,0x00};
+       
+
+extern uint8_t mode;
+extern uint8_t gcontrol;
+extern uint8_t reset_indicator;
+extern uint8_t alarmflag;
+
+volatile uint8_t wdcounter;
+
+
+typedef union {
+#if  defined(__AVR_ATtiny25__)
+       volatile uint8_t bytes[16];
+#else
+       volatile uint8_t bytes[64];
+#endif
+       struct {
+               uint8_t status;  //1
+               int16_t temp;  //2
+               uint16_t voltage;  //4
+               uint16_t current;  //6
+               uint8_t threshold; //8
+               
+               uint8_t page1[8]; //9
+#if  defined(__AVR_ATtiny25__)
+#else
+               uint8_t page2[8]; //17
+               uint8_t page3[8]; //25
+               uint8_t page4[8];  //33
+               uint8_t page5[8];  //41
+               uint8_t page6[8];  //49
+               uint8_t page7[8];  //57
+               //uint8_t crc;  //65
+#endif
+       };
+} pack_t;
+volatile pack_t pack;
+
+#if  defined(__AVR_ATtiny25__)||defined(__AVR_ATtiny45__)  || defined(__AVR_ATtiny85__)
+
+#define DDR_SENSOR   DDRB 
+#define PORT_SENSOR  PORTB
+#define PIN_SENSOR   PINB
+#define SENSOR       PB4
+#endif
+
+#if  defined(__AVR_ATtiny24__)||defined(__AVR_ATtiny44__)  || defined(__AVR_ATtiny84__) || defined(__AVR_ATtiny24A__)||defined(__AVR_ATtiny44A__)  || defined(__AVR_ATtiny84A__)
+#define DDR_SENSOR   DDRA
+#define PORT_SENSOR  PORTA
+#define PIN_SENSOR   PINA
+#define SENSOR       PINA2
+#endif
+
+
+
+#define SENSOR_sda_out         DDR_SENSOR |= (1 << SENSOR)
+#define SENSOR_sda_in                  DDR_SENSOR &= ~(1 << SENSOR);PORT_SENSOR |= (1 << SENSOR) // release sda => hi in consequence of pullup
+#define SENSOR_sda_low    PORT_SENSOR &= ~(1 << SENSOR)
+#define SENSOR_is_hi                   PIN_SENSOR & (1 << SENSOR)
+#define SENSOR_is_low          !(PIN_SENSOR & (1 << SENSOR))
+
+volatile int16_t am2302_temp;
+volatile uint16_t am2302_hum;
+
+
+uint8_t am_wait(uint8_t _time,uint8_t _signal){
+       TCNT1=0;
+       while(TCNT1==0);
+       if (_signal) 
+               while((SENSOR_is_hi)&&(TCNT1<_time)) {}
+       else
+               while((SENSOR_is_low)&&(TCNT1<_time)) {}
+        
+               if (TCNT1>=_time) {return 1;}
+       return 0;
+}
+
+volatile uint8_t am2302_mode=0;        
+volatile uint8_t timeout=0;
+
+
+
+#if  defined(__AVR_ATtiny24__)||defined(__AVR_ATtiny44__)  || defined(__AVR_ATtiny84__) || defined(__AVR_ATtiny24A__)||defined(__AVR_ATtiny44A__)  || defined(__AVR_ATtiny84A__)
+ISR(WATCHDOG_vect) {
+#else
+ISR(WDT_vect) {
+#endif 
+       sleep_disable();          // Disable Sleep on Wakeup
+       am2302_mode++;
+       if (reset_indicator==1) reset_indicator++;
+       else if (reset_indicator==2) mode=0;
+/*     if (timeout==2) {
+               DIS_TIMER;
+               EN_OWINT;
+               mode=OWM_SLEEP;
+       }
+       timeout++;*/
+       sleep_enable();           // Enable Sleep Mode
+
+}
+
+int testSW() {
+       uint8_t r;
+       DDRB&=~(1<<PORTB0);  //Eingang
+       __asm__ __volatile__ ("nop");
+       PORTB|=(1<<PORTB0); //Pullup
+       __asm__ __volatile__ ("nop");
+       __asm__ __volatile__ ("nop");
+       __asm__ __volatile__ ("nop");
+       __asm__ __volatile__ ("nop");
+       __asm__ __volatile__ ("nop");
+       r=PINB&(1<<PORTB0);
+       __asm__ __volatile__ ("nop");
+       PORTB&=~(1<<PORTB0);
+       __asm__ __volatile__ ("nop");
+       DDRB|=(1<<PORTB0);  //Eingang
+       return (r==0);
+       
+       
+}      
+       
+uint8_t am2302_1() {
+       int16_t lam2302_temp;
+       uint16_t lam2302_hum;
+       uint8_t rSREG;
+       uint8_t sensor_data[5];
+#if  defined(__AVR_ATtiny25__)||defined(__AVR_ATtiny45__)  || defined(__AVR_ATtiny85__)
+       TCCR1=(1<<CS12); //Clock/8 1µs
+#endif
+
+#if  defined(__AVR_ATtiny24__)||defined(__AVR_ATtiny44__)  || defined(__AVR_ATtiny84__) || defined(__AVR_ATtiny24A__)||defined(__AVR_ATtiny44A__)  || defined(__AVR_ATtiny84A__)
+       TCCR1B=(1<<CS11); //Clock/8 1µs
+#endif
+       SENSOR_sda_out;
+       SENSOR_sda_low; // MCU start signal
+       TCNT1=0;while(TCNT1==0);while(TCNT1<250) {}// start signal (pull sda down for min 0.8ms and maximum 20ms)
+       TCNT1=0;while(TCNT1==0);while(TCNT1<250) {}// start signal (pull sda down for min 0.8ms and maximum 20ms)
+       SENSOR_sda_in;
+       if (am_wait(200,1)) return 2;
+
+       // AM2302 response signal min: 75us typ:80us max:85us
+       if (am_wait(100,0)) return 3;
+       if (am_wait(100,1)) return 4;
+       
+       for(uint8_t i = 0; i < 5; i++)  {
+               uint8_t sensor_byte = 0;
+               for(uint8_t j = 1; j <= 8; j++) {// get 8 bits from sensor
+                       if (am_wait(88,0)) return 5;
+                       
+                       TCNT1=0;while(TCNT1==0);;while(TCNT1<35)                ;
+                       sensor_byte <<= 1; // add new lower byte
+                       if (SENSOR_is_hi) {// if sda high after 30us => bit=1 else bit=0
+                               sensor_byte |= 1;
+                               if (am_wait(45,1)) return 6;// 30us - 75us = 45us
+                       }
+               }
+               sensor_data[i] = sensor_byte;
+       }
+
+       // checksum
+       if ( ((sensor_data[0]+sensor_data[1]+sensor_data[2]+sensor_data[3]) & 0xff ) != sensor_data[4])
+       {
+               // debug output
+               //printf("%b %b %b %b %b %b" CR, sensor_data[0], sensor_data[1], sensor_data[2], sensor_data[3], sensor_data[4], ((sensor_data[0]+sensor_data[1]+sensor_data[2]+sensor_data[3]) & 0xff ));
+               PORTB&=~(1<<PINB0);
+               return 7;
+       }
+       if (!testSW()) {
+#ifdef FP_CALC
+       double htemp;
+       if (sensor_data[2]&0x80) { //min
+               sensor_data[2]&=~(0x80);
+               htemp=-((sensor_data[2]<<8) + sensor_data[3]);
+       } else
+               htemp=((sensor_data[2]<<8) + sensor_data[3]);
+       double hhum=(1.0546-0.000216*htemp)*((sensor_data[0]<<8) + sensor_data[1]);
+       
+       lam2302_hum=0.318*hhum +76;
+       lam2302_temp=htemp*25.6;
+#else
+
+       if (sensor_data[2]&0x80) { //minus
+               sensor_data[2]&=~(0x80);
+               lam2302_temp=-((sensor_data[2]<<8) + sensor_data[3]);
+       } else
+               lam2302_temp=((sensor_data[2]<<8) + sensor_data[3]);
+       
+       lam2302_hum=((sensor_data[0]<<8) + sensor_data[1]);
+       volatile uint32_t h1=lam2302_temp*lam2302_hum*3/44803;
+       lam2302_hum=lam2302_hum*16/49-h1+80;
+       //lam2302_temp=lam2302_temp*128/5;
+
+       int16_t h2=lam2302_temp%5;
+       lam2302_temp=lam2302_temp/5;
+       lam2302_temp*=128;
+       lam2302_temp+=h2*128/5;
+#endif    
+       config_info[5]=7;
+       }
+       else {
+               if (sensor_data[2]&0x80) { //minus
+                       sensor_data[2]&=~(0x80);
+                       lam2302_temp=-((sensor_data[2]<<8) + sensor_data[3]);
+               } else
+               lam2302_temp=((sensor_data[2]<<8) + sensor_data[3])*25.6;;
+               
+               lam2302_hum=((sensor_data[0]<<8) + sensor_data[1]);
+               config_info[5]=12;
+       }
+       rSREG=SREG;
+       cli();
+       am2302_hum=lam2302_hum;
+       am2302_temp=lam2302_temp;
+       SREG=rSREG;
+       return 0;
+}
+
+
+uint8_t am2302_2() { //4mhz
+       int16_t lam2302_temp;
+       uint16_t lam2302_hum;
+       uint8_t rSREG;
+       uint8_t sensor_data[5];
+       #if  defined(__AVR_ATtiny25__)||defined(__AVR_ATtiny45__)  || defined(__AVR_ATtiny85__)
+       TCCR1=(1<<CS11)|(1<<CS10); //Clock/8 1µs
+       #endif
+
+       #if  defined(__AVR_ATtiny24__)||defined(__AVR_ATtiny44__)  || defined(__AVR_ATtiny84__) || defined(__AVR_ATtiny24A__)||defined(__AVR_ATtiny44A__)  || defined(__AVR_ATtiny84A__)
+       TCCR1B=(1<<CS11); //Clock/8 1µs
+       #endif
+       SENSOR_sda_out;
+       SENSOR_sda_low; // MCU start signal
+       TCNT1=0;while(TCNT1==0);while(TCNT1<250) {}// start signal (pull sda down for min 0.8ms and maximum 20ms)
+       TCNT1=0;while(TCNT1==0);while(TCNT1<250) {}// start signal (pull sda down for min 0.8ms and maximum 20ms)
+       SENSOR_sda_in;
+       if (am_wait(200,1)) return 2;
+
+       // AM2302 response signal min: 75us typ:80us max:85us
+       if (am_wait(100,0)) return 3;
+       if (am_wait(100,1)) return 4;
+       
+       for(uint8_t i = 0; i < 5; i++)  {
+               uint8_t sensor_byte = 0;
+               for(uint8_t j = 1; j <= 8; j++) {// get 8 bits from sensor
+                       if (am_wait(88,0)) return 5;
+                       
+                       TCNT1=0;while(TCNT1==0);;while(TCNT1<35)                ;
+                       sensor_byte <<= 1; // add new lower byte
+                       if (SENSOR_is_hi) {// if sda high after 30us => bit=1 else bit=0
+                               sensor_byte |= 1;
+                               if (am_wait(45,1)) return 6;// 30us - 75us = 45us
+                       }
+               }
+               sensor_data[i] = sensor_byte;
+       }
+
+       // checksum
+       if ( ((sensor_data[0]+sensor_data[1]+sensor_data[2]+sensor_data[3]) & 0xff ) != sensor_data[4])
+       {
+               // debug output
+               //printf("%b %b %b %b %b %b" CR, sensor_data[0], sensor_data[1], sensor_data[2], sensor_data[3], sensor_data[4], ((sensor_data[0]+sensor_data[1]+sensor_data[2]+sensor_data[3]) & 0xff ));
+               PORTB&=~(1<<PINB0);
+               return 7;
+       }
+#ifdef FP_CALC
+       lam2302_hum=0.318* ((sensor_data[0]<<8) + sensor_data[1])+76;
+       if (sensor_data[2]&0x80) { //minus
+               sensor_data[2]&=~(0x80);
+               lam2302_temp=-((sensor_data[2]<<8) + sensor_data[3])*25.6;
+       } else
+               lam2302_temp=((sensor_data[2]<<8) + sensor_data[3])*25.6;
+#else
+
+
+       if (sensor_data[2]&0x80) { //minus
+               sensor_data[2]&=~(0x80);
+               lam2302_temp=-((sensor_data[2]<<8) + sensor_data[3]);
+       } else
+       lam2302_temp=((sensor_data[2]<<8) + sensor_data[3]);
+       
+       lam2302_hum=((sensor_data[0]<<8) + sensor_data[1]);
+       volatile uint32_t h1=lam2302_temp*lam2302_hum*3/44803;
+       lam2302_hum=lam2302_hum*16/49-h1+80;
+       //lam2302_temp=lam2302_temp*128/5;
+
+       int16_t h2=lam2302_temp%5;
+       lam2302_temp=lam2302_temp/5;
+       lam2302_temp*=128;
+       lam2302_temp+=h2*128/5;
+#endif 
+       
+       
+       rSREG=SREG;
+       cli();
+       am2302_hum=lam2302_hum;
+       am2302_temp=lam2302_temp;
+       SREG=rSREG;
+       return 0;
+}
+
+
+
+int main(void){
+    PRR|=(1<<PRUSI)|(1<<PRADC);  //Switch off usi and adc for save Power
+#if  defined(__AVR_ATtiny24__)||defined(__AVR_ATtiny44__)  || defined(__AVR_ATtiny84__) || defined(__AVR_ATtiny24A__)||defined(__AVR_ATtiny44A__)  || defined(__AVR_ATtiny84A__)
+       PORTA=0xFF;
+       PORTB=0xFF-(1<<PORTB0); //Schalter kann gegen Masse sein und zieht dann immer Strom
+       DDRB|=(1<<PORTB0); //Als Ausgang und 0
+#endif
+       OWINIT();
+
+       ACSR|=(1<<ACD);  //Disable Comparator
+       ADCSRB|=(1<<ACME); //Disable Analog multiplexer
+       MCUCR &=~(1<<PUD); //All Pins Pullup...
+       MCUCR |=(1<<BODS);
+       MCUCR &=~(1<<PUD);
+       
+#if  defined(__AVR_ATtiny25__)||defined(__AVR_ATtiny45__)  || defined(__AVR_ATtiny85__)
+
+       PORTB|=(1<<PINB0)|(1<<PINB1)|(1<<PINB3)|(1<<PINB4)|(1<<PINB5);
+       DDRB|=(1<<PINB1); //DBLINE
+#define SENSON PORTB|=(1<<PINB0);
+#define SENSOFF PORTB&=~(1<<PINB0);
+       DDRB|=(1<<PINB0); //stromversorgung
+       
+       // Set up Watch Dog Timer for Inactivity
+       WDTCR |= ((1<<WDCE) | (1<<WDE));   // Enable the WD Change Bit
+       WDTCR =   (1<<WDIE) |              // Enable WDT Interrupt
+       (1<<WDP2) | (1<<WDP1);   // Set Timeout to ~2 seconds
+#endif
+
+#if  defined(__AVR_ATtiny24__)||defined(__AVR_ATtiny44__)  || defined(__AVR_ATtiny84__) || defined(__AVR_ATtiny24A__)||defined(__AVR_ATtiny44A__)  || defined(__AVR_ATtiny84A__)
+
+
+       DDRA|=(1<<PINA1); //stromversorgung
+#define SENSON PORTA|=(1<<PINA1);
+#define SENSOFF PORTA&=~(1<<PINA1);
+
+       // Set up Watch Dog Timer for Inactivity
+       WDTCSR |= (1<<WDCE) ;   // Enable the WD Change Bit
+       WDTCSR =   (1<<WDIE) |              // Enable WDT Interrupt
+       (1<<WDP2) | (1<<WDP1);   // Set Timeout to ~2 seconds
+#endif
+
+       
+    uint8_t i;
+       uint8_t err;
+#if  defined(__AVR_ATtiny25__)
+    for(i=0;i<16;i++) pack.bytes[i]=0;
+#else
+       uint8_t pn=1;
+    for(i=0;i<64;i++) pack.bytes[i]=0;
+#endif
+       //pack.bytes[0]=1;
+       //pack.bytes[1]=2;
+       SENSON
+       _delay_ms(4000);
+       err =am2302_1();
+       sei();
+    while(1)   {
+               alarmflag=1;
+               if (am2302_mode==2) {
+                       err=am2302_1();
+                       if (err!=0) {
+#if  defined(__AVR_ATtiny25__)
+#else
+                               pack.page3[pn]=err;
+                               pn=pn+1;if (pn>31) pn=1;
+#endif
+                       }
+                       SENSOFF
+                       am2302_mode=3;
+               }
+               if (am2302_mode>=8) {
+                       am2302_mode=0;
+                       SENSON
+               }
+#if  defined(__AVR_ATtiny25__)||defined(__AVR_ATtiny45__)  || defined(__AVR_ATtiny85__)
+                       if (((TIMSK & (1<<TOIE0))==0)&& (mode==0))
+#endif                 
+#if  defined(__AVR_ATtiny24__)||defined(__AVR_ATtiny44__)  || defined(__AVR_ATtiny84__) || defined(__AVR_ATtiny24A__)||defined(__AVR_ATtiny44A__)  || defined(__AVR_ATtiny84A__)
+                       if (((TIMSK0 & (1<<TOIE0))==0)&& (mode==0))
+#endif
+                         {
+//                     CLKPR=(1<<CLKPCE);
+       //              CLKPR=(1<<CLKPS2); /*0.5Mhz*/
+                       //PORTB&=~(1<<PINB1);
+                       MCUCR|=(1<<SE)|(1<<SM1);
+                       MCUCR&=~(1<<ISC01);
+               } else {
+                       MCUCR|=(1<<SE);
+                       MCUCR&=~(1<<SM1);
+               }
+               asm("SLEEP");
+   }
+
+
+}
\ No newline at end of file
index 3fadddd..93b2372 100644 (file)
     <ExternalProgrammingToolCommand />
     <AsfFrameworkConfig>
       <framework-data xmlns="">
-  <options />
-  <configurations />
-  <files />
-  <documentation help="" />
-  <offline-documentation help="" />
-  <dependencies>
-    <content-extension eid="atmel.asf" uuidref="Atmel.ASF" version="3.27.3" />
-  </dependencies>
-</framework-data>
+        <options />
+        <configurations />
+        <files />
+        <documentation help="" />
+        <offline-documentation help="" />
+        <dependencies>
+          <content-extension eid="atmel.asf" uuidref="Atmel.ASF" version="3.27.3" />
+        </dependencies>
+      </framework-data>
     </AsfFrameworkConfig>
     <avrtool>com.atmel.avrdbg.tool.atmelice</avrtool>
     <avrtoolserialnumber>J41800000789</avrtoolserialnumber>
   <PropertyGroup Condition=" '$(Configuration)' == 'Release' ">
     <ToolchainSettings>
       <AvrGcc>
-  <avrgcc.common.Device>-mmcu=attiny84a -B "%24(PackRepoDir)\atmel\ATtiny_DFP\1.0.68\gcc\dev\attiny84a"</avrgcc.common.Device>
-  <avrgcc.common.outputfiles.hex>True</avrgcc.common.outputfiles.hex>
-  <avrgcc.common.outputfiles.lss>True</avrgcc.common.outputfiles.lss>
-  <avrgcc.common.outputfiles.eep>True</avrgcc.common.outputfiles.eep>
-  <avrgcc.common.outputfiles.srec>True</avrgcc.common.outputfiles.srec>
-  <avrgcc.common.outputfiles.usersignatures>False</avrgcc.common.outputfiles.usersignatures>
-  <avrgcc.compiler.general.ChangeDefaultCharTypeUnsigned>True</avrgcc.compiler.general.ChangeDefaultCharTypeUnsigned>
-  <avrgcc.compiler.general.ChangeDefaultBitFieldUnsigned>True</avrgcc.compiler.general.ChangeDefaultBitFieldUnsigned>
-  <avrgcc.compiler.symbols.DefSymbols>
-    <ListValues>
-      <Value>NDEBUG</Value>
-    </ListValues>
-  </avrgcc.compiler.symbols.DefSymbols>
-  <avrgcc.compiler.directories.IncludePaths>
-    <ListValues>
-      <Value>%24(PackRepoDir)\atmel\ATtiny_DFP\1.0.68\include</Value>
-    </ListValues>
-  </avrgcc.compiler.directories.IncludePaths>
-  <avrgcc.compiler.optimization.level>Optimize for size (-Os)</avrgcc.compiler.optimization.level>
-  <avrgcc.compiler.optimization.PackStructureMembers>True</avrgcc.compiler.optimization.PackStructureMembers>
-  <avrgcc.compiler.optimization.AllocateBytesNeededForEnum>True</avrgcc.compiler.optimization.AllocateBytesNeededForEnum>
-  <avrgcc.compiler.warnings.AllWarnings>True</avrgcc.compiler.warnings.AllWarnings>
-  <avrgcc.linker.libraries.Libraries>
-    <ListValues>
-      <Value>libm</Value>
-    </ListValues>
-  </avrgcc.linker.libraries.Libraries>
-</AvrGcc>
+        <avrgcc.common.Device>-mmcu=attiny84a -B "%24(PackRepoDir)\atmel\ATtiny_DFP\1.0.68\gcc\dev\attiny84a"</avrgcc.common.Device>
+        <avrgcc.common.outputfiles.hex>True</avrgcc.common.outputfiles.hex>
+        <avrgcc.common.outputfiles.lss>True</avrgcc.common.outputfiles.lss>
+        <avrgcc.common.outputfiles.eep>True</avrgcc.common.outputfiles.eep>
+        <avrgcc.common.outputfiles.srec>True</avrgcc.common.outputfiles.srec>
+        <avrgcc.common.outputfiles.usersignatures>False</avrgcc.common.outputfiles.usersignatures>
+        <avrgcc.compiler.general.ChangeDefaultCharTypeUnsigned>True</avrgcc.compiler.general.ChangeDefaultCharTypeUnsigned>
+        <avrgcc.compiler.general.ChangeDefaultBitFieldUnsigned>True</avrgcc.compiler.general.ChangeDefaultBitFieldUnsigned>
+        <avrgcc.compiler.symbols.DefSymbols>
+          <ListValues>
+            <Value>NDEBUG</Value>
+          </ListValues>
+        </avrgcc.compiler.symbols.DefSymbols>
+        <avrgcc.compiler.directories.IncludePaths>
+          <ListValues>
+            <Value>%24(PackRepoDir)\atmel\ATtiny_DFP\1.0.68\include</Value>
+          </ListValues>
+        </avrgcc.compiler.directories.IncludePaths>
+        <avrgcc.compiler.optimization.level>Optimize for size (-Os)</avrgcc.compiler.optimization.level>
+        <avrgcc.compiler.optimization.PackStructureMembers>True</avrgcc.compiler.optimization.PackStructureMembers>
+        <avrgcc.compiler.optimization.AllocateBytesNeededForEnum>True</avrgcc.compiler.optimization.AllocateBytesNeededForEnum>
+        <avrgcc.compiler.warnings.AllWarnings>True</avrgcc.compiler.warnings.AllWarnings>
+        <avrgcc.linker.libraries.Libraries>
+          <ListValues>
+            <Value>libm</Value>
+          </ListValues>
+        </avrgcc.linker.libraries.Libraries>
+      </AvrGcc>
     </ToolchainSettings>
   </PropertyGroup>
   <PropertyGroup Condition=" '$(Configuration)' == 'Debug' ">
     <ToolchainSettings>
       <AvrGcc>
-  <avrgcc.common.Device>-mmcu=attiny84a -B "%24(PackRepoDir)\atmel\ATtiny_DFP\1.0.68\gcc\dev\attiny84a"</avrgcc.common.Device>
-  <avrgcc.common.outputfiles.hex>True</avrgcc.common.outputfiles.hex>
-  <avrgcc.common.outputfiles.lss>True</avrgcc.common.outputfiles.lss>
-  <avrgcc.common.outputfiles.eep>True</avrgcc.common.outputfiles.eep>
-  <avrgcc.common.outputfiles.srec>True</avrgcc.common.outputfiles.srec>
-  <avrgcc.common.outputfiles.usersignatures>False</avrgcc.common.outputfiles.usersignatures>
-  <avrgcc.compiler.general.ChangeDefaultCharTypeUnsigned>True</avrgcc.compiler.general.ChangeDefaultCharTypeUnsigned>
-  <avrgcc.compiler.general.ChangeDefaultBitFieldUnsigned>True</avrgcc.compiler.general.ChangeDefaultBitFieldUnsigned>
-  <avrgcc.compiler.symbols.DefSymbols>
-    <ListValues>
-      <Value>DEBUG</Value>
-    </ListValues>
-  </avrgcc.compiler.symbols.DefSymbols>
-  <avrgcc.compiler.directories.IncludePaths>
-    <ListValues>
-      <Value>%24(PackRepoDir)\atmel\ATtiny_DFP\1.0.68\include</Value>
-    </ListValues>
-  </avrgcc.compiler.directories.IncludePaths>
-  <avrgcc.compiler.optimization.level>Optimize (-O1)</avrgcc.compiler.optimization.level>
-  <avrgcc.compiler.optimization.PackStructureMembers>True</avrgcc.compiler.optimization.PackStructureMembers>
-  <avrgcc.compiler.optimization.AllocateBytesNeededForEnum>True</avrgcc.compiler.optimization.AllocateBytesNeededForEnum>
-  <avrgcc.compiler.optimization.DebugLevel>Default (-g2)</avrgcc.compiler.optimization.DebugLevel>
-  <avrgcc.compiler.warnings.AllWarnings>True</avrgcc.compiler.warnings.AllWarnings>
-  <avrgcc.linker.libraries.Libraries>
-    <ListValues>
-      <Value>libm</Value>
-    </ListValues>
-  </avrgcc.linker.libraries.Libraries>
-  <avrgcc.assembler.debugging.DebugLevel>Default (-Wa,-g)</avrgcc.assembler.debugging.DebugLevel>
-</AvrGcc>
+        <avrgcc.common.Device>-mmcu=attiny84a -B "%24(PackRepoDir)\atmel\ATtiny_DFP\1.0.68\gcc\dev\attiny84a"</avrgcc.common.Device>
+        <avrgcc.common.outputfiles.hex>True</avrgcc.common.outputfiles.hex>
+        <avrgcc.common.outputfiles.lss>True</avrgcc.common.outputfiles.lss>
+        <avrgcc.common.outputfiles.eep>True</avrgcc.common.outputfiles.eep>
+        <avrgcc.common.outputfiles.srec>True</avrgcc.common.outputfiles.srec>
+        <avrgcc.common.outputfiles.usersignatures>False</avrgcc.common.outputfiles.usersignatures>
+        <avrgcc.compiler.general.ChangeDefaultCharTypeUnsigned>True</avrgcc.compiler.general.ChangeDefaultCharTypeUnsigned>
+        <avrgcc.compiler.general.ChangeDefaultBitFieldUnsigned>True</avrgcc.compiler.general.ChangeDefaultBitFieldUnsigned>
+        <avrgcc.compiler.symbols.DefSymbols>
+          <ListValues>
+            <Value>DEBUG</Value>
+          </ListValues>
+        </avrgcc.compiler.symbols.DefSymbols>
+        <avrgcc.compiler.directories.IncludePaths>
+          <ListValues>
+            <Value>%24(PackRepoDir)\atmel\ATtiny_DFP\1.0.68\include</Value>
+          </ListValues>
+        </avrgcc.compiler.directories.IncludePaths>
+        <avrgcc.compiler.optimization.level>Optimize (-O1)</avrgcc.compiler.optimization.level>
+        <avrgcc.compiler.optimization.PackStructureMembers>True</avrgcc.compiler.optimization.PackStructureMembers>
+        <avrgcc.compiler.optimization.AllocateBytesNeededForEnum>True</avrgcc.compiler.optimization.AllocateBytesNeededForEnum>
+        <avrgcc.compiler.optimization.DebugLevel>Default (-g2)</avrgcc.compiler.optimization.DebugLevel>
+        <avrgcc.compiler.warnings.AllWarnings>True</avrgcc.compiler.warnings.AllWarnings>
+        <avrgcc.linker.libraries.Libraries>
+          <ListValues>
+            <Value>libm</Value>
+          </ListValues>
+        </avrgcc.linker.libraries.Libraries>
+        <avrgcc.assembler.debugging.DebugLevel>Default (-Wa,-g)</avrgcc.assembler.debugging.DebugLevel>
+      </AvrGcc>
     </ToolchainSettings>
   </PropertyGroup>
   <ItemGroup>
diff --git a/DS2438_HIH9121/DS2438_9121.atsln b/DS2438_HIH9121/DS2438_9121.atsln
new file mode 100644 (file)
index 0000000..453b0e3
--- /dev/null
@@ -0,0 +1,22 @@
+
+Microsoft Visual Studio Solution File, Format Version 12.00
+# Atmel Studio Solution File, Format Version 11.00
+VisualStudioVersion = 14.0.23107.0
+MinimumVisualStudioVersion = 10.0.40219.1
+Project("{54F91283-7BC4-4236-8FF9-10F437C3AD48}") = "DS2438_HIH9121", "DS2438_HIH9121.cproj", "{91468D4F-8AE2-4C59-8A35-549C49E00934}"
+EndProject
+Global
+       GlobalSection(SolutionConfigurationPlatforms) = preSolution
+               Debug|AVR = Debug|AVR
+               Release|AVR = Release|AVR
+       EndGlobalSection
+       GlobalSection(ProjectConfigurationPlatforms) = postSolution
+               {91468D4F-8AE2-4C59-8A35-549C49E00934}.Debug|AVR.ActiveCfg = Debug|AVR
+               {91468D4F-8AE2-4C59-8A35-549C49E00934}.Debug|AVR.Build.0 = Debug|AVR
+               {91468D4F-8AE2-4C59-8A35-549C49E00934}.Release|AVR.ActiveCfg = Release|AVR
+               {91468D4F-8AE2-4C59-8A35-549C49E00934}.Release|AVR.Build.0 = Release|AVR
+       EndGlobalSection
+       GlobalSection(SolutionProperties) = preSolution
+               HideSolutionNode = FALSE
+       EndGlobalSection
+EndGlobal
diff --git a/DS2438_HIH9121/DS2438_HIH9121.c b/DS2438_HIH9121/DS2438_HIH9121.c
new file mode 100644 (file)
index 0000000..a7e115c
--- /dev/null
@@ -0,0 +1,227 @@
+// Copyright (c) 2015, 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.
+
+
+#define F_CPU 8000000UL
+#include <avr/io.h>
+#include <avr/interrupt.h>
+#include <util/delay.h>
+#include <avr/wdt.h>
+#include <avr/sleep.h>
+#include <avr/pgmspace.h>
+#include "../common/I2C/USI_TWI_Master.h"
+#include "../common/I2C/MAX44009.h"
+#include "../common/I2C/SHT2x.h"
+
+extern void OWINIT();
+extern void EXTERN_SLEEP();
+
+uint8_t owid[8]={0x26, 0xA2, 0xD9, 0x84, 0x00, 0x00, 0x05, 0x16};/**/
+uint8_t config_info[16]={0x01,0x06, 0x05,0x08, 0x04,0x07, 0x00,0x00, 0x01,0x00,0x00,0x00,0x00,0x00,0x00,0x00};
+//uint8_t config_info[16]={0x01,0x06, 0x05,0x08, 0x04,0x08, 0x00,0x00, 0x01,0x00,0x00,0x00,0x00,0x00,0x00,0x00};
+       
+
+extern uint8_t mode;
+extern uint8_t gcontrol;
+extern uint8_t reset_indicator;
+extern uint8_t alarmflag;
+
+volatile uint8_t wdcounter;
+
+
+typedef union {
+
+       volatile uint8_t bytes[64];
+       struct {
+               uint8_t status;  //1
+               int16_t temp;  //2
+               uint16_t voltage;  //4
+               uint16_t current;  //6
+               uint8_t threshold; //8
+               
+               uint8_t page1[8]; //9
+               uint8_t page2[8]; //17
+               uint8_t page3[8]; //25
+               uint8_t page4[8];  //33
+               uint8_t page5[8];  //41
+               uint8_t page6[8];  //49
+               uint8_t page7[8];  //57
+               //uint8_t crc;  //65
+       };
+} pack_t;
+volatile pack_t pack;
+
+
+
+volatile int16_t am2302_temp;
+volatile uint16_t am2302_hum;
+
+uint8_t userRegister[1];
+int16_t sRH,sT;
+volatile double temperatureC,humidityRH;
+volatile double l;
+
+#if  defined(__AVR_ATtiny24__)||defined(__AVR_ATtiny44__)  || defined(__AVR_ATtiny84__) || defined(__AVR_ATtiny24A__)||defined(__AVR_ATtiny44A__)  || defined(__AVR_ATtiny84A__)
+ISR(WATCHDOG_vect) {
+#else
+ISR(WDT_vect) {
+#endif 
+       wdcounter++;
+       if (reset_indicator==1) reset_indicator++;
+       else if (reset_indicator==2) mode=0;
+
+
+}
+
+int testSW(void) {
+       uint8_t r;
+       DDRB&=~(1<<PORTB0);  //Eingang
+        __asm__ __volatile__ ("nop"); 
+        PORTB|=(1<<PORTB0); //Pullup
+        __asm__ __volatile__ ("nop"); 
+        __asm__ __volatile__ ("nop"); 
+        __asm__ __volatile__ ("nop"); 
+        __asm__ __volatile__ ("nop"); 
+        __asm__ __volatile__ ("nop"); 
+        r=PINB&(1<<PORTB0);
+        __asm__ __volatile__ ("nop");  
+        PORTB&=~(1<<PORTB0); 
+        __asm__ __volatile__ ("nop"); 
+       DDRB|=(1<<PORTB0);  //Eingang
+       return (r==0);
+        
+        
+}
+
+int main(void){
+     PRR|=(1<<PRADC);  // adc for save Power
+       PORTA=0xFF;
+       PORTB=0xFF-(1<<PORTB0); //Schalter kann gegen Masse sein und zieht dann immer Strom
+       DDRB|=(1<<PORTB0); //Als Ausgang und 0
+       
+       
+       OWINIT();
+
+       ACSR|=(1<<ACD);  //Disable Comparator
+       ADCSRB|=(1<<ACME); //Disable Analog multiplexer
+       MCUCR &=~(1<<PUD); //All Pins Pullup...
+       MCUCR |=(1<<BODS);
+
+       
+       WDTCSR |= ((1<<WDCE) );   // Enable the WD Change Bit//| (1<<WDE)
+       WDTCSR |=   (1<<WDIE) |              // Enable WDT Interrupt
+       (1<<WDP3) | (1<<WDP0);   // Set Timeout to ~8 seconds
+        if (testSW()) {
+               config_info[5]=8;
+       }else{
+               config_info[5]=7;
+        }
+       
+    uint8_t i;
+    for(i=0;i<64;i++) pack.bytes[i]=0;
+       MCUSR=0;
+       USI_TWI_Master_Initialise();
+       volatile uint16_t res,res1;
+       I2c_StartCondition();
+       I2c_WriteByte (0b01001110);
+       I2c_StopCondition();
+       _delay_us(100);
+       
+       I2c_StartCondition();
+       I2c_WriteByte (0b01001111);
+       _delay_us(80);
+       res=((int16_t)(I2c_ReadByte(ACK))&0x3F)<<8;
+       res|=I2c_ReadByte(ACK);
+       res1=((int16_t)(I2c_ReadByte(ACK)))<<6;
+       res1|=I2c_ReadByte(NO_ACK)>>2;
+
+       I2c_StopCondition();
+       temperatureC=res1/16382.0*160.0-40.0;
+       humidityRH=res/16382.0*100.0;
+       //temperatureC = SHT2x_CalcTemperatureC(sT);
+       //humidityRH = SHT2x_CalcRH(sRH);
+       
+       sei();
+       
+        while(1)   {
+                if (gcontrol) {
+                        wdcounter=3;
+                        gcontrol=0;
+                }
+                if (wdcounter>2) {
+                        I2c_StartCondition();
+                       I2c_WriteByte (0b01001110);
+                       I2c_StopCondition();
+                       _delay_us(100);
+                       I2c_StartCondition();
+                       I2c_WriteByte (0b01001111);
+                       _delay_us(80);
+                       res=((int16_t)(I2c_ReadByte(ACK))&0x3F)<<8;
+                       res|=I2c_ReadByte(ACK);
+                       res1=((int16_t)(I2c_ReadByte(ACK)))<<6;
+                       res1|=I2c_ReadByte(NO_ACK)>>2;
+
+                       I2c_StopCondition();
+                       temperatureC=res1/16382.0*1650.0-400.0;
+                       humidityRH=res/16382.0*1000.0;
+
+                        if (testSW()) {
+                                am2302_hum= humidityRH*10.0;
+                                am2302_temp=temperatureC*25.6;
+                                //am2302_temp=am2302_temp-45;
+                                config_info[5]=8;      
+                                
+                        }else{
+                                
+                               double hhum=(1.0546-0.000216*temperatureC)*(humidityRH);
+                               //am2302_hum=0.318*hhum +76.0;
+                               am2302_hum=0.31*hhum +80;
+                               am2302_temp=temperatureC*25.6;
+                               //am2302_temp=am2302_temp-45;
+                               config_info[5]=7;
+                        }
+                        //PORTB&=~(1<<PINB1);
+                        wdcounter=0;
+                }
+
+               if (((TIMSK0 & (1<<TOIE0))==0)&& (mode==0))       {
+                       MCUCR|=(1<<SE)|(1<<SM1);
+                       MCUCR&=~(1<<ISC01);
+               } else {
+                       MCUCR|=(1<<SE);
+                       MCUCR&=~(1<<SM1);
+               }
+               asm("SLEEP");
+       }
+
+
+}
\ No newline at end of file
diff --git a/DS2438_HIH9121/DS2438_HIH9121.cproj b/DS2438_HIH9121/DS2438_HIH9121.cproj
new file mode 100644 (file)
index 0000000..eb00b22
--- /dev/null
@@ -0,0 +1,139 @@
+<?xml version="1.0" encoding="utf-8"?>
+<Project DefaultTargets="Build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
+  <PropertyGroup>
+    <SchemaVersion>2.0</SchemaVersion>
+    <ProjectVersion>7.0</ProjectVersion>
+    <ToolchainName>com.Atmel.AVRGCC8.C</ToolchainName>
+    <ProjectGuid>{91468d4f-8ae2-4c59-8a35-549c49e00934}</ProjectGuid>
+    <avrdevice>ATtiny84A</avrdevice>
+    <avrdeviceseries>none</avrdeviceseries>
+    <OutputType>Executable</OutputType>
+    <Language>C</Language>
+    <OutputFileName>$(MSBuildProjectName)</OutputFileName>
+    <OutputFileExtension>.elf</OutputFileExtension>
+    <OutputDirectory>$(MSBuildProjectDirectory)\$(Configuration)</OutputDirectory>
+    <AssemblyName>DS2438_SHT2X</AssemblyName>
+    <Name>DS2438_HIH9121</Name>
+    <RootNamespace>DS2438_SHT2X</RootNamespace>
+    <ToolchainFlavour>Native</ToolchainFlavour>
+    <KeepTimersRunning>true</KeepTimersRunning>
+    <OverrideVtor>false</OverrideVtor>
+    <CacheFlash>true</CacheFlash>
+    <ProgFlashFromRam>true</ProgFlashFromRam>
+    <RamSnippetAddress>0x20000000</RamSnippetAddress>
+    <UncachedRange />
+    <preserveEEPROM>true</preserveEEPROM>
+    <OverrideVtorValue>exception_table</OverrideVtorValue>
+    <BootSegment>2</BootSegment>
+    <eraseonlaunchrule>1</eraseonlaunchrule>
+    <AsfFrameworkConfig>
+      <framework-data xmlns="">
+        <options />
+        <configurations />
+        <files />
+        <documentation help="" />
+        <offline-documentation help="" />
+        <dependencies>
+          <content-extension eid="atmel.asf" uuidref="Atmel.ASF" version="3.26.0" />
+        </dependencies>
+      </framework-data>
+    </AsfFrameworkConfig>
+    <avrtool>com.atmel.avrdbg.tool.atmelice</avrtool>
+    <com_atmel_avrdbg_tool_atmelice>
+      <ToolOptions>
+        <InterfaceProperties>
+        </InterfaceProperties>
+        <InterfaceName>debugWIRE</InterfaceName>
+      </ToolOptions>
+      <ToolType>com.atmel.avrdbg.tool.atmelice</ToolType>
+      <ToolNumber>J41800000779</ToolNumber>
+      <ToolName>Atmel-ICE</ToolName>
+    </com_atmel_avrdbg_tool_atmelice>
+    <avrtoolinterface>debugWIRE</avrtoolinterface>
+    <ExternalProgrammingToolCommand />
+  </PropertyGroup>
+  <PropertyGroup Condition=" '$(Configuration)' == 'Release' ">
+    <ToolchainSettings>
+      <AvrGcc>
+        <avrgcc.common.Device>-mmcu=attiny84a -B "%24(PackRepoDir)\atmel\ATtiny_DFP\1.0.68\gcc\dev\attiny84a"</avrgcc.common.Device>
+        <avrgcc.common.outputfiles.hex>True</avrgcc.common.outputfiles.hex>
+        <avrgcc.common.outputfiles.lss>True</avrgcc.common.outputfiles.lss>
+        <avrgcc.common.outputfiles.eep>True</avrgcc.common.outputfiles.eep>
+        <avrgcc.common.outputfiles.srec>True</avrgcc.common.outputfiles.srec>
+        <avrgcc.common.outputfiles.usersignatures>False</avrgcc.common.outputfiles.usersignatures>
+        <avrgcc.compiler.general.ChangeDefaultCharTypeUnsigned>True</avrgcc.compiler.general.ChangeDefaultCharTypeUnsigned>
+        <avrgcc.compiler.general.ChangeDefaultBitFieldUnsigned>True</avrgcc.compiler.general.ChangeDefaultBitFieldUnsigned>
+        <avrgcc.compiler.symbols.DefSymbols>
+          <ListValues>
+            <Value>DEBUG</Value>
+          </ListValues>
+        </avrgcc.compiler.symbols.DefSymbols>
+        <avrgcc.compiler.directories.IncludePaths>
+          <ListValues>
+            <Value>%24(PackRepoDir)\atmel\ATtiny_DFP\1.0.68\include</Value>
+          </ListValues>
+        </avrgcc.compiler.directories.IncludePaths>
+        <avrgcc.compiler.optimization.level>Optimize (-O1)</avrgcc.compiler.optimization.level>
+        <avrgcc.compiler.optimization.PackStructureMembers>True</avrgcc.compiler.optimization.PackStructureMembers>
+        <avrgcc.compiler.optimization.AllocateBytesNeededForEnum>True</avrgcc.compiler.optimization.AllocateBytesNeededForEnum>
+        <avrgcc.compiler.optimization.DebugLevel>Default (-g2)</avrgcc.compiler.optimization.DebugLevel>
+        <avrgcc.compiler.warnings.AllWarnings>True</avrgcc.compiler.warnings.AllWarnings>
+        <avrgcc.linker.libraries.Libraries>
+          <ListValues>
+            <Value>libm</Value>
+          </ListValues>
+        </avrgcc.linker.libraries.Libraries>
+        <avrgcc.assembler.debugging.DebugLevel>Default (-Wa,-g)</avrgcc.assembler.debugging.DebugLevel>
+      </AvrGcc>
+    </ToolchainSettings>
+  </PropertyGroup>
+  <PropertyGroup Condition=" '$(Configuration)' == 'Debug' ">
+    <ToolchainSettings>
+      <AvrGcc>
+        <avrgcc.common.Device>-mmcu=attiny84a -B "%24(PackRepoDir)\atmel\ATtiny_DFP\1.0.68\gcc\dev\attiny84a"</avrgcc.common.Device>
+        <avrgcc.common.outputfiles.hex>True</avrgcc.common.outputfiles.hex>
+        <avrgcc.common.outputfiles.lss>True</avrgcc.common.outputfiles.lss>
+        <avrgcc.common.outputfiles.eep>True</avrgcc.common.outputfiles.eep>
+        <avrgcc.common.outputfiles.srec>True</avrgcc.common.outputfiles.srec>
+        <avrgcc.common.outputfiles.usersignatures>False</avrgcc.common.outputfiles.usersignatures>
+        <avrgcc.compiler.general.ChangeDefaultCharTypeUnsigned>True</avrgcc.compiler.general.ChangeDefaultCharTypeUnsigned>
+        <avrgcc.compiler.general.ChangeDefaultBitFieldUnsigned>True</avrgcc.compiler.general.ChangeDefaultBitFieldUnsigned>
+        <avrgcc.compiler.symbols.DefSymbols>
+          <ListValues>
+            <Value>DEBUG</Value>
+          </ListValues>
+        </avrgcc.compiler.symbols.DefSymbols>
+        <avrgcc.compiler.directories.IncludePaths>
+          <ListValues>
+            <Value>%24(PackRepoDir)\atmel\ATtiny_DFP\1.0.68\include</Value>
+          </ListValues>
+        </avrgcc.compiler.directories.IncludePaths>
+        <avrgcc.compiler.optimization.level>Optimize (-O1)</avrgcc.compiler.optimization.level>
+        <avrgcc.compiler.optimization.PackStructureMembers>True</avrgcc.compiler.optimization.PackStructureMembers>
+        <avrgcc.compiler.optimization.AllocateBytesNeededForEnum>True</avrgcc.compiler.optimization.AllocateBytesNeededForEnum>
+        <avrgcc.compiler.optimization.DebugLevel>Default (-g2)</avrgcc.compiler.optimization.DebugLevel>
+        <avrgcc.compiler.warnings.AllWarnings>True</avrgcc.compiler.warnings.AllWarnings>
+        <avrgcc.linker.libraries.Libraries>
+          <ListValues>
+            <Value>libm</Value>
+          </ListValues>
+        </avrgcc.linker.libraries.Libraries>
+        <avrgcc.assembler.debugging.DebugLevel>Default (-Wa,-g)</avrgcc.assembler.debugging.DebugLevel>
+      </AvrGcc>
+    </ToolchainSettings>
+  </PropertyGroup>
+  <ItemGroup>
+    <Compile Include="D:\oc\dev\owSlave2\common\I2C\USI_TWI_Master.c">
+      <SubType>compile</SubType>
+      <Link>USI_TWI_Master.c</Link>
+    </Compile>
+    <Compile Include="D:\oc\dev\owSlave2\common\OWDS2438.S">
+      <SubType>compile</SubType>
+      <Link>OWDS2438.S</Link>
+    </Compile>
+    <Compile Include="DS2438_HIH9121.c">
+      <SubType>compile</SubType>
+    </Compile>
+  </ItemGroup>
+  <Import Project="$(AVRSTUDIO_EXE_PATH)\\Vs\\Compiler.targets" />
+</Project>
\ No newline at end of file
index 00345f6..dddca10 100644 (file)
@@ -55,7 +55,7 @@ extern uint8_t gcontrol;
 extern uint8_t reset_indicator;
 extern uint8_t alarmflag;
 
-volatile uint8_t wdcounter;
+volatile uint8_t wdcounter=5;
 
 
 typedef union {
@@ -180,7 +180,7 @@ int main(void){
                         if (testSW()) {
                                 am2302_hum= humidityRH*10.0;
                                 am2302_temp=temperatureC*25.6;
-                                am2302_temp=am2302_temp-45;
+                                //am2302_temp=am2302_temp-45;
                                 config_info[5]=8;      
                                 
                         }else{
@@ -189,7 +189,7 @@ int main(void){
                                //am2302_hum=0.318*hhum +76.0;
                                am2302_hum=0.31*hhum +80;
                                am2302_temp=temperatureC*25.6;
-                               am2302_temp=am2302_temp-45;
+                               //am2302_temp=am2302_temp-45;
                                config_info[5]=7;
                         }
                         //PORTB&=~(1<<PINB1);
index bdf657b..618c54f 100644 (file)
     <ExternalProgrammingToolCommand />
     <AsfFrameworkConfig>
       <framework-data xmlns="">
-  <options />
-  <configurations />
-  <files />
-  <documentation help="" />
-  <offline-documentation help="" />
-  <dependencies>
-    <content-extension eid="atmel.asf" uuidref="Atmel.ASF" version="3.27.3" />
-  </dependencies>
-</framework-data>
+        <options />
+        <configurations />
+        <files />
+        <documentation help="" />
+        <offline-documentation help="" />
+        <dependencies>
+          <content-extension eid="atmel.asf" uuidref="Atmel.ASF" version="3.27.3" />
+        </dependencies>
+      </framework-data>
     </AsfFrameworkConfig>
-    <avrtool>com.atmel.avrdbg.tool.atmelice</avrtool>
-    <avrtoolserialnumber>J41800000779</avrtoolserialnumber>
-    <avrdeviceexpectedsignature>0x1E930C</avrdeviceexpectedsignature>
-    <com_atmel_avrdbg_tool_atmelice>
-      <ToolOptions>
-        <InterfaceProperties>
-        </InterfaceProperties>
-        <InterfaceName>debugWIRE</InterfaceName>
-      </ToolOptions>
-      <ToolType>com.atmel.avrdbg.tool.atmelice</ToolType>
-      <ToolNumber>J41800000779</ToolNumber>
-      <ToolName>Atmel-ICE</ToolName>
-    </com_atmel_avrdbg_tool_atmelice>
-    <avrtoolinterface>debugWIRE</avrtoolinterface>
+    <avrtool />
   </PropertyGroup>
   <PropertyGroup Condition=" '$(Configuration)' == 'Release' ">
     <ToolchainSettings>
diff --git a/DS2450/DS2450.pdf b/DS2450/DS2450.pdf
deleted file mode 100644 (file)
index c692e4b..0000000
Binary files a/DS2450/DS2450.pdf and /dev/null differ
diff --git a/DS2450_SHT2X_BMP280_MAX44009/DS2450.pdf b/DS2450_SHT2X_BMP280_MAX44009/DS2450.pdf
new file mode 100644 (file)
index 0000000..c692e4b
Binary files /dev/null and b/DS2450_SHT2X_BMP280_MAX44009/DS2450.pdf differ
index a653b5c..8ce61d0 100644 (file)
 .comm block,1 ; Block der augegeben, geschrieben wird (Parameter von READ/WRITE Scratchpad)
 
 
-.macro CHIP_INIT       
+.macro CHIP_INIT       ;r_temp is pushed other Registers should be saved
 Init_EEPROM_read:
+       push r_bytep
+       push r_rwbyte
        sbic _SFR_IO_ADDR(EECR), EEPE
        rjmp Init_EEPROM_read
        ldi r_temp,0
@@ -64,6 +66,8 @@ Init_EEPROM_read:
        in r_temp,_SFR_IO_ADDR(EEDR)
        sbrs r_temp,7
        rcall hrc_recall_eeprom_func1
+       pop r_rwbyte
+       pop r_bytep
 .endm
 
 .macro COMMAND_TABLE
@@ -248,6 +252,7 @@ h_readcommand2:
        cjmp 0x44,hrc_set_convertT2
        cjmp 0xB4,hrc_set_convertV2
        FW_CONFIG_INFO2
+       //cljmp 0x85,hrc_fw_configinfo2
 #ifdef _CHANGEABLE_ID_
        CHANGE_ID_COMMANDS
 #endif
index 9887940..e889416 100644 (file)
 #ifdef _CHANGEABLE_ID_
 ; lesen der ID aus dem EEPROM beim Start
 read_EEPROM_ID:  
+       push r_bytep
+       push r_rwbyte//r_temp2 and Z is not in gnu C save area
        ldi r_temp2,lo8(E2END)
        ldi zh,hi8(E2END)
        subi r_temp2,7
@@ -123,6 +125,8 @@ read_EEPROM_ID_loop:
        cpi r_bytep,8
        brne read_EEPROM_ID_loop
 read_EEPROM_ID_end:
+       pop r_rwbyte
+       pop r_bytep
        ret
 #endif
 
@@ -437,7 +441,7 @@ OWINIT:
 #ifndef _DIS_FLASH_
 ; check for bootloader jumper
        ;vor allen anderen Registerconfigs
-       
+       push r_temp
        ldi r_temp,(1<<PUD) ;enable pullup 
        out _SFR_IO_ADDR(MCUCR) ,r_temp
        sbi _SFR_IO_ADDR(PORTA),PINA5 ;internal pullup on PINA5
@@ -470,6 +474,7 @@ owinit_botest_end:
        sts bcount,r_temp
        sts alarmflag,r_temp
        RESETZEROMARKER
+       pop r_temp
        ret
 
 
index adc571c..1a9b0d4 100644 (file)
@@ -64,6 +64,7 @@
 #define OW_FWCONFIGINFO1 7
 #define OW_FWCONFIGINFO2 8
 
+.comm idtable,64
 
 #ifdef _CHANGEABLE_ID_
 #define OW_WRITE_NEWID 9
@@ -71,7 +72,6 @@
 #define OW_SET_NEWID 11
 #define OW_FIRST_COMMAND 12
 .comm newid,8
-.comm idtable,64
        
 .macro CHANGE_ID_COMMANDS
        cset 0x75,OW_WRITE_NEWID
@@ -406,10 +406,10 @@ h_fwconfiginfo_go:
        rjmp handle_end_inc
 h_fwconfiginfo_crc:
        lds r_rwbyte,crc
-       rjmp handle_end
+       rjmp handle_end_inc
 h_fwconfiginfo_crc2:
        lds r_rwbyte,crc+1
-       rjmp handle_end
+       rjmp handle_end_inc
 h_fwconfiginfo_all:
        rjmp handle_end_sleep
 
@@ -507,19 +507,11 @@ h_setid_EEPROM_write:
        //rcall read_EEPROM_ID2
        push r_idm1
        push r_idm2
-       push r_idn1
-       push r_idn2
        push xl
        push xh
-       push yl
-       push yh
        rcall init_idtable
-       pop yh
-       pop yl
        pop xh
        pop xl
-       pop r_idn2
-       pop r_idn1
        pop r_idm2
        pop r_idm1
 h_setid_bad_code_all:
@@ -540,10 +532,12 @@ spause:
 
 .global OWINIT
 OWINIT:
+       
 #ifndef _DIS_FLASH_
 ; check for bootloader jumper
        ;vor allen anderen Registerconfigs
-       
+       push r_temp
+
        ldi r_temp,(1<<PUD) ;enable pullup 
        out _SFR_IO_ADDR(MCUCR) ,r_temp
        sbi _SFR_IO_ADDR(PORTA),PINA5 ;internal pullup on PINA5
@@ -568,8 +562,15 @@ owinit_botest_end:
 #endif
        HW_INIT  //Microcontroller specific
        CHIP_INIT //1-Wire device specific
-#ifdef _CHANGEABLE_ID_
+       pop r_temp
 init_idtable:
+       push yl
+       push yh
+       push r_temp
+       push r_rwbyte
+       push r_idn1
+       push r_idn2
+#ifdef _CHANGEABLE_ID_
        rcall read_EEPROM_ID1
        rcall read_EEPROM_ID2
 #endif
@@ -640,6 +641,13 @@ owinit_cpconfig2:
        sts bcount,r_temp
        sts alarmflag,r_temp
        RESETZEROMARKER
+       pop r_idn2
+       pop r_idn1
+       pop r_rwbyte
+       pop r_temp
+       pop yh
+       pop yl
+       
        ret
 
 .global EXTERN_SLEEP
index b157207..98efef2 100644 (file)
        out     _SFR_IO_ADDR(MCUCR),r_temp
 .endm
 
-.macro HW_INIT
+.macro HW_INIT  ;r_temp is pushed other Registers should be saved
        ;set clock to 8 MHz
        ldi r_temp,0x80;
        out _SFR_IO_ADDR(CLKPR),r_temp
diff --git a/common/calibr.c b/common/calibr.c
new file mode 100644 (file)
index 0000000..2f2e68a
--- /dev/null
@@ -0,0 +1,23 @@
+#include "calibr.h"
+#include <avr/pgmspace.h>
+#include <avr/io.h>
+
+
+
+//const uint8_t cor[] PROGMEM= {0, 3, 6, 10, 13, 17, 20, 24, 27, 30, 34, 37, 41, 44, 47, 51, 54, 58, 61, 64, 68, 71, 75, 78, 81, 85, 88, 91, 95, 98, 101, 105, 108, 111, 115, 118, 121, 125, 128, 131, 135, 138, 141, 144, 148, 151, 154, 158, 161, 164, 167, 171, 174, 177, 180, 184, 187, 190, 193, 197, 200, 203, 206, 209, 213, 216, 219, 222, 225, 229, 232, 235, 238, 241, 245, 248, 251, 254, 255, 255};
+
+#define a 7.5
+#define b 237.3
+
+inline double SDDD(double t,double x) {
+        //volatile double p=((a*t/(b+t)-(a*t+a*x)/(b+t+x)))*2000.0;
+       //return ((p*3.3)/3000.0)+1;
+       //return ((3.5*((a*t/(b+t)-(a*t+a*x)/(b+t+x)))*2000.0)/3000.0+1);
+       return 1 - (2.33333 *a* b* x)/((b + t)* (b + t + x));
+}
+
+double calibr_hum(double temp,double tempdiv,double hum) {
+        double r=hum*(SDDD(temp,tempdiv)*(tempdiv/(temp+273.15)+1));
+        if (r>100) return 100.0;
+       return r;
+}
\ No newline at end of file
diff --git a/common/calibr.h b/common/calibr.h
new file mode 100644 (file)
index 0000000..a6bd4fe
--- /dev/null
@@ -0,0 +1,9 @@
+#ifndef CALIBR_H
+#define CALIBR_H
+
+
+
+double calibr_hum(double temp,double tempdiv,double hum);
+
+
+#endif
\ No newline at end of file
diff --git a/programmer/flash/flashp 2.7.bat b/programmer/flash/flashp 2.7.bat
new file mode 100644 (file)
index 0000000..323f30d
--- /dev/null
@@ -0,0 +1,2 @@
+avrdude -c usbasp -p t84 -U lfuse:w:0xE2:m -U hfuse:w:0xDD:m -U efuse:w:0xFE:m
+avrdude -c usbasp -p t84 -e -U flash:w:"../programmer/Release/programmer.hex"
index a44d5aa..5159495 100644 (file)
@@ -1,2 +1,2 @@
-avrdude -c usbasp -p t84 -U lfuse:w:0xE2:m -U hfuse:w:0xDF:m -U efuse:w:0xFE:m
+avrdude -c usbasp -p t84 -U lfuse:w:0xE2:m -U hfuse:w:0xDE:m -U efuse:w:0xFE:m
 avrdude -c usbasp -p t84 -e -U flash:w:"../programmer/Release/programmer.hex"
diff --git a/stest/fdiff.py b/stest/fdiff.py
new file mode 100644 (file)
index 0000000..ea227d0
--- /dev/null
@@ -0,0 +1,74 @@
+import math
+#Bezeichnungen:
+#r = relative Luftfeuchte
+#T = Temperatur in C
+#TK = Temperatur in Kelvin (TK = T + 273.15)
+#TD = Taupunkttemperatur in C
+#DD = Dampfdruck in hPa
+#SDD = Saettigungsdampfdruck in hPa
+
+#Parameter:
+#a = 7.5, b = 237.3 fuer T >= 0
+#a = 7.6, b = 240.7 fuer T < 0 ueber Wasser (Taupunkt)
+#a = 9.5, b = 265.5 fuer T < 0 ueber Eis (Frostpunkt)
+
+Rs = 8314.3 #J/(kmol*K) (universelle Gaskonstante)
+mw = 18.016 #kg/kmol (Molekulargewicht des Wasserdampfes)
+#AF = absolute Feuchte in g Wasserdampf pro m3 Luft
+
+#Formeln:
+
+#    SDD(T) = 6.1078 * 10^((a*T)/(b+T))
+#    DD(r,T) = r/100 * SDD(T)
+#    r(T,TD) = 100 * SDD(TD) / SDD(T)
+#    TD(r,T) = b*v/(a-v) mit v(r,T) = log10(DD(r,T)/6.1078)
+#    AF(r,TK) = 10^5 * mw/R* * DD(r,T)/TK; AF(TD,TK) = 10^5 * mw/R* * SDD(TD)/TK
+
+
+a=7.5
+b=237.3
+
+#a=r/100.0*SDD(T)/(T+273.15)*mw/Rs*10000
+#r=a*100/(SDD(T)/(T+273.15)*mw/Rs*10000)
+
+def SDD(T):
+       return 6.1078 * 10**((a*T)/(b+T))
+
+#def DD(r,T):
+#      return r/100 * SDD(T)
+
+#def _r(T,TD):
+#      return 100 * SDD(TD) / SDD(T)
+
+#def _v(r,T):
+#      return math.log10(DD(r,T)/6.1078)
+       
+#def TD(r,T):
+#      return b*v/(a-_v(r,T))  
+
+       
+#def AF(r,T):
+#      return 10000 * mw/Rs * DD(r,T)/(T+273.15) #; AF(TD,TK) = 10^5 * mw/R* * SDD(TD)/TK
+
+def AF1(r,T):
+       return r/100.0*SDD(T)/(T+273.15)*mw/Rs*10000
+
+def RF1(a,T):
+       return a*100/(SDD(T)/(T+273.15)*mw/Rs*10000)    
+#print(0.5*SDD(20)/(20+273.15)*mw/Rs*10000)
+d=[]
+for i in range(11):
+       s=""
+       r=[]
+       for j in range(6):
+               r.append((i*10)-RF1(AF1(i*10,j*10),j*10+0.5))
+               s=s+"%0.2f\t" % (r[len(r)-1])
+       print(s)
+       d.append(r)
+       
+for i in range(11):
+       s=""
+       for j in range(5):
+               s=s+"%0.4f\t" % (d[i][j]-d[i][j+1])
+       print(s)
+               
diff --git a/stest/find.py b/stest/find.py
new file mode 100644 (file)
index 0000000..5c28895
--- /dev/null
@@ -0,0 +1,292 @@
+import sys
+import os
+import os.path
+import subprocess
+import io
+import time
+import math
+import shutil
+
+toolstr="/home/muto/owtools/src/owtools USB1 DC "
+devdict={}
+devwholist=[]
+f=open("DEVLIST.txt","r")
+for l in f.readlines():
+       ls=l.split(" ")
+       if (len(ls)>1):
+               devdict[ls[0]]=l.replace("\n","")
+               devwholist.append(ls[0])
+f.close()
+
+def id2string(id):
+       s=""
+       for i in range(8):
+               s=s+"%02X" %(id[7-i])
+       return s
+
+def string2id(s):
+       for i in range(8):
+               bl=[]
+               i2=14-i*2;
+               bl.append(int(s[i2:i2+2],16))
+       return bl
+
+
+def calculateValues(code, V, vn):
+       if code==1:
+               return V[vn] / 16.0; 
+       elif code==2:
+               return V[vn]/1.6; 
+       elif code==3:
+               return V[vn]*0.2 + 700; 
+       elif code==4:
+               return math.exp(V[vn] / 160.0); 
+       elif code==5:
+               return V[vn]*62.5 + 55000; 
+       elif code==6:
+               return V[vn] / 256.0; 
+       elif code==7:
+               if V[1]!=0:
+                       return ((float(V[2]) / float(V[1]) - 0.16) / 0.0062) / (1.0546 - 0.00216*V[0]/256.0); 
+               else:
+                       return 0
+       elif code==8:
+               return V[vn] / 100.0; 
+       elif code==9:
+               return V[vn] / 65535.0*5.1; 
+       elif code==10:
+               return V[vn] / 65535.0*2.55; 
+       elif code==11:
+               return V[vn] / 65535.0*1.1; 
+       elif code==12:
+               return V[vn] / 10.0; 
+       elif code==13:
+               return V[vn];  
+       elif code==14:
+               return (V[vn] - 32767.0) / 100.0;  
+       elif code==15:
+               return math.exp((V[vn]-32767.0)/1000.0); 
+       elif code==16:
+               return V[vn]/32.0; 
+       else:
+               return 0;
+
+def getName(code       ):
+       if code==1:
+               return ["Temperatur","C"]
+       if code==2:
+               return ["Druck","hPa"]
+       if code==3:
+               return ["Beleuchtungsstaerke","lux"]
+       if code==4:
+               return ["Luftfeuchte","%%"]
+       if code==5:
+               return ["Konstante",""]
+       if code==6:
+               return ["Spannung","V"]
+       if code==7:
+               return ["Strom","mA"]
+       if code==8:
+               return ["VOC","ppm"]
+       if code==9:
+               return ["Counter",""]
+       return []
+
+
+def owCom(dev,send,rcount):
+       cmd=toolstr+id2string(dev)
+       #for i in range(8):
+       #       cmd=cmd+"%02X" %(dev[7-i])
+       cmd=cmd+" "
+       for b in send:
+               cmd=cmd+"%02X" % (b)
+       for i in range(rcount):
+               cmd=cmd+"FF"
+       #print(cmd.split(' '));
+       p = subprocess.Popen(cmd.split(' '), shell=False, bufsize=14000, stdin=subprocess.PIPE, stdout=subprocess.PIPE)
+       p.wait()
+       s=p.stdout.read().decode("utf-8")
+       l=s.split("\n");
+       #print(l[2])
+       bl=[]
+       for i in range(int(len(l[2])/2)):
+               i2=i*2;
+               bl.append(int(l[2][i2:i2+2],16))
+       return bl
+
+def owComStr(dev,sendstr):
+       cmd=toolstr+id2string(dev)
+       #for i in range(8):
+       #       cmd=cmd+"%02X" %(dev[7-i])
+       cmd=cmd+" "+sendstr
+       p = subprocess.Popen(cmd.split(' '), shell=False, bufsize=14000, stdin=subprocess.PIPE, stdout=subprocess.PIPE)
+       p.wait()
+       s=p.stdout.read().decode("utf-8")
+       #print(s);
+       ll=s.split("\n");
+       bll=[]
+       for l in ll[2:]:
+               bl=[]
+               for i in range(int(len(l)/2)):
+                       i2=i*2;
+                       bl.append(int(l[i2:i2+2],16))
+               bll.append(bl)
+       return bll
+
+def getValues(dev,voc):
+       pl=[]
+       #print(id2string(dev[0]),voc)
+       if dev[0][0]==0x26:
+               vnok=1
+               rc=0
+               while (vnok):
+                       sbl=owComStr(dev[0],"4E000F_RB4_R_P7044_R_P70B800_RBE00FFFFFFFFFFFFFFFFFF_R4E0000_RB4_R_P70B800_RBE00FFFFFFFFFFFFFFFFFF_RBE03FFFFFFFFFFFFFFFFFF")
+                       #print(sbl)
+                       sb=sbl[4]
+                       VDD=(sb[5]+sb[6]*256)
+                       sb=sbl[8]
+                       VAD=(sb[5]+sb[6]*256)
+                       Temp=(sb[3]+sb[4]*256)
+                       if (sb[4] & 0x80):
+                               Temp-=0x10000
+                       curr=sb[7]+sb[8]*256
+                       if (sb[8] & 0x80):
+                               curr-=0x10000
+                       vals=[Temp,VDD,VAD,curr]
+                       formellist=[6,8,7,8]
+                       if dev[1][0]!=0xFF:
+                               formellist=[]
+                               for i in range(4):
+                                       if (dev[1][i*2+1])!=0:
+                                               formellist.append(dev[1][i*2+1])
+                                       else:
+                                               break
+                       cvals=[]
+                       for i in range(len(formellist)):
+                               cvals.append(calculateValues(formellist[i],vals,i))
+                       if (cvals[2]<=110):
+                               vnok=0
+                       else:
+                               rc=rc+1
+                               if (rc==3):
+                                       vnok=0
+                                       cvals[2]=100
+                       if voc!=0:
+                               #R0,VS,Corr,cmode,RS,RSR0,VOC1,VOC2
+                               sb=sbl[9]
+                               R0=(sb[2]+sb[3]*256)/100.0
+                               VS=(sb[4]+sb[5]*256)/10000.0
+                               Corr=(sb[7]+sb[8]*256)/1000.0
+                               cmode=sb[6]
+                               RS=(3/VS-1)*30
+                               RSR0=(RS/R0)
+                               VOC1=RSR0*Corr
+                               VOC2=RSR0/Corr
+                               cvals.append(R0)
+                               cvals.append(VS)
+                               cvals.append(Corr)
+                               cvals.append(cmode)
+                               cvals.append(RS)
+                               cvals.append(RSR0)
+                               cvals.append(VOC1)
+                               cvals.append(VOC2)
+               return cvals
+       if dev[0][0]==0x28:
+               sbl=owComStr(dev[0],"44_R_PFF_PFF_PFF_PFFBEFFFFFFFFFFFFFFFFFF")
+               Temp=sbl[1][1]+sbl[1][2]*256
+               if (sbl[1][2] & 0x80):
+                       Temp=-(Temp&0x7FFF)
+               if dev[1][0]!=0xFF:
+                       return [calculateValues(dev[1][1],[Temp],0)]
+               else:
+                       return [calculateValues(1,[Temp],0)]
+       return []
+
+       
+def owList(): 
+       cmd=toolstr[0:-3]
+       print(cmd)
+       p = subprocess.Popen(["./owtools","USB1"], shell=False, bufsize=14000, stdin=subprocess.PIPE, stdout=subprocess.PIPE)
+       p.wait()
+       s=p.stdout.read()
+       l=s.split("\n")
+       #print(l);
+       l=l[1:-1]
+       devlist=[]
+       ic=0
+       for d in l:
+               dev=[]
+               bl=[]
+               for i in range(8):
+                       i2=14-i*2;
+                       bl.append(int(d[i2:i2+2],16))
+               dev.append(bl)
+               #print(bl)
+               config=owCom(bl,[0x85],18)
+               #print(config)
+               if (config[1]==0xFF):
+                       if (bl[0]==0x26):
+                               config=[0,1,6,6,8,4,7,7,8,0]
+                       if (bl[0]==0x28):
+                               config=[0,1,1,0,0,0,0,0,0,0]
+               dev.append(config[1:])
+               bls=id2string(bl)
+               cs="%i: " %(ic)
+               ic=ic+1
+               cs=cs+bls+": "
+               if bls in devdict:
+                       cs=cs+devdict[bls].split(",")[0].split(" ")[1]+" "
+               for i in range(4):
+                       c=config[i*2+1]
+                       if (c==0xFF):
+                               cs=cs+"Noconfig "
+                               if (bl[0]==0x26):
+                                       config=[0,1,6,6,8,4,7,7,8,0]
+                               if (bl[0]==0x28):
+                                       config=[0,1,1,0,0,0,0,0,0,0]
+                               break
+                       if (c==0):
+                               break
+                       cs=cs+getName(c)[0]+" "
+               voc=0
+               if bls in devdict:
+                       if "VOC" in devdict[bls]:
+                               voc=1
+               l=getValues([bl,config[1:]],voc)
+               for v in l:
+                       cs=cs+" %0.2f " %(v)
+               print(cs)
+               ddev=0
+               vm=0
+               if config[1]==0x08:
+                       vm=1
+               #print("Test_configs")
+               i=0
+               for dv in devlist:
+                       #print("c",dv[1][9:16])
+                       #print("d",bl[0:7])
+                       if dv[1][9:16]==bl[0:7]:
+                               print("Double Device")
+                               ddev=1
+                               dv.append(dev[0])
+                               dv.append(dev[1])
+                               #if vm==1:
+                                       #voc_marker[i]=2
+                       i=i+1
+               if ddev==0:
+                       devlist.append(dev)
+                       #voc_marker.append(vm)
+               #print("devlist",devlist)
+       return devlist
+
+dl=owList()
+#for d in dl:
+#      print(d)
+
+#while (1):
+#      for d in dl:
+#              ds=id2string(d[0])
+#              print(ds)
+               
+       
+       
\ No newline at end of file
diff --git a/stest/log_all.py b/stest/log_all.py
new file mode 100644 (file)
index 0000000..a6ca49d
--- /dev/null
@@ -0,0 +1,482 @@
+import sys
+import os
+import os.path
+import subprocess
+import io
+import time
+import math
+import shutil
+
+toolstr="/home/muto/owtools/src/owtools USB1 DC "
+
+gplist=[] 
+
+def id2string(id):
+       s=""
+       for i in range(8):
+               s=s+"%02X" %(id[7-i])
+       return s
+
+def string2id(s):
+       for i in range(8):
+               bl=[]
+               i2=14-i*2;
+               bl.append(int(s[i2:i2+2],16))
+       return bl
+
+
+def calculateValues(code, V, vn):
+       if code==1:
+               return V[vn] / 16.0; 
+       elif code==2:
+               return V[vn]/1.6; 
+       elif code==3:
+               return V[vn]*0.2 + 700; 
+       elif code==4:
+               return math.exp(V[vn] / 160.0); 
+       elif code==5:
+               return V[vn]*62.5 + 55000; 
+       elif code==6:
+               return V[vn] / 256.0; 
+       elif code==7:
+               if V[1]!=0:
+                       return ((float(V[2]) / float(V[1]) - 0.16) / 0.0062) / (1.0546 - 0.00216*V[0]/256.0); 
+               else:
+                       return 0
+       elif code==8:
+               return V[vn] / 100.0; 
+       elif code==9:
+               return V[vn] / 65535.0*5.1; 
+       elif code==10:
+               return V[vn] / 65535.0*2.55; 
+       elif code==11:
+               return V[vn] / 65535.0*1.1; 
+       elif code==12:
+               return V[vn] / 10.0; 
+       elif code==13:
+               return V[vn];  
+       elif code==14:
+               return (V[vn] - 32767.0) / 100.0;  
+       elif code==15:
+               return math.exp((V[vn]-32767.0)/1000.0); 
+       elif code==16:
+               return V[vn]/32.0; 
+       else:
+               return 0;
+
+def getName(code       ):
+       if code==1:
+               return ["Temperatur","C"]
+       if code==2:
+               return ["Druck","hPa"]
+       if code==3:
+               return ["Beleuchtungsstaerke","lux"]
+       if code==4:
+               return ["Luftfeuchte","%%"]
+       if code==5:
+               return ["Konstante",""]
+       if code==6:
+               return ["Spannung","V"]
+       if code==7:
+               return ["Strom","mA"]
+       if code==8:
+               return ["VOC","ppm"]
+       if code==9:
+               return ["Counter",""]
+       return []
+
+
+def owCom(dev,send,rcount):
+       cmd=toolstr+id2string(dev)
+       #for i in range(8):
+       #       cmd=cmd+"%02X" %(dev[7-i])
+       cmd=cmd+" "
+       for b in send:
+               cmd=cmd+"%02X" % (b)
+       for i in range(rcount):
+               cmd=cmd+"FF"
+       print(cmd.split(' '));
+       p = subprocess.Popen(cmd.split(' '), shell=False, bufsize=14000, stdin=subprocess.PIPE, stdout=subprocess.PIPE)
+       p.wait()
+       s=p.stdout.read().decode("utf-8")
+       l=s.split("\n");
+       #print(l[2])
+       bl=[]
+       for i in range(int(len(l[2])/2)):
+               i2=i*2;
+               bl.append(int(l[2][i2:i2+2],16))
+       return bl
+
+def owComStr(dev,sendstr):
+       cmd=toolstr+id2string(dev)
+       #for i in range(8):
+       #       cmd=cmd+"%02X" %(dev[7-i])
+       cmd=cmd+" "+sendstr
+       p = subprocess.Popen(cmd.split(' '), shell=False, bufsize=14000, stdin=subprocess.PIPE, stdout=subprocess.PIPE)
+       p.wait()
+       s=p.stdout.read().decode("utf-8")
+       #print(s);
+       ll=s.split("\n");
+       bll=[]
+       for l in ll[2:]:
+               bl=[]
+               for i in range(int(len(l)/2)):
+                       i2=i*2;
+                       bl.append(int(l[i2:i2+2],16))
+               bll.append(bl)
+       return bll
+
+voc_marker=[]
+
+def owList(): 
+       cmd=toolstr[0:-3]
+       print(cmd)
+       p = subprocess.Popen(["./owtools","USB1"], shell=False, bufsize=14000, stdin=subprocess.PIPE, stdout=subprocess.PIPE)
+       p.wait()
+       s=p.stdout.read()
+       l=s.split("\n")
+       #print(l);
+       l=l[1:-1]
+       devlist=[]
+       for d in l:
+               dev=[]
+               bl=[]
+               for i in range(8):
+                       i2=14-i*2;
+                       bl.append(int(d[i2:i2+2],16))
+               dev.append(bl)
+               #print(bl)
+               config=owCom(bl,[0x85],18)
+               #print(config)
+               dev.append(config[1:])
+               ddev=0
+               vm=0
+               if config[1]==0x08:
+                       vm=1
+               #print("Test_configs")
+               i=0
+               for dv in devlist:
+                       #print("c",dv[1][9:16])
+                       #print("d",bl[0:7])
+                       if dv[1][9:16]==bl[0:7]:
+                               print("Double Device")
+                               ddev=1
+                               dv.append(dev[0])
+                               dv.append(dev[1])
+                               if vm==1:
+                                       voc_marker[i]=2
+                       i=i+1
+               if ddev==0:
+                       devlist.append(dev)
+                       voc_marker.append(vm)
+               #print("devlist",devlist)
+       return devlist
+
+def getProperties(dev,voc):
+       pl=[]
+       if dev[0][0]==0x26:
+               pl=["Temperatur","Spannung","Luftfeuchte","Strom"]
+               if dev[1][0]!=0xFF:
+                       pl=[]
+                       for i in range(4):
+                               name=getName(dev[1][i*2])
+                               if len(name)!=0:
+                                       pl.append(name[0])
+                       if voc!=0:
+                               #R0,VS,Corr,cmode,RS,RSR0,VOC1,VOC2
+                               pl.append("R0")
+                               pl.append("VS")
+                               pl.append("Corr")
+                               pl.append("cmode")
+                               pl.append("RS")
+                               pl.append("RSR0")
+                               pl.append("VOC1")
+                               pl.append("VOC2")
+       if dev[0][0]==0x28:
+               pl=["Temperatur"]
+               if dev[1][0]!=0xFF:
+                       pl=[]
+                       for i in range(4):
+                               name=getName(dev[1][i*2])
+                               if len(name)!=0:
+                                       pl.append(name[0])
+       return pl
+
+def getValues(dev,voc):
+       pl=[]
+       #print(id2string(dev[0]),voc)
+       if dev[0][0]==0x26:
+               vnok=1
+               while (vnok):
+                       sbl=owComStr(dev[0],"4E000F_RB4_R_P7044_R_P70B800_RBE00FFFFFFFFFFFFFFFFFF_R4E0000_RB4_R_P70B800_RBE00FFFFFFFFFFFFFFFFFF_RBE03FFFFFFFFFFFFFFFFFF")
+                       #print(sbl)
+                       sb=sbl[4]
+                       VDD=(sb[5]+sb[6]*256)
+                       sb=sbl[8]
+                       VAD=(sb[5]+sb[6]*256)
+                       Temp=(sb[3]+sb[4]*256)
+                       curr=sb[7]+sb[8]*256
+                       if (sb[8] & 0x80):
+                               curr=-(curr&0x7FFF)
+                       vals=[Temp,VDD,VAD,curr]
+                       formellist=[6,8,7,8]
+                       if dev[1][0]!=0xFF:
+                               formellist=[]
+                               for i in range(4):
+                                       if (dev[1][i*2+1])!=0:
+                                               formellist.append(dev[1][i*2+1])
+                                       else:
+                                               break
+                       cvals=[]
+                       for i in range(len(formellist)):
+                               cvals.append(calculateValues(formellist[i],vals,i))
+                       if (cvals[2]<=110):
+                               vnok=0
+                       else:
+                               print(cvals)
+                               vnok=0
+                       if voc!=0:
+                               #R0,VS,Corr,cmode,RS,RSR0,VOC1,VOC2
+                               sb=sbl[9]
+                               R0=(sb[2]+sb[3]*256)/100.0
+                               VS=(sb[4]+sb[5]*256)/10000.0
+                               Corr=(sb[7]+sb[8]*256)/1000.0
+                               cmode=sb[6]
+                               RS=(3/VS-1)*30
+                               RSR0=(RS/R0)
+                               VOC1=RSR0*Corr
+                               VOC2=RSR0/Corr
+                               cvals.append(R0)
+                               cvals.append(VS)
+                               cvals.append(Corr)
+                               cvals.append(cmode)
+                               cvals.append(RS)
+                               cvals.append(RSR0)
+                               cvals.append(VOC1)
+                               cvals.append(VOC2)
+               return cvals
+       if dev[0][0]==0x28:
+               sbl=owComStr(dev[0],"44_R_PFF_PFF_PFF_PFFBEFFFFFFFFFFFFFFFFFF")
+               Temp=sbl[1][1]+sbl[1][2]*256
+               if (sbl[1][2] & 0x80):
+                       Temp=-(Temp&0x7FFF)
+               if dev[1][0]!=0xFF:
+                       return [calculateValues(dev[1][1],[Temp],0)]
+               else:
+                       return [calculateValues(1,[Temp],0)]
+       return []
+
+
+
+
+def gp_makefile(name,i):
+       f=open("gpscript%i.dem" %(i),"w")
+       #f.write("set decimalsign ','\n")
+       f.write('set decimalsign locale\n')
+       f.write('set timefmt "%d.%m.%Y %H:%M:%S"\n')
+       f.write('set xdata time\n')
+       f.write('set datafile separator "\\t" \n')
+       f.write('set terminal png size 1024,600\n')
+       f.write('set format x "%d.%m\\n%H:%M"\n')
+       f.write("set output '%s'\n" % (name))
+       f.write("set grid ytics\n")
+       f.write("set terminal postscript landscape\n")
+       f.write('set object 1 rectangle from screen 0,0 to screen 1,1 fillcolor rgb"#FFFFFF" behind\n')
+       #set output 'Temperatur.ps'
+       return f
+
+
+def gnuplot():
+       rl=["Temperatur","Luftfeuchte","Druck","VOC","Beleuchtungsstaerke"]
+       rlf=[]
+       rls=[]
+       rllc=[]
+       for i in range(len(rl)):
+               rlf.append("") #begin of plotline
+               rls.append('') #plotline
+               rllc.append('')  #lineconfig
+       li=0
+       for c in gplist:
+               for i in range(len(rl)):
+                       if c[0]==rl[i]:
+                               li=li+1
+                               cl=c[2].split(",")
+                               rls[i]=rls[i]+" %s using 1:%i with linespoints ls %i title \"%s\" ," % (rlf[i],c[1],li,cl[0])
+                               rllc[i]=rllc[i]+ "set style line %i %s\n" % (li,cl[1])
+                               rlf[i]='""'
+       for i in range(len(rl)):
+               f=gp_makefile(rl[i]+".ps",i)
+               f.write(rllc[i])
+               f.write('plot "log22.txt" '+rls[i]+"\n")
+               f.write("set output '%s'\n" % (rl[i]+"_l.ps"))
+               f.write('plot "< tail -n 100 log22.txt" '+rls[i]+"\n")
+               f.close()
+               p = subprocess.Popen(["gnuplot","gpscript%i.dem" %(i)], shell=False, bufsize=14000, stdin=subprocess.PIPE, stdout=subprocess.PIPE, stderr=subprocess.PIPE)
+               p.wait();
+               cmd="convert -size 2048x1600 -depth 8 %s.ps -rotate 90 -resize 1024x800 -depth 8 %s.png" %(rl[i],rl[i])
+               p = subprocess.Popen(cmd.split(" "), shell=False, bufsize=14000, stdin=subprocess.PIPE, stdout=subprocess.PIPE, stderr=subprocess.PIPE)
+               p.wait();
+               cmd="convert -size 2048x1600 -depth 8 %s_l.ps -rotate 90 -resize 1024x800 -depth 8 %s_l.png" %(rl[i],rl[i])
+               print cmd.split(" ")
+               p = subprocess.Popen(cmd.split(" "), shell=False, bufsize=14000, stdin=subprocess.PIPE, stdout=subprocess.PIPE, stderr=subprocess.PIPE)
+               p.wait();
+               shutil.copyfile(rl[i]+".png","/var/www/html/"+rl[i]+".png")
+               shutil.copyfile(rl[i]+"_l.png","/var/www/html/"+rl[i]+"_l.png")
+
+devlist=owList()
+print(voc_marker)
+tline1="\t"
+tline2="time\t"
+devdict={}
+devwholist=[]
+f=open("DEVLIST.txt","r")
+for l in f.readlines():
+       ls=l.split(" ")
+       if (len(ls)>1):
+               devdict[ls[0]]=l.replace("\n","")
+               devwholist.append(ls[0])
+
+i=0
+col=1
+
+
+devlist1=[]
+devlistn=[]
+voc_marker1=[]
+
+for d in devwholist:
+       i=0
+       print(d)
+       for dd in devlist:
+               if id2string(dd[0])==d:
+                       print("->",id2string(dd[0]))
+                       devlist1.append(dd)
+                       devlist.remove(dd)
+                       voc_marker1.append(voc_marker[i])
+                       del voc_marker[i]
+                       break
+               i=i+1
+for d in devlist:
+       devlist1.append(d)
+       
+devlist=devlist1
+voc_marker=voc_marker1
+
+
+print devlist
+
+print voc_marker
+
+
+
+for d in devlist:
+       print(d[0])
+       prop=getProperties(d,voc_marker[i])
+       if len(prop)>0:
+               tline1=tline1+id2string(d[0])
+       for p in prop:
+               tline2=tline2+p+"\t"
+               tline1=tline1+"\t"
+               col=col+1
+               dn=id2string(d[0])
+               if dn in devdict:
+                       dn=devdict[dn]
+               gplist.append((p,col,dn))
+       if (len(d)>2):
+               print("->",d[2])
+               prop=getProperties(d[2:],voc_marker[i])
+               tline1=tline1+id2string(d[2])
+               for p in prop:
+                       tline2=tline2+p+"\t"
+                       tline1=tline1+"\t"
+                       col=col+1
+                       dn=id2string(d[2])
+                       if dn in devdict:
+                               dn=devdict[dn]
+                       gplist.append((p,col,dn))
+       i=i+1
+
+#if os.path.exists("log22.txt"):
+#      lt = time.localtime()
+#      ts=time.strftime("%Y%m%d%H%M%S", lt)
+#      os.rename("log22.txt","log22_"+ts+".txt")
+
+f=open("log22h.txt","a")
+f.write(tline1+"\n")
+f.write(tline2+"\n")
+f.close()
+print(tline1)
+print(tline2)
+
+while (1):
+       lt = time.localtime()
+       vline=time.strftime("%d#%m#%Y %H:%M:%S\t", lt)
+       i=0
+       for d in devlist:
+               #print(d[0])
+               vals=getValues(d,voc_marker[i])
+               for v in vals:
+                       vline=vline+"%0.5f\t" % (v)
+               if (len(d)>2):
+                       vals=getValues(d[2:],voc_marker[i])
+                       for v in vals:
+                               vline=vline+"%0.5f\t" % (v)
+               i=i+1
+       print(vline)
+       f=open("log22.txt","a")
+       f.write(vline.replace('.',',').replace('#','.')+"\n")
+       #f.write(vline+"\n")
+       f.close()
+       gnuplot()
+       time.sleep(90)
+
+
+
+
+id=[0x26,0xA3,0xD9,0x84,0x00,0x16,0x05,0x67]
+print("VDD\tVAD\tTemp\tHum\tR0\tVS\tCorr\tcm\tRS\tRSR0\tVOC1\tVOC2");
+print(owComStr(id,"85FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF"));
+#print(owComStr(id,"4E000F_RB4_R_P7044_R_P70B8_RBE00FFFFFFFFFFFFFFFFFF_R4E0000_RB4_R_P70BE00FFFFFFFFFFFFFFFFFF_RBE03FFFFFFFFFFFFFFFFFF"))
+
+while(0):
+       sbl=owComStr(id,"4E000F_RB4_R_P7044_R_P70B8_RBE00FFFFFFFFFFFFFFFFFF_R4E0000_RB4_R_P70BE00FFFFFFFFFFFFFFFFFF_RBE03FFFFFFFFFFFFFFFFFF")
+       #owCom(id,[0x4E,0x00,0x0F],0)
+       #owCom(id,[0xB4],0)
+       #time.sleep(0.1)
+       #owCom(id,[0x44],0)
+       #time.sleep(0.1)
+       #owCom(id,[0xB8],0)
+       #sb=owCom(id,[0xBE,0x00],11)
+       sb=sbl[4]
+       VDD=(sb[5]+sb[6]*256)/100.0
+       #owCom(id,[0x4E,0x00,0x00],0)
+       #owCom(id,[0xB4],0)
+       #time.sleep(0.1)
+       #owCom(id,[0xB8],0)
+       #sb=owCom(id,[0xBE,0x00],11)
+       sb=sbl[7]
+       VAD=(sb[5]+sb[6]*256)/100.0
+       Temp=(sb[3]+sb[4]*256)/256.0
+       #sb=owCom(id,[0xBE,0x03],11)
+       sb=sbl[8]
+       R0=(sb[2]+sb[3]*256)/100.0
+       VS=(sb[4]+sb[5]*256)/10000.0
+       Corr=(sb[7]+sb[8]*256)/1000.0
+       cmode=sb[6]
+       RS=(3/VS-1)*30
+       RSR0=(RS/R0)
+       VOC1=RSR0*Corr
+       VOC2=RSR0/Corr
+       Hum=(VAD/VDD-0.16)/0.0062
+       Hum=(Hum)/(1.0546-0.00216*(Temp))
+       f=open("log.txt","a")
+       print("%0.3f\t%0.3f\t%0.3f\t%0.3f\t%0.3f\t%0.3f\t%0.3f\t%i\t%0.3f\t%0.3f\t%0.3f\t%0.3f" %(VDD,VAD,Temp,Hum,R0,VS,Corr,cmode,RS,RSR0,VOC1,VOC2))
+       f.write("%0.3f\t%0.3f\t%0.3f\t%0.3f\t%0.3f\t%0.3f\t%0.3f\t%i\t%0.3f\t%0.3f\t%0.3f\t%0.3f\n" %(VDD,VAD,Temp,Hum,R0,VS,Corr,cmode,RS,RSR0,VOC1,VOC2))
+       f.close()
+       time.sleep(30)
+
+#cmd="owtools.exe usb1 DC 6705160084D9A326 BE00FFFFFFFFFFFFFFFFFFFF"
+#print(owCom([0x26,0xA3,0xD9,0x84,0x00,0x16,0x05,0x67],[0xBE,0x00],11))
+
+
+
diff --git a/stest/log_all1.py b/stest/log_all1.py
new file mode 100644 (file)
index 0000000..323d6fa
--- /dev/null
@@ -0,0 +1,341 @@
+import sys
+import os
+import os.path
+import subprocess
+import io
+import time
+import datetime
+import math
+import shutil
+
+toolstr="/home/muto/owtools/src/owtools USB1 DC "
+devdict={}
+devwholist=[]
+f=open("DEVLIST.txt","r")
+for l in f.readlines():
+       ls=l.split(" ")
+       if (len(ls)>1):
+               devdict[ls[0]]=l.replace("\n","")
+               devwholist.append(ls[0])
+f.close()
+
+def id2string(id):
+       s=""
+       for i in range(8):
+               s=s+"%02X" %(id[7-i])
+       return s
+
+def string2id(s):
+       for i in range(8):
+               bl=[]
+               i2=14-i*2;
+               bl.append(int(s[i2:i2+2],16))
+       return bl
+
+
+def calculateValues(code, V, vn):
+       if code==1:
+               return V[vn] / 16.0; 
+       elif code==2:
+               return V[vn]/1.6; 
+       elif code==3:
+               return V[vn]*0.2 + 700; 
+       elif code==4:
+               return math.exp(V[vn] / 160.0); 
+       elif code==5:
+               return V[vn]*62.5 + 55000; 
+       elif code==6:
+               return V[vn] / 256.0; 
+       elif code==7:
+               if V[1]!=0:
+                       return ((float(V[2]) / float(V[1]) - 0.16) / 0.0062) / (1.0546 - 0.00216*V[0]/256.0); 
+               else:
+                       return 0
+       elif code==8:
+               return V[vn] / 100.0; 
+       elif code==9:
+               return V[vn] / 65535.0*5.1; 
+       elif code==10:
+               return V[vn] / 65535.0*2.55; 
+       elif code==11:
+               return V[vn] / 65535.0*1.1; 
+       elif code==12:
+               return V[vn] / 10.0; 
+       elif code==13:
+               return V[vn];  
+       elif code==14:
+               return (V[vn] - 32767.0) / 100.0;  
+       elif code==15:
+               return math.exp((V[vn]-32767.0)/1000.0); 
+       elif code==16:
+               return V[vn]/32.0; 
+       else:
+               return 0;
+
+def getName(code       ):
+       if code==1:
+               return ["Temperatur","C"]
+       if code==2:
+               return ["Druck","hPa"]
+       if code==3:
+               return ["Beleuchtungsstaerke","lux"]
+       if code==4:
+               return ["Luftfeuchte","%%"]
+       if code==5:
+               return ["Konstante",""]
+       if code==6:
+               return ["Spannung","V"]
+       if code==7:
+               return ["Strom","mA"]
+       if code==8:
+               return ["VOC","ppm"]
+       if code==9:
+               return ["Counter",""]
+       return []
+
+
+def owCom(dev,send,rcount):
+       cmd=toolstr+id2string(dev)
+       #for i in range(8):
+       #       cmd=cmd+"%02X" %(dev[7-i])
+       cmd=cmd+" "
+       for b in send:
+               cmd=cmd+"%02X" % (b)
+       for i in range(rcount):
+               cmd=cmd+"FF"
+       #print(cmd.split(' '));
+       p = subprocess.Popen(cmd.split(' '), shell=False, bufsize=14000, stdin=subprocess.PIPE, stdout=subprocess.PIPE)
+       p.wait()
+       s=p.stdout.read().decode("utf-8")
+       l=s.split("\n");
+       #print(l[2])
+       bl=[]
+       for i in range(int(len(l[2])/2)):
+               i2=i*2;
+               bl.append(int(l[2][i2:i2+2],16))
+       return bl
+
+def owComStr(dev,sendstr):
+       cmd=toolstr+id2string(dev)
+       #for i in range(8):
+       #       cmd=cmd+"%02X" %(dev[7-i])
+       cmd=cmd+" "+sendstr
+       p = subprocess.Popen(cmd.split(' '), shell=False, bufsize=14000, stdin=subprocess.PIPE, stdout=subprocess.PIPE)
+       p.wait()
+       s=p.stdout.read().decode("utf-8")
+       #print(s);
+       ll=s.split("\n");
+       bll=[]
+       for l in ll[2:]:
+               bl=[]
+               for i in range(int(len(l)/2)):
+                       i2=i*2;
+                       bl.append(int(l[i2:i2+2],16))
+               bll.append(bl)
+       return bll
+
+def getValues(dev,voc):
+       pl=[]
+       #print(id2string(dev[0]),voc)
+       if dev[0][0]==0x26:
+               vnok=1
+               rc=0
+               while (vnok):
+                       sbl=owComStr(dev[0],"4E000F_RB4_R_P7044_R_P70B800_RBE00FFFFFFFFFFFFFFFFFF_R4E0000_RB4_R_P70B800_RBE00FFFFFFFFFFFFFFFFFF_RBE03FFFFFFFFFFFFFFFFFF")
+                       #print(sbl)
+                       sb=sbl[4]
+                       VDD=(sb[5]+sb[6]*256)
+                       sb=sbl[8]
+                       VAD=(sb[5]+sb[6]*256)
+                       Temp=(sb[3]+sb[4]*256)
+                       if (sb[4] & 0x80):
+                               Temp-=0x10000
+                       curr=sb[7]+sb[8]*256
+                       if (sb[8] & 0x80):
+                               curr-=0x10000
+                       vals=[Temp,VDD,VAD,curr]
+                       formellist=[6,8,7,8]
+                       if dev[1][0]!=0xFF:
+                               formellist=[]
+                               for i in range(4):
+                                       if (dev[1][i*2+1])!=0:
+                                               formellist.append(dev[1][i*2+1])
+                                       else:
+                                               break
+                       cvals=[]
+                       for i in range(len(formellist)):
+                               cvals.append(calculateValues(formellist[i],vals,i))
+                       if (cvals[2]<=110):
+                               vnok=0
+                       else:
+                               rc=rc+1
+                               if (rc==3):
+                                       vnok=0
+                                       cvals[2]=100
+                       if voc!=0:
+                               #R0,VS,Corr,cmode,RS,RSR0,VOC1,VOC2
+                               sb=sbl[9]
+                               R0=(sb[2]+sb[3]*256)/100.0
+                               VS=(sb[4]+sb[5]*256)/10000.0
+                               Corr=(sb[7]+sb[8]*256)/1000.0
+                               cmode=sb[6]
+                               RS=(3/VS-1)*30
+                               RSR0=(RS/R0)
+                               VOC1=RSR0*Corr
+                               VOC2=RSR0/Corr
+                               cvals.append(R0)
+                               cvals.append(VS)
+                               cvals.append(Corr)
+                               cvals.append(cmode)
+                               cvals.append(RS)
+                               cvals.append(RSR0)
+                               cvals.append(VOC1)
+                               cvals.append(VOC2)
+               return cvals
+       if dev[0][0]==0x28:
+               sbl=owComStr(dev[0],"44_R_PFF_PFF_PFF_PFFBEFFFFFFFFFFFFFFFFFF")
+               Temp=sbl[1][1]+sbl[1][2]*256
+               if (sbl[1][2] & 0x80):
+                       Temp=-(Temp&0x7FFF)
+               if dev[1][0]!=0xFF:
+                       return [calculateValues(dev[1][1],[Temp],0)]
+               else:
+                       return [calculateValues(1,[Temp],0)]
+       return []
+
+       
+def owList(): 
+       cmd=toolstr[0:-3]
+       print(cmd)
+       p = subprocess.Popen(["./owtools","USB1"], shell=False, bufsize=14000, stdin=subprocess.PIPE, stdout=subprocess.PIPE)
+       p.wait()
+       s=p.stdout.read()
+       l=s.split("\n")
+       #print(l);
+       l=l[1:-1]
+       devlist=[]
+       ic=0
+       for d in l:
+               dev=[]
+               bl=[]
+               for i in range(8):
+                       i2=14-i*2;
+                       bl.append(int(d[i2:i2+2],16))
+               dev.append(bl)
+               #print(bl)
+               config=owCom(bl,[0x85],18)
+               #print(config)
+               if (config[1]==0xFF):
+                       if (bl[0]==0x26):
+                               config=[0,1,6,6,8,4,7,7,8,0]
+                       if (bl[0]==0x28):
+                               config=[0,1,1,0,0,0,0,0,0,0]
+               dev.append(config[1:])
+               bls=id2string(bl)
+               cs="%i: " %(ic)
+               ic=ic+1
+               cs=cs+bls+": "
+               if bls in devdict:
+                       cs=cs+devdict[bls].split(",")[0].split(" ")[1]+" "
+               for i in range(4):
+                       c=config[i*2+1]
+                       if (c==0xFF):
+                               cs=cs+"Noconfig "
+                               config=[0,0,0,0,0,0,0,0,0,0]
+                               break
+                       if (c==0):
+                               break
+                       cs=cs+getName(c)[0]+" "
+               #voc=0
+               #if bls in devdict:
+               #       if "VOC" in devdict[bls]:
+               #               voc=1
+               #l=getValues([bl,config[1:]],voc)
+               #for v in l:
+               #       cs=cs+" %0.2f " %(v)
+               print(cs)
+               ddev=0
+               vm=0
+               if config[1]==0x08:
+                       vm=1
+               #print("Test_configs")
+               i=0
+               for dv in devlist:
+                       #print("c",dv[1][9:16])
+                       #print("d",bl[0:7])
+                       if dv[1][9:16]==bl[0:7]:
+                               print("Double Device")
+                               ddev=1
+                               dv.append(dev[0])
+                               dv.append(dev[1])
+                               #if vm==1:
+                                       #voc_marker[i]=2
+                       i=i+1
+               #if ddev==0:
+               devlist.append(dev)
+                       #voc_marker.append(vm)
+               #print("devlist",devlist)
+       return devlist
+
+dl=owList()
+#for d in dl:
+#      print(d)
+
+while (1):
+       lt = time.localtime()
+       vline=time.strftime("%d#%m#%Y %H:%M:%S\t", lt)
+       n = datetime.datetime.now()
+       unix_timestamp = time.mktime(n.timetuple())# works if Python >= 3.3
+       for d in dl:
+               ds=id2string(d[0])
+               bezeichnung="not in List"
+               if ds in devdict:
+                       bezeichnung=devdict[ds].split(",")[0].split(" ")[1]+" "
+               vnames=[]
+               for i in range(4):
+                       c=d[1][i*2]
+                       if (c==0):
+                               break
+                       name=getName(c)
+                       if name!=[]:
+                               vnames.append(name[0])
+               voc=0
+               if "VOC" in bezeichnung:
+                       voc=1
+                       vnames.append("R0")
+                       vnames.append("VS")
+                       vnames.append("Corr")
+                       vnames.append("cmode")
+                       vnames.append("RS")
+                       vnames.append("RSR0")
+                       vnames.append("VOC1")
+                       vnames.append("VOC2")
+               #print(ds)
+               l=getValues([d[0],d[1]],voc)
+               s=vline+"%i" %(unix_timestamp)
+               for i in range(len(l)):
+                       print("%s %s: %0.2f " %(bezeichnung,vnames[i],l[i]))
+                       s=s+"\t%0.4f" % (l[i])
+               fname="log_%s.ow1" %(ds)
+               writeheader=1
+               if os.path.exists(fname):
+                       writeheader=0
+               f=open(fname,"a")
+               if writeheader==1:
+                       sh="time\tunixtime"
+                       for i in range(len(l)):
+                               sh=sh+"\t%s" % (vnames[i])
+                       f.write(sh+"\n")
+               f.write(s.replace(".",",").replace("#",".")+"\n")
+               f.close()
+       #execfile("separate1.py")
+       os.system("python separate1.py")
+       print("--------------------")
+       n = datetime.datetime.now()
+       unix_timestamp1 = time.mktime(n.timetuple())# works if Python >= 3.3
+       d=unix_timestamp1-unix_timestamp
+       print (d)
+       print("--------------------")
+       time.sleep(120-d)
+       
+       
\ No newline at end of file
diff --git a/stest/main.cpp b/stest/main.cpp
new file mode 100644 (file)
index 0000000..c1ca42f
--- /dev/null
@@ -0,0 +1,184 @@
+//============================================================================
+// Name        : owtools.cpp
+// Author      : 
+// Version     :
+// Copyright   : Your copyright notice
+// Description : Hello World in C++, Ansi-style
+//============================================================================
+
+#include <iostream>
+#include <queue>
+using namespace std;
+extern "C" {
+#include <ownet.h>
+}
+
+#include <stdio.h>
+#include <stdlib.h>
+#include <string.h>
+#include <stdint.h>
+
+
+#include <unistd.h>
+#include <sys/types.h>
+#include <sys/socket.h>
+#include <netinet/in.h>
+
+
+
+unsigned char conf2(const char *s) {
+       unsigned char b = 0;
+       for (int i = 0; i < 2; i++) {
+               b = b * 16;
+               if ((s[i] >= '0') && (s[i] <= '9')) {
+                       b += s[i] - '0';
+               } else
+               if ((s[i] >= 'A') && (s[i] <= 'F')) {
+                       b += s[i] - 'A'+10;
+               } else
+               if ((s[i] >= 'a') && (s[i] <= 'f')) {
+                       b += s[i] - 'a'+10;
+               }
+               
+       }
+       return b;
+}
+
+void strcpys(char *s, const char* d,bool up) {
+       if (strlen(d) > 7990) {
+               strncpy(s, d, 7990);
+               s[200] = 0;
+       }
+       else strcpy(s, d);
+       if (up) {
+               for (int i = 0; i<strlen(s); i++)
+                       if ((s[i] >= 'a') && (s[i] <= 'z'))
+                               s[i] += 'A' - 'a';
+       }
+}
+
+int main(int argc, char *argv[]) {
+       uchar SNum[8];
+       int rslt, cnt, i;
+       uchar send_block[256];
+       uchar send_cnt = 0;
+       int portnum;
+       char adapter[20];
+       int found = 0;
+       int rw = 0;
+       int err = 0;
+       char s[8000];
+       int adt = 0;
+       int mod = 0;
+       if (argc >= 2) {
+               strcpys(s, argv[1],true);
+               
+               
+               if (strncmp(s,"USB",3)==0) {adt = 6;}
+               if (strncmp(s, "COM", 3) == 0) { adt = 5; }
+               if (adt != 0) {
+                       strcpy(s, argv[1] + 3);
+                       sprintf(adapter, "DS2490-%s\0",s);
+                       //sprintf(adapter, "{%s,%i}\0",s,adt);
+                       printf("Open Port %s\n", argv[1]);
+                       if ((portnum = owAcquireEx(adapter)) < 0) {
+                               printf("ERROR \n", adt);
+                       }
+                       else mod = 1;
+
+               } 
+               if ((argc == 2) && (mod == 1)) mod = 2;
+               if (argc > 2) {
+                       strcpys(s, argv[2],true);
+                       if (strncmp(s, "DC", 2) == 0) {
+                               if (argc > 3) {
+                                       if (strlen(argv[3])>=16)
+                                       for (int i = 0; i < 16; i += 2) {
+                                               SNum[7 - (i / 2)] = conf2(argv[3] + i);
+
+                                       }
+                                       printf("Select: %02X%02X%02X%02X%02X%02X%02X%02X\n", SNum[7], SNum[6], SNum[5], SNum[4], SNum[3], SNum[2], SNum[1], SNum[0]);
+                                       mod = 3;
+                               }
+
+                       }
+               }
+               if ((mod == 3) && (argc>4)) {
+                       strcpys(s, argv[4], true);
+                       mod = 4;
+               }
+       
+       }
+
+       if (mod == 2) {
+               rslt = owFirst(portnum, TRUE, FALSE);
+               cnt = 0;
+               while (rslt) {
+                       cnt++;
+                       owSerialNum(portnum, &SNum[0], TRUE);
+                       printf("%02X%02X%02X%02X%02X%02X%02X%02X\n", SNum[7], SNum[6], SNum[5], SNum[4], SNum[3], SNum[2], SNum[1], SNum[0]);
+                       //                      fprintf(ft,"%02X%02X%02X%02X%02X%02X%02X%02X\n",SNum[7],SNum[6],SNum[5],SNum[4],SNum[3],SNum[2],SNum[1],SNum[0]);
+/*                     switch (SNum[0]) {
+
+
+                               case 0x14: {
+                                       //TestDS2430(portnum,&SNum[0]);
+                                       //scanf("%i",&i);
+                                       //ResetDS2430(portnum,&SNum[0]);
+                                       //uchar id[]={0x14,0xF5 ,0xEA ,0x24 ,0x06 ,0x00 ,0x00 ,0x5E};
+                                       //SetIDDS2430(portnum,&SNum[0],id);
+                                       if (rw) WriteDS2430(portnum, &SNum[0]); else ReadDS2430(portnum, &SNum[0]);
+                                       //WriteDS2430(portnum,&SNum[0],"5E00000624EAF514.bin");
+                                       break;
+                               }
+                               case 0x23: {
+                                       //TestDS2433(portnum,&SNum[0]);
+                                       //TestDS2433_reset(portnum,&SNum[0]);
+                                       //scanf("%i",&i);
+                                       if (rw) WriteDS2433(portnum, &SNum[0]); else ReadDS2433(portnum, &SNum[0]);
+                                       break;
+                               }
+                               }*/
+                       rslt = owNext(portnum, TRUE, FALSE);
+               }
+       }
+       if (mod == 4) {
+               owSerialNum(portnum, SNum, FALSE);
+               strcat(s, "_R");
+               int len = strlen(s);
+               int i = 0;
+               while (i < len) {
+                       if (s[i] == '_') {
+                               if (s[i + 1] == 'R') {
+                                       if (owAccess(portnum)) {
+                                               if (owBlock(portnum, FALSE, send_block, send_cnt)) {
+                                                       for (int j = 0; j < send_cnt; j++) {
+                                                               printf("%02X", send_block[j]);
+                                                       }
+                                                       printf("\n");
+                                               }
+                                               else printf("ERROR RESET\n");
+                                       }
+                                       else printf("ERROR SEND\n");
+                                       send_cnt = 0;
+                               }
+                               if (s[i + 1] == 'P') {
+                                       if (i + 2 < len) {
+                                               i += 2;
+                                               msDelay(conf2(s + i));
+                                               
+                                       }
+                               }
+                       }
+                       else {
+                               send_block[send_cnt++] = conf2(s + i);
+                       }
+                       i += 2;
+               
+                       
+               }
+       }
+       if (mod>0) owRelease(portnum);
+       
+       return 0;
+}
diff --git a/stest/separate1.py b/stest/separate1.py
new file mode 100644 (file)
index 0000000..bffda77
--- /dev/null
@@ -0,0 +1,103 @@
+import sys
+import os
+import os.path
+import subprocess
+import io
+import time
+import math
+import shutil
+import datetime
+
+
+#Parameter:
+#a = 7.5, b = 237.3 fuer T >= 0
+#a = 7.6, b = 240.7 fuer T < 0 ueber Wasser (Taupunkt)
+#a = 9.5, b = 265.5 fuer T < 0 ueber Eis (Frostpunkt)
+a=7.5
+b=237.3
+Rs = 8314.3 #J/(kmol*K) (universelle Gaskonstante)
+mw = 18.016 #kg/kmol (Molekulargewicht des Wasserdampfes)
+
+def SDD(T):
+       return 6.1078 * 10**((a*T)/(b+T))
+       
+def AF1(r,T):
+       return r/100.0*SDD(T)/(T+273.15)*mw/Rs*10000
+
+def RF1(a,T):
+       return a*100/(SDD(T)/(T+273.15)*mw/Rs*10000)    
+#print(0.5*SDD(20)/(20+273.15)*mw/Rs*10000)
+
+def rdiff(r1,t1,t2):
+       return (r1)-RF1(AF1(r1,t1),t2)
+
+
+def calcDerivation(Name,Valuetype,Value,T):
+       return [0.5,0.5]
+
+
+devdict={}
+devwholist=[]
+f=open("DEVLIST.txt","r")
+for l in f.readlines():
+       ls=l.split(" ")
+       if (len(ls)>1):
+               devdict[ls[0]]=l.replace("\n","").split(",")[0].split(" ")[1]
+               devwholist.append(ls[0])
+f.close()
+
+sel_list=["Temperatur","Luftfeuchte","Beleuchtungsstaerke","R0","VOC","RS","Corr"]
+data=[]
+for s in sel_list:
+       data.append(["Time"])
+
+for ds in devwholist:   #fuer Jedes Geraet in DEVLIST.txt
+       fname="log_%s.ow1" %(ds)  #Sind Daten da?
+       if os.path.exists(fname):
+               f=open(fname,"r")  #Lesen
+               lines=f.readlines()
+               ti=lines[0][:-1].split("\t")  #Ueberschriften aufteilen
+               i=0
+               if ("Temperatur" in ti):
+                       tempindex=ti.index("Temperatur")
+               for t in ti:   #fuer jedes Element in der Ueberschrift
+                       if t in sel_list:  #schauen ob es Uebernommen werden soll
+                               p=sel_list.index(t)  #schaue nach Nummer in der Datenbank
+                               data[p][0]=data[p][0]+","+ds+" "+devdict[ds] #hinzufuegen der Ueberschrift in der Tabelle
+                               if len(data[p])==1: #erstes Element, Time einfuegen und neue zeile anlegen
+                                       for l in lines[1:]:
+                                               l=l[:-1]
+                                               ll=l.split("\t")
+                                               la=ll[0].split(" ")
+                                               lb=la[0].split(".")
+                                               ts=lb[2]+"/"+lb[1]+"/"+lb[0]+" "+la[1]
+                                               data[p].append(ts)
+                               j=1;
+                               for l in lines[1:]:
+                                       #print(ll)
+                                       l=l[:-1] #\n wegmachen
+                                       ll=l.split("\t") #telen
+                                       fl=float(ll[i].replace(",","."))
+                                       if "VOC" in devdict[ds] or "Lum" in devdict[ds]:
+                                               if (t=="Temperatur"):
+                                                       ltemp=fl
+                                                       fl=fl-1
+                                               if (t=="Luftfeuchte"):
+                                                       ltemp=float(ll[tempindex].replace(",","."))
+                                                       fl=fl-rdiff(fl,ltemp,ltemp-1)
+                                       data[p][j]=data[p][j]+",%0.2f" % (fl)
+                                       j=j+1
+                       i=i+1
+               f.close()               
+                        
+       
+#print data
+
+for i in range(len(sel_list)):
+       f=open("/var/www/html/"+sel_list[i]+".csv","w")
+       for l in data[i]:
+               f.write(l+"\n")
+       f.close()
+
+       
+
diff --git a/tools_cmd/IB10E64.dll b/tools_cmd/IB10E64.dll
new file mode 100644 (file)
index 0000000..41580e1
Binary files /dev/null and b/tools_cmd/IB10E64.dll differ
diff --git a/tools_cmd/IB97E64.dll b/tools_cmd/IB97E64.dll
new file mode 100644 (file)
index 0000000..db02450
Binary files /dev/null and b/tools_cmd/IB97E64.dll differ
diff --git a/tools_cmd/IB97U64.dll b/tools_cmd/IB97U64.dll
new file mode 100644 (file)
index 0000000..1a29cd7
Binary files /dev/null and b/tools_cmd/IB97U64.dll differ
diff --git a/tools_cmd/IBFS64.dll b/tools_cmd/IBFS64.dll
new file mode 100644 (file)
index 0000000..d81a266
Binary files /dev/null and b/tools_cmd/IBFS64.dll differ
diff --git a/tools_cmd/IBUSB64.dll b/tools_cmd/IBUSB64.dll
new file mode 100644 (file)
index 0000000..9c1403c
Binary files /dev/null and b/tools_cmd/IBUSB64.dll differ
diff --git a/tools_cmd/bin/ib90usb.dll b/tools_cmd/bin/ib90usb.dll
new file mode 100644 (file)
index 0000000..ca0f069
Binary files /dev/null and b/tools_cmd/bin/ib90usb.dll differ
diff --git a/tools_cmd/bin/ib97e32.dll b/tools_cmd/bin/ib97e32.dll
new file mode 100644 (file)
index 0000000..6e6db4b
Binary files /dev/null and b/tools_cmd/bin/ib97e32.dll differ
diff --git a/tools_cmd/bin/ib97u32.dll b/tools_cmd/bin/ib97u32.dll
new file mode 100644 (file)
index 0000000..c08f1f4
Binary files /dev/null and b/tools_cmd/bin/ib97u32.dll differ
diff --git a/tools_cmd/bin/ibfs32.dll b/tools_cmd/bin/ibfs32.dll
new file mode 100644 (file)
index 0000000..bced541
Binary files /dev/null and b/tools_cmd/bin/ibfs32.dll differ
diff --git a/tools_cmd/bin/ibusb32.dll b/tools_cmd/bin/ibusb32.dll
new file mode 100644 (file)
index 0000000..772fa8d
Binary files /dev/null and b/tools_cmd/bin/ibusb32.dll differ
diff --git a/tools_cmd/ib90usb.dll b/tools_cmd/ib90usb.dll
new file mode 100644 (file)
index 0000000..ca0f069
Binary files /dev/null and b/tools_cmd/ib90usb.dll differ
diff --git a/tools_cmd/ib97e32.dll b/tools_cmd/ib97e32.dll
new file mode 100644 (file)
index 0000000..6e6db4b
Binary files /dev/null and b/tools_cmd/ib97e32.dll differ
diff --git a/tools_cmd/ib97u32.dll b/tools_cmd/ib97u32.dll
new file mode 100644 (file)
index 0000000..c08f1f4
Binary files /dev/null and b/tools_cmd/ib97u32.dll differ
diff --git a/tools_cmd/ibfs32.dll b/tools_cmd/ibfs32.dll
new file mode 100644 (file)
index 0000000..bced541
Binary files /dev/null and b/tools_cmd/ibfs32.dll differ
diff --git a/tools_cmd/ibtmjava.dll b/tools_cmd/ibtmjava.dll
new file mode 100644 (file)
index 0000000..c1a4d85
Binary files /dev/null and b/tools_cmd/ibtmjava.dll differ
diff --git a/tools_cmd/ibtmjava64.dll b/tools_cmd/ibtmjava64.dll
new file mode 100644 (file)
index 0000000..be0c59d
Binary files /dev/null and b/tools_cmd/ibtmjava64.dll differ
diff --git a/tools_cmd/ibusb32.dll b/tools_cmd/ibusb32.dll
new file mode 100644 (file)
index 0000000..772fa8d
Binary files /dev/null and b/tools_cmd/ibusb32.dll differ
diff --git a/tools_cmd/owtools.sdf b/tools_cmd/owtools.sdf
new file mode 100644 (file)
index 0000000..16df8ea
Binary files /dev/null and b/tools_cmd/owtools.sdf differ
diff --git a/tools_cmd/owtools.sln b/tools_cmd/owtools.sln
new file mode 100644 (file)
index 0000000..50196c8
--- /dev/null
@@ -0,0 +1,22 @@
+
+Microsoft Visual Studio Solution File, Format Version 12.00
+# Visual Studio 2013
+VisualStudioVersion = 12.0.30501.0
+MinimumVisualStudioVersion = 10.0.40219.1
+Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "rwOW", "rwOW\rwOW.vcxproj", "{5D2435E4-D963-4533-AC3B-C4E0F2C251DB}"
+EndProject
+Global
+       GlobalSection(SolutionConfigurationPlatforms) = preSolution
+               Debug|Win32 = Debug|Win32
+               Release|Win32 = Release|Win32
+       EndGlobalSection
+       GlobalSection(ProjectConfigurationPlatforms) = postSolution
+               {5D2435E4-D963-4533-AC3B-C4E0F2C251DB}.Debug|Win32.ActiveCfg = Debug|Win32
+               {5D2435E4-D963-4533-AC3B-C4E0F2C251DB}.Debug|Win32.Build.0 = Debug|Win32
+               {5D2435E4-D963-4533-AC3B-C4E0F2C251DB}.Release|Win32.ActiveCfg = Release|Win32
+               {5D2435E4-D963-4533-AC3B-C4E0F2C251DB}.Release|Win32.Build.0 = Release|Win32
+       EndGlobalSection
+       GlobalSection(SolutionProperties) = preSolution
+               HideSolutionNode = FALSE
+       EndGlobalSection
+EndGlobal
diff --git a/tools_cmd/rwOW/crcutil.c b/tools_cmd/rwOW/crcutil.c
new file mode 100644 (file)
index 0000000..7ae13cb
--- /dev/null
@@ -0,0 +1,119 @@
+//---------------------------------------------------------------------------
+// Copyright (C) 2000 Dallas Semiconductor Corporation, All Rights Reserved.
+//
+// Permission is hereby granted, free of charge, to any person obtaining a
+// copy of this software and associated documentation files (the "Software"),
+// to deal in the Software without restriction, including without limitation
+// the rights to use, copy, modify, merge, publish, distribute, sublicense,
+// and/or sell copies of the Software, and to permit persons to whom the
+// Software is furnished to do so, subject to the following conditions:
+//
+// The above copyright notice and this permission notice shall be included
+// in all copies or substantial portions of the Software.
+//
+// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
+// OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
+// MERCHANTABILITY,  FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
+// IN NO EVENT SHALL DALLAS SEMICONDUCTOR BE LIABLE FOR ANY CLAIM, DAMAGES
+// OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
+// ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
+// OTHER DEALINGS IN THE SOFTWARE.
+//
+// Except as contained in this notice, the name of Dallas Semiconductor
+// shall not be used except as stated in the Dallas Semiconductor
+// Branding Policy.
+//--------------------------------------------------------------------------
+//
+//  crcutil.c - Keeps track of the CRC for 16 and 8 bit operations
+//  version 2.00
+
+// Include files
+#include "ownet.h"
+
+// Local global variables
+ushort utilcrc16[MAX_PORTNUM];
+uchar utilcrc8[MAX_PORTNUM];
+static short oddparity[16] = { 0, 1, 1, 0, 1, 0, 0, 1, 1, 0, 0, 1, 0, 1, 1, 0 };
+static uchar dscrc_table[] = {
+        0, 94,188,226, 97, 63,221,131,194,156,126, 32,163,253, 31, 65,
+      157,195, 33,127,252,162, 64, 30, 95,  1,227,189, 62, 96,130,220,
+       35,125,159,193, 66, 28,254,160,225,191, 93,  3,128,222, 60, 98,
+      190,224,  2, 92,223,129, 99, 61,124, 34,192,158, 29, 67,161,255,
+       70, 24,250,164, 39,121,155,197,132,218, 56,102,229,187, 89,  7,
+      219,133,103, 57,186,228,  6, 88, 25, 71,165,251,120, 38,196,154,
+      101, 59,217,135,  4, 90,184,230,167,249, 27, 69,198,152,122, 36,
+      248,166, 68, 26,153,199, 37,123, 58,100,134,216, 91,  5,231,185,
+      140,210, 48,110,237,179, 81, 15, 78, 16,242,172, 47,113,147,205,
+       17, 79,173,243,112, 46,204,146,211,141,111, 49,178,236, 14, 80,
+      175,241, 19, 77,206,144,114, 44,109, 51,209,143, 12, 82,176,238,
+       50,108,142,208, 83, 13,239,177,240,174, 76, 18,145,207, 45,115,
+      202,148,118, 40,171,245, 23, 73,  8, 86,180,234,105, 55,213,139,
+       87,  9,235,181, 54,104,138,212,149,203, 41,119,244,170, 72, 22,
+      233,183, 85, 11,136,214, 52,106, 43,117,151,201, 74, 20,246,168,
+      116, 42,200,150, 21, 75,169,247,182,232, 10, 84,215,137,107, 53};
+
+//--------------------------------------------------------------------------
+// Reset crc16 to the value passed in
+//
+// 'reset' - data to set crc16 to.
+//
+void setcrc16(int portnum, ushort reset)
+{
+   utilcrc16[portnum&0x0FF] = reset;
+   return;
+}
+
+//--------------------------------------------------------------------------
+// Reset crc8 to the value passed in
+//
+// 'portnum'  - number 0 to MAX_PORTNUM-1.  This number is provided to
+//              indicate the symbolic port number.
+// 'reset'    - data to set crc8 to
+//
+void setcrc8(int portnum, uchar reset)
+{
+   utilcrc8[portnum&0x0FF] = reset;
+   return;
+}
+
+//--------------------------------------------------------------------------
+// Calculate a new CRC16 from the input data short.  Return the current
+// CRC16 and also update the global variable CRC16.
+//
+// 'portnum'  - number 0 to MAX_PORTNUM-1.  This number is provided to
+//              indicate the symbolic port number.
+// 'data'     - data to perform a CRC16 on
+//
+// Returns: the current CRC16
+//
+ushort docrc16(int portnum, ushort cdata)
+{
+   cdata = (cdata ^ (utilcrc16[portnum&0x0FF] & 0xff)) & 0xff;
+   utilcrc16[portnum&0x0FF] >>= 8;
+
+   if (oddparity[cdata & 0xf] ^ oddparity[cdata >> 4])
+     utilcrc16[portnum&0x0FF] ^= 0xc001;
+
+   cdata <<= 6;
+   utilcrc16[portnum&0x0FF]   ^= cdata;
+   cdata <<= 1;
+   utilcrc16[portnum&0x0FF]   ^= cdata;
+
+   return utilcrc16[portnum&0x0FF];
+}
+
+//--------------------------------------------------------------------------
+// Update the Dallas Semiconductor One Wire CRC (utilcrc8) from the global
+// variable utilcrc8 and the argument.
+//
+// 'portnum'  - number 0 to MAX_PORTNUM-1.  This number is provided to
+//              indicate the symbolic port number.
+// 'x'        - data byte to calculate the 8 bit crc from
+//
+// Returns: the updated utilcrc8.
+//
+uchar docrc8(int portnum, uchar x)
+{
+   utilcrc8[portnum&0x0FF] = dscrc_table[utilcrc8[portnum&0x0FF] ^ x];
+   return utilcrc8[portnum&0x0FF];
+}
diff --git a/tools_cmd/rwOW/ibfs32.lib b/tools_cmd/rwOW/ibfs32.lib
new file mode 100644 (file)
index 0000000..a856f6e
Binary files /dev/null and b/tools_cmd/rwOW/ibfs32.lib differ
diff --git a/tools_cmd/rwOW/ibtmexcw.h b/tools_cmd/rwOW/ibtmexcw.h
new file mode 100644 (file)
index 0000000..6c1bfbe
--- /dev/null
@@ -0,0 +1,234 @@
+/*---------------------------------------------------------------------------
+* Copyright Â© 1992-2008 Maxim Integrated Products, All Rights Reserved.
+*
+* Permission is hereby granted, free of charge, to any person obtaining a
+* copy of this software and associated documentation files (the "Software"),
+* to deal in the Software without restriction, including without limitation
+* the rights to use, copy, modify, merge, publish, distribute, sublicense,
+* and/or sell copies of the Software, and to permit persons to whom the
+* Software is furnished to do so, subject to the following conditions:
+*
+* The above copyright notice and this permission notice shall be included
+* in all copies or substantial portions of the Software.
+*
+* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
+* OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
+* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
+* IN NO EVENT SHALL MAXIM INTEGRATED PRODUCTS BE LIABLE FOR ANY CLAIM, DAMAGES
+* OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
+* ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
+* OTHER DEALINGS IN THE SOFTWARE.
+*
+* Except as contained in this notice, the name of Maxim Integrated Products
+* shall not be used except as stated in the Maxim Integrated Products
+* Branding Policy.
+*---------------------------------------------------------------------------
+* Version 4.01
+*/
+
+/* includes */
+#include <stdlib.h>
+#include <string.h>
+#include <ctype.h>
+#include <windows.h>
+#ifndef _WIN32_WCE
+#include <stdio.h>
+#include <conio.h>
+#include <dos.h>
+#include <fcntl.h>
+#include <io.h>
+#include <time.h>
+#endif
+
+/* type defs */
+typedef unsigned char uchar;
+typedef unsigned short ushort;
+typedef unsigned long ulong;
+
+/* typedef structure sent back by TMEX routines */
+typedef struct 
+{
+uchar name[4];
+uchar extension;
+uchar startpage;
+uchar numpages;
+uchar attrib;
+uchar bitmap[32];
+} FileEntry;
+
+/* structure to hold directory path */
+typedef struct
+{
+uchar NumEntries; /* number of entries in path 0-10 */
+char Ref; /* reference character '\' or '.' */
+char Entries[10][4]; /* sub-directory entry names */ 
+} DirectoryPath;
+
+/* Holds info of each object in the Directory list */
+struct DirNumInfo 
+{ 
+unsigned char Name[4];
+unsigned char Extension;
+char Attrib;
+};
+
+/* structure to hold exportable device parameters by family code (3.11) */
+typedef struct
+{
+short features[32];
+char dscrptn[255];
+} Specification;
+
+
+/* Error codes from TMEX functions */
+#define NO_DEVICE -1 
+#define WRONG_TYPE -2 
+#define FILE_READ_ERR -3 
+#define BUFFER_TOO_SMALL -4 
+#define HANDLE_NOT_AVAIL -5 
+#define FILE_NOT_FOUND -6 
+#define REPEAT_FILE -7 
+#define HANDLE_NOT_USED -8 
+#define FILE_WRITE_ONLY -9 
+#define OUT_OF_SPACE -10 
+#define FILE_WRITE_ERR -11 
+#define TMFILE_READ_ONLY -12 
+#define FUNC_NOT_SUP -13 
+#define BAD_FILENAME -14 
+#define CANT_DEL_READ_ONLY -15 
+#define HANDLE_NOT_EXIST -16 
+#define ONE_WIRE_PORT_ERROR -17 
+#define INVALID_DIRECTORY -18 
+#define DIRECTORY_NOT_EMPTY -19 
+#define UNABLE_TO_CREATE_DIR -20 
+#define NO_PROGRAM_JOB -21 
+#define PROGRAM_WRITE_PROTECT -22
+#define NON_PROGRAM_PARTS -23 
+#define ADDFILE_TERMINATED -24 
+#define TIMEOUT -25 
+#define INVALID_ARGUMENT -26 
+#define BAD_ACK -27 
+#define INVALID_SESSION -200
+#define NO_BASDRV_FOUND -201
+
+/* Basic physical level error codes */
+#define BPORT_NOT_INITIALIZED -1 
+#define BPORT_NOT_EXIST -2 
+#define BNO_SUCH_FUNCTION -3 
+
+/* Transport level error codes */
+#define TERROR_READ_WRITE -4 
+#define TBUFFER_TOO_SMALL -5 
+#define TDEVICE_TOO_SMALL -6 
+#define TNO_DEVICE -7 
+#define TBLOCK_TOO_BIG -8 
+#define TWRONG_TYPE -9 
+#define TPAGE_REDIRECTED -10
+#define TPROGRAM_NOT_POSSIBLE -11
+#define BCOM_FAILURE -12
+#define BCOM_EVENT -13
+
+/* for TMOneWireLevel */
+#define LEVEL_NORMAL 0
+#define LEVEL_STRONG_PULLUP 1
+#define LEVEL_BREAK 2
+#define LEVEL_PROGRAM 3 
+#define PRIMED_NONE 0
+#define PRIMED_BIT 1
+#define PRIMED_BYTE 2 
+#define LEVEL_READ 1
+#define LEVEL_SET 0
+
+/* misc */
+#define GENERAL_FAIL -2 
+#define BAD_ARGUMENT 50
+#define NO_DRIVERS 51
+#define KEY_ABORT 52
+#define OUT_MEMORY 53
+#define NORMAL_EXIT 0
+
+#define TRUE 1
+#define FALSE 0
+#define DIR_READ 1
+#define DIR_SET 0
+#define DIR_REMOVE 1
+#define DIR_MAKE 0
+
+/* for specification */
+#define NOMEM 0
+#define NVRAM 1
+#define EPROM1 2
+#define EPROM2 3
+#define EPROM3 4
+#define EEPROM1 5
+#define MNVRAM 6
+#define EEPROM2 7
+#define NVRAM2 8
+#define NVRAM3 9 
+#define FTR_REG_PAGES 0
+#define FTR_REG_LEN 1
+#define FTR_STAT_PAGES 2
+#define FTR_STAT_LEN 3
+#define FTR_MAX_COM 4 
+#define FTR_MEM_TYPE 5
+
+// session
+extern long __fastcall TMExtendedStartSession(short, short, void far *);
+extern short __fastcall TMValidSession(long); 
+extern short __fastcall TMEndSession(long); 
+extern short __fastcall Get_Version(char far *); 
+// file_operations
+extern short __fastcall TMFirstFile(long, void far *, FileEntry far *); 
+extern short __fastcall TMNextFile(long, void far *, FileEntry far *);
+extern short __fastcall TMOpenFile(long, void far *, FileEntry far *);
+extern short __fastcall TMCreateFile(long, void far *, short far *, FileEntry far *);
+extern short __fastcall TMCloseFile(long, void far *, short);
+extern short __fastcall TMReadFile(long, void far *, short, uchar far *, short);
+extern short __fastcall TMWriteFile(long, void far *, short, uchar far *, short);
+extern short __fastcall TMDeleteFile(long, void far *, FileEntry far *);
+extern short __fastcall TMFormat(long, void far *);
+extern short __fastcall TMAttribute(long, void far *, short, FileEntry far *);
+extern short __fastcall TMReNameFile(long, void far *, short, FileEntry far *); 
+extern short __fastcall TMChangeDirectory(long, void far *, short, DirectoryPath far *); 
+extern short __fastcall TMDirectoryMR(long, void far *, short, FileEntry far *);
+extern short __fastcall TMCreateProgramJob(long, void far *);
+extern short __fastcall TMDoProgramJob(long, void far *);
+extern short __fastcall TMWriteAddFile(long, void far *, short, short, short, uchar far *, short);
+extern short __fastcall TMTerminateAddFile(long, void far *, FileEntry far *);
+extern short __fastcall TMGetFamilySpec(long, void far *, Specification *); 
+// transport
+extern short __fastcall TMReadPacket(long, void far *, short, uchar far *, short);
+extern short __fastcall TMWritePacket(long, void far *, short, uchar far *, short);
+extern short __fastcall TMBlockIO(long, uchar far *, short);
+extern short __fastcall TMExtendedReadPage(long, void far *, short, uchar far *, short);
+extern short __fastcall TMProgramByte(long, void far *, short, short, short, short far *, short);
+extern short __fastcall TMProgramBlock(long, void far *, uchar far *, short, short, short far *); /* (3.11) */
+extern long __fastcall TMCRC(short, uchar far *, ushort, short); 
+// network
+extern short __fastcall TMSkipFamily(long, void far *); 
+extern short __fastcall TMFamilySearchSetup(long, void far *, short); 
+extern short __fastcall TMFirst(long, void far *);
+extern short __fastcall TMNext(long, void far *);
+extern short __fastcall TMAccess(long, void far *);
+extern short __fastcall TMOverAccess(long, void far *);
+extern short __fastcall TMStrongAccess(long, void far *);
+extern short __fastcall TMStrongAlarmAccess(long, void far *);
+extern short __fastcall TMRom(long, void far *, short far *);
+extern short __fastcall TMFirstAlarm(long, void far *);
+extern short __fastcall TMNextAlarm(long, void far *); 
+extern short __fastcall TMAutoOverDrive(long, void far *, short); 
+extern short __fastcall TMSearch(short, short, short, short); 
+// hardware_specific
+extern short __fastcall TMSetup(long);
+extern short __fastcall TMTouchByte(long, short);
+extern short __fastcall TMTouchReset(long);
+extern short __fastcall TMTouchBit(long, short);
+extern short __fastcall TMClose(long);
+extern short __fastcall TMProgramPulse(long); 
+extern short __fastcall TMOneWireCom(long, short, short); 
+extern short __fastcall TMOneWireLevel(long, short, short, short); 
+extern short __fastcall TMGetTypeVersion(short,char far *); 
+extern short __fastcall TMBlockStream(long, uchar far *, short);
+extern short __fastcall TMGetAdapterSpec(long, Specification far *); 
+extern short __fastcall TMReadDefaultPort(short far *, short far *); 
+
diff --git a/tools_cmd/rwOW/main.cpp b/tools_cmd/rwOW/main.cpp
new file mode 100644 (file)
index 0000000..184ffd7
--- /dev/null
@@ -0,0 +1,391 @@
+#define _CRT_SECURE_NO_WARNINGS 1
+extern "C" {
+#include "ownet.h"
+}
+#include <stdio.h>
+#include <stdlib.h>
+#include <string.h>
+
+FILE *fio;
+char s[100], fname[254];
+
+
+SMALLINT ReadDS2430(int portnum, uchar SerialNum[8]) {
+       uchar rt = FALSE;
+       uchar send_block[145];
+       uchar send_cnt = 0, i;
+       int address;
+       char s[100];
+       FILE *f;
+       sprintf(s, "%02X%02X%02X%02X%02X%02X%02X%02X.bin", SerialNum[7], SerialNum[6], SerialNum[5], SerialNum[4], SerialNum[3], SerialNum[2], SerialNum[1], SerialNum[0]);
+       fprintf(fio, ">14\n");
+       send_cnt = 0;
+       printf("Read Data MEM  \n");
+       if (!owAccess(portnum)) { printf("ERROR MATCH ROM \n"); return 1; }
+       send_block[send_cnt++] = 0xF0;
+       send_block[send_cnt++] = 0x00;
+       for (i = 0; i<32; i++) send_block[send_cnt++] = 0xFF;
+       if (!owBlock(portnum, FALSE, send_block, send_cnt))  { printf("ERROR RUN COMMAND \n"); return 1; }
+       for (i = 2; i<send_cnt; i++) { printf("%02X ", send_block[i]); fprintf(fio,"%02X ", send_block[i]); }
+       printf("\n");
+       fprintf(fio, "\n");
+       send_cnt = 0;
+       printf("Read App MEM  \n");
+       if (!owAccess(portnum)) { printf("ERROR MATCH ROM \n"); return 1; }
+       send_block[send_cnt++] = 0xC3;
+       send_block[send_cnt++] = 0x00;
+       for (i = 0; i<8; i++) send_block[send_cnt++] = 0xFF;
+       if (!owBlock(portnum, FALSE, send_block, send_cnt))  { printf("ERROR RUN COMMAND \n"); return 1; }
+       for (i = 2; i<send_cnt; i++) { printf("%02X ", send_block[i]); fprintf(fio, "%02X ", send_block[i]); }
+       printf("\n");
+       fprintf(fio, "\n");
+
+       send_cnt = 0;
+       printf("Read App State  \n");
+       if (!owAccess(portnum)) { printf("ERROR MATCH ROM \n"); return 1; }
+       send_block[send_cnt++] = 0x66;
+       for (i = 0; i<1; i++) send_block[send_cnt++] = 0xFF;
+       if (!owBlock(portnum, FALSE, send_block, send_cnt))  { printf("ERROR RUN COMMAND \n"); return 1; }
+       for (i = 1; i<send_cnt; i++) { printf("%02X ", send_block[i]);  fprintf(fio, "%02X ", send_block[i]); }
+       printf("\n");
+       fprintf(fio, "\n");
+}
+
+
+SMALLINT ReadDS2433(int portnum, uchar SerialNum[8]) {
+       uchar rt = FALSE;
+       uchar send_block[145];
+       uchar send_cnt = 0, i, j;
+       int address;
+       send_cnt = 0;
+       printf("-----> TEST DS2433 \n");
+       fprintf(fio, ">23\n");
+
+       send_cnt = 0;
+       printf("\nRead MEM ALL \n");
+       if (!owAccess(portnum)) { printf("ERROR MATCH ROM \n"); return 1; }
+       send_block[send_cnt++] = 0xF0;
+       send_block[send_cnt++] = 0x00;
+       send_block[send_cnt++] = 0x00;
+       for (j = 0; j<16; j++) {
+               for (i = 0; i<32; i++) send_block[send_cnt++] = 0xFF;
+               if (!owBlock(portnum, FALSE, send_block, send_cnt))  { printf("ERROR RUN COMMAND \n"); return 1; }
+               for (i = j?0:3; i < send_cnt; i++) { printf("%02X ", send_block[i]); fprintf(fio, "%02X ", send_block[i]); }
+               send_cnt = 0;
+               printf("\n");
+               fprintf(fio, "\n");
+       }
+
+}
+
+
+int findDev(uchar code) {
+       int find = 0;
+       fio = fopen(fname, "r");
+       while (!feof(fio)) {
+               s[0] = fgetc(fio);
+               if (s[0] == '>') {
+                       s[0] = fgetc(fio);
+                       s[1] = fgetc(fio);
+                       s[2] = 0;
+                       uchar w = strtol(s, NULL, 16);
+                       if (code ==w) return 1;
+               }
+       }
+       fclose(fio);
+       return 0;
+}
+
+
+
+SMALLINT WriteDS2433(int portnum, uchar SerialNum[8]) {
+       uchar rt = FALSE;
+       uchar send_block[145];
+       uchar send_cnt = 0, i, j;
+       int address;
+       send_cnt = 0;
+       printf("-----> TEST DS2433 \n");
+       if (findDev(0x23)) {
+               for (j = 0; j < 16; j++) {
+                       for (i = 0; i < 32; i++) {
+                               fscanf(fio, "%02X", &send_block[i + 3]);
+                       }
+                       if (!owAccess(portnum)) { printf("ERROR MATCH ROM \n"); return 1; }
+                       send_block[0] = 0x0F;
+                       send_block[1] = j << 5;
+                       send_block[2] = j >> 3;
+                       if (!owBlock(portnum, FALSE, send_block, 32 + 3))  { printf("ERROR RUN COMMAND \n"); return 1; }
+                       if (!owAccess(portnum)) { printf("ERROR MATCH ROM \n"); return 1; }
+                       send_cnt = 0;
+                       send_block[send_cnt++] = 0xAA;
+                       for (i = 0; i < 32 + 3; i++) send_block[send_cnt++] = 0xFF;
+                       if (!owBlock(portnum, FALSE, send_block, send_cnt))  { printf("ERROR RUN COMMAND \n"); return 1; }
+                       for (i = 0; i < send_cnt; i++) { printf("%02X ", send_block[i]); }
+                       if (!owAccess(portnum)) { printf("ERROR MATCH ROM \n"); return 1; }
+                       send_cnt = 0;
+                       send_block[send_cnt++] = 0x55;
+                       send_cnt += 3;
+                       if (!owBlock(portnum, FALSE, send_block, send_cnt))  { printf("ERROR RUN COMMAND \n"); return 1; }
+                       msDelay(100);
+                       printf("\n");
+               }
+       
+       }
+       fclose(fio);
+       return 0;
+
+
+}
+
+
+SMALLINT WriteDS2430(int portnum, uchar SerialNum[8]) {
+       uchar rt = FALSE;
+       uchar send_block[145];
+       uchar send_cnt = 0, i, j;
+       int address;
+       send_cnt = 0;
+       printf("-----> TEST DS2430 \n");
+       if (findDev(0x14)) {
+               for (i = 0; i < 32; i++) {
+                       fscanf(fio, "%02X", &send_block[i + 2]);
+               }
+               if (!owAccess(portnum)) { printf("ERROR MATCH ROM \n"); return 1; }
+               send_block[0] = 0x0F;
+               send_block[1] = 0;
+               if (!owBlock(portnum, FALSE, send_block, 32 + 2))  { printf("ERROR RUN COMMAND \n"); return 1; }
+               if (!owAccess(portnum)) { printf("ERROR MATCH ROM \n"); return 1; }
+               send_cnt = 0;
+               send_block[send_cnt++] = 0xAA;
+               send_block[send_cnt++] = 0x00;
+               for (i = 0; i < 32 + 2; i++) send_block[send_cnt++] = 0xFF;
+               if (!owBlock(portnum, FALSE, send_block, send_cnt))  { printf("ERROR RUN COMMAND \n"); return 1; }
+               for (i = 0; i < send_cnt; i++) { printf("%02X ", send_block[i]); }
+               if (!owAccess(portnum)) { printf("ERROR MATCH ROM \n"); return 1; }
+               send_cnt = 0;
+               send_block[send_cnt++] = 0x55;
+               send_block[send_cnt++] = 0xA5;
+               if (!owBlock(portnum, FALSE, send_block, send_cnt))  { printf("ERROR RUN COMMAND \n"); return 1; }
+               msDelay(100);
+               printf("\n");
+       }
+       fclose(fio);
+
+}
+/*
+SMALLINT WriteDS2430(int portnum, uchar SerialNum[8], const char *fname) {
+       uchar rt = FALSE;
+       uchar send_block[145];
+       uchar send_cnt = 0, i;
+       int address;
+       uchar readbl[64];
+       FILE *f;
+       f = fopen(fname, "rb");
+       fread(readbl, 1, 32 + 16, f);
+       fclose(f);
+       ResetDS2430(portnum, SerialNum);
+       msDelay(1000);
+       send_cnt = 0;
+       if (!owAccess(portnum)) { printf("ERROR MATCH ROM \n"); return 1; }
+       send_block[send_cnt++] = 0x0F;
+       send_block[send_cnt++] = 0x00;
+       for (i = 0; i<32; i++) send_block[send_cnt++] = readbl[i + 8];
+       if (!owBlock(portnum, FALSE, send_block, send_cnt))  { printf("ERROR RUN COMMAND \n"); return 1; }
+       send_cnt = 0;
+       if (!owAccess(portnum)) { printf("ERROR MATCH ROM \n"); return 1; }
+       send_block[send_cnt++] = 0xAA;
+       send_block[send_cnt++] = 0x00;
+       for (i = 0; i<32; i++) send_block[send_cnt++] = 0xFF;
+       if (!owBlock(portnum, FALSE, send_block, send_cnt))  { printf("ERROR RUN COMMAND \n"); return 1; }
+       for (i = 0; i<send_cnt; i++) { printf("%02X ", send_block[i]); if ((i - 1) % 16 == 0) printf("\n"); }
+
+       send_cnt = 0;
+       if (!owAccess(portnum)) { printf("ERROR MATCH ROM \n"); return 1; }
+       send_block[send_cnt++] = 0x55;
+       send_block[send_cnt++] = 0xA5;
+       if (!owBlock(portnum, FALSE, send_block, send_cnt))  { printf("ERROR RUN COMMAND \n"); return 1; }
+       msDelay(10);
+
+       send_cnt = 0;
+       if (!owAccess(portnum)) { printf("ERROR MATCH ROM \n"); return 1; }
+       send_block[send_cnt++] = 0xF0;
+       send_block[send_cnt++] = 0x00;
+       for (i = 0; i<32; i++) send_block[send_cnt++] = 0xFF;
+       if (!owBlock(portnum, FALSE, send_block, send_cnt))  { printf("ERROR RUN COMMAND \n"); return 1; }
+       for (i = 0; i<send_cnt; i++) { printf("%02X ", send_block[i]); if ((i - 1) % 16 == 0) printf("\n"); }
+
+       send_cnt = 0;
+       if (!owAccess(portnum)) { printf("ERROR MATCH ROM \n"); return 1; }
+       send_block[send_cnt++] = 0x99;
+       send_block[send_cnt++] = 0x00;
+       for (i = 0; i<8; i++) send_block[send_cnt++] = readbl[i + 8 + 32];
+       if (!owBlock(portnum, FALSE, send_block, send_cnt))  { printf("ERROR RUN COMMAND \n"); return 1; }
+
+       send_cnt = 0;
+       if (!owAccess(portnum)) { printf("ERROR MATCH ROM \n"); return 1; }
+       send_block[send_cnt++] = 0x5A;
+       send_block[send_cnt++] = 0xA5;
+       if (!owBlock(portnum, FALSE, send_block, send_cnt))  { printf("ERROR RUN COMMAND \n"); return 1; }
+       msDelay(10);
+       SetIDDS2430(portnum, SerialNum, readbl);
+
+
+}
+*/
+
+
+
+unsigned char conf2(const char *s) {
+       unsigned char b = 0;
+       for (int i = 0; i < 2; i++) {
+               b = b * 16;
+               if ((s[i] >= '0') && (s[i] <= '9')) {
+                       b += s[i] - '0';
+               } else
+               if ((s[i] >= 'A') && (s[i] <= 'F')) {
+                       b += s[i] - 'A'+10;
+               } else
+               if ((s[i] >= 'a') && (s[i] <= 'f')) {
+                       b += s[i] - 'a'+10;
+               }
+               
+       }
+       return b;
+}
+
+void strcpys(char *s, const char* d,bool up) {
+       if (strlen(d) > 7990) {
+               strncpy(s, d, 7990);
+               s[200] = 0;
+       }
+       else strcpy(s, d);
+       if (up) {
+               for (int i = 0; i<strlen(s); i++)
+                       if ((s[i] >= 'a') && (s[i] <= 'z'))
+                               s[i] += 'A' - 'a';
+       }
+}
+
+int main(int argc, char *argv[]) {
+       uchar SNum[8];
+       int rslt, cnt, i;
+       uchar send_block[256];
+       uchar send_cnt = 0;
+       int portnum;
+       char adapter[20];
+       int found = 0;
+       int rw = 0;
+       int err = 0;
+       char s[8000];
+       int adt = 0;
+       int mod = 0;
+       if (argc >= 2) {
+               strcpys(s, argv[1],true);
+               
+               
+               if (strncmp(s,"USB",3)==0) {adt = 6;}
+               if (strncmp(s, "COM", 3) == 0) { adt = 5; }
+               if (adt != 0) {
+                       strcpy(s, argv[1] + 3);
+                       sprintf(adapter, "{%s,%i}\0",s,adt);
+                       printf("Open Port %s\n", argv[1]);
+                       if ((portnum = owAcquireEx(adapter)) < 0) {
+                               printf("ERROR \n", adt);
+                       }
+                       else mod = 1;
+
+               } 
+               if ((argc == 2) && (mod == 1)) mod = 2;
+               if (argc > 2) {
+                       strcpys(s, argv[2],true);
+                       if (strncmp(s, "DC", 2) == 0) {
+                               if (argc > 3) {
+                                       if (strlen(argv[3])>=16)
+                                       for (int i = 0; i < 16; i += 2) {
+                                               SNum[7 - (i / 2)] = conf2(argv[3] + i);
+
+                                       }
+                                       printf("Select: %02X%02X%02X%02X%02X%02X%02X%02X\n", SNum[7], SNum[6], SNum[5], SNum[4], SNum[3], SNum[2], SNum[1], SNum[0]);
+                                       mod = 3;
+                               }
+
+                       }
+               }
+               if ((mod == 3) && (argc>4)) {
+                       strcpys(s, argv[4], true);
+                       mod = 4;
+               }
+       
+       }
+
+       if (mod == 2) {
+               rslt = owFirst(portnum, TRUE, FALSE);
+               cnt = 0;
+               while (rslt) {
+                       cnt++;
+                       owSerialNum(portnum, &SNum[0], TRUE);
+                       printf("%02X%02X%02X%02X%02X%02X%02X%02X\n", SNum[7], SNum[6], SNum[5], SNum[4], SNum[3], SNum[2], SNum[1], SNum[0]);
+                       //                      fprintf(ft,"%02X%02X%02X%02X%02X%02X%02X%02X\n",SNum[7],SNum[6],SNum[5],SNum[4],SNum[3],SNum[2],SNum[1],SNum[0]);
+/*                     switch (SNum[0]) {
+
+
+                               case 0x14: {
+                                       //TestDS2430(portnum,&SNum[0]);
+                                       //scanf("%i",&i);
+                                       //ResetDS2430(portnum,&SNum[0]);
+                                       //uchar id[]={0x14,0xF5 ,0xEA ,0x24 ,0x06 ,0x00 ,0x00 ,0x5E};
+                                       //SetIDDS2430(portnum,&SNum[0],id);
+                                       if (rw) WriteDS2430(portnum, &SNum[0]); else ReadDS2430(portnum, &SNum[0]);
+                                       //WriteDS2430(portnum,&SNum[0],"5E00000624EAF514.bin");
+                                       break;
+                               }
+                               case 0x23: {
+                                       //TestDS2433(portnum,&SNum[0]);
+                                       //TestDS2433_reset(portnum,&SNum[0]);
+                                       //scanf("%i",&i);
+                                       if (rw) WriteDS2433(portnum, &SNum[0]); else ReadDS2433(portnum, &SNum[0]);
+                                       break;
+                               }
+                               }*/
+                       rslt = owNext(portnum, TRUE, FALSE);
+               }
+       }
+       if (mod == 4) {
+               owSerialNum(portnum, SNum, FALSE);
+               strcat(s, "_R");
+               int len = strlen(s);
+               int i = 0;
+               while (i < len) {
+                       if (s[i] == '_') {
+                               if (s[i + 1] == 'R') {
+                                       if (owAccess(portnum)) {
+                                               if (owBlock(portnum, FALSE, send_block, send_cnt)) {
+                                                       for (int j = 0; j < send_cnt; j++) {
+                                                               printf("%02X", send_block[j]);
+                                                       }
+                                                       printf("\n");
+                                               }
+                                               else printf("ERROR RESET\n");
+                                       }
+                                       else printf("ERROR SEND\n");
+                                       send_cnt = 0;
+                               }
+                               if (s[i + 1] == 'P') {
+                                       if (i + 2 < len) {
+                                               i += 2;
+                                               msDelay(conf2(s + i));
+                                               
+                                       }
+                               }
+                       }
+                       else {
+                               send_block[send_cnt++] = conf2(s + i);
+                       }
+                       i += 2;
+               
+                       
+               }
+       }
+       if (mod>0) owRelease(portnum);
+       
+       return 0;
+}
\ No newline at end of file
diff --git a/tools_cmd/rwOW/owerr.c b/tools_cmd/rwOW/owerr.c
new file mode 100644 (file)
index 0000000..e26a97a
--- /dev/null
@@ -0,0 +1,348 @@
+//---------------------------------------------------------------------------
+// Copyright (C) 2000 Dallas Semiconductor Corporation, All Rights Reserved.
+//
+// Permission is hereby granted, free of charge, to any person obtaining a
+// copy of this software and associated documentation files (the "Software"),
+// to deal in the Software without restriction, including without limitation
+// the rights to use, copy, modify, merge, publish, distribute, sublicense,
+// and/or sell copies of the Software, and to permit persons to whom the
+// Software is furnished to do so, subject to the following conditions:
+//
+// The above copyright notice and this permission notice shall be included
+// in all copies or substantial portions of the Software.
+//
+// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
+// OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
+// MERCHANTABILITY,  FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
+// IN NO EVENT SHALL DALLAS SEMICONDUCTOR BE LIABLE FOR ANY CLAIM, DAMAGES
+// OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
+// ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
+// OTHER DEALINGS IN THE SOFTWARE.
+//
+// Except as contained in this notice, the name of Dallas Semiconductor
+// shall not be used except as stated in the Dallas Semiconductor
+// Branding Policy.
+//---------------------------------------------------------------------------
+//
+// owerr.c - Library functions for error handling with 1-Wire library
+//
+// Version: 1.00
+//
+
+#include <string.h>
+#ifndef _WIN32_WCE
+#include <stdio.h>
+#endif
+#ifdef _WIN64
+#include <stdio.h>
+#endif
+#include "ownet.h"
+
+#ifndef SIZE_OWERROR_STACK
+   #ifdef SMALL_MEMORY_TARGET
+      //for small memory, only hole 1 error
+      #define SIZE_OWERROR_STACK 1
+   #else
+      #define SIZE_OWERROR_STACK 10
+   #endif
+#endif
+
+//---------------------------------------------------------------------------
+// Variables
+//---------------------------------------------------------------------------
+
+// Error Struct for holding error information.
+// In DEBUG, this will also hold the line number and filename.
+typedef struct
+{
+   int owErrorNum;
+#ifdef DEBUG
+   int lineno;
+   char *filename;
+#endif
+} owErrorStruct;
+
+// Ring-buffer used for stack.
+// In case of overflow, deepest error is over-written.
+static owErrorStruct owErrorStack[SIZE_OWERROR_STACK];
+
+// Stack pointer to top-most error.
+static int owErrorPointer = 0;
+
+
+//---------------------------------------------------------------------------
+// Functions Definitions
+//---------------------------------------------------------------------------
+int owGetErrorNum(void);
+void owClearError(void);
+int owHasErrors(void);
+#ifdef DEBUG
+   void owRaiseError(int,int,char*);
+#else
+   void owRaiseError(int);
+#endif
+#ifndef SMALL_MEMORY_TARGET
+   void owPrintErrorMsg(FILE *);
+   void owPrintErrorMsgStd();
+   char *owGetErrorMsg(int);
+#endif
+
+
+//--------------------------------------------------------------------------
+// The 'owGetErroNum' returns the error code of the top-most error on the
+// error stack.  NOTE: This function has the side effect of popping the
+// current error off the stack.  All successive calls to 'owGetErrorNum'
+// will further clear the error stack.
+//
+// For list of error codes, see 'ownet.h'
+//
+// Returns:   int :  The error code of the top-most error on the stack
+//
+int owGetErrorNum(void)
+{
+   int i = owErrorStack[ owErrorPointer ].owErrorNum;
+   owErrorStack[ owErrorPointer ].owErrorNum = 0;
+   if(!owErrorPointer)
+      owErrorPointer = SIZE_OWERROR_STACK - 1;
+   else
+      owErrorPointer = (owErrorPointer - 1);
+   return i;
+}
+
+//--------------------------------------------------------------------------
+// The 'owClearError' clears all the errors.
+//
+void owClearError(void)
+{
+   owErrorStack[ owErrorPointer ].owErrorNum = 0;
+}
+
+//--------------------------------------------------------------------------
+// The 'owHasErrors' is a boolean test function which tests whether or not
+// a valid error is waiting on the stack.
+//
+// Returns:   TRUE (1) : When there are errors on the stack.
+//            FALSE (0): When stack's errors are set to 0, or NO_ERROR_SET.
+//
+int owHasErrors(void)
+{
+   if(owErrorStack[ owErrorPointer ].owErrorNum)
+      return 1; //TRUE
+   else
+      return 0; //FALSE
+}
+
+#ifdef DEBUG
+   //--------------------------------------------------------------------------
+   // The 'owRaiseError' is the method for raising an error onto the error
+   // stack.
+   //
+   // Arguments:  int err - the error code you wish to raise.
+   //             int lineno - DEBUG only - the line number where it was raised
+   //             char* filename - DEBUG only - the file name where it occured.
+   //
+   void owRaiseError(int err, int lineno, char* filename)
+   {
+      owErrorPointer = (owErrorPointer + 1) % SIZE_OWERROR_STACK;
+      owErrorStack[ owErrorPointer ].owErrorNum = err;
+      owErrorStack[ owErrorPointer ].lineno = lineno;
+      owErrorStack[ owErrorPointer ].filename = filename;
+   }
+#else
+   //--------------------------------------------------------------------------
+   // The 'owRaiseError' is the method for raising an error onto the error
+   // stack.
+   //
+   // Arguments:  int err - the error code you wish to raise.
+   //
+   void owRaiseError(int err)
+   {
+      owErrorPointer = (owErrorPointer + 1) % SIZE_OWERROR_STACK;
+      owErrorStack[ owErrorPointer ].owErrorNum = err;
+   }
+#endif
+
+
+// SMALL_MEMORY_TARGET - embedded microcontrollers, where these
+// messaging functions might not make any sense.
+#ifndef SMALL_MEMORY_TARGET
+   //Array of meaningful error messages to associate with codes.
+   //Not used on targets with low memory (i.e. PIC).
+   static char *owErrorMsg[125] =
+   {
+   /*000*/ "No Error Was Set",
+   /*001*/ "No Devices found on 1-Wire Network",
+   /*002*/ "1-Wire Net Reset Failed",
+   /*003*/ "Search ROM Error: Couldn't locate next device on 1-Wire",
+   /*004*/ "Access Failed: Could not select device",
+   /*005*/ "DS2480B Adapter Not Detected",
+   /*006*/ "DS2480B: Wrong Baud",
+   /*007*/ "DS2480B: Bad Response",
+   /*008*/ "Open COM Failed",
+   /*009*/ "Write COM Failed",
+   /*010*/ "Read COM Failed",
+   /*011*/ "Data Block Too Large",
+   /*012*/ "Block Transfer failed",
+   /*013*/ "Program Pulse Failed",
+   /*014*/ "Program Byte Failed",
+   /*015*/ "Write Byte Failed",
+   /*016*/ "Read Byte Failed",
+   /*017*/ "Write Verify Failed",
+   /*018*/ "Read Verify Failed",
+   /*019*/ "Write Scratchpad Failed",
+   /*020*/ "Copy Scratchpad Failed",
+   /*021*/ "Incorrect CRC Length",
+   /*022*/ "CRC Failed",
+   /*023*/ "Failed to acquire a necessary system resource",
+   /*024*/ "Failed to initialize system resource",
+   /*025*/ "Data too long to fit on specified device.",
+   /*026*/ "Read exceeds memory bank end.",
+   /*027*/ "Write exceeds memory bank end.",
+   /*028*/ "Device select failed",
+   /*029*/ "Read Scratch Pad verify failed.",
+   /*030*/ "Copy scratchpad complete not found",
+   /*031*/ "Erase scratchpad complete not found",
+   /*032*/ "Address read back from scrachpad was incorrect",
+   /*033*/ "Read page with extra-info not supported by this memory bank",
+   /*034*/ "Read page packet with extra-info not supported by this memory bank",
+   /*035*/ "Length of packet requested exceeds page size",
+   /*036*/ "Invalid length in packet",
+   /*037*/ "Program pulse required but not available",
+   /*038*/ "Trying to access a read-only memory bank",
+   /*039*/ "Current bank is not general purpose memory",
+   /*040*/ "Read back from write compare is incorrect, page may be locked",
+   /*041*/ "Invalid page number for this memory bank",
+   /*042*/ "Read page with CRC not supported by this memory bank",
+   /*043*/ "Read page with CRC and extra-info not supported by this memory bank",
+   /*044*/ "Read back from write incorrect, could not lock page",
+   /*045*/ "Read back from write incorrect, could not lock redirect byte",
+   /*046*/ "The read of the status was not completed.",
+   /*047*/ "Page redirection not supported by this memory bank",
+   /*048*/ "Lock Page redirection not supported by this memory bank",
+   /*049*/ "Read back byte on EPROM programming did not match.",
+   /*050*/ "Can not write to a page that is locked.",
+   /*051*/ "Can not lock a redirected page that has already been locked.",
+   /*052*/ "Trying to redirect a locked redirected page.",
+   /*053*/ "Trying to lock a page that is already locked.",
+   /*054*/ "Trying to write to a memory bank that is write protected.",
+   /*055*/ "Error due to not matching MAC.",
+   /*056*/ "Memory Bank is write protected.",
+   /*057*/ "Secret is write protected, can not Load First Secret.",
+   /*058*/ "Error in Reading Scratchpad after Computing Next Secret.",
+   /*059*/ "Load Error from Loading First Secret.",
+   /*060*/ "Power delivery required but not available",
+   /*061*/ "Not a valid file name.",
+   /*062*/ "Unable to Create a Directory in this part.",
+   /*063*/ "That file already exists.",
+   /*064*/ "The directory is not empty.",
+   /*065*/ "The wrong type of part for this operation.",
+   /*066*/ "The max len for this file is too small.",
+   /*067*/ "This is not a write once bank.",
+   /*068*/ "The file can not be found.",
+   /*069*/ "There is not enough space available.",
+   /*070*/ "There is not a page to match that bit in the bitmap.",
+   /*071*/ "There are no jobs for EPROM parts.",
+   /*072*/ "Function not supported to modify attributes.",
+   /*073*/ "Handle is not in use.",
+   /*074*/ "Tring to read a write only file.",
+   /*075*/ "There is no handle available for use.",
+   /*076*/ "The directory provided is an invalid directory.",
+   /*077*/ "Handle does not exist.",
+   /*078*/ "Serial Number did not match with current job.",
+   /*079*/ "Can not program EPROM because a non-EPROM part on the network.",
+   /*080*/ "Write protect redirection byte is set.",
+   /*081*/ "There is an inappropriate directory length.",
+   /*082*/ "The file has already been terminated.",
+   /*083*/ "Failed to read memory page of iButton part.",
+   /*084*/ "Failed to match scratchpad of iButton part.",
+   /*085*/ "Failed to erase scratchpad of iButton part.",
+   /*086*/ "Failed to read scratchpad of iButton part.",
+   /*087*/ "Failed to execute SHA function on SHA iButton.",
+   /*088*/ "SHA iButton did not return a status completion byte.",
+   /*089*/ "Write data page failed.",
+   /*090*/ "Copy secret into secret memory pages failed.",
+   /*091*/ "Bind unique secret to iButton failed.",
+   /*092*/ "Could not install secret into user token.",
+   /*093*/ "Transaction Incomplete: signature did not match.",
+   /*094*/ "Transaction Incomplete: could not sign service data.",
+   /*095*/ "User token did not provide a valid authentication response.",
+   /*096*/ "Failed to answer a challenge on the user token.",
+   /*097*/ "Failed to create a challenge on the coprocessor.",
+   /*098*/ "Transaction Incomplete: service data was not valid.",
+   /*099*/ "Transaction Incomplete: service data was not updated.",
+   /*100*/ "Unrecoverable, catastrophic service failure occured.",
+   /*101*/ "Load First Secret from scratchpad data failed.",
+   /*102*/ "Failed to match signature of user's service data.",
+   /*103*/ "Subkey out of range for the DS1991.",
+   /*104*/ "Block ID out of range for the DS1991",
+   /*105*/ "Password is enabled",
+   /*106*/ "Password is invalid",
+   /*107*/ "This memory bank has no read only password",
+   /*108*/ "This memory bank has no read/write password",
+   /*109*/ "1-Wire is shorted",
+   /*110*/ "Error communicating with 1-Wire adapter",
+   /*111*/ "CopyScratchpad failed: Ending Offset must go to end of page",
+   /*112*/ "WriteScratchpad failed: Ending Offset must go to end of page",
+   /*113*/ "Mission can not be stopped while one is not in progress",
+   /*114*/ "Error stopping the mission",
+   /*115*/ "Port number is outside (0,MAX_PORTNUM) interval",
+   /*116*/ "Level of the 1-Wire was not changed",
+   /*117*/ "Both the Read Only and Read Write Passwords must be set",
+   /*118*/ "Failure to change latch state."
+   /*119*/ "Could not open usb port through libusb",
+   /*120*/ "Libusb DS2490 port already opened",
+   /*121*/ "Failed to set libusb configuration",
+   /*122*/ "Failed to claim libusb interface",
+   /*123*/ "Failed to set libusb altinterface",
+   /*124*/ "No adapter found at this port number"
+   };
+
+   char *owGetErrorMsg(int err)
+   {
+      return owErrorMsg[err];
+   }
+
+#ifndef __C51__
+   //--------------------------------------------------------------------------
+   // The 'owPrintErrorMsg' is the method for printing an error from the stack.
+   // The destination for the print is specified by the argument, fileno, which
+   // can be stderr, stdout, or a log file.  In non-debug mode, the output is
+   // of the form:
+   // Error num: Error msg
+   //
+   // In debug-mode, the output is of the form:
+   // Error num: filename line#: Error msg
+   //
+   // NOTE: This function has the side-effect of popping the error off the stack.
+   //
+   // Arguments:  FILE*: the destination for printing.
+   //
+   void owPrintErrorMsg(FILE *filenum)
+   {
+   #ifdef DEBUG
+      int l = owErrorStack[ owErrorPointer ].lineno;
+      char *f = owErrorStack[ owErrorPointer ].filename;
+      int err = owGetErrorNum();
+      fprintf(filenum,"Error %d: %s line %d: %s\r\n",err,f,l,owErrorMsg[err]);
+   #else
+      int err = owGetErrorNum();
+      fprintf(filenum,"Error %d: %s\r\n",err,owErrorMsg[err]);
+   #endif
+   }
+#endif //__C51__
+
+   // Same as above, except uses default printf output
+   void owPrintErrorMsgStd()
+   {
+   #ifdef DEBUG
+      int l = owErrorStack[ owErrorPointer ].lineno;
+      char *f = owErrorStack[ owErrorPointer ].filename;
+      int err = owGetErrorNum();
+      printf("Error %d: %s line %d: %s\r\n",err,f,l,owErrorMsg[err]);
+   #else
+      int err = owGetErrorNum();
+      printf("Error %d: %s\r\n",err,owErrorMsg[err]);
+   #endif
+   }
+#endif
+
diff --git a/tools_cmd/rwOW/ownet.h b/tools_cmd/rwOW/ownet.h
new file mode 100644 (file)
index 0000000..a74cd95
--- /dev/null
@@ -0,0 +1,422 @@
+//---------------------------------------------------------------------------
+// Copyright (C) 2000 Dallas Semiconductor Corporation, All Rights Reserved.
+//
+// Permission is hereby granted, free of charge, to any person obtaining a
+// copy of this software and associated documentation files (the "Software"),
+// to deal in the Software without restriction, including without limitation
+// the rights to use, copy, modify, merge, publish, distribute, sublicense,
+// and/or sell copies of the Software, and to permit persons to whom the
+// Software is furnished to do so, subject to the following conditions:
+//
+// The above copyright notice and this permission notice shall be included
+// in all copies or substantial portions of the Software.
+//
+// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
+// OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
+// MERCHANTABILITY,  FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
+// IN NO EVENT SHALL DALLAS SEMICONDUCTOR BE LIABLE FOR ANY CLAIM, DAMAGES
+// OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
+// ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
+// OTHER DEALINGS IN THE SOFTWARE.
+//
+// Except as contained in this notice, the name of Dallas Semiconductor
+// shall not be used except as stated in the Dallas Semiconductor
+// Branding Policy.
+//---------------------------------------------------------------------------
+//
+// ownet.h - Include file for 1-Wire Net library
+//
+// Version: 2.10
+//
+// History: 1.02 -> 1.03 Make sure uchar is not defined twice.
+//          1.03 -> 2.00 Changed 'MLan' to 'ow'.
+//          2.00 -> 2.01 Added error handling. Added circular-include check.
+//          2.01 -> 2.10 Added raw memory error handling and SMALLINT
+//          2.10 -> 3.00 Added memory bank functionality
+//                       Added file I/O operations
+//
+
+#ifndef OWNET_H
+#define OWNET_H
+
+//--------------------------------------------------------------//
+// Common Includes to ownet applications
+//--------------------------------------------------------------//
+#include <stdlib.h>
+
+
+//--------------------------------------------------------------//
+// Target Specific Information
+//--------------------------------------------------------------//
+//--------------------------------------------------------------//
+// Handhelds (PalmOS, WinCE)
+//--------------------------------------------------------------//
+#ifdef __MC68K__
+   //MC68K is the type of processor in the PILOT
+   //Metrowerk's CodeWarrior defines this symbol
+   #include <string.h>
+   #ifndef strcmp
+      #include <StringMgr.h>
+      #define strcmp StrCompare
+   #endif
+   #include <file_struc.h>
+#endif
+
+#ifdef _WIN32_WCE
+   //All of our projects had this flag defined by default (_WIN32_WCE),
+   //but I'm not 100% positive that this is _the_ definitive
+   //flag to use to identify a WinCE system.
+   #include "WinCElnk.h"
+   #ifndef FILE
+      #define FILE int
+      extern int sprintf(char *buffer, char *format,...);
+      extern void fprintf(FILE *fp, char *format,...);
+      extern void printf(char *format,...);
+   #endif
+#endif
+
+#if !defined(_WIN32_WCE) && !defined(__MC68K__)
+   #include <stdio.h>
+#endif
+
+#ifdef __C51__
+   #define FILE int
+   #define exit(c) return
+   typedef unsigned int ushort;
+   typedef unsigned long ulong;
+   #define SMALLINT uchar
+#endif
+
+#ifdef __ICCMAXQ__
+   #define FILE int
+   #define stdout 0
+   #define stdin  1
+   #define stderr 2
+   typedef unsigned int ushort;
+   typedef unsigned long ulong;
+   #define SMALLINT short
+   #define main micro_main
+   #define real_main main
+   #define SMALL_MEMORY_TARGET
+#endif
+
+
+//--------------------------------------------------------------//
+// Typedefs
+//--------------------------------------------------------------//
+#ifndef SMALLINT
+   //
+   // purpose of smallint is for compile-time changing of formal
+   // parameters and return values of functions.  For each target
+   // machine, an integer is alleged to represent the most "simple"
+   // number representable by that architecture.  This should, in
+   // most cases, produce optimal code for that particular arch.
+   // BUT...  The majority of compilers designed for embedded
+   // processors actually keep an int at 16 bits, although the
+   // architecture might only be comfortable with 8 bits.
+   // The default size of smallint will be the same as that of
+   // an integer, but this allows for easy overriding of that size.
+   //
+   // NOTE:
+   // In all cases where a smallint is used, it is assumed that
+   // decreasing the size of this integer to something as low as
+   // a single byte _will_not_ change the functionality of the
+   // application.  e.g. a loop counter that will iterate through
+   // several kilobytes of data should not be SMALLINT.  The most
+   // common place you'll see smallint is for boolean return types.
+   //
+   #define SMALLINT int
+#endif
+
+// setting max baud
+#ifdef _WINDOWS
+   // 0x02 = PARAMSET_19200
+#define MAX_BAUD 0x02
+#else
+   // 0x06 = PARMSET_115200
+#define MAX_BAUD 0x06
+#endif
+
+#ifndef OW_UCHAR
+   #define OW_UCHAR
+   typedef unsigned char uchar;
+   #if !defined(__MINGW32__) && (defined(__CYGWIN__) || defined(__GNUC__))
+      typedef unsigned long ulong;
+      //ushort already defined in sys/types.h
+      #include <sys/types.h>
+   #else
+      #if defined(_WIN32) || defined(WIN32) || defined(__MC68K__) || defined(_WIN32_WCE) || defined(_DOS)  || defined(_WINDOWS) || defined(__MINGW32__)
+         typedef unsigned short ushort;
+         typedef unsigned long ulong;
+      #endif
+   #endif
+   #ifdef __sun__
+      #include <sys/types.h>
+   #endif
+   #ifdef SDCC
+      //intent of ushort is 2 bytes unsigned.
+      //for ds390 in sdcc, an int, not a short,
+      //is 2 bytes.
+      typedef unsigned int ushort;
+   #endif
+#endif
+
+// general defines
+#define WRITE_FUNCTION 1
+#define READ_FUNCTION  0
+
+// error codes
+// todo: investigate these and replace with new Error Handling library
+#define READ_ERROR    -1
+#define INVALID_DIR   -2
+#define NO_FILE       -3
+#define WRITE_ERROR   -4
+#define WRONG_TYPE    -5
+#define FILE_TOO_BIG  -6
+
+// Misc
+#define FALSE          0
+#define TRUE           1
+
+#ifndef MAX_PORTNUM
+   #define MAX_PORTNUM    16
+#endif
+
+// mode bit flags
+#define MODE_NORMAL                    0x00
+#define MODE_OVERDRIVE                 0x01
+#define MODE_STRONG5                   0x02
+#define MODE_PROGRAM                   0x04
+#define MODE_BREAK                     0x08
+
+// Output flags
+#define LV_ALWAYS          2
+#define LV_OPTIONAL        1
+#define LV_VERBOSE         0
+
+//--------------------------------------------------------------//
+// Error handling
+//--------------------------------------------------------------//
+extern int owGetErrorNum(void);
+extern int owHasErrors(void);
+
+//Clears the stack.
+#define OWERROR_CLEAR() while(owHasErrors()) owGetErrorNum();
+
+#ifdef DEBUG
+   //Raises an exception with extra debug info
+   #define OWERROR(err) owRaiseError(err,__LINE__,__FILE__)
+   extern void owRaiseError(int,int,char*);
+   #define OWASSERT(s,err,ret) if(!(s)){owRaiseError((err),__LINE__,__FILE__);return (ret);}
+#else
+   //Raises an exception with just the error code
+   #define OWERROR(err) owRaiseError(err)
+   extern void owRaiseError(int);
+   #define OWASSERT(s,err,ret) if(!(s)){owRaiseError((err));return (ret);}
+#endif
+
+#ifdef SMALL_MEMORY_TARGET
+   #define OWERROR_DUMP(fileno) /*no-op*/;
+#else
+   //Prints the stack out to the given file.
+   #define OWERROR_DUMP(fileno) while(owHasErrors()) owPrintErrorMsg(fileno);
+   extern void owPrintErrorMsg(FILE *);
+   extern void owPrintErrorMsgStd();
+   extern char *owGetErrorMsg(int);
+#endif
+
+#define OWERROR_NO_ERROR_SET                    0
+#define OWERROR_NO_DEVICES_ON_NET               1
+#define OWERROR_RESET_FAILED                    2
+#define OWERROR_SEARCH_ERROR                    3
+#define OWERROR_ACCESS_FAILED                   4
+#define OWERROR_DS2480_NOT_DETECTED             5
+#define OWERROR_DS2480_WRONG_BAUD               6
+#define OWERROR_DS2480_BAD_RESPONSE             7
+#define OWERROR_OPENCOM_FAILED                  8
+#define OWERROR_WRITECOM_FAILED                 9
+#define OWERROR_READCOM_FAILED                  10
+#define OWERROR_BLOCK_TOO_BIG                   11
+#define OWERROR_BLOCK_FAILED                    12
+#define OWERROR_PROGRAM_PULSE_FAILED            13
+#define OWERROR_PROGRAM_BYTE_FAILED             14
+#define OWERROR_WRITE_BYTE_FAILED               15
+#define OWERROR_READ_BYTE_FAILED                16
+#define OWERROR_WRITE_VERIFY_FAILED             17
+#define OWERROR_READ_VERIFY_FAILED              18
+#define OWERROR_WRITE_SCRATCHPAD_FAILED         19
+#define OWERROR_COPY_SCRATCHPAD_FAILED          20
+#define OWERROR_INCORRECT_CRC_LENGTH            21
+#define OWERROR_CRC_FAILED                      22
+#define OWERROR_GET_SYSTEM_RESOURCE_FAILED      23
+#define OWERROR_SYSTEM_RESOURCE_INIT_FAILED     24
+#define OWERROR_DATA_TOO_LONG                   25
+#define OWERROR_READ_OUT_OF_RANGE               26
+#define OWERROR_WRITE_OUT_OF_RANGE              27
+#define OWERROR_DEVICE_SELECT_FAIL              28
+#define OWERROR_READ_SCRATCHPAD_VERIFY          29
+#define OWERROR_COPY_SCRATCHPAD_NOT_FOUND       30
+#define OWERROR_ERASE_SCRATCHPAD_NOT_FOUND      31
+#define OWERROR_ADDRESS_READ_BACK_FAILED        32
+#define OWERROR_EXTRA_INFO_NOT_SUPPORTED        33
+#define OWERROR_PG_PACKET_WITHOUT_EXTRA         34
+#define OWERROR_PACKET_LENGTH_EXCEEDS_PAGE      35
+#define OWERROR_INVALID_PACKET_LENGTH           36
+#define OWERROR_NO_PROGRAM_PULSE                37
+#define OWERROR_READ_ONLY                       38
+#define OWERROR_NOT_GENERAL_PURPOSE             39
+#define OWERROR_READ_BACK_INCORRECT             40
+#define OWERROR_INVALID_PAGE_NUMBER             41
+#define OWERROR_CRC_NOT_SUPPORTED               42
+#define OWERROR_CRC_EXTRA_INFO_NOT_SUPPORTED    43
+#define OWERROR_READ_BACK_NOT_VALID             44
+#define OWERROR_COULD_NOT_LOCK_REDIRECT         45
+#define OWERROR_READ_STATUS_NOT_COMPLETE        46
+#define OWERROR_PAGE_REDIRECTION_NOT_SUPPORTED  47
+#define OWERROR_LOCK_REDIRECTION_NOT_SUPPORTED  48
+#define OWERROR_READBACK_EPROM_FAILED           49
+#define OWERROR_PAGE_LOCKED                     50
+#define OWERROR_LOCKING_REDIRECTED_PAGE_AGAIN   51
+#define OWERROR_REDIRECTED_PAGE                 52
+#define OWERROR_PAGE_ALREADY_LOCKED             53
+#define OWERROR_WRITE_PROTECTED                 54
+#define OWERROR_NONMATCHING_MAC                 55
+#define OWERROR_WRITE_PROTECT                   56
+#define OWERROR_WRITE_PROTECT_SECRET            57
+#define OWERROR_COMPUTE_NEXT_SECRET             58
+#define OWERROR_LOAD_FIRST_SECRET               59
+#define OWERROR_POWER_NOT_AVAILABLE             60
+#define OWERROR_XBAD_FILENAME                   61
+#define OWERROR_XUNABLE_TO_CREATE_DIR           62
+#define OWERROR_REPEAT_FILE                     63
+#define OWERROR_DIRECTORY_NOT_EMPTY             64
+#define OWERROR_WRONG_TYPE                      65
+#define OWERROR_BUFFER_TOO_SMALL                66
+#define OWERROR_NOT_WRITE_ONCE                  67
+#define OWERROR_FILE_NOT_FOUND                  68
+#define OWERROR_OUT_OF_SPACE                    69
+#define OWERROR_TOO_LARGE_BITNUM                70
+#define OWERROR_NO_PROGRAM_JOB                  71
+#define OWERROR_FUNC_NOT_SUP                    72
+#define OWERROR_HANDLE_NOT_USED                 73
+#define OWERROR_FILE_WRITE_ONLY                 74
+#define OWERROR_HANDLE_NOT_AVAIL                75
+#define OWERROR_INVALID_DIRECTORY               76
+#define OWERROR_HANDLE_NOT_EXIST                77
+#define OWERROR_NONMATCHING_SNUM                78
+#define OWERROR_NON_PROGRAM_PARTS               79
+#define OWERROR_PROGRAM_WRITE_PROTECT           80
+#define OWERROR_FILE_READ_ERR                   81
+#define OWERROR_ADDFILE_TERMINATED              82
+#define OWERROR_READ_MEMORY_PAGE_FAILED         83
+#define OWERROR_MATCH_SCRATCHPAD_FAILED         84
+#define OWERROR_ERASE_SCRATCHPAD_FAILED         85
+#define OWERROR_READ_SCRATCHPAD_FAILED          86
+#define OWERROR_SHA_FUNCTION_FAILED             87
+#define OWERROR_NO_COMPLETION_BYTE              88
+#define OWERROR_WRITE_DATA_PAGE_FAILED          89
+#define OWERROR_COPY_SECRET_FAILED              90
+#define OWERROR_BIND_SECRET_FAILED              91
+#define OWERROR_INSTALL_SECRET_FAILED           92
+#define OWERROR_VERIFY_SIG_FAILED               93
+#define OWERROR_SIGN_SERVICE_DATA_FAILED        94
+#define OWERROR_VERIFY_AUTH_RESPONSE_FAILED     95
+#define OWERROR_ANSWER_CHALLENGE_FAILED         96
+#define OWERROR_CREATE_CHALLENGE_FAILED         97
+#define OWERROR_BAD_SERVICE_DATA                98
+#define OWERROR_SERVICE_DATA_NOT_UPDATED        99
+#define OWERROR_CATASTROPHIC_SERVICE_FAILURE    100
+#define OWERROR_LOAD_FIRST_SECRET_FAILED        101
+#define OWERROR_MATCH_SERVICE_SIGNATURE_FAILED  102
+#define OWERROR_KEY_OUT_OF_RANGE                103
+#define OWERROR_BLOCK_ID_OUT_OF_RANGE           104
+#define OWERROR_PASSWORDS_ENABLED               105
+#define OWERROR_PASSWORD_INVALID                106
+#define OWERROR_NO_READ_ONLY_PASSWORD           107
+#define OWERROR_NO_READ_WRITE_PASSWORD          108
+#define OWERROR_OW_SHORTED                      109
+#define OWERROR_ADAPTER_ERROR                   110
+#define OWERROR_EOP_COPY_SCRATCHPAD_FAILED      111
+#define OWERROR_EOP_WRITE_SCRATCHPAD_FAILED     112
+#define OWERROR_HYGRO_STOP_MISSION_UNNECESSARY  113
+#define OWERROR_HYGRO_STOP_MISSION_ERROR        114
+#define OWERROR_PORTNUM_ERROR                   115
+#define OWERROR_LEVEL_FAILED                    116
+#define OWERROR_PASSWORD_NOT_SET                117
+#define OWERROR_LATCH_NOT_SET                   118
+#define OWERROR_LIBUSB_OPEN_FAILED              119
+#define OWERROR_LIBUSB_DEVICE_ALREADY_OPENED    120
+#define OWERROR_LIBUSB_SET_CONFIGURATION_ERROR  121
+#define OWERROR_LIBUSB_CLAIM_INTERFACE_ERROR    122
+#define OWERROR_LIBUSB_SET_ALTINTERFACE_ERROR   123
+#define OWERROR_LIBUSB_NO_ADAPTER_FOUND         124
+
+// One Wire functions defined in ownetu.c
+SMALLINT  owFirst(int portnum, SMALLINT do_reset, SMALLINT alarm_only);
+SMALLINT  owNext(int portnum, SMALLINT do_reset, SMALLINT alarm_only);
+void      owSerialNum(int portnum, uchar *serialnum_buf, SMALLINT do_read);
+void      owFamilySearchSetup(int portnum, SMALLINT search_family);
+void      owSkipFamily(int portnum);
+SMALLINT  owAccess(int portnum);
+SMALLINT  owVerify(int portnum, SMALLINT alarm_only);
+SMALLINT  owOverdriveAccess(int portnum);
+
+
+// external One Wire functions defined in owsesu.c
+ SMALLINT owAcquire(int portnum, char *port_zstr);
+ int      owAcquireEx(char *port_zstr);
+ void     owRelease(int portnum);
+
+// external One Wire functions defined in findtype.c
+// SMALLINT FindDevices(int,uchar FamilySN[][8],SMALLINT,int);
+
+// external One Wire functions from link layer owllu.c
+SMALLINT owTouchReset(int portnum);
+SMALLINT owTouchBit(int portnum, SMALLINT sendbit);
+SMALLINT owTouchByte(int portnum, SMALLINT sendbyte);
+SMALLINT owWriteByte(int portnum, SMALLINT sendbyte);
+SMALLINT owReadByte(int portnum);
+SMALLINT owSpeed(int portnum, SMALLINT new_speed);
+SMALLINT owLevel(int portnum, SMALLINT new_level);
+SMALLINT owProgramPulse(int portnum);
+SMALLINT owWriteBytePower(int portnum, SMALLINT sendbyte);
+SMALLINT owReadBytePower(int portnum);
+SMALLINT owHasPowerDelivery(int portnum);
+SMALLINT owHasProgramPulse(int portnum);
+SMALLINT owHasOverDrive(int portnum);
+SMALLINT owReadBitPower(int portnum, SMALLINT applyPowerResponse);
+// external One Wire global from owllu.c
+extern SMALLINT FAMILY_CODE_04_ALARM_TOUCHRESET_COMPLIANCE;
+
+// external One Wire functions from transaction layer in owtrnu.c
+SMALLINT owBlock(int portnum, SMALLINT do_reset, uchar *tran_buf, SMALLINT tran_len);
+SMALLINT owReadPacketStd(int portnum, SMALLINT do_access, int start_page, uchar *read_buf);
+SMALLINT owWritePacketStd(int portnum, int start_page, uchar *write_buf,
+                          SMALLINT write_len, SMALLINT is_eprom, SMALLINT crc_type);
+SMALLINT owProgramByte(int portnum, SMALLINT write_byte, int addr, SMALLINT write_cmd,
+                       SMALLINT crc_type, SMALLINT do_access);
+
+// link functions
+void      msDelay(int len);
+long      msGettick(void);
+
+// ioutil.c functions prototypes
+int  EnterString(char *msg, char *buf, int min, int max);
+int  EnterNum(char *msg, int numchars, long *value, long min, long max);
+int  EnterHex(char *msg, int numchars, ulong *value);
+int  ToHex(char ch);
+int  getkeystroke(void);
+int  key_abort(void);
+void ExitProg(char *msg, int exit_code);
+int  getData(uchar *write_buff, int max_len, SMALLINT gethex);
+void PrintHex(uchar* buffer, int cnt);
+void PrintChars(uchar* buffer, int cnt);
+void PrintSerialNum(uchar* buffer);
+
+// external functions defined in crcutil.c
+void setcrc16(int portnum, ushort reset);
+ushort docrc16(int portnum, ushort cdata);
+void setcrc8(int portnum, uchar reset);
+uchar docrc8(int portnum, uchar x);
+
+#endif //OWNET_H
diff --git a/tools_cmd/rwOW/tmexlnk.c b/tools_cmd/rwOW/tmexlnk.c
new file mode 100644 (file)
index 0000000..7555714
--- /dev/null
@@ -0,0 +1,368 @@
+//---------------------------------------------------------------------------
+// Copyright (C) 2001 Dallas Semiconductor Corporation, All Rights Reserved.
+//
+// Permission is hereby granted, free of charge, to any person obtaining a
+// copy of this software and associated documentation files (the "Software"),
+// to deal in the Software without restriction, including without limitation
+// the rights to use, copy, modify, merge, publish, distribute, sublicense,
+// and/or sell copies of the Software, and to permit persons to whom the
+// Software is furnished to do so, subject to the following conditions:
+//
+// The above copyright notice and this permission notice shall be included
+// in all copies or substantial portions of the Software.
+//
+// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
+// OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
+// MERCHANTABILITY,  FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
+// IN NO EVENT SHALL DALLAS SEMICONDUCTOR BE LIABLE FOR ANY CLAIM, DAMAGES
+// OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
+// ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
+// OTHER DEALINGS IN THE SOFTWARE.
+//
+// Except as contained in this notice, the name of Dallas Semiconductor
+// shall not be used except as stated in the Dallas Semiconductor
+// Branding Policy.
+//---------------------------------------------------------------------------
+//
+//  TMEXLnk.C - Link module to call on TMEX low-level functions to
+//              excersize the general 1-Wire Net functions.
+//              (Requires TMEX 3.11 or newer)
+//
+//  Version: 3.00
+//
+//  History: 1.00 -> 1.01  Return values in owLevel corrected.
+//                         Added function msDelay.
+//           1.02 -> 1.03  Add msGettick, always return owLevel success
+//                         to hide adapters (DS9097E) that do not have
+//                         power delivery capabilities.
+//           1.03 -> 2.00  Changed 'MLan' to 'ow'. Added support for
+//                         multiple ports.
+//           2.10 -> 3.00  Added owReadBitPower and owWriteBytePower
+
+#include "ownet.h"
+#include <windows.h>
+
+// external TMEX variables
+extern long SessionHandle[MAX_PORTNUM];
+extern uchar StateBuffer[MAX_PORTNUM][5120];
+extern short far pascal TMTouchByte(long, short);
+extern short far pascal TMTouchReset(long);
+extern short far pascal TMTouchBit(long, short);
+extern short far pascal TMProgramPulse(long);
+extern short far pascal TMOneWireCom(long, short, short);
+extern short far pascal TMOneWireLevel(long, short, short, short);
+
+// globals
+SMALLINT FAMILY_CODE_04_ALARM_TOUCHRESET_COMPLIANCE = FALSE; // for compatibility purposes
+
+//--------------------------------------------------------------------------
+// Reset all of the devices on the 1-Wire Net and return the result.
+//
+// 'portnum'     - number 0 to MAX_PORTNUM-1.  This number is provided to
+//                 indicate the symbolic port number.
+//
+// Returns: TRUE(1):  presense pulse(s) detected, device(s) reset
+//          FALSE(0): no presense pulses detected
+//
+SMALLINT owTouchReset(int portnum)
+{
+   int result;
+
+   // Assume valid Session
+   result = TMTouchReset(SessionHandle[portnum]);
+
+   // success if the normal or alarm presence
+   if ((result == 1) || (result == 2))
+      return TRUE;
+   else
+      return FALSE;
+}
+
+
+//--------------------------------------------------------------------------
+// Send 1 bit of communication to the 1-Wire Net and return the
+// result 1 bit read from the 1-Wire Net.  The parameter 'sendbit'
+// least significant bit is used and the least significant bit
+// of the result is the return bit.
+//
+// 'portnum'     - number 0 to MAX_PORTNUM-1.  This number is provided to
+//                 indicate the symbolic port number.
+// 'sendbit'     - the least significant bit is the bit to send
+//
+// Returns: 0:   0 bit read from sendbit
+//          1:   1 bit read from sendbit
+//
+SMALLINT owTouchBit(int portnum, SMALLINT sendbit)
+{
+   // Assume valid Session
+   return TMTouchBit(SessionHandle[portnum],(short)sendbit);
+}
+
+//--------------------------------------------------------------------------
+// Send 8 bits of communication to the 1-Wire Net and verify that the
+// 8 bits read from the 1-Wire Net is the same (write operation).
+// The parameter 'sendbyte' least significant 8 bits are used.
+//
+// 'portnum'    - number 0 to MAX_PORTNUM-1.  This number is provided to
+//                indicate the symbolic port number.
+// 'sendbyte'   - 8 bits to send (least significant byte)
+//
+// Returns:  TRUE: bytes written and echo was the same
+//           FALSE: echo was not the same
+//
+SMALLINT owTouchByte(int portnum, SMALLINT sendbyte)
+{
+   // Assume valid Session
+   return TMTouchByte(SessionHandle[portnum],(short)sendbyte);
+}
+
+//--------------------------------------------------------------------------
+// Send 8 bits of communication to the MicroLAN and verify that the
+// 8 bits read from the MicroLAN is the same (write operation).
+// The parameter 'sendbyte' least significant 8 bits are used.
+//
+// 'portnum'    - number 0 to MAX_PORTNUM-1.  This number is provided to
+//                indicate the symbolic port number.
+// 'sendbyte'   - 8 bits to send (least significant byte)
+//
+// Returns:  TRUE: bytes written and echo was the same
+//           FALSE: echo was not the same
+//
+SMALLINT owWriteByte(int portnum, SMALLINT sendbyte)
+{
+   return (owTouchByte(portnum,sendbyte) == sendbyte) ? TRUE : FALSE;
+}
+
+//--------------------------------------------------------------------------
+// Send 8 bits of read communication to the 1-Wire Net and and return the
+// result 8 bits read from the 1-Wire Net.
+//
+// 'portnum'     - number 0 to MAX_PORTNUM-1.  This number is provided to
+//                 indicate the symbolic port number.
+//
+// Returns:  TRUE:  8 bytes read from 1-Wire Net
+//           FALSE: the 8 bytes were not read
+//
+SMALLINT owReadByte(int portnum)
+{
+   return owTouchByte(portnum,0xFF);
+}
+
+//--------------------------------------------------------------------------
+// Set the 1-Wire Net communucation speed.
+//
+// 'portnum'    - number 0 to MAX_PORTNUM-1.  This number is provided to
+//                indicate the symbolic port number.
+// 'new_speed'  - new speed defined as
+//                MODE_NORMAL     0x00
+//                MODE_OVERDRIVE  0x01
+//
+// Returns:  current 1-Wire Net speed
+//
+SMALLINT owSpeed(int portnum, SMALLINT new_speed)
+{
+   return TMOneWireCom(SessionHandle[portnum],0,(short)new_speed);
+}
+
+//--------------------------------------------------------------------------
+// Set the 1-Wire Net line level.  The values for new_level are
+// as follows:
+//
+// 'portnum'   - number 0 to MAX_PORTNUM-1.  This number is provided to
+//               indicate the symbolic port number.
+// 'new_level' - new level defined as
+//                MODE_NORMAL     0x00
+//                MODE_STRONG5    0x02
+//                MODE_PROGRAM    0x04
+//                MODE_BREAK      0x08 (not supported)
+//
+// Returns:  current 1-Wire Net level
+//
+SMALLINT owLevel(int portnum, SMALLINT new_level)
+{
+   int rslt;
+   int docheck = FALSE;
+
+   // check for DS2480 bug
+   if (((SessionHandle[portnum] & 0x0F0) == 0x050) &&
+       (TMOneWireLevel(SessionHandle[portnum],1,0,0) == 1))
+      docheck = TRUE;
+
+   switch (new_level)
+   {
+      case MODE_NORMAL:
+         rslt = TMOneWireLevel(SessionHandle[portnum],0,0,0);
+         // test code for DS2480 bug
+         if (docheck)
+            TMTouchBit(SessionHandle[portnum],1);
+         break;
+      case MODE_STRONG5:
+         rslt = TMOneWireLevel(SessionHandle[portnum],0,1,0);
+         break;
+      case MODE_PROGRAM:
+         rslt = TMOneWireLevel(SessionHandle[portnum],0,3,0);
+         break;
+      case MODE_BREAK:
+         rslt = TMOneWireLevel(SessionHandle[portnum],0,2,0);
+         break;
+      default:
+         rslt = 0;
+   }
+
+   // Assume TMEX can do it so always return NewLevel
+   return new_level;
+}
+
+//--------------------------------------------------------------------------
+// This procedure creates a fixed 480 microseconds 12 volt pulse
+// on the 1-Wire Net for programming EPROM iButtons.
+//
+// 'portnum'     - number 0 to MAX_PORTNUM-1.  This number is provided to
+//                 indicate the symbolic port number.
+//
+// Returns:  TRUE  successful
+//           FALSE program voltage not available
+//
+SMALLINT owProgramPulse(int portnum)
+{
+   return TMProgramPulse(SessionHandle[portnum]);
+}
+
+//--------------------------------------------------------------------------
+//  Description:
+//     Delay for at least 'len' ms
+//
+void msDelay(int len)
+{
+   Sleep(len);
+}
+
+//--------------------------------------------------------------------------
+// Get the current millisecond tick count.  Does not have to represent
+// an actual time, it just needs to be an incrementing timer.
+//
+long msGettick(void)
+{
+   return GetTickCount();
+}
+
+//--------------------------------------------------------------------------
+// Send 8 bits of communication to the 1-Wire Net and verify that the
+// 8 bits read from the 1-Wire Net is the same (write operation).  
+// The parameter 'sendbyte' least significant 8 bits are used.  After the
+// 8 bits are sent change the level of the 1-Wire net.
+//
+// 'portnum'  - number 0 to MAX_PORTNUM-1.  This number was provided to
+//              OpenCOM to indicate the port number.
+// 'sendbyte' - 8 bits to send (least significant byte)
+//
+// Returns:  TRUE: bytes written and echo was the same
+//           FALSE: echo was not the same 
+//
+SMALLINT owWriteBytePower(int portnum, SMALLINT sendbyte)
+{
+   // prime for power delivery after byte
+   TMOneWireLevel(SessionHandle[portnum],0,1,2);
+
+   // send the byte and start strong pullup
+   if(TMTouchByte(SessionHandle[portnum],(short)sendbyte) != sendbyte)
+   {
+      TMOneWireLevel(SessionHandle[portnum],0,0,0);
+      return FALSE;
+   }
+
+   return TRUE;
+}
+
+//--------------------------------------------------------------------------
+// Read 8 bits of communication to the 1-Wire Net and verify that the
+// 8 bits read from the 1-Wire Net is the same (write operation).  
+// The parameter 'sendbyte' least significant 8 bits are used.  After the
+// 8 bits are read change the level of the 1-Wire net.
+//
+// 'portnum'  - number 0 to MAX_PORTNUM-1.  This number was provided to
+//              OpenCOM to indicate the port number.
+// 'sendbyte' - 8 bits to send (least significant byte)
+//
+// Returns:  TRUE: bytes written and echo was the same
+//           FALSE: echo was not the same 
+//
+SMALLINT owReadBytePower(int portnum)
+{
+   SMALLINT sendbyte = 0xFF;
+
+   // prime for power delivery after byte
+   TMOneWireLevel(SessionHandle[portnum],0,1,2);
+
+   // send the byte and start strong pullup
+   return TMTouchByte(SessionHandle[portnum],(short)sendbyte);
+}
+
+//--------------------------------------------------------------------------
+// Send 1 bit of communication to the 1-Wire Net and verify that the
+// response matches the 'applyPowerResponse' bit and apply power delivery
+// to the 1-Wire net.  Note that some implementations may apply the power
+// first and then turn it off if the response is incorrect.
+//
+// 'portnum'  - number 0 to MAX_PORTNUM-1.  This number was provided to
+//              OpenCOM to indicate the port number.
+// 'applyPowerResponse' - 1 bit response to check, if correct then start
+//                        power delivery 
+//
+// Returns:  TRUE: bit written and response correct, strong pullup now on
+//           FALSE: response incorrect
+//
+SMALLINT owReadBitPower(int portnum, SMALLINT applyPowerResponse)
+{
+   // prime for power delivery after bit
+   TMOneWireLevel(SessionHandle[portnum],0,1,1);
+
+   // send the byte and start strong pullup
+   if(TMTouchBit(SessionHandle[portnum],0x01) != applyPowerResponse)
+   {
+      TMOneWireLevel(SessionHandle[portnum],0,0,0);
+      return FALSE;
+   }
+
+   return TRUE;
+}
+
+//--------------------------------------------------------------------------
+// This procedure indicates wether the adapter can deliver power.
+//
+// 'portnum'  - number 0 to MAX_PORTNUM-1.  This number was provided to
+//              OpenCOM to indicate the port number.
+//
+// Returns:  TRUE  because all userial adapters have over drive. 
+//
+SMALLINT owHasPowerDelivery(int portnum)
+{
+   return TRUE;
+}
+
+//--------------------------------------------------------------------------
+// This procedure indicates wether the adapter can deliver power.
+//
+// 'portnum'  - number 0 to MAX_PORTNUM-1.  This number was provided to
+//              OpenCOM to indicate the port number.
+//
+// Returns:  TRUE  because all userial adapters have over drive. 
+//
+SMALLINT owHasOverDrive(int portnum)
+{
+   return TRUE;
+}
+
+//--------------------------------------------------------------------------
+// This procedure creates a fixed 480 microseconds 12 volt pulse 
+// on the 1-Wire Net for programming EPROM iButtons.
+//
+// 'portnum'  - number 0 to MAX_PORTNUM-1.  This number was provided to
+//              OpenCOM to indicate the port number.
+//
+// Returns:  TRUE  program volatage available
+//           FALSE program voltage not available  
+SMALLINT owHasProgramPulse(int portnum)
+{
+   return TMProgramPulse(SessionHandle[portnum]);
+}
\ No newline at end of file
diff --git a/tools_cmd/rwOW/tmexnet.c b/tools_cmd/rwOW/tmexnet.c
new file mode 100644 (file)
index 0000000..5f328c7
--- /dev/null
@@ -0,0 +1,249 @@
+//---------------------------------------------------------------------------
+// Copyright (C) 2001 Dallas Semiconductor Corporation, All Rights Reserved.
+//
+// Permission is hereby granted, free of charge, to any person obtaining a
+// copy of this software and associated documentation files (the "Software"),
+// to deal in the Software without restriction, including without limitation
+// the rights to use, copy, modify, merge, publish, distribute, sublicense,
+// and/or sell copies of the Software, and to permit persons to whom the
+// Software is furnished to do so, subject to the following conditions:
+//
+// The above copyright notice and this permission notice shall be included
+// in all copies or substantial portions of the Software.
+//
+// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
+// OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
+// MERCHANTABILITY,  FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
+// IN NO EVENT SHALL DALLAS SEMICONDUCTOR BE LIABLE FOR ANY CLAIM, DAMAGES
+// OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
+// ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
+// OTHER DEALINGS IN THE SOFTWARE.
+//
+// Except as contained in this notice, the name of Dallas Semiconductor
+// shall not be used except as stated in the Dallas Semiconductor
+// Branding Policy.
+//---------------------------------------------------------------------------
+//
+//  tmexnet.C - Wrapper class to hook 1-Wire Public Domain API to TMEX API
+//              for network functions.
+//
+//  Version: 3.00
+//
+//
+
+#include "ownet.h"
+#include <windows.h>
+
+uchar StateBuffer[MAX_PORTNUM][5120];
+
+// external TMEX variables
+extern long SessionHandle[MAX_PORTNUM];
+extern short far pascal TMSearch(long session_handle, void *start_buffer, 
+                                 short ResetSearch,  short PerformReset, 
+                                 short SrchCmd);
+extern short pascal TMFirst(long, void *);
+extern short pascal TMNext(long, void *);
+extern short pascal TMAccess(long, void *);
+extern short pascal TMStrongAccess(long, void *);
+extern short pascal TMStrongAlarmAccess(long, void *);
+extern short pascal TMOverAccess(long, void *);
+extern short pascal TMRom(long, void *, short *);
+extern short pascal TMFirstAlarm(long, void *);
+extern short pascal TMNextAlarm(long, void *);
+extern short pascal TMFamilySearchSetup(long, void *, short);
+extern short pascal TMSkipFamily(long, void *);
+extern short pascal TMAutoOverDrive(long, void *, short);
+
+
+//--------------------------------------------------------------------------
+// The 'owFirst' finds the first device on the 1-Wire Net  This function
+// contains one parameter 'alarm_only'.  When
+// 'alarm_only' is TRUE (1) the find alarm command 0xEC is
+// sent instead of the normal search command 0xF0.
+// Using the find alarm command 0xEC will limit the search to only
+// 1-Wire devices that are in an 'alarm' state.
+//
+// 'portnum'    - number 0 to MAX_PORTNUM-1.  This number is provided to
+//                indicate the symbolic port number.
+// 'do_reset'   - TRUE (1) perform reset before search, FALSE (0) do not
+//                perform reset before search.
+// 'alarm_only' - TRUE (1) the find alarm command 0xEC is
+//                sent instead of the normal search command 0xF0
+//
+// Returns:   TRUE (1) : when a 1-Wire device was found and it's
+//                        Serial Number placed in the global SerialNum[portnum]
+//            FALSE (0): There are no devices on the 1-Wire Net.
+//
+SMALLINT owFirst(int portnum, SMALLINT do_reset, SMALLINT alarm_only)
+{
+   return (TMSearch(SessionHandle[portnum], StateBuffer[portnum], 1, 
+                    (short)do_reset, (short)((alarm_only) ? 0xEC : 0xF0)) == 1);
+}
+
+//--------------------------------------------------------------------------
+// The 'owNext' function does a general search.  This function
+// continues from the previos search state. The search state
+// can be reset by using the 'owFirst' function.
+// This function contains one parameter 'alarm_only'.
+// When 'alarm_only' is TRUE (1) the find alarm command
+// 0xEC is sent instead of the normal search command 0xF0.
+// Using the find alarm command 0xEC will limit the search to only
+// 1-Wire devices that are in an 'alarm' state.
+//
+// 'portnum'    - number 0 to MAX_PORTNUM-1.  This number is provided to
+//                indicate the symbolic port number.
+// 'do_reset'   - TRUE (1) perform reset before search, FALSE (0) do not
+//                perform reset before search.
+// 'alarm_only' - TRUE (1) the find alarm command 0xEC is
+//                sent instead of the normal search command 0xF0
+//
+// Returns:   TRUE (1) : when a 1-Wire device was found and it's
+//                       Serial Number placed in the global SerialNum[portnum]
+//            FALSE (0): when no new device was found.  Either the
+//                       last search was the last device or there
+//                       are no devices on the 1-Wire Net.
+//
+SMALLINT owNext(int portnum, SMALLINT do_reset, SMALLINT alarm_only)
+{
+   return (TMSearch(SessionHandle[portnum], StateBuffer[portnum], 0, 
+                    (short)do_reset, (short)((alarm_only) ? 0xEC : 0xF0)) == 1);
+}
+
+//--------------------------------------------------------------------------
+// The 'owSerialNum' function either reads or sets the SerialNum buffer
+// that is used in the search functions 'owFirst' and 'owNext'.
+// This function contains two parameters, 'serialnum_buf' is a pointer
+// to a buffer provided by the caller.  'serialnum_buf' should point to
+// an array of 8 unsigned chars.  The second parameter is a flag called
+// 'do_read' that is TRUE (1) if the operation is to read and FALSE
+// (0) if the operation is to set the internal SerialNum buffer from
+// the data in the provided buffer.
+//
+// 'portnum'       - number 0 to MAX_PORTNUM-1.  This number is provided to
+//                   indicate the symbolic port number.
+// 'serialnum_buf' - buffer to that contains the serial number to set
+//                   when do_read = FALSE (0) and buffer to get the serial
+//                   number when do_read = TRUE (1).
+// 'do_read'       - flag to indicate reading (1) or setting (0) the current
+//                   serial number.
+//
+void owSerialNum(int portnum, uchar *serialnum_buf, SMALLINT do_read)
+{
+   short ROM[8],i;
+
+   // check if reading or writing
+   if (do_read)
+   {
+      ROM[0] = 0;
+   }
+   else
+   {
+      for (i = 0; i < 8; i++)
+         ROM[i] = serialnum_buf[i];
+   }
+
+   // call TMEX to read or set the current device
+   TMRom(SessionHandle[portnum], StateBuffer[portnum], ROM);
+
+   // place in 'serialnum_buf'
+   if (do_read)
+   {
+      for (i = 0; i < 8; i++)
+         serialnum_buf[i] = (uchar)ROM[i];
+   }
+}
+
+//--------------------------------------------------------------------------
+// Setup the search algorithm to find a certain family of devices
+// the next time a search function is called 'owNext'.
+//
+// 'portnum'       - number 0 to MAX_PORTNUM-1.  This number was provided to
+//                   OpenCOM to indicate the port number.
+// 'search_family' - family code type to set the search algorithm to find
+//                   next.
+//
+void owFamilySearchSetup(int portnum, SMALLINT search_family)
+{
+   TMFamilySearchSetup(SessionHandle[portnum], StateBuffer[portnum], 
+                       (short)search_family);
+}
+
+//--------------------------------------------------------------------------
+// Set the current search state to skip the current family code.
+//
+// 'portnum'     - number 0 to MAX_PORTNUM-1.  This number is provided to
+//                 indicate the symbolic port number.
+//
+void owSkipFamily(int portnum)
+{
+   TMSkipFamily(SessionHandle[portnum], StateBuffer[portnum]);
+}
+
+//--------------------------------------------------------------------------
+// The 'owAccess' function resets the 1-Wire and sends a MATCH Serial
+// Number command followed by the current SerialNum code. After this
+// function is complete the 1-Wire device is ready to accept device-specific
+// commands.
+//
+// 'portnum'     - number 0 to MAX_PORTNUM-1.  This number is provided to
+//                 indicate the symbolic port number.
+//
+// Returns:   TRUE (1) : reset indicates present and device is ready
+//                       for commands.
+//            FALSE (0): reset does not indicate presence or echos 'writes'
+//                       are not correct.
+//
+SMALLINT owAccess(int portnum)
+{
+   return (TMAccess(SessionHandle[portnum], StateBuffer[portnum]) == 1);
+}
+
+//----------------------------------------------------------------------
+// The function 'owVerify' verifies that the current device
+// is in contact with the 1-Wire Net.
+// Using the find alarm command 0xEC will verify that the device
+// is in contact with the 1-Wire Net and is in an 'alarm' state.
+//
+// 'portnum'     - number 0 to MAX_PORTNUM-1.  This number is provided to
+//                 indicate the symbolic port number.
+// 'alarm_only'  - TRUE (1) the find alarm command 0xEC
+//                 is sent instead of the normal search
+//                 command 0xF0.
+//
+// Returns:   TRUE (1) : when the 1-Wire device was verified
+//                       to be on the 1-Wire Net
+//                       with alarm_only == FALSE
+//                       or verified to be on the 1-Wire Net
+//                       AND in an alarm state when
+//                       alarm_only == TRUE.
+//            FALSE (0): the 1-Wire device was not on the
+//                       1-Wire Net or if alarm_only
+//                       == TRUE, the device may be on the
+//                       1-Wire Net but in a non-alarm state.
+//
+SMALLINT owVerify(int portnum, SMALLINT alarm_only)
+{
+   if (alarm_only)
+      return (TMStrongAlarmAccess(SessionHandle[portnum], StateBuffer[portnum]) == 1);
+   else
+      return (TMStrongAccess(SessionHandle[portnum], StateBuffer[portnum]) == 1);
+}
+
+//----------------------------------------------------------------------
+// Perform a overdrive MATCH command to select the 1-Wire device with
+// the address in the ID data register.
+//
+// 'portnum'     - number 0 to MAX_PORTNUM-1.  This number is provided to
+//                 indicate the symbolic port number.
+//
+// Returns:  TRUE: If the device is present on the 1-Wire Net and
+//                 can do overdrive then the device is selected.
+//           FALSE: Device is not present or not capable of overdrive.
+//
+//  *Note: This function could be converted to send DS2480
+//         commands in one packet.
+//
+SMALLINT owOverdriveAccess(int portnum)
+{
+   return (TMOverAccess(SessionHandle[portnum], StateBuffer[portnum]) == 1);
+}
diff --git a/tools_cmd/rwOW/tmexses.c b/tools_cmd/rwOW/tmexses.c
new file mode 100644 (file)
index 0000000..793d650
--- /dev/null
@@ -0,0 +1,212 @@
+//---------------------------------------------------------------------------
+// Copyright (C) 2001 Dallas Semiconductor Corporation, All Rights Reserved.
+//
+// Permission is hereby granted, free of charge, to any person obtaining a
+// copy of this software and associated documentation files (the "Software"),
+// to deal in the Software without restriction, including without limitation
+// the rights to use, copy, modify, merge, publish, distribute, sublicense,
+// and/or sell copies of the Software, and to permit persons to whom the
+// Software is furnished to do so, subject to the following conditions:
+//
+// The above copyright notice and this permission notice shall be included
+// in all copies or substantial portions of the Software.
+//
+// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
+// OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
+// MERCHANTABILITY,  FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
+// IN NO EVENT SHALL DALLAS SEMICONDUCTOR BE LIABLE FOR ANY CLAIM, DAMAGES
+// OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
+// ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
+// OTHER DEALINGS IN THE SOFTWARE.
+//
+// Except as contained in this notice, the name of Dallas Semiconductor
+// shall not be used except as stated in the Dallas Semiconductor
+// Branding Policy.
+//---------------------------------------------------------------------------
+//
+//  owsestmx.c - Acquire and release a Session on the 1-Wire Net using TMEX.
+//               (Requires TMEX 3.11 or newer)
+//
+//  Version: 2.01
+//
+//  History: 1.03 -> 2.00  Changed 'MLan' to 'ow'. Added support for
+//                         multiple ports.
+//           2.00 -> 2.01  Added support for owError library.
+//
+
+#include <stdio.h>
+#include <windows.h>
+#include "ownet.h"
+
+// external function prototypes
+extern long  far pascal TMExtendedStartSession(short, short, void far *);
+extern short far pascal TMEndSession(long);
+extern short far pascal TMClose(long);
+extern short far pascal TMSetup(long);
+extern short far pascal TMReadDefaultPort(short far *, short far *);
+
+short PortNum=1,PortType=2;
+long  SessionHandle[MAX_PORTNUM];
+SMALLINT handle_init = FALSE;
+
+//---------------------------------------------------------------------------
+// Attempt to acquire a 1-Wire net using a com port and a DS2480 based
+// adapter.
+//
+// 'port_zstr'     - zero terminated port name.  For this platform
+//                   use format {port number, port type}.
+//
+// Returns: port number and -1 if not successful in setting up the port.
+//
+int owAcquireEx(char *port_zstr)
+{
+   int portnum;
+   int string_counter, counter, i, lenmax;
+   char portnum_str[15];
+   char porttype_str[15];
+   void *tmex_options = NULL;
+
+   if(!handle_init)
+   {
+      for(i=0; i<MAX_PORTNUM; i++)
+         SessionHandle[i] = 0;
+      handle_init = TRUE;
+   }
+
+   // check to find first available handle slot
+   for(portnum = 0; portnum<MAX_PORTNUM; portnum++)
+   {
+      if(!SessionHandle[portnum])
+         break;
+   }
+   OWASSERT( portnum<MAX_PORTNUM, OWERROR_PORTNUM_ERROR, -1 );
+
+   // convert the string in port_zstr to be the port number and port type
+   if(port_zstr)
+   {
+      lenmax = strlen(port_zstr);
+      if (lenmax > 12)
+         lenmax = 12;
+      string_counter = 1;
+      counter = 0;
+      do
+      {
+         portnum_str[counter] = port_zstr[string_counter];
+
+         counter++;
+         string_counter++;
+      }
+      while((port_zstr[string_counter] != ',') && (string_counter <= lenmax));
+
+      portnum_str[counter] = '\0';
+
+      string_counter++;
+      counter = 0;
+
+      do
+      {
+         porttype_str[counter] = port_zstr[string_counter];
+
+         counter++;
+         string_counter++;
+      }
+      while((port_zstr[string_counter] != '}') && (string_counter <= lenmax));
+
+      porttype_str[counter] = '\0';
+
+      PortNum = atoi(portnum_str);
+      PortType = atoi(porttype_str);
+   }
+
+   // open a session
+   SessionHandle[portnum] = TMExtendedStartSession(PortNum,PortType,tmex_options);
+
+   // check the session handle
+   if (SessionHandle[portnum] <= 0)
+   {
+      OWERROR(OWERROR_GET_SYSTEM_RESOURCE_FAILED);
+      SessionHandle[portnum] = 0;
+      return -1;
+   }
+
+   // setup the port
+   if (TMSetup(SessionHandle[portnum]) != 1)
+   {
+      TMClose(SessionHandle[portnum]);
+      TMEndSession(SessionHandle[portnum]);
+      OWERROR(OWERROR_SYSTEM_RESOURCE_INIT_FAILED);
+      SessionHandle[portnum] = 0;
+      return -1;
+   }
+
+   return portnum;
+}
+
+//---------------------------------------------------------------------------
+// Attempt to acquire a 1-Wire net using a com port and a DS2480 based
+// adapter.
+//
+// 'portnum'    - number 0 to MAX_PORTNUM-1.  This number is provided to
+//                indicate the symbolic port number.
+// 'port_zstr'  - zero terminated port name.  For this platform
+//                use format COMX where X is the port number.
+//
+// Returns: TRUE - success, COM port opened
+//
+SMALLINT owAcquire(int portnum, char *port_zstr)
+{
+   int i;
+
+   if(!handle_init)
+   {
+      for(i=0; i<MAX_PORTNUM; i++)
+         SessionHandle[i] = 0;
+      handle_init = TRUE;
+   }
+
+   OWASSERT( portnum<MAX_PORTNUM && portnum>=0 && !SessionHandle[portnum],
+             OWERROR_PORTNUM_ERROR, FALSE );
+
+   // read the default PortNum and PortType
+   TMReadDefaultPort(&PortNum,&PortType);
+
+   // convert the string in port_zstr to be the port number
+   PortNum = atoi(port_zstr);
+
+   // open a session
+   SessionHandle[portnum] = TMExtendedStartSession(PortNum,PortType,NULL);
+
+   // check the session handle
+   if (SessionHandle[portnum] <= 0)
+   {
+      OWERROR(OWERROR_GET_SYSTEM_RESOURCE_FAILED);
+      SessionHandle[portnum] = 0;
+      return FALSE;
+   }
+
+   // setup the port
+   if (TMSetup(SessionHandle[portnum]) != 1)
+   {
+      TMClose(SessionHandle[portnum]);
+      TMEndSession(SessionHandle[portnum]);
+      OWERROR(OWERROR_SYSTEM_RESOURCE_INIT_FAILED);
+      SessionHandle[portnum] = 0;
+      return FALSE;
+   }
+
+   return TRUE;
+}
+
+//---------------------------------------------------------------------------
+// Release the previously acquired a 1-Wire net.
+//
+// 'portnum'    - number 0 to MAX_PORTNUM-1.  This number is provided to
+//                indicate the symbolic port number.
+//
+void owRelease(int portnum)
+{
+   TMClose(SessionHandle[portnum]);
+   TMEndSession(SessionHandle[portnum]);
+   SessionHandle[portnum] = 0;
+}
+
diff --git a/tools_cmd/rwOW/tmextran.c b/tools_cmd/rwOW/tmextran.c
new file mode 100644 (file)
index 0000000..31d2cf7
--- /dev/null
@@ -0,0 +1,199 @@
+//---------------------------------------------------------------------------
+// Copyright (C) 1999 Dallas Semiconductor Corporation, All Rights Reserved.
+//
+// Permission is hereby granted, free of charge, to any person obtaining a
+// copy of this software and associated documentation files (the "Software"),
+// to deal in the Software without restriction, including without limitation
+// the rights to use, copy, modify, merge, publish, distribute, sublicense,
+// and/or sell copies of the Software, and to permit persons to whom the
+// Software is furnished to do so, subject to the following conditions:
+//
+// The above copyright notice and this permission notice shall be included
+// in all copies or substantial portions of the Software.
+//
+// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
+// OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
+// MERCHANTABILITY,  FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
+// IN NO EVENT SHALL DALLAS SEMICONDUCTOR BE LIABLE FOR ANY CLAIM, DAMAGES
+// OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
+// ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
+// OTHER DEALINGS IN THE SOFTWARE.
+//
+// Except as contained in this notice, the name of Dallas Semiconductor
+// shall not be used except as stated in the Dallas Semiconductor
+// Branding Policy.
+//---------------------------------------------------------------------------
+//
+//  tmexnet.C - Wrapper class to hook 1-Wire Public Domain API to TMEX API
+//              for transport functions.
+//
+//  Version: 3.00
+//
+
+#include "ownet.h"
+#include <windows.h>
+
+// external TMEX variables
+extern long SessionHandle[MAX_PORTNUM];
+extern short far pascal TMBlockIO(long, uchar *, short);
+extern short far pascal TMBlockStream(long, uchar *, short);
+
+//--------------------------------------------------------------------------
+// The 'owBlock' transfers a block of data to and from the
+// 1-Wire Net with an optional reset at the begining of communication.
+// The result is returned in the same buffer.
+//
+// 'do_reset' - cause a owTouchReset to occure at the begining of
+//              communication TRUE(1) or not FALSE(0)
+// 'tran_buf' - pointer to a block of unsigned
+//              chars of length 'TranferLength' that will be sent
+//              to the 1-Wire Net
+// 'tran_len' - length in bytes to transfer
+// Supported devices: all
+//
+// Returns:   TRUE (1) : The optional reset returned a valid
+//                       presence (do_reset == TRUE) or there
+//                       was no reset required.
+//            FALSE (0): The reset did not return a valid prsence
+//                       (do_reset == TRUE).
+//
+//  The maximum tran_len is 64
+//
+SMALLINT owBlock(int portnum, SMALLINT do_reset, uchar *tran_buf, SMALLINT tran_len)
+{
+   short rslt;
+
+   // check for a block too big
+   if (tran_len > 192)
+   {
+      OWERROR(OWERROR_BLOCK_TOO_BIG);
+      return FALSE;
+   }
+
+   // check if need to do a owTouchReset first
+   if (do_reset)
+      rslt = TMBlockIO(SessionHandle[portnum], tran_buf, (short)tran_len);
+   else
+      rslt = TMBlockStream(SessionHandle[portnum], tran_buf, (short)tran_len);
+
+   return (rslt == tran_len);
+}
+
+//--------------------------------------------------------------------------
+// Write a byte to an EPROM 1-Wire device.
+//
+// Supported devices: crc_type=0(CRC8)
+//                        DS1982
+//                    crc_type=1(CRC16)
+//                        DS1985, DS1986, DS2407
+//
+// 'portnum'    - number 0 to MAX_PORTNUM-1.  This number is provided to
+//                indicate the symbolic port number.
+// 'write_byte' - byte to program
+// 'addr'       - address of byte to program
+// 'write_cmd'  - command used to write (0x0F reg mem, 0x55 status)
+// 'crc_type'   - CRC used (0 CRC8, 1 CRC16)
+// 'do_access'  - Flag to access device for each byte
+//                (0 skip access, 1 do the access)
+//                WARNING, only use do_access=0 if programing the NEXT
+//                byte immediatly after the previous byte.
+//
+// Returns: >=0   success, this is the resulting byte from the program
+//                effort
+//          -1    error, device not connected or program pulse voltage
+//                not available
+//
+SMALLINT owProgramByte(int portnum, SMALLINT write_byte, int addr, SMALLINT write_cmd,
+                       SMALLINT crc_type, SMALLINT do_access)
+{
+   ushort lastcrc16;
+   uchar lastcrc8;
+
+   // optionally access the device
+   if (do_access)
+   {
+      if (!owAccess(portnum))
+      {
+         OWERROR(OWERROR_ACCESS_FAILED);
+         return -1;
+      }
+
+      // send the write command
+      if (!owWriteByte(portnum,write_cmd))
+      {
+         OWERROR(OWERROR_WRITE_BYTE_FAILED);
+         return -1;
+      }
+
+      // send the address
+      if (!owWriteByte(portnum,addr & 0xFF) || !owWriteByte(portnum,addr >> 8))
+      {
+         OWERROR(OWERROR_WRITE_BYTE_FAILED);
+         return -1;
+      }
+   }
+
+   // send the data to write
+   if (!owWriteByte(portnum,write_byte))
+   {
+      OWERROR(OWERROR_WRITE_BYTE_FAILED);
+      return -1;
+   }
+
+   // read the CRC
+   if (crc_type == 0)
+   {
+      // calculate CRC8
+      if (do_access)
+      {
+         setcrc8(portnum,0);
+         docrc8(portnum,(uchar)write_cmd);
+         docrc8(portnum,(uchar)(addr & 0xFF));
+         docrc8(portnum,(uchar)(addr >> 8));
+      }
+      else
+         setcrc8(portnum,(uchar)(addr & 0xFF));
+
+      docrc8(portnum,(uchar)write_byte);
+      // read and calculate the read crc
+      lastcrc8 = docrc8(portnum,(uchar)owReadByte(portnum));
+      // crc should now be 0x00
+      if (lastcrc8 != 0)
+      {
+         OWERROR(OWERROR_CRC_FAILED);
+         return -1;
+      }
+   }
+   else
+   {
+      // CRC16
+      if (do_access)
+      {
+         setcrc16(portnum,0);
+         docrc16(portnum,(ushort)write_cmd);
+         docrc16(portnum,(ushort)(addr & 0xFF));
+         docrc16(portnum,(ushort)(addr >> 8));
+      }
+      else
+         setcrc16(portnum,(ushort)addr);
+      docrc16(portnum,(ushort)write_byte);
+      // read and calculate the read crc
+      docrc16(portnum,(ushort)owReadByte(portnum));
+      lastcrc16 = docrc16(portnum,(ushort)owReadByte(portnum));
+      // crc should now be 0xB001
+      if (lastcrc16 != 0xB001)
+         return -1;
+   }
+
+   // send the program pulse
+   if (!owProgramPulse(portnum))
+   {
+      OWERROR(OWERROR_PROGRAM_PULSE_FAILED);
+      return -1;
+   }
+
+   // read back and return the resulting byte
+   return owReadByte(portnum);
+}
+
+