Reading values works now
This commit is contained in:
parent
e66d13e5a3
commit
ffb81213bb
@ -25,6 +25,7 @@ class GcLogger {
|
|||||||
|
|
||||||
public:
|
public:
|
||||||
void readIni(const string &);
|
void readIni(const string &);
|
||||||
|
|
||||||
int run();
|
int run();
|
||||||
};
|
};
|
||||||
|
|
||||||
|
@ -33,7 +33,7 @@ int GmcDevice::getCPM() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
string cmd = "<GETCPM>>";
|
string cmd = "<GETCPM>>";
|
||||||
string result;
|
vector<uint8_t> result;
|
||||||
|
|
||||||
if (device->serialWrite(cmd) == cmd.length()) {
|
if (device->serialWrite(cmd) == cmd.length()) {
|
||||||
result = device->serialRead(2); // cpm result has size 2
|
result = device->serialRead(2); // cpm result has size 2
|
||||||
@ -51,7 +51,7 @@ float GmcDevice::getTemperature() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
string cmd = "<GETTEMP>>";
|
string cmd = "<GETTEMP>>";
|
||||||
string result;
|
vector<uint8_t> result;
|
||||||
|
|
||||||
if (device->serialWrite(cmd) == cmd.length()) {
|
if (device->serialWrite(cmd) == cmd.length()) {
|
||||||
result = device->serialRead(4); // temp result has size 4
|
result = device->serialRead(4); // temp result has size 4
|
||||||
@ -60,8 +60,8 @@ float GmcDevice::getTemperature() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
int sign = result[2] == 0 ? 1 : -1;
|
int sign = result[2] == 0 ? 1 : -1;
|
||||||
float temp = result[0];
|
float temp = result[0]; // integer part
|
||||||
temp += (float) result[1] / 10;
|
temp += static_cast<float>(result[1] / 10.0); // float part
|
||||||
temp = temp * sign;
|
temp = temp * sign;
|
||||||
return temp;
|
return temp;
|
||||||
}
|
}
|
||||||
@ -73,7 +73,7 @@ string GmcDevice::getVersion() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
string cmd = "<GETVER>>";
|
string cmd = "<GETVER>>";
|
||||||
string result;
|
vector<uint8_t> result;
|
||||||
|
|
||||||
if (device->serialWrite(cmd) == cmd.length()) {
|
if (device->serialWrite(cmd) == cmd.length()) {
|
||||||
result = device->serialRead(14); // version result has size 14
|
result = device->serialRead(14); // version result has size 14
|
||||||
@ -81,7 +81,9 @@ string GmcDevice::getVersion() {
|
|||||||
cout << "Failed to send command to device!" << endl;
|
cout << "Failed to send command to device!" << endl;
|
||||||
}
|
}
|
||||||
|
|
||||||
return result;
|
string strResult(result.begin(), result.end());
|
||||||
|
|
||||||
|
return strResult;
|
||||||
}
|
}
|
||||||
|
|
||||||
bool GmcDevice::setHeartbeatOff() {
|
bool GmcDevice::setHeartbeatOff() {
|
||||||
|
@ -12,14 +12,19 @@ class GmcDevice {
|
|||||||
|
|
||||||
public:
|
public:
|
||||||
GmcDevice(const string &serialPort, int baud);
|
GmcDevice(const string &serialPort, int baud);
|
||||||
|
|
||||||
~GmcDevice();
|
~GmcDevice();
|
||||||
|
|
||||||
bool close();
|
bool close();
|
||||||
|
|
||||||
bool isConnected();
|
bool isConnected();
|
||||||
|
|
||||||
int getCPM();
|
int getCPM();
|
||||||
|
|
||||||
float getTemperature();
|
float getTemperature();
|
||||||
|
|
||||||
string getVersion();
|
string getVersion();
|
||||||
|
|
||||||
bool setHeartbeatOff();
|
bool setHeartbeatOff();
|
||||||
};
|
};
|
||||||
|
|
||||||
|
@ -60,12 +60,12 @@ SerialPort::~SerialPort() {
|
|||||||
serialClose();
|
serialClose();
|
||||||
}
|
}
|
||||||
|
|
||||||
string SerialPort::serialRead(int length) {
|
vector<uint8_t> SerialPort::serialRead(int length) {
|
||||||
char *buf = (char *) calloc(length + 1, sizeof(char));
|
auto *buf = reinterpret_cast<uint8_t *> (calloc(length, sizeof(uint8_t)));
|
||||||
|
|
||||||
read(fd, buf, length);
|
read(fd, buf, length);
|
||||||
|
|
||||||
string result(buf);
|
vector<uint8_t> result(buf, buf + length);
|
||||||
free(buf);
|
free(buf);
|
||||||
|
|
||||||
return result;
|
return result;
|
||||||
|
@ -7,6 +7,7 @@
|
|||||||
|
|
||||||
#include <iostream>
|
#include <iostream>
|
||||||
#include <string>
|
#include <string>
|
||||||
|
#include <vector>
|
||||||
|
|
||||||
#include <termios.h> // POSIX terminal control definitions
|
#include <termios.h> // POSIX terminal control definitions
|
||||||
#include <unistd.h>
|
#include <unistd.h>
|
||||||
@ -19,19 +20,24 @@ class SerialPort {
|
|||||||
struct termios tio;
|
struct termios tio;
|
||||||
int tioBaud;
|
int tioBaud;
|
||||||
|
|
||||||
int getTioBaud(int);
|
static int getTioBaud(int);
|
||||||
|
|
||||||
public:
|
public:
|
||||||
// Constructor
|
// Constructor
|
||||||
SerialPort();
|
SerialPort();
|
||||||
|
|
||||||
SerialPort(const string &, int);
|
SerialPort(const string &, int);
|
||||||
|
|
||||||
~SerialPort();
|
~SerialPort();
|
||||||
|
|
||||||
bool isOpen();
|
bool isOpen();
|
||||||
|
|
||||||
bool serialClose();
|
bool serialClose();
|
||||||
|
|
||||||
string serialRead(int);
|
vector<uint8_t> serialRead(int);
|
||||||
|
|
||||||
int serialWrite(const string &);
|
int serialWrite(const string &);
|
||||||
|
|
||||||
bool clearInput(int);
|
bool clearInput(int);
|
||||||
};
|
};
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user