19 #ifdef TGT_OS_TYPE_VXWORKS 20 #define M_PI (22.0 / 7.0) 30 : SignalGenComponentBase(name),
33 signalAmplitude(0.0f),
36 sigType(SignalType::SINE),
41 m_dpInProgress(false),
52 F32 SignalGen::generateSample(U32 ticks) {
58 F32 samplesPerPeriod =
static_cast<F32>(this->sampleFrequency) / static_cast<F32>(this->signalFrequency);
59 U32 halfSamplesPerPeriod = samplesPerPeriod / 2;
61 switch (this->sigType.e) {
62 case SignalType::TRIANGLE: {
63 F32 m = this->signalAmplitude /
static_cast<F32>(halfSamplesPerPeriod);
64 val = m *
static_cast<F32>(ticks % halfSamplesPerPeriod);
67 case SignalType::SINE: {
68 F32 normalizedFrequency = 1.0f / samplesPerPeriod;
69 val = this->signalAmplitude * std::sin((2.0 * M_PI * normalizedFrequency * static_cast<F32>(ticks)) +
70 (this->signalPhase * 2.0 * M_PI));
73 case SignalType::SQUARE: {
74 val = this->signalAmplitude *
75 ((ticks %
static_cast<U32
>(samplesPerPeriod) < halfSamplesPerPeriod) ? 1.0f : -1.0f);
78 case SignalType::NOISE: {
79 val = this->signalAmplitude * (std::rand() /
static_cast<double>(RAND_MAX));
88 void SignalGen::schedIn_handler(
FwIndexType portNum,
97 if (not this->running) {
101 if (not this->skipOne) {
102 value = this->generateSample(this->ticks);
104 this->skipOne =
false;
107 SignalPair pair = SignalPair(this->ticks, value);
110 for (U32 i = 1; i < this->sigHistory.SIZE; i++) {
111 this->sigHistory[i - 1] = this->sigHistory[i];
112 this->sigPairHistory[i - 1] = this->sigPairHistory[i];
114 this->sigHistory[this->sigHistory.SIZE - 1] = value;
115 this->sigPairHistory[this->sigPairHistory.SIZE - 1] = pair;
118 SignalInfo sigInfo(this->sigType, this->sigHistory, this->sigPairHistory);
121 this->tlmWrite_Type(this->sigType);
122 this->tlmWrite_Output(value);
123 this->tlmWrite_PairOutput(pair);
124 this->tlmWrite_History(this->sigHistory);
125 this->tlmWrite_PairHistory(this->sigPairHistory);
126 this->tlmWrite_Info(sigInfo);
129 if (this->m_dpInProgress) {
132 this->m_dpBytes += SignalInfo::SERIALIZED_SIZE;
135 this->log_WARNING_LO_DpRecordFull(this->m_currDp, this->m_dpBytes);
136 this->cleanupAndSendDp();
137 }
else if (this->m_currDp == this->m_numDps) {
138 this->log_ACTIVITY_LO_DpComplete(this->m_numDps, this->m_dpBytes);
139 this->cleanupAndSendDp();
142 this->tlmWrite_DpBytes(this->m_dpBytes);
143 this->tlmWrite_DpRecords(this->m_currDp);
149 void SignalGen::Settings_cmdHandler(
FwOpcodeType opCode,
154 Ref::SignalType SigType) {
155 this->signalFrequency = Frequency;
156 this->signalAmplitude = Amplitude;
157 this->signalPhase = Phase;
158 this->sigType = SigType;
161 for (U32 i = 0; i < SignalSet::SIZE; i++) {
162 this->sigHistory[i] = 0.0f;
164 for (U32 i = 0; i < SignalPairSet::SIZE; i++) {
165 this->sigPairHistory[i].set_time(0.0f);
166 this->sigPairHistory[i].set_value(0.0f);
168 this->log_ACTIVITY_LO_SettingsChanged(this->signalFrequency, this->signalAmplitude, this->signalPhase,
170 this->tlmWrite_Type(SigType);
177 this->running = !this->running;
185 this->skipOne =
true;
191 Ref::SignalGen_DpReqType reqType,
196 this->log_WARNING_HI_InSufficientDpRecords();
202 if (not this->isConnected_productGetOut_OutputPort(0)) {
203 this->log_WARNING_HI_DpsNotConnected();
211 this->m_numDps = records;
214 this->log_ACTIVITY_LO_DpMemRequested(dpSize);
215 if (Ref::SignalGen_DpReqType::IMMEDIATE == reqType) {
216 Fw::Success stat = this->dpGet_DataContainer(dpSize, this->m_dpContainer);
219 this->log_WARNING_HI_DpMemoryFail();
222 this->m_dpInProgress =
true;
223 this->log_ACTIVITY_LO_DpStarted(records);
224 this->log_ACTIVITY_LO_DpMemReceived(this->m_dpContainer.getBuffer().getSize());
227 this->m_dpContainer.setPriority(this->m_dpPriority);
229 }
else if (Ref::SignalGen_DpReqType::ASYNC == reqType) {
230 this->dpRequest_DataContainer(dpSize);
238 void SignalGen::cleanupAndSendDp() {
239 this->dpSend(this->m_dpContainer);
240 this->m_dpInProgress =
false;
250 void SignalGen ::dpRecv_DataContainer_handler(DpContainer& container,
Fw::Success::T status) {
253 this->m_dpContainer = container;
254 this->m_dpInProgress =
true;
256 this->m_dpContainer.setPriority(this->m_dpPriority);
257 this->log_ACTIVITY_LO_DpStarted(this->m_numDps);
259 this->log_WARNING_HI_DpMemoryFail();
261 this->m_dpInProgress =
false;
FwIdType FwOpcodeType
The type of a command opcode.
PlatformSizeType FwSizeType
U32 FwDpPriorityType
The type of a data product priority.
No room left in the buffer to serialize data.
SerializeStatus
forward declaration for string
float F32
32-bit floating point
Command successfully executed.
Command had execution error.
FwIdType FwDpIdType
The type of a data product identifier.
PlatformIndexType FwIndexType
Command failed validation.
~SignalGen()
Destroy a SignalGen.
SignalGen(const char *compName)
Construct a SignalGen.