From 68ae71db284e38f2fab813ad439591dab87d2c6d Mon Sep 17 00:00:00 2001 From: Wolfgang Hottgenroth Date: Fri, 3 Oct 2014 17:51:07 +0200 Subject: [PATCH] fix --- src/main.cpp | 6 ++++-- src/meterBusClient.cpp | 3 ++- src/meterBusClient.h | 6 ++++-- src/meterBusClientFrames.cpp | 9 ++++----- src/time.cpp | 26 ++------------------------ src/time.h | 19 ------------------- 6 files changed, 16 insertions(+), 53 deletions(-) diff --git a/src/main.cpp b/src/main.cpp index 308c8c9..0d7f0d4 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -15,10 +15,11 @@ #include "meterBusClient.h" #include "debug.h" #include "adc.h" +#include "uptime.h" MeterBusClient meterBusClient; - +Uptime uptime; int main() { WDTCTL = WDTPW | WDTHOLD; @@ -29,7 +30,7 @@ int main() { adcInit(); timeInit(); - meterBusClient.begin(); + meterBusClient.begin(&uptime); __enable_interrupt(); @@ -38,6 +39,7 @@ int main() { while (1) { // __bis_status_register(LPM0_bits); meterBusClient.exec(); + uptime.exec(); } } diff --git a/src/meterBusClient.cpp b/src/meterBusClient.cpp index 480b5e4..a29c213 100644 --- a/src/meterBusClient.cpp +++ b/src/meterBusClient.cpp @@ -23,9 +23,10 @@ MeterBusClient::MeterBusClient() : m_address(0), -void MeterBusClient::begin() { +void MeterBusClient::begin(Uptime *uptime) { // setAddress(Config::getUChar(Config::METERBUSCLIENT_ADDRESS)); setAddress(0x22); + m_uptime = uptime; } void MeterBusClient::setAddress(unsigned char a) { diff --git a/src/meterBusClient.h b/src/meterBusClient.h index b6f4e4d..ea2c067 100644 --- a/src/meterBusClient.h +++ b/src/meterBusClient.h @@ -8,7 +8,7 @@ #ifndef METERBUSCLIENT_H_ #define METERBUSCLIENT_H_ - +#include "uptime.h" @@ -52,9 +52,11 @@ struct MeterBusFrame { class MeterBusClient { public: MeterBusClient(); - void begin(); + void begin(Uptime *uptime); void exec(); private: + Uptime *m_uptime; + unsigned char m_address; void setAddress(unsigned char address); unsigned char getAddress(); diff --git a/src/meterBusClientFrames.cpp b/src/meterBusClientFrames.cpp index 184d433..33a1c13 100644 --- a/src/meterBusClientFrames.cpp +++ b/src/meterBusClientFrames.cpp @@ -9,7 +9,6 @@ #include "stdint.h" #include "adc.h" -#include "time.h" void MeterBusClient::aSB(unsigned char v) { m_sendBuffer[m_sendBufferLen] = v; @@ -114,25 +113,25 @@ void MeterBusClient::REQ_UD2() { aSB((unsigned char)0x01); // VIF aSB((unsigned char)0x24); - aSB(uptime.getSeconds()); + aSB(m_uptime->getSeconds()); // DIF aSB((unsigned char)0x01); // VIF aSB((unsigned char)0x25); - aSB(uptime.getMinutes()); + aSB(m_uptime->getMinutes()); // DIF aSB((unsigned char)0x01); // VIF aSB((unsigned char)0x26); - aSB(uptime.getHours()); + aSB(m_uptime->getHours()); // DIF aSB((unsigned char)0x02); // VIF aSB((unsigned char)0x27); - aSB((unsigned int)uptime.getDays()); + aSB((unsigned int)m_uptime->getDays()); // Measurement Value diff --git a/src/time.cpp b/src/time.cpp index b0b5a41..1aa40e3 100644 --- a/src/time.cpp +++ b/src/time.cpp @@ -12,7 +12,6 @@ volatile unsigned long timestamp; -Uptime uptime; ISR(TIMER0_A0, TA0_ISR) { static uint8_t state = 0; @@ -40,9 +39,9 @@ void timeInit() { P1DIR |= BIT6 | BIT0; P1OUT = 0; - TACCR0 = 1024; + TACCR0 = 32; TACCTL0 = CCIE; - TACTL = MC_1 | ID_3 | TASSEL_1 | TACLR; + TACTL = MC_1 | ID_0 | TASSEL_1 | TACLR; } @@ -50,24 +49,3 @@ unsigned long millis() { return timestamp; } - -Uptime::Uptime() : m_seconds(0), m_minutes(0), m_hours(0), m_days(0) { - -} - - -void Uptime::incOneSecond() { - m_seconds++; - if (m_seconds >= 60) { - m_seconds -= 60; - m_minutes++; - if (m_minutes >= 60) { - m_minutes -= 60; - m_hours++; - if (m_hours >= 24) { - m_hours -= 24; - m_days++; - } - } - } -} diff --git a/src/time.h b/src/time.h index 4eb0c1a..3b745b1 100644 --- a/src/time.h +++ b/src/time.h @@ -16,23 +16,4 @@ unsigned long millis(); - -class Uptime { -public: - Uptime(); - uint8_t getSeconds() { return m_seconds; }; - uint8_t getMinutes() { return m_minutes; }; - uint8_t getHours() { return m_hours; }; - uint16_t getDays() { return m_days; }; - void incOneSecond(); -private: - uint8_t m_seconds; - uint8_t m_minutes; - uint8_t m_hours; - uint16_t m_days; -}; - - -extern Uptime uptime; - #endif /* TIME_H_ */