prepare upcoming adapter3 firmware enhancements
This commit is contained in:
@@ -1911,6 +1911,10 @@ result_t MainLoop::executeInfo(const vector<string>& args, const string& user, o
|
||||
if (!m_updateCheck.empty()) {
|
||||
*ostream << "update check: " << m_updateCheck << "\n";
|
||||
}
|
||||
string info = m_device->getEnhancedInfos();
|
||||
if (!info.empty()) {
|
||||
*ostream << "device: " << info << "\n";
|
||||
}
|
||||
if (!user.empty()) {
|
||||
*ostream << "user: " << user << "\n";
|
||||
}
|
||||
|
||||
+97
-4
@@ -60,6 +60,8 @@ namespace ebusd {
|
||||
#define ENH_RES_RECEIVED ((uint8_t)0x1)
|
||||
#define ENH_REQ_START ((uint8_t)0x2)
|
||||
#define ENH_RES_STARTED ((uint8_t)0x2)
|
||||
#define ENH_REQ_INFO ((uint8_t)0x3)
|
||||
#define ENH_RES_INFO ((uint8_t)0x3)
|
||||
#define ENH_RES_FAILED ((uint8_t)0xa)
|
||||
#define ENH_RES_ERROR_EBUS ((uint8_t)0xb)
|
||||
#define ENH_RES_ERROR_HOST ((uint8_t)0xc)
|
||||
@@ -79,7 +81,8 @@ Device::Device(const char* name, bool checkDevice, unsigned int latency, bool re
|
||||
: m_name(name), m_checkDevice(checkDevice),
|
||||
m_latency(HOST_LATENCY_MS+latency), m_readOnly(readOnly), m_initialSend(initialSend),
|
||||
m_enhancedProto(enhancedProto), m_fd(-1), m_listener(nullptr), m_arbitrationMaster(SYN),
|
||||
m_arbitrationCheck(false), m_bufSize(((MAX_LEN+1+3)/4)*4), m_bufLen(0), m_bufPos(0) {
|
||||
m_arbitrationCheck(false), m_bufSize(((MAX_LEN+1+3)/4)*4), m_bufLen(0), m_bufPos(0),
|
||||
m_extraFatures(0), m_infoId(0xff), m_infoLen(0), m_infoPos(0) {
|
||||
m_buffer = reinterpret_cast<symbol_t*>(malloc(m_bufSize));
|
||||
if (!m_buffer) {
|
||||
m_bufSize = 0;
|
||||
@@ -141,8 +144,9 @@ result_t Device::open() {
|
||||
|
||||
result_t Device::afterOpen() {
|
||||
m_bufLen = 0;
|
||||
m_extraFatures = 0;
|
||||
if (m_enhancedProto) {
|
||||
symbol_t buf[2] = makeEnhancedSequence(ENH_REQ_INIT, 0); // TODO define additional feature flags
|
||||
symbol_t buf[2] = makeEnhancedSequence(ENH_REQ_INIT, 0x01); // extra feature: info
|
||||
#ifdef DEBUG_RAW_TRAFFIC
|
||||
fprintf(stdout, "raw enhanced > %2.2x %2.2x\n", buf[0], buf[1]);
|
||||
#endif
|
||||
@@ -176,6 +180,47 @@ bool Device::isValid() {
|
||||
return m_fd != -1;
|
||||
}
|
||||
|
||||
result_t Device::requestEnhancedInfo(symbol_t infoId) {
|
||||
if (!m_enhancedProto || m_extraFatures == 0 || infoId == 0xff) {
|
||||
return RESULT_ERR_INVALID_ARG;
|
||||
}
|
||||
if (m_infoId != 0xff) {
|
||||
usleep(40000);
|
||||
if (m_infoId != 0xff) {
|
||||
return RESULT_ERR_DUPLICATE;
|
||||
}
|
||||
}
|
||||
symbol_t buf[2] = makeEnhancedSequence(ENH_REQ_INFO, infoId);
|
||||
#ifdef DEBUG_RAW_TRAFFIC
|
||||
fprintf(stdout, "raw enhanced > %2.2x %2.2x\n", buf[0], buf[1]);
|
||||
#endif
|
||||
m_infoPos = 0;
|
||||
m_infoId = infoId;
|
||||
if (::write(m_fd, buf, 2) != 2) {
|
||||
return RESULT_ERR_DEVICE;
|
||||
}
|
||||
return RESULT_OK;
|
||||
}
|
||||
|
||||
string Device::getEnhancedInfos() {
|
||||
if (!m_enhancedProto || m_extraFatures == 0) {
|
||||
return "";
|
||||
}
|
||||
result_t res = requestEnhancedInfo(0);
|
||||
if (res != RESULT_OK) {
|
||||
return "cannot request info";
|
||||
}
|
||||
res = requestEnhancedInfo(1);
|
||||
res = requestEnhancedInfo(2);
|
||||
res = requestEnhancedInfo(3);
|
||||
res = requestEnhancedInfo(4);
|
||||
res = requestEnhancedInfo(5);
|
||||
if (m_infoPos == 0) {
|
||||
return "did not get info";
|
||||
}
|
||||
return "";
|
||||
}
|
||||
|
||||
result_t Device::send(symbol_t value) {
|
||||
if (!isValid()) {
|
||||
return RESULT_ERR_DEVICE;
|
||||
@@ -528,9 +573,57 @@ bool Device::read(symbol_t* value, bool isAvailable, ArbitrationState* arbitrati
|
||||
m_arbitrationMaster = SYN;
|
||||
m_arbitrationCheck = false;
|
||||
}
|
||||
// TODO define additional feature flags
|
||||
m_extraFatures = data;
|
||||
if (m_listener != nullptr) {
|
||||
m_listener->notifyStatus(false, "reset");
|
||||
m_listener->notifyStatus(false, (m_extraFatures&0x01) ? "reset, supports info" : "reset");
|
||||
}
|
||||
break;
|
||||
case ENH_RES_INFO:
|
||||
if (m_infoLen == 0) {
|
||||
if (data<=16) { // max length
|
||||
m_infoLen = data;
|
||||
m_infoPos = 0;
|
||||
}
|
||||
} else if (m_infoPos < m_infoLen) {
|
||||
m_infoBuf[m_infoPos++] = data;
|
||||
if (m_infoPos >= m_infoLen) {
|
||||
unsigned int val;
|
||||
ostringstream stream;
|
||||
stream << "extra info: ";
|
||||
switch ((m_infoLen<<8) | m_infoId) {
|
||||
case 0x0200:
|
||||
stream << "firmware " << static_cast<unsigned>(m_infoBuf[0]) << "." << std::hex << static_cast<unsigned>(m_infoBuf[1]) << ".";
|
||||
break;
|
||||
case 0x0901:
|
||||
case 0x0802:
|
||||
stream << (m_infoId == 1 ? "ID" : "config");
|
||||
stream << std::hex << std::setfill('0');
|
||||
for (uint8_t pos = 0; pos<m_infoPos; pos++) {
|
||||
stream << " " << std::setw(2) << static_cast<unsigned>(m_infoBuf[pos]);
|
||||
}
|
||||
break;
|
||||
case 0x0203:
|
||||
val = (static_cast<unsigned>(m_infoBuf[0])<<8) | static_cast<unsigned>(m_infoBuf[1]);
|
||||
stream << "temperature " << static_cast<unsigned>(val) << " °C";
|
||||
break;
|
||||
case 0x0204:
|
||||
val = (static_cast<unsigned>(m_infoBuf[0])<<8) | static_cast<unsigned>(m_infoBuf[1]);
|
||||
stream << "supply voltage " << static_cast<unsigned>(val) << " mV";
|
||||
break;
|
||||
case 0x0205:
|
||||
stream << "bus voltage " << std::fixed << std::setprecision(1)
|
||||
<< static_cast<float>(m_infoBuf[1] / 10.0) << " V - "
|
||||
<< static_cast<float>(m_infoBuf[0] / 10.0) << " V";
|
||||
break;
|
||||
default:
|
||||
stream << "unknown 0x" << std::hex << std::setfill('0') << std::setw(2) << static_cast<unsigned>(m_infoId)
|
||||
<< ", len " << std::dec << std::setw(0) << static_cast<unsigned>(m_infoPos);
|
||||
break;
|
||||
}
|
||||
m_listener->notifyStatus(false, stream.str().c_str());
|
||||
m_infoLen = 0;
|
||||
m_infoId = 0xff;
|
||||
}
|
||||
}
|
||||
break;
|
||||
case ENH_RES_ERROR_EBUS:
|
||||
|
||||
@@ -206,6 +206,9 @@ class Device {
|
||||
*/
|
||||
void setListener(DeviceListener* listener) { m_listener = listener; }
|
||||
|
||||
result_t requestEnhancedInfo(symbol_t infoId);
|
||||
|
||||
string getEnhancedInfos();
|
||||
|
||||
protected:
|
||||
/**
|
||||
@@ -288,6 +291,21 @@ class Device {
|
||||
|
||||
/** the read buffer read position. */
|
||||
size_t m_bufPos;
|
||||
|
||||
/** the extra features supported by the device. */
|
||||
symbol_t m_extraFatures;
|
||||
|
||||
/** the ID of the last requested info. */
|
||||
symbol_t m_infoId;
|
||||
|
||||
/** the info buffer expected length. */
|
||||
size_t m_infoLen;
|
||||
|
||||
/** the info buffer write position. */
|
||||
size_t m_infoPos;
|
||||
|
||||
/** the info buffer. */
|
||||
symbol_t m_infoBuf[16];
|
||||
};
|
||||
|
||||
|
||||
|
||||
Reference in New Issue
Block a user