Added PSU DS
Signed-off-by: Bernardo Carvalho <bernardo.carvalho@tecnico.ulisboa.pt>
This commit is contained in:
@@ -336,7 +336,7 @@ $TestApp = {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
+UartOutDS = {
|
+UartOutDS = {
|
||||||
Class = UARTOutput
|
Class = PSUCommunicator::PSUCommunicatorTX
|
||||||
PortName = "/dev/ttyS0" //Name of the UART port, Mandatory
|
PortName = "/dev/ttyS0" //Name of the UART port, Mandatory
|
||||||
//PortName = "/dev/ttyLoopWr" //Name of the UART port, Mandatory
|
//PortName = "/dev/ttyLoopWr" //Name of the UART port, Mandatory
|
||||||
BaudRate = 9600 // 10.851 µs / Byte
|
BaudRate = 9600 // 10.851 µs / Byte
|
||||||
@@ -344,6 +344,8 @@ $TestApp = {
|
|||||||
Timeout = 200000 //Maximum time to wait for data
|
Timeout = 200000 //Maximum time to wait for data
|
||||||
CPUMask = 8 //Affinity of the CPU of where to read data from
|
CPUMask = 8 //Affinity of the CPU of where to read data from
|
||||||
SerialTimeout = 1000
|
SerialTimeout = 1000
|
||||||
|
PointOfZeroCurrent = 5.100000e+02
|
||||||
|
CurrentStep = 2.929700e+00
|
||||||
Signals = {
|
Signals = {
|
||||||
SerialOut = {
|
SerialOut = {
|
||||||
Type = float32 //Mandatory. Only type that is supported.
|
Type = float32 //Mandatory. Only type that is supported.
|
||||||
|
|||||||
@@ -54,19 +54,14 @@ const float32 DAC_RANGE = 20.0;
|
|||||||
// const float32 ATCA_IOP_MAX_DAC_RANGE = 20.0;
|
// const float32 ATCA_IOP_MAX_DAC_RANGE = 20.0;
|
||||||
PSUCommunicatorTX::PSUCommunicatorTX() : DataSourceI(), MessageI() {
|
PSUCommunicatorTX::PSUCommunicatorTX() : DataSourceI(), MessageI() {
|
||||||
// boardFileDescriptor = -1;
|
// boardFileDescriptor = -1;
|
||||||
// numberOfDACsEnabled = 0u;
|
|
||||||
// isMaster = 0u;
|
|
||||||
// deviceName = "";
|
|
||||||
// boardId = 2u;
|
|
||||||
triggerSet = false;
|
triggerSet = false;
|
||||||
uint32 n;
|
uint32 n;
|
||||||
// for (n = 0u; n < ATCA_IOP_MAX_DAC_CHANNELS; n++) {
|
// for (n = 0u; n < ATCA_IOP_MAX_DAC_CHANNELS; n++) {
|
||||||
// dacEnabled[n] = false;
|
// dacEnabled[n] = false;
|
||||||
outputRange = DAC_RANGE;
|
|
||||||
//}
|
//}
|
||||||
|
communicatorOnlineStage = FA_COMMUNICATOR_ONLINE_IDLE;
|
||||||
// channelsMemory = NULL_PTR(float32 *);
|
// channelsMemory = NULL_PTR(float32 *);
|
||||||
channelValue = 0.0; // NULL_PTR(float32 *);
|
currentValue = 0.0; // NULL_PTR(float32 *);
|
||||||
currentStep = 0.0;
|
currentStep = 0.0;
|
||||||
pointOfZeroCurrent = 0.0;
|
pointOfZeroCurrent = 0.0;
|
||||||
|
|
||||||
@@ -88,11 +83,6 @@ PSUCommunicatorTX::~PSUCommunicatorTX() {
|
|||||||
serial.Close();
|
serial.Close();
|
||||||
REPORT_ERROR_PARAMETERS(ErrorManagement::Information, "Close %s OK.",
|
REPORT_ERROR_PARAMETERS(ErrorManagement::Information, "Close %s OK.",
|
||||||
portName);
|
portName);
|
||||||
/*
|
|
||||||
if (channelsMemory != NULL_PTR(float32 *)) {
|
|
||||||
delete[] channelsMemory;
|
|
||||||
}
|
|
||||||
*/
|
|
||||||
}
|
}
|
||||||
|
|
||||||
bool PSUCommunicatorTX::AllocateMemory() { return true; }
|
bool PSUCommunicatorTX::AllocateMemory() { return true; }
|
||||||
@@ -104,11 +94,9 @@ uint32 PSUCommunicatorTX::GetNumberOfMemoryBuffers() { return 1u; }
|
|||||||
bool PSUCommunicatorTX::GetSignalMemoryBuffer(const uint32 signalIdx,
|
bool PSUCommunicatorTX::GetSignalMemoryBuffer(const uint32 signalIdx,
|
||||||
const uint32 bufferIdx,
|
const uint32 bufferIdx,
|
||||||
void *&signalAddress) {
|
void *&signalAddress) {
|
||||||
bool ok = (signalIdx < (UART_MAX_CHANNELS));
|
bool ok = (signalIdx < (PSU_MAX_CHANNELS));
|
||||||
if (ok) {
|
if (ok) {
|
||||||
// if (channelsMemory != NULL_PTR(float32 *)) {
|
signalAddress = ¤tValue;
|
||||||
signalAddress = &channelValue;
|
|
||||||
//}
|
|
||||||
}
|
}
|
||||||
return ok;
|
return ok;
|
||||||
}
|
}
|
||||||
@@ -134,6 +122,7 @@ const char8 *PSUCommunicatorTX::GetBrokerName(StructuredDataI &data,
|
|||||||
}
|
}
|
||||||
return brokerName;
|
return brokerName;
|
||||||
}
|
}
|
||||||
|
|
||||||
bool PSUCommunicatorTX::GetInputBrokers(ReferenceContainer &inputBrokers,
|
bool PSUCommunicatorTX::GetInputBrokers(ReferenceContainer &inputBrokers,
|
||||||
const char8 *const functionName,
|
const char8 *const functionName,
|
||||||
void *const gamMemPtr) {
|
void *const gamMemPtr) {
|
||||||
@@ -281,62 +270,6 @@ bool PSUCommunicatorTX::Initialise(StructuredDataI &data) {
|
|||||||
"The port %s Not opened.", portName);
|
"The port %s Not opened.", portName);
|
||||||
}
|
}
|
||||||
|
|
||||||
// Get individual signal parameters
|
|
||||||
uint32 i = 0u;
|
|
||||||
if (ok) {
|
|
||||||
ok = data.MoveRelative("Signals");
|
|
||||||
if (!ok) {
|
|
||||||
REPORT_ERROR(ErrorManagement::ParametersError,
|
|
||||||
"Could not move to the Signals section");
|
|
||||||
}
|
|
||||||
// Do not allow to add signals in run-time
|
|
||||||
if (ok) {
|
|
||||||
ok = signalsDatabase.MoveRelative("Signals");
|
|
||||||
}
|
|
||||||
if (ok) {
|
|
||||||
ok = signalsDatabase.Write("Locked", 1u);
|
|
||||||
}
|
|
||||||
if (ok) {
|
|
||||||
ok = signalsDatabase.MoveToAncestor(1u);
|
|
||||||
}
|
|
||||||
// while ((i < ATCA_IOP_MAX_DAC_CHANNELS) && (ok)) {
|
|
||||||
if (data.MoveRelative(data.GetChildName(0))) {
|
|
||||||
// uint32 channelId;
|
|
||||||
float64 range;
|
|
||||||
ok = data.Read("OutputRange", range);
|
|
||||||
if (ok) {
|
|
||||||
// if (data.Read("OutputRange", range)) {
|
|
||||||
ok = (range > 0.0) && (range <= DAC_RANGE);
|
|
||||||
if (!ok) {
|
|
||||||
REPORT_ERROR(ErrorManagement::ParametersError,
|
|
||||||
"Invalid OutputRange specified.");
|
|
||||||
}
|
|
||||||
if (ok) {
|
|
||||||
outputRange = range;
|
|
||||||
REPORT_ERROR_PARAMETERS(ErrorManagement::Information,
|
|
||||||
" Parameter DAC Output Range %f", range);
|
|
||||||
// dacEnabled[i] = true;
|
|
||||||
// numberOfDACsEnabled++;
|
|
||||||
}
|
|
||||||
} else {
|
|
||||||
REPORT_ERROR(ErrorManagement::ParametersError,
|
|
||||||
"The OutputRange shall be specified.");
|
|
||||||
}
|
|
||||||
if (ok) {
|
|
||||||
ok = data.MoveToAncestor(1u);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
if (ok) {
|
|
||||||
ok = data.MoveToAncestor(1u);
|
|
||||||
if (!ok) {
|
|
||||||
REPORT_ERROR(ErrorManagement::ParametersError,
|
|
||||||
"Could not move to the parent section");
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
// REPORT_ERROR_PARAMETERS(ErrorManagement::Information, "numberOfDACsEnabled
|
|
||||||
// %d", numberOfDACsEnabled);
|
|
||||||
return ok;
|
return ok;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -352,12 +285,11 @@ bool PSUCommunicatorTX::SetConfiguredDatabase(StructuredDataI &data) {
|
|||||||
"At least one Trigger signal shall be set.");
|
"At least one Trigger signal shall be set.");
|
||||||
}
|
}
|
||||||
if (ok) {
|
if (ok) {
|
||||||
// for (i = 0u; (i < numberOfDACsEnabled) && (ok); i++) {
|
|
||||||
ok = (GetSignalType(0u) == Float32Bit);
|
ok = (GetSignalType(0u) == Float32Bit);
|
||||||
//}
|
//}
|
||||||
if (!ok) {
|
if (!ok) {
|
||||||
REPORT_ERROR(ErrorManagement::ParametersError,
|
REPORT_ERROR(ErrorManagement::ParametersError,
|
||||||
"All the DAC signals shall be of type Float32Bit");
|
"The PSU current signal shall be of type Float32Bit");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -385,10 +317,12 @@ bool PSUCommunicatorTX::SetConfiguredDatabase(StructuredDataI &data) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Create/Decode current packet
|
// Create/Decode current packet
|
||||||
bool PSUCommunicatorTX::CreateCurrentPacket(float32 current, char8 *packet) {
|
bool PSUCommunicatorTX::CreateCurrentPacket() {
|
||||||
|
bool ok = true;
|
||||||
|
|
||||||
// Calculate the point in the scale of the current
|
// Calculate the point in the scale of the current
|
||||||
int16 pointOfCurrent = (int16)(pointOfZeroCurrent + current / currentStep);
|
int16 pointOfCurrent =
|
||||||
|
(int16)(pointOfZeroCurrent + currentValue / currentStep);
|
||||||
|
|
||||||
// Saturate current
|
// Saturate current
|
||||||
if (pointOfCurrent < FA_SCALE_MIN)
|
if (pointOfCurrent < FA_SCALE_MIN)
|
||||||
@@ -402,33 +336,96 @@ bool PSUCommunicatorTX::CreateCurrentPacket(float32 current, char8 *packet) {
|
|||||||
packet[0] = (char8)(0x0000 | ((nc & 0x03C0) >> 5) | ((pc & 0x0007) << 5));
|
packet[0] = (char8)(0x0000 | ((nc & 0x03C0) >> 5) | ((pc & 0x0007) << 5));
|
||||||
packet[1] = (char8)(0x0001 | ((pc & 0x03F8) >> 2));
|
packet[1] = (char8)(0x0001 | ((pc & 0x03F8) >> 2));
|
||||||
|
|
||||||
return true;
|
return ok;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
bool PSUCommunicatorTX::SendMessage() {
|
||||||
|
bool ok = true;
|
||||||
|
serial.Write(packet, 2);
|
||||||
|
return ok;
|
||||||
|
}
|
||||||
|
bool PSUCommunicatorTX::CommunicatorOnline() {
|
||||||
|
bool ok = true;
|
||||||
|
switch (communicatorOnlineStage) {
|
||||||
|
case FA_COMMUNICATOR_ONLINE_IDLE:
|
||||||
|
// Log the entry on this stage
|
||||||
|
// if(this->communicatorOnlineIdleCount++ == 0)
|
||||||
|
// AssertErrorCondition(Information, "[FACom] COMMUNICATOR_ONLINE_IDLE");
|
||||||
|
break;
|
||||||
|
// Wait for the CODAC trigger
|
||||||
|
case FA_COMMUNICATOR_ONLINE_WAIT_CODAC_TRIGGER:
|
||||||
|
|
||||||
|
// Log the entry on this stage
|
||||||
|
// if(this->communicatorOnlineWaitTriggerCount++ == 0)
|
||||||
|
// AssertErrorCondition(Information, "[FACom]
|
||||||
|
// COMMUNICATOR_ONLINE_WAIT_CODAC_TRIGGER");
|
||||||
|
|
||||||
|
// if(IsTriggered)
|
||||||
|
//{
|
||||||
|
// Send Start Operation message
|
||||||
|
// this->SendMessage(FA_STARTOP_MESSAGE_1, FA_STARTOP_MESSAGE_2);
|
||||||
|
packet[0] = FA_STARTOP_MESSAGE_1;
|
||||||
|
packet[1] = FA_STARTOP_MESSAGE_2;
|
||||||
|
SendMessage();
|
||||||
|
|
||||||
|
// Increase attempts counter
|
||||||
|
// this->communicatorOnlineStartOperationAttempts++;
|
||||||
|
|
||||||
|
// Change online state
|
||||||
|
communicatorOnlineStage = FA_COMMUNICATOR_ONLINE_DISCHARGE;
|
||||||
|
// this->communicatorOnlineWaitTriggerCount = 0;
|
||||||
|
//}
|
||||||
|
|
||||||
|
break;
|
||||||
|
case FA_COMMUNICATOR_ONLINE_DISCHARGE:
|
||||||
|
/*
|
||||||
|
if(PlasmaEnded)
|
||||||
|
{
|
||||||
|
this->communicatorOnlineStage =
|
||||||
|
FA_COMMUNICATOR_ONLINE_STOP_OPERATION;
|
||||||
|
this->communicatorOnlineDischargeCount =
|
||||||
|
0; break;
|
||||||
|
}
|
||||||
|
*/
|
||||||
|
// CreateCurrentPacket(CurrentToSendCopy, packet1, packet2);
|
||||||
|
CreateCurrentPacket();
|
||||||
|
ok = SendMessage();
|
||||||
|
communicatorOnlineStage = FA_COMMUNICATOR_ONLINE_STOP_OPERATION;
|
||||||
|
break;
|
||||||
|
case FA_COMMUNICATOR_ONLINE_STOP_OPERATION:
|
||||||
|
packet[0] = FA_STARTOP_MESSAGE_1;
|
||||||
|
packet[1] = FA_STARTOP_MESSAGE_2;
|
||||||
|
ok = SendMessage();
|
||||||
|
break;
|
||||||
|
case FA_COMMUNICATOR_ONLINE_ERROR:
|
||||||
|
|
||||||
|
// AssertErrorCondition(InitialisationError, "[FACom]::%s Power supplies
|
||||||
|
// timeout: after %d attemps, FA_COMMUNICATOR_ONLINE_ERROR, RETURN FALSE",
|
||||||
|
// this->Name(), this->communicatorOnlineStopOperationAttempts);
|
||||||
|
|
||||||
|
ok = false;
|
||||||
|
|
||||||
|
break;
|
||||||
|
|
||||||
|
default:
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
return ok;
|
||||||
|
}
|
||||||
bool PSUCommunicatorTX::Synchronise() {
|
bool PSUCommunicatorTX::Synchronise() {
|
||||||
uint32 i;
|
uint32 i;
|
||||||
int32 w = 24;
|
int32 w = 24;
|
||||||
bool ok = true;
|
bool ok = true;
|
||||||
char8 text[] = "ola";
|
// char8 text[] = "ola";
|
||||||
// if (channelsMemory != NULL_PTR(float32 *)) {
|
// if (channelsMemory != NULL_PTR(float32 *)) {
|
||||||
|
|
||||||
// value = channelsMemory[0] / DAC_RANGE;
|
// value = channelsMemory[0] / DAC_RANGE;
|
||||||
// for (i = 0u; (i < numberOfDACsEnabled ) && (ok); i++) {
|
|
||||||
int32 ser_value = channelValue / outputRange * 1000000.0;
|
|
||||||
REPORT_ERROR_PARAMETERS(ErrorManagement::Information,
|
REPORT_ERROR_PARAMETERS(ErrorManagement::Information,
|
||||||
"Synchronise called. value: %f, %d", channelValue,
|
"Synchronise called. value: %f", currentValue);
|
||||||
ser_value);
|
|
||||||
// w = SetDacReg(i, value);
|
// w = SetDacReg(i, value);
|
||||||
char8 *data = reinterpret_cast<char8 *>(&ser_value);
|
// char8 *data = reinterpret_cast<char8 *>(&ser_value);
|
||||||
serial.Write(data, sizeof(int32));
|
// serial.Write(data, sizeof(int32));
|
||||||
// serial.Write(text, 4);
|
// serial.Write(text, 4);
|
||||||
// write(boardFileDescriptor, &w, 4);
|
|
||||||
// value = channelsMemory[1] / DAC_RANGE;
|
|
||||||
// value = channelsMemory[1] / DAC_RANGE * pow(2,17);
|
|
||||||
// w = SetDacReg(1, value);
|
|
||||||
// w = 0x000FFFFF & static_cast<uint32>(value);
|
|
||||||
// write(boardFileDescriptor, &w, 4);
|
|
||||||
// REPORT_ERROR(ErrorManagement::Information, " Writing DAC 0 0x%x", w);
|
|
||||||
/*
|
/*
|
||||||
|
|
||||||
w = dacValues[i];
|
w = dacValues[i];
|
||||||
|
|||||||
@@ -36,6 +36,7 @@
|
|||||||
/*---------------------------------------------------------------------------*/
|
/*---------------------------------------------------------------------------*/
|
||||||
/* Project header includes */
|
/* Project header includes */
|
||||||
/*---------------------------------------------------------------------------*/
|
/*---------------------------------------------------------------------------*/
|
||||||
|
#include "CLASSMETHODREGISTER.h"
|
||||||
#include "DataSourceI.h"
|
#include "DataSourceI.h"
|
||||||
#include "EmbeddedServiceMethodBinderI.h"
|
#include "EmbeddedServiceMethodBinderI.h"
|
||||||
#include "EventSem.h"
|
#include "EventSem.h"
|
||||||
@@ -53,7 +54,7 @@ namespace MARTe {
|
|||||||
* The number of signals
|
* The number of signals
|
||||||
*/
|
*/
|
||||||
|
|
||||||
const uint32 UART_MAX_CHANNELS = 1u;
|
const uint32 PSU_MAX_CHANNELS = 1u;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @brief A DataSource which provides an analogue output interface to the ATCA
|
* @brief A DataSource which provides an analogue output interface to the ATCA
|
||||||
@@ -70,7 +71,7 @@ const uint32 UART_MAX_CHANNELS = 1u;
|
|||||||
* CurrentStep =
|
* CurrentStep =
|
||||||
* PointOfZeroCurrent =
|
* PointOfZeroCurrent =
|
||||||
* Signals = {
|
* Signals = {
|
||||||
* SerialOut = {
|
* CurrentSignal= {
|
||||||
* Type = float32//Mandatory. Only type that is supported.
|
* Type = float32//Mandatory. Only type that is supported.
|
||||||
* OutputRange = 10.0 //Mandatory. The channel Module Output Range
|
* OutputRange = 10.0 //Mandatory. The channel Module Output Range
|
||||||
in volt.
|
in volt.
|
||||||
@@ -92,6 +93,7 @@ const uint32 UART_MAX_CHANNELS = 1u;
|
|||||||
class PSUCommunicatorTX : public DataSourceI, public MessageI {
|
class PSUCommunicatorTX : public DataSourceI, public MessageI {
|
||||||
public:
|
public:
|
||||||
CLASS_REGISTER_DECLARATION()
|
CLASS_REGISTER_DECLARATION()
|
||||||
|
// AtcaIopConfig ();
|
||||||
/**
|
/**
|
||||||
* @brief Default constructor
|
* @brief Default constructor
|
||||||
* @post
|
* @post
|
||||||
@@ -191,7 +193,7 @@ public:
|
|||||||
virtual bool SetConfiguredDatabase(StructuredDataI &data);
|
virtual bool SetConfiguredDatabase(StructuredDataI &data);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @details Writes the value of all the DAC channels to the board.
|
* @details Writes the packet to the PSU
|
||||||
* @return true if the writing of all the channels is successful.
|
* @return true if the writing of all the channels is successful.
|
||||||
*/
|
*/
|
||||||
virtual bool Synchronise();
|
virtual bool Synchronise();
|
||||||
@@ -201,14 +203,6 @@ private:
|
|||||||
* The board device name
|
* The board device name
|
||||||
*/
|
*/
|
||||||
StreamString portName;
|
StreamString portName;
|
||||||
/**
|
|
||||||
* The board identifier
|
|
||||||
*/
|
|
||||||
uint32 boardId;
|
|
||||||
/**
|
|
||||||
* The board file descriptor
|
|
||||||
*/
|
|
||||||
// int32 boardFileDescriptor;
|
|
||||||
/**
|
/**
|
||||||
* The UART interface.
|
* The UART interface.
|
||||||
*/
|
*/
|
||||||
@@ -223,31 +217,14 @@ private:
|
|||||||
*/
|
*/
|
||||||
uint32 timeout;
|
uint32 timeout;
|
||||||
|
|
||||||
/**
|
|
||||||
* DAC values
|
|
||||||
*/
|
|
||||||
// int32 dacValues[ATCA_IOP_N_DACs];
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* The signal memory
|
* The signal memory
|
||||||
*/
|
*/
|
||||||
float32 channelValue;
|
float32 currentValue;
|
||||||
float32 currentStep;
|
float32 currentStep;
|
||||||
float32 pointOfZeroCurrent;
|
float32 pointOfZeroCurrent;
|
||||||
/**
|
// Communicator online behaviour
|
||||||
* The DACs that are enabled
|
uint32 communicatorOnlineStage;
|
||||||
*/
|
|
||||||
// bool dacEnabled[ATCA_IOP_MAX_DAC_CHANNELS];
|
|
||||||
|
|
||||||
/**
|
|
||||||
* The board individual channel output ranges
|
|
||||||
*/
|
|
||||||
float32 outputRange;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* The number of enabled DACs
|
|
||||||
*/
|
|
||||||
uint32 numberOfDACsEnabled;
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Filter to receive the RPC which allows to change the...
|
* Filter to receive the RPC which allows to change the...
|
||||||
@@ -258,9 +235,12 @@ private:
|
|||||||
* True if at least one trigger was set.
|
* True if at least one trigger was set.
|
||||||
*/
|
*/
|
||||||
bool triggerSet;
|
bool triggerSet;
|
||||||
|
char8 packet[2];
|
||||||
|
|
||||||
// int32 SetDacReg(uint32 channel, float32 val) const;
|
// int32 SetDacReg(uint32 channel, float32 val) const;
|
||||||
bool CreateCurrentPacket(float32 current, char8 *packet);
|
bool SendMessage();
|
||||||
|
bool CommunicatorOnline();
|
||||||
|
bool CreateCurrentPacket(); // float32 current, char8 *packet);
|
||||||
};
|
};
|
||||||
} // namespace MARTe
|
} // namespace MARTe
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user