From: Tobias Date: Wed, 23 Nov 2016 12:51:28 +0000 (+0100) Subject: HDC1080 support X-Git-Url: https://git.smho.de/?a=commitdiff_plain;h=3608ace7dd5bd4fa5d7d49224ef770b21596092c;p=owSlave2.git HDC1080 support --- diff --git a/DS18B20_Thermocouble_DS2438_SHT/DS18B20_DS2438.c b/DS18B20_Thermocouble_DS2438_SHT/DS18B20_DS2438.c index e78a682..d3e41f1 100644 --- a/DS18B20_Thermocouble_DS2438_SHT/DS18B20_DS2438.c +++ b/DS18B20_Thermocouble_DS2438_SHT/DS18B20_DS2438.c @@ -1,315 +1,315 @@ - -// 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 -#include -#include -#include -#include -#include -#include "../common/I2C/USI_TWI_Master.h" -#include "../common/I2C/SHT2x.h" - - -extern void OWINIT(); -extern void EXTERN_SLEEP(); - -const float k_rs[54] PROGMEM ={0.000000,24.125000,48.585366,72.731707,96.829268,121.097561,145.700000,170.600000,195.650000,220.625000,245.365854,269.853659,294.119048,318.195122,342.166667,366.000000,389.761905,413.428571,437.023810,460.558140,484.047619,507.511628,530.976190,554.418605,577.883721,601.395349,624.952381,648.571429,672.285714,696.073171,719.976190,744.000000,768.146341,792.439024,816.853659,841.414634,866.125000,890.975000,916.000000,941.179487,966.525000,992.025641,1017.717949,1043.589744,1069.657895,1095.945946,1122.432432,1149.184211,1176.189189,1203.472222,1231.083333,1259.000000,1287.285714,1315.941176}; -//const float j_rs[70] PROGMEM ={0, 18.302913, 34.830476, 50.783019, 70.653704, 90.505455, 110.341818, 130.165455, 149.163636, 160.791071, 180.596364, 200.398214, 220.200000, 240.000000, 250.882883, 270.603636, 290.409091, 310.216364, 330.025455, 342.472727, 360.649091, 380.461818, 400.275000, 420.087273, 435.275676, 450.703636, 470.503636, 490.298214, 510.082456, 523.486726, 540.621053, 560.370175, 580.105172, 591.979487, 610.527119, 630.213559, 644.601653, 660.534426, 680.168852, 690.787097, 710.391935, 729.123810, 740.559375, 760.126562, 770.684615, 790.235385, 800.782812, 820.331250, 834.681250, 850.446032, 870.017460, 880.600000, 900.196774, 911.099187, 930.432787, 950.073333, 960.728333, 980.396667, 1000.078333, 1010.772881, 1030.475862, 1050.187931, 1065.717241, 1080.631034, 1100.358621, 1120.089655, 1131.840000,1150.556897, 1170.294737, 1190.035088}; -double gettemp_rs(double V) { - uint8_t iv=(uint8_t)(V); - float t0=pgm_read_float(&(k_rs[iv])); - float t1=pgm_read_float(&(k_rs[iv+1])); - return t0+(t1-t0)/1*(V-iv); -} - - - - - -uint8_t owid1[8]={0x28, 0xA6, 0xD9, 0x84, 0x00, 0x00, 0x03, 0x68};/**/ -uint8_t owid2[8]={0x26, 0xA7, 0xD9, 0x84, 0x00, 0x00, 0x03, 0x20};/**/ -uint8_t config_info1[16]={0x01,0x02 ,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, 0x00,0x00, 0x01,0x00,0x00,0x00,0x00,0x00,0x00,0x00}; - -#if (owid>128) -#error "Variable not correct" -#endif - -extern uint8_t mode; -extern uint8_t gcontrol; -extern uint8_t reset_indicator; -extern uint8_t alarmflag; -volatile uint8_t wdcounter=5; - - -#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 - wdcounter++; - 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(void) { - uint8_t r; - DDRB&=~(1<0) { - if (par==0) { - //PORTB|=(1<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; - } - } - ares[par]=ADmess(); - par++; - if (par>15) par=0; - wdcounter=0; - } - - if (gcontrol==1) { - gcontrol=0; - sum=0; - for(uint8_t i=0;i<16;i++) { - sum+=ares[i]; - } - V=sum/20.0/1024.0*1.12*1000.0/16.0; - //V=sum/20.0/1024.0*1.01*1000.0/16.0; - uint16_t htemp; - ktemp=gettemp_rs(V); - //htemp=(ktemp*16)/10; - htemp=(ktemp*16+temperatureC*1.6)/10; - - uint16_t w=htemp; - uint8_t t8=w>>4; - uint8_t af=0; - if (t8>pack1.TH) af=1; - if (t8<=pack1.TL) af=1; - cli(); - pack1.temp=w; - //pack.temp++; - alarmflag=af; - sei(); - EXTERN_SLEEP(); - } - - - -#if defined(__AVR_ATtiny25__)||defined(__AVR_ATtiny45__) || defined(__AVR_ATtiny85__) - if (((TIMSK & (1< +#include +#include +#include +#include +#include +#include "../common/I2C/USI_TWI_Master.h" +#include "../common/I2C/SHT2x.h" + + +extern void OWINIT(); +extern void EXTERN_SLEEP(); + +const float k_rs[54] PROGMEM ={0.000000,24.125000,48.585366,72.731707,96.829268,121.097561,145.700000,170.600000,195.650000,220.625000,245.365854,269.853659,294.119048,318.195122,342.166667,366.000000,389.761905,413.428571,437.023810,460.558140,484.047619,507.511628,530.976190,554.418605,577.883721,601.395349,624.952381,648.571429,672.285714,696.073171,719.976190,744.000000,768.146341,792.439024,816.853659,841.414634,866.125000,890.975000,916.000000,941.179487,966.525000,992.025641,1017.717949,1043.589744,1069.657895,1095.945946,1122.432432,1149.184211,1176.189189,1203.472222,1231.083333,1259.000000,1287.285714,1315.941176}; +//const float j_rs[70] PROGMEM ={0, 18.302913, 34.830476, 50.783019, 70.653704, 90.505455, 110.341818, 130.165455, 149.163636, 160.791071, 180.596364, 200.398214, 220.200000, 240.000000, 250.882883, 270.603636, 290.409091, 310.216364, 330.025455, 342.472727, 360.649091, 380.461818, 400.275000, 420.087273, 435.275676, 450.703636, 470.503636, 490.298214, 510.082456, 523.486726, 540.621053, 560.370175, 580.105172, 591.979487, 610.527119, 630.213559, 644.601653, 660.534426, 680.168852, 690.787097, 710.391935, 729.123810, 740.559375, 760.126562, 770.684615, 790.235385, 800.782812, 820.331250, 834.681250, 850.446032, 870.017460, 880.600000, 900.196774, 911.099187, 930.432787, 950.073333, 960.728333, 980.396667, 1000.078333, 1010.772881, 1030.475862, 1050.187931, 1065.717241, 1080.631034, 1100.358621, 1120.089655, 1131.840000,1150.556897, 1170.294737, 1190.035088}; +double gettemp_rs(double V) { + uint8_t iv=(uint8_t)(V); + float t0=pgm_read_float(&(k_rs[iv])); + float t1=pgm_read_float(&(k_rs[iv+1])); + return t0+(t1-t0)/1*(V-iv); +} + + + + + +uint8_t owid1[8]={0x28, 0xA6, 0xD9, 0x84, 0x00, 0x00, 0x03, 0x68};/**/ +uint8_t owid2[8]={0x26, 0xA7, 0xD9, 0x84, 0x00, 0x00, 0x03, 0x20};/**/ +uint8_t config_info1[16]={0x01,0x02 ,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, 0x00,0x00, 0x01,0x00,0x00,0x00,0x00,0x00,0x00,0x00}; + +#if (owid>128) +#error "Variable not correct" +#endif + +extern uint8_t mode; +extern uint8_t gcontrol; +extern uint8_t reset_indicator; +extern uint8_t alarmflag; +volatile uint8_t wdcounter=5; + + +#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 + wdcounter++; + 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(void) { + uint8_t r; + DDRB&=~(1<0) { + if (par==0) { + //PORTB|=(1<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; + } + } + ares[par]=ADmess(); + par++; + if (par>15) par=0; + wdcounter=0; + } + + if (gcontrol==1) { + gcontrol=0; + sum=0; + for(uint8_t i=0;i<16;i++) { + sum+=ares[i]; + } + V=sum/20.0/1024.0*1.12*1000.0/16.0; + //V=sum/20.0/1024.0*1.01*1000.0/16.0; + uint16_t htemp; + ktemp=gettemp_rs(V); + //htemp=(ktemp*16)/10; + htemp=(ktemp*16+temperatureC*1.6)/10; + + uint16_t w=htemp; + uint8_t t8=w>>4; + uint8_t af=0; + if (t8>pack1.TH) af=1; + if (t8<=pack1.TL) af=1; + cli(); + pack1.temp=w; + //pack.temp++; + alarmflag=af; + sei(); + EXTERN_SLEEP(); + } + + + +#if defined(__AVR_ATtiny25__)||defined(__AVR_ATtiny45__) || defined(__AVR_ATtiny85__) + if (((TIMSK & (1< -#include -#include -#include -#include - - - - -extern void OWINIT(); - -uint8_t owid[8]={0x1D, 0xA2, 0xD9, 0x84, 0x00, 0x26, 0x02, 0x5C};/**/ -uint8_t config_info[16]={0x02,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x02,0x00,0x00,0x00,0x00,0x00,0x00,0x00}; - - - -extern uint8_t mode; -extern uint8_t gcontrol; -extern uint8_t reset_indicator; - - -volatile uint8_t wdcounter; - - - - -typedef union { - volatile uint8_t bytes[45]; - struct { - uint16_t addr; - uint8_t status; - uint8_t scratch[32];//3 - uint32_t counter; //35 - uint32_t zero; //39 - uint16_t crc; //43 - }; -} counterpack_t; -counterpack_t pack; - -typedef union { - uint32_t c32[4]; - uint8_t c8[16]; -} counters_t; - -volatile counters_t counters; - -volatile uint8_t istat; - -#define PCINT_VECTOR PCINT0_vect -#define PIN_REG PINA -#define PIN_DDR DDRA -#define PIN_CH0 (1< +#include +#include +#include +#include + + + + +extern void OWINIT(); + +uint8_t owid[8]={0x1D, 0xA2, 0xD9, 0x84, 0x00, 0x26, 0x02, 0x5C};/**/ +uint8_t config_info[16]={0x02,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x02,0x00,0x00,0x00,0x00,0x00,0x00,0x00}; + + + +extern uint8_t mode; +extern uint8_t gcontrol; +extern uint8_t reset_indicator; + + +volatile uint8_t wdcounter; + + + + +typedef union { + volatile uint8_t bytes[45]; + struct { + uint16_t addr; + uint8_t status; + uint8_t scratch[32];//3 + uint32_t counter; //35 + uint32_t zero; //39 + uint16_t crc; //43 + }; +} counterpack_t; +counterpack_t pack; + +typedef union { + uint32_t c32[4]; + uint8_t c8[16]; +} counters_t; + +volatile counters_t counters; + +volatile uint8_t istat; + +#define PCINT_VECTOR PCINT0_vect +#define PIN_REG PINA +#define PIN_DDR DDRA +#define PIN_CH0 (1< -#include -#include -#include -#include -#include -#include "../common/I2C/USI_TWI_Master.h" -#include "../common/I2C/HDC1080.h" -#include "../common/calibr.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=5; - - -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<2) { - //PORTB|=(1< +#include +#include +#include +#include +#include +#include "../common/I2C/USI_TWI_Master.h" +#include "../common/I2C/HDC1080.h" +#include "../common/calibr.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=5; + + +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<2) { + //PORTB|=(1< -#include -#include -#include -#include -#include -#include "../common/I2C/USI_TWI_Master.h" -#include "../common/I2C/SHT2x.h" -#include "../common/I2C/BMP280.h" -extern void OWINIT(); -extern void EXTERN_SLEEP(); - -uint8_t owid[8]={0x20, 0xA2, 0xD9, 0x84, 0x00, 0x16, 0x02, 0x5D};/**/ -uint8_t config_info[16]={0x01,14,0x04,0x08, 0x06,0x09, 0x02,16,0x02,0x00,0x00,0x00,0x00,0x00,0x00,0x00}; - -#if (owid>128) -#error "Variable not correct" -#endif - -extern uint8_t mode; -extern uint8_t gcontrol; -extern uint8_t reset_indicator; -extern uint8_t alarmflag; -volatile uint8_t wdcounter=10; - - -#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; -} - -typedef union { - volatile uint8_t bytes[0x20]; - struct { - //Page0 - uint16_t A; //0 - uint16_t B; //2 - uint16_t C; //4 - uint16_t D; //6 - //Page1 - uint8_t CSA1; - uint8_t CSA2; - uint8_t CSB1; - uint8_t CSB2; - uint8_t CSC1; - uint8_t CSC2; - uint8_t CSD1; - uint8_t CSD2; - //Page2 - uint8_t LA; - uint8_t HA; - uint8_t LB; - uint8_t HB; - uint8_t LC; - uint8_t HC; - uint8_t LD; - uint8_t HD; - //Page3 - uint8_t FC1; - uint8_t FC2; - uint8_t FC3; - uint8_t FC4; - uint8_t VCCP; - uint8_t FC5; - uint8_t FC6; - uint8_t FC7; - uint8_t convc1; - uint8_t convc2; - - - }; -} 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; -uint32_t P; -int32_t t; - - - - -int main(void){ - pack.A=0; - pack.B=0; - pack.C=0; - pack.D=0; - pack.CSA1=0x08; - pack.CSA2=0x8C; - pack.CSB1=0x08; - pack.CSB2=0x8C; - pack.CSC1=0x08; - pack.CSC2=0x8C; - pack.CSD1=0x08; - pack.CSD2=0x8C; - pack.HA=0xFF; - pack.LA=0x00; - pack.HB=0xFF; - pack.LB=0x00; - pack.HC=0xFF; - pack.LC=0x00; - pack.HD=0xFF; - pack.LD=0x00; - pack.VCCP=0; - PORTB=0xFF-(1<3) { - SHT2x_MeasurePoll(HUMIDITY, &sRH); - // --- measure temperature with "Polling Mode" (no hold master) --- - SHT2x_MeasurePoll(TEMP, &sT); - //-- calculate humidity and temperature -- - temperatureC = SHT2x_CalcTemperatureC(sT); - humidityRH = SHT2x_CalcRH(sRH); - bmp280ConvertInt(&t,&P,1); - wdcounter=0; - } - - - - - - - if (gcontrol) { - //PORTB|=(1<pack.HA) {alarmflag=1;pack.CSA2|=0x20;} - if (pack.CSA2&0x04) //AEL - if (pack.bytes[1]pack.HB) {alarmflag=1;pack.CSB2|=0x20;} - if (pack.CSB2&0x04) //AEL - if (pack.bytes[1]pack.HC) {alarmflag=1;pack.CSC2|=0x20;} - if (pack.CSC2&0x04) //AEL - if (pack.bytes[1]pack.HD) {alarmflag=1;pack.CSD2|=0x20;} - if (pack.CSD2&0x04) //AEL - if (pack.bytes[1] +#include +#include +#include +#include +#include +#include "../common/I2C/USI_TWI_Master.h" +#include "../common/I2C/SHT2x.h" +#include "../common/I2C/BMP280.h" +extern void OWINIT(); +extern void EXTERN_SLEEP(); + +uint8_t owid[8]={0x20, 0xA2, 0xD9, 0x84, 0x00, 0x16, 0x02, 0x5D};/**/ +uint8_t config_info[16]={0x01,14,0x04,0x08, 0x06,0x09, 0x02,16,0x02,0x00,0x00,0x00,0x00,0x00,0x00,0x00}; + +#if (owid>128) +#error "Variable not correct" +#endif + +extern uint8_t mode; +extern uint8_t gcontrol; +extern uint8_t reset_indicator; +extern uint8_t alarmflag; +volatile uint8_t wdcounter=10; + + +#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; +} + +typedef union { + volatile uint8_t bytes[0x20]; + struct { + //Page0 + uint16_t A; //0 + uint16_t B; //2 + uint16_t C; //4 + uint16_t D; //6 + //Page1 + uint8_t CSA1; + uint8_t CSA2; + uint8_t CSB1; + uint8_t CSB2; + uint8_t CSC1; + uint8_t CSC2; + uint8_t CSD1; + uint8_t CSD2; + //Page2 + uint8_t LA; + uint8_t HA; + uint8_t LB; + uint8_t HB; + uint8_t LC; + uint8_t HC; + uint8_t LD; + uint8_t HD; + //Page3 + uint8_t FC1; + uint8_t FC2; + uint8_t FC3; + uint8_t FC4; + uint8_t VCCP; + uint8_t FC5; + uint8_t FC6; + uint8_t FC7; + uint8_t convc1; + uint8_t convc2; + + + }; +} 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; +uint32_t P; +int32_t t; + + + + +int main(void){ + pack.A=0; + pack.B=0; + pack.C=0; + pack.D=0; + pack.CSA1=0x08; + pack.CSA2=0x8C; + pack.CSB1=0x08; + pack.CSB2=0x8C; + pack.CSC1=0x08; + pack.CSC2=0x8C; + pack.CSD1=0x08; + pack.CSD2=0x8C; + pack.HA=0xFF; + pack.LA=0x00; + pack.HB=0xFF; + pack.LB=0x00; + pack.HC=0xFF; + pack.LC=0x00; + pack.HD=0xFF; + pack.LD=0x00; + pack.VCCP=0; + PORTB=0xFF-(1<3) { + SHT2x_MeasurePoll(HUMIDITY, &sRH); + // --- measure temperature with "Polling Mode" (no hold master) --- + SHT2x_MeasurePoll(TEMP, &sT); + //-- calculate humidity and temperature -- + temperatureC = SHT2x_CalcTemperatureC(sT); + humidityRH = SHT2x_CalcRH(sRH); + bmp280ConvertInt(&t,&P,1); + wdcounter=0; + } + + + + + + + if (gcontrol) { + //PORTB|=(1<pack.HA) {alarmflag=1;pack.CSA2|=0x20;} + if (pack.CSA2&0x04) //AEL + if (pack.bytes[1]pack.HB) {alarmflag=1;pack.CSB2|=0x20;} + if (pack.CSB2&0x04) //AEL + if (pack.bytes[1]pack.HC) {alarmflag=1;pack.CSC2|=0x20;} + if (pack.CSC2&0x04) //AEL + if (pack.bytes[1]pack.HD) {alarmflag=1;pack.CSD2|=0x20;} + if (pack.CSD2&0x04) //AEL + if (pack.bytes[1] -#include -#include -#include -#include -#include -#include "../common/I2C/USI_TWI_Master.h" -#include "../common/I2C/SHT2x.h" -#include "../common/I2C/MAX44009.h" -extern void OWINIT(); -extern void EXTERN_SLEEP(); - -uint8_t owid[8]={0x20, 0xA2, 0xD9, 0x84, 0x00, 0x16, 0x02, 0x5D};/**/ -uint8_t config_info[16]={0x01,14,0x04,0x08, 0x03,15, 0x06,0x09,0x00,0x00,0x00,0x00,0x00,0x00,0x00}; - -#if (owid>128) -#error "Variable not correct" -#endif - -extern uint8_t mode; -extern uint8_t gcontrol; -extern uint8_t reset_indicator; -extern uint8_t alarmflag; -volatile uint8_t wdcounter=10; - - -#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; -} - -typedef union { - volatile uint8_t bytes[0x20]; - struct { - //Page0 - uint16_t A; //0 - uint16_t B; //2 - uint16_t C; //4 - uint16_t D; //6 - //Page1 - uint8_t CSA1; - uint8_t CSA2; - uint8_t CSB1; - uint8_t CSB2; - uint8_t CSC1; - uint8_t CSC2; - uint8_t CSD1; - uint8_t CSD2; - //Page2 - uint8_t LA; - uint8_t HA; - uint8_t LB; - uint8_t HB; - uint8_t LC; - uint8_t HC; - uint8_t LD; - uint8_t HD; - //Page3 - uint8_t FC1; - uint8_t FC2; - uint8_t FC3; - uint8_t FC4; - uint8_t VCCP; - uint8_t FC5; - uint8_t FC6; - uint8_t FC7; - uint8_t convc1; - uint8_t convc2; - - - }; -} 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; -uint32_t P; -int32_t t; -uint8_t max_adr=0; - - - -int main(void){ - pack.A=0; - pack.B=0; - pack.C=0; - pack.D=0; - pack.CSA1=0x08; - pack.CSA2=0x8C; - pack.CSB1=0x08; - pack.CSB2=0x8C; - pack.CSC1=0x08; - pack.CSC2=0x8C; - pack.CSD1=0x08; - pack.CSD2=0x8C; - pack.HA=0xFF; - pack.LA=0x00; - pack.HB=0xFF; - pack.LB=0x00; - pack.HC=0xFF; - pack.LC=0x00; - pack.HD=0xFF; - pack.LD=0x00; - pack.VCCP=0; - PORTB=0xFF-(1<3) { - SHT2x_MeasurePoll(HUMIDITY, &sRH); - // --- measure temperature with "Polling Mode" (no hold master) --- - SHT2x_MeasurePoll(TEMP, &sT); - //-- calculate humidity and temperature -- - temperatureC = SHT2x_CalcTemperatureC(sT); - humidityRH = SHT2x_CalcRH(sRH); - - 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; - l=(log(l)*1000)+32767.0; - wdcounter=0; - } - - - - - - - if (gcontrol) { - //PORTB|=(1<pack.HA) {alarmflag=1;pack.CSA2|=0x20;} - if (pack.CSA2&0x04) //AEL - if (pack.bytes[1]pack.HB) {alarmflag=1;pack.CSB2|=0x20;} - if (pack.CSB2&0x04) //AEL - if (pack.bytes[1]pack.HC) {alarmflag=1;pack.CSC2|=0x20;} - if (pack.CSC2&0x04) //AEL - if (pack.bytes[1]pack.HD) {alarmflag=1;pack.CSD2|=0x20;} - if (pack.CSD2&0x04) //AEL - if (pack.bytes[1] +#include +#include +#include +#include +#include +#include "../common/I2C/USI_TWI_Master.h" +#include "../common/I2C/SHT2x.h" +#include "../common/I2C/MAX44009.h" +extern void OWINIT(); +extern void EXTERN_SLEEP(); + +uint8_t owid[8]={0x20, 0xA2, 0xD9, 0x84, 0x00, 0x16, 0x02, 0x5D};/**/ +uint8_t config_info[16]={0x01,14,0x04,0x08, 0x03,15, 0x06,0x09,0x00,0x00,0x00,0x00,0x00,0x00,0x00}; + +#if (owid>128) +#error "Variable not correct" +#endif + +extern uint8_t mode; +extern uint8_t gcontrol; +extern uint8_t reset_indicator; +extern uint8_t alarmflag; +volatile uint8_t wdcounter=10; + + +#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; +} + +typedef union { + volatile uint8_t bytes[0x20]; + struct { + //Page0 + uint16_t A; //0 + uint16_t B; //2 + uint16_t C; //4 + uint16_t D; //6 + //Page1 + uint8_t CSA1; + uint8_t CSA2; + uint8_t CSB1; + uint8_t CSB2; + uint8_t CSC1; + uint8_t CSC2; + uint8_t CSD1; + uint8_t CSD2; + //Page2 + uint8_t LA; + uint8_t HA; + uint8_t LB; + uint8_t HB; + uint8_t LC; + uint8_t HC; + uint8_t LD; + uint8_t HD; + //Page3 + uint8_t FC1; + uint8_t FC2; + uint8_t FC3; + uint8_t FC4; + uint8_t VCCP; + uint8_t FC5; + uint8_t FC6; + uint8_t FC7; + uint8_t convc1; + uint8_t convc2; + + + }; +} 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; +uint32_t P; +int32_t t; +uint8_t max_adr=0; + + + +int main(void){ + pack.A=0; + pack.B=0; + pack.C=0; + pack.D=0; + pack.CSA1=0x08; + pack.CSA2=0x8C; + pack.CSB1=0x08; + pack.CSB2=0x8C; + pack.CSC1=0x08; + pack.CSC2=0x8C; + pack.CSD1=0x08; + pack.CSD2=0x8C; + pack.HA=0xFF; + pack.LA=0x00; + pack.HB=0xFF; + pack.LB=0x00; + pack.HC=0xFF; + pack.LC=0x00; + pack.HD=0xFF; + pack.LD=0x00; + pack.VCCP=0; + PORTB=0xFF-(1<3) { + SHT2x_MeasurePoll(HUMIDITY, &sRH); + // --- measure temperature with "Polling Mode" (no hold master) --- + SHT2x_MeasurePoll(TEMP, &sT); + //-- calculate humidity and temperature -- + temperatureC = SHT2x_CalcTemperatureC(sT); + humidityRH = SHT2x_CalcRH(sRH); + + 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; + l=(log(l)*1000)+32767.0; + wdcounter=0; + } + + + + + + + if (gcontrol) { + //PORTB|=(1<pack.HA) {alarmflag=1;pack.CSA2|=0x20;} + if (pack.CSA2&0x04) //AEL + if (pack.bytes[1]pack.HB) {alarmflag=1;pack.CSB2|=0x20;} + if (pack.CSB2&0x04) //AEL + if (pack.bytes[1]pack.HC) {alarmflag=1;pack.CSC2|=0x20;} + if (pack.CSC2&0x04) //AEL + if (pack.bytes[1]pack.HD) {alarmflag=1;pack.CSD2|=0x20;} + if (pack.CSD2&0x04) //AEL + if (pack.bytes[1] -#include -#include -#include -#include -#include "../common/I2C/USI_TWI_Master.h" -#include "../common/I2C/MAX1164x.h" -#include "../common/I2C/SHT2x.h" -#include "../common/calibr.h" -#include "../common/I2C/BMP280.h" - - - -extern void OWINIT(); -extern void EXTERN_SLEEP(); - -uint8_t owid[8]={0x20, 0xA2, 0xD9, 0x84, 0x00, 0x16, 0x02, 0x5D};/**/ -uint8_t config_info[16]={0x01,14, 0x04,0x08, 0x08,1, 0x02,16,0x02,0x00,0x00,0x00,0x00,0x00,0x00,0x00}; - -#if (owid>128) -#error "Variable not correct" -#endif - -extern uint8_t mode; -extern uint8_t gcontrol; -extern uint8_t reset_indicator; -extern uint8_t alarmflag; -volatile uint8_t wdcounter=1; - - -#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; - - -} - -volatile uint16_t _temp; -volatile uint16_t _hum; - - -uint8_t userRegister[1]; -int16_t sRH,sT; -double temperatureC,humidityRH,hhum; -double l; - -double R0; -uint16_t mr; -uint8_t startup=10; -double ip; - -uint32_t bmp_P; -int32_t bmp_t; - -uint8_t max_adr=0; -#define CH0_M MAX1164x_C_SCAN0|MAX1164x_C_SGL -#define CH1_M MAX1164x_C_SCAN0|MAX1164x_C_SGL|MAX1164x_C_CS0 -#define CH0_CH1 MAX1164x_C_SCAN0 -//|MAX1164x_C_CS0 - -uint16_t weekmaxarr[8]; - - -typedef union { - volatile uint8_t bytes[0x20]; - struct { - //Page0 - uint16_t A; //0 - uint16_t B; //2 - uint16_t C; //4 - uint16_t D; //6 - //Page1 - uint8_t CSA1; - uint8_t CSA2; - uint8_t CSB1; - uint8_t CSB2; - uint8_t CSC1; - uint8_t CSC2; - uint8_t CSD1; - uint8_t CSD2; - //Page2 - uint8_t LA; - uint8_t HA; - uint8_t LB; - uint8_t HB; - uint8_t LC; - uint8_t HC; - uint8_t LD; - uint8_t HD; - //Page3 - uint8_t FC1; - uint8_t FC2; - uint8_t FC3; - uint8_t FC4; - uint8_t VCCP; - uint8_t FC5; - uint8_t FC6; - uint8_t FC7; - uint8_t convc1; - uint8_t convc2; - - - }; -} pack_t; -volatile pack_t pack; - - -typedef struct { - int16_t current; //6 - uint16_t R0; - //uint16_t VS; - uint8_t cmode; - int16_t ip; - //uint8_t free; - uint16_t tol_s8; - uint16_t tol_d; - uint16_t r_day_max; - uint16_t r_week_max; -} pack2_t; -volatile pack2_t pack2; - - -//Kompensieren der Abhänigkeit von RS/RO von Temperatur und Luftfeuchte -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; -} - -#define EEPROM_R0 0 -#define EEPROM_R0d 2 -#define EEPROM_R0w 4 -#define EEPROM_dol 6 - - -uint16_t readEEPROM(uint8_t addr,uint16_t def) { - uint16_t hr; - while(EECR & (1<>8; - EECR |= (1< 1,5V - gcontrol=1; - sei(); - - - while(1) { - - /*if (pack1.config==0x1F) { - pack1.config=0x7F; - R0=1; - pack2.R0=0; - writeEEPROM(EEPROM_R0,0); - } - if (pack1.config==0x05) { - pack1.config=0x7F; - pack2.r_day_max=1; - pack2.r_week_max=1; - pack2.tol_d=0; - pack2.tol_s8=0; //Tag faengt mit Einschalten an - R0=1; - writeEEPROM(EEPROM_R0,0xFF); - writeEEPROM(EEPROM_R0d,0xFF); //Maximum des Tages - writeEEPROM(EEPROM_R0w,0xFF); //Maximum der Letzten 7 Tage - writeEEPROM(EEPROM_dol,0xFF); //Anzahl der Betriebstage - for(uint8_t i=0;i<7;i++) { - weekmaxarr[i]=1; - } - } */ - if (wdcounter>0) { - pack2.tol_s8++; - if (pack2.tol_s8>(10000)) {//10800 ist theortisch der Tag aber meistens zu lang - pack2.tol_s8=0; - pack2.tol_d++; //rund 180 Jahre :-) - pack2.r_week_max=0; - weekmaxarr[7]=pack2.r_day_max; - for(uint8_t i=0;i<7;i++) { - weekmaxarr[i]=weekmaxarr[i+1]; - if (weekmaxarr[i]>pack2.r_week_max) pack2.r_week_max=weekmaxarr[i]; - } - if (pack2.tol_d>7) { - pack2.R0=pack2.r_week_max; - } else { - pack2.R0=pack2.r_day_max; - } - //R0=pack2.R0/100.0-0.5*(pack2.R0/100.0-R0); - R0=R0-(R0-pack2.R0/100.0)*0.5 ; - pack2.R0=R0*100; - writeEEPROM(EEPROM_R0,pack2.R0); - writeEEPROM(EEPROM_R0d,pack2.r_day_max); //Maximum des Tages - writeEEPROM(EEPROM_R0w,pack2.r_week_max); //Maximum der Letzten 7 Tage - writeEEPROM(EEPROM_dol,pack2.tol_d); //Anzahl der Betriebstage - pack2.r_day_max=0; - } - if (startup!=0) startup--; - SHT2x_MeasurePoll(HUMIDITY, &sRH); - // --- measure temperature with "Polling Mode" (no hold master) --- - SHT2x_MeasurePoll(TEMP, &sT); - //-- calculate humidity and temperature -- - temperatureC = SHT2x_CalcTemperatureC(sT); - humidityRH = SHT2x_CalcRH(sRH); - ip=interp(temperatureC,humidityRH); - pack2.ip=ip*1000; - //humidityRH=calibr_hum(temperatureC,-0.45,humidityRH); - //temperatureC =temperatureC -0.45; - _hum= humidityRH*100.0; - _temp=(temperatureC*100.0)+32767; - //PORTB&=~(1<1.8) { - if (mr>7200) { - if (pack2.cmode==0) { - MAX1164x_config(MAX1164x_S_SEL2|MAX1164x_S_SEL0,CH0_CH1); - pack2.cmode=1; - } - } - //if (l<1.6) { - if (mr<6400) { - if (pack2.cmode==1) { - MAX1164x_config(MAX1164x_S_SEL2|MAX1164x_S_SEL0,CH0_M); - pack2.cmode=0; - } - - - } - //pack2.VS=mr*5/2; - l=mr/4000.0; - l=( 3/l- 1) *30; - pack2.current=l*100; - - l=l/ip; - - if (startup==0){ - if (l>R0) { - R0=l; - pack2.R0=R0*100; - writeEEPROM(EEPROM_R0,pack2.R0); - - } - if (l*100>pack2.r_day_max) { - pack2.r_day_max=l*100; - } - } else if (lpack.HA) {alarmflag=1;pack.CSA2|=0x20;} - if (pack.CSA2&0x04) //AEL - if (pack.bytes[1]pack.HB) {alarmflag=1;pack.CSB2|=0x20;} - if (pack.CSB2&0x04) //AEL - if (pack.bytes[1]pack.HC) {alarmflag=1;pack.CSC2|=0x20;} - if (pack.CSC2&0x04) //AEL - if (pack.bytes[1]pack.HD) {alarmflag=1;pack.CSD2|=0x20;} - if (pack.CSD2&0x04) //AEL - if (pack.bytes[1] +#include +#include +#include +#include +#include "../common/I2C/USI_TWI_Master.h" +#include "../common/I2C/MAX1164x.h" +#include "../common/I2C/SHT2x.h" +#include "../common/calibr.h" +#include "../common/I2C/BMP280.h" + + + +extern void OWINIT(); +extern void EXTERN_SLEEP(); + +uint8_t owid[8]={0x20, 0xA2, 0xD9, 0x84, 0x00, 0x16, 0x02, 0x5D};/**/ +uint8_t config_info[16]={0x01,14, 0x04,0x08, 0x08,1, 0x02,16,0x02,0x00,0x00,0x00,0x00,0x00,0x00,0x00}; + +#if (owid>128) +#error "Variable not correct" +#endif + +extern uint8_t mode; +extern uint8_t gcontrol; +extern uint8_t reset_indicator; +extern uint8_t alarmflag; +volatile uint8_t wdcounter=1; + + +#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; + + +} + +volatile uint16_t _temp; +volatile uint16_t _hum; + + +uint8_t userRegister[1]; +int16_t sRH,sT; +double temperatureC,humidityRH,hhum; +double l; + +double R0; +uint16_t mr; +uint8_t startup=10; +double ip; + +uint32_t bmp_P; +int32_t bmp_t; + +uint8_t max_adr=0; +#define CH0_M MAX1164x_C_SCAN0|MAX1164x_C_SGL +#define CH1_M MAX1164x_C_SCAN0|MAX1164x_C_SGL|MAX1164x_C_CS0 +#define CH0_CH1 MAX1164x_C_SCAN0 +//|MAX1164x_C_CS0 + +uint16_t weekmaxarr[8]; + + +typedef union { + volatile uint8_t bytes[0x20]; + struct { + //Page0 + uint16_t A; //0 + uint16_t B; //2 + uint16_t C; //4 + uint16_t D; //6 + //Page1 + uint8_t CSA1; + uint8_t CSA2; + uint8_t CSB1; + uint8_t CSB2; + uint8_t CSC1; + uint8_t CSC2; + uint8_t CSD1; + uint8_t CSD2; + //Page2 + uint8_t LA; + uint8_t HA; + uint8_t LB; + uint8_t HB; + uint8_t LC; + uint8_t HC; + uint8_t LD; + uint8_t HD; + //Page3 + uint8_t FC1; + uint8_t FC2; + uint8_t FC3; + uint8_t FC4; + uint8_t VCCP; + uint8_t FC5; + uint8_t FC6; + uint8_t FC7; + uint8_t convc1; + uint8_t convc2; + + + }; +} pack_t; +volatile pack_t pack; + + +typedef struct { + int16_t current; //6 + uint16_t R0; + //uint16_t VS; + uint8_t cmode; + int16_t ip; + //uint8_t free; + uint16_t tol_s8; + uint16_t tol_d; + uint16_t r_day_max; + uint16_t r_week_max; +} pack2_t; +volatile pack2_t pack2; + + +//Kompensieren der Abhänigkeit von RS/RO von Temperatur und Luftfeuchte +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; +} + +#define EEPROM_R0 0 +#define EEPROM_R0d 2 +#define EEPROM_R0w 4 +#define EEPROM_dol 6 + + +uint16_t readEEPROM(uint8_t addr,uint16_t def) { + uint16_t hr; + while(EECR & (1<>8; + EECR |= (1< 1,5V + gcontrol=1; + sei(); + + + while(1) { + + /*if (pack1.config==0x1F) { + pack1.config=0x7F; + R0=1; + pack2.R0=0; + writeEEPROM(EEPROM_R0,0); + } + if (pack1.config==0x05) { + pack1.config=0x7F; + pack2.r_day_max=1; + pack2.r_week_max=1; + pack2.tol_d=0; + pack2.tol_s8=0; //Tag faengt mit Einschalten an + R0=1; + writeEEPROM(EEPROM_R0,0xFF); + writeEEPROM(EEPROM_R0d,0xFF); //Maximum des Tages + writeEEPROM(EEPROM_R0w,0xFF); //Maximum der Letzten 7 Tage + writeEEPROM(EEPROM_dol,0xFF); //Anzahl der Betriebstage + for(uint8_t i=0;i<7;i++) { + weekmaxarr[i]=1; + } + } */ + if (wdcounter>0) { + pack2.tol_s8++; + if (pack2.tol_s8>(10000)) {//10800 ist theortisch der Tag aber meistens zu lang + pack2.tol_s8=0; + pack2.tol_d++; //rund 180 Jahre :-) + pack2.r_week_max=0; + weekmaxarr[7]=pack2.r_day_max; + for(uint8_t i=0;i<7;i++) { + weekmaxarr[i]=weekmaxarr[i+1]; + if (weekmaxarr[i]>pack2.r_week_max) pack2.r_week_max=weekmaxarr[i]; + } + if (pack2.tol_d>7) { + pack2.R0=pack2.r_week_max; + } else { + pack2.R0=pack2.r_day_max; + } + //R0=pack2.R0/100.0-0.5*(pack2.R0/100.0-R0); + R0=R0-(R0-pack2.R0/100.0)*0.5 ; + pack2.R0=R0*100; + writeEEPROM(EEPROM_R0,pack2.R0); + writeEEPROM(EEPROM_R0d,pack2.r_day_max); //Maximum des Tages + writeEEPROM(EEPROM_R0w,pack2.r_week_max); //Maximum der Letzten 7 Tage + writeEEPROM(EEPROM_dol,pack2.tol_d); //Anzahl der Betriebstage + pack2.r_day_max=0; + } + if (startup!=0) startup--; + SHT2x_MeasurePoll(HUMIDITY, &sRH); + // --- measure temperature with "Polling Mode" (no hold master) --- + SHT2x_MeasurePoll(TEMP, &sT); + //-- calculate humidity and temperature -- + temperatureC = SHT2x_CalcTemperatureC(sT); + humidityRH = SHT2x_CalcRH(sRH); + ip=interp(temperatureC,humidityRH); + pack2.ip=ip*1000; + //humidityRH=calibr_hum(temperatureC,-0.45,humidityRH); + //temperatureC =temperatureC -0.45; + _hum= humidityRH*100.0; + _temp=(temperatureC*100.0)+32767; + //PORTB&=~(1<1.8) { + if (mr>7200) { + if (pack2.cmode==0) { + MAX1164x_config(MAX1164x_S_SEL2|MAX1164x_S_SEL0,CH0_CH1); + pack2.cmode=1; + } + } + //if (l<1.6) { + if (mr<6400) { + if (pack2.cmode==1) { + MAX1164x_config(MAX1164x_S_SEL2|MAX1164x_S_SEL0,CH0_M); + pack2.cmode=0; + } + + + } + //pack2.VS=mr*5/2; + l=mr/4000.0; + l=( 3/l- 1) *30; + pack2.current=l*100; + + l=l/ip; + + if (startup==0){ + if (l>R0) { + R0=l; + pack2.R0=R0*100; + writeEEPROM(EEPROM_R0,pack2.R0); + + } + if (l*100>pack2.r_day_max) { + pack2.r_day_max=l*100; + } + } else if (lpack.HA) {alarmflag=1;pack.CSA2|=0x20;} + if (pack.CSA2&0x04) //AEL + if (pack.bytes[1]pack.HB) {alarmflag=1;pack.CSB2|=0x20;} + if (pack.CSB2&0x04) //AEL + if (pack.bytes[1]pack.HC) {alarmflag=1;pack.CSC2|=0x20;} + if (pack.CSC2&0x04) //AEL + if (pack.bytes[1]pack.HD) {alarmflag=1;pack.CSD2|=0x20;} + if (pack.CSD2&0x04) //AEL + if (pack.bytes[1] -#include -#include -#include -#include -#include "USI_TWI_Master.h" -#include "HDC1080.h" -typedef enum{ - I2C_ADR_W = 128, // sensor I2C address + write bit - I2C_ADR_R = 129 // sensor I2C address + read bit -}etI2cHeader; - -uint8_t HDC1080_Init() { - volatile uint8_t error=0; - I2c_StartCondition(); - error |= I2c_WriteByte (I2C_ADR_W); // I2C Adr - error |= I2c_WriteByte (0x02); // Config - error |= I2c_WriteByte (0x0); // 14 bit - error |= I2c_WriteByte (0x0); // - I2c_StopCondition(); - return error; - -} - -uint8_t HDC1080_Readf(double * temperature, double * hum) { - int16_t t; - uint16_t h; - uint8_t error=0; - error=HDC1080_Readi(&t,&h); - *temperature=(double)t/65536.0*165.0-40.0; - *hum=(double)h/65536.0*100; - return error; - -} -uint8_t HDC1080_Readi(int16_t * temperature, uint16_t * hum) { - volatile uint8_t error=0; - I2c_StartCondition(); - error |= I2c_WriteByte (I2C_ADR_W); // I2C Adr - error |= I2c_WriteByte (0x0); // - I2c_StopCondition(); - _delay_ms(10); - I2c_StartCondition(); - error |= I2c_WriteByte (I2C_ADR_R); //I2C address - *temperature=0; - *temperature |= I2c_ReadByte(ACK)<<8; - *temperature |= I2c_ReadByte(ACK); - I2c_StopCondition(); - - I2c_StartCondition(); - error |= I2c_WriteByte (I2C_ADR_W); // I2C Adr - error |= I2c_WriteByte (0x01); // - I2c_StopCondition(); - _delay_ms(10); - I2c_StartCondition(); - error |= I2c_WriteByte (I2C_ADR_R); //I2C address - *hum=0; - *hum|= I2c_ReadByte(ACK)<<8; - *hum|= I2c_ReadByte(NO_ACK); - I2c_StopCondition(); - return error; - } - -/* - -const uint16_t POLYNOMIAL = 0x131; //P(x)=x^8+x^5+x^4+1 = 100110001 - - -//============================================================================== -uint8_t SHT2x_CheckCrc(uint8_t data[], uint8_t nbrOfBytes, uint8_t checksum) -//============================================================================== -{ - uint8_t crc = 0; - uint8_t byteCtr; - //calculates 8-Bit checksum with given polynomial - for (byteCtr = 0; byteCtr < nbrOfBytes; ++byteCtr) - { crc ^= (data[byteCtr]); - for (uint8_t bit = 8; bit > 0; --bit) - { if (crc & 0x80) crc = (crc << 1) ^ POLYNOMIAL; - else crc = (crc << 1); - } - } - if (crc != checksum) return CHECKSUM_ERROR; - else return 0; -} -//=========================================================================== -uint8_t SHT2x_ReadUserRegister(uint8_t *pRegisterValue) -//=========================================================================== -{ - uint8_t checksum; //variable for checksum byte - uint8_t error=0; //variable for error code - I2c_StartCondition(); - error |= I2c_WriteByte (I2C_ADR_W); - error |= I2c_WriteByte (USER_REG_R); - I2c_StartCondition(); - error |= I2c_WriteByte (I2C_ADR_R); - *pRegisterValue = I2c_ReadByte(ACK); - checksum=I2c_ReadByte(NO_ACK); - error |= SHT2x_CheckCrc (pRegisterValue,1,checksum); - I2c_StopCondition(); - return error; -} -//=========================================================================== -uint8_t SHT2x_WriteUserRegister(uint8_t *pRegisterValue) -//=========================================================================== -{ - uint8_t error=0; //variable for error code - I2c_StartCondition(); - error |= I2c_WriteByte (I2C_ADR_W); - error |= I2c_WriteByte (USER_REG_W); - error |= I2c_WriteByte (*pRegisterValue); - I2c_StopCondition(); - return error; -} -//=========================================================================== -uint8_t SHT2x_MeasureHM(etSHT2xMeasureType eSHT2xMeasureType, int16_t *pMeasurand) -//=========================================================================== -{ - uint8_t checksum; //checksum - uint8_t data[2]; //data array for checksum verification - uint8_t error=0; //error variable - uint16_t i; //counting variable - //-- write I2C sensor address and command -- - I2c_StartCondition(); - error |= I2c_WriteByte (I2C_ADR_W); // I2C Adr - switch(eSHT2xMeasureType) - { case HUMIDITY: error |= I2c_WriteByte (TRIG_RH_MEASUREMENT_HM); break; - case TEMP : error |= I2c_WriteByte (TRIG_T_MEASUREMENT_HM); break; - //default: assert(0); - } - //-- wait until hold master is released -- - I2c_StartCondition(); - error |= I2c_WriteByte (I2C_ADR_R); - //SCL=HIGH; // set SCL I/O port as input - DDR_USI&=~(1<>8) & 0xFF; - *pMeasurand|=0xFF & (data[1] = I2c_ReadByte(ACK)); -// pMeasurand->s16.u8H = data[0] = I2c_ReadByte(ACK); -// pMeasurand->s16.u8L = data[1] = I2c_ReadByte(ACK); - - checksum=I2c_ReadByte(NO_ACK); - //-- verify checksum -- - error |= SHT2x_CheckCrc (data,2,checksum); - I2c_StopCondition(); - return error; -} -//=========================================================================== -uint8_t SHT2x_MeasurePoll(etSHT2xMeasureType eSHT2xMeasureType, int16_t *pMeasurand) -//=========================================================================== -{ - uint8_t checksum; //checksum - uint8_t data[2]; //data array for checksum verification - uint8_t error=0; //error variable - uint16_t i=0; //counting variable - //-- write I2C sensor address and command -- - I2c_StartCondition(); - error |= I2c_WriteByte (I2C_ADR_W); // I2C Adr - switch(eSHT2xMeasureType) - { case HUMIDITY: error |= I2c_WriteByte (TRIG_RH_MEASUREMENT_POLL); break; - case TEMP : error |= I2c_WriteByte (TRIG_T_MEASUREMENT_POLL); break; - //default: assert(0); - } - //-- poll every 10ms for measurement ready. Timeout after 20 retries (200ms)-- - do - { I2c_StartCondition(); - _delay_ms(200); //delay 10ms - if(i++ >= 20) break; - } while(I2c_WriteByte (I2C_ADR_R) == ACK_ERROR); - if (i>=20) error |= TIME_OUT_ERROR; - //-- read two data bytes and one checksum byte -- - data[0]=I2c_ReadByte(ACK); - data[1]=I2c_ReadByte(ACK); - *pMeasurand=(data[0]<<8)|data[1]; - -// pMeasurand->s16.u8H = data[0] = I2c_ReadByte(ACK); -// pMeasurand->s16.u8L = data[1] = I2c_ReadByte(ACK); - checksum=I2c_ReadByte(NO_ACK); - //-- verify checksum -- - error |= SHT2x_CheckCrc (data,2,checksum); - I2c_StopCondition(); - return error; -} -//=========================================================================== -uint8_t SHT2x_SoftReset(void) -//=========================================================================== -{ - uint8_t error=0; //error variable - I2c_StartCondition(); - error |= I2c_WriteByte (I2C_ADR_W); // I2C Adr - error |= I2c_WriteByte (SOFT_RESET); // Command - I2c_StopCondition(); - _delay_ms(15); // wait till sensor has restarted - return error; -} -//============================================================================== -float SHT2x_CalcRH(uint16_t u16sRH) -//============================================================================== -{ - double humidityRH; // variable for result - u16sRH &= ~0x0003; // clear bits [1..0] (status bits) - //-- calculate relative humidity [%RH] -- - humidityRH = -6.0 + 125.0/65536 * (double)u16sRH; // RH= -6 + 125 * SRH/2^16 - return humidityRH; -} -//============================================================================== -float SHT2x_CalcTemperatureC(uint16_t u16sT) -//============================================================================== -{ - double temperatureC; // variable for result - u16sT &= ~0x0003; // clear bits [1..0] (status bits) - //-- calculate temperature [°C] -- - temperatureC= -46.85 + 175.72/65536 *(double)u16sT; //T= -46.85 + 175.72 * ST/2^16 - return temperatureC; -} -//============================================================================== -uint8_t SHT2x_GetSerialNumber(uint8_t u8SerialNumber[]) -//============================================================================== -{ - uint8_t error=0; //error variable - //Read from memory location 1 - I2c_StartCondition(); - error |= I2c_WriteByte (I2C_ADR_W); //I2C address - error |= I2c_WriteByte (0xFA); //Command for readout on-chip memory - error |= I2c_WriteByte (0x0F); //on-chip memory address - I2c_StartCondition(); - error |= I2c_WriteByte (I2C_ADR_R); //I2C address - u8SerialNumber[5] = I2c_ReadByte(ACK); //Read SNB_3 - I2c_ReadByte(ACK); //Read CRC SNB_3 (CRC is not analyzed) - u8SerialNumber[4] = I2c_ReadByte(ACK); //Read SNB_2 - I2c_ReadByte(ACK); //Read CRC SNB_2 (CRC is not analyzed) - u8SerialNumber[3] = I2c_ReadByte(ACK); //Read SNB_1 - I2c_ReadByte(ACK); //Read CRC SNB_1 (CRC is not analyzed) - u8SerialNumber[2] = I2c_ReadByte(ACK); //Read SNB_0 - I2c_ReadByte(NO_ACK); //Read CRC SNB_0 (CRC is not analyzed) - I2c_StopCondition(); - //Read from memory location 2 - I2c_StartCondition(); - error |= I2c_WriteByte (I2C_ADR_W); //I2C address - error |= I2c_WriteByte (0xFC); //Command for readout on-chip memory - error |= I2c_WriteByte (0xC9); //on-chip memory address - I2c_StartCondition(); - error |= I2c_WriteByte (I2C_ADR_R); //I2C address - u8SerialNumber[1] = I2c_ReadByte(ACK); //Read SNC_1 - u8SerialNumber[0] = I2c_ReadByte(ACK); //Read SNC_0 - I2c_ReadByte(ACK); //Read CRC SNC0/1 (CRC is not analyzed) - u8SerialNumber[7] = I2c_ReadByte(ACK); //Read SNA_1 - u8SerialNumber[6] = I2c_ReadByte(ACK); //Read SNA_0 - I2c_ReadByte(NO_ACK); //Read CRC SNA0/1 (CRC is not analyzed) - I2c_StopCondition(); - return error; -} +// Copyright (c) 2016, 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. + +//---------- Includes ---------------------------------------------------------- +#define F_CPU 8000000UL +#include +#include +#include +#include +#include +#include "USI_TWI_Master.h" +#include "HDC1080.h" +typedef enum{ + I2C_ADR_W = 128, // sensor I2C address + write bit + I2C_ADR_R = 129 // sensor I2C address + read bit +}etI2cHeader; + +uint8_t HDC1080_Init() { + volatile uint8_t error=0; + I2c_StartCondition(); + error |= I2c_WriteByte (I2C_ADR_W); // I2C Adr + error |= I2c_WriteByte (0x02); // Config + error |= I2c_WriteByte (0x0); // 14 bit + error |= I2c_WriteByte (0x0); // + I2c_StopCondition(); + return error; + +} + +uint8_t HDC1080_Readf(double * temperature, double * hum) { + int16_t t; + uint16_t h; + uint8_t error=0; + error=HDC1080_Readi(&t,&h); + *temperature=(double)t/65536.0*165.0-40.0; + *hum=(double)h/65536.0*100; + return error; + +} +uint8_t HDC1080_Readi(int16_t * temperature, uint16_t * hum) { + volatile uint8_t error=0; + I2c_StartCondition(); + error |= I2c_WriteByte (I2C_ADR_W); // I2C Adr + error |= I2c_WriteByte (0x0); // + I2c_StopCondition(); + _delay_ms(10); + I2c_StartCondition(); + error |= I2c_WriteByte (I2C_ADR_R); //I2C address + *temperature=0; + *temperature |= I2c_ReadByte(ACK)<<8; + *temperature |= I2c_ReadByte(ACK); + I2c_StopCondition(); + + I2c_StartCondition(); + error |= I2c_WriteByte (I2C_ADR_W); // I2C Adr + error |= I2c_WriteByte (0x01); // + I2c_StopCondition(); + _delay_ms(10); + I2c_StartCondition(); + error |= I2c_WriteByte (I2C_ADR_R); //I2C address + *hum=0; + *hum|= I2c_ReadByte(ACK)<<8; + *hum|= I2c_ReadByte(NO_ACK); + I2c_StopCondition(); + return error; + } + +/* + +const uint16_t POLYNOMIAL = 0x131; //P(x)=x^8+x^5+x^4+1 = 100110001 + + +//============================================================================== +uint8_t SHT2x_CheckCrc(uint8_t data[], uint8_t nbrOfBytes, uint8_t checksum) +//============================================================================== +{ + uint8_t crc = 0; + uint8_t byteCtr; + //calculates 8-Bit checksum with given polynomial + for (byteCtr = 0; byteCtr < nbrOfBytes; ++byteCtr) + { crc ^= (data[byteCtr]); + for (uint8_t bit = 8; bit > 0; --bit) + { if (crc & 0x80) crc = (crc << 1) ^ POLYNOMIAL; + else crc = (crc << 1); + } + } + if (crc != checksum) return CHECKSUM_ERROR; + else return 0; +} +//=========================================================================== +uint8_t SHT2x_ReadUserRegister(uint8_t *pRegisterValue) +//=========================================================================== +{ + uint8_t checksum; //variable for checksum byte + uint8_t error=0; //variable for error code + I2c_StartCondition(); + error |= I2c_WriteByte (I2C_ADR_W); + error |= I2c_WriteByte (USER_REG_R); + I2c_StartCondition(); + error |= I2c_WriteByte (I2C_ADR_R); + *pRegisterValue = I2c_ReadByte(ACK); + checksum=I2c_ReadByte(NO_ACK); + error |= SHT2x_CheckCrc (pRegisterValue,1,checksum); + I2c_StopCondition(); + return error; +} +//=========================================================================== +uint8_t SHT2x_WriteUserRegister(uint8_t *pRegisterValue) +//=========================================================================== +{ + uint8_t error=0; //variable for error code + I2c_StartCondition(); + error |= I2c_WriteByte (I2C_ADR_W); + error |= I2c_WriteByte (USER_REG_W); + error |= I2c_WriteByte (*pRegisterValue); + I2c_StopCondition(); + return error; +} +//=========================================================================== +uint8_t SHT2x_MeasureHM(etSHT2xMeasureType eSHT2xMeasureType, int16_t *pMeasurand) +//=========================================================================== +{ + uint8_t checksum; //checksum + uint8_t data[2]; //data array for checksum verification + uint8_t error=0; //error variable + uint16_t i; //counting variable + //-- write I2C sensor address and command -- + I2c_StartCondition(); + error |= I2c_WriteByte (I2C_ADR_W); // I2C Adr + switch(eSHT2xMeasureType) + { case HUMIDITY: error |= I2c_WriteByte (TRIG_RH_MEASUREMENT_HM); break; + case TEMP : error |= I2c_WriteByte (TRIG_T_MEASUREMENT_HM); break; + //default: assert(0); + } + //-- wait until hold master is released -- + I2c_StartCondition(); + error |= I2c_WriteByte (I2C_ADR_R); + //SCL=HIGH; // set SCL I/O port as input + DDR_USI&=~(1<>8) & 0xFF; + *pMeasurand|=0xFF & (data[1] = I2c_ReadByte(ACK)); +// pMeasurand->s16.u8H = data[0] = I2c_ReadByte(ACK); +// pMeasurand->s16.u8L = data[1] = I2c_ReadByte(ACK); + + checksum=I2c_ReadByte(NO_ACK); + //-- verify checksum -- + error |= SHT2x_CheckCrc (data,2,checksum); + I2c_StopCondition(); + return error; +} +//=========================================================================== +uint8_t SHT2x_MeasurePoll(etSHT2xMeasureType eSHT2xMeasureType, int16_t *pMeasurand) +//=========================================================================== +{ + uint8_t checksum; //checksum + uint8_t data[2]; //data array for checksum verification + uint8_t error=0; //error variable + uint16_t i=0; //counting variable + //-- write I2C sensor address and command -- + I2c_StartCondition(); + error |= I2c_WriteByte (I2C_ADR_W); // I2C Adr + switch(eSHT2xMeasureType) + { case HUMIDITY: error |= I2c_WriteByte (TRIG_RH_MEASUREMENT_POLL); break; + case TEMP : error |= I2c_WriteByte (TRIG_T_MEASUREMENT_POLL); break; + //default: assert(0); + } + //-- poll every 10ms for measurement ready. Timeout after 20 retries (200ms)-- + do + { I2c_StartCondition(); + _delay_ms(200); //delay 10ms + if(i++ >= 20) break; + } while(I2c_WriteByte (I2C_ADR_R) == ACK_ERROR); + if (i>=20) error |= TIME_OUT_ERROR; + //-- read two data bytes and one checksum byte -- + data[0]=I2c_ReadByte(ACK); + data[1]=I2c_ReadByte(ACK); + *pMeasurand=(data[0]<<8)|data[1]; + +// pMeasurand->s16.u8H = data[0] = I2c_ReadByte(ACK); +// pMeasurand->s16.u8L = data[1] = I2c_ReadByte(ACK); + checksum=I2c_ReadByte(NO_ACK); + //-- verify checksum -- + error |= SHT2x_CheckCrc (data,2,checksum); + I2c_StopCondition(); + return error; +} +//=========================================================================== +uint8_t SHT2x_SoftReset(void) +//=========================================================================== +{ + uint8_t error=0; //error variable + I2c_StartCondition(); + error |= I2c_WriteByte (I2C_ADR_W); // I2C Adr + error |= I2c_WriteByte (SOFT_RESET); // Command + I2c_StopCondition(); + _delay_ms(15); // wait till sensor has restarted + return error; +} +//============================================================================== +float SHT2x_CalcRH(uint16_t u16sRH) +//============================================================================== +{ + double humidityRH; // variable for result + u16sRH &= ~0x0003; // clear bits [1..0] (status bits) + //-- calculate relative humidity [%RH] -- + humidityRH = -6.0 + 125.0/65536 * (double)u16sRH; // RH= -6 + 125 * SRH/2^16 + return humidityRH; +} +//============================================================================== +float SHT2x_CalcTemperatureC(uint16_t u16sT) +//============================================================================== +{ + double temperatureC; // variable for result + u16sT &= ~0x0003; // clear bits [1..0] (status bits) + //-- calculate temperature [°C] -- + temperatureC= -46.85 + 175.72/65536 *(double)u16sT; //T= -46.85 + 175.72 * ST/2^16 + return temperatureC; +} +//============================================================================== +uint8_t SHT2x_GetSerialNumber(uint8_t u8SerialNumber[]) +//============================================================================== +{ + uint8_t error=0; //error variable + //Read from memory location 1 + I2c_StartCondition(); + error |= I2c_WriteByte (I2C_ADR_W); //I2C address + error |= I2c_WriteByte (0xFA); //Command for readout on-chip memory + error |= I2c_WriteByte (0x0F); //on-chip memory address + I2c_StartCondition(); + error |= I2c_WriteByte (I2C_ADR_R); //I2C address + u8SerialNumber[5] = I2c_ReadByte(ACK); //Read SNB_3 + I2c_ReadByte(ACK); //Read CRC SNB_3 (CRC is not analyzed) + u8SerialNumber[4] = I2c_ReadByte(ACK); //Read SNB_2 + I2c_ReadByte(ACK); //Read CRC SNB_2 (CRC is not analyzed) + u8SerialNumber[3] = I2c_ReadByte(ACK); //Read SNB_1 + I2c_ReadByte(ACK); //Read CRC SNB_1 (CRC is not analyzed) + u8SerialNumber[2] = I2c_ReadByte(ACK); //Read SNB_0 + I2c_ReadByte(NO_ACK); //Read CRC SNB_0 (CRC is not analyzed) + I2c_StopCondition(); + //Read from memory location 2 + I2c_StartCondition(); + error |= I2c_WriteByte (I2C_ADR_W); //I2C address + error |= I2c_WriteByte (0xFC); //Command for readout on-chip memory + error |= I2c_WriteByte (0xC9); //on-chip memory address + I2c_StartCondition(); + error |= I2c_WriteByte (I2C_ADR_R); //I2C address + u8SerialNumber[1] = I2c_ReadByte(ACK); //Read SNC_1 + u8SerialNumber[0] = I2c_ReadByte(ACK); //Read SNC_0 + I2c_ReadByte(ACK); //Read CRC SNC0/1 (CRC is not analyzed) + u8SerialNumber[7] = I2c_ReadByte(ACK); //Read SNA_1 + u8SerialNumber[6] = I2c_ReadByte(ACK); //Read SNA_0 + I2c_ReadByte(NO_ACK); //Read CRC SNA0/1 (CRC is not analyzed) + I2c_StopCondition(); + return error; +} */ \ No newline at end of file diff --git a/common/I2C/HDC1080.h b/common/I2C/HDC1080.h index 801cca1..b250afe 100644 --- a/common/I2C/HDC1080.h +++ b/common/I2C/HDC1080.h @@ -1,42 +1,42 @@ -#ifndef HDC1080_H -#define HDC1080_H -// Copyright (c) 2016, 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. - - -uint8_t HDC1080_Init(); - -uint8_t HDC1080_Readf(double * temperature, double * hum); -uint8_t HDC1080_Readi(int16_t * temperature, uint16_t * hum); - - -#endif +#ifndef HDC1080_H +#define HDC1080_H +// Copyright (c) 2016, 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. + + +uint8_t HDC1080_Init(); + +uint8_t HDC1080_Readf(double * temperature, double * hum); +uint8_t HDC1080_Readi(int16_t * temperature, uint16_t * hum); + + +#endif diff --git a/common/OWDS2450.S b/common/OWDS2450.S index a60addd..c6a43ec 100644 --- a/common/OWDS2450.S +++ b/common/OWDS2450.S @@ -1,247 +1,247 @@ - -// 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_ -#define _ZERO_POLLING_ - -#include "../common/OWConfig.s" -#include "../common/OWCRC16.s" - -.extern pack,8 -.comm addr,1 ;zweites Adressbyte ist unnoetig (Warum auch immer fuer 32 Byte 16 Bit Adressen verwendet werden....) -.comm crcsave,1 ; zwischenspeicherspeicher fuer crc nur zweites byte.... -//.extern am2302_temp,2 - - - -.macro CHIP_INIT -.endm - -.macro COMMAND_TABLE - rjmp h_readmemoryaddr - rjmp h_readmemory - rjmp h_readmemorycrc1 - rjmp h_readmemorycrc2 - rjmp h_writememoryaddr - rjmp h_writememory - rjmp h_writememorycrc1 - rjmp h_writememorycrc2 - rjmp h_writememoryreadback - rjmp h_convert - rjmp h_convertcrc1 - rjmp h_convertcrc2 - rjmp h_convert_conv -.endm - -#include "../common/OWRomFunctions.s" -#include "../common/OWTimerInterrupt.s" - - - -; Ab hier Geraeteabhaenging -#define OW_READ_MEMORY_ADDR OW_FIRST_COMMAND+0 -#define OW_READ_MEMORY OW_FIRST_COMMAND+1 -#define OW_READ_MEMORY_CRC1 OW_FIRST_COMMAND+2 -#define OW_READ_MEMORY_CRC2 OW_FIRST_COMMAND+3 -#define OW_WRITE_MEMORY_ADDR OW_FIRST_COMMAND+4 -#define OW_WRITE_MEMORY OW_FIRST_COMMAND+5 -#define OW_WRITE_MEMORY_CRC1 OW_FIRST_COMMAND+6 -#define OW_WRITE_MEMORY_CRC2 OW_FIRST_COMMAND+7 -#define OW_WRITE_MEMORY_READBACK OW_FIRST_COMMAND+8 -#define OW_CONVERT OW_FIRST_COMMAND+9 -#define OW_CONVERT_CRC1 OW_FIRST_COMMAND+10 -#define OW_CONVERT_CRC2 OW_FIRST_COMMAND+11 -#define OW_CONVERT_CONV OW_FIRST_COMMAND+12 - -;--------------------------------------------------- -; READ COMMAND and start operation -;--------------------------------------------------- - - -h_readcommand: - clr r_bytep -#ifndef _DIS_FLASH_ - FLASH_COMMANDS ; muss zu erst sein.... -#endif - cset 0xAA,OW_READ_MEMORY_ADDR - cset 0x55,OW_WRITE_MEMORY_ADDR - cset 0x3C,OW_CONVERT - FW_CONFIG_INFO -#ifdef _CHANGEABLE_ID_ - CHANGE_ID_COMMANDS -#endif - ldi r_mode,OW_SLEEP - rjmp handle_end - - -h_readmemoryaddr: - cpi r_bytep,0 ;erstes Adressbyte ? - brne h_readmemory_addr_byte1 ;nein dann weiter - andi r_rwbyte,0x1F ; nur Adressen zwischen 0 und 0x1F zulassen - sts addr,r_rwbyte ;speichern des ersten bytes - rjmp handle_end_inc -h_readmemory_addr_byte1: ;zweiters Addressbyte wird nicht gespeichert! - ldi r_mode,OW_READ_MEMORY ;weiter zu read Memory - ;;ldi r_bcount,1 ;ist unten - ldi r_sendflag,1 ;jetzt sendet der Slave zum Master - clr r_bytep - rjmp h_readmemory2 -h_readmemory: - lds r_bytep,addr - inc r_bytep - sts addr,r_bytep - andi r_bytep,0x07 - breq h_readmemory_init_crc -h_readmemory2: - lds r_bytep,addr - ;andi r_bytep,0x1F ist oben - configZ pack,r_bytep - ld r_rwbyte,Z - ;ldi r_bcount,1 - rjmp handle_end ;sendet das Byte und geht zu h_readmemory -h_readmemory_init_crc:; init erstes CRC byte - lds r_rwbyte,crc - com r_rwbyte - lds r_temp,crc+1 - com r_temp - sts crcsave,r_temp - ldi r_mode,OW_READ_MEMORY_CRC1 - ;ldi r_bcount,1 - rjmp handle_end -h_readmemory_end: - ldi r_mode,OW_SLEEP - clr r_sendflag - rjmp handle_end -h_readmemorycrc1:;init zweites CRC Byte - lds r_rwbyte,crcsave - ;ldi r_bcount,1 - ldi r_mode,OW_READ_MEMORY_CRC2 - rjmp handle_end -h_readmemorycrc2:;weiteres senden..... nach zweitem Byte - lds r_temp,addr - andi r_temp,0xE0 - brne h_readmemory_end; ende des speichers - ldi r_mode,OW_READ_MEMORY - CRCInit1 ;Start with new CRC - rjmp h_readmemory2 - -h_writememoryaddr: - cpi r_bytep,0 ;erstes Adressbyte ? - brne h_writememory_addr_byte1 ;nein dann weiter - andi r_rwbyte,0x1F ; nur Adressen zwischen 0 und 0x1F zulassen - sts addr,r_rwbyte ;speichern des ersten bytes - inc r_bytep - ;ldi r_bcount,1 - rjmp handle_end -h_writememory_addr_byte1: ;zweiters Addressbyte wird nicht gespeichert! - ldi r_mode,OW_WRITE_MEMORY ;weiter zu read Memory - ;ldi r_bcount,1 ;; _________________________________________________in handle_end integrieren..... - lds r_bytep,addr - rjmp handle_end ;read Memory Byte -h_writememory: - lds r_bytep,addr - configZ pack,r_bytep - st Z,r_rwbyte - ;ldi r_bcount,1 - ldi r_mode,OW_WRITE_MEMORY_CRC1 - ldi r_sendflag,1 ;jetzt sendet der Slave zum Master - lds r_rwbyte,crc - com r_rwbyte - lds r_temp,crc+1 - com r_temp - sts crcsave,r_temp - rjmp handle_end -h_writememorycrc1: - lds r_rwbyte,crcsave - ;ldi r_bcount,1 - ldi r_mode,OW_WRITE_MEMORY_CRC2 - rjmp handle_end -h_writememorycrc2: - lds r_temp,addr - configZ pack,r_temp - ld r_rwbyte,Z - ;ldi r_bcount,1 - ldi r_mode,OW_WRITE_MEMORY_READBACK - rjmp handle_end -h_writememoryreadback: - ldi r_temp,0x00 - sts crc+1,r_temp - lds r_temp,addr - inc r_temp - sts addr,r_temp - sts crc,r_temp - ldi r_sendflag,0 - ;ldi r_bcount,1 - ldi r_mode,OW_WRITE_MEMORY - rjmp handle_end - -h_convert: - cpi r_bytep,0 ;erstes Adressbyte ? - brne h_convert_byte1 ;nein dann weiter - inc r_bytep - sts pack+0x20,r_rwbyte - ;ldi r_bcount,1 - rjmp handle_end -h_convert_byte1: ;zweies byte glesen go crc# - sts pack+0x21,r_rwbyte - lds r_rwbyte,crc - com r_rwbyte - lds r_temp,crc+1 - com r_temp - sts crcsave,r_temp - ldi r_mode,OW_CONVERT_CRC1 - ;ldi r_bcount,1 - ldi r_sendflag,1 - rjmp handle_end -h_convertcrc1: - lds r_rwbyte,crcsave - ;ldi r_bcount,1 - ldi r_mode,OW_CONVERT_CRC2 - rjmp handle_end -h_convertcrc2: - ldi r_temp,1 - sts gcontrol,r_temp - ;ldi r_bcount,1 - ldi r_mode,OW_CONVERT_CONV - ;clr r_sendflag - ldi r_sendflag,3 ;set bit 0 and 1 for no zero polling -h_convert_conv: - ldi r_bcount,0 - ldi r_rwbyte,0 - rjmp handle_end_no_bcount - - - - -#include "../common/OWPinInterrupt.s" + +// 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_ +#define _ZERO_POLLING_ + +#include "../common/OWConfig.s" +#include "../common/OWCRC16.s" + +.extern pack,8 +.comm addr,1 ;zweites Adressbyte ist unnoetig (Warum auch immer fuer 32 Byte 16 Bit Adressen verwendet werden....) +.comm crcsave,1 ; zwischenspeicherspeicher fuer crc nur zweites byte.... +//.extern am2302_temp,2 + + + +.macro CHIP_INIT +.endm + +.macro COMMAND_TABLE + rjmp h_readmemoryaddr + rjmp h_readmemory + rjmp h_readmemorycrc1 + rjmp h_readmemorycrc2 + rjmp h_writememoryaddr + rjmp h_writememory + rjmp h_writememorycrc1 + rjmp h_writememorycrc2 + rjmp h_writememoryreadback + rjmp h_convert + rjmp h_convertcrc1 + rjmp h_convertcrc2 + rjmp h_convert_conv +.endm + +#include "../common/OWRomFunctions.s" +#include "../common/OWTimerInterrupt.s" + + + +; Ab hier Geraeteabhaenging +#define OW_READ_MEMORY_ADDR OW_FIRST_COMMAND+0 +#define OW_READ_MEMORY OW_FIRST_COMMAND+1 +#define OW_READ_MEMORY_CRC1 OW_FIRST_COMMAND+2 +#define OW_READ_MEMORY_CRC2 OW_FIRST_COMMAND+3 +#define OW_WRITE_MEMORY_ADDR OW_FIRST_COMMAND+4 +#define OW_WRITE_MEMORY OW_FIRST_COMMAND+5 +#define OW_WRITE_MEMORY_CRC1 OW_FIRST_COMMAND+6 +#define OW_WRITE_MEMORY_CRC2 OW_FIRST_COMMAND+7 +#define OW_WRITE_MEMORY_READBACK OW_FIRST_COMMAND+8 +#define OW_CONVERT OW_FIRST_COMMAND+9 +#define OW_CONVERT_CRC1 OW_FIRST_COMMAND+10 +#define OW_CONVERT_CRC2 OW_FIRST_COMMAND+11 +#define OW_CONVERT_CONV OW_FIRST_COMMAND+12 + +;--------------------------------------------------- +; READ COMMAND and start operation +;--------------------------------------------------- + + +h_readcommand: + clr r_bytep +#ifndef _DIS_FLASH_ + FLASH_COMMANDS ; muss zu erst sein.... +#endif + cset 0xAA,OW_READ_MEMORY_ADDR + cset 0x55,OW_WRITE_MEMORY_ADDR + cset 0x3C,OW_CONVERT + FW_CONFIG_INFO +#ifdef _CHANGEABLE_ID_ + CHANGE_ID_COMMANDS +#endif + ldi r_mode,OW_SLEEP + rjmp handle_end + + +h_readmemoryaddr: + cpi r_bytep,0 ;erstes Adressbyte ? + brne h_readmemory_addr_byte1 ;nein dann weiter + andi r_rwbyte,0x1F ; nur Adressen zwischen 0 und 0x1F zulassen + sts addr,r_rwbyte ;speichern des ersten bytes + rjmp handle_end_inc +h_readmemory_addr_byte1: ;zweiters Addressbyte wird nicht gespeichert! + ldi r_mode,OW_READ_MEMORY ;weiter zu read Memory + ;;ldi r_bcount,1 ;ist unten + ldi r_sendflag,1 ;jetzt sendet der Slave zum Master + clr r_bytep + rjmp h_readmemory2 +h_readmemory: + lds r_bytep,addr + inc r_bytep + sts addr,r_bytep + andi r_bytep,0x07 + breq h_readmemory_init_crc +h_readmemory2: + lds r_bytep,addr + ;andi r_bytep,0x1F ist oben + configZ pack,r_bytep + ld r_rwbyte,Z + ;ldi r_bcount,1 + rjmp handle_end ;sendet das Byte und geht zu h_readmemory +h_readmemory_init_crc:; init erstes CRC byte + lds r_rwbyte,crc + com r_rwbyte + lds r_temp,crc+1 + com r_temp + sts crcsave,r_temp + ldi r_mode,OW_READ_MEMORY_CRC1 + ;ldi r_bcount,1 + rjmp handle_end +h_readmemory_end: + ldi r_mode,OW_SLEEP + clr r_sendflag + rjmp handle_end +h_readmemorycrc1:;init zweites CRC Byte + lds r_rwbyte,crcsave + ;ldi r_bcount,1 + ldi r_mode,OW_READ_MEMORY_CRC2 + rjmp handle_end +h_readmemorycrc2:;weiteres senden..... nach zweitem Byte + lds r_temp,addr + andi r_temp,0xE0 + brne h_readmemory_end; ende des speichers + ldi r_mode,OW_READ_MEMORY + CRCInit1 ;Start with new CRC + rjmp h_readmemory2 + +h_writememoryaddr: + cpi r_bytep,0 ;erstes Adressbyte ? + brne h_writememory_addr_byte1 ;nein dann weiter + andi r_rwbyte,0x1F ; nur Adressen zwischen 0 und 0x1F zulassen + sts addr,r_rwbyte ;speichern des ersten bytes + inc r_bytep + ;ldi r_bcount,1 + rjmp handle_end +h_writememory_addr_byte1: ;zweiters Addressbyte wird nicht gespeichert! + ldi r_mode,OW_WRITE_MEMORY ;weiter zu read Memory + ;ldi r_bcount,1 ;; _________________________________________________in handle_end integrieren..... + lds r_bytep,addr + rjmp handle_end ;read Memory Byte +h_writememory: + lds r_bytep,addr + configZ pack,r_bytep + st Z,r_rwbyte + ;ldi r_bcount,1 + ldi r_mode,OW_WRITE_MEMORY_CRC1 + ldi r_sendflag,1 ;jetzt sendet der Slave zum Master + lds r_rwbyte,crc + com r_rwbyte + lds r_temp,crc+1 + com r_temp + sts crcsave,r_temp + rjmp handle_end +h_writememorycrc1: + lds r_rwbyte,crcsave + ;ldi r_bcount,1 + ldi r_mode,OW_WRITE_MEMORY_CRC2 + rjmp handle_end +h_writememorycrc2: + lds r_temp,addr + configZ pack,r_temp + ld r_rwbyte,Z + ;ldi r_bcount,1 + ldi r_mode,OW_WRITE_MEMORY_READBACK + rjmp handle_end +h_writememoryreadback: + ldi r_temp,0x00 + sts crc+1,r_temp + lds r_temp,addr + inc r_temp + sts addr,r_temp + sts crc,r_temp + ldi r_sendflag,0 + ;ldi r_bcount,1 + ldi r_mode,OW_WRITE_MEMORY + rjmp handle_end + +h_convert: + cpi r_bytep,0 ;erstes Adressbyte ? + brne h_convert_byte1 ;nein dann weiter + inc r_bytep + sts pack+0x20,r_rwbyte + ;ldi r_bcount,1 + rjmp handle_end +h_convert_byte1: ;zweies byte glesen go crc# + sts pack+0x21,r_rwbyte + lds r_rwbyte,crc + com r_rwbyte + lds r_temp,crc+1 + com r_temp + sts crcsave,r_temp + ldi r_mode,OW_CONVERT_CRC1 + ;ldi r_bcount,1 + ldi r_sendflag,1 + rjmp handle_end +h_convertcrc1: + lds r_rwbyte,crcsave + ;ldi r_bcount,1 + ldi r_mode,OW_CONVERT_CRC2 + rjmp handle_end +h_convertcrc2: + ldi r_temp,1 + sts gcontrol,r_temp + ;ldi r_bcount,1 + ldi r_mode,OW_CONVERT_CONV + ;clr r_sendflag + ldi r_sendflag,3 ;set bit 0 and 1 for no zero polling +h_convert_conv: + ldi r_bcount,0 + ldi r_rwbyte,0 + rjmp handle_end_no_bcount + + + + +#include "../common/OWPinInterrupt.s" .end \ No newline at end of file diff --git a/programmer/owflash.py b/programmer/owflash.py index 5083173..47eef66 100644 --- a/programmer/owflash.py +++ b/programmer/owflash.py @@ -1,232 +1,232 @@ -#!/usr/bin/python -# 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. - - - - -import time -import subprocess -import sys - -def owcom(dev,send,rc): - res=[] - f=open("/sys/bus/w1/devices/%s/rw" %(dev),"r+b",0) - f.write("".join(map(chr, send))) - if (rc!=0): - res=map(ord,f.read(rc)) - f.close() - return res - - -def crc8(arr): - lscrc=0x0; - for v in arr: - bit=1; - while bit<256: - if (v&bit)==bit: - lb=1 - else: - lb=0 - if (lscrc&1)!=lb: - lscrc=(lscrc>>1)^0x8c - else: - lscrc=(lscrc>>1) - bit=bit*2 - return lscrc - -def testnr(s): - for c in s.lower()[:]: - if not((c) in ['0','1','2','3','4','5','6','7','8','9','a','b','c','d','e','f','-']): - return False - return True - -def addid(id,val): - for i in range(7): - id[i+1]=id[i+1]+val - if id[i+1]>254: - id[i+1]=id[i+1]-254 - val=1 - else: - return id - return id -# - -print "Open Hex File ...", -fi=open(sys.argv[1],"r") -data=[] -for l in fi.readlines(): - sys.stdout.write(".") - sys.stdout.flush() - bc=int(l[1:3],16) - fw=int(l[3:7],16) - ty=int(l[7:9],16) - chsm=bc+(fw>>8)+(fw&0xFF)+ty - for i in range(bc): - p=9+(i*2) - d=int(l[p:p+2],16) - chsm=(chsm+d)&0xFF - data.append(d) - chsm=(chsm+int(l[9+bc*2:11+bc*2],16))&0xFF - if (chsm!=0): - print "Error Checksum...." - exit() - #print bc,fw,ty,chsm -fi.close() -print - -l=subprocess.check_output("ls /sys/bus/w1/devices/", shell=True) -dc=0 -dl=[] -for g in (l.split("\n")): - if len(g)>2: - if testnr(g[0:2]): - dl.append(g) - dc=dc+1 - print dc,") ",g -if dc==0: - print "No 1-Wire Device found" - exit(0) -n=int(raw_input("No. of Device: ")) -n=n-1 -if (n>dc-1)or(n<0): - exit(0) -s=dl[n] -sys.stdout.write('Go to Flashmode....') -sys.stdout.flush() -owcom(s,[0x88],0) -owcom(s,[0x88],0) -owcom(s,[0x88],0) -for i in range (20): - l=subprocess.check_output("ls /sys/bus/w1/devices/", shell=True) - dc=0 - dl=[] - sys.stdout.write(".") - sys.stdout.flush() - for g in (l.split("\n")): - if (g[0:15]=="a3-55aa55aa55aa"): - break - if (g[0:15]!="a3-55aa55aa55aa"): - time.sleep(1) -if (g[0:15]=="a3-55aa55aa55aa"): - print "found" -else: - print "ERROR Enter Flashmode!" - exit() -f=open("/sys/bus/w1/devices/w1_bus_master1/w1_master_remove","r+b",0) -f.write(s) -f.close() -time.sleep(5) -s="a3-55aa55aa55aa" -prog=data -l=len(prog) -if (l>7616): - print "Code to big ... Max 7616 Byte (119 Pages)" - exit() -pages= l/64 -for i in range(64-(l%64)): - #print i - prog.append(0xFF) -pages= len(prog)/64 -if (pages>119): - print "Code to big ... Max 7616 Byte (119 Pages)" - exit() - - -print "Programm Page (of ", pages,")" - -for i in range(pages): - sys.stdout.write("%i " % (i+1) ) - sys.stdout.flush() - - h=i*64; - hl=h&0xFF - hh=h>>8 - #print hh, hl - mem=[hl,hh]+prog[h:h+64] - erroc=0 - while (1): - owcom(s,[0x0F]+mem,0) - rmem=owcom(s,[0xAA],66) - if (rmem!=mem): - print rmem - erroc=erroc+1 - if erroc>5: - print "WRITING ERROR ... " - exit() - continue - owcom(s,[0x55],0) - time.sleep(0.05) - owcom(s,[0xB8,hl,hh],0) - time.sleep(0.05) - rmem=owcom(s,[0xAA],66) - if (rmem!=mem): - print "error in flash" - print mem - print rmem - erroc=erroc+1 - if erroc>5: - print "WRITING ERROR ... " - exit() - continue - #for v in rmem: - # print "%02X " % (v), - break -print "\nReset AVR" -owcom(s,[0x89],0) -time.sleep(1) -f=open("/sys/bus/w1/devices/w1_bus_master1/w1_master_remove","r+b",0) -f.write("a3-55aa55aa55aa") -f.close() - - - - - - -#mem=[0x00,0x2] -#for i in range (64): -# mem.append(i) -#owcom(s,[0x0F]+mem,0) -#rmem=owcom(s,[0xAA],70) -#print rmem -#owcom(s,[0x55],0) -#time.sleep(0.05) -#owcom(s,[0xB8,0x00,0x02],0) -#time.sleep(0.05) -#rmem=owcom(s,[0xAA],70) -#print rmem -#for v in rmem: -# print "%02X " % (v) - - - +#!/usr/bin/python +# 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. + + + + +import time +import subprocess +import sys + +def owcom(dev,send,rc): + res=[] + f=open("/sys/bus/w1/devices/%s/rw" %(dev),"r+b",0) + f.write("".join(map(chr, send))) + if (rc!=0): + res=map(ord,f.read(rc)) + f.close() + return res + + +def crc8(arr): + lscrc=0x0; + for v in arr: + bit=1; + while bit<256: + if (v&bit)==bit: + lb=1 + else: + lb=0 + if (lscrc&1)!=lb: + lscrc=(lscrc>>1)^0x8c + else: + lscrc=(lscrc>>1) + bit=bit*2 + return lscrc + +def testnr(s): + for c in s.lower()[:]: + if not((c) in ['0','1','2','3','4','5','6','7','8','9','a','b','c','d','e','f','-']): + return False + return True + +def addid(id,val): + for i in range(7): + id[i+1]=id[i+1]+val + if id[i+1]>254: + id[i+1]=id[i+1]-254 + val=1 + else: + return id + return id +# + +print "Open Hex File ...", +fi=open(sys.argv[1],"r") +data=[] +for l in fi.readlines(): + sys.stdout.write(".") + sys.stdout.flush() + bc=int(l[1:3],16) + fw=int(l[3:7],16) + ty=int(l[7:9],16) + chsm=bc+(fw>>8)+(fw&0xFF)+ty + for i in range(bc): + p=9+(i*2) + d=int(l[p:p+2],16) + chsm=(chsm+d)&0xFF + data.append(d) + chsm=(chsm+int(l[9+bc*2:11+bc*2],16))&0xFF + if (chsm!=0): + print "Error Checksum...." + exit() + #print bc,fw,ty,chsm +fi.close() +print + +l=subprocess.check_output("ls /sys/bus/w1/devices/", shell=True) +dc=0 +dl=[] +for g in (l.split("\n")): + if len(g)>2: + if testnr(g[0:2]): + dl.append(g) + dc=dc+1 + print dc,") ",g +if dc==0: + print "No 1-Wire Device found" + exit(0) +n=int(raw_input("No. of Device: ")) +n=n-1 +if (n>dc-1)or(n<0): + exit(0) +s=dl[n] +sys.stdout.write('Go to Flashmode....') +sys.stdout.flush() +owcom(s,[0x88],0) +owcom(s,[0x88],0) +owcom(s,[0x88],0) +for i in range (20): + l=subprocess.check_output("ls /sys/bus/w1/devices/", shell=True) + dc=0 + dl=[] + sys.stdout.write(".") + sys.stdout.flush() + for g in (l.split("\n")): + if (g[0:15]=="a3-55aa55aa55aa"): + break + if (g[0:15]!="a3-55aa55aa55aa"): + time.sleep(1) +if (g[0:15]=="a3-55aa55aa55aa"): + print "found" +else: + print "ERROR Enter Flashmode!" + exit() +f=open("/sys/bus/w1/devices/w1_bus_master1/w1_master_remove","r+b",0) +f.write(s) +f.close() +time.sleep(5) +s="a3-55aa55aa55aa" +prog=data +l=len(prog) +if (l>7616): + print "Code to big ... Max 7616 Byte (119 Pages)" + exit() +pages= l/64 +for i in range(64-(l%64)): + #print i + prog.append(0xFF) +pages= len(prog)/64 +if (pages>119): + print "Code to big ... Max 7616 Byte (119 Pages)" + exit() + + +print "Programm Page (of ", pages,")" + +for i in range(pages): + sys.stdout.write("%i " % (i+1) ) + sys.stdout.flush() + + h=i*64; + hl=h&0xFF + hh=h>>8 + #print hh, hl + mem=[hl,hh]+prog[h:h+64] + erroc=0 + while (1): + owcom(s,[0x0F]+mem,0) + rmem=owcom(s,[0xAA],66) + if (rmem!=mem): + print rmem + erroc=erroc+1 + if erroc>5: + print "WRITING ERROR ... " + exit() + continue + owcom(s,[0x55],0) + time.sleep(0.05) + owcom(s,[0xB8,hl,hh],0) + time.sleep(0.05) + rmem=owcom(s,[0xAA],66) + if (rmem!=mem): + print "error in flash" + print mem + print rmem + erroc=erroc+1 + if erroc>5: + print "WRITING ERROR ... " + exit() + continue + #for v in rmem: + # print "%02X " % (v), + break +print "\nReset AVR" +owcom(s,[0x89],0) +time.sleep(1) +f=open("/sys/bus/w1/devices/w1_bus_master1/w1_master_remove","r+b",0) +f.write("a3-55aa55aa55aa") +f.close() + + + + + + +#mem=[0x00,0x2] +#for i in range (64): +# mem.append(i) +#owcom(s,[0x0F]+mem,0) +#rmem=owcom(s,[0xAA],70) +#print rmem +#owcom(s,[0x55],0) +#time.sleep(0.05) +#owcom(s,[0xB8,0x00,0x02],0) +#time.sleep(0.05) +#rmem=owcom(s,[0xAA],70) +#print rmem +#for v in rmem: +# print "%02X " % (v) + + + diff --git a/stest/fdiff.py b/stest/fdiff.py deleted file mode 100644 index e4c2056..0000000 --- a/stest/fdiff.py +++ /dev/null @@ -1,74 +0,0 @@ -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 deleted file mode 100644 index 415ffe3..0000000 --- a/stest/find.py +++ /dev/null @@ -1,292 +0,0 @@ -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 deleted file mode 100644 index a6ca49d..0000000 --- a/stest/log_all.py +++ /dev/null @@ -1,482 +0,0 @@ -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 deleted file mode 100644 index 70b3e17..0000000 --- a/stest/log_all1.py +++ /dev/null @@ -1,341 +0,0 @@ -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 deleted file mode 100644 index c1ca42f..0000000 --- a/stest/main.cpp +++ /dev/null @@ -1,184 +0,0 @@ -//============================================================================ -// Name : owtools.cpp -// Author : -// Version : -// Copyright : Your copyright notice -// Description : Hello World in C++, Ansi-style -//============================================================================ - -#include -#include -using namespace std; -extern "C" { -#include -} - -#include -#include -#include -#include - - -#include -#include -#include -#include - - - -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= '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 deleted file mode 100644 index b1c2871..0000000 --- a/stest/separate1.py +++ /dev/null @@ -1,103 +0,0 @@ -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/owReadBMP.py b/tools/owReadBMP.py new file mode 100644 index 0000000..00eac22 --- /dev/null +++ b/tools/owReadBMP.py @@ -0,0 +1,130 @@ +#!/usr/bin/python +# 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. + + + + +import time +import subprocess +import sys + +def owcom(dev,send,rc): + res=[] + f=open("/sys/bus/w1/devices/%s/rw" %(dev),"r+b",0) + f.write("".join(map(chr, send))) + if (rc!=0): + res=map(ord,f.read(rc)) + f.close() + return res + + +def crc8(arr): + lscrc=0x0; + for v in arr: + bit=1; + while bit<256: + if (v&bit)==bit: + lb=1 + else: + lb=0 + if (lscrc&1)!=lb: + lscrc=(lscrc>>1)^0x8c + else: + lscrc=(lscrc>>1) + bit=bit*2 + return lscrc + +def testnr(s): + for c in s.lower()[:]: + if not((c) in ['0','1','2','3','4','5','6','7','8','9','a','b','c','d','e','f','-']): + return False + return True + +def addid(id,val): + for i in range(7): + id[i+1]=id[i+1]+val + if id[i+1]>254: + id[i+1]=id[i+1]-254 + val=1 + else: + return id + return id +# + + +l=subprocess.check_output("ls /sys/bus/w1/devices/", shell=True) +dc=0 +dl=[] +for g in (l.split("\n")): + if len(g)>2: + if testnr(g[0:2]): + if (g[0:2]=="26"): + dl.append(g) + dc=dc+1 + print dc,") ",g +if dc==0: + print "No 26 1-Wire Device found" + exit(0) +n=int(raw_input("No. of Device (28-Device will get automatically): ")) +n=n-1 +if (n>dc-1)or(n<0): + exit(0) +s=dl[n] +config=owcom(s,[0x85],17) +print(config) +s2="%02x-%02x%02x%02x%02x%02x%02x" % (config[9],config[15],config[14],config[13],config[12],config[11],config[10]) +print("Second Device: %s" %( s2)) +f=open("/sys/bus/w1/devices/%s/w1_slave" %(s2),"rb",0) +res=f.read().split(" ") +f.close() +Press=((int(res[0],16)+int(res[1],16)*256)/16.0*3.2+700) +owcom(s,[0x4E,0x00,0x01],0) +owcom(s,[0x44],0) +time.sleep(1) +owcom(s,[0xB4],0) +time.sleep(1) + +p=owcom(s,[0xBE,0x00],10) +print (p) +T=((p[1]+p[2]*256)/256.0) +if (config[5]==8): + RH=((p[3]+p[4]*256)/100.0) +if (config[5]==7): + RH=(((p[3]+p[4]*256)/ 500.0 - 0.16) / 0.0062) / (1.0546 - 0.00216*T); + +print("Temperatur: %f °C" %(T)); +print("Luftfeuchte: %f %%" %(RH)); +print("Druck (absolut): %f hPa" %(Press)); +h=float(raw_input("Höhe über Meerespiegel in m: ")) +P0=Press/((1-h/44330)**5.255) +print("Druck (normalisiert): %f hPa" %(P0)); diff --git a/tools/owflash.py b/tools/owflash.py new file mode 100644 index 0000000..0d37e84 --- /dev/null +++ b/tools/owflash.py @@ -0,0 +1,255 @@ +#!/usr/bin/python +# 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. + + + + +import time +import subprocess +import sys + +def owcom(dev,send,rc): + res=[] + f=open("/sys/bus/w1/devices/%s/rw" %(dev),"r+b",0) + f.write("".join(map(chr, send))) + if (rc!=0): + res=map(ord,f.read(rc)) + f.close() + return res + + +def crc8(arr): + lscrc=0x0; + for v in arr: + bit=1; + while bit<256: + if (v&bit)==bit: + lb=1 + else: + lb=0 + if (lscrc&1)!=lb: + lscrc=(lscrc>>1)^0x8c + else: + lscrc=(lscrc>>1) + bit=bit*2 + return lscrc + +def testnr(s): + for c in s.lower()[:]: + if not((c) in ['0','1','2','3','4','5','6','7','8','9','a','b','c','d','e','f','-']): + return False + return True + +def addid(id,val): + for i in range(7): + id[i+1]=id[i+1]+val + if id[i+1]>254: + id[i+1]=id[i+1]-254 + val=1 + else: + return id + return id +# + + + +#start search +f=open("/sys/bus/w1/devices/w1_bus_master1/w1_master_search","r+b",0) +f.write("-1") +f.close() + + +print "Open Hex File ...", +fi=open(sys.argv[1],"r") +data=[] +for l in fi.readlines(): + sys.stdout.write(".") + sys.stdout.flush() + bc=int(l[1:3],16) + fw=int(l[3:7],16) + ty=int(l[7:9],16) + chsm=bc+(fw>>8)+(fw&0xFF)+ty + for i in range(bc): + p=9+(i*2) + d=int(l[p:p+2],16) + chsm=(chsm+d)&0xFF + data.append(d) + chsm=(chsm+int(l[9+bc*2:11+bc*2],16))&0xFF + if (chsm!=0): + print "Error Checksum...." + exit() + #print bc,fw,ty,chsm +fi.close() +print + +l=subprocess.check_output("ls /sys/bus/w1/devices/", shell=True) +dc=0 +dl=[] +for g in (l.split("\n")): + if len(g)>2: + if testnr(g[0:2]): + if (g[0:2]!="28"): + dl.append(g) + dc=dc+1 + print dc,") ",g +if dc==0: + print "No 1-Wire Device found" + exit(0) +n=int(raw_input("No. of Device: ")) +n=n-1 +if (n>dc-1)or(n<0): + exit(0) +s=dl[n] +if (s!="a3-55aa55aa55aa"): + sys.stdout.write('Go to Flashmode....') + sys.stdout.flush() + owcom(s,[0x88],0) + owcom(s,[0x88],0) + owcom(s,[0x88],0) + for i in range (20): + l=subprocess.check_output("ls /sys/bus/w1/devices/", shell=True) + dc=0 + dl=[] + sys.stdout.write(".") + sys.stdout.flush() + for g in (l.split("\n")): + if (g[0:15]=="a3-55aa55aa55aa"): + break + if (g[0:15]!="a3-55aa55aa55aa"): + time.sleep(1) + if (g[0:15]=="a3-55aa55aa55aa"): + print "found" + else: + print "ERROR Enter Flashmode!" + exit() + f=open("/sys/bus/w1/devices/w1_bus_master1/w1_master_remove","r+b",0) + f.write(s) + f.close() + time.sleep(5) + +#stop search +print("Disable Device Search (Wait 15s)") +f=open("/sys/bus/w1/devices/w1_bus_master1/w1_master_search","r+b",0) +f.write("0") +f.close() +time.sleep(15) + +s="a3-55aa55aa55aa" +prog=data +l=len(prog) +if (l>7551): + print "Code to big ... Max 7552 Byte (118 Pages)" + exit() +pages= l/64 +for i in range(64-(l%64)): + #print i + prog.append(0xFF) +pages= len(prog)/64 +if (pages>118): + print "Code to big ... Max 7552 Byte (118 Pages)" + exit() + + +print "Programm Page (of ", pages,")" + +for i in range(pages): + sys.stdout.write("%i " % (i+1) ) + sys.stdout.flush() + + h=i*64; + hl=h&0xFF + hh=h>>8 + #print hh, hl + mem=[hl,hh]+prog[h:h+64] + erroc=0 + while (1): + owcom(s,[0x0F]+mem,0) + rmem=owcom(s,[0xAA],66) + if (rmem!=mem): + print rmem + erroc=erroc+1 + if erroc>5: + print "WRITING ERROR ... " + exit() + continue + owcom(s,[0x55],0) + time.sleep(0.05) + owcom(s,[0xB8,hl,hh],0) + time.sleep(0.05) + rmem=owcom(s,[0xAA],66) + if (rmem!=mem): + print "error in flash" + print mem + print rmem + erroc=erroc+1 + if erroc>5: + print "WRITING ERROR ... " + exit() + continue + #for v in rmem: + # print "%02X " % (v), + break +print "\nReset AVR" +owcom(s,[0x89],0) +time.sleep(1) +f=open("/sys/bus/w1/devices/w1_bus_master1/w1_master_remove","r+b",0) +f.write("a3-55aa55aa55aa") +f.close() + +print("Enable Device Search") +f=open("/sys/bus/w1/devices/w1_bus_master1/w1_master_search","r+b",0) +f.write("-1") +f.close() + + + + + + +#mem=[0x00,0x2] +#for i in range (64): +# mem.append(i) +#owcom(s,[0x0F]+mem,0) +#rmem=owcom(s,[0xAA],70) +#print rmem +#owcom(s,[0x55],0) +#time.sleep(0.05) +#owcom(s,[0xB8,0x00,0x02],0) +#time.sleep(0.05) +#rmem=owcom(s,[0xAA],70) +#print rmem +#for v in rmem: +# print "%02X " % (v) + + + diff --git a/tools/owflashtest.py b/tools/owflashtest.py new file mode 100644 index 0000000..5e0b1a6 --- /dev/null +++ b/tools/owflashtest.py @@ -0,0 +1,241 @@ +#!/usr/bin/python +# 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. + + + + +import time +import subprocess +import sys + +def owcom(dev,send,rc): + res=[] + f=open("/sys/bus/w1/devices/%s/rw" %(dev),"r+b",0) + f.write("".join(map(chr, send))) + if (rc!=0): + res=map(ord,f.read(rc)) + f.close() + return res + + +def crc8(arr): + lscrc=0x0; + for v in arr: + bit=1; + while bit<256: + if (v&bit)==bit: + lb=1 + else: + lb=0 + if (lscrc&1)!=lb: + lscrc=(lscrc>>1)^0x8c + else: + lscrc=(lscrc>>1) + bit=bit*2 + return lscrc + +def testnr(s): + for c in s.lower()[:]: + if not((c) in ['0','1','2','3','4','5','6','7','8','9','a','b','c','d','e','f','-']): + return False + return True + +def addid(id,val): + for i in range(7): + id[i+1]=id[i+1]+val + if id[i+1]>254: + id[i+1]=id[i+1]-254 + val=1 + else: + return id + return id +# + + + +#start search +f=open("/sys/bus/w1/devices/w1_bus_master1/w1_master_search","r+b",0) +f.write("-1") +f.close() + + +print "Open Hex File ...", +fi=open(sys.argv[1],"r") +data=[] +for l in fi.readlines(): + sys.stdout.write(".") + sys.stdout.flush() + bc=int(l[1:3],16) + fw=int(l[3:7],16) + ty=int(l[7:9],16) + chsm=bc+(fw>>8)+(fw&0xFF)+ty + for i in range(bc): + p=9+(i*2) + d=int(l[p:p+2],16) + chsm=(chsm+d)&0xFF + data.append(d) + chsm=(chsm+int(l[9+bc*2:11+bc*2],16))&0xFF + if (chsm!=0): + print "Error Checksum...." + exit() + #print bc,fw,ty,chsm +fi.close() +print + +l=subprocess.check_output("ls /sys/bus/w1/devices/", shell=True) +dc=0 +dl=[] +for g in (l.split("\n")): + if len(g)>2: + if testnr(g[0:2]): + if (g[0:2]!="28"): + dl.append(g) + dc=dc+1 + print dc,") ",g +if dc==0: + print "No 1-Wire Device found" + exit(0) +n=int(raw_input("No. of Device: ")) +n=n-1 +if (n>dc-1)or(n<0): + exit(0) +s=dl[n] +if (s!="a3-55aa55aa55aa"): + sys.stdout.write('Go to Flashmode....') + sys.stdout.flush() + owcom(s,[0x88],0) + owcom(s,[0x88],0) + owcom(s,[0x88],0) + for i in range (20): + l=subprocess.check_output("ls /sys/bus/w1/devices/", shell=True) + dc=0 + dl=[] + sys.stdout.write(".") + sys.stdout.flush() + for g in (l.split("\n")): + if (g[0:15]=="a3-55aa55aa55aa"): + break + if (g[0:15]!="a3-55aa55aa55aa"): + time.sleep(1) + if (g[0:15]=="a3-55aa55aa55aa"): + print "found" + else: + print "ERROR Enter Flashmode!" + exit() + f=open("/sys/bus/w1/devices/w1_bus_master1/w1_master_remove","r+b",0) + f.write(s) + f.close() + time.sleep(5) + +#stop search +print("Disable Device Search (Wait 15s)") +f=open("/sys/bus/w1/devices/w1_bus_master1/w1_master_search","r+b",0) +f.write("0") +f.close() +time.sleep(15) + +s="a3-55aa55aa55aa" +prog=data +l=len(prog) +if (l>7551): + print "Code to big ... Max 7552 Byte (118 Pages)" + exit() +pages= l/64 +for i in range(64-(l%64)): + #print i + prog.append(0xFF) +pages= len(prog)/64 +if (pages>118): + print "Code to big ... Max 7552 Byte (118 Pages)" + exit() + + +print "Programm Page (of ", pages,")" + +for i in range(pages): + sys.stdout.write("%i " % (i+1) ) + sys.stdout.flush() + + h=i*64; + hl=h&0xFF + hh=h>>8 + #print hh, hl + mem=[hl,hh]+prog[h:h+64] + erroc=0 + while (1): + owcom(s,[0x0F]+mem,0) + rmem=owcom(s,[0xAA],66) + if (rmem!=mem): + print rmem + erroc=erroc+1 + if erroc>5: + print "WRITING ERROR ... " + exit() + continue + #for v in rmem: + # print "%02X " % (v), + break +print "\nReset AVR" +owcom(s,[0x89],0) +time.sleep(1) +f=open("/sys/bus/w1/devices/w1_bus_master1/w1_master_remove","r+b",0) +f.write("a3-55aa55aa55aa") +f.close() + +print("Enable Device Search") +f=open("/sys/bus/w1/devices/w1_bus_master1/w1_master_search","r+b",0) +f.write("-1") +f.close() + + + + + + +#mem=[0x00,0x2] +#for i in range (64): +# mem.append(i) +#owcom(s,[0x0F]+mem,0) +#rmem=owcom(s,[0xAA],70) +#print rmem +#owcom(s,[0x55],0) +#time.sleep(0.05) +#owcom(s,[0xB8,0x00,0x02],0) +#time.sleep(0.05) +#rmem=owcom(s,[0xAA],70) +#print rmem +#for v in rmem: +# print "%02X " % (v) + + + diff --git a/tools/readTempHum.py b/tools/readTempHum.py new file mode 100644 index 0000000..d129db6 --- /dev/null +++ b/tools/readTempHum.py @@ -0,0 +1,125 @@ +#!/usr/bin/python +# 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. + + + + +import time +import subprocess +import sys + +def owcom(dev,send,rc): + res=[] + f=open("/sys/bus/w1/devices/%s/rw" %(dev),"r+b",0) + f.write("".join(map(chr, send))) + if (rc!=0): + res=map(ord,f.read(rc)) + f.close() + return res + + +def crc8(arr): + lscrc=0x0; + for v in arr: + bit=1; + while bit<256: + if (v&bit)==bit: + lb=1 + else: + lb=0 + if (lscrc&1)!=lb: + lscrc=(lscrc>>1)^0x8c + else: + lscrc=(lscrc>>1) + bit=bit*2 + return lscrc + +def testnr(s): + for c in s.lower()[:]: + if not((c) in ['0','1','2','3','4','5','6','7','8','9','a','b','c','d','e','f','-']): + return False + return True + +def addid(id,val): + for i in range(7): + id[i+1]=id[i+1]+val + if id[i+1]>254: + id[i+1]=id[i+1]-254 + val=1 + else: + return id + return id +# + +def readDS18B20(s): + f=open("/sys/bus/w1/devices/%s/w1_slave" %(s),"rb",0) + res=f.read().split(" ") + f.close() + T=((int(res[0],16)+int(res[1],16)*256)/16.0) + print("Temperatur: %f °C" %(T)); + +def readDS2438(s): + owcom(s,[0x4E,0x00,0x01],0) + owcom(s,[0x44],0) + time.sleep(1) + owcom(s,[0xB4],0) + time.sleep(1) + owcom(s,[0xB8,0x00],0) + crc=1 + while crc: + p=owcom(s,[0xBE,0x00],9) + crc=crc8(p) + #print (p) + T=((p[1]+p[2]*256)/256.0) + RH=(((p[3]+p[4]*256)/ 500.0 - 0.16) / 0.0062) / (1.0546 - 0.00216*T); + print("Temperatur: %f °C" %(T)); + print("Luftfeuchte: %f %%" %(RH)); + + + +l=subprocess.check_output("ls /sys/bus/w1/devices/", shell=True) +dc=0 +dl=[] +for g in (l.split("\n")): + if len(g)>2: + if testnr(g[0:2]): + if (g[0:2]=="26"): + print dc,") ",g + readDS2438(g) + dl.append(g) + dc=dc+1 + if (g[0:2]=="28"): + print dc,") ",g + readDS18B20(g) + dl.append(g) + dc=dc+1 diff --git a/tools_cmd/IB10E64.dll b/tools_cmd/IB10E64.dll deleted file mode 100644 index 41580e1..0000000 Binary files a/tools_cmd/IB10E64.dll and /dev/null differ diff --git a/tools_cmd/IB97E64.dll b/tools_cmd/IB97E64.dll deleted file mode 100644 index db02450..0000000 Binary files a/tools_cmd/IB97E64.dll and /dev/null differ diff --git a/tools_cmd/IB97U64.dll b/tools_cmd/IB97U64.dll deleted file mode 100644 index 1a29cd7..0000000 Binary files a/tools_cmd/IB97U64.dll and /dev/null differ diff --git a/tools_cmd/IBFS64.dll b/tools_cmd/IBFS64.dll deleted file mode 100644 index d81a266..0000000 Binary files a/tools_cmd/IBFS64.dll and /dev/null differ diff --git a/tools_cmd/IBUSB64.dll b/tools_cmd/IBUSB64.dll deleted file mode 100644 index 9c1403c..0000000 Binary files a/tools_cmd/IBUSB64.dll and /dev/null differ diff --git a/tools_cmd/ib90usb.dll b/tools_cmd/ib90usb.dll deleted file mode 100644 index ca0f069..0000000 Binary files a/tools_cmd/ib90usb.dll and /dev/null differ diff --git a/tools_cmd/ib97e32.dll b/tools_cmd/ib97e32.dll deleted file mode 100644 index 6e6db4b..0000000 Binary files a/tools_cmd/ib97e32.dll and /dev/null differ diff --git a/tools_cmd/ib97u32.dll b/tools_cmd/ib97u32.dll deleted file mode 100644 index c08f1f4..0000000 Binary files a/tools_cmd/ib97u32.dll and /dev/null differ diff --git a/tools_cmd/ibfs32.dll b/tools_cmd/ibfs32.dll deleted file mode 100644 index bced541..0000000 Binary files a/tools_cmd/ibfs32.dll and /dev/null differ diff --git a/tools_cmd/ibtmjava.dll b/tools_cmd/ibtmjava.dll deleted file mode 100644 index c1a4d85..0000000 Binary files a/tools_cmd/ibtmjava.dll and /dev/null differ diff --git a/tools_cmd/ibtmjava64.dll b/tools_cmd/ibtmjava64.dll deleted file mode 100644 index be0c59d..0000000 Binary files a/tools_cmd/ibtmjava64.dll and /dev/null differ diff --git a/tools_cmd/ibusb32.dll b/tools_cmd/ibusb32.dll deleted file mode 100644 index 772fa8d..0000000 Binary files a/tools_cmd/ibusb32.dll and /dev/null differ diff --git a/tools_cmd/owtools.sdf b/tools_cmd/owtools.sdf deleted file mode 100644 index 367c2e9..0000000 Binary files a/tools_cmd/owtools.sdf and /dev/null differ diff --git a/tools_cmd/owtools.sln b/tools_cmd/owtools.sln deleted file mode 100644 index a00b8e7..0000000 --- a/tools_cmd/owtools.sln +++ /dev/null @@ -1,22 +0,0 @@ - -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