Files
BionxControl/bcdriver.cpp

123 lines
2.8 KiB
C++
Raw Normal View History

2025-12-26 14:07:55 +01:00
/***************************************************************************
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 <info@bigxionflasher.org>
@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
***************************************************************************/
2025-12-20 16:33:00 +01:00
#include <QDebug>
2025-12-30 14:42:49 +01:00
#include <QRandomGenerator>
2025-12-20 16:33:00 +01:00
2025-12-30 10:12:01 +01:00
#include <bcdriver.h>
2025-12-20 16:33:00 +01:00
2025-12-30 10:12:01 +01:00
BCDriver::BCDriver(QObject* parent )
2025-12-20 16:33:00 +01:00
: QObject{ parent }
{
}
2025-12-30 10:12:01 +01:00
BCDriver::DriverState BCDriver::getState() const
2025-12-20 16:33:00 +01:00
{
return _driverState;
}
/**
*
* @brief Der Slot, der das Initialisieren des Treibers auslöst.
* Teilt sich in die zwei Etappen
* - Driver dll laden
* - Driver mit der Console verbinden
* D.h. initDriver kann als Wiedereinstiegspunkt
* verwendet werden, falls der Treiber geladen wurde,
* aber die Console noch nicht eingeschaltet war.
*/
2026-01-01 00:40:27 +01:00
void BCDriverDummy::onStartDriver()
2025-12-20 16:33:00 +01:00
{
2026-01-01 00:40:27 +01:00
_driverState = DriverState::Ready;
emit driverStateChanged( DriverState::Ready, "Driver Ready." );
}
/*
2025-12-20 16:33:00 +01:00
try
{
// erstmal die Dll Laden: State::sIdle -> State::sLoaded
2025-12-21 18:31:16 +01:00
if( _driverState == DriverState::NotPresent)
2026-01-01 00:40:27 +01:00
_driverState = loadAndInitDriver();
2025-12-20 16:33:00 +01:00
2025-12-29 13:05:35 +01:00
emit stateChanged( _driverState );
2025-12-20 16:33:00 +01:00
}
catch( std::exception& except )
{
//::CanDownDriver();
2026-01-01 00:40:27 +01:00
//::UnloadAndInitDriver();
2025-12-20 16:33:00 +01:00
2026-01-01 00:40:27 +01:00
emit statusHint( except.what() );
2025-12-20 16:33:00 +01:00
}
2026-01-01 00:40:27 +01:00
*/
2025-12-20 16:33:00 +01:00
2025-12-30 14:42:49 +01:00
/// -----------------------------------------------------------------------------------
/// -----------------------------------------------------------------------------------
/**
* @brief BCDriverDummy::BCDriverDummy
* @param parent
*/
BCDriverDummy::BCDriverDummy( QObject* parent )
: BCDriver(parent)
{
}
uint32_t BCDriverDummy::readRawByte( uint32_t deviceID, uint8_t registerID ) const
{
2026-01-01 01:58:54 +01:00
if( getState() != DriverState::Ready)
throw BCException( "readRawValue error: driver not loaded." );
2025-12-30 14:42:49 +01:00
uint32_t myRandomByte = static_cast<uint32_t>(QRandomGenerator::global()->bounded(256));
return myRandomByte;
}
void BCDriverDummy::writeRawByte( uint32_t deviceID, uint8_t registerID, uint8_t value ) const
{
if( getState() != DriverState::Ready)
throw BCException( "readRawValue error: driver not loaded." );
qDebug() << " --- BCDriverTinyCan writeRawValue: " << value;
return;
}
2025-12-20 16:33:00 +01:00