Skip to content

Commit

Permalink
clang-formatted
Browse files Browse the repository at this point in the history
  • Loading branch information
pkubanek committed Nov 24, 2023
1 parent b715b32 commit 4fdbd6e
Show file tree
Hide file tree
Showing 38 changed files with 5,002 additions and 3,885 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -9,3 +9,4 @@ ts-VMSd
.mypy.ini
.ruff.toml
src/version.c
towncrier.toml
2,723 changes: 1,574 additions & 1,149 deletions Bitfiles/NiFpga.c

Large diffs are not rendered by default.

174 changes: 88 additions & 86 deletions src/LSST/VMS/Accelerometer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -36,117 +36,119 @@ namespace LSST {
namespace 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);
}
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;
delete[] _psds;
delete[] _sampleData;
}

void Accelerometer::enableAccelerometers() {
SPDLOG_INFO("Accelerometer: enableAccelerometers(), period {}, output type {}",
_vmsApplicationSettings->period, _vmsApplicationSettings->outputType);
FPGA::instance().setPeriodOutputType(_vmsApplicationSettings->period,
_vmsApplicationSettings->outputType);
FPGA::instance().setOperate(true);
SPDLOG_INFO(
"Accelerometer: enableAccelerometers(), period {}, output type {}",
_vmsApplicationSettings->period, _vmsApplicationSettings->outputType);
FPGA::instance().setPeriodOutputType(_vmsApplicationSettings->period,
_vmsApplicationSettings->outputType);
FPGA::instance().setOperate(true);
}

void Accelerometer::disableAccelerometers() {
SPDLOG_INFO("Accelerometer: disableAccelerometers()");
FPGA::instance().setOperate(false);
SPDLOG_INFO("Accelerometer: disableAccelerometers()");
FPGA::instance().setOperate(false);
}

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

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

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

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

uint32_t *dataBuffer = buffer;
for (int s = 0; s < _numberOfSensors; s++) {
float acc_x = _convert(&dataBuffer);
float acc_y = _convert(&dataBuffer);
float acc_z = _convert(&dataBuffer);
uint32_t *dataBuffer = buffer;
for (int s = 0; s < _numberOfSensors; 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;
_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);
}
_psds[s].append(acc_x, acc_y, acc_z);
}

_dataIndex++;
_dataIndex++;

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

float Accelerometer::_convert(uint32_t **data) {
union {
uint32_t i;
float f;
} u32float;
switch (_vmsApplicationSettings->outputType) {
case 1:
case 2:
u32float.f = G2M_S_2(NiFpga_ConvertFromFxpToFloat(ResponseFxpTypeInfo, **data));
++*data;
return u32float.f;
case 3:
u32float.i = **data;
++*data;
return u32float.f;
case 50:
*data += 3;
u32float.i = **data;
++*data;
return u32float.f;
default:
return NAN;
}
union {
uint32_t i;
float f;
} u32float;
switch (_vmsApplicationSettings->outputType) {
case 1:
case 2:
u32float.f =
G2M_S_2(NiFpga_ConvertFromFxpToFloat(ResponseFxpTypeInfo, **data));
++*data;
return u32float.f;
case 3:
u32float.i = **data;
++*data;
return u32float.f;
case 50:
*data += 3;
u32float.i = **data;
++*data;
return u32float.f;
default:
return NAN;
}
}

} /* namespace VMS */
Expand Down
26 changes: 13 additions & 13 deletions src/LSST/VMS/Accelerometer.h
Original file line number Diff line number Diff line change
Expand Up @@ -25,8 +25,8 @@
#define ACCELEROMETER_H_

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

