code style

This commit is contained in:
john30
2017-01-14 17:34:02 +01:00
parent 774e01e937
commit 0217096b6b
22 changed files with 132 additions and 120 deletions
+3 -3
View File
@@ -320,7 +320,7 @@ void BusHandler::run() {
} }
result_t BusHandler::handleSymbol() { result_t BusHandler::handleSymbol() {
long timeout = SYN_TIMEOUT; unsigned int timeout = SYN_TIMEOUT;
unsigned char sendSymbol = ESC; unsigned char sendSymbol = ESC;
bool sending = false; bool sending = false;
BusRequest* startRequest = NULL; BusRequest* startRequest = NULL;
@@ -879,7 +879,7 @@ void BusHandler::receiveCompleted() {
} }
Message* message = m_messages->find(m_command); Message* message = m_messages->find(m_command);
if (m_grabMessages) { if (m_grabMessages) {
unsigned long long key; uint64_t key;
if (message) { if (message) {
key = message->getKey(); key = message->getKey();
} else { } else {
@@ -1110,7 +1110,7 @@ void BusHandler::formatGrabResult(const bool unknown, ostringstream& output) {
output << "grab disabled"; output << "grab disabled";
} else { } else {
bool first = true; bool first = true;
for (map<unsigned long long, GrabbedMessage>::iterator it = m_grabbedMessages.begin(); it != m_grabbedMessages.end(); it++) { for (map<uint64_t, GrabbedMessage>::iterator it = m_grabbedMessages.begin(); it != m_grabbedMessages.end(); it++) {
if (it->second.dump(unknown, m_messages, first, output)) { if (it->second.dump(unknown, m_messages, first, output)) {
first = false; first = false;
} }
+3 -2
View File
@@ -20,6 +20,7 @@
#define EBUSD_BUSHANDLER_H_ #define EBUSD_BUSHANDLER_H_
#include <pthread.h> #include <pthread.h>
#include <stdint.h>
#include <string> #include <string>
#include <vector> #include <vector>
#include <map> #include <map>
@@ -588,7 +589,7 @@ class BusHandler : public WaitThread {
unsigned int m_remainLockCount; unsigned int m_remainLockCount;
/** the interval in microseconds after which to generate an AUTO-SYN symbol, or 0 if disabled. */ /** the interval in microseconds after which to generate an AUTO-SYN symbol, or 0 if disabled. */
long m_generateSynInterval; unsigned int m_generateSynInterval;
/** the interval in seconds in which poll messages are cycled, or 0 if disabled. */ /** the interval in seconds in which poll messages are cycled, or 0 if disabled. */
const unsigned int m_pollInterval; const unsigned int m_pollInterval;
@@ -649,7 +650,7 @@ class BusHandler : public WaitThread {
bool m_grabMessages; bool m_grabMessages;
/** the grabbed messages by key.*/ /** the grabbed messages by key.*/
map<unsigned long long, GrabbedMessage> m_grabbedMessages; map<uint64_t, GrabbedMessage> m_grabbedMessages;
}; };
} // namespace ebusd } // namespace ebusd
+1
View File
@@ -22,6 +22,7 @@
#include "datahandler.h" #include "datahandler.h"
#include <list> #include <list>
#include <string>
#ifdef HAVE_MQTT #ifdef HAVE_MQTT
# include "mqtthandler.h" # include "mqtthandler.h"
#endif #endif
+1 -1
View File
@@ -861,7 +861,7 @@ result_t loadScanConfigFile(MessageMap* messages, unsigned char address, SymbolS
if (::isspace(*it)) { if (::isspace(*it)) {
ident.erase(it--); ident.erase(it--);
} else { } else {
*it = (char)::tolower(*it); *it = static_cast<char>(::tolower(*it));
} }
} }
// complete name: cfgpath/MANUFACTURER/ZZ[.C[C[C[C[C]]]]][.circuit][.suffix][.*][.SWxxxx][.HWxxxx][.*].csv // complete name: cfgpath/MANUFACTURER/ZZ[.C[C[C[C[C]]]]][.circuit][.suffix][.*][.SWxxxx][.HWxxxx][.*].csv
+2 -2
View File
@@ -615,14 +615,14 @@ string MainLoop::executeRead(vector<string> &args) {
" Dx data byte(s) to send"; " Dx data byte(s) to send";
} }
string fieldName; string fieldName;
signed char fieldIndex = -2; char fieldIndex = -2;
if (args.size() == argPos + 2) { if (args.size() == argPos + 2) {
fieldName = args[argPos + 1]; fieldName = args[argPos + 1];
fieldIndex = -1; fieldIndex = -1;
size_t pos = fieldName.find_last_of('.'); size_t pos = fieldName.find_last_of('.');
if (pos != string::npos) { if (pos != string::npos) {
result_t result = RESULT_OK; result_t result = RESULT_OK;
fieldIndex = (char)parseInt(fieldName.substr(pos+1).c_str(), 10, 0, MAX_POS, result); fieldIndex = static_cast<char>(parseInt(fieldName.substr(pos+1).c_str(), 10, 0, MAX_POS, result));
if (result == RESULT_OK) { if (result == RESULT_OK) {
fieldName = fieldName.substr(0, pos); fieldName = fieldName.substr(0, pos);
} }
+4 -4
View File
@@ -215,7 +215,7 @@ MqttHandler::MqttHandler(BusHandler* busHandler, MessageMap* messages)
#if (LIBMOSQUITTO_MAJOR < 1) #if (LIBMOSQUITTO_MAJOR < 1)
true, true,
#endif #endif
willTopic.c_str(), (uint32_t)len, (uint8_t*)(willData.c_str()), 0, true); willTopic.c_str(), (uint32_t)len, reinterpret_cast<const uint8_t*>(willData.c_str()), 0, true);
if (mosquitto_connect(m_mosquitto, g_host, g_port, 60 if (mosquitto_connect(m_mosquitto, g_host, g_port, 60
#if (LIBMOSQUITTO_MAJOR < 1) #if (LIBMOSQUITTO_MAJOR < 1)
, true , true
@@ -250,12 +250,12 @@ void on_message(
struct mosquitto *mosq, struct mosquitto *mosq,
#endif #endif
void *obj, const struct mosquitto_message *message) { void *obj, const struct mosquitto_message *message) {
MqttHandler* handler = (MqttHandler*)obj; MqttHandler* handler = reinterpret_cast<MqttHandler*>(obj);
if (!handler || !message || !handler->isRunning()) { if (!handler || !message || !handler->isRunning()) {
return; return;
} }
string topic(message->topic); string topic(message->topic);
string data(message->payloadlen > 0 ? (char*)message->payload : ""); string data(message->payloadlen > 0 ? reinterpret_cast<char*>(message->payload) : "");
handler->notifyTopic(topic, data); handler->notifyTopic(topic, data);
} }
@@ -455,7 +455,7 @@ void MqttHandler::publishMessage(Message* message, ostringstream& updates) {
void MqttHandler::publishTopic(string topic, string data, bool retain) { void MqttHandler::publishTopic(string topic, string data, bool retain) {
logOtherDebug("mqtt", "publish %s %s", topic.c_str(), data.c_str()); logOtherDebug("mqtt", "publish %s %s", topic.c_str(), data.c_str());
mosquitto_publish(m_mosquitto, NULL, topic.c_str(), (uint32_t)data.size(), (uint8_t*)(data.c_str()), 0, retain); mosquitto_publish(m_mosquitto, NULL, topic.c_str(), (uint32_t)data.size(), reinterpret_cast<const uint8_t*>(data.c_str()), 0, retain);
} }
} // namespace ebusd } // namespace ebusd
+1 -1
View File
@@ -94,7 +94,7 @@ class NetMessage {
if (sscanf("%1x%1x", m_request.c_str()+pos+1, &value1, &value2) < 2) { if (sscanf("%1x%1x", m_request.c_str()+pos+1, &value1, &value2) < 2) {
break; break;
} }
m_request[pos] = (char)(((value1&0x0f)<<4) | (value2&0x0f)); m_request[pos] = static_cast<char>(((value1&0x0f)<<4) | (value2&0x0f));
m_request.erase(pos+1, 2); m_request.erase(pos+1, 2);
} }
} else if (pos+1 == m_request.length()) { } else if (pos+1 == m_request.length()) {
+17 -12
View File
@@ -128,7 +128,7 @@ result_t DataField::create(vector<string>::iterator& it,
FileReader::trim(token); FileReader::trim(token);
const char* str = token.c_str(); const char* str = token.c_str();
char* strEnd = NULL; char* strEnd = NULL;
unsigned long int id; unsigned long id;
if (strncasecmp(str, "0x", 2) == 0) { if (strncasecmp(str, "0x", 2) == 0) {
str += 2; str += 2;
id = strtoul(str, &strEnd, 16); // hexadecimal id = strtoul(str, &strEnd, 16); // hexadecimal
@@ -296,7 +296,7 @@ result_t SingleDataField::create(const string id, const unsigned char length,
return RESULT_OK; return RESULT_OK;
} }
if (dataType->isNumeric()) { if (dataType->isNumeric()) {
NumberDataType* numType = (NumberDataType*)dataType; NumberDataType* numType = reinterpret_cast<NumberDataType*>(dataType);
if (values.empty() && numType->hasFlag(DAY)) { if (values.empty() && numType->hasFlag(DAY)) {
for (unsigned int i = 0; i < sizeof(dayNames) / sizeof(dayNames[0]); i++) for (unsigned int i = 0; i < sizeof(dayNames) / sizeof(dayNames[0]); i++)
values[numType->getMinValue() + i] = dayNames[i]; values[numType->getMinValue() + i] = dayNames[i];
@@ -318,7 +318,7 @@ result_t SingleDataField::create(const string id, const unsigned char length,
if (divisor != 0 || !values.empty()) { if (divisor != 0 || !values.empty()) {
return RESULT_ERR_INVALID_ARG; // cannot set divisor or values for string field return RESULT_ERR_INVALID_ARG; // cannot set divisor or values for string field
} }
returnField = new SingleDataField(name, comment, unit, (StringDataType*)dataType, partType, byteCount); returnField = new SingleDataField(name, comment, unit, dataType, partType, byteCount);
return RESULT_OK; return RESULT_OK;
} }
@@ -488,7 +488,7 @@ result_t SingleDataField::derive(string name, string comment,
} }
DataType* dataType = m_dataType; DataType* dataType = m_dataType;
if (numeric) { if (numeric) {
NumberDataType* numType = (NumberDataType*)m_dataType; NumberDataType* numType = reinterpret_cast<NumberDataType*>(dataType);
result_t result = numType->derive(divisor, 0, numType); result_t result = numType->derive(divisor, 0, numType);
if (result != RESULT_OK) { if (result != RESULT_OK) {
return result; return result;
@@ -497,8 +497,10 @@ result_t SingleDataField::derive(string name, string comment,
} }
if (values.empty()) { if (values.empty()) {
fields.push_back(new SingleDataField(name, comment, unit, dataType, partType, m_length)); fields.push_back(new SingleDataField(name, comment, unit, dataType, partType, m_length));
} else if (numeric) {
fields.push_back(new ValueListDataField(name, comment, unit, reinterpret_cast<NumberDataType*>(dataType), partType, m_length, values));
} else { } else {
fields.push_back(new ValueListDataField(name, comment, unit, (NumberDataType*)dataType, partType, m_length, values)); return RESULT_ERR_INVALID_ARG;
} }
return RESULT_OK; return RESULT_OK;
} }
@@ -520,7 +522,7 @@ bool SingleDataField::hasFullByteOffset(bool after) {
if (m_length > 1 || !m_dataType->isNumeric()) { if (m_length > 1 || !m_dataType->isNumeric()) {
return true; return true;
} }
NumberDataType* num = (NumberDataType*)m_dataType; NumberDataType* num = reinterpret_cast<NumberDataType*>(m_dataType);
return (num->getBitCount() % 8) == 0 return (num->getBitCount() % 8) == 0
|| (after && num->getFirstBit() + (num->getBitCount() % 8) >= 8); || (after && num->getFirstBit() + (num->getBitCount() % 8) >= 8);
} }
@@ -549,15 +551,18 @@ result_t ValueListDataField::derive(string name, string comment,
if (divisor != 0 && divisor != 1) { if (divisor != 0 && divisor != 1) {
return RESULT_ERR_INVALID_ARG; // cannot use divisor != 1 for value list field return RESULT_ERR_INVALID_ARG; // cannot use divisor != 1 for value list field
} }
if (!m_dataType->isNumeric()) {
return RESULT_ERR_INVALID_ARG;
}
if (!values.empty()) { if (!values.empty()) {
NumberDataType* num = (NumberDataType*)m_dataType; NumberDataType* num = reinterpret_cast<NumberDataType*>(m_dataType);
if (values.begin()->first < num->getMinValue() || values.rbegin()->first > num->getMaxValue()) { if (values.begin()->first < num->getMinValue() || values.rbegin()->first > num->getMaxValue()) {
return RESULT_ERR_INVALID_ARG; // cannot use divisor != 1 for value list field return RESULT_ERR_INVALID_ARG; // cannot use divisor != 1 for value list field
} }
} else { } else {
values = m_values; values = m_values;
} }
fields.push_back(new ValueListDataField(name, comment, unit, (NumberDataType*)m_dataType, partType, m_length, values)); fields.push_back(new ValueListDataField(name, comment, unit, reinterpret_cast<NumberDataType*>(m_dataType), partType, m_length, values));
return RESULT_OK; return RESULT_OK;
} }
@@ -617,7 +622,7 @@ result_t ValueListDataField::readSymbols(SymbolString& input, const bool isMaste
result_t ValueListDataField::writeSymbols(istringstream& input, result_t ValueListDataField::writeSymbols(istringstream& input,
const unsigned char offset, const unsigned char offset,
SymbolString& output, const bool isMaster, unsigned char* usedLength) { SymbolString& output, const bool isMaster, unsigned char* usedLength) {
NumberDataType* numType = (NumberDataType*)m_dataType; NumberDataType* numType = reinterpret_cast<NumberDataType*>(m_dataType);
if (isIgnored()) { if (isIgnored()) {
return numType->writeRawValue(numType->getReplacement(), offset, m_length, output, usedLength); // replacement value return numType->writeRawValue(numType->getReplacement(), offset, m_length, output, usedLength); // replacement value
} }
@@ -721,9 +726,9 @@ DataFieldSet* DataFieldSet::s_identFields = NULL;
DataFieldSet* DataFieldSet::getIdentFields() { DataFieldSet* DataFieldSet::getIdentFields() {
if (s_identFields == NULL) { if (s_identFields == NULL) {
NumberDataType* uchDataType = (NumberDataType*)DataTypeList::getInstance()->get("UCH"); NumberDataType* uchDataType = reinterpret_cast<NumberDataType*>(DataTypeList::getInstance()->get("UCH"));
StringDataType* stringDataType = (StringDataType*)DataTypeList::getInstance()->get("STR"); StringDataType* stringDataType = reinterpret_cast<StringDataType*>(DataTypeList::getInstance()->get("STR"));
NumberDataType* pinDataType = (NumberDataType*)DataTypeList::getInstance()->get("PIN"); NumberDataType* pinDataType = reinterpret_cast<NumberDataType*>(DataTypeList::getInstance()->get("PIN"));
map<unsigned int, string> manufacturers; map<unsigned int, string> manufacturers;
manufacturers[0x06] = "Dungs"; manufacturers[0x06] = "Dungs";
manufacturers[0x0f] = "FH Ostfalia"; manufacturers[0x0f] = "FH Ostfalia";
+24 -24
View File
@@ -43,7 +43,7 @@ using std::setw;
unsigned int parseInt(const char* str, int base, const unsigned int minValue, const unsigned int maxValue, result_t& result, unsigned int* length) { unsigned int parseInt(const char* str, int base, const unsigned int minValue, const unsigned int maxValue, result_t& result, unsigned int* length) {
char* strEnd = NULL; char* strEnd = NULL;
unsigned long int ret = strtoul(str, &strEnd, base); unsigned long ret = strtoul(str, &strEnd, base);
if (strEnd == NULL || strEnd == str || *strEnd != 0) { if (strEnd == NULL || strEnd == str || *strEnd != 0) {
result = RESULT_ERR_INVALID_NUM; // invalid value result = RESULT_ERR_INVALID_NUM; // invalid value
@@ -64,7 +64,7 @@ unsigned int parseInt(const char* str, int base, const unsigned int minValue, co
int parseSignedInt(const char* str, int base, const int minValue, const int maxValue, result_t& result, unsigned int* length) { int parseSignedInt(const char* str, int base, const int minValue, const int maxValue, result_t& result, unsigned int* length) {
char* strEnd = NULL; char* strEnd = NULL;
long int ret = strtol(str, &strEnd, base); long ret = strtol(str, &strEnd, base);
if (strEnd == NULL || *strEnd != 0) { if (strEnd == NULL || *strEnd != 0) {
result = RESULT_ERR_INVALID_NUM; // invalid value result = RESULT_ERR_INVALID_NUM; // invalid value
@@ -79,7 +79,7 @@ int parseSignedInt(const char* str, int base, const int minValue, const int maxV
*length = (unsigned int)(strEnd - str); *length = (unsigned int)(strEnd - str);
} }
result = RESULT_OK; result = RESULT_OK;
return (int)ret; return static_cast<int>(ret);
} }
void printErrorPos(ostream& out, vector<string>::iterator begin, const vector<string>::iterator end, vector<string>::iterator pos, string filename, size_t lineNo, result_t result) { void printErrorPos(ostream& out, vector<string>::iterator begin, const vector<string>::iterator end, vector<string>::iterator pos, string filename, size_t lineNo, result_t result) {
@@ -337,9 +337,9 @@ result_t DateTimeDataType::readSymbols(SymbolString& input, const bool isMaster,
break; break;
} }
int mjd = last + ch*256 + 15020; // 01.01.1900 int mjd = last + ch*256 + 15020; // 01.01.1900
int y = (int)((mjd-15078.2)/365.25); int y = static_cast<int>((mjd-15078.2)/365.25);
int m = (int)((mjd-14956.1-(int)(y*365.25))/30.6001); int m = static_cast<int>((mjd-14956.1-static_cast<int>(y*365.25))/30.6001);
int d = mjd-14956-(int)(y*365.25)-(int)(m*30.6001); int d = mjd-14956-static_cast<int>(y*365.25)-static_cast<int>(m*30.6001);
m--; m--;
if (m >= 13) { if (m >= 13) {
y++; y++;
@@ -470,7 +470,7 @@ result_t DateTimeDataType::writeSymbols(istringstream& input,
} else if (i + 1 == count) { } else if (i + 1 == count) {
int y = (value < 100 ? value + 2000 : value) - 1900; int y = (value < 100 ? value + 2000 : value) - 1900;
int l = last <= 2 ? 1 : 0; int l = last <= 2 ? 1 : 0;
int mjd = 14956 + lastLast + (int)((y-l)*365.25) + (int)((last+1+l*12)*30.6001); int mjd = 14956 + lastLast + static_cast<int>((y-l)*365.25) + static_cast<int>((last+1+l*12)*30.6001);
value = mjd - 15020; // 01.01.1900 value = mjd - 15020; // 01.01.1900
output[baseOffset + offset] = (unsigned char)(value&0xff); output[baseOffset + offset] = (unsigned char)(value&0xff);
value >>= 8; value >>= 8;
@@ -484,7 +484,7 @@ result_t DateTimeDataType::writeSymbols(istringstream& input,
// calculate local week day // calculate local week day
int y = (value < 100 ? value + 2000 : value) - 1900; int y = (value < 100 ? value + 2000 : value) - 1900;
int l = last <= 2 ? 1 : 0; int l = last <= 2 ? 1 : 0;
int mjd = 14956 + lastLast + (int)((y-l)*365.25) + (int)((last+1+l*12)*30.6001); int mjd = 14956 + lastLast + static_cast<int>((y-l)*365.25) + static_cast<int>((last+1+l*12)*30.6001);
int daysSinceSunday = (mjd+3) % 7; // Sun=0 int daysSinceSunday = (mjd+3) % 7; // Sun=0
if (hasFlag(BCD)) { if (hasFlag(BCD)) {
output[baseOffset + offset - incr] = (unsigned char)((6+daysSinceSunday) % 7); // Sun=0x06 output[baseOffset + offset - incr] = (unsigned char)((6+daysSinceSunday) % 7); // Sun=0x06
@@ -737,7 +737,7 @@ result_t NumberDataType::readSymbols(SymbolString& input, const bool isMaster,
value = __builtin_bswap32(value); value = __builtin_bswap32(value);
# endif # endif
unsigned char* pval = (unsigned char*)&value; unsigned char* pval = (unsigned char*)&value;
val = *((float*)pval); val = *reinterpret_cast<float*>(pval);
#else #else
int exp = (value >> 23) & 0xff; // 8 bits, signed int exp = (value >> 23) & 0xff; // 8 bits, signed
if (exp == 0) { if (exp == 0) {
@@ -745,7 +745,7 @@ result_t NumberDataType::readSymbols(SymbolString& input, const bool isMaster,
} else { } else {
exp -= 127; exp -= 127;
unsigned int sig = value & ((1 << 23) - 1); unsigned int sig = value & ((1 << 23) - 1);
val = (1.0f + (float)(sig / exp2(23))) * (float)exp2(exp); val = (1.0f + static_cast<float>(sig / exp2(23))) * static_cast<float>(exp2(exp));
if (negative) { if (negative) {
val = -val; val = -val;
} }
@@ -753,9 +753,9 @@ result_t NumberDataType::readSymbols(SymbolString& input, const bool isMaster,
#endif #endif
if (val != 0.0) { if (val != 0.0) {
if (m_divisor < 0) { if (m_divisor < 0) {
val *= (float)-m_divisor; val *= static_cast<float>(-m_divisor);
} else if (m_divisor > 1) { } else if (m_divisor > 1) {
val /= (float)m_divisor; val /= static_cast<float>(m_divisor);
} }
} }
if (m_precision != 0) { if (m_precision != 0) {
@@ -768,24 +768,24 @@ result_t NumberDataType::readSymbols(SymbolString& input, const bool isMaster,
} }
if (!negative) { if (!negative) {
if (m_divisor < 0) { if (m_divisor < 0) {
output << static_cast<float>((float)value * (float)(-m_divisor)); output << (static_cast<float>(value) * static_cast<float>(-m_divisor));
} else if (m_divisor <= 1) { } else if (m_divisor <= 1) {
output << static_cast<unsigned>(value); output << static_cast<unsigned>(value);
} else { } else {
output << setprecision(m_precision) output << setprecision(m_precision)
<< fixed << static_cast<float>((float)value / (float)m_divisor); << fixed << (static_cast<float>(value) / static_cast<float>(m_divisor));
} }
return RESULT_OK; return RESULT_OK;
} }
signedValue = (int)value; // negative signed value signedValue = static_cast<int>(value); // negative signed value
} else if (negative) { // negative signed value } else if (negative) { // negative signed value
signedValue = (int)value - (1 << m_bitCount); signedValue = static_cast<int>(value) - (1 << m_bitCount);
} else { } else {
signedValue = (int)value; signedValue = static_cast<int>(value);
} }
if (m_divisor < 0) { if (m_divisor < 0) {
output << fixed << setprecision(0) output << fixed << setprecision(0)
<< static_cast<float>((float)signedValue * (float)(-m_divisor)); << (static_cast<float>(signedValue) * static_cast<float>(-m_divisor));
} else if (m_divisor <= 1) { } else if (m_divisor <= 1) {
if (hasFlag(FIX) && hasFlag(BCD)) { if (hasFlag(FIX) && hasFlag(BCD)) {
if (outputFormat & OF_JSON) { if (outputFormat & OF_JSON) {
@@ -800,7 +800,7 @@ result_t NumberDataType::readSymbols(SymbolString& input, const bool isMaster,
output << static_cast<signed>(signedValue) << setw(0); output << static_cast<signed>(signedValue) << setw(0);
} else { } else {
output << setprecision(m_precision) output << setprecision(m_precision)
<< fixed << static_cast<float>((float)signedValue / (float)m_divisor); << fixed << (static_cast<float>(signedValue) / static_cast<float>(m_divisor));
} }
return RESULT_OK; return RESULT_OK;
} }
@@ -873,9 +873,9 @@ result_t NumberDataType::writeSymbols(istringstream& input,
dvalue *= m_divisor; dvalue *= m_divisor;
} }
#ifdef HAVE_DIRECT_FLOAT_FORMAT #ifdef HAVE_DIRECT_FLOAT_FORMAT
float val = (float)dvalue; float val = static_cast<float>(dvalue);
unsigned char* pval = (unsigned char*)&val; unsigned char* pval = (unsigned char*)&val;
value = *((int32_t*)pval); value = *reinterpret_cast<int32_t*>(pval);
# if HAVE_DIRECT_FLOAT_FORMAT == 2 # if HAVE_DIRECT_FLOAT_FORMAT == 2
value = __builtin_bswap32(value); value = __builtin_bswap32(value);
# endif # endif
@@ -903,7 +903,7 @@ result_t NumberDataType::writeSymbols(istringstream& input,
char* strEnd = NULL; char* strEnd = NULL;
if (m_divisor == 1) { if (m_divisor == 1) {
if (hasFlag(SIG)) { if (hasFlag(SIG)) {
long int signedValue = strtol(str, &strEnd, 10); long signedValue = strtol(str, &strEnd, 10);
if (signedValue < 0 && m_bitCount != 32) { if (signedValue < 0 && m_bitCount != 32) {
value = (unsigned int)(signedValue + (1 << m_bitCount)); value = (unsigned int)(signedValue + (1 << m_bitCount));
} else { } else {
@@ -931,9 +931,9 @@ result_t NumberDataType::writeSymbols(istringstream& input,
return RESULT_ERR_OUT_OF_RANGE; // value out of range return RESULT_ERR_OUT_OF_RANGE; // value out of range
} }
if (dvalue < 0 && m_bitCount != 32) { if (dvalue < 0 && m_bitCount != 32) {
value = (int)(dvalue + (1 << m_bitCount)); value = static_cast<int>(dvalue + (1 << m_bitCount));
} else { } else {
value = (int)dvalue; value = static_cast<int>(dvalue);
} }
} else { } else {
if (dvalue < 0.0 || dvalue >= (1LL << (8 * length))) { if (dvalue < 0.0 || dvalue >= (1LL << (8 * length))) {
+13 -12
View File
@@ -19,6 +19,7 @@
#ifndef LIB_EBUS_DATATYPE_H_ #ifndef LIB_EBUS_DATATYPE_H_
#define LIB_EBUS_DATATYPE_H_ #define LIB_EBUS_DATATYPE_H_
#include <stdint.h>
#include <string> #include <string>
#include <iostream> #include <iostream>
#include <sstream> #include <sstream>
@@ -158,7 +159,7 @@ class DataType {
* @param flags the combination of flags (like #BCD). * @param flags the combination of flags (like #BCD).
* @param replacement the replacement value (fill-up value for @a StringDataType, no replacement if equal to @a NumberDataType#minValue). * @param replacement the replacement value (fill-up value for @a StringDataType, no replacement if equal to @a NumberDataType#minValue).
*/ */
DataType(const string id, const unsigned char bitCount, const unsigned short flags, const unsigned int replacement) DataType(const string id, const unsigned char bitCount, const uint16_t flags, const unsigned int replacement)
: m_id(id), m_bitCount(bitCount), m_flags(flags), m_replacement(replacement) {} : m_id(id), m_bitCount(bitCount), m_flags(flags), m_replacement(replacement) {}
/** /**
@@ -261,7 +262,7 @@ class DataType {
const unsigned char m_bitCount; const unsigned char m_bitCount;
/** the combination of flags (like #BCD). */ /** the combination of flags (like #BCD). */
const unsigned short m_flags; const uint16_t m_flags;
/** the replacement value (fill-up value for @a StringDataType, no replacement if equal to @a NumberDataType#minValue). */ /** the replacement value (fill-up value for @a StringDataType, no replacement if equal to @a NumberDataType#minValue). */
const unsigned int m_replacement; const unsigned int m_replacement;
@@ -281,7 +282,7 @@ class StringDataType : public DataType {
* @param replacement the replacement value (fill-up value). * @param replacement the replacement value (fill-up value).
* @param isHex true for hex digits instead of characters. * @param isHex true for hex digits instead of characters.
*/ */
StringDataType(const string id, const unsigned char bitCount, const unsigned short flags, StringDataType(const string id, const unsigned char bitCount, const uint16_t flags,
const unsigned int replacement, bool isHex = false) const unsigned int replacement, bool isHex = false)
: DataType(id, bitCount, flags, replacement), m_isHex(isHex) {} : DataType(id, bitCount, flags, replacement), m_isHex(isHex) {}
@@ -327,8 +328,8 @@ class DateTimeDataType : public DataType {
* @param hasTime true if time part is present. * @param hasTime true if time part is present.
* @param resolution the the resolution in minutes for time types, or 1. * @param resolution the the resolution in minutes for time types, or 1.
*/ */
DateTimeDataType(const string id, const unsigned char bitCount, const unsigned short flags, const unsigned int replacement, DateTimeDataType(const string id, const unsigned char bitCount, const uint16_t flags, const unsigned int replacement,
const bool hasDate, const bool hasTime, const short resolution) const bool hasDate, const bool hasTime, const int16_t resolution)
: DataType(id, bitCount, flags, replacement), m_hasDate(hasDate), m_hasTime(hasTime), m_resolution(resolution) {} : DataType(id, bitCount, flags, replacement), m_hasDate(hasDate), m_hasTime(hasTime), m_resolution(resolution) {}
/** /**
@@ -349,7 +350,7 @@ class DateTimeDataType : public DataType {
/** /**
* @return the resolution in minutes for time types, or 1. * @return the resolution in minutes for time types, or 1.
*/ */
short getResolution() const { return m_resolution; } int16_t getResolution() const { return m_resolution; }
// @copydoc // @copydoc
virtual result_t readRawValue(SymbolString& input, virtual result_t readRawValue(SymbolString& input,
@@ -375,7 +376,7 @@ class DateTimeDataType : public DataType {
const bool m_hasTime; const bool m_hasTime;
/** the resolution in minutes for time types, or 1. */ /** the resolution in minutes for time types, or 1. */
const short m_resolution; const int16_t m_resolution;
}; };
@@ -394,7 +395,7 @@ class NumberDataType : public DataType {
* @param maxValue the maximum raw value. * @param maxValue the maximum raw value.
* @param divisor the divisor (negative for reciprocal). * @param divisor the divisor (negative for reciprocal).
*/ */
NumberDataType(const string id, const unsigned char bitCount, const unsigned short flags, const unsigned int replacement, NumberDataType(const string id, const unsigned char bitCount, const uint16_t flags, const unsigned int replacement,
const unsigned int minValue, const unsigned int maxValue, const int divisor) const unsigned int minValue, const unsigned int maxValue, const int divisor)
: DataType(id, bitCount, flags|NUM, replacement), m_minValue(minValue), m_maxValue(maxValue), m_divisor(divisor), m_precision(calcPrecision(divisor)), m_firstBit(0), m_baseType(NULL) {} : DataType(id, bitCount, flags|NUM, replacement), m_minValue(minValue), m_maxValue(maxValue), m_divisor(divisor), m_precision(calcPrecision(divisor)), m_firstBit(0), m_baseType(NULL) {}
@@ -407,8 +408,8 @@ class NumberDataType : public DataType {
* @param firstBit the offset to the first bit. * @param firstBit the offset to the first bit.
* @param divisor the divisor (negative for reciprocal). * @param divisor the divisor (negative for reciprocal).
*/ */
NumberDataType(const string id, const unsigned char bitCount, const unsigned short flags, const unsigned int replacement, NumberDataType(const string id, const unsigned char bitCount, const uint16_t flags, const unsigned int replacement,
const short firstBit, const int divisor) const int16_t firstBit, const int divisor)
: DataType(id, bitCount, flags|NUM, replacement), m_minValue(0), m_maxValue((1<<bitCount)-1), m_divisor(divisor), m_precision(0), m_firstBit(firstBit), m_baseType(NULL) {} : DataType(id, bitCount, flags|NUM, replacement), m_minValue(0), m_maxValue((1<<bitCount)-1), m_divisor(divisor), m_precision(0), m_firstBit(firstBit), m_baseType(NULL) {}
/** /**
@@ -462,7 +463,7 @@ class NumberDataType : public DataType {
/** /**
* @return the offset to the first bit. * @return the offset to the first bit.
*/ */
short getFirstBit() const { return m_firstBit; } int16_t getFirstBit() const { return m_firstBit; }
// @copydoc // @copydoc
virtual result_t readRawValue(SymbolString& input, virtual result_t readRawValue(SymbolString& input,
@@ -508,7 +509,7 @@ class NumberDataType : public DataType {
const unsigned char m_precision; const unsigned char m_precision;
/** the offset to the first bit. */ /** the offset to the first bit. */
const short m_firstBit; const int16_t m_firstBit;
/** the base @a NumberDataType for derived instances. */ /** the base @a NumberDataType for derived instances. */
NumberDataType* m_baseType; NumberDataType* m_baseType;
+4 -4
View File
@@ -63,7 +63,7 @@ Device* Device::create(const char* name, const bool checkDevice, const bool read
return NULL; // invalid port return NULL; // invalid port
} }
struct sockaddr_in address; struct sockaddr_in address;
memset((char*)&address, 0, sizeof(address)); memset(reinterpret_cast<char*>(&address), 0, sizeof(address));
*portpos = 0; *portpos = 0;
if (inet_aton(addrpos, &address.sin_addr) == 0) { if (inet_aton(addrpos, &address.sin_addr) == 0) {
struct hostent* h = gethostbyname(addrpos); struct hostent* h = gethostbyname(addrpos);
@@ -111,7 +111,7 @@ result_t Device::send(const unsigned char value) {
return RESULT_OK; return RESULT_OK;
} }
result_t Device::recv(const long timeout, unsigned char& value) { result_t Device::recv(const unsigned int timeout, unsigned char& value) {
if (!isValid()) { if (!isValid()) {
return RESULT_ERR_DEVICE; return RESULT_ERR_DEVICE;
} }
@@ -254,9 +254,9 @@ result_t NetworkDevice::open() {
ret = bind(m_fd, (struct sockaddr*)&address, sizeof(address)); ret = bind(m_fd, (struct sockaddr*)&address, sizeof(address));
} else { } else {
int value = 1; int value = 1;
ret = setsockopt(m_fd, IPPROTO_TCP, TCP_NODELAY, (void*)&value, sizeof(value)); ret = setsockopt(m_fd, IPPROTO_TCP, TCP_NODELAY, reinterpret_cast<void*>(&value), sizeof(value));
value = 1; value = 1;
setsockopt(m_fd, SOL_SOCKET, SO_KEEPALIVE, (void*)&value, sizeof(value)); setsockopt(m_fd, SOL_SOCKET, SO_KEEPALIVE, reinterpret_cast<void*>(&value), sizeof(value));
} }
if (ret == 0) { if (ret == 0) {
ret = connect(m_fd, (struct sockaddr*)&m_address, sizeof(m_address)); ret = connect(m_fd, (struct sockaddr*)&m_address, sizeof(m_address));
+1 -1
View File
@@ -119,7 +119,7 @@ class Device {
* @param value the reference in which the received byte value is stored. * @param value the reference in which the received byte value is stored.
* @return the result_t code. * @return the result_t code.
*/ */
result_t recv(const long timeout, unsigned char& value); result_t recv(const unsigned int timeout, unsigned char& value);
/** /**
* Return the device name. * Return the device name.
+37 -37
View File
@@ -92,13 +92,13 @@ Message::Message(const string circuit, const string name,
m_lastUpdateTime(0), m_lastChangeTime(0), m_pollCount(0), m_lastPollTime(0) { m_lastUpdateTime(0), m_lastChangeTime(0), m_pollCount(0), m_lastPollTime(0) {
m_id.push_back(pb); m_id.push_back(pb);
m_id.push_back(sb); m_id.push_back(sb);
unsigned long long key = 0; uint64_t key = 0;
if (!isPassive) { if (!isPassive) {
key |= (isWrite ? 0x1fLL : 0x1eLL) << (8 * 7); // special values for active key |= (isWrite ? 0x1fLL : 0x1eLL) << (8 * 7); // special values for active
} }
key |= (unsigned long long)SYN << (8 * 6); key |= (uint64_t)SYN << (8 * 6);
key |= (unsigned long long)pb << (8 * 5); key |= (uint64_t)pb << (8 * 5);
key |= (unsigned long long)sb << (8 * 4); key |= (uint64_t)sb << (8 * 4);
m_key = key; m_key = key;
setScanMessage(); setScanMessage();
} }
@@ -134,19 +134,19 @@ string getDefault(const string value, vector<string>* defaults, size_t pos, bool
return defaultStr.substr(0, insertPos)+value+defaultStr.substr(insertPos+1); return defaultStr.substr(0, insertPos)+value+defaultStr.substr(insertPos+1);
} }
unsigned long long Message::createKey(const vector<unsigned char> id, uint64_t Message::createKey(const vector<unsigned char> id,
const bool isWrite, const bool isPassive, const bool isWrite, const bool isPassive,
const unsigned char srcAddress, const unsigned char dstAddress) { const unsigned char srcAddress, const unsigned char dstAddress) {
unsigned long long key = (unsigned long long)(id.size()-2) << (8 * 7 + 5); uint64_t key = (uint64_t)(id.size()-2) << (8 * 7 + 5);
if (isPassive) { if (isPassive) {
key |= (unsigned long long)getMasterNumber(srcAddress) << (8 * 7); // 0..25 key |= (uint64_t)getMasterNumber(srcAddress) << (8 * 7); // 0..25
} else { } else {
key |= (isWrite ? 0x1fLL : 0x1eLL) << (8 * 7); // special values for active key |= (isWrite ? 0x1fLL : 0x1eLL) << (8 * 7); // special values for active
} }
key |= (unsigned long long)dstAddress << (8 * 6); key |= (uint64_t)dstAddress << (8 * 6);
int exp = 5; int exp = 5;
for (vector<unsigned char>::const_iterator it = id.begin(); it < id.end(); it++) { for (vector<unsigned char>::const_iterator it = id.begin(); it < id.end(); it++) {
key ^= (unsigned long long)*it << (8 * exp--); key ^= (uint64_t)*it << (8 * exp--);
if (exp == 0) { if (exp == 0) {
exp = 3; exp = 3;
} }
@@ -154,7 +154,7 @@ unsigned long long Message::createKey(const vector<unsigned char> id,
return key; return key;
} }
unsigned long long Message::createKey(SymbolString& master, unsigned char maxIdLength, bool anyDestination) { uint64_t Message::createKey(SymbolString& master, unsigned char maxIdLength, bool anyDestination) {
if (master.size() < 5) { if (master.size() < 5) {
return INVALID_KEY; return INVALID_KEY;
} }
@@ -165,14 +165,14 @@ unsigned long long Message::createKey(SymbolString& master, unsigned char maxIdL
if (master.size() < 5+idLength) { if (master.size() < 5+idLength) {
return INVALID_KEY; return INVALID_KEY;
} }
unsigned long long key = (unsigned long long)idLength << (8 * 7 + 5); uint64_t key = (uint64_t)idLength << (8 * 7 + 5);
key |= (unsigned long long)getMasterNumber(master[0]) << (8 * 7); // QQ address for passive message key |= (uint64_t)getMasterNumber(master[0]) << (8 * 7); // QQ address for passive message
key |= (unsigned long long)(anyDestination ? SYN : master[1]) << (8 * 6); // ZZ address key |= (uint64_t)(anyDestination ? SYN : master[1]) << (8 * 6); // ZZ address
key |= (unsigned long long)master[2] << (8 * 5); // PB key |= (uint64_t)master[2] << (8 * 5); // PB
key |= (unsigned long long)master[3] << (8 * 4); // SB key |= (uint64_t)master[3] << (8 * 4); // SB
int exp = 3; int exp = 3;
for (unsigned char i = 0; i < idLength; i++) { for (unsigned char i = 0; i < idLength; i++) {
key ^= (unsigned long long)master[5 + i] << (8 * exp--); key ^= (uint64_t)master[5 + i] << (8 * exp--);
if (exp == 0) { if (exp == 0) {
exp = 3; exp = 3;
} }
@@ -190,11 +190,11 @@ result_t Message::parseId(string input, vector<unsigned char>& id) {
break; break;
} }
input.clear(); input.clear();
input.push_back((char)in.get()); input.push_back(static_cast<char>(in.get()));
if (in.eof()) { if (in.eof()) {
return RESULT_ERR_INVALID_ARG; // too short hex return RESULT_ERR_INVALID_ARG; // too short hex
} }
input.push_back((char)in.get()); input.push_back(static_cast<char>(in.get()));
result_t result; result_t result;
unsigned char value = (unsigned char)parseInt(input.c_str(), 16, 0, 0xff, result); unsigned char value = (unsigned char)parseInt(input.c_str(), 16, 0, 0xff, result);
@@ -522,8 +522,8 @@ bool Message::checkId(Message& other) {
return other.checkIdPrefix(m_id); return other.checkIdPrefix(m_id);
} }
unsigned long long Message::getDerivedKey(const unsigned char dstAddress) { uint64_t Message::getDerivedKey(const unsigned char dstAddress) {
return (m_key & ~(0xffLL << (8*6))) | (unsigned long long)dstAddress << (8*6); return (m_key & ~(0xffLL << (8*6))) | (uint64_t)dstAddress << (8*6);
} }
bool Message::setPollPriority(unsigned char priority) { bool Message::setPollPriority(unsigned char priority) {
@@ -842,10 +842,10 @@ ChainedMessage::ChainedMessage(const string circuit, const string name,
m_ids(ids), m_lengths(lengths), m_ids(ids), m_lengths(lengths),
m_maxTimeDiff(m_ids.size()*15) { // 15 seconds per message m_maxTimeDiff(m_ids.size()*15) { // 15 seconds per message
size_t cnt = ids.size(); size_t cnt = ids.size();
m_lastMasterDatas = (SymbolString**)calloc(cnt, sizeof(SymbolString*)); m_lastMasterDatas = reinterpret_cast<SymbolString**>(calloc(cnt, sizeof(SymbolString*)));
m_lastSlaveDatas = (SymbolString**)calloc(cnt, sizeof(SymbolString*)); m_lastSlaveDatas = reinterpret_cast<SymbolString**>(calloc(cnt, sizeof(SymbolString*)));
m_lastMasterUpdateTimes = (time_t*)calloc(cnt, sizeof(time_t)); m_lastMasterUpdateTimes = reinterpret_cast<time_t*>(calloc(cnt, sizeof(time_t)));
m_lastSlaveUpdateTimes = (time_t*)calloc(cnt, sizeof(time_t)); m_lastSlaveUpdateTimes = reinterpret_cast<time_t*>(calloc(cnt, sizeof(time_t)));
for (size_t index = 0; index < cnt; index++) { for (size_t index = 0; index < cnt; index++) {
m_lastMasterDatas[index] = new SymbolString(); m_lastMasterDatas[index] = new SymbolString();
m_lastSlaveDatas[index] = new SymbolString(); m_lastSlaveDatas[index] = new SymbolString();
@@ -1331,7 +1331,7 @@ result_t SimpleCondition::resolve(MessageMap* messages, ostringstream& errorMess
return RESULT_ERR_INVALID_ADDR; return RESULT_ERR_INVALID_ADDR;
} }
// clone the message with dedicated dstAddress if necessary // clone the message with dedicated dstAddress if necessary
unsigned long long key = message->getDerivedKey(m_dstAddress); uint64_t key = message->getDerivedKey(m_dstAddress);
vector<Message*>* derived = messages->getByKey(key); vector<Message*>* derived = messages->getByKey(key);
if (derived == NULL) { if (derived == NULL) {
message = message->derive(m_dstAddress, true); message = message->derive(m_dstAddress, true);
@@ -1524,10 +1524,10 @@ result_t LoadInstruction::execute(MessageMap* messages, ostringstream& log, Cond
result_t MessageMap::add(Message* message, bool storeByName) { result_t MessageMap::add(Message* message, bool storeByName) {
unsigned long long key = message->getKey(); uint64_t key = message->getKey();
bool conditional = message->isConditional(); bool conditional = message->isConditional();
if (!m_addAll) { if (!m_addAll) {
map<unsigned long long, vector<Message*> >::iterator keyIt = m_messagesByKey.find(key); map<uint64_t, vector<Message*> >::iterator keyIt = m_messagesByKey.find(key);
if (keyIt != m_messagesByKey.end()) { if (keyIt != m_messagesByKey.end()) {
Message* other = getFirstAvailable(keyIt->second, message); Message* other = getFirstAvailable(keyIt->second, message);
if (other != NULL) { if (other != NULL) {
@@ -1768,7 +1768,7 @@ Message* MessageMap::getScanMessage(const unsigned char dstAddress) {
if (!isValidAddress(dstAddress, false) || isMaster(dstAddress)) { if (!isValidAddress(dstAddress, false) || isMaster(dstAddress)) {
return NULL; return NULL;
} }
unsigned long long key = m_scanMessage->getDerivedKey(dstAddress); uint64_t key = m_scanMessage->getDerivedKey(dstAddress);
vector<Message*>* msgs = getByKey(key); vector<Message*>* msgs = getByKey(key);
if (msgs != NULL) { if (msgs != NULL) {
return msgs->front(); return msgs->front();
@@ -1888,8 +1888,8 @@ string MessageMap::getLoadedFiles(unsigned char address) {
return m_loadedFiles[address]; return m_loadedFiles[address];
} }
vector<Message*>* MessageMap::getByKey(const unsigned long long key) { vector<Message*>* MessageMap::getByKey(const uint64_t key) {
map<unsigned long long, vector<Message*> >::iterator it = m_messagesByKey.find(key); map<uint64_t, vector<Message*> >::iterator it = m_messagesByKey.find(key);
if (it != m_messagesByKey.end()) { if (it != m_messagesByKey.end()) {
return &it->second; return &it->second;
} }
@@ -2002,26 +2002,26 @@ Message* MessageMap::find(SymbolString& master, bool anyDestination,
if (master.size() >= 5 && master[4] == 0 && anyDestination && master[2] == 0x07 && master[3] == 0x04) { if (master.size() >= 5 && master[4] == 0 && anyDestination && master[2] == 0x07 && master[3] == 0x04) {
return m_scanMessage; return m_scanMessage;
} }
unsigned long long baseKey = Message::createKey(master, m_maxIdLength, anyDestination); uint64_t baseKey = Message::createKey(master, m_maxIdLength, anyDestination);
if (baseKey == INVALID_KEY) { if (baseKey == INVALID_KEY) {
return NULL; return NULL;
} }
unsigned char maxIdLength = Message::getKeyLength(baseKey); unsigned char maxIdLength = Message::getKeyLength(baseKey);
for (unsigned char idLength = maxIdLength; true; idLength--) { for (unsigned char idLength = maxIdLength; true; idLength--) {
unsigned long long key = baseKey; uint64_t key = baseKey;
if (idLength == maxIdLength) { if (idLength == maxIdLength) {
baseKey &= ~ID_LENGTH_AND_IDS_MASK; baseKey &= ~ID_LENGTH_AND_IDS_MASK;
} else { } else {
key |= (unsigned long long)idLength << (8 * 7 + 5); key |= (uint64_t)idLength << (8 * 7 + 5);
int exp = 3; int exp = 3;
for (unsigned char i = 0; i < idLength; i++) { for (unsigned char i = 0; i < idLength; i++) {
key ^= (unsigned long long)master[5 + i] << (8 * exp--); key ^= (uint64_t)master[5 + i] << (8 * exp--);
if (exp == 0) { if (exp == 0) {
exp = 3; exp = 3;
} }
} }
} }
map<unsigned long long , vector<Message*> >::iterator it; map<uint64_t , vector<Message*> >::iterator it;
if (withPassive) { if (withPassive) {
it = m_messagesByKey.find(key); it = m_messagesByKey.find(key);
if (it != m_messagesByKey.end()) { if (it != m_messagesByKey.end()) {
@@ -2105,7 +2105,7 @@ void MessageMap::clear() {
if (it->first[0] != '-') { // avoid double free: instances stored multiple times have a key starting with "-" if (it->first[0] != '-') { // avoid double free: instances stored multiple times have a key starting with "-"
for (vector<Message*>::iterator nit = nameMessages.begin(); nit != nameMessages.end(); nit++) { for (vector<Message*>::iterator nit = nameMessages.begin(); nit != nameMessages.end(); nit++) {
Message* message = *nit; Message* message = *nit;
map<unsigned long long, vector<Message*> >::iterator keyIt = m_messagesByKey.find(message->getKey()); map<uint64_t, vector<Message*> >::iterator keyIt = m_messagesByKey.find(message->getKey());
if (keyIt != m_messagesByKey.end()) { if (keyIt != m_messagesByKey.end()) {
vector<Message*>* keyMessages = &keyIt->second; vector<Message*>* keyMessages = &keyIt->second;
if (!keyMessages->empty()) { if (!keyMessages->empty()) {
@@ -2122,7 +2122,7 @@ void MessageMap::clear() {
nameMessages.clear(); nameMessages.clear();
} }
// free remaining message instances by key // free remaining message instances by key
for (map<unsigned long long, vector<Message*> >::iterator it = m_messagesByKey.begin(); it != m_messagesByKey.end(); it++) { for (map<uint64_t, vector<Message*> >::iterator it = m_messagesByKey.begin(); it != m_messagesByKey.end(); it++) {
vector<Message*> keyMessages = it->second; vector<Message*> keyMessages = it->second;
for (vector<Message*>::iterator kit = keyMessages.begin(); kit != keyMessages.end(); kit++) { for (vector<Message*>::iterator kit = keyMessages.begin(); kit != keyMessages.end(); kit++) {
Message* message = *kit; Message* message = *kit;
+9 -8
View File
@@ -19,6 +19,7 @@
#ifndef LIB_EBUS_MESSAGE_H_ #ifndef LIB_EBUS_MESSAGE_H_
#define LIB_EBUS_MESSAGE_H_ #define LIB_EBUS_MESSAGE_H_
#include <stdint.h>
#include <string> #include <string>
#include <vector> #include <vector>
#include <deque> #include <deque>
@@ -160,7 +161,7 @@ class Message {
* @param dstAddress the destination address, or @a SYN for any (set later). * @param dstAddress the destination address, or @a SYN for any (set later).
* @return the key for the ID. * @return the key for the ID.
*/ */
static unsigned long long createKey(const vector<unsigned char> id, static uint64_t createKey(const vector<unsigned char> id,
const bool isWrite, const bool isPassive, const bool isWrite, const bool isPassive,
const unsigned char srcAddress, const unsigned char dstAddress); const unsigned char srcAddress, const unsigned char dstAddress);
@@ -171,7 +172,7 @@ class Message {
* @param anyDestination @p true to use the special @a SYN as destination address in the key. * @param anyDestination @p true to use the special @a SYN as destination address in the key.
* @return the key for the ID, or -1LL if the data is invalid. * @return the key for the ID, or -1LL if the data is invalid.
*/ */
static unsigned long long createKey(SymbolString& master, static uint64_t createKey(SymbolString& master,
unsigned char maxIdLength, bool anyDestination = false); unsigned char maxIdLength, bool anyDestination = false);
/** /**
@@ -179,7 +180,7 @@ class Message {
* @param key the key. * @param key the key.
* @return the length field from the key. * @return the length field from the key.
*/ */
static unsigned char getKeyLength(unsigned long long key) { return (unsigned char)(key >> (8 * 7 + 5)); } static unsigned char getKeyLength(uint64_t key) { return (unsigned char)(key >> (8 * 7 + 5)); }
/** /**
* Parse an ID part from the input @a string. * Parse an ID part from the input @a string.
@@ -332,14 +333,14 @@ class Message {
* Return the key for storing in @a MessageMap. * Return the key for storing in @a MessageMap.
* @return the key for storing in @a MessageMap. * @return the key for storing in @a MessageMap.
*/ */
unsigned long long getKey() { return m_key; } uint64_t getKey() { return m_key; }
/** /**
* Return the derived key for storing in @a MessageMap. * Return the derived key for storing in @a MessageMap.
* @param dstAddress the destination address for the derivation. * @param dstAddress the destination address for the derivation.
* @return the derived key for storing in @a MessageMap. * @return the derived key for storing in @a MessageMap.
*/ */
unsigned long long getDerivedKey(const unsigned char dstAddress); uint64_t getDerivedKey(const unsigned char dstAddress);
/** /**
* Get the polling priority, or 0 for no polling at all. * Get the polling priority, or 0 for no polling at all.
@@ -573,7 +574,7 @@ class Message {
* <li>bytes 3-0: ID bytes (with cyclic xor if more than 4)</li> * <li>bytes 3-0: ID bytes (with cyclic xor if more than 4)</li>
* </ul> * </ul>
*/ */
unsigned long long m_key; uint64_t m_key;
/** the @a DataField for encoding/decoding the message. */ /** the @a DataField for encoding/decoding the message. */
DataField* m_data; DataField* m_data;
@@ -1228,7 +1229,7 @@ class MessageMap : public FileReader {
* @return the found @a Message instances, or NULL. * @return the found @a Message instances, or NULL.
* Note: the caller may not free the returned instances. * Note: the caller may not free the returned instances.
*/ */
vector<Message*>* getByKey(const unsigned long long key); vector<Message*>* getByKey(const uint64_t key);
/** /**
* Find the @a Message instance for the specified circuit and name. * Find the @a Message instance for the specified circuit and name.
@@ -1369,7 +1370,7 @@ class MessageMap : public FileReader {
map<string, vector<Message*> > m_messagesByName; map<string, vector<Message*> > m_messagesByName;
/** the known @a Message instances by key. */ /** the known @a Message instances by key. */
map<unsigned long long, vector<Message*> > m_messagesByKey; map<uint64_t, vector<Message*> > m_messagesByKey;
/** the known @a Message instances to poll, by priority. */ /** the known @a Message instances to poll, by priority. */
MessagePriorityQueue m_pollMessages; MessagePriorityQueue m_pollMessages;
+1 -1
View File
@@ -75,7 +75,7 @@ result_t SymbolString::parseHex(const string& str, const bool isEscaped) {
for (size_t i = 0; i < str.size(); i += 2) { for (size_t i = 0; i < str.size(); i += 2) {
char* strEnd = NULL; char* strEnd = NULL;
const char* strBegin = str.substr(i, 2).c_str(); const char* strBegin = str.substr(i, 2).c_str();
unsigned long int value = strtoul(strBegin, &strEnd, 16); unsigned long value = strtoul(strBegin, &strEnd, 16);
if (strEnd == NULL || strEnd != strBegin+2 || value > 0xff) { if (strEnd == NULL || strEnd != strBegin+2 || value > 0xff) {
return RESULT_ERR_INVALID_NUM; // invalid value return RESULT_ERR_INVALID_NUM; // invalid value
+1
View File
@@ -20,6 +20,7 @@
#include <iomanip> #include <iomanip>
#include "device.h" #include "device.h"
using namespace std;
using namespace ebusd; using namespace ebusd;
int main() { int main() {
+1
View File
@@ -21,6 +21,7 @@
#include <string> #include <string>
#include "symbol.h" #include "symbol.h"
using namespace std;
using namespace ebusd; using namespace ebusd;
static bool error = false; static bool error = false;
+2 -2
View File
@@ -57,7 +57,7 @@ static FILE* s_logFile = stdout;
bool setLogFacilities(const char* facilities) { bool setLogFacilities(const char* facilities) {
char *input = strdup(facilities); char *input = strdup(facilities);
char *opt = (char*)input, *value = NULL; char *opt = reinterpret_cast<char*>(input), *value = NULL;
int newFacilites = 0; int newFacilites = 0;
while (*opt) { while (*opt) {
int val = getsubopt(&opt, (char *const *)facilityNames, &value); int val = getsubopt(&opt, (char *const *)facilityNames, &value);
@@ -97,7 +97,7 @@ bool getLogFacilities(char* buffer) {
bool setLogLevel(const char* level) { bool setLogLevel(const char* level) {
char *input = strdup(level); char *input = strdup(level);
char *opt = (char*)input, *value = NULL; char *opt = reinterpret_cast<char*>(input), *value = NULL;
int newLevel = 0; int newLevel = 0;
if (*opt) { if (*opt) {
int val = getsubopt(&opt, (char *const *)levelNames, &value); int val = getsubopt(&opt, (char *const *)levelNames, &value);
+1 -1
View File
@@ -77,7 +77,7 @@ void RotateFile::write(unsigned char* value, unsigned int size, bool received) {
if ((m_fileSize%1024) == 0) { if ((m_fileSize%1024) == 0) {
fflush(m_stream); fflush(m_stream);
} }
if (m_fileSize >= m_maxSize * 1024) { if (m_fileSize >= m_maxSize * 1024LL) {
string oldfile = string(m_fileName)+".old"; string oldfile = string(m_fileName)+".old";
if (rename(m_fileName.c_str(), oldfile.c_str()) == 0) { if (rename(m_fileName.c_str(), oldfile.c_str()) == 0) {
fclose(m_stream); fclose(m_stream);
+4 -3
View File
@@ -20,6 +20,7 @@
#define LIB_UTILS_ROTATEFILE_H_ #define LIB_UTILS_ROTATEFILE_H_
#include <unistd.h> #include <unistd.h>
#include <stdint.h>
#include <iostream> #include <iostream>
#include <fstream> #include <fstream>
#include <string> #include <string>
@@ -41,7 +42,7 @@ class RotateFile {
* @param maxSize the maximum size of the file to write to. * @param maxSize the maximum size of the file to write to.
* @param textMode whether to write each byte with prefixed timestamp and direction as text. * @param textMode whether to write each byte with prefixed timestamp and direction as text.
*/ */
RotateFile(const string fileName, const unsigned long maxSize, const bool textMode = false) RotateFile(const string fileName, const unsigned int maxSize, const bool textMode = false)
: m_enabled(false), m_fileName(fileName), m_maxSize(maxSize), m_textMode(textMode), m_stream(), m_fileSize(0) {} : m_enabled(false), m_fileName(fileName), m_maxSize(maxSize), m_textMode(textMode), m_stream(), m_fileSize(0) {}
/** /**
@@ -79,7 +80,7 @@ class RotateFile {
const string m_fileName; const string m_fileName;
/** the maximum size of @a m_file, or 0 for infinite. */ /** the maximum size of @a m_file, or 0 for infinite. */
const unsigned long m_maxSize; const unsigned int m_maxSize;
/** whether to write each byte with prefixed timestamp and direction as text. */ /** whether to write each byte with prefixed timestamp and direction as text. */
const bool m_textMode; const bool m_textMode;
@@ -88,7 +89,7 @@ class RotateFile {
FILE* m_stream; FILE* m_stream;
/** the number of bytes already written to the @a m_file. */ /** the number of bytes already written to the @a m_file. */
unsigned long m_fileSize; uint64_t m_fileSize;
}; };
#endif // LIB_UTILS_ROTATEFILE_H_ #endif // LIB_UTILS_ROTATEFILE_H_
+1 -1
View File
@@ -39,7 +39,7 @@ TCPSocket* TCPClient::connect(const string& server, const uint16_t& port) {
struct sockaddr_in address; struct sockaddr_in address;
int ret; int ret;
memset((char*) &address, 0, sizeof(address)); memset(reinterpret_cast<char*>(&address), 0, sizeof(address));
if (inet_addr(server.c_str()) == INADDR_NONE) { if (inet_addr(server.c_str()) == INADDR_NONE) {
struct hostent* he; struct hostent* he;
+1 -1
View File
@@ -24,7 +24,7 @@
#include "clock.h" #include "clock.h"
void* Thread::runThread(void* arg) { void* Thread::runThread(void* arg) {
((Thread*)arg)->enter(); reinterpret_cast<Thread*>(arg)->enter();
return NULL; return NULL;
} }