This example shows a fictional thermometer.
The Makefile for this sample is the following:
CXX = g++
# We enable the c++0x flag, plus we define the NDS3_DLL preprocessor macro.
CXXFLAGS = -std=c++0x -Wall -Wextra -pedantic -fPIC -pthread -DNDS3_DLL
# Flags passed to gcc during linking
LINK = -shared -fPIC -Wl,-as-needed
# Name of our device library
TARGET = libthermometer.so
# We specify that we depend on NDS3
LIBS = -lnds3
# We assume that all the .cpp files are in the src folder
SRCS = thermometer.cpp
OBJS = $(SRCS:.cpp=.o)
# Rules for building
$(TARGET): $(OBJS)
$(CXX) $(LINK) -o $@ $^ $(LIBS)
.PHONY: clean
clean:
$(RM) $(TARGET) $(OBJS)
The code shows a simple delegate function that is called each time the control system wants to read the temperature.
#include <iostream>
class Thermometer
{
private:
public:
const std::string &deviceName,
this,
std::placeholders::_1,
std::placeholders::_2)))
{
this,
std::placeholders::_1,
std::placeholders::_2)));
m_thermometerPiniPV.processAtInit(1);
}
void getTemperature(timespec* pTimestamp, double* pValue)
{
*pValue = 10;
std::cout << "Temperature #1: " << *pValue << std::endl;
}
void getTempRandom(timespec* pTimestamp, double* pValue)
{
*pValue = 35;
std::cout << "Temperature #2 (pini): " << *pValue << std::endl;
}
};