Skip to content
Snippets Groups Projects
Commit 4f3c386d authored by Cyril Danilevski's avatar Cyril Danilevski :scooter:
Browse files

Add channel target voltage set in power procedure

parent 0287dd20
No related branches found
No related tags found
1 merge request!3DEPFET Q2M1 Power Procedure
Pipeline #165010 passed
...@@ -35,7 +35,7 @@ SNMP::Message *MPOD::read(uint16_t channel) { ...@@ -35,7 +35,7 @@ SNMP::Message *MPOD::read(uint16_t channel) {
} }
// Create an SNMP SETREQUEST message to switch on or off the specified channel // Create an SNMP SETREQUEST message to switch on or off the specified channel
SNMP::Message *MPOD::output(const uint16_t channel, const bool on) { SNMP::Message *MPOD::setChannelState(const uint16_t channel, const bool on) {
SNMP::Message *message = new SNMP::Message(SNMP::Version::V2C, "guru", SNMP::Type::SetRequest); SNMP::Message *message = new SNMP::Message(SNMP::Version::V2C, "guru", SNMP::Type::SetRequest);
// In SETREQUEST, use node type and set the value. // In SETREQUEST, use node type and set the value.
// OUTPUT SWITCH, integer type, 0 is OFF and 1 is ON. // OUTPUT SWITCH, integer type, 0 is OFF and 1 is ON.
...@@ -45,6 +45,17 @@ SNMP::Message *MPOD::output(const uint16_t channel, const bool on) { ...@@ -45,6 +45,17 @@ SNMP::Message *MPOD::output(const uint16_t channel, const bool on) {
return message; return message;
} }
// Create an SNMP SETREQUEST message to set the channel voltage
SNMP::Message *MPOD::setTargetVoltage(const uint16_t channel, const float targetVoltage) {
SNMP::Message *message = new SNMP::Message(SNMP::Version::V2C, "guru", SNMP::Type::SetRequest);
// In SETREQUEST, use node type and set the value.
// OUTPUT VOLTAGE, float type.
String snmp_cmd = OID::NAMES[OID::OUTPUTVOLTAGE];
snmp_cmd += channel;
message->add(snmp_cmd.c_str(), new OpaqueBER(new OpaqueFloatBER(targetVoltage)));
return message;
}
// Parse incoming message // Parse incoming message
bool MPOD::message(const SNMP::Message *message) { bool MPOD::message(const SNMP::Message *message) {
unsigned int found = 0; unsigned int found = 0;
...@@ -194,9 +205,9 @@ void initializeSNMP() { ...@@ -194,9 +205,9 @@ void initializeSNMP() {
/* setChannelAndWait /* setChannelAndWait
* Set a channel's parameters and wait until it's settled. * Set a channel's parameters and wait until it's settled.
*/ */
void setChannelAndWait(const IPAddress *ipAddr, const uint16_t channel, const uint8_t output) { void setChannelStateAndWait(const IPAddress *ipAddr, const uint16_t channel, const uint8_t output) {
// Send set command // Send set command
SNMP::Message *snmp_msg = mpod.output(channel, output); SNMP::Message *snmp_msg = mpod.setChannelState(channel, output);
snmp.send(snmp_msg, *ipAddr, SNMP::Port::SNMP); snmp.send(snmp_msg, *ipAddr, SNMP::Port::SNMP);
delete snmp_msg; delete snmp_msg;
...@@ -213,3 +224,26 @@ void setChannelAndWait(const IPAddress *ipAddr, const uint16_t channel, const ui ...@@ -213,3 +224,26 @@ void setChannelAndWait(const IPAddress *ipAddr, const uint16_t channel, const ui
snmp.loop(); snmp.loop();
} while (mpod.isOn() != (bool)output || mpod.isRampingDown() || mpod.isRampingUp()); } while (mpod.isOn() != (bool)output || mpod.isRampingDown() || mpod.isRampingUp());
} }
void setChannelVoltageAndWait(const IPAddress *ipAddr, const uint16_t channel,
const float targetVoltage) {
// Send set command
SNMP::Message *snmp_msg = mpod.setTargetVoltage(channel, targetVoltage);
snmp.send(snmp_msg, *ipAddr, SNMP::Port::SNMP);
delete snmp_msg;
// wait for channel reply
delay(MPOD_UPDATE_LATENCY);
snmp.loop();
// Poll channel until it's settled
do {
SNMP::Message *snmp_msg = mpod.read(channel);
snmp.send(snmp_msg, *ipAddr, SNMP::Port::SNMP);
delete snmp_msg;
delay(MPOD_UPDATE_LATENCY);
snmp.loop();
} while (mpod.isRampingDown() ||
mpod.isRampingUp()); // TODO check applied voltage close to target voltage
}
...@@ -62,7 +62,8 @@ class MPOD { ...@@ -62,7 +62,8 @@ class MPOD {
// Create an SNMP SETREQUEST message to setup MPOD // Create an SNMP SETREQUEST message to setup MPOD
MPOD(); MPOD();
SNMP::Message* read(const uint16_t); SNMP::Message* read(const uint16_t);
SNMP::Message* output(const uint16_t, const bool); SNMP::Message* setChannelState(const uint16_t, const bool);
SNMP::Message* setTargetVoltage(const uint16_t, const float);
bool message(const SNMP::Message*); bool message(const SNMP::Message*);
bool isOn() const; bool isOn() const;
bool isRampingUp() const; bool isRampingUp() const;
...@@ -95,5 +96,6 @@ extern MPOD mpod; ...@@ -95,5 +96,6 @@ extern MPOD mpod;
// Event handler to process SNMP messages // Event handler to process SNMP messages
void onSNMPMessage(const SNMP::Message *message, const IPAddress remote, const uint16_t port); void onSNMPMessage(const SNMP::Message *message, const IPAddress remote, const uint16_t port);
void initializeSNMP(); void initializeSNMP();
void setChannelAndWait(const IPAddress*, uint16_t, uint8_t); void setChannelStateAndWait(const IPAddress*, const uint16_t, const uint8_t);
void setChannelVoltageAndWait(const IPAddress*, const uint16_t, const float);
...@@ -6,19 +6,25 @@ PowerProcedure::PowerProcedure(const IPAddress& ipAddr) ...@@ -6,19 +6,25 @@ PowerProcedure::PowerProcedure(const IPAddress& ipAddr)
: ipAddr(ipAddr), stagesCount(STAGESCOUNT), currentStage(""), currentChannel(-1) { : ipAddr(ipAddr), stagesCount(STAGESCOUNT), currentStage(""), currentChannel(-1) {
stages = new Stage[stagesCount]; stages = new Stage[stagesCount];
stages[0].name = "AON"; stages[0].name = "ASICS";
stages[0].size = 4; stages[0].type = SWITCH;
stages[0].channels = new int[stages[0].size]{604, 705, 706, 707}; stages[0].size = 9;
stages[0].channels = new int[stages[0].size]{508, 708, 502, 503, 504, 501, 507, 607, 608};
stages[1].name = "ASICS";
stages[1].size = 9; stages[1].name = "HV";
stages[1].channels = new int[stages[1].size]{508, 708, 502, 503, 504, 501, 507, 607, 608}; stages[1].type = SWITCH;
stages[1].size = 10;
stages[2].name = "HV"; stages[1].channels = new int[stages[1].size]{1, 2, 101, 103, 102, 104, 105, 106, 107, 108};
stages[2].size = 10;
stages[2].channels = new int[stages[2].size]{1, 2, 101, 103, 102, 104, 105, 106, 107, 108}; stages[2].name = "ISVOLTAGE";
stages[2].type = VOLTAGE;
stages[2].size = 2;
stages[2].channels = new int[stages[2].size]{1, 2};
stages[2].onValue = new float[stages[2].size]{10, 10};
stages[2].offValue = new float[stages[2].size]{2.5, 2.5};
stages[3].name = "PLCSOURCE"; stages[3].name = "PLCSOURCE";
stages[3].type = SWITCH;
stages[3].size = 9; stages[3].size = 9;
stages[3].channels = new int[stages[3].size]{701, 801, 802, 803, 804, 301, 302, 303, 304}; stages[3].channels = new int[stages[3].size]{701, 801, 802, 803, 804, 301, 302, 303, 304};
} }
...@@ -26,6 +32,10 @@ PowerProcedure::PowerProcedure(const IPAddress& ipAddr) ...@@ -26,6 +32,10 @@ PowerProcedure::PowerProcedure(const IPAddress& ipAddr)
PowerProcedure::~PowerProcedure() { PowerProcedure::~PowerProcedure() {
for (size_t stageIdx = 0; stageIdx < stagesCount; stageIdx++) { for (size_t stageIdx = 0; stageIdx < stagesCount; stageIdx++) {
delete[] stages[stageIdx].channels; delete[] stages[stageIdx].channels;
if (stages[stageIdx].type == VOLTAGE) {
delete[] stages[stageIdx].onValue;
delete[] stages[stageIdx].offValue;
}
} }
delete[] stages; delete[] stages;
} }
...@@ -37,6 +47,9 @@ String PowerProcedure::toJSON() { ...@@ -37,6 +47,9 @@ String PowerProcedure::toJSON() {
for (size_t stageIdx = 0; stageIdx < stagesCount; stageIdx++) { for (size_t stageIdx = 0; stageIdx < stagesCount; stageIdx++) {
Stage* currentStage = &stages[stageIdx]; Stage* currentStage = &stages[stageIdx];
if (currentStage->type == VOLTAGE) {
continue;
}
json += "{\"name\":\"" + currentStage->name + "\","; json += "{\"name\":\"" + currentStage->name + "\",";
json += "\"channels\":[\n"; json += "\"channels\":[\n";
...@@ -71,7 +84,12 @@ bool PowerProcedure::powerOn(const String& stage) { ...@@ -71,7 +84,12 @@ bool PowerProcedure::powerOn(const String& stage) {
Stage* currentStage = &stages[stageIdx]; Stage* currentStage = &stages[stageIdx];
if (currentStage->name == stage) { if (currentStage->name == stage) {
for (size_t chIdx = 0; chIdx < currentStage->size; chIdx++) { for (size_t chIdx = 0; chIdx < currentStage->size; chIdx++) {
setChannelAndWait(&ipAddr, currentStage->channels[chIdx], 1); // 1 == ON if (currentStage->type == SWITCH) {
setChannelStateAndWait(&ipAddr, currentStage->channels[chIdx], 1); // 1 == ON
} else if (currentStage->type == VOLTAGE) {
setChannelVoltageAndWait(&ipAddr, currentStage->channels[chIdx],
currentStage->onValue[chIdx]);
}
} }
return true; return true;
} }
...@@ -84,7 +102,12 @@ bool PowerProcedure::powerOff(const String& stage) { ...@@ -84,7 +102,12 @@ bool PowerProcedure::powerOff(const String& stage) {
Stage* currentStage = &stages[stageIdx]; Stage* currentStage = &stages[stageIdx];
if (currentStage->name == stage) { if (currentStage->name == stage) {
for (int chIdx = currentStage->size - 1; chIdx >= 0; chIdx--) { for (int chIdx = currentStage->size - 1; chIdx >= 0; chIdx--) {
setChannelAndWait(&ipAddr, currentStage->channels[chIdx], 0); // 0 == OFF if (currentStage->type == SWITCH) {
setChannelStateAndWait(&ipAddr, currentStage->channels[chIdx], 0); // 0 == OFF
} else if (currentStage->type == VOLTAGE) {
setChannelVoltageAndWait(&ipAddr, currentStage->channels[chIdx],
currentStage->offValue[chIdx]);
}
} }
return true; return true;
} }
......
...@@ -3,15 +3,21 @@ ...@@ -3,15 +3,21 @@
#include "pins.hpp" #include "pins.hpp"
#define SWITCH "SWITCH"
#define VOLTAGE "VOLTAGE"
#define STAGESCOUNT 4 #define STAGESCOUNT 4
class PowerProcedure { class PowerProcedure {
private: private:
String currentStage; // Stores the current stage name String currentStage; // Stores the current stage name
int currentChannel; // Stores the current channel int currentChannel; // Stores the current channel
struct Stage { struct Stage {
String name; // Name of the stage (e.g., "ASICS") String name; // Name of the stage (e.g. "ASICS")
String type; // Type of stage (i.e. "SWITCH", "VOLTAGE")
int* channels; // Pointer to dynamically allocated channel array int* channels; // Pointer to dynamically allocated channel array
float* onValue; // Pointer to dynamically allocated array, when type == VOLTAGE
float* offValue; // Pointer to dynamically allocated array, when type == VOLTAGE
size_t size; // Number of channels in the stage size_t size; // Number of channels in the stage
}; };
......
...@@ -160,7 +160,7 @@ void sendSNMP() { ...@@ -160,7 +160,7 @@ void sendSNMP() {
auto ipAddr = pproc.ipAddr; auto ipAddr = pproc.ipAddr;
if (output != NONE && channel != 0) { if (output != NONE && channel != 0) {
setChannelAndWait(&ipAddr, channel, output); setChannelStateAndWait(&ipAddr, channel, output);
success = true; // validates input parameters, not MPOD status, reported separately success = true; // validates input parameters, not MPOD status, reported separately
} }
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment