89void rim::Variable::setup_python() {
91 bp::class_<rim::VariableWrap, rim::VariableWrapPtr, boost::noncopyable>(
"Variable",
106 .def(
"_varBytes", &rim::Variable::varBytes)
107 .def(
"_offset", &rim::Variable::offset)
108 .def(
"_shiftOffsetDown", &rim::Variable::shiftOffsetDown)
109 .def(
"_updatePath", &rim::Variable::updatePath)
110 .def(
"_overlapEn", &rim::Variable::overlapEn)
111 .def(
"_verifyEn", &rim::Variable::verifyEn)
112 .def(
"_bitOffset", &rim::VariableWrap::bitOffset)
113 .def(
"_bitSize", &rim::VariableWrap::bitSize)
114 .def(
"_get", &rim::VariableWrap::get)
115 .def(
"_set", &rim::VariableWrap::set)
116 .def(
"_rateTest", &rim::VariableWrap::rateTest)
117 .def(
"_queueUpdate", &rim::Variable::queueUpdate, &rim::VariableWrap::defQueueUpdate)
118 .def(
"_setLogLevel", &rim::Variable::setLogLevel)
119 .def(
"_getDumpValue", &rim::Variable::getDumpValue)
120 .def(
"_numValues", &rim::Variable::numValues)
121 .def(
"_valueBits", &rim::Variable::valueBits)
122 .def(
"_valueStride", &rim::Variable::valueStride)
123 .def(
"_retryCount", &rim::Variable::retryCount);
128rim::Variable::Variable(std::string name,
133 std::vector<uint32_t> bitOffset,
134 std::vector<uint32_t> bitSize,
145 uint32_t valueStride,
146 uint32_t retryCount) {
155 bitOffset_ = bitOffset;
157 overlapEn_ = overlapEn;
158 verifyEn_ = verifyEn;
159 byteReverse_ = byteReverse;
160 bitReverse_ = bitReverse;
161 bulkOpEn_ = bulkOpEn;
162 updateNotify_ = updateNotify;
165 binPoint_ = binPoint;
166 numValues_ = numValues;
167 valueBits_ = valueBits;
168 valueStride_ = valueStride;
169 retryCount_ = retryCount;
172 if (numValues_ == 0) {
174 bitTotal_ = bitSize_[0];
175 for (x = 1; x < bitSize_.size(); x++) bitTotal_ += bitSize_[x];
178 byteSize_ =
static_cast<int>(std::ceil(
static_cast<float>(bitTotal_) / 8.0));
180 lowTranByte_ =
reinterpret_cast<uint32_t*
>(malloc(
sizeof(uint32_t)));
181 highTranByte_ =
reinterpret_cast<uint32_t*
>(malloc(
sizeof(uint32_t)));
184 valueBytes_ = byteSize_;
185 valueBits_ = bitTotal_;
186 valueStride_ = bitTotal_;
191 bitTotal_ = bitSize_[0];
194 byteSize_ =
static_cast<int>(std::ceil(
static_cast<float>(bitTotal_) / 8.0));
197 valueBytes_ =
static_cast<uint32_t
>(std::ceil(
static_cast<float>(valueBits_) / 8.0));
200 lowTranByte_ =
reinterpret_cast<uint32_t*
>(malloc(numValues_ *
sizeof(uint32_t)));
201 highTranByte_ =
reinterpret_cast<uint32_t*
>(malloc(numValues_ *
sizeof(uint32_t)));
210 if ((bitOffset_.size() == 1) && (bitOffset_[0] % 8 == 0) && (bitSize_[0] % 8 == 0)) {
212 if (numValues_ == 0) {
213 fastByte_ =
reinterpret_cast<uint32_t*
>(malloc(
sizeof(uint32_t)));
216 }
else if ((valueBits_ % 8) == 0 && (valueStride_ % 8) == 0) {
217 fastByte_ =
reinterpret_cast<uint32_t*
>(malloc(numValues_ *
sizeof(uint32_t)));
223 shiftOffsetDown(0, 1);
229 setByteArray_ = NULL;
230 getByteArray_ = NULL;
252 setByteArray_ = &rim::Block::setByteArray;
257 setByteArray_ = &rim::Block::setByteArray;
259 setUInt_ = &rim::Block::setUInt;
264 setByteArray_ = &rim::Block::setByteArray;
266 setInt_ = &rim::Block::setInt;
270 setBool_ = &rim::Block::setBool;
274 setString_ = &rim::Block::setString;
278 setFloat_ = &rim::Block::setFloat;
282 setDouble_ = &rim::Block::setDouble;
286 setFixed_ = &rim::Block::setFixed;
299 getByteArray_ = &rim::Block::getByteArray;
304 getByteArray_ = &rim::Block::getByteArray;
306 getUInt_ = &rim::Block::getUInt;
311 getByteArray_ = &rim::Block::getByteArray;
313 getInt_ = &rim::Block::getInt;
317 getBool_ = &rim::Block::getBool;
321 getString_ = &rim::Block::getString;
325 getFloat_ = &rim::Block::getFloat;
329 getDouble_ = &rim::Block::getDouble;
333 getFixed_ = &rim::Block::getFixed;
345 setFuncPy_ = &rim::Block::setPyFunc;
349 setFuncPy_ = &rim::Block::setByteArrayPy;
354 setFuncPy_ = &rim::Block::setPyFunc;
356 setFuncPy_ = &rim::Block::setUIntPy;
361 setFuncPy_ = &rim::Block::setPyFunc;
363 setFuncPy_ = &rim::Block::setIntPy;
367 setFuncPy_ = &rim::Block::setBoolPy;
371 setFuncPy_ = &rim::Block::setStringPy;
375 setFuncPy_ = &rim::Block::setFloatPy;
379 setFuncPy_ = &rim::Block::setDoublePy;
383 setFuncPy_ = &rim::Block::setFixedPy;
394 getFuncPy_ = &rim::Block::getPyFunc;
398 getFuncPy_ = &rim::Block::getByteArrayPy;
403 getFuncPy_ = &rim::Block::getPyFunc;
405 getFuncPy_ = &rim::Block::getUIntPy;
410 getFuncPy_ = &rim::Block::getPyFunc;
412 getFuncPy_ = &rim::Block::getIntPy;
416 getFuncPy_ = &rim::Block::getBoolPy;
420 getFuncPy_ = &rim::Block::getStringPy;
424 getFuncPy_ = &rim::Block::getFloatPy;
428 getFuncPy_ = &rim::Block::getDoublePy;
432 getFuncPy_ = &rim::Block::getFixedPy;
451void rim::Variable::shiftOffsetDown(uint32_t shift, uint32_t minSize) {
456 for (x = 0; x < bitOffset_.size(); x++) bitOffset_[x] += shift * 8;
460 if (numValues_ == 0) {
462 varBytes_ =
static_cast<int>(std::ceil(
463 static_cast<float>(bitOffset_[bitOffset_.size() - 1] + bitSize_[bitSize_.size() - 1]) /
464 (
static_cast<float>(minSize) * 8.0))) *
469 static_cast<int>(std::floor(
static_cast<float>(bitOffset_[0]) / (
static_cast<float>(minSize) * 8.0))) *
473 highTranByte_[0] = varBytes_ - 1;
474 staleHighByte_ = highTranByte_[0];
478 for (x = 0; x < numValues_; x++) {
480 static_cast<uint32_t
>(std::floor(
481 (
static_cast<float>(bitOffset_[0]) +
static_cast<float>(x) *
static_cast<float>(valueStride_)) /
482 (
static_cast<float>(minSize) * 8.0))) *
484 highTranByte_[x] =
static_cast<uint32_t
>(
485 std::ceil((
static_cast<float>(bitOffset_[0]) +
486 static_cast<float>(x) *
static_cast<float>(valueStride_) + valueBits_) /
487 (
static_cast<float>(minSize) * 8.0))) *
493 varBytes_ = highTranByte_[numValues_ - 1] + 1;
494 staleHighByte_ = highTranByte_[numValues_ - 1];
498 if (fastByte_ != NULL) {
499 if (numValues_ == 0) {
500 fastByte_[0] = bitOffset_[0] / 8;
504 for (x = 0; x < numValues_; x++) fastByte_[x] = (bitOffset_[0] + (valueStride_ * x)) / 8;
508 staleLowByte_ = lowTranByte_[0];
552rim::VariableWrap::VariableWrap(std::string name,
557 bp::object bitOffset,
578 bp::extract<uint32_t>(model.attr(
"modelId")),
579 bp::extract<bool>(model.attr(
"isBigEndian")),
580 bp::extract<bool>(model.attr(
"bitReverse")),
581 bp::extract<uint32_t>(model.attr(
"binPoint")),
582 bp::extract<uint32_t>(listData.attr(
"numValues")),
583 bp::extract<uint32_t>(listData.attr(
"valueBits")),
584 bp::extract<uint32_t>(listData.attr(
"valueStride")),
644void rim::Variable::rateTest() {
647 struct timeval stime;
648 struct timeval etime;
649 struct timeval dtime;
651 uint64_t count = 1000000;
656 gettimeofday(&stime, NULL);
657 for (x = 0; x < count; ++x) {
660 gettimeofday(&etime, NULL);
662 timersub(&etime, &stime, &dtime);
663 durr = dtime.tv_sec +
static_cast<float>(dtime.tv_usec) / 1.0e6;
666 printf(
"\nVariable c++ get: Read %" PRIu64
" times in %f seconds. Rate = %f\n", count, durr, rate);
668 gettimeofday(&stime, NULL);
669 for (x = 0; x < count; ++x) {
672 gettimeofday(&etime, NULL);
674 timersub(&etime, &stime, &dtime);
675 durr = dtime.tv_sec +
static_cast<float>(dtime.tv_usec) / 1.0e6;
678 printf(
"\nVariable c++ set: Wrote %" PRIu64
" times in %f seconds. Rate = %f\n", count, durr, rate);
690std::string rim::Variable::getDumpValue(
bool read) {
691 std::stringstream ret;
695 uint8_t byteData[valueBytes_];
697 memset(byteData, 0, valueBytes_);
699 if (read) block_->read(
this);
701 ret << path_ <<
" =";
708 while (index <
static_cast<int32_t
>(numValues_)) {
713 (block_->*getByteArray_)(byteData,
this, index);
715 for (x = 0; x < valueBytes_; x++)
716 ret << std::setfill(
'0') << std::setw(2) << std::hex << static_cast<uint32_t>(byteData[x]);
720 if (valueBits_ > 64) {
721 (block_->*getByteArray_)(byteData,
this, index);
723 for (x = 0; x < valueBytes_; x++)
724 ret << std::setfill(
'0') << std::setw(2) << std::hex << static_cast<uint32_t>(byteData[x]);
726 ret << (block_->*getUInt_)(
this, index);
731 if (valueBits_ > 64) {
732 (block_->*getByteArray_)(byteData,
this, index);
734 for (x = 0; x < valueBytes_; x++)
735 ret << std::setfill(
'0') << std::setw(2) << std::hex << static_cast<uint32_t>(byteData[x]);
737 ret << (block_->*getInt_)(
this, index);
742 ret << (block_->*getBool_)(
this, index);
746 ret << (block_->*getString_)(
this, index);
750 ret << (block_->*getFloat_)(
this, index);
754 ret << (block_->*getDouble_)(
this, index);
758 ret << (block_->*getFixed_)(
this, index);