Skip to content

Commit

Permalink
Merge pull request #22 from lsst-ts/tickets/DM-37449
Browse files Browse the repository at this point in the history
Readout new (current) flow meter model
  • Loading branch information
pkubanek authored Jan 3, 2023
2 parents 1815eca + 1edeae8 commit eeed171
Show file tree
Hide file tree
Showing 15 changed files with 74,054 additions and 72,742 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -2,5 +2,6 @@
*.d
*.o
*.a
*.ipk
m1m3tscli
ts-M1M3thermald
146,515 changes: 73,817 additions & 72,698 deletions Bitfiles/NiFpga_ts_M1M3ThermalFPGA.lvbitx

Large diffs are not rendered by default.

45 changes: 31 additions & 14 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -1,26 +1,43 @@
FROM lsstts/develop-env:c0025.005
FROM lsstts/develop-env:c0026.010 as crio-develop

ARG XML_BRANCH=develop

USER root
RUN chmod a+rwX -R /home/saluser/
USER saluser

ARG XML_BRANCH

WORKDIR /home/saluser/repos/ts_xml
RUN git fetch && git checkout $XML_BRANCH && git pull
ARG XML_BRANCH=main

WORKDIR /home/saluser
RUN source .setup.sh \
&& cd repos/ts_sal \
&& cp ../ts_xml/sal_interfaces/*.xml ../ts_xml/sal_interfaces/MTM1M3TS/*.xml test \
&& cd test \

RUN source ~/.setup.sh \
&& mamba install -y readline yaml-cpp boost-cpp catch2 spdlog \
&& echo > .crio_setup.sh -e \
echo "Configuring cRIO development environment" \\n\
export SHELL=bash \\n\
source /home/saluser/.setup_salobj.sh \\n\
export PATH=\$CONDA_PREFIX/bin:\$PATH \\n\
export LIBS="-L\$CONDA_PREFIX/lib" \\n\
export CPP_FLAGS="-I\$CONDA_PREFIX/include" \\n

# temporary upgrade ts_sal, needed for current develop ts_xml (which changed paths)
RUN source ~/.crio_setup.sh && cd repos/ts_sal \
&& git fetch && git checkout develop && git pull

RUN source ~/.crio_setup.sh && cd $TS_XML_DIR/sal_interfaces \
&& git fetch && git checkout $XML_BRANCH && git pull \
&& salgenerator generate cpp MTM1M3TS

USER root
RUN chmod a+rwX -R /home/saluser/
USER saluser
FROM crio-develop

ARG cRIO_CPP=v1.5.1
ARG M1M3_SUPPORT=develop
ARG TARGET=simulator

RUN cd repos && git clone --branch $cRIO_CPP https://github.com/lsst-ts/ts_cRIOcpp
RUN source ~/.crio_setup.sh && cd repos/ts_cRIOcpp && make

RUN source .setup.sh \
&& mamba install -y readline yaml-cpp boost-cpp catch2
RUN cd repos && git clone --branch $M1M3_SUPPORT https://github.com/lsst-ts/ts_m1m3support
RUN source ~/.crio_setup.sh && cd repos/ts_m1m3support && make $TARGET

SHELL ["/bin/bash", "-lc"]
2 changes: 1 addition & 1 deletion Jenkinsfile
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ node {

stage('Building dev container')
{
M1M3sim = docker.build("lsstts/mtm1m3_sim:" + env.BRANCH_NAME.replace("/", "_"), (params.noCache ? "--no-cache " : " ") + " --build-arg XML_BRANCH=$XML_BRANCH ts_m1m3thermal")
M1M3sim = docker.build("lsstts/mtm1m3_sim:" + env.BRANCH_NAME.replace("/", "_"), "--target crio-develop --build-arg XML_BRANCH=$XML_BRANCH " + (params.noCache ? "--no-cache " : " ") + "$WORKSPACE/ts_m1m3thermal")
}

stage("Running tests")
Expand Down
3 changes: 3 additions & 0 deletions src/LSST/M1M3/TS/IFPGA.h
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,9 @@ class IFPGA : public cRIO::FPGA {
float getMixingValvePosition();
void setMixingValvePosition(float position);

virtual void getVFDError(bool& status, int32_t& code) = 0;
virtual void getFlowMeterError(bool& status, int32_t& code) = 0;

uint32_t getSlot4DIs();

void setFCUPower(bool on);
Expand Down
19 changes: 10 additions & 9 deletions src/LSST/M1M3/TS/MPU/FlowMeter.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -20,35 +20,36 @@
* this program. If not, see <https://www.gnu.org/licenses/>.
*/

