reveal enhanced device version in info cmd and add to update check, unify wait

This commit is contained in:
John
2022-12-17 17:20:19 +01:00
parent cd6be6002d
commit f3d030c137
3 changed files with 64 additions and 16 deletions
+15
View File
@@ -365,6 +365,12 @@ void MainLoop::run() {
<< ",\"a\":\"other\"" << ",\"a\":\"other\""
#endif #endif
<< ",\"u\":" << (now-start); << ",\"u\":" << (now-start);
if (m_device->isEnhancedProto()) {
string ver = m_device->getEnhancedVersion();
if (!ver.empty()) {
ostr << ",\"dv\":\"" << ver << "\"";
}
}
if (m_reconnectCount) { if (m_reconnectCount) {
ostr << ",\"rc\":" << m_reconnectCount; ostr << ",\"rc\":" << m_reconnectCount;
} }
@@ -1937,12 +1943,21 @@ result_t MainLoop::executeInfo(const vector<string>& args, const string& user, o
if (!m_device->isValid()) { if (!m_device->isValid()) {
*ostream << ", invalid"; *ostream << ", invalid";
} }
bool infoAdded = false;
if (verbose) { if (verbose) {
string info = m_device->getEnhancedInfos(); string info = m_device->getEnhancedInfos();
if (!info.empty()) { if (!info.empty()) {
*ostream << ", " << info; *ostream << ", " << info;
infoAdded = true;
} }
} }
if (!infoAdded) {
string info = m_device->getEnhancedVersion();
if (!info.empty()) {
*ostream << ", firmware " << info;
}
}
*ostream << "\n"; *ostream << "\n";
if (!user.empty()) { if (!user.empty()) {
*ostream << "user: " << user << "\n"; *ostream << "user: " << user << "\n";
+29 -13
View File
@@ -184,7 +184,7 @@ bool Device::isValid() {
} }
result_t Device::requestEnhancedInfo(symbol_t infoId) { result_t Device::requestEnhancedInfo(symbol_t infoId) {
if (!m_enhancedProto || m_extraFatures == 0 || infoId == 0xff) { if (!m_enhancedProto || m_extraFatures == 0) {
return RESULT_ERR_INVALID_ARG; return RESULT_ERR_INVALID_ARG;
} }
for (unsigned int i = 0; i < 4; i++) { for (unsigned int i = 0; i < 4; i++) {
@@ -196,16 +196,24 @@ result_t Device::requestEnhancedInfo(symbol_t infoId) {
if (m_infoId != 0xff) { if (m_infoId != 0xff) {
return RESULT_ERR_DUPLICATE; return RESULT_ERR_DUPLICATE;
} }
if (infoId == 0xff) {
// just waited for completion
return RESULT_OK;
}
return sendEnhancedInfoRequest(infoId);
}
result_t Device::sendEnhancedInfoRequest(symbol_t infoId) {
symbol_t buf[2] = makeEnhancedSequence(ENH_REQ_INFO, infoId); symbol_t buf[2] = makeEnhancedSequence(ENH_REQ_INFO, infoId);
#ifdef DEBUG_RAW_TRAFFIC #ifdef DEBUG_RAW_TRAFFIC
fprintf(stdout, "raw enhanced > %2.2x %2.2x\n", buf[0], buf[1]); fprintf(stdout, "raw enhanced > %2.2x %2.2x\n", buf[0], buf[1]);
fflush(stdout); fflush(stdout);
#endif #endif
m_infoPos = 0;
m_infoId = infoId;
if (::write(m_fd, buf, 2) != 2) { if (::write(m_fd, buf, 2) != 2) {
return RESULT_ERR_DEVICE; return RESULT_ERR_DEVICE;
} }
m_infoPos = 0;
m_infoId = infoId;
return RESULT_OK; return RESULT_OK;
} }
@@ -214,7 +222,7 @@ string Device::getEnhancedInfos() {
return ""; return "";
} }
result_t res; result_t res;
if (m_enhInfoTemperature.empty()) { if (m_enhInfoTemperature.empty()) { // use empty temperature for potential refresh after reset
res = requestEnhancedInfo(0); res = requestEnhancedInfo(0);
if (res != RESULT_OK) { if (res != RESULT_OK) {
return "cannot request version"; return "cannot request version";
@@ -244,11 +252,11 @@ string Device::getEnhancedInfos() {
if (res != RESULT_OK) { if (res != RESULT_OK) {
return "cannot request bus voltage"; return "cannot request bus voltage";
} }
usleep(8*40000); res = requestEnhancedInfo(0xff);
if (m_infoPos == 0) { if (res != RESULT_OK) {
return "did not get info"; m_enhInfoBusVoltage = "bus voltage unknown";
} }
return m_enhInfoTemperature + ", " + m_enhInfoSupplyVoltage + ", " + m_enhInfoBusVoltage; return "firmware " + m_enhInfoVersion + ", " + m_enhInfoTemperature + ", " + m_enhInfoSupplyVoltage + ", " + m_enhInfoBusVoltage;
} }
result_t Device::send(symbol_t value) { result_t Device::send(symbol_t value) {
@@ -644,13 +652,16 @@ bool Device::read(symbol_t* value, bool isAvailable, ArbitrationState* arbitrati
m_enhInfoSupplyVoltage = ""; m_enhInfoSupplyVoltage = "";
m_enhInfoBusVoltage = ""; m_enhInfoBusVoltage = "";
m_infoId = 0xff; m_infoId = 0xff;
m_extraFatures = data;
if (m_resetRequested) { if (m_resetRequested) {
m_resetRequested = false; m_resetRequested = false;
if (m_extraFatures&0x01) {
sendEnhancedInfoRequest(0); // request version, ignore result
}
} else { } else {
close(); // on self-reset of device close and reopen it to have a clean startup close(); // on self-reset of device close and reopen it to have a clean startup
cancelRunningArbitration(arbitrationState); cancelRunningArbitration(arbitrationState);
} }
m_extraFatures = data;
if (m_listener != nullptr) { if (m_listener != nullptr) {
m_listener->notifyStatus(false, (m_extraFatures&0x01) ? "reset, supports info" : "reset"); m_listener->notifyStatus(false, (m_extraFatures&0x01) ? "reset, supports info" : "reset");
} }
@@ -670,19 +681,24 @@ bool Device::read(symbol_t* value, bool isAvailable, ArbitrationState* arbitrati
case 0x0200: case 0x0200:
case 0x0500: // with firmware version and jumper info case 0x0500: // with firmware version and jumper info
case 0x0800: // with firmware version, jumper info, and bootloader version case 0x0800: // with firmware version, jumper info, and bootloader version
stream << "firmware " << static_cast<unsigned>(m_infoBuf[0]) << "." // version minor stream << static_cast<unsigned>(m_infoBuf[0]) << "." // version minor
<< std::hex << static_cast<unsigned>(m_infoBuf[1]); // features mask << std::hex << static_cast<unsigned>(m_infoBuf[1]); // features mask
if (m_infoLen >= 5) { if (m_infoLen >= 5) {
stream << "[" << std::setfill('0') << std::setw(2) << std::hex << static_cast<unsigned>(m_infoBuf[2]) stream << "[" << std::setfill('0') << std::setw(2) << std::hex << static_cast<unsigned>(m_infoBuf[2])
<< std::setw(2) << static_cast<unsigned>(m_infoBuf[3]) << "]"; << std::setw(2) << static_cast<unsigned>(m_infoBuf[3]) << "]";
stream << ", jumpers 0x" << std::setw(2) << static_cast<unsigned>(m_infoBuf[4]);
stream << std::setfill(' '); // reset
} }
if (m_infoLen >= 8) { if (m_infoLen >= 8) {
stream << ", bootloader " << std::dec << static_cast<unsigned>(m_infoBuf[5]); stream << "." << std::dec << static_cast<unsigned>(m_infoBuf[5]);
stream << "[" << std::setfill('0') << std::setw(2) << std::hex << static_cast<unsigned>(m_infoBuf[6]) stream << "[" << std::setfill('0') << std::setw(2) << std::hex << static_cast<unsigned>(m_infoBuf[6])
<< std::setw(2) << static_cast<unsigned>(m_infoBuf[7]) << "]"; << std::setw(2) << static_cast<unsigned>(m_infoBuf[7]) << "]";
} }
m_enhInfoVersion = stream.str();
stream.str(" ");
stream << "firmware " << m_enhInfoVersion;
if (m_infoLen >= 5) {
stream << ", jumpers 0x" << std::setw(2) << static_cast<unsigned>(m_infoBuf[4]);
}
stream << std::setfill(' '); // reset
break; break;
case 0x0901: case 0x0901:
case 0x0802: case 0x0802:
+18 -1
View File
@@ -212,12 +212,26 @@ class Device {
void setListener(DeviceListener* listener) { m_listener = listener; } void setListener(DeviceListener* listener) { m_listener = listener; }
/** /**
* Send a request for extra infos to enhanced device. * Check for a running extra infos request, wait for it to complete,
* and then send a new request for extra infos to enhanced device.
* @param infoId the ID of the info to request. * @param infoId the ID of the info to request.
* @return @a RESULT_OK on success, or an error code otherwise. * @return @a RESULT_OK on success, or an error code otherwise.
*/ */
result_t requestEnhancedInfo(symbol_t infoId); result_t requestEnhancedInfo(symbol_t infoId);
/**
* Send a request for extra infos to enhanced device.
* @param infoId the ID of the info to request.
* @return @a RESULT_OK on success, or an error code otherwise.
*/
result_t sendEnhancedInfoRequest(symbol_t infoId);
/**
* Get the enhanced device version.
* @return @a a string with the version infos, or empty.
*/
string getEnhancedVersion() const { return m_enhInfoVersion; }
/** /**
* Retrieve/update all extra infos from an enhanced device. * Retrieve/update all extra infos from an enhanced device.
* @return @a a string with the extra infos, or empty. * @return @a a string with the extra infos, or empty.
@@ -324,6 +338,9 @@ class Device {
/** the info buffer. */ /** the info buffer. */
symbol_t m_infoBuf[16]; symbol_t m_infoBuf[16];
/** a string describing the enhanced device version. */
string m_enhInfoVersion;
/** a string describing the enhanced device temperature. */ /** a string describing the enhanced device temperature. */
string m_enhInfoTemperature; string m_enhInfoTemperature;