X-Git-Url: http://sraa.de/git/?a=blobdiff_plain;f=dol%2Fsrc%2Fdol%2Fvisitor%2Fhdsd%2Fscd%2Fscd_command.cpp;fp=dol%2Fsrc%2Fdol%2Fvisitor%2Fhdsd%2Fscd%2Fscd_command.cpp;h=008171dfdfc65b945898e491c259816ebe64cafa;hb=8c411cf24ed0eb889191aaeafd8fa1e69081df42;hp=0000000000000000000000000000000000000000;hpb=dea7a4fb1ed110d3ce6e6d9255103d724bd66c0e;p=jump.git diff --git a/dol/src/dol/visitor/hdsd/scd/scd_command.cpp b/dol/src/dol/visitor/hdsd/scd/scd_command.cpp new file mode 100644 index 0000000..008171d --- /dev/null +++ b/dol/src/dol/visitor/hdsd/scd/scd_command.cpp @@ -0,0 +1,105 @@ +#include "scd_command.h" + +#include "cstring" +#include "arpa/inet.h" + + +scd_command::scd_command(): _type(0), _subtype(0), _msglen(0) +{ + _msg = NULL; +} + + +scd_command::scd_command(uint16_t type, uint16_t subtype): + _type(type), _subtype(subtype), _msglen(0) +{ + _msg = NULL; +} + + +scd_command::scd_command(uint16_t type, uint16_t subtype, + const std::string& msg): + _type(type), _subtype(subtype) +{ + if (msg.length() > 0) + { + _msglen = msg.length()+1; + _msg = new char[_msglen]; + strncpy(_msg, msg.c_str(), _msglen); + _msg[_msglen-1] = 0; + } + else + { + _msglen = 0; + _msg = NULL; + } +} + + +scd_command::scd_command(uint16_t type, uint16_t subtype, + const sc_core::sc_time& time) : _type(type), _subtype(subtype) +{ + uint64_t value; + uint32_t hi, lo; + + _msglen = 8; + _msg = new char[_msglen]; + + // obtain high and low words + value = time.value(); + lo = value & 0xFFFFFFFF; + value >>= 32; + hi = value & 0xFFFFFFFF; + + // do network conversion + hi = htonl(hi); + lo = htonl(lo); + + // store to buffer + memcpy(_msg, &hi, 4); + memcpy(_msg + 4, &lo, 4); +} + + + +scd_command::~scd_command() +{ + if (_msg != NULL) + delete _msg; +} + + +uint16_t scd_command::get_type() const { return _type; } + + +uint16_t scd_command::get_subtype() const { return _subtype; } + + +std::string scd_command::get_string() const +{ + if (_msglen <= 1) + return std::string(); + else + return std::string(_msg, _msglen-1); +} + + +sc_core::sc_time scd_command::get_time() const +{ + if (_msglen != 8) + return sc_core::SC_ZERO_TIME; + + uint64_t value; + uint32_t hi, lo; + + // get value from buffer + memcpy(&hi, _msg, 4); + memcpy(&lo, _msg+4, 4); + + // do network conversion + value = ntohl(hi); + value <<= 32; + value |= ntohl(lo); + + return sc_core::sc_time(value, false); +}