fix
This commit is contained in:
parent
2b89c9736b
commit
68ae71db28
@ -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();
|
||||
|
||||
}
|
||||
}
|
||||
|
@ -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) {
|
||||
|
@ -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();
|
||||
|
@ -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
|
||||
|
26
src/time.cpp
26
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++;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
19
src/time.h
19
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_ */
|
||||
|
Loading…
x
Reference in New Issue
Block a user