Skip to content

Commit

Permalink
Merge pull request #27 from lsst-ts/tickets/DM-44552
Browse files Browse the repository at this point in the history
DM-44552: vmscli, vmsrawdump utilities
  • Loading branch information
pkubanek authored Jun 16, 2024
2 parents dad159b + 10065b7 commit 96186df
Show file tree
Hide file tree
Showing 27 changed files with 3,215 additions and 4,323 deletions.
18 changes: 14 additions & 4 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ include Makefile.inc
#

# All Target
all: ts-VMSd
all: vmscli utils/vmsrawdump ts-VMSd

src/libVMS.a: FORCE
$(MAKE) -C src libVMS.a
Expand All @@ -16,9 +16,16 @@ ts-VMSd: src/ts-VMSd.cpp.o src/libVMS.a
@echo '[LD ] $@'
${co}$(CPP) $(LIBS_FLAGS) -o $@ $^ ${CRIOCPP}/lib/libcRIOcpp.a $(LIBS)

vmscli: src/vmscli.cpp.o src/libVMS.a
@echo '[LD ] $@'
${co}$(CPP) $(LIBS_FLAGS) -o $@ $^ ../ts_cRIOcpp/lib/libcRIOcpp.a $(LIBS) $(shell pkg-config --libs readline $(silence)) -lreadline

utils/vmsrawdump: utils/vmsrawdump.cpp
@${MAKE} -C utils

# Other Targets
clean:
@$(foreach file,ts_MTVMS src/ts_MTVMS.cpp.o *.ipk ipk, echo '[RM ] ${file}'; $(RM) -r $(file);)
@$(foreach file,ts-VMSd vmscli src/ts-VMS.cpp.o src/vmscli.cpp.o *.ipk ipk, echo '[RM ] ${file}'; $(RM) -r $(file);)
@$(foreach dir,src tests,$(MAKE) -C ${dir} $@;)

# file targets
Expand All @@ -44,14 +51,17 @@ ipk: ts-VMS_$(VERSION)_x64.ipk

TS_DDSCONFIG=../ts_ddsconfig

