00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019 #include "LOW_compTwinSwitch.h"
00020 #include "LOW_netSegment.h"
00021
00022
00023
00024
00025
00026
00027
00028
00029 LOW_compTwinSwitch::LOW_compTwinSwitch( const LOW_devDS2406 &inPIODevice, actionReceiver &inActionRcv,
00030 const bool inDetectShortClicks) :
00031 pioDevice( inPIODevice),
00032 actionRcv( inActionRcv),
00033 detectShortClicks( inDetectShortClicks)
00034 {
00035 if ( !pioDevice.getNetSegment().getHasExternalPower() )
00036 throw compTwinSwitch_error( "Network segment must supply power.", __FILE__, __LINE__);
00037
00038 if ( ! pioDevice.getHasPioB() )
00039 switchStatesVec = std::vector<bool>( 2, false);
00040 else
00041 switchStatesVec = std::vector<bool>( 1, false);
00042
00043 LOW_devDS2406::cmd_ChannelAccess::channelInfo_t dummy;
00044 resetLatches( dummy);
00045
00046 setAlarmCondition();
00047 }
00048
00049
00050 LOW_compTwinSwitch::~LOW_compTwinSwitch()
00051 {
00052 }
00053
00054
00055
00056
00057
00058
00059
00060
00061 void LOW_compTwinSwitch::handleAlarm()
00062 {
00063 LOW_devDS2406::cmd_ChannelAccess::channelInfo_t chInfoRead, chInfoReset;
00064
00065
00066 readStatus( chInfoRead);
00067 resetLatches( chInfoReset);
00068
00069
00070 if ( chInfoRead.activityLatch_pioA )
00071
00072
00073 doSwitchAction( 0, chInfoReset.sensedLevel_pioA);
00074
00075
00076 if ( pioDevice.getHasPioB() && chInfoRead.activityLatch_pioB )
00077
00078
00079 doSwitchAction( 1, chInfoReset.sensedLevel_pioB);
00080 }
00081
00082
00083 void LOW_compTwinSwitch::alarmPollLoop()
00084 {
00085 while( ! pioDevice.verifyDevice( true) );
00086 }
00087
00088
00089 bool LOW_compTwinSwitch::getDetectShortClicks()
00090 {
00091 return detectShortClicks;
00092 }
00093
00094 const LOW_devDS2406& LOW_compTwinSwitch::getPioDevice() const
00095 {
00096 return pioDevice;
00097 }
00098
00099
00100
00101
00102
00103
00104
00105
00106 void LOW_compTwinSwitch::setAlarmCondition()
00107 {
00108 pioDevice.setSearchCondition( LOW_devDS2406::chanBothSelect, LOW_devDS2406::latchSelect,
00109 LOW_devDS2406::activeHigh,
00110 LOW_devDS2406::pioTransistorOff, LOW_devDS2406::pioTransistorOff);
00111 }
00112
00113
00114 void LOW_compTwinSwitch::readStatus( LOW_devDS2406::cmd_ChannelAccess::channelInfo_t &outChannelInfo)
00115 {
00116 LOW_devDS2406::cmd_ChannelAccess readAccess =
00117 LOW_devDS2406::cmd_ChannelAccess( pioDevice,
00118 LOW_devDS2406::cmd_ChannelAccess::CRC_disable,
00119 LOW_devDS2406::chanBothSelect,
00120 LOW_devDS2406::cmd_ChannelAccess::asyncInterleaveMode,
00121 LOW_devDS2406::cmd_ChannelAccess::noToggleMode,
00122 LOW_devDS2406::cmd_ChannelAccess::readMode,
00123 LOW_devDS2406::cmd_ChannelAccess::noResetLatches);
00124 outChannelInfo = readAccess.getChannelInfo();
00125 }
00126
00127
00128 void LOW_compTwinSwitch::resetLatches( LOW_devDS2406::cmd_ChannelAccess::channelInfo_t &outChannelInfo)
00129 {
00130 LOW_devDS2406::cmd_ChannelAccess clearLatchAccess =
00131 LOW_devDS2406::cmd_ChannelAccess( pioDevice,
00132 LOW_devDS2406::cmd_ChannelAccess::CRC_disable,
00133 LOW_devDS2406::chanBothSelect,
00134 LOW_devDS2406::cmd_ChannelAccess::asyncInterleaveMode,
00135 LOW_devDS2406::cmd_ChannelAccess::noToggleMode,
00136 LOW_devDS2406::cmd_ChannelAccess::readMode,
00137 LOW_devDS2406::cmd_ChannelAccess::resetLatches);
00138 outChannelInfo = clearLatchAccess.getChannelInfo();
00139 }
00140
00141
00142
00143
00144
00145
00146
00147
00148
00149
00150
00151
00152
00153
00154
00155
00156
00157
00158
00159
00160
00161
00162 void LOW_compTwinSwitch::doSwitchAction( const unsigned int inSwitchNum, const bool inSensedLevel)
00163 {
00164 bool oldLogState = switchStatesVec[inSwitchNum];
00165
00166 if ( !oldLogState && !inSensedLevel && !detectShortClicks ) {
00167 switchStatesVec[inSwitchNum] = false;
00168 actionRcv.switchAction( this, inSwitchNum, true);
00169 actionRcv.switchAction( this, inSwitchNum, false);
00170 }
00171
00172 if ( !oldLogState && !inSensedLevel && detectShortClicks ) {
00173 switchStatesVec[inSwitchNum] = false;
00174 actionRcv.shortSwitchAction( this, inSwitchNum);
00175 }
00176
00177 if ( !oldLogState && inSensedLevel ) {
00178 switchStatesVec[inSwitchNum] = true;
00179 actionRcv.switchAction( this, inSwitchNum, true);
00180 }
00181
00182 if ( oldLogState && !inSensedLevel ) {
00183 switchStatesVec[inSwitchNum] = false;
00184 actionRcv.switchAction( this, inSwitchNum, false);
00185 }
00186
00187 if ( oldLogState && inSensedLevel ) {
00188 switchStatesVec[inSwitchNum] = true;
00189 actionRcv.switchAction( this, inSwitchNum, false);
00190 actionRcv.switchAction( this, inSwitchNum, true);
00191 }
00192 }
00193
00194
00195
00196
00197
00198
00199
00200
00201 LOW_compTwinSwitch::actionReceiver::actionReceiver()
00202 {
00203 }