-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathClient.cpp
More file actions
111 lines (96 loc) · 2.5 KB
/
Client.cpp
File metadata and controls
111 lines (96 loc) · 2.5 KB
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
#include "Client.h"
Client::Client()
{
//ctor
}
Client::~Client()
{
//dtor
}
Client& Client::setIp(char *ip){
this->ip = string(ip);
return *this;
}
Client& Client::setNodeConfigurator(nodeConfigurator *config){
this->config = config;
return *this;
}
string Client::getIp(){
return ip;
}
int Client::getId(){
return id;
}
Client& Client::setId(int id){
this->id = id;
return *this;
}
Client& Client::setLogger(log4cpp::Category *logger){
this->logger = logger;
return *this;
}
Client& Client::setCanHandler(canHandler *can){
this->can = can;
return *this;
}
Client& Client::setClientSocket(int client_socket){
this->client_sock = client_socket;
return *this;
}
Client& Client::setSockAddr(struct sockaddr_in client_addr){
this->client_addr = client_addr;
return *this;
}
Client& Client::setServer(tcpServer *server){
this->server = server;
return *this;
}
vector<string> & Client::split(const string &s, char delim, vector<string> &elems)
{
stringstream ss(s+' ');
string item;
while(getline(ss, item, delim))
{
elems.push_back(item);
}
return elems;
}
void Client::sendCbusMessage(int nbytes, byte b0, byte b1, byte b2, byte b3, byte b4, byte b5, byte b6, byte b7){
char msg[CAN_MSG_SIZE];
msg[0] = b0;
msg[1] = b1;
msg[2] = b2;
msg[3] = b3;
msg[4] = b4;
msg[5] = b5;
msg[6] = b6;
msg[7] = b7;
logger->debug("[%d] [Client] Sending message to CBUS",id);
int n=nbytes;
if (nbytes>CAN_MSG_SIZE) n = CAN_MSG_SIZE;
can->put_to_out_queue(msg,n,clientType);
}
void Client::sendCbusMessage(byte b0){
sendCbusMessage(1,b0,0,0,0,0,0,0,0);
}
void Client::sendCbusMessage(byte b0,byte b1){
sendCbusMessage(2,b0,b1,0,0,0,0,0,0);
}
void Client::sendCbusMessage(byte b0,byte b1, byte b2){
sendCbusMessage(3,b0,b1,b2,0,0,0,0,0);
}
void Client::sendCbusMessage(byte b0,byte b1, byte b2, byte b3){
sendCbusMessage(4,b0,b1,b2,b3,0,0,0,0);
}
void Client::sendCbusMessage(byte b0,byte b1, byte b2, byte b3, byte b4){
sendCbusMessage(5,b0,b1,b2,b3,b4,0,0,0);
}
void Client::sendCbusMessage(byte b0,byte b1, byte b2, byte b3, byte b4, byte b5){
sendCbusMessage(6,b0,b1,b2,b3,b4,b5,0,0);
}
void Client::sendCbusMessage(byte b0,byte b1, byte b2, byte b3, byte b4, byte b5, byte b6){
sendCbusMessage(7,b0,b1,b2,b3,b4,b5,b6,0);
}
void Client::sendCbusMessage(byte b0,byte b1, byte b2, byte b3, byte b4, byte b5, byte b6, byte b7){
sendCbusMessage(8,b0,b1,b2,b3,b4,b5,b6,b7);
}