ts-VMS_$(VERSION)_x64.ipk: ts-VMSd
ts-VMS_$(VERSION)_x64.ipk: vmscli utils/vmsrawdump ts-VMSd
@echo '[MK ] ipk $@'
${co}mkdir -p ipk/data/usr/bin
${co}mkdir -p ipk/data/usr/sbin
${co}mkdir -p ipk/data/etc/init.d
${co}mkdir -p ipk/data/etc/default
${co}mkdir -p ipk/data/var/lib/MTVMS
${co}mkdir -p ipk/control
${co}cp ts-VMSd ipk/data/usr/sbin/ts-VMSd
${co}cp vmscli ipk/data/usr/bin/
${co}cp utils/vmsrawdump ipk/data/usr/bin/
${co}cp ts-VMSd ipk/data/usr/sbin/
${co}cp init ipk/data/etc/init.d/ts-VMS
${co}cp default_ts-VMS ipk/data/etc/default/ts-VMS
${co}cp -r SettingFiles/* ipk/data/var/lib/MTVMS
Expand Down
3 changes: 2 additions & 1 deletion Makefile.inc
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,8 @@ endif
LIBS += $(PKG_LIBS) -ldl -ldcpssacpp -ldcpsgapi -lddsuser -lddskernel \
-lpthread -lddsserialization -lddsconfparser -lddsconf \
-lddsdatabase -lddsutil -lddsos \
${SAL_WORK_DIR}/lib/libSAL_MTVMS.a
${SAL_WORK_DIR}/lib/libSAL_MTVMS.a \
-lstdc++fs

LIBS_FLAGS += -L${OSPL_HOME}/lib -L${LSST_SDK_INSTALL}/lib

Expand Down
1 change: 1 addition & 0 deletions SettingFiles/CameraRotator.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ Subsystem : "CameraRotator"
IsController : true
Period: 5
OutputType: 3
Sensors: 3
XCoefficients : [1.0,1.0,1.0]
YCoefficients : [1.0,1.0,1.0]
ZCoefficients : [1.0,1.0,1.0]
Expand Down
1 change: 1 addition & 0 deletions SettingFiles/M1M3.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ Subsystem : "M1M3"
IsController : true
Period: 5
OutputType: 3
Sensors: 3
XCoefficients : [1.0,1.0,1.0]
YCoefficients : [1.0,1.0,1.0]
ZCoefficients : [1.0,1.0,1.0]
Expand Down
3 changes: 2 additions & 1 deletion SettingFiles/M2.yaml
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
Subsystem : "M2"
IsController : true
Period: 5
OutputType: 3
IsController : true
Sensors: 6
XCoefficients : [1.0,1.0,1.0]
YCoefficients : [1.0,1.0,1.0]
ZCoefficients : [1.0,1.0,1.0]
Expand Down
5 changes: 5 additions & 0 deletions doc/version-history.rst
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,11 @@
Version History
===============

v1.2.2
------

* vmscli, vmsrawdump utilities

v1.2.1
------

Expand Down
4 changes: 2 additions & 2 deletions init
Original file line number Diff line number Diff line change
Expand Up @@ -48,12 +48,12 @@ startdaemon(){
done
logger -t VMS_start -p user.info "Starting with IP $LSST_DDS_IP"
echo -n "Starting TS VMS $1:"
start-stop-daemon --start --oknodo --pidfile ${PIDFILE}_$1.pid --startas $DAEMON -- -p ${PIDFILE}_$1.pid -u vms:vms $1
start-stop-daemon --start --oknodo --pidfile ${PIDFILE}_$1.pid --exec $DAEMON -- -p ${PIDFILE}_$1.pid -u vms:vms $1
echo "done"
}
stopdaemon(){
echo -n "Stopping TS VMS $1:"
start-stop-daemon --stop --oknodo --remove-pidfile --retry 5 -p ${PIDFILE}_$1.pid
start-stop-daemon --stop --oknodo --remove-pidfile --user vms --retry 5 -p ${PIDFILE}_$1.pid
sudo -E -u vms -g vms LD_LIBRARY_PATH=$OSPL_HOME/lib PATH=$PATH:$OSPL_HOME/bin $OSPL_HOME/bin/ospl stop
echo "done"
}
Expand Down
72 changes: 7 additions & 65 deletions src/LSST/VMS/Accelerometer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -26,52 +26,18 @@
#include <Accelerometer.h>
#include <FPGA.h>
#include <FPGAAddresses.h>
#include <VMSPublisher.h>

#define AXIS_PER_SENSOR 3
#define MAX_SAMPLE_PER_PUBLISH 50
#define G2M_S_2(g) (g * 9.80665)

namespace LSST {
namespace VMS {
using namespace LSST::VMS;

Accelerometer::Accelerometer(VMSApplicationSettings *vmsApplicationSettings) {
SPDLOG_DEBUG("Accelerometer::Accelerometer()");

_vmsApplicationSettings = vmsApplicationSettings;

if (vmsApplicationSettings->Subsystem == "M1M3") {
_subsystem = M1M3;
_numberOfSensors = 3;
} else if (vmsApplicationSettings->Subsystem == "M2") {
_subsystem = M2;
_numberOfSensors = 6;
} else if (vmsApplicationSettings->Subsystem == "CameraRotator") {
_subsystem = CameraRotator;
_numberOfSensors = 3;
} else if (vmsApplicationSettings->Subsystem == "TMA") {
_subsystem = TMA;
_numberOfSensors = 3;
} else {
SPDLOG_ERROR("Unknown subsystem: {}", vmsApplicationSettings->Subsystem);
exit(EXIT_FAILURE);
}
_sampleData = new MTVMS_dataC[_numberOfSensors];
_psds = new Telemetry::PSD[_numberOfSensors];
_dataIndex = 0;

float _periodInS = _vmsApplicationSettings->period / 1000.0f;

for (int s = 0; s < _numberOfSensors; s++) {
_sampleData[s].sensor = s + 1;
_psds[s].configure(s + 1, 1.0f / (2.0f * _periodInS), _periodInS);
}
}

Accelerometer::~Accelerometer(void) {
delete[] _psds;
delete[] _sampleData;
}
Accelerometer::~Accelerometer(void) {}

void Accelerometer::enableAccelerometers() {
SPDLOG_INFO("Accelerometer: enableAccelerometers(), period {}, output type {}",
Expand All @@ -87,40 +53,19 @@ void Accelerometer::disableAccelerometers() {
}

void Accelerometer::sampleData() {
SPDLOG_TRACE("Accelerometer: sampleData() count {}", _dataIndex);
uint32_t buffer[_numberOfSensors * AXIS_PER_SENSOR];
SPDLOG_TRACE("Accelerometer: sampleData()");
uint32_t buffer[_vmsApplicationSettings->sensors * AXIS_PER_SENSOR];

FPGA::instance().readResponseFIFO(buffer, _numberOfSensors * AXIS_PER_SENSOR,
FPGA::instance().readResponseFIFO(buffer, _vmsApplicationSettings->sensors * AXIS_PER_SENSOR,
_vmsApplicationSettings->period * 2);

if (_dataIndex == 0) {
double data_timestamp = VMSPublisher::instance().getTimestamp();

for (int s = 0; s < _numberOfSensors; s++) {
_sampleData[s].timestamp = data_timestamp;
}
}

uint32_t *dataBuffer = buffer;
for (int s = 0; s < _numberOfSensors; s++) {
for (int s = 0; s < _vmsApplicationSettings->sensors; s++) {
float acc_x = _convert(&dataBuffer);
float acc_y = _convert(&dataBuffer);
float acc_z = _convert(&dataBuffer);

_sampleData[s].accelerationX[_dataIndex] = acc_x;
_sampleData[s].accelerationY[_dataIndex] = acc_y;
_sampleData[s].accelerationZ[_dataIndex] = acc_z;

_psds[s].append(acc_x, acc_y, acc_z);
}

_dataIndex++;

if (_dataIndex >= MAX_SAMPLE_PER_PUBLISH) {
for (int s = 0; s < _numberOfSensors; s++) {
VMSPublisher::instance().putData(&(_sampleData[s]));
}
_dataIndex = 0;
processData(s, acc_x, acc_y, acc_z);
}
}

Expand Down Expand Up @@ -148,6 +93,3 @@ float Accelerometer::_convert(uint32_t **data) {
return NAN;
}
}

} /* namespace VMS */
} /* namespace LSST */
21 changes: 10 additions & 11 deletions src/LSST/VMS/Accelerometer.h
Original file line number Diff line number Diff line change
Expand Up @@ -21,16 +21,16 @@
* along with this program. If not, see <https://www.gnu.org/licenses/>.
*/