namespace LSST {
namespace VMS {
Expand All @@ -36,24 +36,24 @@ namespace VMS {
*/
class Accelerometer {
public:
Accelerometer(VMSApplicationSettings* vmsApplicationSettings);
virtual ~Accelerometer(void);
Accelerometer(VMSApplicationSettings *vmsApplicationSettings);
virtual ~Accelerometer(void);

void enableAccelerometers();
void disableAccelerometers();
void enableAccelerometers();
void disableAccelerometers();

void sampleData();
void sampleData();

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

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

float _convert(uint32_t** data);
float _convert(uint32_t **data);
};

} /* namespace VMS */
Expand Down
31 changes: 16 additions & 15 deletions src/LSST/VMS/Commands/EnterControl.h
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
/*
* EnterControl command.
*
* Developed for the Vera C. Rubin Observatory Telescope & Site Software Systems.
* This product includes software developed by the Vera C.Rubin Observatory Project
* (https://www.lsst.org). See the COPYRIGHT file at the top-level directory of
* this distribution for details of code ownership.
* Developed for the Vera C. Rubin Observatory Telescope & Site Software
* Systems. This product includes software developed by the Vera C.Rubin
* Observatory Project (https://www.lsst.org). See the COPYRIGHT file at the
* top-level directory of this distribution for details of code ownership.
*
* This program is free software: you can redistribute it and/or modify it
* under the terms of the GNU General Public License as published by the Free
Expand All @@ -23,9 +23,9 @@
#ifndef _VMS_Command_EnterControl_
#define _VMS_Command_ENterControl_

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

#include <Events/SummaryState.h>

Expand All @@ -35,16 +35,17 @@ namespace Commands {

class EnterControl : public cRIO::Command {
public:
void execute() override {
SPDLOG_DEBUG("EnterControl");
VMSPublisher::instance().logSoftwareVersions();
VMSPublisher::instance().logSimulationMode();
Events::SummaryState::setState(MTVMS::MTVMS_shared_SummaryStates_StandbyState);
}
void execute() override {
SPDLOG_DEBUG("EnterControl");
VMSPublisher::instance().logSoftwareVersions();
VMSPublisher::instance().logSimulationMode();
Events::SummaryState::setState(
MTVMS::MTVMS_shared_SummaryStates_StandbyState);
}
};

} // namespace Commands
} // namespace VMS
} // namespace LSST
} // namespace Commands
} // namespace VMS
} // namespace LSST

#endif // !_VMS_Command_EnterControl_
#endif // !_VMS_Command_EnterControl_
50 changes: 25 additions & 25 deletions src/LSST/VMS/Commands/SAL.cpp
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
/*
* SAL command.
*
* Developed for the Vera C. Rubin Observatory Telescope & Site Software Systems.
* This product includes software developed by the Vera C.Rubin Observatory Project
* (https://www.lsst.org). See the COPYRIGHT file at the top-level directory of
* this distribution for details of code ownership.
* Developed for the Vera C. Rubin Observatory Telescope & Site Software
* Systems. This product includes software developed by the Vera C.Rubin
* Observatory Project (https://www.lsst.org). See the COPYRIGHT file at the
* top-level directory of this distribution for details of code ownership.
*
* This program is free software: you can redistribute it and/or modify it
* under the terms of the GNU General Public License as published by the Free
Expand Down Expand Up @@ -34,47 +34,47 @@ using namespace LSST::VMS::Commands;
using namespace MTVMS;

void SAL_start::execute() {
SPDLOG_INFO("Starting, settings={}", params.configurationOverride);
SPDLOG_INFO("Starting, settings={}", params.configurationOverride);

Events::SummaryState::setState(MTVMS_shared_SummaryStates_DisabledState);
ackComplete();
SPDLOG_INFO("Started");
Events::SummaryState::setState(MTVMS_shared_SummaryStates_DisabledState);
ackComplete();
SPDLOG_INFO("Started");
}

void SAL_enable::execute() {
Events::SummaryState::setState(MTVMS_shared_SummaryStates_EnabledState);
ackComplete();
SPDLOG_INFO("Enabled");
Events::SummaryState::setState(MTVMS_shared_SummaryStates_EnabledState);
ackComplete();
SPDLOG_INFO("Enabled");
}

void SAL_disable::execute() {
Events::SummaryState::setState(MTVMS_shared_SummaryStates_DisabledState);
ackComplete();
Events::SummaryState::setState(MTVMS_shared_SummaryStates_DisabledState);
ackComplete();
}

void SAL_standby::execute() {
Events::SummaryState::setState(MTVMS_shared_SummaryStates_StandbyState);
ackComplete();
SPDLOG_INFO("Standby");
Events::SummaryState::setState(MTVMS_shared_SummaryStates_StandbyState);
ackComplete();
SPDLOG_INFO("Standby");
}

void SAL_exitControl::execute() {
ControllerThread::setExitRequested();
ackComplete();
ControllerThread::setExitRequested();
ackComplete();
}

bool SAL_changeSamplePeriod::validate() {
if (Events::SummaryState::instance().enabled() == false) {
return false;
}
return true;
if (Events::SummaryState::instance().enabled() == false) {
return false;
}
return true;
}

void SAL_changeSamplePeriod::execute() {
FPGA::instance().setOperate(false);
ackComplete();
FPGA::instance().setOperate(false);
ackComplete();
}

void SAL_timeSynchronization::received() {
std::cerr << "TimeSynchronization " << params.baseClockOffset << std::endl;
std::cerr << "TimeSynchronization " << params.baseClockOffset << std::endl;
}
Loading

0 comments on commit 4fdbd6e

Please sign in to comment.