-
Notifications
You must be signed in to change notification settings - Fork 7
/
MergCBUSThrottle.cpp
113 lines (92 loc) · 2.49 KB
/
MergCBUSThrottle.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
#include "MergCBUSThrottle.h"
MergCBUSThrottle::MergCBUSThrottle(MergCBUS *cbus)
{
//ctor
this->cbus=cbus;
//this->message=message;
for (uint8_t i=0;i<NUM_SESSIONS;i++){
tinfo[i].setSession(255);
tinfo[i].setLoco(0);
}
setKeepAliveInterval(2000);
}
MergCBUSThrottle::~MergCBUSThrottle()
{
//dtor
}
void MergCBUSThrottle::run(){
sendKeepAlive();
}
void MergCBUSThrottle::sendKeepAlive(){
uint32_t t;
for (uint8_t i=0;i<NUM_SESSIONS;i++){
t=millis();
if (tinfo[i].getLoco() != 0){
if ((t-tinfo[i].getTime())>keepalive_interval){
tinfo[i].setTime(t);
Serial.println(F("keep alive"));
cbus->sendKeepAliveSession(tinfo[i].getSession());
}
}
}
}
bool MergCBUSThrottle::getSession(uint16_t loco){
if (cbus->sendGetSession(loco) == 0){
return true;
}
return false;
}
bool MergCBUSThrottle::releaseSession(uint8_t session){
if (cbus->sendReleaseSession(session) == 0){
for (uint8_t i=0;i<NUM_SESSIONS;i++){
if (tinfo[i].getSession() == session){
tinfo[i].setLoco(0);
tinfo[i].setSession(0);
break;
}
}
return true;
}
return false;
}
bool MergCBUSThrottle::setSession(uint8_t session,uint16_t loco){
for (uint8_t i=0;i<NUM_SESSIONS;i++){
if (tinfo[i].getLoco() == 0 ){
tinfo[i].setTime(millis());
tinfo[i].setSession(session);
tinfo[i].setLoco(loco);
return true;
}
}
return false;
}
bool MergCBUSThrottle::consist(uint16_t loco1,uint16_t loco2){
}
void MergCBUSThrottle::setKeepAliveInterval(uint16_t interval_milli){
this->keepalive_interval=interval_milli;
}
uint16_t MergCBUSThrottle::getKeepAliveInterval(){
return this->keepalive_interval;
}
void MergCBUSThrottle::setFOn(uint8_t session,uint8_t f){
cbus->sendSetFun(session,f);
}
void MergCBUSThrottle::setFOff(uint8_t session, uint8_t f){
cbus->sendUnsetFun(session,f);
}
void MergCBUSThrottle::setSpeedMode(uint8_t session){
cbus->sendSpeedMode(session,0);
}
uint8_t MergCBUSThrottle::getSpeed(){
}
void MergCBUSThrottle::setDirection(bool d_forward){
}
bool MergCBUSThrottle::getDirection(){
}
bool MergCBUSThrottle::setSpeedDirection(uint8_t session, uint8_t v,bool d_forward){
cbus->sendSpeedDir(session,v,d_forward);
}
bool MergCBUSThrottle::stealLoco(){
}
bool MergCBUSThrottle::shareLoco(){
}