Merge branch 'master' of git://github.com/yuhu-/ebusd

This commit is contained in:
john30
2014-11-22 20:46:25 +01:00
33 changed files with 803 additions and 693 deletions
+15 -15
View File
@@ -27,7 +27,7 @@
#include <vector>
#include <cstring>
std::string Command::calcData()
string Command::calcData()
{
// encode - only first entry will be encoded
// ToDo: if more parts are needed, they will be implemented
@@ -39,7 +39,7 @@ std::string Command::calcData()
return m_result;
}
std::string Command::calcResult(const cmd_t& cmd)
string Command::calcResult(const cmd_t& cmd)
{
int elements = strtol(m_command[9].c_str(), NULL, 10);
@@ -81,10 +81,10 @@ std::string Command::calcResult(const cmd_t& cmd)
return m_result;
}
void Command::calcSub(const std::string& part, const std::string& position,
const std::string& type, const std::string& factor)
void Command::calcSub(const string& part, const string& position,
const string& type, const string& factor)
{
std::string data;
string data;
// Master Data
if (strcasecmp(part.c_str(), "MD") == 0) {
@@ -121,18 +121,18 @@ void Command::calcSub(const std::string& part, const std::string& position,
decode(data, position, type, factor);
}
void Command::decode(const std::string& data, const std::string& position,
const std::string& type, const std::string& factor)
void Command::decode(const string& data, const string& position,
const string& type, const string& factor)
{
std::ostringstream result, value;
ostringstream result, value;
Decode* help = NULL;
// prepare position
std::string token;
std::istringstream stream(position);
std::vector<int> pos;
string token;
istringstream stream(position);
vector<int> pos;
while (std::getline(stream, token, ',') != 0)
while (getline(stream, token, ',') != 0)
pos.push_back(strtol(token.c_str(), NULL, 10));
if (strcasecmp(type.c_str(), "HEX") == 0) {
@@ -251,10 +251,10 @@ void Command::decode(const std::string& data, const std::string& position,
delete help;
}
void Command::encode(const std::string& data, const std::string& type,
const std::string& factor)
void Command::encode(const string& data, const string& type,
const string& factor)
{
std::ostringstream result;
ostringstream result;
Encode* help = NULL;
if (strcasecmp(type.c_str(), "HEX") == 0) {
+17 -15
View File
@@ -23,7 +23,9 @@
#include <string>
#include <vector>
typedef std::vector<std::string> cmd_t;
using namespace std;
typedef vector<string> cmd_t;
typedef cmd_t::const_iterator cmdCI_t;
class Command
@@ -31,31 +33,31 @@ class Command
public:
Command(int index, cmd_t command) : m_index(index), m_command(command) {}
Command(int index, cmd_t command, std::string data)
Command(int index, cmd_t command, string data)
: m_index(index), m_command(command), m_data(data) {}
cmd_t getCommand() const { return m_command; }
void setData(const std::string& data) { m_data = data; }
std::string getData() const { return m_data; }
std::string calcData();
void setData(const string& data) { m_data = data; }
string getData() const { return m_data; }
string calcData();
std::string calcResult(const cmd_t& cmd);
string calcResult(const cmd_t& cmd);
private:
int m_index;
cmd_t m_command;
std::string m_data;
std::string m_result;
std::string m_error;
string m_data;
string m_result;
string m_error;
void calcSub(const std::string& part, const std::string& position,
const std::string& type, const std::string& factor);
void calcSub(const string& part, const string& position,
const string& type, const string& factor);
void decode(const std::string& data, const std::string& position,
const std::string& type, const std::string& factor);
void decode(const string& data, const string& position,
const string& type, const string& factor);
void encode(const std::string& data, const std::string& type,
const std::string& factor);
void encode(const string& data, const string& type,
const string& factor);
};
+24 -22
View File
@@ -25,6 +25,8 @@
#include <vector>
#include <cstring>
using namespace std;
Commands::~Commands()
{
for (mapCI_t iter = m_pollDB.begin(); iter != m_pollDB.end(); ++iter)
@@ -62,26 +64,26 @@ void Commands::printCommands() const
for (cmdDBCI_t i = m_cmdDB.begin(); i != m_cmdDB.end(); i++) {
printCommand(*i);
std::cout << std::endl;
cout << endl;
}
}
int Commands::findCommand(const std::string& data) const
int Commands::findCommand(const string& data) const
{
// no commands definend
if (m_cmdDB.size() == 0)
return -2;
// preapre string for searching command
std::string token;
std::istringstream isstr(data);
std::vector<std::string> cmd;
string token;
istringstream isstr(data);
vector<string> cmd;
// split stream
while (std::getline(isstr, token, ' ') != 0)
while (getline(isstr, token, ' ') != 0)
cmd.push_back(token);
std::size_t index;
size_t index;
cmdDBCI_t i = m_cmdDB.begin();
// walk through commands - GET
@@ -123,25 +125,25 @@ int Commands::findCommand(const std::string& data) const
return -1;
}
std::string Commands::getBusCommand(const int index) const
string Commands::getBusCommand(const int index) const
{
cmd_t command = m_cmdDB.at(index);
std::string cmd;
std::stringstream sstr;
string cmd;
stringstream sstr;
if (strcasecmp(command[0].c_str(), "C") == 0)
cmd += command[4]; // QQ
cmd += command[5]; // ZZ
cmd += command[6]; // PBSB
sstr << std::setw(2) << std::hex << std::setfill('0') << command[7];
sstr << setw(2) << hex << setfill('0') << command[7];
cmd += sstr.str(); // NN
cmd += command[8]; // Dx
return cmd;
}
int Commands::storeCycData(const std::string& data) const
int Commands::storeCycData(const string& data) const
{
// no commands defined
if (m_cycDB.size() == 0)
@@ -152,14 +154,14 @@ int Commands::storeCycData(const std::string& data) const
return -3;
// prepare string for searching command
std::string search(data.substr(2, 8 + strtol(data.substr(8,2).c_str(), NULL, 16) * 2));
string search(data.substr(2, 8 + strtol(data.substr(8,2).c_str(), NULL, 16) * 2));
mapCI_t iter = m_cycDB.begin();
// walk through commands
for (; iter != m_cycDB.end(); iter++) {
std::string command = getBusCommand(iter->first);
string command = getBusCommand(iter->first);
// skip wrong search string length
if (command.length() > search.length())
@@ -175,7 +177,7 @@ int Commands::storeCycData(const std::string& data) const
return -1;
}
std::string Commands::getCycData(int index) const
string Commands::getCycData(int index) const
{
mapCI_t iter = m_cycDB.find(index);
if (iter != m_cycDB.end())
@@ -202,17 +204,17 @@ int Commands::nextPollCommand()
return -1;
}
void Commands::storePollData(const std::string& data) const
void Commands::storePollData(const string& data) const
{
// prepare string for searching command
std::string search(data.substr(2, 8 + strtol(data.substr(8,2).c_str(), NULL, 16) * 2));
string search(data.substr(2, 8 + strtol(data.substr(8,2).c_str(), NULL, 16) * 2));
mapCI_t iter = m_pollDB.begin();
// walk through commands
for (; iter != m_pollDB.end(); iter++) {
std::string command = getBusCommand(iter->first);
string command = getBusCommand(iter->first);
// skip wrong search string length
if (command.length() > search.length())
@@ -224,7 +226,7 @@ void Commands::storePollData(const std::string& data) const
}
}
std::string Commands::getPollData(const int index) const
string Commands::getPollData(const int index) const
{
mapCI_t iter = m_pollDB.find(index);
if (iter != m_pollDB.end())
@@ -233,9 +235,9 @@ std::string Commands::getPollData(const int index) const
return "";
}
void Commands::storeScanData(const std::string& data)
void Commands::storeScanData(const string& data)
{
std::vector<std::string>::const_iterator iter = m_scanDB.begin();
vector<string>::const_iterator iter = m_scanDB.begin();
bool found = false;
// walk through scan data
@@ -253,6 +255,6 @@ void Commands::printCommand(const cmd_t& command) const
return;
for (cmdCI_t i = command.begin(); i != command.end(); i++)
std::cout << *i << ';';
cout << *i << ';';
}
+20 -18
View File
@@ -25,12 +25,14 @@
#include <vector>
#include <map>
typedef std::vector<cmd_t> cmdDB_t;
using namespace std;
typedef vector<cmd_t> cmdDB_t;
typedef cmdDB_t::const_iterator cmdDBCI_t;
typedef std::map<int, Command*> map_t;
typedef map<int, Command*> map_t;
typedef map_t::const_iterator mapCI_t;
typedef std::pair<int, Command*> pair_t;
typedef pair<int, Command*> pair_t;
class Commands
{
@@ -42,34 +44,34 @@ public:
void addCommand(const cmd_t& command);
void printCommands() const;
std::size_t sizeCmdDB() const { return m_cmdDB.size(); }
std::size_t sizeCycDB() const { return m_cycDB.size(); }
std::size_t sizePollDB() const { return m_pollDB.size(); }
std::size_t sizeScanDB() const { return m_scanDB.size(); }
size_t sizeCmdDB() const { return m_cmdDB.size(); }
size_t sizeCycDB() const { return m_cycDB.size(); }
size_t sizePollDB() const { return m_pollDB.size(); }
size_t sizeScanDB() const { return m_scanDB.size(); }
cmd_t const& operator[](const std::size_t& index) const { return m_cmdDB[index]; }
cmd_t const& operator[](const size_t& index) const { return m_cmdDB[index]; }
int findCommand(const std::string& data) const;
int findCommand(const string& data) const;
std::string getCmdType(const int index) const { return std::string(m_cmdDB.at(index)[0]); }
std::string getBusCommand(const int index) const;
string getCmdType(const int index) const { return string(m_cmdDB.at(index)[0]); }
string getBusCommand(const int index) const;
int storeCycData(const std::string& data) const;
std::string getCycData(int index) const;
int storeCycData(const string& data) const;
string getCycData(int index) const;
int nextPollCommand();
void storePollData(const std::string& data) const;
std::string getPollData(const int index) const;
void storePollData(const string& data) const;
string getPollData(const int index) const;
void storeScanData(const std::string& data);
std::string getScanData(const int index) const { return m_scanDB[index]; }
void storeScanData(const string& data);
string getScanData(const int index) const { return m_scanDB[index]; }
private:
cmdDB_t m_cmdDB;
map_t m_cycDB;
map_t m_pollDB;
size_t m_pollIndex;
std::vector<std::string> m_scanDB;
vector<string> m_scanDB;
void printCommand(const cmd_t& command) const;
+17 -15
View File
@@ -22,19 +22,21 @@
#include <fstream>
#include <dirent.h>
void ConfigFileCSV::parse(std::istream& is, Commands& commands)
using namespace std;
void ConfigFileCSV::parse(istream& is, Commands& commands)
{
std::string line;
string line;
// read lines
while (std::getline(is, line) != 0) {
while (getline(is, line) != 0) {
cmd_t row;
std::string column;
string column;
std::istringstream isstr(line);
istringstream isstr(line);
// walk through columns
while (std::getline(isstr, column, ';') != 0)
while (getline(isstr, column, ';') != 0)
row.push_back(column);
// skip empty and commented rows
@@ -46,7 +48,7 @@ void ConfigFileCSV::parse(std::istream& is, Commands& commands)
};
ConfigCommands::ConfigCommands(const std::string path, const FileType type)
ConfigCommands::ConfigCommands(const string path, const FileType type)
{
m_path = path;
m_configfile = NULL;
@@ -70,10 +72,10 @@ void ConfigCommands::setType(const FileType type)
Commands* ConfigCommands::getCommands()
{
Commands* commands = new Commands();
std::vector<std::string>::const_iterator i = m_files.begin();
vector<string>::const_iterator i = m_files.begin();
for(; i != m_files.end(); i++) {
std::fstream file((*i).c_str(), std::ios::in);
fstream file((*i).c_str(), ios::in);
if(file.is_open() == true) {
m_configfile->parse(file, *commands);
@@ -83,7 +85,7 @@ Commands* ConfigCommands::getCommands()
return commands;
};
void ConfigCommands::addFiles(const std::string path, const std::string extension)
void ConfigCommands::addFiles(const string path, const string extension)
{
DIR* dir = opendir(path.c_str());
@@ -95,18 +97,18 @@ void ConfigCommands::addFiles(const std::string path, const std::string extensio
while (d != NULL) {
if (d->d_type == DT_DIR) {
std::string fn = d->d_name;
string fn = d->d_name;
if (fn != "." && fn != "..") {
const std::string p = path + "/" + d->d_name;
const string p = path + "/" + d->d_name;
addFiles(p, extension);
}
} else if (d->d_type == DT_REG) {
std::string fn = d->d_name;
string fn = d->d_name;
if (fn.find(extension, (fn.length() - extension.length())) != std::string::npos) {
const std::string p = path + "/" + d->d_name;
if (fn.find(extension, (fn.length() - extension.length())) != string::npos) {
const string p = path + "/" + d->d_name;
m_files.push_back(p);
}
}
+16 -12
View File
@@ -24,9 +24,13 @@
#include <string>
#include <vector>
using namespace std;
/** \file configfile.h */
/** available file endings / types. */
enum FileType {
ft_csv
ft_csv /*!< CSV */
};
/**
@@ -46,12 +50,12 @@ public:
* @param is open input stream for reading.
* @param commands object as datastore.
*/
virtual void parse(std::istream& is, Commands& commands) = 0;
virtual void parse(istream& is, Commands& commands) = 0;
};
/**
* @brief class for CSV config files.
* @brief derived class for CSV config files.
*/
class ConfigFileCSV : public ConfigFile
{
@@ -67,12 +71,12 @@ public:
* @param is open input stream for reading.
* @param commands object as datastore.
*/
void parse(std::istream& is, Commands& commands);
void parse(istream& is, Commands& commands);
};
/**
* @brief class for class device.
* @brief class to parse configuration files and store into commands instance.
*/
class ConfigCommands
{
@@ -81,9 +85,9 @@ public:
/**
* @brief set file type and add recursive files from given path.
* @param path to configuration files.
* @param filetype to parse.
* @param type to parse.
*/
ConfigCommands(const std::string path, const FileType type);
ConfigCommands(const string path, const FileType type);
/**
* @brief destructor.
@@ -92,7 +96,7 @@ public:
/**
* @brief setter for file type.
* @param filetype of files.
* @param type of files.
*/
void setType(const FileType type);
@@ -107,20 +111,20 @@ private:
ConfigFile* m_configfile;
/** main path for configuration files */
std::string m_path;
string m_path;
/** valid file extension */
std::string m_extension;
string m_extension;
/** vector of configuration files */
std::vector<std::string> m_files;
vector<string> m_files;
/**
* @brief parse path for given file extension.
* @param path to configuration files.
* @param extension with file type.
*/
void addFiles(const std::string path, const std::string extension);
void addFiles(const string path, const string extension);
};
+80 -78
View File
@@ -26,19 +26,21 @@
#include <vector>
#include <cstring>
Decode::Decode(const std::string& data, const std::string& factor)
using namespace std;
Decode::Decode(const string& data, const string& factor)
: m_data(data)
{
if ((factor.find_first_not_of("0123456789.") == std::string::npos) == true)
if ((factor.find_first_not_of("0123456789.") == string::npos) == true)
m_factor = static_cast<float>(strtod(factor.c_str(), NULL));
else
m_factor = 1.0;
}
std::string DecodeHEX::decode()
string DecodeHEX::decode()
{
std::ostringstream result;
ostringstream result;
for (size_t i = 0; i < m_data.length()/2; i++)
result << m_data.substr(i*2, 2) << " ";
@@ -46,112 +48,112 @@ std::string DecodeHEX::decode()
return result.str().substr(0, result.str().length()-1);
}
std::string DecodeUCH::decode()
string DecodeUCH::decode()
{
std::stringstream ss;
ss << std::hex << m_data;
stringstream ss;
ss << hex << m_data;
unsigned short x;
ss >> x;
std::ostringstream result;
result << std::setprecision(3) << std::fixed << static_cast<float>(x * m_factor);
ostringstream result;
result << setprecision(3) << fixed << static_cast<float>(x * m_factor);
return result.str();
}
std::string DecodeSCH::decode()
string DecodeSCH::decode()
{
std::stringstream ss;
ss << std::hex << m_data;
stringstream ss;
ss << hex << m_data;
unsigned short x;
ss >> x;
std::ostringstream result;
ostringstream result;
if ((x & 0x80) == 0x80)
result << std::setprecision(3) << std::fixed
result << setprecision(3) << fixed
<< static_cast<float>(static_cast<short>(- ( ((unsigned char) (~ x)) + 1) ) * m_factor);
else
result << std::setprecision(3) << std::fixed
result << setprecision(3) << fixed
<< static_cast<float>(static_cast<short>(x) * m_factor);
return result.str();
}
std::string DecodeUIN::decode()
string DecodeUIN::decode()
{
std::stringstream ss;
ss << std::hex << m_data;
stringstream ss;
ss << hex << m_data;
unsigned short x;
ss >> x;
std::ostringstream result;
result << std::setprecision(3) << std::fixed << static_cast<float>(x * m_factor);
ostringstream result;
result << setprecision(3) << fixed << static_cast<float>(x * m_factor);
return result.str();
}
std::string DecodeSIN::decode()
string DecodeSIN::decode()
{
std::stringstream ss;
ss << std::hex << m_data;
stringstream ss;
ss << hex << m_data;
unsigned short x;
ss >> x;
std::ostringstream result;
result << std::setprecision(3) << std::fixed << static_cast<float>(static_cast<short>(x) * m_factor);
ostringstream result;
result << setprecision(3) << fixed << static_cast<float>(static_cast<short>(x) * m_factor);
return result.str();
}
std::string DecodeULG::decode()
string DecodeULG::decode()
{
std::stringstream ss;
ss << std::hex << m_data;
stringstream ss;
ss << hex << m_data;
unsigned int x;
ss >> x;
std::ostringstream result;
result << std::setprecision(3) << std::fixed << static_cast<float>(x * m_factor);
ostringstream result;
result << setprecision(3) << fixed << static_cast<float>(x * m_factor);
return result.str();
}
std::string DecodeSLG::decode()
string DecodeSLG::decode()
{
std::stringstream ss;
ss << std::hex << m_data;
stringstream ss;
ss << hex << m_data;
unsigned int x;
ss >> x;
std::ostringstream result;
result << std::setprecision(3) << std::fixed <<static_cast<float>(static_cast<int>(x) * m_factor);
ostringstream result;
result << setprecision(3) << fixed <<static_cast<float>(static_cast<int>(x) * m_factor);
return result.str();
}
std::string DecodeFLT::decode()
string DecodeFLT::decode()
{
std::stringstream ss;
ss << std::hex << m_data;
stringstream ss;
ss << hex << m_data;
short x;
ss >> x;
std::ostringstream result;
result << std::setprecision(3) << std::fixed << static_cast<float>(x / 1000.0 * m_factor);
ostringstream result;
result << setprecision(3) << fixed << static_cast<float>(x / 1000.0 * m_factor);
return result.str();
}
std::string DecodeSTR::decode()
string DecodeSTR::decode()
{
std::ostringstream result;
ostringstream result;
for (size_t i = 0; i <= m_data.length()/2; i++) {
char tmp = static_cast<char>(strtol(m_data.substr(i*2, 2).c_str(), NULL, 16));
@@ -162,9 +164,9 @@ std::string DecodeSTR::decode()
return result.str().substr(0, result.str().length()-1);
}
std::string DecodeBCD::decode()
string DecodeBCD::decode()
{
std::ostringstream result;
ostringstream result;
unsigned char src = strtol(m_data.c_str(), NULL, 16);
if ((src & 0x0F) > 0x09 || ((src >> 4) & 0x0F) > 0x09)
@@ -175,9 +177,9 @@ std::string DecodeBCD::decode()
return result.str();
}
std::string DecodeD1B::decode()
string DecodeD1B::decode()
{
std::ostringstream result;
ostringstream result;
unsigned char src = strtol(m_data.c_str(), NULL, 16);
if ((src & 0x80) == 0x80)
@@ -188,9 +190,9 @@ std::string DecodeD1B::decode()
return result.str();
}
std::string DecodeD1C::decode()
string DecodeD1C::decode()
{
std::ostringstream result;
ostringstream result;
unsigned char src = strtol(m_data.c_str(), NULL, 16);
if (src > 0xC8)
@@ -201,9 +203,9 @@ std::string DecodeD1C::decode()
return result.str();
}
std::string DecodeD2B::decode()
string DecodeD2B::decode()
{
std::ostringstream result;
ostringstream result;
unsigned char src_lsb = static_cast<char>(strtol(m_data.substr(0, 2).c_str(), NULL, 16));
unsigned char src_msb = static_cast<char>(strtol(m_data.substr(2, 2).c_str(), NULL, 16));
@@ -218,9 +220,9 @@ std::string DecodeD2B::decode()
return result.str();
}
std::string DecodeD2C::decode()
string DecodeD2C::decode()
{
std::ostringstream result;
ostringstream result;
unsigned char src_lsb = static_cast<char>(strtol(m_data.substr(0, 2).c_str(), NULL, 16));
unsigned char src_msb = static_cast<char>(strtol(m_data.substr(2, 2).c_str(), NULL, 16));
@@ -237,9 +239,9 @@ std::string DecodeD2C::decode()
return result.str();
}
std::string DecodeBDA::decode()
string DecodeBDA::decode()
{
std::ostringstream result;
ostringstream result;
Decode* decode;
short array[3];
for (int i = 0; i < 3; i++) {
@@ -248,30 +250,30 @@ std::string DecodeBDA::decode()
delete decode;
}
result << std::setw(2) << std::setfill('0') << array[0] << "."
<< std::setw(2) << std::setfill('0') << array[1] << "."
result << setw(2) << setfill('0') << array[0] << "."
<< setw(2) << setfill('0') << array[1] << "."
<< array[2] + 2000;
return result.str();
}
std::string DecodeHDA::decode()
string DecodeHDA::decode()
{
std::ostringstream result;
ostringstream result;
short dd = static_cast<short>(strtol(m_data.substr(0, 2).c_str(), NULL, 16));
short mm = static_cast<short>(strtol(m_data.substr(2, 2).c_str(), NULL, 16));
short yy = static_cast<short>(strtol(m_data.substr(4, 2).c_str(), NULL, 16));
result << std::setw(2) << std::setfill('0') << dd << "."
<< std::setw(2) << std::setfill('0') << mm << "."
result << setw(2) << setfill('0') << dd << "."
<< setw(2) << setfill('0') << mm << "."
<< yy + 2000;
return result.str();
}
std::string DecodeBTI::decode()
string DecodeBTI::decode()
{
std::ostringstream result;
ostringstream result;
Decode* decode;
short array[3];
for (int i = 0; i < 3; i++) {
@@ -280,32 +282,32 @@ std::string DecodeBTI::decode()
delete decode;
}
result << std::setw(2) << std::setfill('0') << array[0] << ":"
<< std::setw(2) << std::setfill('0') << array[1] << ":"
<< std::setw(2) << std::setfill('0') << array[2];
result << setw(2) << setfill('0') << array[0] << ":"
<< setw(2) << setfill('0') << array[1] << ":"
<< setw(2) << setfill('0') << array[2];
return result.str();
}
std::string DecodeHTI::decode()
string DecodeHTI::decode()
{
std::ostringstream result;
ostringstream result;
short hh = static_cast<short>(strtol(m_data.substr(0, 2).c_str(), NULL, 16));
short mm = static_cast<short>(strtol(m_data.substr(2, 2).c_str(), NULL, 16));
short ss = static_cast<short>(strtol(m_data.substr(4, 2).c_str(), NULL, 16));
result << std::setw(2) << std::setfill('0') << hh << ":"
<< std::setw(2) << std::setfill('0') << mm << ":"
<< std::setw(2) << std::setfill('0') << ss;
result << setw(2) << setfill('0') << hh << ":"
<< setw(2) << setfill('0') << mm << ":"
<< setw(2) << setfill('0') << ss;
return result.str();
}
std::string DecodeBDY::decode()
string DecodeBDY::decode()
{
const char *days[] = {"Mon", "Tue", "Wed", "Thu", "Fri", "Sat", "Sun", "Err"};
std::ostringstream result;
ostringstream result;
short day = static_cast<short>(strtol(m_data.c_str(), NULL, 16));
if (day < 0 || day > 6)
@@ -316,11 +318,11 @@ std::string DecodeBDY::decode()
return result.str();
}
std::string DecodeHDY::decode()
string DecodeHDY::decode()
{
const char *days[] = {"Mon", "Tue", "Wed", "Thu", "Fri", "Sat", "Sun", "Err"};
std::ostringstream result;
ostringstream result;
short day = static_cast<short>(strtol(m_data.c_str(), NULL, 16)) - 1;
if (day < 0 || day > 6)
@@ -331,14 +333,14 @@ std::string DecodeHDY::decode()
return result.str();
}
std::string DecodeTTM::decode()
string DecodeTTM::decode()
{
std::ostringstream result;
ostringstream result;
short hh = static_cast<short>(strtol(m_data.c_str(), NULL, 16)) / 6;
short mm = static_cast<short>(strtol(m_data.c_str(), NULL, 16)) % 6 * 10;
result << std::setw(2) << std::setfill('0') << hh << ":"
<< std::setw(2) << std::setfill('0') << mm;
result << setw(2) << setfill('0') << hh << ":"
<< setw(2) << setfill('0') << mm;
return result.str();
}
+47 -45
View File
@@ -22,17 +22,19 @@
#include <string>
using namespace std;
class Decode
{
public:
Decode(const std::string& data, const std::string& factor = "");
Decode(const string& data, const string& factor = "");
virtual ~Decode() {}
virtual std::string decode() = 0;
virtual string decode() = 0;
protected:
std::string m_data;
string m_data;
float m_factor;
};
@@ -42,10 +44,10 @@ class DecodeHEX : public Decode
{
public:
DecodeHEX(const std::string& data) : Decode(data) {}
DecodeHEX(const string& data) : Decode(data) {}
~DecodeHEX() {}
std::string decode();
string decode();
};
@@ -53,11 +55,11 @@ class DecodeUCH : public Decode
{
public:
DecodeUCH(const std::string& data, const std::string& factor)
DecodeUCH(const string& data, const string& factor)
: Decode(data, factor) {}
~DecodeUCH() {}
std::string decode();
string decode();
};
@@ -65,11 +67,11 @@ class DecodeSCH : public Decode
{
public:
DecodeSCH(const std::string& data, const std::string& factor)
DecodeSCH(const string& data, const string& factor)
: Decode(data, factor) {}
~DecodeSCH() {}
std::string decode();
string decode();
};
@@ -77,11 +79,11 @@ class DecodeUIN : public Decode
{
public:
DecodeUIN(const std::string& data, const std::string& factor)
DecodeUIN(const string& data, const string& factor)
: Decode(data, factor) {}
~DecodeUIN() {}
std::string decode();
string decode();
};
@@ -89,11 +91,11 @@ class DecodeSIN : public Decode
{
public:
DecodeSIN(const std::string& data, const std::string& factor)
DecodeSIN(const string& data, const string& factor)
: Decode(data, factor) {}
~DecodeSIN() {}
std::string decode();
string decode();
};
@@ -101,11 +103,11 @@ class DecodeULG : public Decode
{
public:
DecodeULG(const std::string& data, const std::string& factor)
DecodeULG(const string& data, const string& factor)
: Decode(data, factor) {}
~DecodeULG() {}
std::string decode();
string decode();
};
@@ -113,11 +115,11 @@ class DecodeSLG : public Decode
{
public:
DecodeSLG(const std::string& data, const std::string& factor)
DecodeSLG(const string& data, const string& factor)
: Decode(data, factor) {}
~DecodeSLG() {}
std::string decode();
string decode();
};
@@ -125,11 +127,11 @@ class DecodeFLT : public Decode
{
public:
DecodeFLT(const std::string& data, const std::string& factor)
DecodeFLT(const string& data, const string& factor)
: Decode(data, factor) {}
~DecodeFLT() {}
std::string decode();
string decode();
};
@@ -137,10 +139,10 @@ class DecodeSTR : public Decode
{
public:
DecodeSTR(std::string data) : Decode(data) {}
DecodeSTR(string data) : Decode(data) {}
~DecodeSTR() {}
std::string decode();
string decode();
};
@@ -148,11 +150,11 @@ class DecodeBCD : public Decode
{
public:
DecodeBCD(const std::string& data, const std::string& factor)
DecodeBCD(const string& data, const string& factor)
: Decode(data, factor) {}
~DecodeBCD() {}
std::string decode();
string decode();
};
@@ -160,11 +162,11 @@ class DecodeD1B : public Decode
{
public:
DecodeD1B(const std::string& data, const std::string& factor)
DecodeD1B(const string& data, const string& factor)
: Decode(data, factor) {}
~DecodeD1B() {}
std::string decode();
string decode();
};
@@ -172,11 +174,11 @@ class DecodeD1C : public Decode
{
public:
DecodeD1C(const std::string& data, const std::string& factor)
DecodeD1C(const string& data, const string& factor)
: Decode(data, factor) {}
~DecodeD1C() {}
std::string decode();
string decode();
};
@@ -184,11 +186,11 @@ class DecodeD2B : public Decode
{
public:
DecodeD2B(const std::string& data, const std::string& factor)
DecodeD2B(const string& data, const string& factor)
: Decode(data, factor) {}
~DecodeD2B() {}
std::string decode();
string decode();
};
@@ -196,11 +198,11 @@ class DecodeD2C : public Decode
{
public:
DecodeD2C(const std::string& data, const std::string& factor)
DecodeD2C(const string& data, const string& factor)
: Decode(data, factor) {}
~DecodeD2C() {}
std::string decode();
string decode();
};
@@ -208,10 +210,10 @@ class DecodeBDA : public Decode
{
public:
DecodeBDA(const std::string& data) : Decode(data) {}
DecodeBDA(const string& data) : Decode(data) {}
~DecodeBDA() {}
std::string decode();
string decode();
};
@@ -219,10 +221,10 @@ class DecodeHDA : public Decode
{
public:
DecodeHDA(const std::string& data) : Decode(data) {}
DecodeHDA(const string& data) : Decode(data) {}
~DecodeHDA() {}
std::string decode();
string decode();
};
@@ -230,10 +232,10 @@ class DecodeBTI : public Decode
{
public:
DecodeBTI(const std::string& data) : Decode(data) {}
DecodeBTI(const string& data) : Decode(data) {}
~DecodeBTI() {}
std::string decode();
string decode();
};
@@ -241,10 +243,10 @@ class DecodeHTI : public Decode
{
public:
DecodeHTI(const std::string& data) : Decode(data) {}
DecodeHTI(const string& data) : Decode(data) {}
~DecodeHTI() {}
std::string decode();
string decode();
};
@@ -252,10 +254,10 @@ class DecodeBDY : public Decode
{
public:
DecodeBDY(const std::string& data) : Decode(data) {}
DecodeBDY(const string& data) : Decode(data) {}
~DecodeBDY() {}
std::string decode();
string decode();
};
@@ -263,10 +265,10 @@ class DecodeHDY : public Decode
{
public:
DecodeHDY(const std::string& data) : Decode(data) {}
DecodeHDY(const string& data) : Decode(data) {}
~DecodeHDY() {}
std::string decode();
string decode();
};
@@ -274,10 +276,10 @@ class DecodeTTM : public Decode
{
public:
DecodeTTM(const std::string& data) : Decode(data) {}
DecodeTTM(const string& data) : Decode(data) {}
~DecodeTTM() {}
std::string decode();
string decode();
};
+104 -102
View File
@@ -26,158 +26,160 @@
#include <vector>
#include <cstring>
Encode::Encode(const std::string& data, const std::string& factor)
using namespace std;
Encode::Encode(const string& data, const string& factor)
: m_data(data)
{
if ((factor.find_first_not_of("0123456789.") == std::string::npos) == true)
if ((factor.find_first_not_of("0123456789.") == string::npos) == true)
m_factor = static_cast<float>(strtod(factor.c_str(), NULL));
else
m_factor = 1.0;
}
std::string EncodeHEX::encode()
string EncodeHEX::encode()
{
m_data.erase(std::remove_if(m_data.begin(), m_data.end(), isspace), m_data.end());
m_data.erase(remove_if(m_data.begin(), m_data.end(), ::isspace), m_data.end());
return m_data;
}
std::string EncodeUCH::encode()
string EncodeUCH::encode()
{
std::ostringstream result;
ostringstream result;
unsigned short src = static_cast<unsigned short>(strtod(m_data.c_str(), NULL) / m_factor);
result << std::setw(2) << std::hex << std::setfill('0') << src;
result << setw(2) << hex << setfill('0') << src;
return result.str().substr(result.str().length()-2,2);
}
std::string EncodeSCH::encode()
string EncodeSCH::encode()
{
std::ostringstream result;
ostringstream result;
short src = static_cast<short>(strtod(m_data.c_str(), NULL) / m_factor);
if (src < -127 || src > 127)
result << std::setw(2) << std::hex << std::setfill('0')
result << setw(2) << hex << setfill('0')
<< static_cast<unsigned>(0x80);
else
result << std::setw(2) << std::hex << std::setfill('0')
result << setw(2) << hex << setfill('0')
<< static_cast<unsigned>(src);
return result.str().substr(result.str().length()-2,2);
}
std::string EncodeUIN::encode()
string EncodeUIN::encode()
{
std::ostringstream result;
ostringstream result;
unsigned short src = static_cast<unsigned short>(strtod(m_data.c_str(), NULL) / m_factor);
result << std::setw(4) << std::hex << std::setfill('0') << src;
result << setw(4) << hex << setfill('0') << src;
return result.str().substr(2,2) + result.str().substr(0,2);
}
std::string EncodeSIN::encode()
string EncodeSIN::encode()
{
std::ostringstream result;
ostringstream result;
short src = static_cast<short>(strtod(m_data.c_str(), NULL) / m_factor);
result << std::setw(4) << std::hex << std::setfill('0') << src;
result << setw(4) << hex << setfill('0') << src;
return result.str().substr(2,2) + result.str().substr(0,2);
}
std::string EncodeULG::encode()
string EncodeULG::encode()
{
std::ostringstream result;
ostringstream result;
unsigned long src = static_cast<unsigned long>(strtod(m_data.c_str(), NULL) / m_factor);
result << std::setw(8) << std::hex << std::setfill('0') << src;
result << setw(8) << hex << setfill('0') << src;
return result.str().substr(6,2) + result.str().substr(4,2) +
result.str().substr(2,2) + result.str().substr(0,2);
}
std::string EncodeSLG::encode()
string EncodeSLG::encode()
{
std::ostringstream result;
ostringstream result;
int src = static_cast<int>(strtod(m_data.c_str(), NULL) / m_factor);
result << std::setw(8) << std::hex << std::setfill('0') << src;
result << setw(8) << hex << setfill('0') << src;
return result.str().substr(6,2) + result.str().substr(4,2) +
result.str().substr(2,2) + result.str().substr(0,2);
}
std::string EncodeFLT::encode()
string EncodeFLT::encode()
{
std::ostringstream result;
ostringstream result;
short src = static_cast<short>(strtod(m_data.c_str(), NULL) * 1000.0 / m_factor);
result << std::setw(4) << std::hex << std::setfill('0') << src;
result << setw(4) << hex << setfill('0') << src;
return result.str().substr(2,2) + result.str().substr(0,2);
}
std::string EncodeSTR::encode()
string EncodeSTR::encode()
{
std::ostringstream result;
ostringstream result;
for (size_t i = 0; i < m_data.length(); i++)
result << std::setw(2) << std::hex << std::setfill('0') << static_cast<short>(m_data[i]);
result << setw(2) << hex << setfill('0') << static_cast<short>(m_data[i]);
return result.str();
}
std::string EncodeBCD::encode()
string EncodeBCD::encode()
{
std::ostringstream result;
ostringstream result;
short src = static_cast<short>(strtod(m_data.c_str(), NULL) / m_factor);
if (src > 99)
result << std::setw(2) << std::hex << std::setfill('0')
result << setw(2) << hex << setfill('0')
<< static_cast<unsigned>(0xFF);
else
result << std::setw(2) << std::hex << std::setfill('0')
result << setw(2) << hex << setfill('0')
<< static_cast<unsigned>( ((src / 10) << 4) | (src % 10) );
return result.str().substr(result.str().length()-2,2);
}
std::string EncodeD1B::encode()
string EncodeD1B::encode()
{
std::ostringstream result;
ostringstream result;
short src = static_cast<short>(strtod(m_data.c_str(), NULL) / m_factor);
if (src < -127 || src > 127)
result << std::setw(2) << std::hex << std::setfill('0')
result << setw(2) << hex << setfill('0')
<< static_cast<unsigned>(0x80);
else
result << std::setw(2) << std::hex << std::setfill('0')
result << setw(2) << hex << setfill('0')
<< static_cast<unsigned>(src);
return result.str().substr(result.str().length()-2,2);
}
std::string EncodeD1C::encode()
string EncodeD1C::encode()
{
std::ostringstream result;
ostringstream result;
float src = static_cast<float>(strtod(m_data.c_str(), NULL) / m_factor);
if (src < 0.0 || src > 100.0)
result << std::setw(2) << std::hex << std::setfill('0')
result << setw(2) << hex << setfill('0')
<< static_cast<unsigned>(0xFF);
else
result << std::setw(2) << std::hex << std::setfill('0')
result << setw(2) << hex << setfill('0')
<< static_cast<unsigned>(src * 2.0);
return result.str();
}
std::string EncodeD2B::encode()
string EncodeD2B::encode()
{
std::ostringstream result;
ostringstream result;
float src = static_cast<float>(strtod(m_data.c_str(), NULL) / m_factor);
if (src < -127.999 || src > 127.999) {
result << std::setw(2) << std::hex << std::setfill('0')
result << setw(2) << hex << setfill('0')
<< static_cast<unsigned>(0x80)
<< std::setw(2) << std::hex << std::setfill('0')
<< setw(2) << hex << setfill('0')
<< static_cast<unsigned>(0x00);
} else {
unsigned char tgt_lsb = static_cast<unsigned>((src - ((short) src)) * 256.0);
@@ -188,24 +190,24 @@ std::string EncodeD2B::encode()
else
tgt_msb = static_cast<unsigned>((short) src);
result << std::setw(2) << std::hex << std::setfill('0')
result << setw(2) << hex << setfill('0')
<< static_cast<unsigned>(tgt_msb)
<< std::setw(2) << std::hex << std::setfill('0')
<< setw(2) << hex << setfill('0')
<< static_cast<unsigned>(tgt_lsb);
}
return result.str();
}
std::string EncodeD2C::encode()
string EncodeD2C::encode()
{
std::ostringstream result;
ostringstream result;
float src = static_cast<float>(strtod(m_data.c_str(), NULL) / m_factor);
if (src < -2047.999 || src > 2047.999) {
result << std::setw(2) << std::hex << std::setfill('0')
result << setw(2) << hex << setfill('0')
<< static_cast<unsigned>(0x80)
<< std::setw(2) << std::hex << std::setfill('0')
<< setw(2) << hex << setfill('0')
<< static_cast<unsigned>(0x00);
} else {
unsigned char tgt_lsb = static_cast<unsigned>(
@@ -219,100 +221,100 @@ std::string EncodeD2C::encode()
else
tgt_msb = static_cast<unsigned>((short) src / 16.0);
result << std::setw(2) << std::hex << std::setfill('0')
result << setw(2) << hex << setfill('0')
<< static_cast<unsigned>(tgt_msb)
<< std::setw(2) << std::hex << std::setfill('0')
<< setw(2) << hex << setfill('0')
<< static_cast<unsigned>(tgt_lsb);
}
return result.str();
}
std::string EncodeBDA::encode()
string EncodeBDA::encode()
{
// prepare data
std::string token;
std::istringstream stream(m_data);
std::vector<std::string> data;
string token;
istringstream stream(m_data);
vector<string> data;
while (std::getline(stream, token, '.') != 0)
while (getline(stream, token, '.') != 0)
data.push_back(token);
std::ostringstream result;
result << std::setw(2) << std::dec << std::setfill('0')
ostringstream result;
result << setw(2) << dec << setfill('0')
<< static_cast<short>(strtod(data[0].c_str(), NULL))
<< std::setw(2) << std::dec << std::setfill('0')
<< setw(2) << dec << setfill('0')
<< static_cast<short>(strtod(data[1].c_str(), NULL))
<< std::setw(2) << std::dec << std::setfill('0')
<< setw(2) << dec << setfill('0')
<< static_cast<short>(strtod(data[2].c_str(), NULL) - 2000);
return result.str();
}
std::string EncodeHDA::encode()
string EncodeHDA::encode()
{
// prepare data
std::string token;
std::istringstream stream(m_data);
std::vector<std::string> data;
string token;
istringstream stream(m_data);
vector<string> data;
while (std::getline(stream, token, '.') != 0)
while (getline(stream, token, '.') != 0)
data.push_back(token);
std::ostringstream result;
result << std::setw(2) << std::hex << std::setfill('0')
ostringstream result;
result << setw(2) << hex << setfill('0')
<< static_cast<short>(strtod(data[0].c_str(), NULL))
<< std::setw(2) << std::hex << std::setfill('0')
<< setw(2) << hex << setfill('0')
<< static_cast<short>(strtod(data[1].c_str(), NULL))
<< std::setw(2) << std::hex << std::setfill('0')
<< setw(2) << hex << setfill('0')
<< static_cast<short>(strtod(data[2].c_str(), NULL) - 2000);
return result.str();
}
std::string EncodeBTI::encode()
string EncodeBTI::encode()
{
// prepare data
std::string token;
std::istringstream stream(m_data);
std::vector<std::string> data;
string token;
istringstream stream(m_data);
vector<string> data;
while (std::getline(stream, token, ':') != 0)
while (getline(stream, token, ':') != 0)
data.push_back(token);
std::ostringstream result;
result << std::setw(2) << std::dec << std::setfill('0')
ostringstream result;
result << setw(2) << dec << setfill('0')
<< static_cast<short>(strtod(data[0].c_str(), NULL))
<< std::setw(2) << std::dec << std::setfill('0')
<< setw(2) << dec << setfill('0')
<< static_cast<short>(strtod(data[1].c_str(), NULL))
<< std::setw(2) << std::dec << std::setfill('0')
<< setw(2) << dec << setfill('0')
<< static_cast<short>(strtod(data[2].c_str(), NULL));
return result.str();
}
std::string EncodeHTI::encode()
string EncodeHTI::encode()
{
// prepare data
std::string token;
std::istringstream stream(m_data);
std::vector<std::string> data;
string token;
istringstream stream(m_data);
vector<string> data;
while (std::getline(stream, token, ':') != 0)
while (getline(stream, token, ':') != 0)
data.push_back(token);
std::ostringstream result;
result << std::setw(2) << std::hex << std::setfill('0')
ostringstream result;
result << setw(2) << hex << setfill('0')
<< static_cast<short>(strtod(data[0].c_str(), NULL))
<< std::setw(2) << std::hex << std::setfill('0')
<< setw(2) << hex << setfill('0')
<< static_cast<short>(strtod(data[1].c_str(), NULL))
<< std::setw(2) << std::hex << std::setfill('0')
<< setw(2) << hex << setfill('0')
<< static_cast<short>(strtod(data[2].c_str(), NULL));
return result.str();
}
std::string EncodeBDY::encode()
string EncodeBDY::encode()
{
const char *days[] = {"Mon", "Tue", "Wed", "Thu", "Fri", "Sat", "Sun", "Err"};
short day = 7;
@@ -321,13 +323,13 @@ std::string EncodeBDY::encode()
if (strcasecmp(days[i], m_data.c_str()) == 0)
day = i;
std::ostringstream result;
result << std::setw(2) << std::hex << std::setfill('0') << day;
ostringstream result;
result << setw(2) << hex << setfill('0') << day;
return result.str();
}
std::string EncodeHDY::encode()
string EncodeHDY::encode()
{
const char *days[] = {"Mon", "Tue", "Wed", "Thu", "Fri", "Sat", "Sun", "Err"};
short day = 8;
@@ -336,24 +338,24 @@ std::string EncodeHDY::encode()
if (strcasecmp(days[i], m_data.c_str()) == 0)
day = i + 1;
std::ostringstream result;
result << std::setw(2) << std::hex << std::setfill('0') << day;
ostringstream result;
result << setw(2) << hex << setfill('0') << day;
return result.str();
}
std::string EncodeTTM::encode()
string EncodeTTM::encode()
{
// prepare data
std::string token;
std::istringstream stream(m_data);
std::vector<std::string> data;
string token;
istringstream stream(m_data);
vector<string> data;
while (std::getline(stream, token, ':') != 0)
while (getline(stream, token, ':') != 0)
data.push_back(token);
std::ostringstream result;
result << std::setw(2) << std::hex << std::setfill('0')
ostringstream result;
result << setw(2) << hex << setfill('0')
<< static_cast<short>( (strtod(data[0].c_str(), NULL) * 6)
+ (strtod(data[1].c_str(), NULL) / 10) );
+47 -45
View File
@@ -22,17 +22,19 @@
#include <string>
using namespace std;
class Encode
{
public:
Encode(const std::string& data, const std::string& factor = "");
Encode(const string& data, const string& factor = "");
virtual ~Encode() {}
virtual std::string encode() = 0;
virtual string encode() = 0;
protected:
std::string m_data;
string m_data;
float m_factor;
};
@@ -42,10 +44,10 @@ class EncodeHEX : public Encode
{
public:
EncodeHEX(const std::string& data) : Encode(data) {}
EncodeHEX(const string& data) : Encode(data) {}
~EncodeHEX() {}
std::string encode();
string encode();
};
@@ -53,11 +55,11 @@ class EncodeUCH : public Encode
{
public:
EncodeUCH(const std::string& data, const std::string& factor)
EncodeUCH(const string& data, const string& factor)
: Encode(data, factor) {}
~EncodeUCH() {}
std::string encode();
string encode();
};
@@ -65,11 +67,11 @@ class EncodeSCH : public Encode
{
public:
EncodeSCH(const std::string& data, const std::string& factor)
EncodeSCH(const string& data, const string& factor)
: Encode(data, factor) {}
~EncodeSCH() {}
std::string encode();
string encode();
};
@@ -77,11 +79,11 @@ class EncodeUIN : public Encode
{
public:
EncodeUIN(const std::string& data, const std::string& factor)
EncodeUIN(const string& data, const string& factor)
: Encode(data, factor) {}
~EncodeUIN() {}
std::string encode();
string encode();
};
@@ -89,11 +91,11 @@ class EncodeSIN : public Encode
{
public:
EncodeSIN(const std::string& data, const std::string& factor)
EncodeSIN(const string& data, const string& factor)
: Encode(data, factor) {}
~EncodeSIN() {}
std::string encode();
string encode();
};
@@ -101,11 +103,11 @@ class EncodeULG : public Encode
{
public:
EncodeULG(const std::string& data, const std::string& factor)
EncodeULG(const string& data, const string& factor)
: Encode(data, factor) {}
~EncodeULG() {}
std::string encode();
string encode();
};
@@ -113,11 +115,11 @@ class EncodeSLG : public Encode
{
public:
EncodeSLG(const std::string& data, const std::string& factor)
EncodeSLG(const string& data, const string& factor)
: Encode(data, factor) {}
~EncodeSLG() {}
std::string encode();
string encode();
};
@@ -125,11 +127,11 @@ class EncodeFLT : public Encode
{
public:
EncodeFLT(const std::string& data, const std::string& factor)
EncodeFLT(const string& data, const string& factor)
: Encode(data, factor) {}
~EncodeFLT() {}
std::string encode();
string encode();
};
@@ -137,10 +139,10 @@ class EncodeSTR : public Encode
{
public:
EncodeSTR(const std::string& data) : Encode(data) {}
EncodeSTR(const string& data) : Encode(data) {}
~EncodeSTR() {}
std::string encode();
string encode();
};
@@ -148,11 +150,11 @@ class EncodeBCD : public Encode
{
public:
EncodeBCD(const std::string& data, const std::string& factor)
EncodeBCD(const string& data, const string& factor)
: Encode(data, factor) {}
~EncodeBCD() {}
std::string encode();
string encode();
};
@@ -160,11 +162,11 @@ class EncodeD1B : public Encode
{
public:
EncodeD1B(const std::string& data, const std::string& factor)
EncodeD1B(const string& data, const string& factor)
: Encode(data, factor) {}
~EncodeD1B() {}
std::string encode();
string encode();
};
@@ -172,11 +174,11 @@ class EncodeD1C : public Encode
{
public:
EncodeD1C(const std::string& data, const std::string& factor)
EncodeD1C(const string& data, const string& factor)
: Encode(data, factor) {}
~EncodeD1C() {}
std::string encode();
string encode();
};
@@ -184,11 +186,11 @@ class EncodeD2B : public Encode
{
public:
EncodeD2B(const std::string& data, const std::string& factor)
EncodeD2B(const string& data, const string& factor)
: Encode(data, factor) {}
~EncodeD2B() {}
std::string encode();
string encode();
};
@@ -196,11 +198,11 @@ class EncodeD2C : public Encode
{
public:
EncodeD2C(const std::string& data, const std::string& factor)
EncodeD2C(const string& data, const string& factor)
: Encode(data, factor) {}
~EncodeD2C() {}
std::string encode();
string encode();
};
@@ -208,10 +210,10 @@ class EncodeBDA : public Encode
{
public:
EncodeBDA(const std::string& data) : Encode(data) {}
EncodeBDA(const string& data) : Encode(data) {}
~EncodeBDA() {}
std::string encode();
string encode();
};
@@ -219,10 +221,10 @@ class EncodeHDA : public Encode
{
public:
EncodeHDA(const std::string& data) : Encode(data) {}
EncodeHDA(const string& data) : Encode(data) {}
~EncodeHDA() {}
std::string encode();
string encode();
};
@@ -230,10 +232,10 @@ class EncodeBTI : public Encode
{
public:
EncodeBTI(const std::string& data) : Encode(data) {}
EncodeBTI(const string& data) : Encode(data) {}
~EncodeBTI() {}
std::string encode();
string encode();
};
@@ -241,10 +243,10 @@ class EncodeHTI : public Encode
{
public:
EncodeHTI(const std::string& data) : Encode(data) {}
EncodeHTI(const string& data) : Encode(data) {}
~EncodeHTI() {}
std::string encode();
string encode();
};
@@ -252,10 +254,10 @@ class EncodeBDY : public Encode
{
public:
EncodeBDY(const std::string& data) : Encode(data) {}
EncodeBDY(const string& data) : Encode(data) {}
~EncodeBDY() {}
std::string encode();
string encode();
};
@@ -263,10 +265,10 @@ class EncodeHDY : public Encode
{
public:
EncodeHDY(const std::string& data) : Encode(data) {}
EncodeHDY(const string& data) : Encode(data) {}
~EncodeHDY() {}
std::string encode();
string encode();
};
@@ -274,10 +276,10 @@ class EncodeTTM : public Encode
{
public:
EncodeTTM(const std::string& data) : Encode(data) {}
EncodeTTM(const string& data) : Encode(data) {}
~EncodeTTM() {}
std::string encode();
string encode();
};
+5 -3
View File
@@ -33,6 +33,8 @@
#include <poll.h>
#endif
using namespace std;
bool Device::isOpen()
{
if (isValid() == false)
@@ -130,7 +132,7 @@ unsigned char Device::getByte()
}
void DeviceSerial::openDevice(const std::string deviceName, const bool noDeviceCheck)
void DeviceSerial::openDevice(const string deviceName, const bool noDeviceCheck)
{
m_noDeviceCheck = noDeviceCheck;
@@ -188,7 +190,7 @@ void DeviceSerial::closeDevice()
}
void DeviceNetwork::openDevice(const std::string deviceName, const bool noDeviceCheck)
void DeviceNetwork::openDevice(const string deviceName, const bool noDeviceCheck)
{
m_noDeviceCheck = noDeviceCheck;
@@ -245,7 +247,7 @@ void DeviceNetwork::closeDevice()
}
Port::Port(const std::string deviceName, const bool noDeviceCheck)
Port::Port(const string deviceName, const bool noDeviceCheck)
: m_deviceName(deviceName), m_noDeviceCheck(noDeviceCheck)
{
m_device = NULL;
+13 -9
View File
@@ -25,10 +25,14 @@
#include <termios.h>
#include <unistd.h>
using namespace std;
/** \file port.h */
/** available device types. */
enum DeviceType {
dt_serial,
dt_network,
dt_serial, /*!< serial device */
dt_network /*!< network device */
};
/** max bytes write to bus. */
@@ -60,7 +64,7 @@ public:
* @param deviceName to determine device type.
* @param noDeviceCheck en-/disable device check.
*/
virtual void openDevice(const std::string deviceName, const bool noDeviceCheck) = 0;
virtual void openDevice(const string deviceName, const bool noDeviceCheck) = 0;
/**
* @brief virtual close function for closing opened file descriptor
@@ -83,7 +87,7 @@ public:
/**
* @brief recvBytes read bytes from opened file descriptor.
* @param timeoutmax time for new input data [usec].
* @param timeout time for new input data [usec].
* @param maxCount max size of receive buffer.
* @return number of read bytes or -1 if an error has occured.
*/
@@ -112,7 +116,7 @@ protected:
bool m_noDeviceCheck;
/** queue for received bytes */
std::queue<unsigned char> m_recvBuffer;
queue<unsigned char> m_recvBuffer;
/** receive buffer */
unsigned char m_buffer[MAX_READ_SIZE];
@@ -143,7 +147,7 @@ public:
* @param deviceName to determine device type.
* @param noDeviceCheck en-/disable device check.
*/
void openDevice(const std::string deviceName, const bool noDeviceCheck);
void openDevice(const string deviceName, const bool noDeviceCheck);
/**
* @brief close function for closing opened file descriptor
@@ -173,7 +177,7 @@ public:
* @param deviceName to determine device type.
* @param noDeviceCheck en-/disable device check.
*/
void openDevice(const std::string deviceName, const bool noDeviceCheck);
void openDevice(const string deviceName, const bool noDeviceCheck);
/**
* @brief close opened file descriptor
@@ -196,7 +200,7 @@ public:
* @param deviceName to determine device type.
* @param noDeviceCheck en-/disable device check.
*/
Port(const std::string deviceName, const bool noDeviceCheck);
Port(const string deviceName, const bool noDeviceCheck);
/**
* @brief destructor.
@@ -251,7 +255,7 @@ public:
private:
/** the device name */
std::string m_deviceName;
string m_deviceName;
/** the device instance */
Device* m_device;
+20 -18
View File
@@ -25,22 +25,24 @@
#include <sstream>
#include <vector>
using namespace std;
// will be part of cfg csv class
void readCSV(std::istream& is, Commands& commands){
std::string line;
void readCSV(istream& is, Commands& commands){
string line;
// read lines
while (std::getline(is, line) != 0) {
std::vector<std::string> row;
std::string column;
while (getline(is, line) != 0) {
vector<string> row;
string column;
int count;
count = 0;
std::istringstream stream(line);
istringstream stream(line);
// walk through columns
while (std::getline(stream, column, ';') != 0) {
while (getline(stream, column, ';') != 0) {
row.push_back(column);
count++;
}
@@ -52,29 +54,29 @@ void readCSV(std::istream& is, Commands& commands){
int main()
{
Commands* commands = ConfigCommands("test", ft_csv).getCommands();
std::cout << "Commands: " << commands->sizeCmdDB() << std::endl;
cout << "Commands: " << commands->sizeCmdDB() << endl;
//~ std::string data("g ci password pin1");
std::string data("s vwxmk DesiredTemp");
//~ string data("g ci password pin1");
string data("s vwxmk DesiredTemp");
int index = commands->findCommand(data);
std::cout << "found at index: " << index << std::endl;
cout << "found at index: " << index << endl;
// prepare data
std::string token;
std::istringstream stream(data);
std::vector<std::string> cmd;
string token;
istringstream stream(data);
vector<string> cmd;
// split stream
while (std::getline(stream, token, ' ') != 0)
while (getline(stream, token, ' ') != 0)
cmd.push_back(token);
//~ Command* command = new Command(index, (*commands)[index], "ff15b509030d2c0035000401000000cf00");
Command* command = new Command(index, (*commands)[index], "19.0");
//~ std::string result = command->calcResult(cmd);
std::string result = command->calcData();
std::cout << "result: " << result << std::endl;
//~ string result = command->calcResult(cmd);
string result = command->calcData();
cout << "result: " << result << endl;
delete command;
+5 -3
View File
@@ -24,18 +24,20 @@
#include <sstream>
#include <vector>
using namespace std;
int main() {
std::string dir("test");
string dir("test");
ConfigCommands config(dir, ft_csv);
Commands* commands = config.getCommands();
std::cout << "size: " << commands->sizeCmdDB() << std::endl;
cout << "size: " << commands->sizeCmdDB() << endl;
commands->findCommand("g ci Password");
std::cout << (*commands)[0][0] << std::endl;
cout << (*commands)[0][0] << endl;
delete commands;
+45 -43
View File
@@ -21,23 +21,25 @@
#include <iostream>
#include <iomanip>
using namespace std;
int main()
{
Decode* help_dec = NULL;
std::cout << std::endl;
cout << endl;
// HEX
{
const char* hex[] = {"53706569636865722020"};
for (size_t i = 0; i < sizeof(hex)/sizeof(hex[0]); i++) {
help_dec = new DecodeHEX(hex[i]);
std::cout << "DecodeHEX: " << std::setw(20) << hex[i] << " = " << help_dec->decode() << std::endl;
cout << "DecodeHEX: " << setw(20) << hex[i] << " = " << help_dec->decode() << endl;
delete help_dec;
}
std::cout << std::endl;
cout << endl;
}
// UCH
@@ -45,12 +47,12 @@ int main()
const char* uch[] = {"00", "01", "7f", "80", "fe", "ff", "a1"};
for (size_t i = 0; i < sizeof(uch)/sizeof(uch[0]); i++) {
help_dec = new DecodeUCH(uch[i], "1.0");
std::cout << "DecodeUCH: " << std::setw(20) << uch[i] << " = " << help_dec->decode() << std::endl;
cout << "DecodeUCH: " << setw(20) << uch[i] << " = " << help_dec->decode() << endl;
delete help_dec;
}
std::cout << std::endl;
cout << endl;
}
// SCH
@@ -58,12 +60,12 @@ int main()
const char* sch[] = {"00", "01", "7f", "80", "fe", "ff", "a1"};
for (size_t i = 0; i < sizeof(sch)/sizeof(sch[0]); i++) {
help_dec = new DecodeSCH(sch[i], "1.0");
std::cout << "DecodeSCH: " << std::setw(20) << sch[i] << " = " << help_dec->decode() << std::endl;
cout << "DecodeSCH: " << setw(20) << sch[i] << " = " << help_dec->decode() << endl;
delete help_dec;
}
std::cout << std::endl;
cout << endl;
}
// UIN
@@ -71,12 +73,12 @@ int main()
const char* uin[] = {"0000", "0001", "7fff", "8000", "fffe", "ffff", "a1b2"};
for (size_t i = 0; i < sizeof(uin)/sizeof(uin[0]); i++) {
help_dec = new DecodeUIN(uin[i], "1.0");
std::cout << "DecodeUIN: " << std::setw(20) << uin[i] << " = " << help_dec->decode() << std::endl;
cout << "DecodeUIN: " << setw(20) << uin[i] << " = " << help_dec->decode() << endl;
delete help_dec;
}
std::cout << std::endl;
cout << endl;
}
// SIN
@@ -84,12 +86,12 @@ int main()
const char* sin[] = {"0000", "0001", "7fff", "8000", "fffe", "ffff", "a1b2"};
for (size_t i = 0; i < sizeof(sin)/sizeof(sin[0]); i++) {
help_dec = new DecodeSIN(sin[i], "1.0");
std::cout << "DecodeSIN: " << std::setw(20) << sin[i] << " = " << help_dec->decode() << std::endl;
cout << "DecodeSIN: " << setw(20) << sin[i] << " = " << help_dec->decode() << endl;
delete help_dec;
}
std::cout << std::endl;
cout << endl;
}
// ULG
@@ -97,12 +99,12 @@ int main()
const char* ulg[] = {"00000000", "00000001", "7fffffff", "80000000", "fffffffe", "ffffffff", "a1b2c3d4"};
for (size_t i = 0; i < sizeof(ulg)/sizeof(ulg[0]); i++) {
help_dec = new DecodeULG(ulg[i], "1.0");
std::cout << "DecodeULG: " << std::setw(20) << ulg[i] << " = " << help_dec->decode() << std::endl;
cout << "DecodeULG: " << setw(20) << ulg[i] << " = " << help_dec->decode() << endl;
delete help_dec;
}
std::cout << std::endl;
cout << endl;
}
// SLG
@@ -110,12 +112,12 @@ int main()
const char* slg[] = {"00000000", "00000001", "7fffffff", "80000000", "fffffffe", "ffffffff", "a1b2c3d4"};
for (size_t i = 0; i < sizeof(slg)/sizeof(slg[0]); i++) {
help_dec = new DecodeSLG(slg[i], "1.0");
std::cout << "DecodeSLG: " << std::setw(20) << slg[i] << " = " << help_dec->decode() << std::endl;
cout << "DecodeSLG: " << setw(20) << slg[i] << " = " << help_dec->decode() << endl;
delete help_dec;
}
std::cout << std::endl;
cout << endl;
}
// FLT
@@ -123,12 +125,12 @@ int main()
const char* flt[] = {"0000", "081b", "2532", "2689", "0851"};
for (size_t i = 0; i < sizeof(flt)/sizeof(flt[0]); i++) {
help_dec = new DecodeFLT(flt[i], "1.0");
std::cout << "DecodeFLT: " << std::setw(20) << flt[i] << " = " << help_dec->decode() << std::endl;
cout << "DecodeFLT: " << setw(20) << flt[i] << " = " << help_dec->decode() << endl;
delete help_dec;
}
std::cout << std::endl;
cout << endl;
}
// STR
@@ -136,12 +138,12 @@ int main()
const char* str[] = {"53706569636865722020", "5644363030" };
for (size_t i = 0; i < sizeof(str)/sizeof(str[0]); i++) {
help_dec = new DecodeSTR(str[i]);
std::cout << "DecodeSTR: " << std::setw(20) << str[i] << " = " << help_dec->decode() << std::endl;
cout << "DecodeSTR: " << setw(20) << str[i] << " = " << help_dec->decode() << endl;
delete help_dec;
}
std::cout << std::endl;
cout << endl;
}
// BCD
@@ -149,12 +151,12 @@ int main()
const char* bcd[] = {"00", "01", "02", "03", "12", "99"};
for (size_t i = 0; i < sizeof(bcd)/sizeof(bcd[0]); i++) {
help_dec = new DecodeBCD(bcd[i], "1.0");
std::cout << "DecodeBCD: " << std::setw(20) << bcd[i] << " = " << help_dec->decode() << std::endl;
cout << "DecodeBCD: " << setw(20) << bcd[i] << " = " << help_dec->decode() << endl;
delete help_dec;
}
std::cout << std::endl;
cout << endl;
}
// D1B
@@ -162,12 +164,12 @@ int main()
const char* d1b[] = {"00", "01", "7f", "81", "80"};
for (size_t i = 0; i < sizeof(d1b)/sizeof(d1b[0]); i++) {
help_dec = new DecodeD1B(d1b[i], "1.0");
std::cout << "DecodeD1B: " << std::setw(20) << d1b[i] << " = " << help_dec->decode() << std::endl;
cout << "DecodeD1B: " << setw(20) << d1b[i] << " = " << help_dec->decode() << endl;
delete help_dec;
}
std::cout << std::endl;
cout << endl;
}
// D1C
@@ -175,12 +177,12 @@ int main()
const char* d1c[] = {"00", "64", "c8"};
for (size_t i = 0; i < sizeof(d1c)/sizeof(d1c[0]); i++) {
help_dec = new DecodeD1C(d1c[i], "1.0");
std::cout << "DecodeD1C: " << std::setw(20) << d1c[i] << " = " << help_dec->decode() << std::endl;
cout << "DecodeD1C: " << setw(20) << d1c[i] << " = " << help_dec->decode() << endl;
delete help_dec;
}
std::cout << std::endl;
cout << endl;
}
// D2B
@@ -188,12 +190,12 @@ int main()
const char* d2b[] = {"0000", "0100", "ffff", "00ff", "0080", "0180", "ff7f"};
for (size_t i = 0; i < sizeof(d2b)/sizeof(d2b[0]); i++) {
help_dec = new DecodeD2B(d2b[i], "1.0");
std::cout << "DecodeD2B: " << std::setw(20) << d2b[i] << " = " << help_dec->decode() << std::endl;
cout << "DecodeD2B: " << setw(20) << d2b[i] << " = " << help_dec->decode() << endl;
delete help_dec;
}
std::cout << std::endl;
cout << endl;
}
// D2C
@@ -201,12 +203,12 @@ int main()
const char* d2c[] = {"0000", "0100", "ffff", "f0ff", "0080", "0180", "ff7f"};
for (size_t i = 0; i < sizeof(d2c)/sizeof(d2c[0]); i++) {
help_dec = new DecodeD2C(d2c[i], "1.0");
std::cout << "DecodeD2C: " << std::setw(20) << d2c[i] << " = " << help_dec->decode() << std::endl;
cout << "DecodeD2C: " << setw(20) << d2c[i] << " = " << help_dec->decode() << endl;
delete help_dec;
}
std::cout << std::endl;
cout << endl;
}
// BDA
@@ -214,12 +216,12 @@ int main()
const char* bda[] = {"171113", "220901"};
for (size_t i = 0; i < sizeof(bda)/sizeof(bda[0]); i++) {
help_dec = new DecodeBDA(bda[i]);
std::cout << "DecodeBDA: " << std::setw(20) << bda[i] << " = " << help_dec->decode() << std::endl;
cout << "DecodeBDA: " << setw(20) << bda[i] << " = " << help_dec->decode() << endl;
delete help_dec;
}
std::cout << std::endl;
cout << endl;
}
// HDA
@@ -227,12 +229,12 @@ int main()
const char* hda[] = {"010101", "1f0c1b"};
for (size_t i = 0; i < sizeof(hda)/sizeof(hda[0]); i++) {
help_dec = new DecodeHDA(hda[i]);
std::cout << "DecodeHDA: " << std::setw(20) << hda[i] << " = " << help_dec->decode() << std::endl;
cout << "DecodeHDA: " << setw(20) << hda[i] << " = " << help_dec->decode() << endl;
delete help_dec;
}
std::cout << std::endl;
cout << endl;
}
// BTI
@@ -240,12 +242,12 @@ int main()
const char* bti[] = {"010101", "174209", "235959"};
for (size_t i = 0; i < sizeof(bti)/sizeof(bti[0]); i++) {
help_dec = new DecodeBTI(bti[i]);
std::cout << "DecodeBTI: " << std::setw(20) << bti[i] << " = " << help_dec->decode() << std::endl;
cout << "DecodeBTI: " << setw(20) << bti[i] << " = " << help_dec->decode() << endl;
delete help_dec;
}
std::cout << std::endl;
cout << endl;
}
// HTI
@@ -253,12 +255,12 @@ int main()
const char* hti[] = {"010101", "112a09", "173b3b"};
for (size_t i = 0; i < sizeof(hti)/sizeof(hti[0]); i++) {
help_dec = new DecodeHTI(hti[i]);
std::cout << "DecodeHTI: " << std::setw(20) << hti[i] << " = " << help_dec->decode() << std::endl;
cout << "DecodeHTI: " << setw(20) << hti[i] << " = " << help_dec->decode() << endl;
delete help_dec;
}
std::cout << std::endl;
cout << endl;
}
// BDY
@@ -266,12 +268,12 @@ int main()
const char* bdy[] = {"01", "03", "06", "07"};
for (size_t i = 0; i < sizeof(bdy)/sizeof(bdy[0]); i++) {
help_dec = new DecodeBDY(bdy[i]);
std::cout << "DecodeBDY: " << std::setw(20) << bdy[i] << " = " << help_dec->decode() << std::endl;
cout << "DecodeBDY: " << setw(20) << bdy[i] << " = " << help_dec->decode() << endl;
delete help_dec;
}
std::cout << std::endl;
cout << endl;
}
// HDY
@@ -279,12 +281,12 @@ int main()
const char* hdy[] = {"01", "03", "07", "08"};
for (size_t i = 0; i < sizeof(hdy)/sizeof(hdy[0]); i++) {
help_dec = new DecodeHDY(hdy[i]);
std::cout << "DecodeHDY: " << std::setw(20) << hdy[i] << " = " << help_dec->decode() << std::endl;
cout << "DecodeHDY: " << setw(20) << hdy[i] << " = " << help_dec->decode() << endl;
delete help_dec;
}
std::cout << std::endl;
cout << endl;
}
// TTM
@@ -292,12 +294,12 @@ int main()
const char* ttm[] = {"00", "23", "4f", "90"};
for (size_t i = 0; i < sizeof(ttm)/sizeof(ttm[0]); i++) {
help_dec = new DecodeTTM(ttm[i]);
std::cout << "DecodeTTM: " << std::setw(20) << ttm[i] << " = " << help_dec->decode() << std::endl;
cout << "DecodeTTM: " << setw(20) << ttm[i] << " = " << help_dec->decode() << endl;
delete help_dec;
}
std::cout << std::endl;
cout << endl;
}
return 0;
+45 -43
View File
@@ -21,23 +21,25 @@
#include <iostream>
#include <iomanip>
using namespace std;
int main()
{
Encode* help_enc = NULL;
std::cout << std::endl;
cout << endl;
// HEX
{
const char* hex[] = {"53 70 65 69 63 68 65 72 20 20"};
for (size_t i = 0; i < sizeof(hex)/sizeof(hex[0]); i++) {
help_enc = new EncodeHEX(hex[i]);
std::cout << "EncodeHEX: " << std::setw(20) << hex[i] << " = " << help_enc->encode() << std::endl;
cout << "EncodeHEX: " << setw(20) << hex[i] << " = " << help_enc->encode() << endl;
delete help_enc;
}
std::cout << std::endl;
cout << endl;
}
// UCH
@@ -45,12 +47,12 @@ int main()
const char* uch[] = {"0", "1", "127", "128", "254", "255", "161"};
for (size_t i = 0; i < sizeof(uch)/sizeof(uch[0]); i++) {
help_enc = new EncodeUCH(uch[i], "1.0");
std::cout << "EncodeUCH: " << std::setw(20) << uch[i] << " = " << help_enc->encode() << std::endl;
cout << "EncodeUCH: " << setw(20) << uch[i] << " = " << help_enc->encode() << endl;
delete help_enc;
}
std::cout << std::endl;
cout << endl;
}
// SCH
@@ -58,12 +60,12 @@ int main()
const char* sch[] = {"0", "1", "127", "-128", "-2", "-1", "-95"};
for (size_t i = 0; i < sizeof(sch)/sizeof(sch[0]); i++) {
help_enc = new EncodeSCH(sch[i], "1.0");
std::cout << "EncodeSCH: " << std::setw(20) << sch[i] << " = " << help_enc->encode() << std::endl;
cout << "EncodeSCH: " << setw(20) << sch[i] << " = " << help_enc->encode() << endl;
delete help_enc;
}
std::cout << std::endl;
cout << endl;
}
// UIN
@@ -71,12 +73,12 @@ int main()
const char* uin[] = {"0", "1", "32767", "32768", "65534", "65535", "41394"};
for (size_t i = 0; i < sizeof(uin)/sizeof(uin[0]); i++) {
help_enc = new EncodeUIN(uin[i], "1.0");
std::cout << "EncodeUIN: " << std::setw(20) << uin[i] << " = " << help_enc->encode() << std::endl;
cout << "EncodeUIN: " << setw(20) << uin[i] << " = " << help_enc->encode() << endl;
delete help_enc;
}
std::cout << std::endl;
cout << endl;
}
// SIN
@@ -84,12 +86,12 @@ int main()
const char* sin[] = {"0", "1", "32767", "-32768", "-2", "-1", "-24142"};
for (size_t i = 0; i < sizeof(sin)/sizeof(sin[0]); i++) {
help_enc = new EncodeSIN(sin[i], "1.0");
std::cout << "EncodeSIN: " << std::setw(20) << sin[i] << " = " << help_enc->encode() << std::endl;
cout << "EncodeSIN: " << setw(20) << sin[i] << " = " << help_enc->encode() << endl;
delete help_enc;
}
std::cout << std::endl;
cout << endl;
}
// ULG
@@ -97,12 +99,12 @@ int main()
const char* ulg[] = {"0", "1", "2147483647", "2147483648", "4294967294", "4294967295", "2712847316"};
for (size_t i = 0; i < sizeof(ulg)/sizeof(ulg[0]); i++) {
help_enc = new EncodeULG(ulg[i], "1.0");
std::cout << "EncodeULG: " << std::setw(20) << ulg[i] << " = " << help_enc->encode() << std::endl;
cout << "EncodeULG: " << setw(20) << ulg[i] << " = " << help_enc->encode() << endl;
delete help_enc;
}
std::cout << std::endl;
cout << endl;
}
// SLG
@@ -110,12 +112,12 @@ int main()
const char* slg[] = {"0", "1", "2147483647", "-2147483648", "-2", "-1", "-1582119980"};
for (size_t i = 0; i < sizeof(slg)/sizeof(slg[0]); i++) {
help_enc = new EncodeSLG(slg[i], "1.0");
std::cout << "EncodeSLG: " << std::setw(20) << slg[i] << " = " << help_enc->encode() << std::endl;
cout << "EncodeSLG: " << setw(20) << slg[i] << " = " << help_enc->encode() << endl;
delete help_enc;
}
std::cout << std::endl;
cout << endl;
}
// FLT
@@ -123,12 +125,12 @@ int main()
const char* flt[] = {"0.000", "2.075", "9.522", "9.865", "2.129"};
for (size_t i = 0; i < sizeof(flt)/sizeof(flt[0]); i++) {
help_enc = new EncodeFLT(flt[i], "1.0");
std::cout << "EncodeFLT: " << std::setw(20) << flt[i] << " = " << help_enc->encode() << std::endl;
cout << "EncodeFLT: " << setw(20) << flt[i] << " = " << help_enc->encode() << endl;
delete help_enc;
}
std::cout << std::endl;
cout << endl;
}
// STR
@@ -136,12 +138,12 @@ int main()
const char* str[] = {"Speicher ", "VD600" };
for (size_t i = 0; i < sizeof(str)/sizeof(str[0]); i++) {
help_enc = new EncodeSTR(str[i]);
std::cout << "EncodeSTR: " << std::setw(20) << str[i] << " = " << help_enc->encode() << std::endl;
cout << "EncodeSTR: " << setw(20) << str[i] << " = " << help_enc->encode() << endl;
delete help_enc;
}
std::cout << std::endl;
cout << endl;
}
// BCD
@@ -149,12 +151,12 @@ int main()
const char* bcd[] = {"0", "1", "2", "3", "12", "99"};
for (size_t i = 0; i < sizeof(bcd)/sizeof(bcd[0]); i++) {
help_enc = new EncodeBCD(bcd[i], "1.0");
std::cout << "EncodeBCD: " << std::setw(20) << bcd[i] << " = " << help_enc->encode() << std::endl;
cout << "EncodeBCD: " << setw(20) << bcd[i] << " = " << help_enc->encode() << endl;
delete help_enc;
}
std::cout << std::endl;
cout << endl;
}
// D1B
@@ -162,12 +164,12 @@ int main()
const char* d1b[] = {"00", "01", "127", "-127", "-128"};
for (size_t i = 0; i < sizeof(d1b)/sizeof(d1b[0]); i++) {
help_enc = new EncodeD1B(d1b[i], "1.0");
std::cout << "EncodeD1B: " << std::setw(20) << d1b[i] << " = " << help_enc->encode() << std::endl;
cout << "EncodeD1B: " << setw(20) << d1b[i] << " = " << help_enc->encode() << endl;
delete help_enc;
}
std::cout << std::endl;
cout << endl;
}
// D1C
@@ -175,12 +177,12 @@ int main()
const char* d1c[] = {"0", "50", "100"};
for (size_t i = 0; i < sizeof(d1c)/sizeof(d1c[0]); i++) {
help_enc = new EncodeD1C(d1c[i], "1.0");
std::cout << "EncodeD1C: " << std::setw(20) << d1c[i] << " = " << help_enc->encode() << std::endl;
cout << "EncodeD1C: " << setw(20) << d1c[i] << " = " << help_enc->encode() << endl;
delete help_enc;
}
std::cout << std::endl;
cout << endl;
}
// D2B
@@ -188,12 +190,12 @@ int main()
const char* d2b[] = {"0", "0.00390625", "-0.00390625", "-1", "-128", "-127.99609375", "127.99609375"};
for (size_t i = 0; i < sizeof(d2b)/sizeof(d2b[0]); i++) {
help_enc = new EncodeD2B(d2b[i], "1.0");
std::cout << "EncodeD2B: " << std::setw(20) << d2b[i] << " = " << help_enc->encode() << std::endl;
cout << "EncodeD2B: " << setw(20) << d2b[i] << " = " << help_enc->encode() << endl;
delete help_enc;
}
std::cout << std::endl;
cout << endl;
}
// D2C
@@ -201,12 +203,12 @@ int main()
const char* d2c[] = {"0", "0.0625", "-0.0625", "-1", "-2048", "-2047.9375", "2047.9375"};
for (size_t i = 0; i < sizeof(d2c)/sizeof(d2c[0]); i++) {
help_enc = new EncodeD2C(d2c[i], "1.0");
std::cout << "EncodeD2C: " << std::setw(20) << d2c[i] << " = " << help_enc->encode() << std::endl;
cout << "EncodeD2C: " << setw(20) << d2c[i] << " = " << help_enc->encode() << endl;
delete help_enc;
}
std::cout << std::endl;
cout << endl;
}
// BDA
@@ -214,12 +216,12 @@ int main()
const char* bda[] = {"17.11.2013", "22.09.2001"};
for (size_t i = 0; i < sizeof(bda)/sizeof(bda[0]); i++) {
help_enc = new EncodeBDA(bda[i]);
std::cout << "EncodeBDA: " << std::setw(20) << bda[i] << " = " << help_enc->encode() << std::endl;
cout << "EncodeBDA: " << setw(20) << bda[i] << " = " << help_enc->encode() << endl;
delete help_enc;
}
std::cout << std::endl;
cout << endl;
}
// HDA
@@ -227,12 +229,12 @@ int main()
const char* hda[] = {"01.01.2001", "31.12.2027"};
for (size_t i = 0; i < sizeof(hda)/sizeof(hda[0]); i++) {
help_enc = new EncodeHDA(hda[i]);
std::cout << "EncodeHDA: " << std::setw(20) << hda[i] << " = " << help_enc->encode() << std::endl;
cout << "EncodeHDA: " << setw(20) << hda[i] << " = " << help_enc->encode() << endl;
delete help_enc;
}
std::cout << std::endl;
cout << endl;
}
// BTI
@@ -240,12 +242,12 @@ int main()
const char* bti[] = {"01:01:01", "17:42:09", "23:59:59"};
for (size_t i = 0; i < sizeof(bti)/sizeof(bti[0]); i++) {
help_enc = new EncodeBTI(bti[i]);
std::cout << "EncodeBTI: " << std::setw(20) << bti[i] << " = " << help_enc->encode() << std::endl;
cout << "EncodeBTI: " << setw(20) << bti[i] << " = " << help_enc->encode() << endl;
delete help_enc;
}
std::cout << std::endl;
cout << endl;
}
// HTI
@@ -253,12 +255,12 @@ int main()
const char* hti[] = {"01:01:01", "17:42:09", "23:59:59"};
for (size_t i = 0; i < sizeof(hti)/sizeof(hti[0]); i++) {
help_enc = new EncodeHTI(hti[i]);
std::cout << "EncodeHTI: " << std::setw(20) << hti[i] << " = " << help_enc->encode() << std::endl;
cout << "EncodeHTI: " << setw(20) << hti[i] << " = " << help_enc->encode() << endl;
delete help_enc;
}
std::cout << std::endl;
cout << endl;
}
// BDY
@@ -266,12 +268,12 @@ int main()
const char* bdy[] = {"Tue", "Thu", "Sun", "Err"};
for (size_t i = 0; i < sizeof(bdy)/sizeof(bdy[0]); i++) {
help_enc = new EncodeBDY(bdy[i]);
std::cout << "EncodeBDY: " << std::setw(20) << bdy[i] << " = " << help_enc->encode() << std::endl;
cout << "EncodeBDY: " << setw(20) << bdy[i] << " = " << help_enc->encode() << endl;
delete help_enc;
}
std::cout << std::endl;
cout << endl;
}
@@ -280,12 +282,12 @@ int main()
const char* hdy[] = {"Mon", "Wed", "Sun", "Err"};
for (size_t i = 0; i < sizeof(hdy)/sizeof(hdy[0]); i++) {
help_enc = new EncodeHDY(hdy[i]);
std::cout << "EncodeHDY: " << std::setw(20) << hdy[i] << " = " << help_enc->encode() << std::endl;
cout << "EncodeHDY: " << setw(20) << hdy[i] << " = " << help_enc->encode() << endl;
delete help_enc;
}
std::cout << std::endl;
cout << endl;
}
// TTM
@@ -293,12 +295,12 @@ int main()
const char* ttm[] = {"00:00", "05:50", "13:10", "24:00"};
for (size_t i = 0; i < sizeof(ttm)/sizeof(ttm[0]); i++) {
help_enc = new EncodeTTM(ttm[i]);
std::cout << "EncodeTTM: " << std::setw(20) << ttm[i] << " = " << help_enc->encode() << std::endl;
cout << "EncodeTTM: " << setw(20) << ttm[i] << " = " << help_enc->encode() << endl;
delete help_enc;
}
std::cout << std::endl;
cout << endl;
}
return 0;
+7 -5
View File
@@ -21,15 +21,17 @@
#include <iostream>
#include <iomanip>
using namespace std;
int main ()
{
std::string dev("/dev/ttyUSB20");
string dev("/dev/ttyUSB20");
Port port(dev, true);
port.open();
if(port.isOpen() == true)
std::cout << "openPort successful." << std::endl;
cout << "openPort successful." << endl;
int count = 0;
@@ -40,8 +42,8 @@ int main ()
for (int i = 0; i < bytes_read; i++)
byte = port.byte();
std::cout << std::hex << std::setw(2) << std::setfill('0')
<< static_cast<unsigned>(byte) << std::endl;
cout << hex << setw(2) << setfill('0')
<< static_cast<unsigned>(byte) << endl;
bytes_read = 0;
@@ -51,7 +53,7 @@ int main ()
port.close();
if(port.isOpen() == false)
std::cout << "closePort successful." << std::endl;
cout << "closePort successful." << endl;
return 0;