From 2b89c9736bd9293d826d04409487c7ff17347b26 Mon Sep 17 00:00:00 2001 From: hg Date: Fri, 3 Oct 2014 17:27:42 +0200 Subject: [PATCH] measurement in telegram --- src/meterBusClientFrames.cpp | 35 +++++++++++++++++++++++++++++++++++ src/time.cpp | 24 ++++++++++++++++++++++++ src/time.h | 21 +++++++++++++++++++++ 3 files changed, 80 insertions(+) diff --git a/src/meterBusClientFrames.cpp b/src/meterBusClientFrames.cpp index c5982d7..184d433 100644 --- a/src/meterBusClientFrames.cpp +++ b/src/meterBusClientFrames.cpp @@ -9,6 +9,8 @@ #include "stdint.h" #include "adc.h" +#include "time.h" + void MeterBusClient::aSB(unsigned char v) { m_sendBuffer[m_sendBufferLen] = v; m_sendBufferLen++; @@ -106,8 +108,41 @@ void MeterBusClient::REQ_UD2() { aSB(getStatus()); // Status aSB((unsigned int)0); // Signatur + + // Uptime + // DIF + aSB((unsigned char)0x01); + // VIF + aSB((unsigned char)0x24); + aSB(uptime.getSeconds()); + + // DIF + aSB((unsigned char)0x01); + // VIF + aSB((unsigned char)0x25); + aSB(uptime.getMinutes()); + + // DIF + aSB((unsigned char)0x01); + // VIF + aSB((unsigned char)0x26); + aSB(uptime.getHours()); + + // DIF + aSB((unsigned char)0x02); + // VIF + aSB((unsigned char)0x27); + aSB((unsigned int)uptime.getDays()); + + + // Measurement Value + // DIF + aSB((uint8_t)0x02); + aSB((uint8_t)0x7f); + uint16_t measVal = adcGet(); aSB(measVal); + //aSB((uint16_t) 0xaffe); aSB(calcSendChecksum()); diff --git a/src/time.cpp b/src/time.cpp index 650a963..b0b5a41 100644 --- a/src/time.cpp +++ b/src/time.cpp @@ -8,9 +8,11 @@ #include #include +#include "time.h" volatile unsigned long timestamp; +Uptime uptime; ISR(TIMER0_A0, TA0_ISR) { static uint8_t state = 0; @@ -47,3 +49,25 @@ void timeInit() { 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 10a66bc..4eb0c1a 100644 --- a/src/time.h +++ b/src/time.h @@ -14,4 +14,25 @@ void timeInit(); 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_ */