initial commit

This commit is contained in:
2021-03-09 16:11:58 +01:00
parent bc3f3abdaa
commit d930003d81
18 changed files with 15955 additions and 41 deletions
+62 -41
View File
@@ -1,52 +1,73 @@
# C++ objects and libs
*.slo
*.lo
*.o
# This file is used to ignore files which are generated
# ----------------------------------------------------------------------------
*~
*.autosave
*.a
*.la
*.lai
*.core
*.moc
*.o
*.obj
*.orig
*.rej
*.so
*.so.*
*.dll
*.dylib
# Qt-es
object_script.*.Release
object_script.*.Debug
*_plugin_import.cpp
*_pch.h.cpp
*_resource.rc
*.qm
.#*
*.*#
core
!core/
tags
.DS_Store
.directory
*.debug
Makefile*
*.prl
*.app
moc_*.cpp
ui_*.h
qrc_*.cpp
Thumbs.db
*.res
*.rc
/.qmake.cache
/.qmake.stash
*.pro.user
*.pro.user.*
*.qbs.user
*.qbs.user.*
*.moc
moc_*.cpp
moc_*.h
qrc_*.cpp
ui_*.h
*.qmlc
*.jsc
Makefile*
*build-*
*.qm
*.prl
# Qt unit tests
target_wrapper.*
# qtcreator generated files
*.pro.user*
# QtCreator
*.autosave
# xemacs temporary files
*.flc
# QtCreator Qml
*.qmlproject.user
*.qmlproject.user.*
# Vim temporary files
.*.swp
# QtCreator CMake
CMakeLists.txt.user*
# Visual Studio generated files
*.ib_pdb_index
*.idb
*.ilk
*.pdb
*.sln
*.suo
*.vcproj
*vcproj.*.*.user
*.ncb
*.sdf
*.opensdf
*.vcxproj
*vcxproj.*
# QtCreator 4.8< compilation database
compile_commands.json
# MinGW generated files
*.Debug
*.Release
# Python byte code
*.pyc
# Binaries
# --------
*.dll
*.exe
# QtCreator local machine specific files for imported projects
*creator.user*
+76
View File
@@ -0,0 +1,76 @@
#include "cairquality.h"
cAirQuality::cAirQuality(cTinkerForge* tinkerForge, const QString& uid) :
m_tinkerForge(tinkerForge),
m_uid(uid)
{
if(!m_tinkerForge)
return;
air_quality_create(&m_airQuality, m_uid.toLocal8Bit().data(), m_tinkerForge->connection());
}
cAirQuality::~cAirQuality()
{
air_quality_destroy(&m_airQuality);
}
qint32 cAirQuality::iaqIndex()
{
int32_t iaq_index;
uint8_t iaq_index_acuracy;
if(air_quality_get_iaq_index(&m_airQuality, &iaq_index, &iaq_index_acuracy) < 0)
return(0.0);
return(iaq_index);
}
double cAirQuality::temperature()
{
int32_t temperature;
if(air_quality_get_temperature(&m_airQuality, &temperature) < 0)
return(0.0);
return((double)temperature/100.0);
}
double cAirQuality::humidity()
{
int32_t humidity;
if(air_quality_get_humidity(&m_airQuality, &humidity) < 0)
return(0.0);
return((double)humidity/100.0);
}
double cAirQuality::airPressure()
{
int32_t airPressure;
if(air_quality_get_air_pressure(&m_airQuality, &airPressure) < 0)
return(0.0);
return((double)airPressure/100.0);
}
QString cAirQuality::iaqIndexAccuracy()
{
int32_t iaq_index;
uint8_t iaq_index_acuracy;
if(air_quality_get_iaq_index(&m_airQuality, &iaq_index, &iaq_index_acuracy) < 0)
return("IAQ Index Accuracy: Unreliable");
switch(iaq_index_acuracy)
{
case AIR_QUALITY_ACCURACY_UNRELIABLE:
return("Unreliable");
case AIR_QUALITY_ACCURACY_LOW:
return("Low");
case AIR_QUALITY_ACCURACY_MEDIUM:
return("Medium");
case AIR_QUALITY_ACCURACY_HIGH:
return("High");
}
return("Unreliable");
}
+26
View File
@@ -0,0 +1,26 @@
#ifndef CAIRQUALITY_H
#define CAIRQUALITY_H
#include "ctinkerforge.h"
#include "tinkerforge/bricklet_air_quality.h"
class cAirQuality
{
public:
cAirQuality(cTinkerForge* tinkerForge, const QString& uid);
~cAirQuality();
qint32 iaqIndex();
double temperature();
double humidity();
double airPressure();
QString iaqIndexAccuracy();
private:
cTinkerForge* m_tinkerForge;
QString m_uid;
AirQuality m_airQuality;
};
#endif // CAIRQUALITY_H
+35
View File
@@ -0,0 +1,35 @@
#include "cmainwindow.h"
#include "ui_cmainwindow.h"
#include <QDebug>
cMainWindow::cMainWindow(QWidget *parent)
: QMainWindow(parent)
, ui(new Ui::cMainWindow),
m_tinkerForge(0),
m_airQuality(0)
{
ui->setupUi(this);
m_tinkerForge = new cTinkerForge("192.168.0.208", 4223);
m_airQuality = new cAirQuality(m_tinkerForge, "QqD");
qDebug() << "Temperatur: " << m_airQuality->temperature();
qDebug() << "Luftfeuchte: " << m_airQuality->humidity();
qDebug() << "Luftdruck: " << m_airQuality->airPressure();
qDebug() << "Index: " << m_airQuality->iaqIndex();
qDebug() << "Genauigkeit: " << m_airQuality->iaqIndexAccuracy();
}
cMainWindow::~cMainWindow()
{
if(m_airQuality)
delete m_airQuality;
if(m_tinkerForge)
delete m_tinkerForge;
delete ui;
}
+28
View File
@@ -0,0 +1,28 @@
#ifndef CMAINWINDOW_H
#define CMAINWINDOW_H
#include <QMainWindow>
#include "ctinkerforge.h"
#include "cairquality.h"
QT_BEGIN_NAMESPACE
namespace Ui { class cMainWindow; }
QT_END_NAMESPACE
class cMainWindow : public QMainWindow
{
Q_OBJECT
public:
cMainWindow(QWidget *parent = nullptr);
~cMainWindow();
private:
Ui::cMainWindow *ui;
cTinkerForge* m_tinkerForge;
cAirQuality* m_airQuality;
};
#endif // CMAINWINDOW_H
+22
View File
@@ -0,0 +1,22 @@
<?xml version="1.0" encoding="UTF-8"?>
<ui version="4.0">
<class>cMainWindow</class>
<widget class="QMainWindow" name="cMainWindow">
<property name="geometry">
<rect>
<x>0</x>
<y>0</y>
<width>800</width>
<height>600</height>
</rect>
</property>
<property name="windowTitle">
<string>cMainWindow</string>
</property>
<widget class="QWidget" name="centralwidget"/>
<widget class="QMenuBar" name="menubar"/>
<widget class="QStatusBar" name="statusbar"/>
</widget>
<resources/>
<connections/>
</ui>
+21
View File
@@ -0,0 +1,21 @@
#include "ctinkerforge.h"
cTinkerForge::cTinkerForge(const QString& host, const int& port)
{
ipcon_create(&m_ipConnection);
if(ipcon_connect(&m_ipConnection, host.toLocal8Bit().data(), port) < 0)
return;
}
cTinkerForge::~cTinkerForge()
{
ipcon_destroy(&m_ipConnection);
}
IPConnection* cTinkerForge::connection()
{
return(&m_ipConnection);
}
+21
View File
@@ -0,0 +1,21 @@
#ifndef CTINKERFORGE_H
#define CTINKERFORGE_H
#include "tinkerforge/ip_connection.h"
#include <QString>
class cTinkerForge
{
public:
cTinkerForge(const QString& host, const int &port);
~cTinkerForge();
IPConnection* connection();
private:
IPConnection m_ipConnection;
};
#endif // CTINKERFORGE_H
+11
View File
@@ -0,0 +1,11 @@
#include "cmainwindow.h"
#include <QApplication>
int main(int argc, char *argv[])
{
QApplication a(argc, argv);
cMainWindow w;
w.show();
return a.exec();
}
File diff suppressed because it is too large Load Diff
File diff suppressed because it is too large Load Diff
File diff suppressed because it is too large Load Diff
+941
View File
@@ -0,0 +1,941 @@
/* ***********************************************************
* This file was automatically generated on 2021-01-15. *
* *
* C/C++ Bindings Version 2.1.31 *
* *
* If you have a bugfix for this file and want to commit it, *
* please fix the bug in the generator. You can find a link *
* to the generators git repository on tinkerforge.com *
*************************************************************/
#ifndef BRICKLET_AIR_QUALITY_H
#define BRICKLET_AIR_QUALITY_H
#include "ip_connection.h"
#ifdef __cplusplus
extern "C" {
#endif
/**
* \defgroup BrickletAirQuality Air Quality Bricklet
*/
/**
* \ingroup BrickletAirQuality
*
* Measures IAQ index, temperature, humidity and air pressure
*/
typedef Device AirQuality;
/**
* \ingroup BrickletAirQuality
*/
#define AIR_QUALITY_FUNCTION_GET_ALL_VALUES 1
/**
* \ingroup BrickletAirQuality
*/
#define AIR_QUALITY_FUNCTION_SET_TEMPERATURE_OFFSET 2
/**
* \ingroup BrickletAirQuality
*/
#define AIR_QUALITY_FUNCTION_GET_TEMPERATURE_OFFSET 3
/**
* \ingroup BrickletAirQuality
*/
#define AIR_QUALITY_FUNCTION_SET_ALL_VALUES_CALLBACK_CONFIGURATION 4
/**
* \ingroup BrickletAirQuality
*/
#define AIR_QUALITY_FUNCTION_GET_ALL_VALUES_CALLBACK_CONFIGURATION 5
/**
* \ingroup BrickletAirQuality
*/
#define AIR_QUALITY_FUNCTION_GET_IAQ_INDEX 7
/**
* \ingroup BrickletAirQuality
*/
#define AIR_QUALITY_FUNCTION_SET_IAQ_INDEX_CALLBACK_CONFIGURATION 8
/**
* \ingroup BrickletAirQuality
*/
#define AIR_QUALITY_FUNCTION_GET_IAQ_INDEX_CALLBACK_CONFIGURATION 9
/**
* \ingroup BrickletAirQuality
*/
#define AIR_QUALITY_FUNCTION_GET_TEMPERATURE 11
/**
* \ingroup BrickletAirQuality
*/
#define AIR_QUALITY_FUNCTION_SET_TEMPERATURE_CALLBACK_CONFIGURATION 12
/**
* \ingroup BrickletAirQuality
*/
#define AIR_QUALITY_FUNCTION_GET_TEMPERATURE_CALLBACK_CONFIGURATION 13
/**
* \ingroup BrickletAirQuality
*/
#define AIR_QUALITY_FUNCTION_GET_HUMIDITY 15
/**
* \ingroup BrickletAirQuality
*/
#define AIR_QUALITY_FUNCTION_SET_HUMIDITY_CALLBACK_CONFIGURATION 16
/**
* \ingroup BrickletAirQuality
*/
#define AIR_QUALITY_FUNCTION_GET_HUMIDITY_CALLBACK_CONFIGURATION 17
/**
* \ingroup BrickletAirQuality
*/
#define AIR_QUALITY_FUNCTION_GET_AIR_PRESSURE 19
/**
* \ingroup BrickletAirQuality
*/
#define AIR_QUALITY_FUNCTION_SET_AIR_PRESSURE_CALLBACK_CONFIGURATION 20
/**
* \ingroup BrickletAirQuality
*/
#define AIR_QUALITY_FUNCTION_GET_AIR_PRESSURE_CALLBACK_CONFIGURATION 21
/**
* \ingroup BrickletAirQuality
*/
#define AIR_QUALITY_FUNCTION_REMOVE_CALIBRATION 23
/**
* \ingroup BrickletAirQuality
*/
#define AIR_QUALITY_FUNCTION_SET_BACKGROUND_CALIBRATION_DURATION 24
/**
* \ingroup BrickletAirQuality
*/
#define AIR_QUALITY_FUNCTION_GET_BACKGROUND_CALIBRATION_DURATION 25
/**
* \ingroup BrickletAirQuality
*/
#define AIR_QUALITY_FUNCTION_GET_SPITFP_ERROR_COUNT 234
/**
* \ingroup BrickletAirQuality
*/
#define AIR_QUALITY_FUNCTION_SET_BOOTLOADER_MODE 235
/**
* \ingroup BrickletAirQuality
*/
#define AIR_QUALITY_FUNCTION_GET_BOOTLOADER_MODE 236
/**
* \ingroup BrickletAirQuality
*/
#define AIR_QUALITY_FUNCTION_SET_WRITE_FIRMWARE_POINTER 237
/**
* \ingroup BrickletAirQuality
*/
#define AIR_QUALITY_FUNCTION_WRITE_FIRMWARE 238
/**
* \ingroup BrickletAirQuality
*/
#define AIR_QUALITY_FUNCTION_SET_STATUS_LED_CONFIG 239
/**
* \ingroup BrickletAirQuality
*/
#define AIR_QUALITY_FUNCTION_GET_STATUS_LED_CONFIG 240
/**
* \ingroup BrickletAirQuality
*/
#define AIR_QUALITY_FUNCTION_GET_CHIP_TEMPERATURE 242
/**
* \ingroup BrickletAirQuality
*/
#define AIR_QUALITY_FUNCTION_RESET 243
/**
* \ingroup BrickletAirQuality
*/
#define AIR_QUALITY_FUNCTION_WRITE_UID 248
/**
* \ingroup BrickletAirQuality
*/
#define AIR_QUALITY_FUNCTION_READ_UID 249
/**
* \ingroup BrickletAirQuality
*/
#define AIR_QUALITY_FUNCTION_GET_IDENTITY 255
/**
* \ingroup BrickletAirQuality
*
* Signature: \code void callback(int32_t iaq_index, uint8_t iaq_index_accuracy, int32_t temperature, int32_t humidity, int32_t air_pressure, void *user_data) \endcode
*
* This callback is triggered periodically according to the configuration set by
* {@link air_quality_set_all_values_callback_configuration}.
*
* The parameters are the same as {@link air_quality_get_all_values}.
*/
#define AIR_QUALITY_CALLBACK_ALL_VALUES 6
/**
* \ingroup BrickletAirQuality
*
* Signature: \code void callback(int32_t iaq_index, uint8_t iaq_index_accuracy, void *user_data) \endcode
*
* This callback is triggered periodically according to the configuration set by
* {@link air_quality_set_iaq_index_callback_configuration}.
*
* The parameters are the same as {@link air_quality_get_iaq_index}.
*/
#define AIR_QUALITY_CALLBACK_IAQ_INDEX 10
/**
* \ingroup BrickletAirQuality
*
* Signature: \code void callback(int32_t temperature, void *user_data) \endcode
*
* This callback is triggered periodically according to the configuration set by
* {@link air_quality_set_temperature_callback_configuration}.
*
* The parameter is the same as {@link air_quality_get_temperature}.
*/
#define AIR_QUALITY_CALLBACK_TEMPERATURE 14
/**
* \ingroup BrickletAirQuality
*
* Signature: \code void callback(int32_t humidity, void *user_data) \endcode
*
* This callback is triggered periodically according to the configuration set by
* {@link air_quality_set_humidity_callback_configuration}.
*
* The parameter is the same as {@link air_quality_get_humidity}.
*/
#define AIR_QUALITY_CALLBACK_HUMIDITY 18
/**
* \ingroup BrickletAirQuality
*
* Signature: \code void callback(int32_t air_pressure, void *user_data) \endcode
*
* This callback is triggered periodically according to the configuration set by
* {@link air_quality_set_air_pressure_callback_configuration}.
*
* The parameter is the same as {@link air_quality_get_air_pressure}.
*/
#define AIR_QUALITY_CALLBACK_AIR_PRESSURE 22
/**
* \ingroup BrickletAirQuality
*/
#define AIR_QUALITY_ACCURACY_UNRELIABLE 0
/**
* \ingroup BrickletAirQuality
*/
#define AIR_QUALITY_ACCURACY_LOW 1
/**
* \ingroup BrickletAirQuality
*/
#define AIR_QUALITY_ACCURACY_MEDIUM 2
/**
* \ingroup BrickletAirQuality
*/
#define AIR_QUALITY_ACCURACY_HIGH 3
/**
* \ingroup BrickletAirQuality
*/
#define AIR_QUALITY_THRESHOLD_OPTION_OFF 'x'
/**
* \ingroup BrickletAirQuality
*/
#define AIR_QUALITY_THRESHOLD_OPTION_OUTSIDE 'o'
/**
* \ingroup BrickletAirQuality
*/
#define AIR_QUALITY_THRESHOLD_OPTION_INSIDE 'i'
/**
* \ingroup BrickletAirQuality
*/
#define AIR_QUALITY_THRESHOLD_OPTION_SMALLER '<'
/**
* \ingroup BrickletAirQuality
*/
#define AIR_QUALITY_THRESHOLD_OPTION_GREATER '>'
/**
* \ingroup BrickletAirQuality
*/
#define AIR_QUALITY_DURATION_4_DAYS 0
/**
* \ingroup BrickletAirQuality
*/
#define AIR_QUALITY_DURATION_28_DAYS 1
/**
* \ingroup BrickletAirQuality
*/
#define AIR_QUALITY_BOOTLOADER_MODE_BOOTLOADER 0
/**
* \ingroup BrickletAirQuality
*/
#define AIR_QUALITY_BOOTLOADER_MODE_FIRMWARE 1
/**
* \ingroup BrickletAirQuality
*/
#define AIR_QUALITY_BOOTLOADER_MODE_BOOTLOADER_WAIT_FOR_REBOOT 2
/**
* \ingroup BrickletAirQuality
*/
#define AIR_QUALITY_BOOTLOADER_MODE_FIRMWARE_WAIT_FOR_REBOOT 3
/**
* \ingroup BrickletAirQuality
*/
#define AIR_QUALITY_BOOTLOADER_MODE_FIRMWARE_WAIT_FOR_ERASE_AND_REBOOT 4
/**
* \ingroup BrickletAirQuality
*/
#define AIR_QUALITY_BOOTLOADER_STATUS_OK 0
/**
* \ingroup BrickletAirQuality
*/
#define AIR_QUALITY_BOOTLOADER_STATUS_INVALID_MODE 1
/**
* \ingroup BrickletAirQuality
*/
#define AIR_QUALITY_BOOTLOADER_STATUS_NO_CHANGE 2
/**
* \ingroup BrickletAirQuality
*/
#define AIR_QUALITY_BOOTLOADER_STATUS_ENTRY_FUNCTION_NOT_PRESENT 3
/**
* \ingroup BrickletAirQuality
*/
#define AIR_QUALITY_BOOTLOADER_STATUS_DEVICE_IDENTIFIER_INCORRECT 4
/**
* \ingroup BrickletAirQuality
*/
#define AIR_QUALITY_BOOTLOADER_STATUS_CRC_MISMATCH 5
/**
* \ingroup BrickletAirQuality
*/
#define AIR_QUALITY_STATUS_LED_CONFIG_OFF 0
/**
* \ingroup BrickletAirQuality
*/
#define AIR_QUALITY_STATUS_LED_CONFIG_ON 1
/**
* \ingroup BrickletAirQuality
*/
#define AIR_QUALITY_STATUS_LED_CONFIG_SHOW_HEARTBEAT 2
/**
* \ingroup BrickletAirQuality
*/
#define AIR_QUALITY_STATUS_LED_CONFIG_SHOW_STATUS 3
/**
* \ingroup BrickletAirQuality
*
* This constant is used to identify a Air Quality Bricklet.
*
* The {@link air_quality_get_identity} function and the
* {@link IPCON_CALLBACK_ENUMERATE} callback of the IP Connection have a
* \c device_identifier parameter to specify the Brick's or Bricklet's type.
*/
#define AIR_QUALITY_DEVICE_IDENTIFIER 297
/**
* \ingroup BrickletAirQuality
*
* This constant represents the display name of a Air Quality Bricklet.
*/
#define AIR_QUALITY_DEVICE_DISPLAY_NAME "Air Quality Bricklet"
/**
* \ingroup BrickletAirQuality
*
* Creates the device object \c air_quality with the unique device ID \c uid and adds
* it to the IPConnection \c ipcon.
*/
void air_quality_create(AirQuality *air_quality, const char *uid, IPConnection *ipcon);
/**
* \ingroup BrickletAirQuality
*
* Removes the device object \c air_quality from its IPConnection and destroys it.
* The device object cannot be used anymore afterwards.
*/
void air_quality_destroy(AirQuality *air_quality);
/**
* \ingroup BrickletAirQuality
*
* Returns the response expected flag for the function specified by the
* \c function_id parameter. It is *true* if the function is expected to
* send a response, *false* otherwise.
*
* For getter functions this is enabled by default and cannot be disabled,
* because those functions will always send a response. For callback
* configuration functions it is enabled by default too, but can be disabled
* via the air_quality_set_response_expected function. For setter functions it is
* disabled by default and can be enabled.
*
* Enabling the response expected flag for a setter function allows to
* detect timeouts and other error conditions calls of this setter as well.
* The device will then send a response for this purpose. If this flag is
* disabled for a setter function then no response is sent and errors are
* silently ignored, because they cannot be detected.
*/
int air_quality_get_response_expected(AirQuality *air_quality, uint8_t function_id, bool *ret_response_expected);
/**
* \ingroup BrickletAirQuality
*
* Changes the response expected flag of the function specified by the
* \c function_id parameter. This flag can only be changed for setter
* (default value: *false*) and callback configuration functions
* (default value: *true*). For getter functions it is always enabled.
*
* Enabling the response expected flag for a setter function allows to detect
* timeouts and other error conditions calls of this setter as well. The device
* will then send a response for this purpose. If this flag is disabled for a
* setter function then no response is sent and errors are silently ignored,
* because they cannot be detected.
*/
int air_quality_set_response_expected(AirQuality *air_quality, uint8_t function_id, bool response_expected);
/**
* \ingroup BrickletAirQuality
*
* Changes the response expected flag for all setter and callback configuration
* functions of this device at once.
*/
int air_quality_set_response_expected_all(AirQuality *air_quality, bool response_expected);
/**
* \ingroup BrickletAirQuality
*
* Registers the given \c function with the given \c callback_id. The
* \c user_data will be passed as the last parameter to the \c function.
*/
void air_quality_register_callback(AirQuality *air_quality, int16_t callback_id, void (*function)(void), void *user_data);
/**
* \ingroup BrickletAirQuality
*
* Returns the API version (major, minor, release) of the bindings for this
* device.
*/
int air_quality_get_api_version(AirQuality *air_quality, uint8_t ret_api_version[3]);
/**
* \ingroup BrickletAirQuality
*
* Returns all values measured by the Air Quality Bricklet. The values are
* IAQ (Indoor Air Quality) Index (higher value means greater level of air pollution), IAQ Index Accuracy, Temperature, Humidity and
* Air Pressure.
*
* .. image:: /Images/Misc/bricklet_air_quality_iaq_index.png
* :scale: 100 %
* :alt: Air Quality Index description
* :align: center
* :target: ../../_images/Misc/bricklet_air_quality_iaq_index.png
*/
int air_quality_get_all_values(AirQuality *air_quality, int32_t *ret_iaq_index, uint8_t *ret_iaq_index_accuracy, int32_t *ret_temperature, int32_t *ret_humidity, int32_t *ret_air_pressure);
/**
* \ingroup BrickletAirQuality
*
* Sets a temperature offset. A offset of 10 will decrease the measured temperature by 0.1 °C.
*
* If you install this Bricklet into an enclosure and you want to measure the ambient
* temperature, you may have to decrease the measured temperature by some value to
* compensate for the error because of the heating inside of the enclosure.
*
* We recommend that you leave the parts in the enclosure running for at least
* 24 hours such that a temperature equilibrium can be reached. After that you can measure
* the temperature directly outside of enclosure and set the difference as offset.
*
* This temperature offset is used to calculate the relative humidity and
* IAQ index measurements. In case the Bricklet is installed in an enclosure, we
* recommend to measure and set the temperature offset to improve the accuracy of
* the measurements.
*/
int air_quality_set_temperature_offset(AirQuality *air_quality, int32_t offset);
/**
* \ingroup BrickletAirQuality
*
* Returns the temperature offset as set by
* {@link air_quality_set_temperature_offset}.
*/
int air_quality_get_temperature_offset(AirQuality *air_quality, int32_t *ret_offset);
/**
* \ingroup BrickletAirQuality
*
* The period is the period with which the {@link AIR_QUALITY_CALLBACK_ALL_VALUES}
* callback is triggered periodically. A value of 0 turns the callback off.
*
* If the `value has to change`-parameter is set to true, the callback is only
* triggered after at least one of the values has changed. If the values didn't
* change within the period, the callback is triggered immediately on change.
*
* If it is set to false, the callback is continuously triggered with the period,
* independent of the value.
*/
int air_quality_set_all_values_callback_configuration(AirQuality *air_quality, uint32_t period, bool value_has_to_change);
/**
* \ingroup BrickletAirQuality
*
* Returns the callback configuration as set by
* {@link air_quality_set_all_values_callback_configuration}.
*/
int air_quality_get_all_values_callback_configuration(AirQuality *air_quality, uint32_t *ret_period, bool *ret_value_has_to_change);
/**
* \ingroup BrickletAirQuality
*
* Returns the IAQ index and accuracy. The higher the IAQ index, the greater the level of air pollution.
*
* .. image:: /Images/Misc/bricklet_air_quality_iaq_index.png
* :scale: 100 %
* :alt: IAQ index description
* :align: center
* :target: ../../_images/Misc/bricklet_air_quality_iaq_index.png
*
* If you want to get the value periodically, it is recommended to use the
* {@link AIR_QUALITY_CALLBACK_IAQ_INDEX} callback. You can set the callback configuration
* with {@link air_quality_set_iaq_index_callback_configuration}.
*/
int air_quality_get_iaq_index(AirQuality *air_quality, int32_t *ret_iaq_index, uint8_t *ret_iaq_index_accuracy);
/**
* \ingroup BrickletAirQuality
*
* The period is the period with which the {@link AIR_QUALITY_CALLBACK_IAQ_INDEX}
* callback is triggered periodically. A value of 0 turns the callback off.
*
* If the `value has to change`-parameter is set to true, the callback is only
* triggered after at least one of the values has changed. If the values didn't
* change within the period, the callback is triggered immediately on change.
*
* If it is set to false, the callback is continuously triggered with the period,
* independent of the value.
*/
int air_quality_set_iaq_index_callback_configuration(AirQuality *air_quality, uint32_t period, bool value_has_to_change);
/**
* \ingroup BrickletAirQuality
*
* Returns the callback configuration as set by
* {@link air_quality_set_iaq_index_callback_configuration}.
*/
int air_quality_get_iaq_index_callback_configuration(AirQuality *air_quality, uint32_t *ret_period, bool *ret_value_has_to_change);
/**
* \ingroup BrickletAirQuality
*
* Returns temperature.
*
*
* If you want to get the value periodically, it is recommended to use the
* {@link AIR_QUALITY_CALLBACK_TEMPERATURE} callback. You can set the callback configuration
* with {@link air_quality_set_temperature_callback_configuration}.
*/
int air_quality_get_temperature(AirQuality *air_quality, int32_t *ret_temperature);
/**
* \ingroup BrickletAirQuality
*
* The period is the period with which the {@link AIR_QUALITY_CALLBACK_TEMPERATURE} callback is triggered
* periodically. A value of 0 turns the callback off.
*
* If the `value has to change`-parameter is set to true, the callback is only
* triggered after the value has changed. If the value didn't change
* within the period, the callback is triggered immediately on change.
*
* If it is set to false, the callback is continuously triggered with the period,
* independent of the value.
*
* It is furthermore possible to constrain the callback with thresholds.
*
* The `option`-parameter together with min/max sets a threshold for the {@link AIR_QUALITY_CALLBACK_TEMPERATURE} callback.
*
* The following options are possible:
*
* \verbatim
* "Option", "Description"
*
* "'x'", "Threshold is turned off"
* "'o'", "Threshold is triggered when the value is *outside* the min and max values"
* "'i'", "Threshold is triggered when the value is *inside* or equal to the min and max values"
* "'<'", "Threshold is triggered when the value is smaller than the min value (max is ignored)"
* "'>'", "Threshold is triggered when the value is greater than the min value (max is ignored)"
* \endverbatim
*
* If the option is set to 'x' (threshold turned off) the callback is triggered with the fixed period.
*/
int air_quality_set_temperature_callback_configuration(AirQuality *air_quality, uint32_t period, bool value_has_to_change, char option, int32_t min, int32_t max);
/**
* \ingroup BrickletAirQuality
*
* Returns the callback configuration as set by {@link air_quality_set_temperature_callback_configuration}.
*/
int air_quality_get_temperature_callback_configuration(AirQuality *air_quality, uint32_t *ret_period, bool *ret_value_has_to_change, char *ret_option, int32_t *ret_min, int32_t *ret_max);
/**
* \ingroup BrickletAirQuality
*
* Returns relative humidity.
*
*
* If you want to get the value periodically, it is recommended to use the
* {@link AIR_QUALITY_CALLBACK_HUMIDITY} callback. You can set the callback configuration
* with {@link air_quality_set_humidity_callback_configuration}.
*/
int air_quality_get_humidity(AirQuality *air_quality, int32_t *ret_humidity);
/**
* \ingroup BrickletAirQuality
*
* The period is the period with which the {@link AIR_QUALITY_CALLBACK_HUMIDITY} callback is triggered
* periodically. A value of 0 turns the callback off.
*
* If the `value has to change`-parameter is set to true, the callback is only
* triggered after the value has changed. If the value didn't change
* within the period, the callback is triggered immediately on change.
*
* If it is set to false, the callback is continuously triggered with the period,
* independent of the value.
*
* It is furthermore possible to constrain the callback with thresholds.
*
* The `option`-parameter together with min/max sets a threshold for the {@link AIR_QUALITY_CALLBACK_HUMIDITY} callback.
*
* The following options are possible:
*
* \verbatim
* "Option", "Description"
*
* "'x'", "Threshold is turned off"
* "'o'", "Threshold is triggered when the value is *outside* the min and max values"
* "'i'", "Threshold is triggered when the value is *inside* or equal to the min and max values"
* "'<'", "Threshold is triggered when the value is smaller than the min value (max is ignored)"
* "'>'", "Threshold is triggered when the value is greater than the min value (max is ignored)"
* \endverbatim
*
* If the option is set to 'x' (threshold turned off) the callback is triggered with the fixed period.
*/
int air_quality_set_humidity_callback_configuration(AirQuality *air_quality, uint32_t period, bool value_has_to_change, char option, int32_t min, int32_t max);
/**
* \ingroup BrickletAirQuality
*
* Returns the callback configuration as set by {@link air_quality_set_humidity_callback_configuration}.
*/
int air_quality_get_humidity_callback_configuration(AirQuality *air_quality, uint32_t *ret_period, bool *ret_value_has_to_change, char *ret_option, int32_t *ret_min, int32_t *ret_max);
/**
* \ingroup BrickletAirQuality
*
* Returns air pressure.
*
*
* If you want to get the value periodically, it is recommended to use the
* {@link AIR_QUALITY_CALLBACK_AIR_PRESSURE} callback. You can set the callback configuration
* with {@link air_quality_set_air_pressure_callback_configuration}.
*/
int air_quality_get_air_pressure(AirQuality *air_quality, int32_t *ret_air_pressure);
/**
* \ingroup BrickletAirQuality
*
* The period is the period with which the {@link AIR_QUALITY_CALLBACK_AIR_PRESSURE} callback is triggered
* periodically. A value of 0 turns the callback off.
*
* If the `value has to change`-parameter is set to true, the callback is only
* triggered after the value has changed. If the value didn't change
* within the period, the callback is triggered immediately on change.
*
* If it is set to false, the callback is continuously triggered with the period,
* independent of the value.
*
* It is furthermore possible to constrain the callback with thresholds.
*
* The `option`-parameter together with min/max sets a threshold for the {@link AIR_QUALITY_CALLBACK_AIR_PRESSURE} callback.
*
* The following options are possible:
*
* \verbatim
* "Option", "Description"
*
* "'x'", "Threshold is turned off"
* "'o'", "Threshold is triggered when the value is *outside* the min and max values"
* "'i'", "Threshold is triggered when the value is *inside* or equal to the min and max values"
* "'<'", "Threshold is triggered when the value is smaller than the min value (max is ignored)"
* "'>'", "Threshold is triggered when the value is greater than the min value (max is ignored)"
* \endverbatim
*
* If the option is set to 'x' (threshold turned off) the callback is triggered with the fixed period.
*/
int air_quality_set_air_pressure_callback_configuration(AirQuality *air_quality, uint32_t period, bool value_has_to_change, char option, int32_t min, int32_t max);
/**
* \ingroup BrickletAirQuality
*
* Returns the callback configuration as set by {@link air_quality_set_air_pressure_callback_configuration}.
*/
int air_quality_get_air_pressure_callback_configuration(AirQuality *air_quality, uint32_t *ret_period, bool *ret_value_has_to_change, char *ret_option, int32_t *ret_min, int32_t *ret_max);
/**
* \ingroup BrickletAirQuality
*
* Deletes the calibration from flash. After you call this function,
* you need to power cycle the Air Quality Bricklet.
*
* On the next power up the Bricklet will start a new calibration, as
* if it was started for the very first time.
*
* The calibration is based on the data of the last four days, so it takes
* four days until a full calibration is re-established.
*
* .. versionadded:: 2.0.3$nbsp;(Plugin)
*/
int air_quality_remove_calibration(AirQuality *air_quality);
/**
* \ingroup BrickletAirQuality
*
* The Air Quality Bricklet uses an automatic background calibration mechanism to
* calculate the IAQ Index. This calibration mechanism considers a history of
* measured data. The duration of this history can be configured to either be
* 4 days or 28 days.
*
* If you keep the Bricklet mostly at one place and it does not get moved around
* to different environments, we recommend that you use a duration of 28 days.
*
* If you change the duration, the current calibration will be discarded and
* the calibration will start from beginning again. The configuration of the
* duration is saved in flash, so you should only have to call this function
* once in the lifetime of the Bricklet.
*
* The Bricklet has to be power cycled after this function is called
* for a duration change to take effect.
*
* Before firmware version 2.0.3 this was not configurable and the duration was
* 4 days.
*
* The default value (since firmware version 2.0.3) is 28 days.
*
* .. versionadded:: 2.0.3$nbsp;(Plugin)
*/
int air_quality_set_background_calibration_duration(AirQuality *air_quality, uint8_t duration);
/**
* \ingroup BrickletAirQuality
*
* Returns the background calibration duration as set by
* {@link air_quality_set_background_calibration_duration}.
*
* .. versionadded:: 2.0.3$nbsp;(Plugin)
*/
int air_quality_get_background_calibration_duration(AirQuality *air_quality, uint8_t *ret_duration);
/**
* \ingroup BrickletAirQuality
*
* Returns the error count for the communication between Brick and Bricklet.
*
* The errors are divided into
*
* * ACK checksum errors,
* * message checksum errors,
* * framing errors and
* * overflow errors.
*
* The errors counts are for errors that occur on the Bricklet side. All
* Bricks have a similar function that returns the errors on the Brick side.
*/
int air_quality_get_spitfp_error_count(AirQuality *air_quality, uint32_t *ret_error_count_ack_checksum, uint32_t *ret_error_count_message_checksum, uint32_t *ret_error_count_frame, uint32_t *ret_error_count_overflow);
/**
* \ingroup BrickletAirQuality
*
* Sets the bootloader mode and returns the status after the requested
* mode change was instigated.
*
* You can change from bootloader mode to firmware mode and vice versa. A change
* from bootloader mode to firmware mode will only take place if the entry function,
* device identifier and CRC are present and correct.
*
* This function is used by Brick Viewer during flashing. It should not be
* necessary to call it in a normal user program.
*/
int air_quality_set_bootloader_mode(AirQuality *air_quality, uint8_t mode, uint8_t *ret_status);
/**
* \ingroup BrickletAirQuality
*
* Returns the current bootloader mode, see {@link air_quality_set_bootloader_mode}.
*/
int air_quality_get_bootloader_mode(AirQuality *air_quality, uint8_t *ret_mode);
/**
* \ingroup BrickletAirQuality
*
* Sets the firmware pointer for {@link air_quality_write_firmware}. The pointer has
* to be increased by chunks of size 64. The data is written to flash
* every 4 chunks (which equals to one page of size 256).
*
* This function is used by Brick Viewer during flashing. It should not be
* necessary to call it in a normal user program.
*/
int air_quality_set_write_firmware_pointer(AirQuality *air_quality, uint32_t pointer);
/**
* \ingroup BrickletAirQuality
*
* Writes 64 Bytes of firmware at the position as written by
* {@link air_quality_set_write_firmware_pointer} before. The firmware is written
* to flash every 4 chunks.
*
* You can only write firmware in bootloader mode.
*
* This function is used by Brick Viewer during flashing. It should not be
* necessary to call it in a normal user program.
*/
int air_quality_write_firmware(AirQuality *air_quality, uint8_t data[64], uint8_t *ret_status);
/**
* \ingroup BrickletAirQuality
*
* Sets the status LED configuration. By default the LED shows
* communication traffic between Brick and Bricklet, it flickers once
* for every 10 received data packets.
*
* You can also turn the LED permanently on/off or show a heartbeat.
*
* If the Bricklet is in bootloader mode, the LED is will show heartbeat by default.
*/
int air_quality_set_status_led_config(AirQuality *air_quality, uint8_t config);
/**
* \ingroup BrickletAirQuality
*
* Returns the configuration as set by {@link air_quality_set_status_led_config}
*/
int air_quality_get_status_led_config(AirQuality *air_quality, uint8_t *ret_config);
/**
* \ingroup BrickletAirQuality
*
* Returns the temperature as measured inside the microcontroller. The
* value returned is not the ambient temperature!
*
* The temperature is only proportional to the real temperature and it has bad
* accuracy. Practically it is only useful as an indicator for
* temperature changes.
*/
int air_quality_get_chip_temperature(AirQuality *air_quality, int16_t *ret_temperature);
/**
* \ingroup BrickletAirQuality
*
* Calling this function will reset the Bricklet. All configurations
* will be lost.
*
* After a reset you have to create new device objects,
* calling functions on the existing ones will result in
* undefined behavior!
*/
int air_quality_reset(AirQuality *air_quality);
/**
* \ingroup BrickletAirQuality
*
* Writes a new UID into flash. If you want to set a new UID
* you have to decode the Base58 encoded UID string into an
* integer first.
*
* We recommend that you use Brick Viewer to change the UID.
*/
int air_quality_write_uid(AirQuality *air_quality, uint32_t uid);
/**
* \ingroup BrickletAirQuality
*
* Returns the current UID as an integer. Encode as
* Base58 to get the usual string version.
*/
int air_quality_read_uid(AirQuality *air_quality, uint32_t *ret_uid);
/**
* \ingroup BrickletAirQuality
*
* Returns the UID, the UID where the Bricklet is connected to,
* the position, the hardware and firmware version as well as the
* device identifier.
*
* The position can be 'a', 'b', 'c', 'd', 'e', 'f', 'g' or 'h' (Bricklet Port).
* A Bricklet connected to an :ref:`Isolator Bricklet <isolator_bricklet>` is always at
* position 'z'.
*
* The device identifier numbers can be found :ref:`here <device_identifier>`.
* |device_identifier_constant|
*/
int air_quality_get_identity(AirQuality *air_quality, char ret_uid[8], char ret_connected_uid[8], char *ret_position, uint8_t ret_hardware_version[3], uint8_t ret_firmware_version[3], uint16_t *ret_device_identifier);
#ifdef __cplusplus
}
#endif
#endif
File diff suppressed because it is too large Load Diff
+682
View File
@@ -0,0 +1,682 @@
/* ***********************************************************
* This file was automatically generated on 2021-01-15. *
* *
* C/C++ Bindings Version 2.1.31 *
* *
* If you have a bugfix for this file and want to commit it, *
* please fix the bug in the generator. You can find a link *
* to the generators git repository on tinkerforge.com *
*************************************************************/
#ifndef BRICKLET_OUTDOOR_WEATHER_H
#define BRICKLET_OUTDOOR_WEATHER_H
#include "ip_connection.h"
#ifdef __cplusplus
extern "C" {
#endif
/**
* \defgroup BrickletOutdoorWeather Outdoor Weather Bricklet
*/
/**
* \ingroup BrickletOutdoorWeather
*
* 433MHz receiver for outdoor weather station
*/
typedef Device OutdoorWeather;
/**
* \ingroup BrickletOutdoorWeather
*/
#define OUTDOOR_WEATHER_FUNCTION_GET_STATION_IDENTIFIERS_LOW_LEVEL 1
/**
* \ingroup BrickletOutdoorWeather
*/
#define OUTDOOR_WEATHER_FUNCTION_GET_SENSOR_IDENTIFIERS_LOW_LEVEL 2
/**
* \ingroup BrickletOutdoorWeather
*/
#define OUTDOOR_WEATHER_FUNCTION_GET_STATION_DATA 3
/**
* \ingroup BrickletOutdoorWeather
*/
#define OUTDOOR_WEATHER_FUNCTION_GET_SENSOR_DATA 4
/**
* \ingroup BrickletOutdoorWeather
*/
#define OUTDOOR_WEATHER_FUNCTION_SET_STATION_CALLBACK_CONFIGURATION 5
/**
* \ingroup BrickletOutdoorWeather
*/
#define OUTDOOR_WEATHER_FUNCTION_GET_STATION_CALLBACK_CONFIGURATION 6
/**
* \ingroup BrickletOutdoorWeather
*/
#define OUTDOOR_WEATHER_FUNCTION_SET_SENSOR_CALLBACK_CONFIGURATION 7
/**
* \ingroup BrickletOutdoorWeather
*/
#define OUTDOOR_WEATHER_FUNCTION_GET_SENSOR_CALLBACK_CONFIGURATION 8
/**
* \ingroup BrickletOutdoorWeather
*/
#define OUTDOOR_WEATHER_FUNCTION_GET_SPITFP_ERROR_COUNT 234
/**
* \ingroup BrickletOutdoorWeather
*/
#define OUTDOOR_WEATHER_FUNCTION_SET_BOOTLOADER_MODE 235
/**
* \ingroup BrickletOutdoorWeather
*/
#define OUTDOOR_WEATHER_FUNCTION_GET_BOOTLOADER_MODE 236
/**
* \ingroup BrickletOutdoorWeather
*/
#define OUTDOOR_WEATHER_FUNCTION_SET_WRITE_FIRMWARE_POINTER 237
/**
* \ingroup BrickletOutdoorWeather
*/
#define OUTDOOR_WEATHER_FUNCTION_WRITE_FIRMWARE 238
/**
* \ingroup BrickletOutdoorWeather
*/
#define OUTDOOR_WEATHER_FUNCTION_SET_STATUS_LED_CONFIG 239
/**
* \ingroup BrickletOutdoorWeather
*/
#define OUTDOOR_WEATHER_FUNCTION_GET_STATUS_LED_CONFIG 240
/**
* \ingroup BrickletOutdoorWeather
*/
#define OUTDOOR_WEATHER_FUNCTION_GET_CHIP_TEMPERATURE 242
/**
* \ingroup BrickletOutdoorWeather
*/
#define OUTDOOR_WEATHER_FUNCTION_RESET 243
/**
* \ingroup BrickletOutdoorWeather
*/
#define OUTDOOR_WEATHER_FUNCTION_WRITE_UID 248
/**
* \ingroup BrickletOutdoorWeather
*/
#define OUTDOOR_WEATHER_FUNCTION_READ_UID 249
/**
* \ingroup BrickletOutdoorWeather
*/
#define OUTDOOR_WEATHER_FUNCTION_GET_IDENTITY 255
/**
* \ingroup BrickletOutdoorWeather
*
* Signature: \code void callback(uint8_t identifier, int16_t temperature, uint8_t humidity, uint32_t wind_speed, uint32_t gust_speed, uint32_t rain, uint8_t wind_direction, bool battery_low, void *user_data) \endcode
*
* Reports the station data every time a new data packet is received.
* See {@link outdoor_weather_get_station_data} for information about the data.
*
* For each station the callback will be triggered about every 45 seconds.
*
* Turn the callback on/off with {@link outdoor_weather_set_station_callback_configuration}
* (by default it is turned off).
*/
#define OUTDOOR_WEATHER_CALLBACK_STATION_DATA 9
/**
* \ingroup BrickletOutdoorWeather
*
* Signature: \code void callback(uint8_t identifier, int16_t temperature, uint8_t humidity, void *user_data) \endcode
*
* Reports the sensor data every time a new data packet is received.
* See {@link outdoor_weather_get_sensor_data} for information about the data.
*
* For each sensor the callback will be called about every 45 seconds.
*
* Turn the callback on/off with {@link outdoor_weather_set_sensor_callback_configuration}
* (by default it is turned off).
*/
#define OUTDOOR_WEATHER_CALLBACK_SENSOR_DATA 10
/**
* \ingroup BrickletOutdoorWeather
*/
#define OUTDOOR_WEATHER_WIND_DIRECTION_N 0
/**
* \ingroup BrickletOutdoorWeather
*/
#define OUTDOOR_WEATHER_WIND_DIRECTION_NNE 1
/**
* \ingroup BrickletOutdoorWeather
*/
#define OUTDOOR_WEATHER_WIND_DIRECTION_NE 2
/**
* \ingroup BrickletOutdoorWeather
*/
#define OUTDOOR_WEATHER_WIND_DIRECTION_ENE 3
/**
* \ingroup BrickletOutdoorWeather
*/
#define OUTDOOR_WEATHER_WIND_DIRECTION_E 4
/**
* \ingroup BrickletOutdoorWeather
*/
#define OUTDOOR_WEATHER_WIND_DIRECTION_ESE 5
/**
* \ingroup BrickletOutdoorWeather
*/
#define OUTDOOR_WEATHER_WIND_DIRECTION_SE 6
/**
* \ingroup BrickletOutdoorWeather
*/
#define OUTDOOR_WEATHER_WIND_DIRECTION_SSE 7
/**
* \ingroup BrickletOutdoorWeather
*/
#define OUTDOOR_WEATHER_WIND_DIRECTION_S 8
/**
* \ingroup BrickletOutdoorWeather
*/
#define OUTDOOR_WEATHER_WIND_DIRECTION_SSW 9
/**
* \ingroup BrickletOutdoorWeather
*/
#define OUTDOOR_WEATHER_WIND_DIRECTION_SW 10
/**
* \ingroup BrickletOutdoorWeather
*/
#define OUTDOOR_WEATHER_WIND_DIRECTION_WSW 11
/**
* \ingroup BrickletOutdoorWeather
*/
#define OUTDOOR_WEATHER_WIND_DIRECTION_W 12
/**
* \ingroup BrickletOutdoorWeather
*/
#define OUTDOOR_WEATHER_WIND_DIRECTION_WNW 13
/**
* \ingroup BrickletOutdoorWeather
*/
#define OUTDOOR_WEATHER_WIND_DIRECTION_NW 14
/**
* \ingroup BrickletOutdoorWeather
*/
#define OUTDOOR_WEATHER_WIND_DIRECTION_NNW 15
/**
* \ingroup BrickletOutdoorWeather
*/
#define OUTDOOR_WEATHER_WIND_DIRECTION_ERROR 255
/**
* \ingroup BrickletOutdoorWeather
*/
#define OUTDOOR_WEATHER_BOOTLOADER_MODE_BOOTLOADER 0
/**
* \ingroup BrickletOutdoorWeather
*/
#define OUTDOOR_WEATHER_BOOTLOADER_MODE_FIRMWARE 1
/**
* \ingroup BrickletOutdoorWeather
*/
#define OUTDOOR_WEATHER_BOOTLOADER_MODE_BOOTLOADER_WAIT_FOR_REBOOT 2
/**
* \ingroup BrickletOutdoorWeather
*/
#define OUTDOOR_WEATHER_BOOTLOADER_MODE_FIRMWARE_WAIT_FOR_REBOOT 3
/**
* \ingroup BrickletOutdoorWeather
*/
#define OUTDOOR_WEATHER_BOOTLOADER_MODE_FIRMWARE_WAIT_FOR_ERASE_AND_REBOOT 4
/**
* \ingroup BrickletOutdoorWeather
*/
#define OUTDOOR_WEATHER_BOOTLOADER_STATUS_OK 0
/**
* \ingroup BrickletOutdoorWeather
*/
#define OUTDOOR_WEATHER_BOOTLOADER_STATUS_INVALID_MODE 1
/**
* \ingroup BrickletOutdoorWeather
*/
#define OUTDOOR_WEATHER_BOOTLOADER_STATUS_NO_CHANGE 2
/**
* \ingroup BrickletOutdoorWeather
*/
#define OUTDOOR_WEATHER_BOOTLOADER_STATUS_ENTRY_FUNCTION_NOT_PRESENT 3
/**
* \ingroup BrickletOutdoorWeather
*/
#define OUTDOOR_WEATHER_BOOTLOADER_STATUS_DEVICE_IDENTIFIER_INCORRECT 4
/**
* \ingroup BrickletOutdoorWeather
*/
#define OUTDOOR_WEATHER_BOOTLOADER_STATUS_CRC_MISMATCH 5
/**
* \ingroup BrickletOutdoorWeather
*/
#define OUTDOOR_WEATHER_STATUS_LED_CONFIG_OFF 0
/**
* \ingroup BrickletOutdoorWeather
*/
#define OUTDOOR_WEATHER_STATUS_LED_CONFIG_ON 1
/**
* \ingroup BrickletOutdoorWeather
*/
#define OUTDOOR_WEATHER_STATUS_LED_CONFIG_SHOW_HEARTBEAT 2
/**
* \ingroup BrickletOutdoorWeather
*/
#define OUTDOOR_WEATHER_STATUS_LED_CONFIG_SHOW_STATUS 3
/**
* \ingroup BrickletOutdoorWeather
*
* This constant is used to identify a Outdoor Weather Bricklet.
*
* The {@link outdoor_weather_get_identity} function and the
* {@link IPCON_CALLBACK_ENUMERATE} callback of the IP Connection have a
* \c device_identifier parameter to specify the Brick's or Bricklet's type.
*/
#define OUTDOOR_WEATHER_DEVICE_IDENTIFIER 288
/**
* \ingroup BrickletOutdoorWeather
*
* This constant represents the display name of a Outdoor Weather Bricklet.
*/
#define OUTDOOR_WEATHER_DEVICE_DISPLAY_NAME "Outdoor Weather Bricklet"
/**
* \ingroup BrickletOutdoorWeather
*
* Creates the device object \c outdoor_weather with the unique device ID \c uid and adds
* it to the IPConnection \c ipcon.
*/
void outdoor_weather_create(OutdoorWeather *outdoor_weather, const char *uid, IPConnection *ipcon);
/**
* \ingroup BrickletOutdoorWeather
*
* Removes the device object \c outdoor_weather from its IPConnection and destroys it.
* The device object cannot be used anymore afterwards.
*/
void outdoor_weather_destroy(OutdoorWeather *outdoor_weather);
/**
* \ingroup BrickletOutdoorWeather
*
* Returns the response expected flag for the function specified by the
* \c function_id parameter. It is *true* if the function is expected to
* send a response, *false* otherwise.
*
* For getter functions this is enabled by default and cannot be disabled,
* because those functions will always send a response. For callback
* configuration functions it is enabled by default too, but can be disabled
* via the outdoor_weather_set_response_expected function. For setter functions it is
* disabled by default and can be enabled.
*
* Enabling the response expected flag for a setter function allows to
* detect timeouts and other error conditions calls of this setter as well.
* The device will then send a response for this purpose. If this flag is
* disabled for a setter function then no response is sent and errors are
* silently ignored, because they cannot be detected.
*/
int outdoor_weather_get_response_expected(OutdoorWeather *outdoor_weather, uint8_t function_id, bool *ret_response_expected);
/**
* \ingroup BrickletOutdoorWeather
*
* Changes the response expected flag of the function specified by the
* \c function_id parameter. This flag can only be changed for setter
* (default value: *false*) and callback configuration functions
* (default value: *true*). For getter functions it is always enabled.
*
* Enabling the response expected flag for a setter function allows to detect
* timeouts and other error conditions calls of this setter as well. The device
* will then send a response for this purpose. If this flag is disabled for a
* setter function then no response is sent and errors are silently ignored,
* because they cannot be detected.
*/
int outdoor_weather_set_response_expected(OutdoorWeather *outdoor_weather, uint8_t function_id, bool response_expected);
/**
* \ingroup BrickletOutdoorWeather
*
* Changes the response expected flag for all setter and callback configuration
* functions of this device at once.
*/
int outdoor_weather_set_response_expected_all(OutdoorWeather *outdoor_weather, bool response_expected);
/**
* \ingroup BrickletOutdoorWeather
*
* Registers the given \c function with the given \c callback_id. The
* \c user_data will be passed as the last parameter to the \c function.
*/
void outdoor_weather_register_callback(OutdoorWeather *outdoor_weather, int16_t callback_id, void (*function)(void), void *user_data);
/**
* \ingroup BrickletOutdoorWeather
*
* Returns the API version (major, minor, release) of the bindings for this
* device.
*/
int outdoor_weather_get_api_version(OutdoorWeather *outdoor_weather, uint8_t ret_api_version[3]);
/**
* \ingroup BrickletOutdoorWeather
*
* Returns the identifiers (number between 0 and 255) of all `stations
* <https://www.tinkerforge.com/en/shop/accessories/sensors/outdoor-weather-station-ws-6147.html>`__
* that have been seen since the startup of the Bricklet.
*
* Each station gives itself a random identifier on first startup.
*
* Since firmware version 2.0.2 a station is removed from the list if no data was received for
* 12 hours.
*/
int outdoor_weather_get_station_identifiers_low_level(OutdoorWeather *outdoor_weather, uint16_t *ret_identifiers_length, uint16_t *ret_identifiers_chunk_offset, uint8_t ret_identifiers_chunk_data[60]);
/**
* \ingroup BrickletOutdoorWeather
*
* Returns the identifiers (number between 0 and 255) of all `sensors
* <https://www.tinkerforge.com/en/shop/accessories/sensors/temperature-humidity-sensor-th-6148.html>`__
* that have been seen since the startup of the Bricklet.
*
* Each sensor gives itself a random identifier on first startup.
*
* Since firmware version 2.0.2 a sensor is removed from the list if no data was received for
* 12 hours.
*/
int outdoor_weather_get_sensor_identifiers_low_level(OutdoorWeather *outdoor_weather, uint16_t *ret_identifiers_length, uint16_t *ret_identifiers_chunk_offset, uint8_t ret_identifiers_chunk_data[60]);
/**
* \ingroup BrickletOutdoorWeather
*
* Returns the last received data for a station with the given identifier.
* Call {@link outdoor_weather_get_station_identifiers} for a list of all available identifiers.
*
* The return values are:
*
* * Temperature,
* * Humidity,
* * Wind Speed,
* * Gust Speed,
* * Rain Fall (accumulated since station power-up),
* * Wind Direction,
* * Battery Low (true if battery is low) and
* * Last Change (seconds since the reception of this data).
*/
int outdoor_weather_get_station_data(OutdoorWeather *outdoor_weather, uint8_t identifier, int16_t *ret_temperature, uint8_t *ret_humidity, uint32_t *ret_wind_speed, uint32_t *ret_gust_speed, uint32_t *ret_rain, uint8_t *ret_wind_direction, bool *ret_battery_low, uint16_t *ret_last_change);
/**
* \ingroup BrickletOutdoorWeather
*
* Returns the last measured data for a sensor with the given identifier.
* Call {@link outdoor_weather_get_sensor_identifiers} for a list of all available identifiers.
*
* The return values are:
*
* * Temperature,
* * Humidity and
* * Last Change (seconds since the last reception of data).
*/
int outdoor_weather_get_sensor_data(OutdoorWeather *outdoor_weather, uint8_t identifier, int16_t *ret_temperature, uint8_t *ret_humidity, uint16_t *ret_last_change);
/**
* \ingroup BrickletOutdoorWeather
*
* Turns callback for station data on or off.
*/
int outdoor_weather_set_station_callback_configuration(OutdoorWeather *outdoor_weather, bool enable_callback);
/**
* \ingroup BrickletOutdoorWeather
*
* Returns the configuration as set by {@link outdoor_weather_set_station_callback_configuration}.
*/
int outdoor_weather_get_station_callback_configuration(OutdoorWeather *outdoor_weather, bool *ret_enable_callback);
/**
* \ingroup BrickletOutdoorWeather
*
* Turns callback for sensor data on or off.
*/
int outdoor_weather_set_sensor_callback_configuration(OutdoorWeather *outdoor_weather, bool enable_callback);
/**
* \ingroup BrickletOutdoorWeather
*
* Returns the configuration as set by {@link outdoor_weather_set_sensor_callback_configuration}.
*/
int outdoor_weather_get_sensor_callback_configuration(OutdoorWeather *outdoor_weather, bool *ret_enable_callback);
/**
* \ingroup BrickletOutdoorWeather
*
* Returns the error count for the communication between Brick and Bricklet.
*
* The errors are divided into
*
* * ACK checksum errors,
* * message checksum errors,
* * framing errors and
* * overflow errors.
*
* The errors counts are for errors that occur on the Bricklet side. All
* Bricks have a similar function that returns the errors on the Brick side.
*/
int outdoor_weather_get_spitfp_error_count(OutdoorWeather *outdoor_weather, uint32_t *ret_error_count_ack_checksum, uint32_t *ret_error_count_message_checksum, uint32_t *ret_error_count_frame, uint32_t *ret_error_count_overflow);
/**
* \ingroup BrickletOutdoorWeather
*
* Sets the bootloader mode and returns the status after the requested
* mode change was instigated.
*
* You can change from bootloader mode to firmware mode and vice versa. A change
* from bootloader mode to firmware mode will only take place if the entry function,
* device identifier and CRC are present and correct.
*
* This function is used by Brick Viewer during flashing. It should not be
* necessary to call it in a normal user program.
*/
int outdoor_weather_set_bootloader_mode(OutdoorWeather *outdoor_weather, uint8_t mode, uint8_t *ret_status);
/**
* \ingroup BrickletOutdoorWeather
*
* Returns the current bootloader mode, see {@link outdoor_weather_set_bootloader_mode}.
*/
int outdoor_weather_get_bootloader_mode(OutdoorWeather *outdoor_weather, uint8_t *ret_mode);
/**
* \ingroup BrickletOutdoorWeather
*
* Sets the firmware pointer for {@link outdoor_weather_write_firmware}. The pointer has
* to be increased by chunks of size 64. The data is written to flash
* every 4 chunks (which equals to one page of size 256).
*
* This function is used by Brick Viewer during flashing. It should not be
* necessary to call it in a normal user program.
*/
int outdoor_weather_set_write_firmware_pointer(OutdoorWeather *outdoor_weather, uint32_t pointer);
/**
* \ingroup BrickletOutdoorWeather
*
* Writes 64 Bytes of firmware at the position as written by
* {@link outdoor_weather_set_write_firmware_pointer} before. The firmware is written
* to flash every 4 chunks.
*
* You can only write firmware in bootloader mode.
*
* This function is used by Brick Viewer during flashing. It should not be
* necessary to call it in a normal user program.
*/
int outdoor_weather_write_firmware(OutdoorWeather *outdoor_weather, uint8_t data[64], uint8_t *ret_status);
/**
* \ingroup BrickletOutdoorWeather
*
* Sets the status LED configuration. By default the LED shows
* communication traffic between Brick and Bricklet, it flickers once
* for every 10 received data packets.
*
* You can also turn the LED permanently on/off or show a heartbeat.
*
* If the Bricklet is in bootloader mode, the LED is will show heartbeat by default.
*/
int outdoor_weather_set_status_led_config(OutdoorWeather *outdoor_weather, uint8_t config);
/**
* \ingroup BrickletOutdoorWeather
*
* Returns the configuration as set by {@link outdoor_weather_set_status_led_config}
*/
int outdoor_weather_get_status_led_config(OutdoorWeather *outdoor_weather, uint8_t *ret_config);
/**
* \ingroup BrickletOutdoorWeather
*
* Returns the temperature as measured inside the microcontroller. The
* value returned is not the ambient temperature!
*
* The temperature is only proportional to the real temperature and it has bad
* accuracy. Practically it is only useful as an indicator for
* temperature changes.
*/
int outdoor_weather_get_chip_temperature(OutdoorWeather *outdoor_weather, int16_t *ret_temperature);
/**
* \ingroup BrickletOutdoorWeather
*
* Calling this function will reset the Bricklet. All configurations
* will be lost.
*
* After a reset you have to create new device objects,
* calling functions on the existing ones will result in
* undefined behavior!
*/
int outdoor_weather_reset(OutdoorWeather *outdoor_weather);
/**
* \ingroup BrickletOutdoorWeather
*
* Writes a new UID into flash. If you want to set a new UID
* you have to decode the Base58 encoded UID string into an
* integer first.
*
* We recommend that you use Brick Viewer to change the UID.
*/
int outdoor_weather_write_uid(OutdoorWeather *outdoor_weather, uint32_t uid);
/**
* \ingroup BrickletOutdoorWeather
*
* Returns the current UID as an integer. Encode as
* Base58 to get the usual string version.
*/
int outdoor_weather_read_uid(OutdoorWeather *outdoor_weather, uint32_t *ret_uid);
/**
* \ingroup BrickletOutdoorWeather
*
* Returns the UID, the UID where the Bricklet is connected to,
* the position, the hardware and firmware version as well as the
* device identifier.
*
* The position can be 'a', 'b', 'c', 'd', 'e', 'f', 'g' or 'h' (Bricklet Port).
* A Bricklet connected to an :ref:`Isolator Bricklet <isolator_bricklet>` is always at
* position 'z'.
*
* The device identifier numbers can be found :ref:`here <device_identifier>`.
* |device_identifier_constant|
*/
int outdoor_weather_get_identity(OutdoorWeather *outdoor_weather, char ret_uid[8], char ret_connected_uid[8], char *ret_position, uint8_t ret_hardware_version[3], uint8_t ret_firmware_version[3], uint16_t *ret_device_identifier);
/**
* \ingroup BrickletOutdoorWeather
*
* Returns the identifiers (number between 0 and 255) of all `stations
* <https://www.tinkerforge.com/en/shop/accessories/sensors/outdoor-weather-station-ws-6147.html>`__
* that have been seen since the startup of the Bricklet.
*
* Each station gives itself a random identifier on first startup.
*
* Since firmware version 2.0.2 a station is removed from the list if no data was received for
* 12 hours.
*/
int outdoor_weather_get_station_identifiers(OutdoorWeather *outdoor_weather, uint8_t *ret_identifiers, uint16_t *ret_identifiers_length);
/**
* \ingroup BrickletOutdoorWeather
*
* Returns the identifiers (number between 0 and 255) of all `sensors
* <https://www.tinkerforge.com/en/shop/accessories/sensors/temperature-humidity-sensor-th-6148.html>`__
* that have been seen since the startup of the Bricklet.
*
* Each sensor gives itself a random identifier on first startup.
*
* Since firmware version 2.0.2 a sensor is removed from the list if no data was received for
* 12 hours.
*/
int outdoor_weather_get_sensor_identifiers(OutdoorWeather *outdoor_weather, uint8_t *ret_identifiers, uint16_t *ret_identifiers_length);
#ifdef __cplusplus
}
#endif
#endif
File diff suppressed because it is too large Load Diff
+716
View File
@@ -0,0 +1,716 @@
/*
* Copyright (C) 2012-2014, 2019-2020 Matthias Bolte <matthias@tinkerforge.com>
* Copyright (C) 2011 Olaf Lüke <olaf@tinkerforge.com>
*
* Redistribution and use in source and binary forms of this file,
* with or without modification, are permitted. See the Creative
* Commons Zero (CC0 1.0) License for more details.
*/
#ifndef IP_CONNECTION_H
#define IP_CONNECTION_H
/**
* \defgroup IPConnection IP Connection
*/
#ifndef __STDC_LIMIT_MACROS
#define __STDC_LIMIT_MACROS
#endif
#include <stdint.h>
#include <string.h>
#include <stdlib.h>
#if (!defined __cplusplus && defined __GNUC__) || (defined _MSC_VER && _MSC_VER >= 1600)
#include <stdbool.h>
#endif
#ifdef _WIN32
#ifndef WIN32_LEAN_AND_MEAN
#define WIN32_LEAN_AND_MEAN
#endif
#include <windows.h>
#else
#include <pthread.h>
#include <semaphore.h>
#endif
#ifdef __cplusplus
extern "C" {
#endif
enum {
E_OK = 0,
E_TIMEOUT = -1,
E_NO_STREAM_SOCKET = -2,
E_HOSTNAME_INVALID = -3,
E_NO_CONNECT = -4,
E_NO_THREAD = -5,
E_NOT_ADDED = -6, // unused since v2.0
E_ALREADY_CONNECTED = -7,
E_NOT_CONNECTED = -8,
E_INVALID_PARAMETER = -9, // error response from device
E_NOT_SUPPORTED = -10, // error response from device
E_UNKNOWN_ERROR_CODE = -11, // error response from device
E_STREAM_OUT_OF_SYNC = -12,
E_INVALID_UID = -13,
E_NON_ASCII_CHAR_IN_SECRET = -14,
E_WRONG_DEVICE_TYPE = -15,
E_DEVICE_REPLACED = -16,
E_WRONG_RESPONSE_LENGTH = -17
};
#ifdef IPCON_EXPOSE_MILLISLEEP
void millisleep(uint32_t msec);
#endif // IPCON_EXPOSE_MILLISLEEP
#ifdef IPCON_EXPOSE_INTERNALS
typedef struct _Socket Socket;
typedef struct {
#ifdef _WIN32
CRITICAL_SECTION handle;
#else
pthread_mutex_t handle;
#endif
} Mutex;
void mutex_create(Mutex *mutex);
void mutex_destroy(Mutex *mutex);
void mutex_lock(Mutex *mutex);
void mutex_unlock(Mutex *mutex);
typedef struct {
#ifdef _WIN32
HANDLE handle;
#else
pthread_cond_t condition;
pthread_mutex_t mutex;
bool flag;
#endif
} Event;
typedef struct {
#ifdef _WIN32
HANDLE handle;
#else
sem_t object;
sem_t *pointer;
#endif
} Semaphore;
typedef void (*ThreadFunction)(void *opaque);
typedef struct {
#ifdef _WIN32
HANDLE handle;
DWORD id;
#else
pthread_t handle;
#endif
ThreadFunction function;
void *opaque;
} Thread;
typedef struct {
Mutex mutex;
int used;
int allocated;
uint32_t *keys;
void **values;
} Table;
typedef struct _QueueItem {
struct _QueueItem *next;
int kind;
void *data;
} QueueItem;
typedef struct {
Mutex mutex;
Semaphore semaphore;
QueueItem *head;
QueueItem *tail;
} Queue;
#if defined _MSC_VER || defined __BORLANDC__
#pragma pack(push)
#pragma pack(1)
#define ATTRIBUTE_PACKED
#elif defined __GNUC__
#ifdef _WIN32
// workaround struct packing bug in GCC 4.7 on Windows
// https://gcc.gnu.org/bugzilla/show_bug.cgi?id=52991
#define ATTRIBUTE_PACKED __attribute__((gcc_struct, packed))
#else
#define ATTRIBUTE_PACKED __attribute__((packed))
#endif
#else
#error unknown compiler, do not know how to enable struct packing
#endif
typedef struct {
uint32_t uid; // always little endian
uint8_t length;
uint8_t function_id;
uint8_t sequence_number_and_options;
uint8_t error_code_and_future_use;
} ATTRIBUTE_PACKED PacketHeader;
typedef struct {
PacketHeader header;
uint8_t payload[64];
uint8_t optional_data[8];
} ATTRIBUTE_PACKED Packet;
#if defined _MSC_VER || defined __BORLANDC__
#pragma pack(pop)
#endif
#undef ATTRIBUTE_PACKED
#endif // IPCON_EXPOSE_INTERNALS
typedef struct _IPConnection IPConnection;
typedef struct _IPConnectionPrivate IPConnectionPrivate;
typedef struct _Device Device;
typedef struct _DevicePrivate DevicePrivate;
#ifdef IPCON_EXPOSE_INTERNALS
typedef struct _CallbackContext CallbackContext;
typedef struct _HighLevelCallback HighLevelCallback;
/**
* \internal
*/
struct _HighLevelCallback {
bool exists;
void *data;
size_t length;
};
#endif
typedef void (*EnumerateCallbackFunction)(const char *uid,
const char *connected_uid,
char position,
uint8_t hardware_version[3],
uint8_t firmware_version[3],
uint16_t device_identifier,
uint8_t enumeration_type,
void *user_data);
typedef void (*ConnectedCallbackFunction)(uint8_t connect_reason,
void *user_data);
typedef void (*DisconnectedCallbackFunction)(uint8_t disconnect_reason,
void *user_data);
#ifdef IPCON_EXPOSE_INTERNALS
typedef void (*CallbackFunction)(void);
typedef void (*CallbackWrapperFunction)(DevicePrivate *device_p, Packet *packet);
#endif
/**
* \internal
*/
struct _Device {
DevicePrivate *p;
};
#ifdef IPCON_EXPOSE_INTERNALS
#define DEVICE_NUM_FUNCTION_IDS 256
typedef enum {
DEVICE_IDENTIFIER_CHECK_PENDING = 0,
DEVICE_IDENTIFIER_CHECK_MATCH = 1,
DEVICE_IDENTIFIER_CHECK_MISMATCH = 2
} DeviceIdentifierCheck;
/**
* \internal
*/
struct _DevicePrivate {
int ref_count;
bool replaced;
uint32_t uid; // always host endian
bool uid_valid;
IPConnectionPrivate *ipcon_p;
uint8_t api_version[3];
uint16_t device_identifier;
Mutex device_identifier_mutex;
DeviceIdentifierCheck device_identifier_check; // protected by device_identifier_mutex
Mutex request_mutex;
uint8_t expected_response_function_id; // protected by request_mutex
uint8_t expected_response_sequence_number; // protected by request_mutex
Mutex response_mutex;
Packet response_packet; // protected by response_mutex
Event response_event;
int response_expected[DEVICE_NUM_FUNCTION_IDS];
Mutex stream_mutex;
CallbackFunction registered_callbacks[DEVICE_NUM_FUNCTION_IDS * 2];
void *registered_callback_user_data[DEVICE_NUM_FUNCTION_IDS * 2];
CallbackWrapperFunction callback_wrappers[DEVICE_NUM_FUNCTION_IDS];
HighLevelCallback high_level_callbacks[DEVICE_NUM_FUNCTION_IDS];
};
/**
* \internal
*/
enum {
DEVICE_RESPONSE_EXPECTED_INVALID_FUNCTION_ID = 0,
DEVICE_RESPONSE_EXPECTED_ALWAYS_TRUE, // getter
DEVICE_RESPONSE_EXPECTED_TRUE, // setter
DEVICE_RESPONSE_EXPECTED_FALSE // setter, default
};
/**
* \internal
*/
void device_create(Device *device, const char *uid,
IPConnectionPrivate *ipcon_p, uint8_t api_version_major,
uint8_t api_version_minor, uint8_t api_version_release,
uint16_t device_identifier);
/**
* \internal
*/
void device_release(DevicePrivate *device_p);
/**
* \internal
*/
int device_get_response_expected(DevicePrivate *device_p, uint8_t function_id,
bool *ret_response_expected);
/**
* \internal
*/
int device_set_response_expected(DevicePrivate *device_p, uint8_t function_id,
bool response_expected);
/**
* \internal
*/
int device_set_response_expected_all(DevicePrivate *device_p, bool response_expected);
/**
* \internal
*/
void device_register_callback(DevicePrivate *device_p, int16_t callback_id,
void (*function)(void), void *user_data);
/**
* \internal
*/
int device_get_api_version(DevicePrivate *device_p, uint8_t ret_api_version[3]);
/**
* \internal
*/
int device_send_request(DevicePrivate *device_p, Packet *request, Packet *response,
int expected_response_length);
/**
* \internal
*/
int device_check_validity(DevicePrivate *device_p);
#endif // IPCON_EXPOSE_INTERNALS
/**
* \ingroup IPConnection
*
* Possible IDs for ipcon_register_callback.
*/
enum {
IPCON_CALLBACK_ENUMERATE = 253,
IPCON_CALLBACK_CONNECTED = 0,
IPCON_CALLBACK_DISCONNECTED = 1
};
/**
* \ingroup IPConnection
*
* Possible values for enumeration_type parameter of EnumerateCallback.
*/
enum {
IPCON_ENUMERATION_TYPE_AVAILABLE = 0,
IPCON_ENUMERATION_TYPE_CONNECTED = 1,
IPCON_ENUMERATION_TYPE_DISCONNECTED = 2
};
/**
* \ingroup IPConnection
*
* Possible values for connect_reason parameter of ConnectedCallback.
*/
enum {
IPCON_CONNECT_REASON_REQUEST = 0,
IPCON_CONNECT_REASON_AUTO_RECONNECT = 1
};
/**
* \ingroup IPConnection
*
* Possible values for disconnect_reason parameter of DisconnectedCallback.
*/
enum {
IPCON_DISCONNECT_REASON_REQUEST = 0,
IPCON_DISCONNECT_REASON_ERROR = 1,
IPCON_DISCONNECT_REASON_SHUTDOWN = 2
};
/**
* \ingroup IPConnection
*
* Possible return values of ipcon_get_connection_state.
*/
enum {
IPCON_CONNECTION_STATE_DISCONNECTED = 0,
IPCON_CONNECTION_STATE_CONNECTED = 1,
IPCON_CONNECTION_STATE_PENDING = 2 // auto-reconnect in progress
};
/**
* \internal
*/
struct _IPConnection {
IPConnectionPrivate *p;
};
#ifdef IPCON_EXPOSE_INTERNALS
#define IPCON_NUM_CALLBACK_IDS 256
#define IPCON_MAX_SECRET_LENGTH 64
/**
* \internal
*/
typedef Device BrickDaemon;
/**
* \internal
*/
struct _IPConnectionPrivate {
#ifdef _WIN32
bool wsa_startup_done; // protected by socket_mutex
#endif
char *host;
uint16_t port;
uint32_t timeout; // in msec
bool auto_reconnect;
bool auto_reconnect_allowed;
bool auto_reconnect_pending;
Mutex sequence_number_mutex;
uint8_t next_sequence_number; // protected by sequence_number_mutex
Mutex authentication_mutex; // protects authentication handshake
uint32_t next_authentication_nonce; // protected by authentication_mutex
Mutex devices_ref_mutex; // protects DevicePrivate.ref_count
Table devices;
CallbackFunction registered_callbacks[IPCON_NUM_CALLBACK_IDS];
void *registered_callback_user_data[IPCON_NUM_CALLBACK_IDS];
Mutex socket_mutex;
Socket *socket; // protected by socket_mutex
uint64_t socket_id; // protected by socket_mutex
bool receive_flag;
Thread receive_thread; // protected by socket_mutex
CallbackContext *callback;
bool disconnect_probe_flag;
Thread disconnect_probe_thread; // protected by socket_mutex
Event disconnect_probe_event;
Semaphore wait;
BrickDaemon brickd;
};
#endif // IPCON_EXPOSE_INTERNALS
/**
* \ingroup IPConnection
*
* Creates an IP Connection object that can be used to enumerate the available
* devices. It is also required for the constructor of Bricks and Bricklets.
*/
void ipcon_create(IPConnection *ipcon);
/**
* \ingroup IPConnection
*
* Destroys the IP Connection object. Calls ipcon_disconnect internally.
* The connection to the Brick Daemon gets closed and the threads of the
* IP Connection are terminated.
*/
void ipcon_destroy(IPConnection *ipcon);
/**
* \ingroup IPConnection
*
* Creates a TCP/IP connection to the given \c host and c\ port. The host and
* port can point to a Brick Daemon or to a WIFI/Ethernet Extension.
*
* Devices can only be controlled when the connection was established
* successfully.
*
* Blocks until the connection is established and returns an error code if
* there is no Brick Daemon or WIFI/Ethernet Extension listening at the given
* host and port.
*/
int ipcon_connect(IPConnection *ipcon, const char *host, uint16_t port);
/**
* \ingroup IPConnection
*
* Disconnects the TCP/IP connection from the Brick Daemon or the WIFI/Ethernet
* Extension.
*/
int ipcon_disconnect(IPConnection *ipcon);
/**
* \ingroup IPConnection
*
* Performs an authentication handshake with the connected Brick Daemon or
* WIFI/Ethernet Extension. If the handshake succeeds the connection switches
* from non-authenticated to authenticated state and communication can
* continue as normal. If the handshake fails then the connection gets closed.
* Authentication can fail if the wrong secret was used or if authentication
* is not enabled at all on the Brick Daemon or the WIFI/Ethernet Extension.
*
* For more information about authentication see
* https://www.tinkerforge.com/en/doc/Tutorials/Tutorial_Authentication/Tutorial.html
*/
int ipcon_authenticate(IPConnection *ipcon, const char secret[64]);
/**
* \ingroup IPConnection
*
* Can return the following states:
*
* - IPCON_CONNECTION_STATE_DISCONNECTED: No connection is established.
* - IPCON_CONNECTION_STATE_CONNECTED: A connection to the Brick Daemon or
* the WIFI/Ethernet Extension is established.
* - IPCON_CONNECTION_STATE_PENDING: IP Connection is currently trying to
* connect.
*/
int ipcon_get_connection_state(IPConnection *ipcon);
/**
* \ingroup IPConnection
*
* Enables or disables auto-reconnect. If auto-reconnect is enabled,
* the IP Connection will try to reconnect to the previously given
* host and port, if the connection is lost.
*
* Default value is *true*.
*/
void ipcon_set_auto_reconnect(IPConnection *ipcon, bool auto_reconnect);
/**
* \ingroup IPConnection
*
* Returns *true* if auto-reconnect is enabled, *false* otherwise.
*/
bool ipcon_get_auto_reconnect(IPConnection *ipcon);
/**
* \ingroup IPConnection
*
* Sets the timeout in milliseconds for getters and for setters for which the
* response expected flag is activated.
*
* Default timeout is 2500.
*/
void ipcon_set_timeout(IPConnection *ipcon, uint32_t timeout);
/**
* \ingroup IPConnection
*
* Returns the timeout as set by ipcon_set_timeout.
*/
uint32_t ipcon_get_timeout(IPConnection *ipcon);
/**
* \ingroup IPConnection
*
* Broadcasts an enumerate request. All devices will respond with an enumerate
* callback.
*/
int ipcon_enumerate(IPConnection *ipcon);
/**
* \ingroup IPConnection
*
* Stops the current thread until ipcon_unwait is called.
*
* This is useful if you rely solely on callbacks for events, if you want
* to wait for a specific callback or if the IP Connection was created in
* a thread.
*
* ipcon_wait and ipcon_unwait act in the same way as "acquire" and "release"
* of a semaphore.
*/
void ipcon_wait(IPConnection *ipcon);
/**
* \ingroup IPConnection
*
* Unwaits the thread previously stopped by ipcon_wait.
*
* ipcon_wait and ipcon_unwait act in the same way as "acquire" and "release"
* of a semaphore.
*/
void ipcon_unwait(IPConnection *ipcon);
/**
* \ingroup IPConnection
*
* Registers the given \c function with the given \c callback_id. The
* \c user_data will be passed as the last parameter to the \c function.
*/
void ipcon_register_callback(IPConnection *ipcon, int16_t callback_id,
void (*function)(void), void *user_data);
#ifdef IPCON_EXPOSE_INTERNALS
/**
* \internal
*/
void ipcon_add_device(IPConnectionPrivate *ipcon_p, DevicePrivate *device_p);
/**
* \internal
*/
int packet_header_create(PacketHeader *header, uint8_t length,
uint8_t function_id, IPConnectionPrivate *ipcon_p,
DevicePrivate *device_p);
/**
* \internal
*/
uint8_t packet_header_get_sequence_number(PacketHeader *header);
/**
* \internal
*/
void packet_header_set_sequence_number(PacketHeader *header, uint8_t sequence_number);
/**
* \internal
*/
uint8_t packet_header_get_response_expected(PacketHeader *header);
/**
* \internal
*/
void packet_header_set_response_expected(PacketHeader *header, bool response_expected);
/**
* \internal
*/
uint8_t packet_header_get_error_code(PacketHeader *header);
/**
* \internal
*/
int16_t leconvert_int16_to(int16_t native);
/**
* \internal
*/
uint16_t leconvert_uint16_to(uint16_t native);
/**
* \internal
*/
int32_t leconvert_int32_to(int32_t native);
/**
* \internal
*/
uint32_t leconvert_uint32_to(uint32_t native);
/**
* \internal
*/
int64_t leconvert_int64_to(int64_t native);
/**
* \internal
*/
uint64_t leconvert_uint64_to(uint64_t native);
/**
* \internal
*/
float leconvert_float_to(float native);
/**
* \internal
*/
int16_t leconvert_int16_from(int16_t little);
/**
* \internal
*/
uint16_t leconvert_uint16_from(uint16_t little);
/**
* \internal
*/
int32_t leconvert_int32_from(int32_t little);
/**
* \internal
*/
uint32_t leconvert_uint32_from(uint32_t little);
/**
* \internal
*/
int64_t leconvert_int64_from(int64_t little);
/**
* \internal
*/
uint64_t leconvert_uint64_from(uint64_t little);
/**
* \internal
*/
float leconvert_float_from(float little);
#endif // IPCON_EXPOSE_INTERNALS
#ifdef __cplusplus
}
#endif
#endif
+39
View File
@@ -0,0 +1,39 @@
QT += core gui
greaterThan(QT_MAJOR_VERSION, 4): QT += widgets
CONFIG += c++11
# You can make your code fail to compile if it uses deprecated APIs.
# In order to do so, uncomment the following line.
#DEFINES += QT_DISABLE_DEPRECATED_BEFORE=0x060000 # disables all the APIs deprecated before Qt 6.0.0
SOURCES += \
cairquality.cpp \
ctinkerforge.cpp \
main.cpp \
cmainwindow.cpp \
tinkerforge/brick_master.c \
tinkerforge/bricklet_air_quality.c \
tinkerforge/bricklet_outdoor_weather.c \
tinkerforge/ip_connection.c
HEADERS += \
cairquality.h \
cmainwindow.h \
ctinkerforge.h \
tinkerforge/brick_master.h \
tinkerforge/bricklet_air_quality.h \
tinkerforge/bricklet_outdoor_weather.h \
tinkerforge/ip_connection.h
FORMS += \
cmainwindow.ui
win32:LIBS += -lws2_32 -ladvapi32
unix:QMAKE_CXXFLAGS += -pthread
# Default rules for deployment.
qnx: target.path = /tmp/$${TARGET}/bin
else: unix:!android: target.path = /opt/$${TARGET}/bin
!isEmpty(target.path): INSTALLS += target