#include <MPU/FlowMeter.h>
#include <endian.h>

#include <MPU/FlowMeter.h>

using namespace LSST::M1M3::TS;

void FlowMeter::poll() { readHoldingRegisters(199, 10, 255); }
void FlowMeter::poll() {
readHoldingRegisters(1000, 4, 255);
readHoldingRegisters(2500, 6, 255);
readHoldingRegisters(5500, 1, 255);
}

float FlowMeter::_getFloatValue(uint16_t reg) {
union {
uint16_t data[2];
uint32_t d32;
float dfloat;
} buffer;
buffer.data[0] = getRegister(reg);
buffer.data[1] = getRegister(reg + 1);
buffer.d32 = le32toh(buffer.d32);
buffer.data[0] = getRegister(reg + 1);
buffer.data[1] = getRegister(reg);
return buffer.dfloat;
}

double FlowMeter::_getDoubleValue(uint16_t reg) {
union {
uint16_t data[4];
uint64_t d64;
double ddouble;
} buffer;

for (int i = 0; i < 4; i++) {
buffer.data[i] = getRegister(reg + i);
buffer.data[i] = getRegister(reg + 4 - i);
}
buffer.d64 = le64toh(buffer.d64);
return buffer.ddouble;
}
10 changes: 5 additions & 5 deletions src/LSST/M1M3/TS/MPU/FlowMeter.h
Original file line number Diff line number Diff line change
Expand Up @@ -38,11 +38,11 @@ class FlowMeter : public cRIO::MPU {

void poll();

double getSignalStrength() { return _getFloatValue(199); }
double getFlowRate() { return _getFloatValue(201); }
double getNetTotalizer() { return _getFloatValue(203); }
double getPositiveTotalizer() { return _getFloatValue(205); }
double getNegativeTotalizer() { return _getFloatValue(207); }
uint16_t getSignalStrength() { return getRegister(5500); }
double getFlowRate() { return _getFloatValue(1000); }
double getNetTotalizer() { return _getFloatValue(2500); }
double getPositiveTotalizer() { return _getFloatValue(2502); }
double getNegativeTotalizer() { return _getFloatValue(2504); }

private:
float _getFloatValue(uint16_t reg);
Expand Down
9 changes: 9 additions & 0 deletions src/LSST/M1M3/TS/SimulatedFPGA.h
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,15 @@ class SimulatedFPGA : public IFPGA, public LSST::cRIO::ThermalILC {
void waitOnIrqs(uint32_t irqs, uint32_t timeout, uint32_t* triggered = NULL) override {}
void ackIrqs(uint32_t irqs) override {}

void getVFDError(bool& status, int32_t& code) override {
status = false;
code = 0;
}
void getFlowMeterError(bool& status, int32_t& code) override {
status = false;
code = 0;
}

protected:
void processServerID(uint8_t address, uint64_t uniqueID, uint8_t ilcAppType, uint8_t networkNodeType,
uint8_t ilcSelectedOptions, uint8_t networkNodeOptions, uint8_t majorRev,
Expand Down
6 changes: 6 additions & 0 deletions src/LSST/M1M3/TS/Telemetry/FlowMeter.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@
#include <Telemetry/FlowMeter.h>

using namespace LSST::M1M3::TS::Telemetry;
using namespace std::chrono_literals;

FlowMeter::FlowMeter(token) {
signalStrength = NAN;
Expand All @@ -40,8 +41,13 @@ FlowMeter::FlowMeter(token) {

void FlowMeter::update() {
auto flowMeter = IFPGA::get().flowMeter;

flowMeter->clearCommanded();

flowMeter->poll();

IFPGA::get().mpuCommands(*flowMeter, 2s);

signalStrength = flowMeter->getSignalStrength();
flowRate = flowMeter->getFlowRate();
netTotalizer = flowMeter->getNetTotalizer();
Expand Down
3 changes: 3 additions & 0 deletions src/LSST/M1M3/TS/Telemetry/VFD.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@
#include <Telemetry/VFD.h>

using namespace LSST::M1M3::TS::Telemetry;
using namespace std::chrono_literals;

VFD::VFD(token) {
commandedFrequency = NAN;
Expand All @@ -43,6 +44,8 @@ void VFD::update() {
auto vfd = IFPGA::get().vfd;
vfd->poll();

IFPGA::get().mpuCommands(*vfd, 1s);

commandedFrequency = vfd->getCommandedFrequency();
targetFrequency = vfd->getTargetFrequency();
outputFrequency = vfd->getOutputFrequency();
Expand Down
27 changes: 27 additions & 0 deletions src/LSST/M1M3/TS/ThermalFPGA.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -204,6 +204,33 @@ void ThermalFPGA::processMPUResponse(MPU& mpu, uint8_t* data, uint16_t len) {
mpu.processResponse(u16_data, len);
}

void ThermalFPGA::getVFDError(bool& status, int32_t& code) {
uint8_t packedData[NiFpga_ts_M1M3ThermalFPGA_IndicatorCluster_VFDError_PackedSizeInBytes];
NiThrowError(__PRETTY_FUNCTION__,
NiFpga_ReadArrayU8(_session, NiFpga_ts_M1M3ThermalFPGA_IndicatorCluster_VFDError_Resource,
packedData,
NiFpga_ts_M1M3ThermalFPGA_IndicatorCluster_VFDError_PackedSizeInBytes));

NiFpga_ts_M1M3ThermalFPGA_IndicatorCluster_VFDError_Type vfdError;
NiFpga_ts_M1M3ThermalFPGA_IndicatorCluster_VFDError_UnpackCluster(packedData, &vfdError);
status = vfdError.status;
code = vfdError.code;
}

void ThermalFPGA::getFlowMeterError(bool& status, int32_t& code) {
uint8_t packedData[NiFpga_ts_M1M3ThermalFPGA_IndicatorCluster_FlowMeterError_PackedSizeInBytes];
NiThrowError(
__PRETTY_FUNCTION__,
NiFpga_ReadArrayU8(_session, NiFpga_ts_M1M3ThermalFPGA_IndicatorCluster_FlowMeterError_Resource,
packedData,
NiFpga_ts_M1M3ThermalFPGA_IndicatorCluster_FlowMeterError_PackedSizeInBytes));

NiFpga_ts_M1M3ThermalFPGA_IndicatorCluster_FlowMeterError_Type flowMeterError;
NiFpga_ts_M1M3ThermalFPGA_IndicatorCluster_FlowMeterError_UnpackCluster(packedData, &flowMeterError);
status = flowMeterError.status;
code = flowMeterError.code;
}

} // namespace TS
} // namespace M1M3
} // namespace LSST
2 changes: 2 additions & 0 deletions src/LSST/M1M3/TS/ThermalFPGA.h
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,8 @@ class ThermalFPGA : public IFPGA {

protected:
void processMPUResponse(LSST::cRIO::MPU& mpu, uint8_t* data, uint16_t len) override;
void getVFDError(bool& status, int32_t& code) override;
void getFlowMeterError(bool& status, int32_t& code) override;

private:
uint32_t _session;
Expand Down
57 changes: 57 additions & 0 deletions src/NiFpga/NiFpga_ts_M1M3ThermalFPGA.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@
#include "NiFpga_ts_M1M3ThermalFPGA.h"

#if !NiFpga_VxWorks

void NiFpga_ts_M1M3ThermalFPGA_IndicatorCluster_FlowMeterError_UnpackCluster(
const uint8_t* const packedData,
NiFpga_ts_M1M3ThermalFPGA_IndicatorCluster_FlowMeterError_Type* const destination)
{
(*destination).status = 0;
(*destination).status |= ((packedData[0] >> 7) & 0x1);
(*destination).code = 0;
(*destination).code |= (packedData[0] & 0x7FULL) << 25;
(*destination).code |= (packedData[1] & 0xFF) << 17;
(*destination).code |= (packedData[2] & 0xFF) << 9;
(*destination).code |= (packedData[3] & 0xFF) << 1;
(*destination).code |= ((packedData[4] >> 7) & 0x1);
}

void NiFpga_ts_M1M3ThermalFPGA_IndicatorCluster_FlowMeterError_PackCluster(
uint8_t* const packedData,
const NiFpga_ts_M1M3ThermalFPGA_IndicatorCluster_FlowMeterError_Type* const source)
{
packedData[0] = (uint8_t)(((*source).status & 0x1) << 7);
packedData[0] |= (uint8_t)(((*source).code >> 25) & 0x7F);
packedData[1] = (uint8_t)(((*source).code >> 17) & 0xFF);
packedData[2] = (uint8_t)(((*source).code >> 9) & 0xFF);
packedData[3] = (uint8_t)(((*source).code >> 1) & 0xFF);
packedData[4] = (uint8_t)(((*source).code & 0x1) << 7);
}

void NiFpga_ts_M1M3ThermalFPGA_IndicatorCluster_VFDError_UnpackCluster(
const uint8_t* const packedData,
NiFpga_ts_M1M3ThermalFPGA_IndicatorCluster_VFDError_Type* const destination)
{
(*destination).status = 0;
(*destination).status |= ((packedData[0] >> 7) & 0x1);
(*destination).code = 0;
(*destination).code |= (packedData[0] & 0x7FULL) << 25;
(*destination).code |= (packedData[1] & 0xFF) << 17;
(*destination).code |= (packedData[2] & 0xFF) << 9;
(*destination).code |= (packedData[3] & 0xFF) << 1;
(*destination).code |= ((packedData[4] >> 7) & 0x1);
}

void NiFpga_ts_M1M3ThermalFPGA_IndicatorCluster_VFDError_PackCluster(
uint8_t* const packedData,
const NiFpga_ts_M1M3ThermalFPGA_IndicatorCluster_VFDError_Type* const source)
{
packedData[0] = (uint8_t)(((*source).status & 0x1) << 7);
packedData[0] |= (uint8_t)(((*source).code >> 25) & 0x7F);
packedData[1] = (uint8_t)(((*source).code >> 17) & 0xFF);
packedData[2] = (uint8_t)(((*source).code >> 9) & 0xFF);
packedData[3] = (uint8_t)(((*source).code >> 1) & 0xFF);
packedData[4] = (uint8_t)(((*source).code & 0x1) << 7);
}

#endif /* !NiFpga_VxWorks */
44 changes: 43 additions & 1 deletion src/NiFpga/NiFpga_ts_M1M3ThermalFPGA.h
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@
/**
* The signature of the FPGA bitfile.
*/
static const char* const NiFpga_ts_M1M3ThermalFPGA_Signature = "55394A26508390FCB304C985E129FB4C";
static const char* const NiFpga_ts_M1M3ThermalFPGA_Signature = "B2BCB65ED487F59CADD36CBBAB0C2B59";

#if NiFpga_Cpp
extern "C"
Expand Down Expand Up @@ -62,6 +62,48 @@ typedef enum
NiFpga_ts_M1M3ThermalFPGA_HostToTargetFifoU64_TimestampControlFIFO = 2,
} NiFpga_ts_M1M3ThermalFPGA_HostToTargetFifoU64;

#if !NiFpga_VxWorks

/* Indicator: FlowMeterError */
/* Use NiFpga_ReadArrayU8() to access FlowMeterError */
const uint32_t NiFpga_ts_M1M3ThermalFPGA_IndicatorCluster_FlowMeterError_Resource = 0x18004;
const uint32_t NiFpga_ts_M1M3ThermalFPGA_IndicatorCluster_FlowMeterError_PackedSizeInBytes = 5;

typedef struct NiFpga_ts_M1M3ThermalFPGA_IndicatorCluster_FlowMeterError_Type{
NiFpga_Bool status;
int32_t code;
}NiFpga_ts_M1M3ThermalFPGA_IndicatorCluster_FlowMeterError_Type;


void NiFpga_ts_M1M3ThermalFPGA_IndicatorCluster_FlowMeterError_UnpackCluster(
const uint8_t* const packedData,
NiFpga_ts_M1M3ThermalFPGA_IndicatorCluster_FlowMeterError_Type* const destination);

void NiFpga_ts_M1M3ThermalFPGA_IndicatorCluster_FlowMeterError_PackCluster(
uint8_t* const packedData,
const NiFpga_ts_M1M3ThermalFPGA_IndicatorCluster_FlowMeterError_Type* const source);

/* Indicator: VFDError */
/* Use NiFpga_ReadArrayU8() to access VFDError */
const uint32_t NiFpga_ts_M1M3ThermalFPGA_IndicatorCluster_VFDError_Resource = 0x18000;
const uint32_t NiFpga_ts_M1M3ThermalFPGA_IndicatorCluster_VFDError_PackedSizeInBytes = 5;

typedef struct NiFpga_ts_M1M3ThermalFPGA_IndicatorCluster_VFDError_Type{
NiFpga_Bool status;
int32_t code;
}NiFpga_ts_M1M3ThermalFPGA_IndicatorCluster_VFDError_Type;


void NiFpga_ts_M1M3ThermalFPGA_IndicatorCluster_VFDError_UnpackCluster(
const uint8_t* const packedData,
NiFpga_ts_M1M3ThermalFPGA_IndicatorCluster_VFDError_Type* const destination);

void NiFpga_ts_M1M3ThermalFPGA_IndicatorCluster_VFDError_PackCluster(
uint8_t* const packedData,
const NiFpga_ts_M1M3ThermalFPGA_IndicatorCluster_VFDError_Type* const source);

#endif /* !NiFpga_VxWorks */


#if NiFpga_Cpp
}
Expand Down
Loading

0 comments on commit eeed171

Please sign in to comment.