diff --git a/bcdrivertinycan.cpp b/bcdrivertinycan.cpp index b676dfa..8510adb 100644 --- a/bcdrivertinycan.cpp +++ b/bcdrivertinycan.cpp @@ -185,17 +185,74 @@ void BCDriverTinyCan::resetDriver() TransmitResult BCDriverTinyCan::readRawByte( uint32_t deviceID, uint8_t registerID ) const { + qDebug() << " --- CAN Read Byte: Device: "<< deviceID << " register: " << registerID << " TRY! "; + + struct TCanMsg msg; + int err, retry = 20; + int timeout = 80; + + unsigned char receipient = (unsigned char) deviceID; + unsigned char reg = (unsigned char) registerID; + + msg.MsgFlags = 0L; + msg.Id = receipient; + msg.MsgLen = 2; + msg.MsgData[0] = 0x00; + msg.MsgData[1] = reg; + + CanTransmit(0, &msg, 1); + + while(timeout-- && CanTransmitGetCount(0)) + bc::delay_millis( cTIMEOUT_MS ); + + if (timeout == -1) + qDebug() << "error: could not send value to node "; + +retry: + + timeout = 80; + while(timeout-- && !CanReceiveGetCount(0)) + bc::delay_millis( cTIMEOUT_MS ); + + if (timeout == -1) + { + qDebug() << "error: no response from node"; + return 0; + } + + if ((err = CanReceive(0, &msg, 1)) > 0) + { + if (--retry && (msg.Id != BIB || msg.MsgLen != 4 || msg.MsgData[1] != reg)) + goto retry; + + if (!retry) + { + qDebug() << "XXX error: no response from node"; + return 0; + } + qDebug() << " --- CAN Read Byte: Device: "<< deviceID << " register: " << registerID << " BYTE: " << (uint32_t) msg.MsgData[3]; + return (unsigned int) msg.MsgData[3]; + } + else + { + qDebug() << "Error:" <readRawByte( deviceID, registerID ); } @@ -212,7 +212,7 @@ TransmitResult BCTransmitter::readByteValue( uint32_t deviceID, uint8_t register TransmitResult BCTransmitter::readWordValue( uint32_t deviceID, uint8_t registerID ) { - qDebug() << " --- YES: Read WordValue: " << registerID; + //qDebug() << " --- YES: Read WordValue: " << registerID; uint32_t result{}; // hi byte Leseversuch. diff --git a/bcvaluemodel.cpp b/bcvaluemodel.cpp index 28dd96f..5079ce9 100644 --- a/bcvaluemodel.cpp +++ b/bcvaluemodel.cpp @@ -88,9 +88,9 @@ void BCValueModel::onValueUpdated( int row, BCValue::State state, const QString& BCValue& value = *(_valueList[row].get()); QModelIndex idx = index(row,1); - qDebug(); - qDebug() << " --- OLD:"; - value.dumpValue(); + //qDebug(); + //qDebug() << " --- OLD:"<< newVisisbleValue; + //value.dumpValue(); value.state = state; @@ -99,8 +99,8 @@ void BCValueModel::onValueUpdated( int row, BCValue::State state, const QString& value.visibleValue = newVisisbleValue; } - qDebug() << " NEW: " << newVisisbleValue << ""; - value.dumpValue(); + //qDebug() << " --- NEW: " << newVisisbleValue; + //value.dumpValue(); // wir schicken auf jeden fall einen update request emit dataChanged(idx, idx, {Qt::DisplayRole, Qt::EditRole}); diff --git a/resources/bikeinfo.xml b/resources/bikeinfo.xml index a3319df..cd8d234 100644 --- a/resources/bikeinfo.xml +++ b/resources/bikeinfo.xml @@ -1,24 +1,18 @@ - - + +