/*************************************************************************** BionxControl Copyright © 2025 christoph holzheuer christoph.holzheuer@gmail.com Using: mhs_can_drv.c © 2011 - 2023 by MHS-Elektronik GmbH & Co. KG, Germany Klaus Demlehner, klaus@mhs-elektronik.de @see www.mhs-elektronik.de Based on Bionx data type descriptions from: BigXionFlasher USB V 0.2.4 rev. 97 © 2011-2013 by Thomas Koenig @see www.bigxionflasher.org Bionx Bike Info © 2018 Thorsten Schmidt (tschmidt@ts-soft.de) @see www.ts-soft.de This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation; either version 3 of the License, or (at your option) any later version. @see https://github.com/bikemike/bionx-bikeinfo ***************************************************************************/ #include #include /// reader functions TransmitResult readDummy( const BCAbstractTransmitter& transmitter, uint32_t deviceID, uint8_t registerID ) { qDebug() << " --- NO: Read DUMMY: " << registerID; return std::unexpected( QString("NO: Read DUMMY: %1 : %2 ").arg( deviceID, registerID ) ); } TransmitResult readByteValue( const BCAbstractTransmitter& transmitter, uint32_t deviceID, uint8_t registerID ) { qDebug() << " --- YES: Read ByteValue: " << registerID; // Wir lesen nur ein Byte und gut. return transmitter.readByte( deviceID, registerID ); } TransmitResult readWordValue( const BCAbstractTransmitter& transmitter, uint32_t deviceID, uint8_t registerID ) { qDebug() << " --- YES: Read WordValue: " << registerID; //getValue(CONSOLE, CONSOLE_SN_PN_HI) << 8) + getValue(CONSOLE, CONSOLE_SN_PN_LO)), uint32_t result{}; // hi byte Leseversuch. TransmitResult value = transmitter.readByte( deviceID, registerID ); // Fehler? dann weg if( !value) return std::unexpected( value.error() ); // hi byte speichern result = *value << 8; // low byte, liegt im followup register: +1 value = transmitter.readByte( deviceID, registerID+1 ); if( !value) return std::unexpected( value.error() ); result += *value; return result; } TransmitResult readSpeedValue( const BCAbstractTransmitter& transmitter, uint32_t deviceID, uint8_t registerID ) { return 0x0; } TransmitResult readODOValue( const BCAbstractTransmitter& transmitter, uint32_t deviceID, uint8_t registerID ) { return 0x0; } TransmitResult readVoltValue( const BCAbstractTransmitter& transmitter, uint32_t deviceID, uint8_t registerID ) { return 0x0; } TransmitResult readCircValue( const BCAbstractTransmitter& transmitter, uint32_t deviceID, uint8_t registerID ) { return 0x0; } /** * @brief BCValueType::BCValueType */ BCValueType::BCValueType() { } BCValueType::BCValueType(QString unitKey_, QString unitLabel_, double factor_, optDouble min_, optDouble max_ ) : unitLabel{unitLabel_}, factor{factor_}, min{min_}, max{max_} { std::optional readFn = fetchReadValueFunction( unitKey_ ); readValueFunc = readFn.has_value() ? readFn.value() : readDummy; } QString BCValueType::formatValue( uint32_t value ) const { if( factor == 1 ) return QString::number( value ); double result = value * factor; return QString::number(result, 'f', 2); } std::optional BCValueType::fetchReadValueFunction( const QString& unitTypeKey ) { static QHash s_bcReadValueFunctions { { "Byte", readByteValue }, { "Word", readWordValue }, { "Assist", readByteValue }, { "Kmh", readByteValue }, { "Percent",readByteValue }, { "KWh", readByteValue }, { "Watt", readByteValue }, { "Km", readByteValue }, { "Mm", readByteValue }, { "Sec", readByteValue }, { "Degree", readByteValue }, { "SoC", readByteValue }, { "Odo", readByteValue }, }; if( !s_bcReadValueFunctions.contains( unitTypeKey ) ) return std::nullopt; return s_bcReadValueFunctions[unitTypeKey]; } std::optional BCValueType::fetchValueType( const QString& unitTypeKey ) { static QHash s_bcDataTypes { { "Byte", new BCValueType( "Byte", "", 1.5625F) }, { "Word", new BCValueType( "Word", "", 1.5625F) }, { "Percent", new BCValueType( "Byte", "%", 1.5625 ) }, { "AssInit", new BCValueType( "Byte", "", 1.0, 0 ,4 ) }, { "Assist", new BCValueType( "Byte", "%", 0,400 ) } /* { "KWh", new BCValueType( "kwh", 1.5625 ) }, { "Watt", new BCValueType( "w", 1.5625 ) }, { "Km", new BCValueType( "km", 1.5625 ) }, { "Kmh", new BCValueType( "km/h", 0.1 ) }, { "Mm", new BCValueType( "mm", 1.5625 ) }, { "Sec", new BCValueType( "s", 1.5625 ) }, { "Degree", new BCValueType( "°C", 1.0 ) }, { "SoC", new BCValueType( "%", 1.5625 ) }, { "Odo", new BCValueType( "km", 1.5625 ) }, { "Assist", new BCValueType( "%" ) }, */ }; if( !s_bcDataTypes.contains( unitTypeKey ) ) return std::nullopt; return s_bcDataTypes[unitTypeKey]; } /// ----