-
Notifications
You must be signed in to change notification settings - Fork 0
/
MiioDevice.cpp
39 lines (30 loc) · 897 Bytes
/
MiioDevice.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
//
// Created by lsk on 12/20/23.
//
#include "MiioDevice.h"
#include "Device.h"
#include <cstring>
#include <cstdlib>
#include <algorithm>
Device *device;
std::vector<const char*> strlist(std::vector<std::string> &input) {
std::vector<const char*> result;
// remember the nullptr terminator
result.reserve(input.size()+1);
std::transform(begin(input), end(input),
std::back_inserter(result),
[](std::string &s) { return s.data(); }
);
result.push_back(nullptr);
return result;
}
MiioDevice::MiioDevice(string ip, string token) {
device = new Device(ip.c_str(), token.c_str());
}
string MiioDevice::sendCommand(string command, vector<string> params) {
int respLength;
return (device->send(command.c_str(), strlist(params).data(), params.size(), respLength));
}
MiioDevice::~MiioDevice() {
delete device;
}