MotorControlModuleSDFM_TMS3.../Projects/EFC_Communication/UMLibrary/technological/function/InverterDebug.cpp
2024-06-07 11:12:56 +03:00

128 lines
2.8 KiB
C++
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

/*
* InverterDebug.cpp
*
* Created on: 4 апр. 2017 г.
* Author: titov
*/
#include "InverterDebug.hh"
#include <cmath>
#include <cstring>
technological::function::InverterDebug::InverterDebug( peripheral::IPwmOverride & u, peripheral::IPwmOverride & v, peripheral::IPwmOverride & w,
ResourceKeeper<driver::IInverter> & inv ) :
pwm_u(u), pwm_v(v), pwm_w(w),
inverter_resource(inv), inverter(nullptr) {}
bool technological::function::InverterDebug::validate( Input & input ) {
using namespace std;
return ( ( input.time_a >= -1.0f && input.time_a <= 1.0f ) || isnan(input.time_a) )
&& ( ( input.time_b >= -1.0f && input.time_b <= 1.0f ) || isnan(input.time_b) )
&& ( ( input.time_c >= -1.0f && input.time_c <= 1.0f ) || isnan(input.time_c) );
}
void technological::function::InverterDebug::prepare_time( const Input & input,
float (& time)[3] ) {
using namespace std;
if( isnan(input.time_a) ) {
pwm_u.overrideDisableOutput();
time[0] = 0.0f;
} else {
pwm_u.resetOverride();
time[0] = input.time_a;
}
if( isnan(input.time_b) ) {
pwm_v.overrideDisableOutput();
time[1] = 0.0f;
} else {
pwm_v.resetOverride();
time[1] = input.time_b;
}
if( isnan(input.time_c) ) {
pwm_w.overrideDisableOutput();
time[2] = 0.0f;
} else {
pwm_w.resetOverride();
time[2] = input.time_c;
}
}
bool technological::function::InverterDebug::run( const char * value, std::size_t size ) {
using namespace std;
if( size != sizeof(Input) )
return false;
Input input;
std::memcpy( &input, value, size );
if( not validate(input) )
return false;
if( not inverter ) {
Local<driver::IInverter> local_inverter( &inverter_resource );
if( local_inverter ) {
float time[3];
prepare_time( input, time );
local_inverter->enPulse();
local_inverter->pwm( time[0], time[1], time[2] );
local_inverter.release( inverter );
}
} else {
float time[3];
prepare_time( input, time );
inverter->enPulse();
inverter->pwm( time[0], time[1], time[2] );
}
return inverter;
}
void technological::function::InverterDebug::stop() {
if( inverter ) {
pwm_u.resetOverride();
pwm_v.resetOverride();
pwm_w.resetOverride();
inverter->disPulse();
inverter_resource.release( inverter );
}
}
short technological::function::InverterDebug::getState() const {
return inverter ? ITechFunction::EXECUTE : ITechFunction::DISABLE;
}
technological::function::InverterDebug::~InverterDebug() noexcept {
inverter_resource.release( inverter );
}