136 lines
4.6 KiB
C++
136 lines
4.6 KiB
C++
/*************************************************************************\
|
|
* Copyright (c) 2023 Paul Scherrer Institute
|
|
* ecmc is distributed subject to a Software License Agreement found
|
|
* in file LICENSE that is included with this distribution.
|
|
*
|
|
* ecmcSafetyPlg.h
|
|
*
|
|
* Created on: jan 29, 2024
|
|
* Author: anderssandstrom
|
|
*
|
|
\*************************************************************************/
|
|
#ifndef ECMC_SAFETY_GROUP_PLG_H_
|
|
#define ECMC_SAFETY_GROUP_PLG_H_
|
|
|
|
#include <stdexcept>
|
|
#include "ecmcDataItem.h"
|
|
#include "ecmcAsynPortDriver.h"
|
|
#include "ecmcSafetyPlgDefs.h"
|
|
#include <string>
|
|
#include "ecmcAxisBase.h"
|
|
#include "ecmcEc.h"
|
|
#include <vector>
|
|
|
|
class safetyAxis {
|
|
public:
|
|
safetyAxis(int axisId,
|
|
double veloLimit,
|
|
int standStillTimeMs) {
|
|
veloLimit_ = veloLimit;
|
|
axisId_ = axisId;
|
|
standStillTimeMs_ = standStillTimeMs;
|
|
printEnableStat_ = 1;
|
|
}
|
|
|
|
double veloLimit_;
|
|
int axisId_;
|
|
int standStillTimeMs_;
|
|
int printEnableStat_;
|
|
};
|
|
|
|
class ecmcSS1SafetyGroup : public asynPortDriver {
|
|
public:
|
|
|
|
/** ecmc Safty Plg class
|
|
* This object can throw:
|
|
* - bad_alloc
|
|
* - out_of_range
|
|
*/
|
|
ecmcSS1SafetyGroup(const char *name,
|
|
const char *ec_rampdown_cmd,
|
|
const char *ec_standstill_status,
|
|
int time_delay_ms,
|
|
const char *cfg_string,
|
|
char* portName);
|
|
|
|
~ecmcSS1SafetyGroup();
|
|
|
|
// Call just before realtime because then all data sources should be available
|
|
void validate();
|
|
void addAxis(int axisId, double veloLimit,int standStillTimeMs);
|
|
void execute();
|
|
virtual asynStatus readInt32(asynUser *pasynUser, epicsInt32 *value);
|
|
std::string getName();
|
|
|
|
private:
|
|
void validateCfgs();
|
|
void validateAxes();
|
|
void stripBits();
|
|
void connectToDataSources();
|
|
void setAxesSafetyInterlocks(int stop);
|
|
void setAxesDisable();
|
|
void setAxesStandstillStatus(int standstill);
|
|
bool checkAxesStandstill();
|
|
bool checkAxisStandstill(safetyAxis* axis);
|
|
bool checkAxisStandstillAndDisableIfNeeded(safetyAxis* axis);
|
|
bool checkAxesStandstillAndDisableIfNeeded();
|
|
void resetPrintoutStatus();
|
|
void parseConfigStr(const char *configStr);
|
|
void initAsyn();
|
|
double ecmcSampleRateHz_;
|
|
int dataSourcesLinked_; // To avoid link several times
|
|
int objectId_; // Unique object id
|
|
int cycleCounter_;
|
|
int rampDownCmd_;
|
|
int rampDownCmdOld_;
|
|
|
|
// Config options
|
|
int cfgDbgMode_; // Config: allow dbg printouts
|
|
|
|
// Asyn
|
|
int asynStatusId_;
|
|
int status_;
|
|
int axesCounter_;
|
|
std::vector<safetyAxis*> axes_;
|
|
|
|
char* sName_;
|
|
char* sEcRampDownCmdNameOrg_;
|
|
char* sEcAxesStandStillStatOrg_;
|
|
char* sEcRampDownCmdNameStrip_;
|
|
char* sEcAxesStandStillStatStrip_;
|
|
char* sConfig_;
|
|
|
|
int delayMs_;
|
|
int masterId_;
|
|
int slaveIdRampDown_;
|
|
int bitRampDown_;
|
|
int slaveIdStandStill_;
|
|
int bitStandStill_;
|
|
int axesAreStandstill_;
|
|
int axesAreStandstillOld_;
|
|
int printEnableStatus_;
|
|
|
|
char aliasRampDown_[EC_MAX_OBJECT_PATH_CHAR_LENGTH];
|
|
char aliasStandStill_[EC_MAX_OBJECT_PATH_CHAR_LENGTH];
|
|
|
|
ecmcEc *ecMaster_;
|
|
ecmcEcEntry *ecEntryRampDown_;
|
|
ecmcEcEntry *ecEntryStandstill_;
|
|
|
|
// Some generic utility functions
|
|
static uint8_t getUint8(uint8_t* data);
|
|
static int8_t getInt8(uint8_t* data);
|
|
static uint16_t getUint16(uint8_t* data);
|
|
static int16_t getInt16(uint8_t* data);
|
|
static uint32_t getUint32(uint8_t* data);
|
|
static int32_t getInt32(uint8_t* data);
|
|
static uint64_t getUint64(uint8_t* data);
|
|
static int64_t getInt64(uint8_t* data);
|
|
static float getFloat32(uint8_t* data);
|
|
static double getFloat64(uint8_t* data);
|
|
static size_t getEcDataTypeByteSize(ecmcEcDataType dt);
|
|
static std::string to_string(int value);
|
|
};
|
|
|
|
#endif /* ECMC_SAFETY_GROUP_PLG_H_ */
|