This commit is contained in:
Wolfgang Hottgenroth 2014-10-03 17:51:07 +02:00
parent 2b89c9736b
commit 68ae71db28
6 changed files with 16 additions and 53 deletions

View File

@ -15,10 +15,11 @@
#include "meterBusClient.h" #include "meterBusClient.h"
#include "debug.h" #include "debug.h"
#include "adc.h" #include "adc.h"
#include "uptime.h"
MeterBusClient meterBusClient; MeterBusClient meterBusClient;
Uptime uptime;
int main() { int main() {
WDTCTL = WDTPW | WDTHOLD; WDTCTL = WDTPW | WDTHOLD;
@ -29,7 +30,7 @@ int main() {
adcInit(); adcInit();
timeInit(); timeInit();
meterBusClient.begin(); meterBusClient.begin(&uptime);
__enable_interrupt(); __enable_interrupt();
@ -38,6 +39,7 @@ int main() {
while (1) { while (1) {
// __bis_status_register(LPM0_bits); // __bis_status_register(LPM0_bits);
meterBusClient.exec(); meterBusClient.exec();
uptime.exec();
} }
} }

View File

@ -23,9 +23,10 @@ MeterBusClient::MeterBusClient() : m_address(0),
void MeterBusClient::begin() { void MeterBusClient::begin(Uptime *uptime) {
// setAddress(Config::getUChar(Config::METERBUSCLIENT_ADDRESS)); // setAddress(Config::getUChar(Config::METERBUSCLIENT_ADDRESS));
setAddress(0x22); setAddress(0x22);
m_uptime = uptime;
} }
void MeterBusClient::setAddress(unsigned char a) { void MeterBusClient::setAddress(unsigned char a) {

View File

@ -8,7 +8,7 @@
#ifndef METERBUSCLIENT_H_ #ifndef METERBUSCLIENT_H_
#define METERBUSCLIENT_H_ #define METERBUSCLIENT_H_
#include "uptime.h"
@ -52,9 +52,11 @@ struct MeterBusFrame {
class MeterBusClient { class MeterBusClient {
public: public:
MeterBusClient(); MeterBusClient();
void begin(); void begin(Uptime *uptime);
void exec(); void exec();
private: private:
Uptime *m_uptime;
unsigned char m_address; unsigned char m_address;
void setAddress(unsigned char address); void setAddress(unsigned char address);
unsigned char getAddress(); unsigned char getAddress();

View File

@ -9,7 +9,6 @@
#include "stdint.h" #include "stdint.h"
#include "adc.h" #include "adc.h"
#include "time.h"
void MeterBusClient::aSB(unsigned char v) { void MeterBusClient::aSB(unsigned char v) {
m_sendBuffer[m_sendBufferLen] = v; m_sendBuffer[m_sendBufferLen] = v;
@ -114,25 +113,25 @@ void MeterBusClient::REQ_UD2() {
aSB((unsigned char)0x01); aSB((unsigned char)0x01);
// VIF // VIF
aSB((unsigned char)0x24); aSB((unsigned char)0x24);
aSB(uptime.getSeconds()); aSB(m_uptime->getSeconds());
// DIF // DIF
aSB((unsigned char)0x01); aSB((unsigned char)0x01);
// VIF // VIF
aSB((unsigned char)0x25); aSB((unsigned char)0x25);
aSB(uptime.getMinutes()); aSB(m_uptime->getMinutes());
// DIF // DIF
aSB((unsigned char)0x01); aSB((unsigned char)0x01);
// VIF // VIF
aSB((unsigned char)0x26); aSB((unsigned char)0x26);
aSB(uptime.getHours()); aSB(m_uptime->getHours());
// DIF // DIF
aSB((unsigned char)0x02); aSB((unsigned char)0x02);
// VIF // VIF
aSB((unsigned char)0x27); aSB((unsigned char)0x27);
aSB((unsigned int)uptime.getDays()); aSB((unsigned int)m_uptime->getDays());
// Measurement Value // Measurement Value

View File

@ -12,7 +12,6 @@
volatile unsigned long timestamp; volatile unsigned long timestamp;
Uptime uptime;
ISR(TIMER0_A0, TA0_ISR) { ISR(TIMER0_A0, TA0_ISR) {
static uint8_t state = 0; static uint8_t state = 0;
@ -40,9 +39,9 @@ void timeInit() {
P1DIR |= BIT6 | BIT0; P1DIR |= BIT6 | BIT0;
P1OUT = 0; P1OUT = 0;
TACCR0 = 1024; TACCR0 = 32;
TACCTL0 = CCIE; 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; 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++;
}
}
}
}

View File

@ -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_ */ #endif /* TIME_H_ */