#ifndef ACCELEROMETER_H_
#define ACCELEROMETER_H_
#ifndef __ACCELEROMETER_H_
#define __ACCELEROMETER_H_

#include <SAL_MTVMS.h>
#include <Telemetry/PSD.h>
#include <VMSApplicationSettings.h>

namespace LSST {
namespace VMS {

constexpr static int AXIS_PER_SENSOR = 3;

/**
* VMS Accelerometer sampling.
*/
Expand All @@ -44,19 +44,18 @@ class Accelerometer {

void sampleData();

protected:
VMSApplicationSettings *_vmsApplicationSettings;

virtual void processData(int sensor, float acc_x, float acc_y, float acc_z) = 0;

private:
enum { M1M3, M2, CameraRotator, TMA } _subsystem;

int _numberOfSensors;
int _dataIndex;
MTVMS_dataC *_sampleData;
Telemetry::PSD *_psds;
VMSApplicationSettings *_vmsApplicationSettings;

float _convert(uint32_t **data);
};

} /* namespace VMS */
} /* namespace LSST */

#endif /* ACCELEROMETER_H_ */
#endif /* __ACCELEROMETER_H_ */
5 changes: 3 additions & 2 deletions src/LSST/VMS/Commands/EnterControl.h
Original file line number Diff line number Diff line change
Expand Up @@ -25,9 +25,10 @@

#include <cRIO/Task.h>
#include <SAL_MTVMS.h>
#include <VMSPublisher.h>
#include <cRIO/Command.h>

#include <cRIO/Task.h>

#include <VMSPublisher.h>
#include <Events/SummaryState.h>

namespace LSST {
Expand Down
3 changes: 3 additions & 0 deletions src/LSST/VMS/Events/FPGAState.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,9 @@ FPGAState::FPGAState(token) {
}

void FPGAState::send() {
if (instance()._publish == false) {
return;
}
salReturn ret = VMSPublisher::SAL()->putSample_logevent_fpgaState(&instance());
if (ret != SAL__OK) {
SPDLOG_WARN("Can not send fpgaState: {}", ret);
Expand Down
7 changes: 7 additions & 0 deletions src/LSST/VMS/Events/FPGAState.h
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,12 @@ class FPGAState final : MTVMS_logevent_fpgaStateC, public cRIO::Singleton<FPGASt
void setPeriodOutputType(int32_t newPeriod, int newOutputType);
void setMisc(bool newReady, bool newTimeouted, bool newStopped, bool newFIFOFull);

/***
* Sets flag if state changes should be outpublished. Used to NOT publish
* from vmsclient, as vmsclient doesn't have any SAL connecton.
*/
void setPublish(bool publish) { _publish = publish; }

/***
* Readout state from FPGA, sends updates if data were changed
*/
Expand All @@ -59,6 +65,7 @@ class FPGAState final : MTVMS_logevent_fpgaStateC, public cRIO::Singleton<FPGASt

private:
std::mutex _stateMutex;
bool _publish = true;
};

} // namespace Events
Expand Down
7 changes: 1 addition & 6 deletions src/LSST/VMS/FPGA.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,6 @@
#include <unistd.h>

#ifdef SIMULATOR
#include <Events/FPGAState.h>
#include <math.h>
#endif

Expand All @@ -44,8 +43,7 @@
#include <VMSPublisher.h>
#include <cRIO/NiError.h>

namespace LSST {
namespace VMS {
using namespace LSST::VMS;

FPGA::FPGA(token) : SimpleFPGA(LSST::cRIO::VMS) {}

Expand Down Expand Up @@ -259,6 +257,3 @@ void FPGA::readResponseFIFO(uint32_t *data, size_t length, int32_t timeoutInMs)
}
#endif
}

} /* namespace VMS */
} /* namespace LSST */
Loading

0 comments on commit 96186df

Please sign in to comment.