Commit 8c42bc5f authored by Projects's avatar Projects Committed by Grzegorz Daniluk

Added support to handle input errors in DIOT_Crate

parent 44a9a1f4
...@@ -21,11 +21,7 @@ ...@@ -21,11 +21,7 @@
void DIOT_Crate::SetOutput(int slot, int idx, bool state) void DIOT_Crate::SetOutput(int slot, int idx, bool state)
{ {
if (slot > card_count) { const int var_offset = getDataOffset(slot, idx);
throw std::runtime_error("DIOT_Crate::GetIO(): Too high slot number");
}
const int var_offset = getVarOffset(slot, idx);
const uint8_t io_mask = getIOMask(idx); const uint8_t io_mask = getIOMask(idx);
uint8_t data = GetProdVarData(var_offset); uint8_t data = GetProdVarData(var_offset);
...@@ -41,20 +37,9 @@ void DIOT_Crate::SetOutput(int slot, int idx, bool state) ...@@ -41,20 +37,9 @@ void DIOT_Crate::SetOutput(int slot, int idx, bool state)
} }
bool DIOT_Crate::GetInput(int slot, int idx)
{
if (slot > card_count) {
throw std::runtime_error("DIOT_Crate::GetIO(): Too high slot number");
}
const uint8_t data = GetConsVarData(getVarOffset(slot, idx));
return data & getIOMask(idx);
}
void DIOT_Crate::SetSlotOutputs(int slot, uint32_t state) void DIOT_Crate::SetSlotOutputs(int slot, uint32_t state)
{ {
const int var_offset = getVarOffset(slot, 0); const int var_offset = getDataOffset(slot, 0);
{ // mutex locked scope { // mutex locked scope
auto lock = getProdLock(); auto lock = getProdLock();
...@@ -66,24 +51,6 @@ void DIOT_Crate::SetSlotOutputs(int slot, uint32_t state) ...@@ -66,24 +51,6 @@ void DIOT_Crate::SetSlotOutputs(int slot, uint32_t state)
} }
uint32_t DIOT_Crate::GetSlotInputs(int slot)
{
const int var_offset = getVarOffset(slot, 0);
uint32_t ret = 0;
{ // mutex locked scope
auto lock = getConsLock();
for (int i = 3; i >= 0; --i) {
ret <<= 8;
ret |= getConsDataLock(var_offset + i, lock);
}
}
return ret;
}
bool DIOT_Crate::GetFanStatus(unsigned int fan) bool DIOT_Crate::GetFanStatus(unsigned int fan)
{ {
if (fan >= FAN_COUNT) if (fan >= FAN_COUNT)
...@@ -159,6 +126,23 @@ DIOT_Crate::VOLTAGE DIOT_Crate::GetVoltEnum(unsigned int idx) ...@@ -159,6 +126,23 @@ DIOT_Crate::VOLTAGE DIOT_Crate::GetVoltEnum(unsigned int idx)
} }
uint32_t DIOT_Crate::getConsWord(int address)
{
uint32_t ret = 0;
{ // mutex locked scope
auto lock = getConsLock();
for (int i = 3; i >= 0; --i) {
ret <<= 8;
ret |= getConsDataLock(address + i, lock);
}
}
return ret;
}
const std::vector<std::pair<DIOT_Crate::VOLTAGE, std::string>> DIOT_Crate::VOLTAGES = const std::vector<std::pair<DIOT_Crate::VOLTAGE, std::string>> DIOT_Crate::VOLTAGES =
{ { P3V3, "+3.3V" }, { P5V0, "+5V" }, { { P3V3, "+3.3V" }, { P5V0, "+5V" },
{ P12V0, "+12V" }, { M12V0, "-12V" } }; { P12V0, "+12V" }, { M12V0, "-12V" } };
...@@ -50,7 +50,21 @@ public: ...@@ -50,7 +50,21 @@ public:
* @param idx is the input number (0 to IO_PER_SLOT - 1 range). * @param idx is the input number (0 to IO_PER_SLOT - 1 range).
* @return True when the input is high, false otherwise. * @return True when the input is high, false otherwise.
*/ */
bool GetInput(int slot, int idx); bool GetInput(int slot, int idx)
{
return getConsBit(getDataOffset(slot, idx), getIOMask(idx));
}
/**
* Return an input error state.
* @param slot is the card number (indexing from 0).
* @param idx is the input number (0 to IO_PER_SLOT - 1 range).
* @return True when there is an error, false otherwise.
*/
bool GetInputErr(int slot, int idx)
{
return getConsBit(getInpErrOffset(slot, idx), getIOMask(idx));
}
/** /**
* Change state of all outputs of a card in a particular slot. * Change state of all outputs of a card in a particular slot.
...@@ -64,7 +78,20 @@ public: ...@@ -64,7 +78,20 @@ public:
* @param slot is the card number (indexing from 0). * @param slot is the card number (indexing from 0).
* @return the inputs state. The LSB corresponds to I/O number 0. * @return the inputs state. The LSB corresponds to I/O number 0.
*/ */
uint32_t GetSlotInputs(int slot); uint32_t GetSlotInputs(int slot)
{
return getConsWord(getDataOffset(slot, 0));
}
/**
* Return state of all input errors of a card in a particular slot.
* @param slot is the card number (indexing from 0).
* @return the input errors state. The LSB corresponds to I/O number 0.
*/
uint32_t GetSlotInputErrs(int slot)
{
return getConsWord(getInpErrOffset(slot, 0));
}
/** /**
* Return the number of I/O cards installed in the crate. * Return the number of I/O cards installed in the crate.
...@@ -190,18 +217,41 @@ public: ...@@ -190,18 +217,41 @@ public:
static VOLTAGE GetVoltEnum(unsigned int idx); static VOLTAGE GetVoltEnum(unsigned int idx);
private: private:
///> Return variable offset corresponding to a particular I/O and slot. ///> Return pin state offset corresponding to a particular I/O and slot.
static int getVarOffset(int slot, int idx) int getDataOffset(int slot, int idx)
{ {
if (slot > card_count) {
throw std::runtime_error("DIOT_Crate::GetIO(): Too high slot number");
}
return slot * (IO_PER_SLOT / 8) + idx / 8; return slot * (IO_PER_SLOT / 8) + idx / 8;
} }
///> Return error status corresponding to a particular input and slot.
int getInpErrOffset(int slot, int idx)
{
if (slot > card_count) {
throw std::runtime_error("DIOT_Crate::GetIO(): Too high slot number");
}
return SLOT1_IN_ERR + slot * (IO_PER_SLOT / 8) + idx / 8;
}
///> Calculates bitmask for particular I/O. ///> Calculates bitmask for particular I/O.
static uint8_t getIOMask(int idx) static uint8_t getIOMask(int idx)
{ {
return (1 << (idx % 8)); return (1 << (idx % 8));
} }
///> Returns state of a bit of a consumed variable.
bool getConsBit(int address, uint8_t mask)
{
return GetConsVarData(address) & mask;
}
///> Returns a 32-bit word made of 4 consecutive consumed variables.
uint32_t getConsWord(int address);
///> Produced/consumed variable size (expressed in bytes) ///> Produced/consumed variable size (expressed in bytes)
static constexpr int VAR_SIZE = 124; static constexpr int VAR_SIZE = 124;
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment