Initial commit

This commit is contained in:
Jaka Mohorko
2025-01-22 13:32:50 +01:00
commit 60daee2a73
24 changed files with 1084 additions and 0 deletions

View File

@@ -0,0 +1,24 @@
/*
* Copyright 2022-2024 openDAQ d.o.o.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
#pragma once
#include <coretypes/common.h>
#define BEGIN_NAMESPACE_EXAMPLE_MODULE BEGIN_NAMESPACE_OPENDAQ_MODULE(example_module)
static const std::string EXAMPLE_MODULE_NAME = "ExampleModule";
#define END_NAMESPACE_EXAMPLE_MODULE END_NAMESPACE_OPENDAQ_MODULE

View File

@@ -0,0 +1,56 @@
/*
* Copyright 2022-2024 openDAQ d.o.o.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
#pragma once
#include <opendaq/sample_type.h>
#define SAMPLE_TYPE_DISPATCH(ST, Func, ...) \
switch (ST) \
{ \
case SampleType::Int8: \
Func<SampleType::Int8>(__VA_ARGS__); \
break; \
case SampleType::Int16: \
Func<SampleType::Int16>(__VA_ARGS__); \
break; \
case SampleType::Int32: \
Func<SampleType::Int32>(__VA_ARGS__); \
break; \
case SampleType::Int64: \
Func<SampleType::Int64>(__VA_ARGS__); \
break; \
case SampleType::UInt8: \
Func<SampleType::UInt8>(__VA_ARGS__); \
break; \
case SampleType::UInt16: \
Func<SampleType::UInt16>(__VA_ARGS__); \
break; \
case SampleType::UInt32: \
Func<SampleType::UInt32>(__VA_ARGS__); \
break; \
case SampleType::UInt64: \
Func<SampleType::UInt64>(__VA_ARGS__); \
break; \
case SampleType::Float32: \
Func<SampleType::Float32>(__VA_ARGS__); \
break; \
case SampleType::Float64: \
Func<SampleType::Float64>(__VA_ARGS__); \
break; \
default: \
assert(false); \
}

View File

@@ -0,0 +1,77 @@
/*
* Copyright 2022-2024 openDAQ d.o.o.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
#pragma once
#include <example_module/common.h>
#include <opendaq/function_block_impl.h>
#include <opendaq/opendaq.h>
#include <opendaq/stream_reader_ptr.h>
BEGIN_NAMESPACE_EXAMPLE_MODULE
class ExampleFBImpl final : public FunctionBlock
{
public:
explicit ExampleFBImpl(const ContextPtr& ctx, const ComponentPtr& parent, const StringPtr& localId);
~ExampleFBImpl() override = default;
static FunctionBlockTypePtr CreateType();
private:
InputPortPtr inputPort;
DataDescriptorPtr inputDataDescriptor;
DataDescriptorPtr inputDomainDataDescriptor;
DataDescriptorPtr outputDataDescriptor;
DataDescriptorPtr outputDomainDataDescriptor;
SampleType inputSampleType;
SignalConfigPtr outputSignal;
SignalConfigPtr outputDomainSignal;
StreamReaderPtr reader;
SizeT sampleRate;
std::vector<float> inputData;
std::vector<uint64_t> inputDomainData;
bool configValid = false;
Float scale;
Float offset;
Float outputHighValue;
Float outputLowValue;
Bool useCustomOutputRange;
std::string outputUnit;
std::string outputName;
void createInputPorts();
void createSignals();
void calculate();
void processData(SizeT readAmount, SizeT packetOffset) const;
void processEventPacket(const EventPacketPtr& packet);
void processSignalDescriptorChanged(const DataDescriptorPtr& dataDescriptor,
const DataDescriptorPtr& domainDescriptor);
void configure();
void initProperties();
void propertyChanged(bool configure);
void readProperties();
};
END_NAMESPACE_EXAMPLE_MODULE

View File

@@ -0,0 +1,32 @@
/*
* Copyright 2022-2024 openDAQ d.o.o.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
#pragma once
#include <example_module/common.h>
#include <opendaq/module_impl.h>
BEGIN_NAMESPACE_EXAMPLE_MODULE
class ExampleModule final : public Module
{
public:
explicit ExampleModule(ContextPtr context);
DictPtr<IString, IFunctionBlockType> onGetAvailableFunctionBlockTypes() override;
FunctionBlockPtr onCreateFunctionBlock(const StringPtr& id, const ComponentPtr& parent, const StringPtr& localId, const PropertyObjectPtr& config) override;
};
END_NAMESPACE_EXAMPLE_MODULE

View File

@@ -0,0 +1,20 @@
/*
* Copyright 2022-2024 openDAQ d.o.o.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
#pragma once
#include <opendaq/module_exports.h>
DECLARE_MODULE_EXPORTS(ExampleModule)