-
Notifications
You must be signed in to change notification settings - Fork 0
/
SerialHandler.cpp
55 lines (39 loc) · 1.29 KB
/
SerialHandler.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
#include "SerialHandler.hpp"
#include "Serial.hpp"
//TODO what here is needed
#include <iostream>
#include <sstream>
#include<map>
SerialHandler::SerialHandler() : connections{std::map<std::string,Serial>{}}
{}
void SerialHandler::openConn(const std::string& device, int baud){
connections.emplace(device, Serial{});
if (!connections.at(device).openConn(device, baud)){
throw std::exception();
}
}
void SerialHandler::closeConn(const std::string& device){
connections.at(device).closeConn();
connections.erase(device);
}
std::string SerialHandler::getASCIIData(const std::string& device){
try{
return std::move(connections.at(device).getASCIIData());
}
catch(std::out_of_range e) {
return "ERROR";
}
}
std::string SerialHandler::getHEXData(const std::string& device){
return std::move(connections.at(device).getHEXData());
}
void SerialHandler::sendData(const std::string& device, const std::string& data) {
connections.at(device).sendData(data);
}
void SerialHandler::sendDataHex(const std::string& device, unsigned char * bytes, int len) {
connections.at(device).sendDataHex(bytes, len);
}
void SerialHandler::sendDataAll(const std::string& data) {
for(auto& [device, serial] : connections)
serial.sendData(data);
}