Skip to content

Commit

Permalink
Fix inheritance "valve_DO2" (#598)
Browse files Browse the repository at this point in the history
* Remove DO2

* Add test valve_DO2

* Add explict to constructor valve_DO2

* Add get_state

* Add test  for valve state

* Group public methods

* Update get_valve_state test
  • Loading branch information
NogameNo-life authored Aug 3, 2023
1 parent 98b228b commit 8b726d0
Show file tree
Hide file tree
Showing 3 changed files with 54 additions and 33 deletions.
6 changes: 3 additions & 3 deletions PAC/common/PAC_dev.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -3231,21 +3231,21 @@ digital_io_device::~digital_io_device()
//-----------------------------------------------------------------------------
#ifndef DEBUG_NO_IO_MODULES

int DO2::get_state()
int valve_DO2::get_state()
{
int b1 = get_DO( DO_INDEX_1 );
int b2 = get_DO( DO_INDEX_2 );
if ( b1 == b2 ) return -1;
return b2;
}
//-----------------------------------------------------------------------------
void DO2::direct_on()
void valve_DO2::direct_on()
{
set_DO( DO_INDEX_1, 0 );
set_DO( DO_INDEX_2, 1 );
}
//-----------------------------------------------------------------------------
void DO2::direct_off()
void valve_DO2::direct_off()
{
set_DO( DO_INDEX_1, 1 );
set_DO( DO_INDEX_2, 0 );
Expand Down
62 changes: 32 additions & 30 deletions PAC/common/PAC_dev.h
Original file line number Diff line number Diff line change
Expand Up @@ -847,33 +847,6 @@ class DO1 : public digital_io_device
#endif // DEBUG_NO_IO_MODULES
};
//-----------------------------------------------------------------------------
/// @brief Устройство с двумя дискретными выходами.
///
/// Это может быть клапан, насос...
class DO2 : public digital_io_device
{
public:
DO2( const char *dev_name, device::DEVICE_TYPE type,
device::DEVICE_SUB_TYPE sub_type, u_int par_cnt ):
digital_io_device( dev_name, type, sub_type, par_cnt )
{
}

#ifndef DEBUG_NO_IO_MODULES
public:
int get_state();
void direct_on();
void direct_off();

private:
enum CONSTANTS
{
DO_INDEX_1 = 0, ///< Индекс канала дискретного выхода №1.
DO_INDEX_2, ///< Индекс канала дискретного выхода №2.
};
#endif // DEBUG_NO_IO_MODULES
};
//-----------------------------------------------------------------------------
class valve_DO2_DI2_bistable;

/// @brief Устройство с обратными связями.
Expand Down Expand Up @@ -3757,12 +3730,41 @@ class valve_DO1 : public valve
};
//-----------------------------------------------------------------------------
/// @brief Клапан с двумя каналами управления.
class valve_DO2 : public DO2
class valve_DO2 : public valve
{
public:
valve_DO2( const char *dev_name ): DO2( dev_name, DT_V, DST_V_DO2, 0 )
explicit valve_DO2( const char* dev_name ) : valve( dev_name, DT_V, DST_V_DO2 )
{
}
/// @brief Получение состояния клапана без учета обратной связи.
VALVE_STATE get_valve_state() override
{
#ifdef DEBUG_NO_IO_MODULES
return ( VALVE_STATE ) digital_io_device::get_state();
#else
return ( VALVE_STATE ) get_state();
#endif // DEBUG_NO_IO_MODULES
}

/// @brief Получение состояния обратной связи.
bool get_fb_state() override
{
return true;
}

#ifndef DEBUG_NO_IO_MODULES
public:
int get_state();
void direct_on();
void direct_off();

private:
enum CONSTANTS
{
DO_INDEX_1 = 0, ///< Индекс канала дискретного выхода №1.
DO_INDEX_2, ///< Индекс канала дискретного выхода №2.
};
#endif // DEBUG_NO_IO_MODULES
};
//-----------------------------------------------------------------------------
class i_motor : public device
Expand All @@ -3775,7 +3777,7 @@ class i_motor : public device
void reverse();

/// @brief Получение линейной скорости (например, приводимого в
// движение конвейра).
// движение конвейера).
virtual float get_linear_speed() const;

/// @brief Получение текущего тока мотора
Expand Down
19 changes: 19 additions & 0 deletions test/PAC_dev_tests.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -788,6 +788,25 @@ TEST( valve_iol_terminal_DO1_DI2, get_fb_state )
EXPECT_EQ( true, V1.get_fb_state() );
}

TEST( valve_DO2, valve_DO2 )
{
valve_DO2 V2( "V2" );
EXPECT_STREQ( "Клапан", V2.get_type_name() );
EXPECT_STREQ( "V2", V2.get_name());
}

TEST( valve_DO2, get_valve_state )
{
valve_DO2 V2( "V2" );
V2.direct_on();
EXPECT_EQ( 1, V2.get_valve_state() );
}

TEST( valve_DO2, get_fb_state )
{
valve_DO2 V2( "V2" );
EXPECT_EQ( true, V2.get_fb_state() );
}

TEST( level_s, is_active )
{
Expand Down

0 comments on commit 8b726d0

Please sign in to comment.