00001 #include "husky_base/horizon_legacy/Message_data.h"
00002 #include "husky_base/horizon_legacy/Number.h"
00003 #include "husky_base/horizon_legacy/Transport.h"
00004
00005 #include <iostream>
00006 #include <string>
00007 #include <string.h>
00008 #include <sstream>
00009
00010 using namespace std;
00011
00012 namespace clearpath
00013 {
00014
00024 #define MESSAGE_CONSTRUCTORS(MessageClass, ExpectedLength) \
00025 MessageClass::MessageClass(void* input, size_t msg_len) : Message(input, msg_len) \
00026 { \
00027 if( ((ExpectedLength) >= 0) && ((ssize_t)getPayloadLength() != (ExpectedLength)) ) { \
00028 stringstream ss; \
00029 ss << "Bad payload length: actual="<<getPayloadLength(); \
00030 ss <<" vs. expected="<<(ExpectedLength); \
00031 throw new MessageException(ss.str().c_str(), MessageException::INVALID_LENGTH); \
00032 } \
00033 } \
00034 MessageClass::MessageClass(const MessageClass& other) : Message(other) {}
00035
00036
00041 #define MESSAGE_CONVENIENCE_FNS(MessageClass, DataMsgID) \
00042 MessageClass* MessageClass::popNext() { \
00043 return dynamic_cast<MessageClass*>(Transport::instance().popNext(DataMsgID)); \
00044 } \
00045 \
00046 MessageClass* MessageClass::waitNext(double timeout) { \
00047 return dynamic_cast<MessageClass*>(Transport::instance().waitNext(DataMsgID, timeout)); \
00048 } \
00049 \
00050 MessageClass* MessageClass::getUpdate(double timeout) { \
00051 Transport::instance().flush(DataMsgID); \
00052 subscribe(0); \
00053 return dynamic_cast<MessageClass*>( \
00054 Transport::instance().waitNext(DataMsgID, timeout) ); \
00055 }\
00056 \
00057 void MessageClass::subscribe(uint16_t freq) { \
00058 Request(DataMsgID-0x4000, freq).send(); \
00059 } \
00060 \
00061 enum MessageTypes MessageClass::getTypeID() { \
00062 return DataMsgID; \
00063 }
00064
00065 MESSAGE_CONSTRUCTORS(DataAckermannOutput, PAYLOAD_LEN)
00066
00067 MESSAGE_CONVENIENCE_FNS(DataAckermannOutput, DATA_ACKERMANN_SETPTS)
00068
00069 double DataAckermannOutput::getSteering()
00070 {
00071 return btof(getPayloadPointer(STEERING), 2, 100);
00072 }
00073
00074 double DataAckermannOutput::getThrottle()
00075 {
00076 return btof(getPayloadPointer(THROTTLE), 2, 100);
00077 }
00078
00079 double DataAckermannOutput::getBrake()
00080 {
00081 return btof(getPayloadPointer(BRAKE), 2, 100);
00082 }
00083
00084 ostream &DataAckermannOutput::printMessage(ostream &stream)
00085 {
00086 stream << "Ackermann Control" << endl;
00087 stream << "=================" << endl;
00088 stream << "Steering: " << getSteering() << endl;
00089 stream << "Throttle: " << getThrottle() << endl;
00090 stream << "Brake : " << getBrake() << endl;
00091 return stream;
00092 }
00093
00094
00095
00096 MESSAGE_CONSTRUCTORS(DataDifferentialControl, PAYLOAD_LEN)
00097
00098 MESSAGE_CONVENIENCE_FNS(DataDifferentialControl, DATA_DIFF_CTRL_CONSTS)
00099
00100 double DataDifferentialControl::getLeftP()
00101 {
00102 return btof(getPayloadPointer(LEFT_P), 2, 100);
00103 }
00104
00105 double DataDifferentialControl::getLeftI()
00106 {
00107 return btof(getPayloadPointer(LEFT_I), 2, 100);
00108 }
00109
00110 double DataDifferentialControl::getLeftD()
00111 {
00112 return btof(getPayloadPointer(LEFT_D), 2, 100);
00113 }
00114
00115 double DataDifferentialControl::getLeftFeedForward()
00116 {
00117 return btof(getPayloadPointer(LEFT_FEEDFWD), 2, 100);
00118 }
00119
00120 double DataDifferentialControl::getLeftStiction()
00121 {
00122 return btof(getPayloadPointer(LEFT_STIC), 2, 100);
00123 }
00124
00125 double DataDifferentialControl::getLeftIntegralLimit()
00126 {
00127 return btof(getPayloadPointer(LEFT_INT_LIM), 2, 100);
00128 }
00129
00130 double DataDifferentialControl::getRightP()
00131 {
00132 return btof(getPayloadPointer(RIGHT_P), 2, 100);
00133 }
00134
00135 double DataDifferentialControl::getRightI()
00136 {
00137 return btof(getPayloadPointer(RIGHT_I), 2, 100);
00138 }
00139
00140 double DataDifferentialControl::getRightD()
00141 {
00142 return btof(getPayloadPointer(RIGHT_D), 2, 100);
00143 }
00144
00145 double DataDifferentialControl::getRightFeedForward()
00146 {
00147 return btof(getPayloadPointer(RIGHT_FEEDFWD), 2, 100);
00148 }
00149
00150 double DataDifferentialControl::getRightStiction()
00151 {
00152 return btof(getPayloadPointer(RIGHT_STIC), 2, 100);
00153 }
00154
00155 double DataDifferentialControl::getRightIntegralLimit()
00156 {
00157 return btof(getPayloadPointer(RIGHT_INT_LIM), 2, 100);
00158 }
00159
00160 ostream &DataDifferentialControl::printMessage(ostream &stream)
00161 {
00162 stream << "Differential Control Constant Data" << endl;
00163 stream << "==================================" << endl;
00164 stream << "Left P : " << getLeftP() << endl;
00165 stream << "Left I : " << getLeftI() << endl;
00166 stream << "Left D : " << getLeftD() << endl;
00167 stream << "Left Feed Forward : " << getLeftFeedForward() << endl;
00168 stream << "Left Stiction : " << getLeftStiction() << endl;
00169 stream << "Left Integral Limit : " << getLeftIntegralLimit() << endl;
00170 stream << "Right P : " << getRightP() << endl;
00171 stream << "Right I : " << getRightI() << endl;
00172 stream << "Right D : " << getRightD() << endl;
00173 stream << "Right Feed Forward : " << getRightFeedForward() << endl;
00174 stream << "Right Stiction : " << getRightStiction() << endl;
00175 stream << "Right Integral Limit: " << getRightIntegralLimit() << endl;
00176 return stream;
00177 }
00178
00179
00180 MESSAGE_CONSTRUCTORS(DataDifferentialOutput, PAYLOAD_LEN)
00181
00182 MESSAGE_CONVENIENCE_FNS(DataDifferentialOutput, DATA_DIFF_WHEEL_SETPTS)
00183
00184 double DataDifferentialOutput::getLeft()
00185 {
00186 return btof(getPayloadPointer(LEFT), 2, 100);
00187 }
00188
00189 double DataDifferentialOutput::getRight()
00190 {
00191 return btof(getPayloadPointer(RIGHT), 2, 100);
00192 }
00193
00194 ostream &DataDifferentialOutput::printMessage(ostream &stream)
00195 {
00196 stream << "Differential Output Data" << endl;
00197 stream << "========================" << endl;
00198 stream << "Left : " << getLeft() << endl;
00199 stream << "Right: " << getRight() << endl;
00200 return stream;
00201 }
00202
00203
00204
00205 MESSAGE_CONSTRUCTORS(DataDifferentialSpeed, PAYLOAD_LEN);
00206
00207 MESSAGE_CONVENIENCE_FNS(DataDifferentialSpeed, DATA_DIFF_WHEEL_SPEEDS);
00208
00209 double DataDifferentialSpeed::getLeftSpeed()
00210 {
00211 return btof(getPayloadPointer(LEFT_SPEED), 2, 100);
00212 }
00213
00214 double DataDifferentialSpeed::getLeftAccel()
00215 {
00216 return btof(getPayloadPointer(LEFT_ACCEL), 2, 100);
00217 }
00218
00219 double DataDifferentialSpeed::getRightSpeed()
00220 {
00221 return btof(getPayloadPointer(RIGHT_SPEED), 2, 100);
00222 }
00223
00224 double DataDifferentialSpeed::getRightAccel()
00225 {
00226 return btof(getPayloadPointer(RIGHT_ACCEL), 2, 100);
00227 }
00228
00229 ostream &DataDifferentialSpeed::printMessage(ostream &stream)
00230 {
00231 stream << "Differential Speed Data" << endl;
00232 stream << "=======================" << endl;
00233 stream << "Left Speed : " << getLeftSpeed() << endl;
00234 stream << "Left Accel : " << getLeftAccel() << endl;
00235 stream << "Right Speed: " << getRightSpeed() << endl;
00236 stream << "Right Accel: " << getRightAccel() << endl;
00237 return stream;
00238 }
00239
00240
00241 MESSAGE_CONSTRUCTORS(DataEcho, 0)
00242
00243 MESSAGE_CONVENIENCE_FNS(DataEcho, DATA_ECHO)
00244
00245 ostream &DataEcho::printMessage(ostream &stream)
00246 {
00247 stream << "Echo!";
00248 return stream;
00249 }
00250
00251
00252 DataEncoders::DataEncoders(void *input, size_t msg_len) : Message(input, msg_len)
00253 {
00254 if ((ssize_t) getPayloadLength() != (1 + getCount() * 6))
00255 {
00256 stringstream ss;
00257 ss << "Bad payload length: actual=" << getPayloadLength();
00258 ss << " vs. expected=" << (1 + getCount() * 6);
00259 throw new MessageException(ss.str().c_str(), MessageException::INVALID_LENGTH);
00260 }
00261 travels_offset = 1;
00262 speeds_offset = travels_offset + (getCount() * 4);
00263 }
00264
00265 DataEncoders::DataEncoders(const DataEncoders &other) : Message(other)
00266 {
00267 }
00268
00269 MESSAGE_CONVENIENCE_FNS(DataEncoders, DATA_ENCODER);
00270
00271 uint8_t DataEncoders::getCount()
00272 {
00273 return *getPayloadPointer(0);
00274 }
00275
00276 double DataEncoders::getTravel(uint8_t index)
00277 {
00278 return btof(getPayloadPointer(travels_offset + index * 4), 4, 1000);
00279 }
00280
00281 double DataEncoders::getSpeed(uint8_t index)
00282 {
00283 return btof(getPayloadPointer(speeds_offset + index * 2), 2, 1000);
00284 }
00285
00286 ostream &DataEncoders::printMessage(ostream &stream)
00287 {
00288 stream << "Encoder Data" << endl;
00289 stream << "============" << endl;
00290 stream << "Count : " << (int) (getCount()) << endl;
00291 for (unsigned i = 0; i < getCount(); ++i)
00292 {
00293 stream << "Encoder " << i << ":" << endl;
00294 stream << " Travel: " << getTravel(i) << endl;
00295 stream << " Speed : " << getSpeed(i) << endl;
00296 }
00297 return stream;
00298 }
00299
00300
00301
00302 MESSAGE_CONSTRUCTORS(DataEncodersRaw, (1 + getCount() * 4))
00303
00304 MESSAGE_CONVENIENCE_FNS(DataEncodersRaw, DATA_ENCODER_RAW)
00305
00306 uint8_t DataEncodersRaw::getCount()
00307 {
00308 return *getPayloadPointer(0);
00309 }
00310
00311 int32_t DataEncodersRaw::getTicks(uint8_t inx)
00312 {
00313 return btoi(getPayloadPointer(1 + inx * 4), 4);
00314 }
00315
00316 ostream &DataEncodersRaw::printMessage(ostream &stream)
00317 {
00318 stream << "Raw Encoder Data" << endl;
00319 stream << "================" << endl;
00320 for (int i = 0; i < getCount(); ++i)
00321 {
00322 stream << "Encoder " << i << ": " << getTicks(i) << endl;
00323 }
00324 return stream;
00325 }
00326
00327
00328
00329 MESSAGE_CONSTRUCTORS(DataFirmwareInfo, PAYLOAD_LEN)
00330
00331 MESSAGE_CONVENIENCE_FNS(DataFirmwareInfo, DATA_FIRMWARE_INFO)
00332
00333 uint8_t DataFirmwareInfo::getMajorFirmwareVersion()
00334 {
00335 return *getPayloadPointer(MAJOR_FIRM_VER);
00336 }
00337
00338 uint8_t DataFirmwareInfo::getMinorFirmwareVersion()
00339 {
00340 return *getPayloadPointer(MINOR_FIRM_VER);
00341 }
00342
00343 uint8_t DataFirmwareInfo::getMajorProtocolVersion()
00344 {
00345 return *getPayloadPointer(MAJOR_PROTO_VER);
00346 }
00347
00348 uint8_t DataFirmwareInfo::getMinorProtocolVersion()
00349 {
00350 return *getPayloadPointer(MINOR_PROTO_VER);
00351 }
00352
00353 DataFirmwareInfo::WriteTime DataFirmwareInfo::getWriteTime()
00354 {
00355 return WriteTime(btou(getPayloadPointer(WRITE_TIME), 4));
00356 }
00357
00358 ostream &DataFirmwareInfo::printMessage(ostream &stream)
00359 {
00360 stream << "Firmware Info" << endl;
00361 stream << "=============" << endl;
00362 stream << "Major firmware version: " << (int) getMajorFirmwareVersion() << endl;
00363 stream << "Minor firmware version: " << (int) getMinorFirmwareVersion() << endl;
00364 stream << "Major protocol version: " << (int) getMajorProtocolVersion() << endl;
00365 stream << "Minor protocol version: " << (int) getMinorProtocolVersion() << endl;
00366 WriteTime t = getWriteTime();
00367 stream << "Firmware write time : ";
00368 stream << (2000 + t.year()) << "-" << (int) t.month() << "-" << (int) t.day() << " ";
00369 stream << (int) t.hour() << ":" << (int) t.minute() << endl;
00370 return stream;
00371 }
00372
00373
00374
00375 MESSAGE_CONSTRUCTORS(DataGear, 1)
00376
00377 MESSAGE_CONVENIENCE_FNS(DataGear, DATA_GEAR_SETPT)
00378
00379 uint8_t DataGear::getGear()
00380 {
00381 return getPayloadPointer()[0];
00382 }
00383
00384 ostream &DataGear::printMessage(ostream &stream)
00385 {
00386 stream << "Gear" << endl;
00387 stream << "====" << endl;
00388 stream << "Gear: " << (int) getGear() << endl;
00389 return stream;
00390 }
00391
00392
00393
00394 MESSAGE_CONSTRUCTORS(DataMaxAcceleration, PAYLOAD_LEN)
00395
00396 MESSAGE_CONVENIENCE_FNS(DataMaxAcceleration, DATA_MAX_ACCEL)
00397
00398 double DataMaxAcceleration::getForwardMax()
00399 {
00400 return btof(getPayloadPointer(FORWARD_MAX), 2, 100);
00401 }
00402
00403 double DataMaxAcceleration::getReverseMax()
00404 {
00405 return btof(getPayloadPointer(REVERSE_MAX), 2, 100);
00406 }
00407
00408 ostream &DataMaxAcceleration::printMessage(ostream &stream)
00409 {
00410 stream << "Max Acceleration Data" << endl;
00411 stream << "=====================" << endl;
00412 stream << "Max Forward: " << getForwardMax() << endl;
00413 stream << "Max Reverse: " << getReverseMax() << endl;
00414 return stream;
00415 }
00416
00417
00418
00419 MESSAGE_CONSTRUCTORS(DataMaxSpeed, PAYLOAD_LEN)
00420
00421 MESSAGE_CONVENIENCE_FNS(DataMaxSpeed, DATA_MAX_SPEED)
00422
00423 double DataMaxSpeed::getForwardMax()
00424 {
00425 return btof(getPayloadPointer(FORWARD_MAX), 2, 100);
00426 }
00427
00428 double DataMaxSpeed::getReverseMax()
00429 {
00430 return btof(getPayloadPointer(REVERSE_MAX), 2, 100);
00431 }
00432
00433 ostream &DataMaxSpeed::printMessage(ostream &stream)
00434 {
00435 stream << "Max Speed Data" << endl;
00436 stream << "==============" << endl;
00437 stream << "Max Forward: " << getForwardMax() << endl;
00438 stream << "Max Reverse: " << getReverseMax() << endl;
00439 return stream;
00440 }
00441
00442
00443
00444 MESSAGE_CONSTRUCTORS(DataPlatformAcceleration, PAYLOAD_LEN)
00445
00446 MESSAGE_CONVENIENCE_FNS(DataPlatformAcceleration, DATA_ACCEL)
00447
00448 double DataPlatformAcceleration::getX()
00449 {
00450 return btof(getPayloadPointer(X), 2, 1000);
00451 }
00452
00453 double DataPlatformAcceleration::getY()
00454 {
00455 return btof(getPayloadPointer(Y), 2, 1000);
00456 }
00457
00458 double DataPlatformAcceleration::getZ()
00459 {
00460 return btof(getPayloadPointer(Z), 2, 1000);
00461 }
00462
00463 ostream &DataPlatformAcceleration::printMessage(ostream &stream)
00464 {
00465 stream << "Platform Acceleration" << endl;
00466 stream << "=====================" << endl;
00467 stream << "X: " << getX() << endl;
00468 stream << "Y: " << getY() << endl;
00469 stream << "Z: " << getZ() << endl;
00470 return stream;
00471 }
00472
00473
00474
00475 MESSAGE_CONSTRUCTORS(DataPlatformInfo, (int) strlenModel() + 6)
00476
00477 MESSAGE_CONVENIENCE_FNS(DataPlatformInfo, DATA_PLATFORM_INFO)
00478
00479 uint8_t DataPlatformInfo::strlenModel()
00480 {
00481 return *getPayloadPointer();
00482 }
00483
00484 string DataPlatformInfo::getModel()
00485 {
00486 char buf[256];
00487
00488 size_t cpy_len = strlenModel();
00489 memcpy(buf, getPayloadPointer(1), cpy_len);
00490 buf[cpy_len] = '\0';
00491
00492 return string(buf);
00493 }
00494
00495 uint8_t DataPlatformInfo::getRevision()
00496 {
00497 char offset = strlenModel() + 1;
00498 return *getPayloadPointer(offset);
00499 }
00500
00501 uint32_t DataPlatformInfo::getSerial()
00502 {
00503 char offset = strlenModel() + 2;
00504 return btou(getPayloadPointer(offset), 4);
00505 }
00506
00507 std::ostream &DataPlatformInfo::printMessage(std::ostream &stream)
00508 {
00509 stream << "Platform Info" << endl;
00510 stream << "=============" << endl;
00511 stream << "Model : " << getModel() << endl;
00512 stream << "Revision: " << (int) (getRevision()) << endl;
00513 stream << "Serial : " << getSerial() << endl;
00514 return stream;
00515 }
00516
00517
00518
00519 MESSAGE_CONSTRUCTORS(DataPlatformName, (int) (*getPayloadPointer()) + 1)
00520
00521 MESSAGE_CONVENIENCE_FNS(DataPlatformName, DATA_PLATFORM_NAME)
00522
00523 string DataPlatformName::getName()
00524 {
00525 char buf[256];
00526 size_t cpy_len = *getPayloadPointer();
00527 memcpy(buf, getPayloadPointer(1), cpy_len);
00528 buf[cpy_len] = '\0';
00529 return string(buf);
00530 }
00531
00532 std::ostream &DataPlatformName::printMessage(std::ostream &stream)
00533 {
00534 stream << "Platform Name" << endl;
00535 stream << "=============" << endl;
00536 stream << "Name: " << getName() << endl;
00537 return stream;
00538 }
00539
00540
00541
00542 MESSAGE_CONSTRUCTORS(DataPlatformMagnetometer, PAYLOAD_LEN)
00543
00544 MESSAGE_CONVENIENCE_FNS(DataPlatformMagnetometer, DATA_MAGNETOMETER)
00545
00546 double DataPlatformMagnetometer::getX()
00547 {
00548 return btof(getPayloadPointer(X), 2, 1000);
00549 }
00550
00551 double DataPlatformMagnetometer::getY()
00552 {
00553 return btof(getPayloadPointer(Y), 2, 1000);
00554 }
00555
00556 double DataPlatformMagnetometer::getZ()
00557 {
00558 return btof(getPayloadPointer(Z), 2, 1000);
00559 }
00560
00561 ostream &DataPlatformMagnetometer::printMessage(ostream &stream)
00562 {
00563 stream << "PlatformMagnetometer Data" << endl;
00564 stream << "=================" << endl;
00565 stream << "X: " << getX() << endl;
00566 stream << "Y: " << getY() << endl;
00567 stream << "Z: " << getZ() << endl;
00568 return stream;
00569 }
00570
00571
00572
00573 MESSAGE_CONSTRUCTORS(DataPlatformOrientation, PAYLOAD_LEN)
00574
00575 MESSAGE_CONVENIENCE_FNS(DataPlatformOrientation, DATA_ORIENT)
00576
00577 double DataPlatformOrientation::getRoll()
00578 {
00579 return btof(getPayloadPointer(ROLL), 2, 1000);
00580 }
00581
00582 double DataPlatformOrientation::getPitch()
00583 {
00584 return btof(getPayloadPointer(PITCH), 2, 1000);
00585 }
00586
00587 double DataPlatformOrientation::getYaw()
00588 {
00589 return btof(getPayloadPointer(YAW), 2, 1000);
00590 }
00591
00592 ostream &DataPlatformOrientation::printMessage(ostream &stream)
00593 {
00594 stream << "Platform Orientation" << endl;
00595 stream << "====================" << endl;
00596 stream << "Roll : " << getRoll() << endl;
00597 stream << "Pitch: " << getPitch() << endl;
00598 stream << "Yaw : " << getYaw() << endl;
00599
00600 return stream;
00601 }
00602
00603
00604
00605 MESSAGE_CONSTRUCTORS(DataPlatformRotation, PAYLOAD_LEN)
00606
00607 MESSAGE_CONVENIENCE_FNS(DataPlatformRotation, DATA_ROT_RATE)
00608
00609 double DataPlatformRotation::getRollRate()
00610 {
00611 return btof(getPayloadPointer(ROLL_RATE), 2, 1000);
00612 }
00613
00614 double DataPlatformRotation::getPitchRate()
00615 {
00616 return btof(getPayloadPointer(PITCH_RATE), 2, 1000);
00617 }
00618
00619 double DataPlatformRotation::getYawRate()
00620 {
00621 return btof(getPayloadPointer(YAW_RATE), 2, 1000);
00622 }
00623
00624 ostream &DataPlatformRotation::printMessage(ostream &stream)
00625 {
00626 stream << "Platform Rotationa Rate Data" << endl;
00627 stream << "============================" << endl;
00628 stream << "Roll : " << getRollRate() << endl;
00629 stream << "Pitch: " << getPitchRate() << endl;
00630 stream << "Yaw : " << getYawRate() << endl;
00631 return stream;
00632 }
00633
00634
00635
00636 MESSAGE_CONSTRUCTORS(DataPowerSystem, 1 + getBatteryCount() * 5)
00637
00638 MESSAGE_CONVENIENCE_FNS(DataPowerSystem, DATA_POWER_SYSTEM)
00639
00640 uint8_t DataPowerSystem::getBatteryCount()
00641 {
00642 return *getPayloadPointer(0);
00643 }
00644
00645 double DataPowerSystem::getChargeEstimate(uint8_t battery)
00646 {
00647 int offset = 1
00648 + battery * 2;
00649 return btof(getPayloadPointer(offset), 2, 100);
00650 }
00651
00652 int16_t DataPowerSystem::getCapacityEstimate(uint8_t battery)
00653 {
00654 int offset = 1
00655 + 2 * getBatteryCount()
00656 + battery * 2;
00657 return btoi(getPayloadPointer(offset), 2);
00658 }
00659
00660 DataPowerSystem::BatteryDescription DataPowerSystem::getDescription(uint8_t battery)
00661 {
00662 int offset = 1
00663 + 4 * getBatteryCount()
00664 + battery;
00665 return BatteryDescription(*getPayloadPointer(offset));
00666 }
00667
00668 ostream &DataPowerSystem::printMessage(ostream &stream)
00669 {
00670 stream << "Power System Status Data" << endl;
00671 stream << "========================" << endl;
00672 int num_bat = getBatteryCount();
00673 stream << "Number of Batteries: " << num_bat << endl;
00674 for (int i = 0; i < num_bat; ++i)
00675 {
00676 stream << "Battery " << i << ":" << endl;
00677 stream << " Charge Estimate : " << getChargeEstimate(i) << endl;
00678 stream << " Capacity Estimate: " << getCapacityEstimate(i) << endl;
00679 stream << " Present : " << (getDescription(0).isPresent() ? "yes" : "no") << endl;
00680 stream << " In Use : " << (getDescription(0).isInUse() ? "yes" : "no") << endl;
00681 stream << " Type : ";
00682 switch (getDescription(0).getType())
00683 {
00684 case BatteryDescription::EXTERNAL:
00685 stream << "External" << endl;
00686 break;
00687 case BatteryDescription::LEAD_ACID:
00688 stream << "Lead-Acid" << endl;
00689 break;
00690 case BatteryDescription::NIMH:
00691 stream << "NiMH" << endl;
00692 break;
00693 case BatteryDescription::GASOLINE:
00694 stream << "Internal Combustion Engine" << endl;
00695 break;
00696 default:
00697 stream << "Unknown Type" << endl;
00698 break;
00699 }
00700 }
00701
00702 return stream;
00703 }
00704
00705
00706
00707 MESSAGE_CONSTRUCTORS(DataProcessorStatus, (1 + getProcessCount() * 2))
00708
00709 MESSAGE_CONVENIENCE_FNS(DataProcessorStatus, DATA_PROC_STATUS)
00710
00711 uint8_t DataProcessorStatus::getProcessCount()
00712 {
00713 return *getPayloadPointer();
00714 }
00715
00716 int16_t DataProcessorStatus::getErrorCount(int process)
00717 {
00718 return btoi(getPayloadPointer(1 + process * 2), 2);
00719 }
00720
00721 ostream &DataProcessorStatus::printMessage(ostream &stream)
00722 {
00723 stream << "Processor Status" << endl;
00724 stream << "================" << endl;
00725 stream << "Process Count : " << (int) (getProcessCount()) << endl;
00726 for (unsigned int i = 0; i < getProcessCount(); ++i)
00727 {
00728 stream << "Process " << i << " Errors: " << getErrorCount(i) << endl;
00729 }
00730 return stream;
00731 }
00732
00733
00734
00735 MESSAGE_CONSTRUCTORS(DataRangefinders, (1 + getRangefinderCount() * 2))
00736
00737 MESSAGE_CONVENIENCE_FNS(DataRangefinders, DATA_DISTANCE_DATA)
00738
00739 uint8_t DataRangefinders::getRangefinderCount()
00740 {
00741 return *getPayloadPointer();
00742 }
00743
00744 int16_t DataRangefinders::getDistance(int rangefinder)
00745 {
00746 return btoi(getPayloadPointer(1 + 2 * rangefinder), 2);
00747 }
00748
00749 ostream &DataRangefinders::printMessage(ostream &stream)
00750 {
00751 stream << "Rangefinder Data" << endl;
00752 stream << "================" << endl;
00753 stream << "Rangefinder Count: " << (int) (getRangefinderCount()) << endl;
00754 for (unsigned int i = 0; i < getRangefinderCount(); ++i)
00755 {
00756 stream << "Distance " << i << " : " << getDistance(i) << endl;
00757 }
00758 return stream;
00759 }
00760
00761
00762
00763 MESSAGE_CONSTRUCTORS(DataRangefinderTimings, (1 + getRangefinderCount() * 6))
00764
00765 MESSAGE_CONVENIENCE_FNS(DataRangefinderTimings, DATA_DISTANCE_TIMING)
00766
00767 uint8_t DataRangefinderTimings::getRangefinderCount()
00768 {
00769 return *getPayloadPointer();
00770 }
00771
00772 int16_t DataRangefinderTimings::getDistance(int rangefinder)
00773 {
00774 return btoi(getPayloadPointer(1 + 2 * rangefinder), 2);
00775 }
00776
00777 uint32_t DataRangefinderTimings::getAcquisitionTime(int rangefinder)
00778 {
00779 return btou(getPayloadPointer(1 + 2 * getRangefinderCount() + 4 * rangefinder), 4);
00780 }
00781
00782 ostream &DataRangefinderTimings::printMessage(ostream &stream)
00783 {
00784 stream << "Rangefinder Timing Data" << endl;
00785 stream << "=======================" << endl;
00786 stream << "Rangefinder Count : " << (int) (getRangefinderCount()) << endl;
00787 for (unsigned int i = 0; i < getRangefinderCount(); ++i)
00788 {
00789 stream << "Rangefinder " << i << ":" << endl;
00790 stream << " Distance : " << getDistance(i) << endl;
00791 stream << " Acquisition Time: " << getAcquisitionTime(i) << endl;
00792 }
00793 return stream;
00794 }
00795
00796
00797
00798 MESSAGE_CONSTRUCTORS(DataRawAcceleration, PAYLOAD_LEN)
00799
00800 MESSAGE_CONVENIENCE_FNS(DataRawAcceleration, DATA_ACCEL_RAW)
00801
00802 uint16_t DataRawAcceleration::getX()
00803 {
00804 return btou(getPayloadPointer(X), 2);
00805 }
00806
00807 uint16_t DataRawAcceleration::getY()
00808 {
00809 return btou(getPayloadPointer(Y), 2);
00810 }
00811
00812 uint16_t DataRawAcceleration::getZ()
00813 {
00814 return btou(getPayloadPointer(Z), 2);
00815 }
00816
00817 ostream &DataRawAcceleration::printMessage(ostream &stream)
00818 {
00819 stream << "Raw Acceleration Data" << endl;
00820 stream << "=====================" << endl;
00821 stream << "X: 0x" << hex << getX() << endl;
00822 stream << "Y: 0x" << getY() << endl;
00823 stream << "Z: 0x" << getZ() << dec << endl;
00824 return stream;
00825 }
00826
00827
00828
00829 MESSAGE_CONSTRUCTORS(DataRawCurrent, (1 + getCurrentCount() * 2))
00830
00831 MESSAGE_CONVENIENCE_FNS(DataRawCurrent, DATA_CURRENT_RAW)
00832
00833 uint8_t DataRawCurrent::getCurrentCount()
00834 {
00835 return *getPayloadPointer();
00836 }
00837
00838 uint16_t DataRawCurrent::getCurrent(int current)
00839 {
00840 return btou(getPayloadPointer(1 + current * 2), 2);
00841 }
00842
00843 ostream &DataRawCurrent::printMessage(ostream &stream)
00844 {
00845 stream << "Raw Current Data" << endl;
00846 stream << "================" << endl;
00847 stream << hex;
00848 for (unsigned int i = 0; i < getCurrentCount(); ++i)
00849 {
00850 stream << "Current " << i << ": 0x" << getCurrent(i) << endl;
00851 }
00852 stream << dec;
00853 return stream;
00854 }
00855
00856
00857
00858 MESSAGE_CONSTRUCTORS(DataRawGyro, PAYLOAD_LEN)
00859
00860 MESSAGE_CONVENIENCE_FNS(DataRawGyro, DATA_GYRO_RAW)
00861
00862 uint16_t DataRawGyro::getRoll()
00863 {
00864 return btou(getPayloadPointer(ROLL), 2);
00865 }
00866
00867 uint16_t DataRawGyro::getPitch()
00868 {
00869 return btou(getPayloadPointer(PITCH), 2);
00870 }
00871
00872 uint16_t DataRawGyro::getYaw()
00873 {
00874 return btou(getPayloadPointer(YAW), 2);
00875 }
00876
00877 ostream &DataRawGyro::printMessage(ostream &stream)
00878 {
00879 stream << "Raw Gyro Data" << endl;
00880 stream << "=============" << endl;
00881 stream << "Roll : 0x" << hex << getRoll() << endl;
00882 stream << "Pitch: 0x" << getPitch() << endl;
00883 stream << "Yaw : 0x" << getYaw() << dec << endl;
00884 return stream;
00885 }
00886
00887
00888
00889 MESSAGE_CONSTRUCTORS(DataRawMagnetometer, PAYLOAD_LEN)
00890
00891 MESSAGE_CONVENIENCE_FNS(DataRawMagnetometer, DATA_MAGNETOMETER_RAW)
00892
00893 uint16_t DataRawMagnetometer::getX()
00894 {
00895 return btou(getPayloadPointer(X), 2);
00896 }
00897
00898 uint16_t DataRawMagnetometer::getY()
00899 {
00900 return btou(getPayloadPointer(Y), 2);
00901 }
00902
00903 uint16_t DataRawMagnetometer::getZ()
00904 {
00905 return btou(getPayloadPointer(Z), 2);
00906 }
00907
00908 ostream &DataRawMagnetometer::printMessage(ostream &stream)
00909 {
00910 stream << "Raw Magnetometer Data" << endl;
00911 stream << "=====================" << endl;
00912 stream << "X: 0x" << hex << getX() << endl;
00913 stream << "Y: 0x" << getY() << endl;
00914 stream << "Z: 0x" << getZ() << dec << endl;
00915 return stream;
00916 }
00917
00918
00919
00920 MESSAGE_CONSTRUCTORS(DataRawOrientation, PAYLOAD_LEN)
00921
00922 MESSAGE_CONVENIENCE_FNS(DataRawOrientation, DATA_ORIENT_RAW)
00923
00924 uint16_t DataRawOrientation::getRoll()
00925 {
00926 return btou(getPayloadPointer(ROLL), 2);
00927 }
00928
00929 uint16_t DataRawOrientation::getPitch()
00930 {
00931 return btou(getPayloadPointer(PITCH), 2);
00932 }
00933
00934 uint16_t DataRawOrientation::getYaw()
00935 {
00936 return btou(getPayloadPointer(YAW), 2);
00937 }
00938
00939 ostream &DataRawOrientation::printMessage(ostream &stream)
00940 {
00941 stream << "Raw Orientation Data" << endl;
00942 stream << "====================" << endl;
00943 stream << "Roll : 0x" << hex << getRoll() << endl;
00944 stream << "Pitch: 0x" << getPitch() << endl;
00945 stream << "Yaw : 0x" << getYaw() << dec << endl;
00946 return stream;
00947 }
00948
00949
00950
00951 MESSAGE_CONSTRUCTORS(DataRawTemperature, (1 + 2 * getTemperatureCount()))
00952
00953 MESSAGE_CONVENIENCE_FNS(DataRawTemperature, DATA_TEMPERATURE_RAW)
00954
00955 uint8_t DataRawTemperature::getTemperatureCount()
00956 {
00957 return *getPayloadPointer();
00958 }
00959
00960 uint16_t DataRawTemperature::getTemperature(int temperature)
00961 {
00962 return btou(getPayloadPointer(1 + 2 * temperature), 2);
00963 }
00964
00965 ostream &DataRawTemperature::printMessage(ostream &stream)
00966 {
00967 stream << "Raw Temperature Data" << endl;
00968 stream << "====================" << endl;
00969 stream << "Temperature Count: " << (int) (getTemperatureCount()) << endl;
00970 stream << hex;
00971 for (unsigned i = 0; i < getTemperatureCount(); ++i)
00972 {
00973 stream << "Temperature " << i << " : 0x" << getTemperature(i) << endl;
00974 }
00975 stream << dec;
00976 return stream;
00977 }
00978
00979
00980
00981 MESSAGE_CONSTRUCTORS(DataRawVoltage, (1 + 2 * getVoltageCount()))
00982
00983 MESSAGE_CONVENIENCE_FNS(DataRawVoltage, DATA_VOLTAGE_RAW)
00984
00985 uint8_t DataRawVoltage::getVoltageCount()
00986 {
00987 return *getPayloadPointer();
00988 }
00989
00990 uint16_t DataRawVoltage::getVoltage(int temperature)
00991 {
00992 return btou(getPayloadPointer(1 + 2 * temperature), 2);
00993 }
00994
00995 ostream &DataRawVoltage::printMessage(ostream &stream)
00996 {
00997 stream << "Raw Voltage Data" << endl;
00998 stream << "================" << endl;
00999 stream << "Voltage Count: " << (int) (getVoltageCount()) << endl;
01000 stream << hex;
01001 for (unsigned i = 0; i < getVoltageCount(); ++i)
01002 {
01003 stream << "Voltage " << i << " : 0x" << getVoltage(i) << endl;
01004 }
01005 stream << dec;
01006 return stream;
01007 }
01008
01009
01010
01011 MESSAGE_CONSTRUCTORS(DataSafetySystemStatus, 2)
01012
01013 MESSAGE_CONVENIENCE_FNS(DataSafetySystemStatus, DATA_SAFETY_SYSTEM)
01014
01015 uint16_t DataSafetySystemStatus::getFlags()
01016 {
01017 return btou(getPayloadPointer(), 2);
01018 }
01019
01020 ostream &DataSafetySystemStatus::printMessage(ostream &stream)
01021 {
01022 stream << "Safety System Status Data" << endl;
01023 stream << "=========================" << endl;
01024 stream << "Flags: " << getFlags() << endl;
01025 return stream;
01026 }
01027
01028
01029 DataSystemStatus::DataSystemStatus(void *input, size_t msg_len) : Message(input, msg_len)
01030 {
01031 voltages_offset = 4;
01032 currents_offset = voltages_offset + 1 + getVoltagesCount() * 2;
01033 temperatures_offset = currents_offset + 1 + getCurrentsCount() * 2;
01034
01035 size_t expect_len = (7 + 2 * getVoltagesCount() + 2 * getCurrentsCount() + 2 * getTemperaturesCount());
01036 if (getPayloadLength() != expect_len)
01037 {
01038 stringstream ss;
01039 ss << "Bad payload length: actual=" << getPayloadLength();
01040 ss << " vs. expected=" << expect_len;
01041 throw new MessageException(ss.str().c_str(), MessageException::INVALID_LENGTH);
01042 }
01043 }
01044
01045 DataSystemStatus::DataSystemStatus(const DataSystemStatus &other) : Message(other)
01046 {
01047 }
01048
01049 MESSAGE_CONVENIENCE_FNS(DataSystemStatus, DATA_SYSTEM_STATUS)
01050
01051 uint32_t DataSystemStatus::getUptime()
01052 {
01053 return btou(getPayloadPointer(0), 4);
01054 }
01055
01056 uint8_t DataSystemStatus::getVoltagesCount()
01057 {
01058 return *getPayloadPointer(voltages_offset);
01059 }
01060
01061 double DataSystemStatus::getVoltage(uint8_t index)
01062 {
01063 return btof(getPayloadPointer(voltages_offset + 1 + (index * 2)), 2, 100);
01064 }
01065
01066 uint8_t DataSystemStatus::getCurrentsCount()
01067 {
01068 return *getPayloadPointer(currents_offset);
01069 }
01070
01071 double DataSystemStatus::getCurrent(uint8_t index)
01072 {
01073 return btof(getPayloadPointer(currents_offset + 1 + (index * 2)), 2, 100);
01074 }
01075
01076 uint8_t DataSystemStatus::getTemperaturesCount()
01077 {
01078 return *getPayloadPointer(temperatures_offset);
01079 }
01080
01081 double DataSystemStatus::getTemperature(uint8_t index)
01082 {
01083 return btof(getPayloadPointer(temperatures_offset + 1 + (index * 2)), 2, 100);
01084 }
01085
01086 ostream &DataSystemStatus::printMessage(ostream &stream)
01087 {
01088 stream << "System Status" << endl;
01089 stream << "=============" << endl;
01090 stream << "Uptime : " << getUptime() << endl;
01091 stream << "Voltage Count : " << (int) (getVoltagesCount()) << endl;
01092 stream << "Voltages : ";
01093 for (unsigned i = 0; i < getVoltagesCount(); ++i)
01094 {
01095 stream << getVoltage(i);
01096 if ((int) i != (getVoltagesCount() - 1)) { stream << ", "; }
01097 }
01098 stream << endl;
01099 stream << "Current Count : " << (int) (getCurrentsCount()) << endl;
01100 stream << "Currents : ";
01101 for (unsigned i = 0; i < getCurrentsCount(); ++i)
01102 {
01103 stream << getCurrent(i);
01104 if ((int) i != (getCurrentsCount() - 1)) { stream << ", "; }
01105 }
01106 stream << endl;
01107 stream << "Temperature Count: " << (int) (getTemperaturesCount()) << endl;
01108 stream << "Temperatures : ";
01109 for (unsigned i = 0; i < getTemperaturesCount(); ++i)
01110 {
01111 stream << getTemperature(i);
01112 if ((int) i != (getTemperaturesCount() - 1)) { stream << ", "; }
01113 }
01114 stream << endl;
01115 return stream;
01116 }
01117
01118
01119
01120 MESSAGE_CONSTRUCTORS(DataVelocity, PAYLOAD_LEN)
01121
01122 MESSAGE_CONVENIENCE_FNS(DataVelocity, DATA_VELOCITY_SETPT)
01123
01124 double DataVelocity::getTranslational()
01125 {
01126 return btof(getPayloadPointer(TRANS_VEL), 2, 100);
01127 }
01128
01129 double DataVelocity::getRotational()
01130 {
01131 return btof(getPayloadPointer(ROTATIONAL), 2, 100);
01132 }
01133
01134 double DataVelocity::getTransAccel()
01135 {
01136 return btof(getPayloadPointer(TRANS_ACCEL), 2, 100);
01137 }
01138
01139 ostream &DataVelocity::printMessage(ostream &stream)
01140 {
01141 stream << "Velocity Setpoints" << endl;
01142 stream << "==================" << endl;
01143 stream << "Translational:" << getTranslational() << endl;
01144 stream << "Rotational: " << getRotational() << endl;
01145 stream << "Trans Accel: " << getTransAccel() << endl;
01146 return stream;
01147 }
01148
01149 };
01150