kdriveExpress SDK 22.1.1
kdrive_express_ip_routing.c
//
// Copyright (c) 2002-2022 WEINZIERL ENGINEERING GmbH
// All rights reserved.
//
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
// FITNESS FOR A PARTICULAR PURPOSE, TITLE AND NON-INFRINGEMENT. IN NO EVENT
// SHALL THE COPYRIGHT HOLDERS BE LIABLE FOR ANY DAMAGES OR OTHER LIABILITY,
// WHETHER IN CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
// WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE
//
#include <stdio.h>
#include <stdlib.h>
#include <kdrive_express.h>
/*******************************
** Private Functions
********************************/
static error_t set_license();
/*******************************
** Main
********************************/
int main(int argc, char* argv[])
{
uint16_t address = 0x901;
uint8_t value = 0;
int32_t ap = 0;
/*
Set here if you want use a secure or unsecured port
When use_secure is true then set here also the used backbone key.
*/
bool_t use_secure = 0;
const char backbone_key[] = "00000000000000000000000000000000";
/* Configure the logging level and console logger */
/* Sets the license key */
if (set_license() != KDRIVE_ERROR_NONE)
{
kdrive_logger(KDRIVE_LOGGER_FATAL, "The license key is invalid. Commercial features are disabled");
return -1;
}
/*
We create a Access Port descriptor. This descriptor is then used for
all calls to that specific access port.
*/
/*
We check that we were able to allocate a new descriptor
This should always happen, unless a bad_alloc exception is internally thrown
which means the memory couldn't be allocated.
*/
{
kdrive_logger(KDRIVE_LOGGER_FATAL, "Unable to create access port. This is a terminal failure");
return -1;
}
if (use_secure)
{
{
kdrive_logger(KDRIVE_LOGGER_FATAL, "Unable to set the backbone key");
}
}
// Use default multicast address and network interface
if (kdrive_ap_open_ip_rout(ap, 0, 0, use_secure) == KDRIVE_ERROR_NONE)
{
{
kdrive_logger(KDRIVE_LOGGER_FATAL, "Unable to set the individual address");
}
/*
Connect the Packet Trace logging mechanism
to see the Rx and Tx packets
*/
/* send a 1-Bit boolean GroupValueWrite telegram: on */
value = 1;
kdrive_ap_group_write(ap, address, &value, 1);
/* send a 1-Bit boolean GroupValueWrite telegram: off */
value = 0;
kdrive_ap_group_write(ap, address, &value, 1);
/* close the access port */
}
/* releases the access port */
return 0;
}
/*******************************
** Private Functions
********************************/
/*
Replace the following licence with your license key
*/
error_t set_license()
{
char license[] =
"[Check]\n"
"Key=I1EkM2JvaE1HMEZtIlF5VnJuJn08KHRfV0AwTlEwRyk4NT55JFNvXnU6ZnpzMDI6QV42JWZ4"
"fHNed11aOld9WHpGXSEibnkrSDVsZU9WIkljeSQ3NWY7eT4rdEJ6XjhpNnw+OkNEIydTYWNF"
"RE15JVdQOno3XmtOJjZaRExwLSV8ZXxOYzlJITlhfFFdOHIjUW43SEshfSx8RWgzSipUZU5X"
"ZiJpSnIhRS9pJyQrOis/VVAoSHMkaV5kYGFfaFxhJj5peUtdfVBgMGh7K25bITF7OnhdeTQv"
"NiZlWCt4Nls3S31nLUU2LE1OXmhubGtxY2wqJHMxVDd0Tlg4OGlIUCE=\n"
"\n"
"[Customer]\n"
"City=84508 Burgkirchen / Alz\n"
"Company=WEINZIERL ENGINEERING GmbH\n"
"Country=Germany\n"
"Street=Achatz 3\n"
"\n"
"[LicenseData]\n"
"LicNum=kdrive-2012-05-14\n"
"LicVersion=71949c2a-be30-4fbe-9c96-d0a617ac6ab8\n"
"\n"
"[Limitations]"
"DateLimit=2012-12-31"
"\n"
"[ProgramFeatures]\n"
"kdriveAccess=0\n"
"kdriveServices=0\n";
return kdrive_lic_set_license(license);
}
kdriveExpress_API error_t kdrive_ap_packet_trace_connect(int32_t ap)
Starts the Packet Trace, for a specific access port.
kdriveExpress_API error_t kdrive_ap_group_write(int32_t ap, uint16_t address, const uint8_t *value, uint32_t bits)
Sends a GroupValue_Write Telegram The length is specified in bits to enable values less than one byte...
kdriveExpress_API bool_t kdrive_ap_release(int32_t ap)
Releases the AccessPort interface.
kdriveExpress_API int32_t kdrive_ap_create(void)
Creates an internal AccessPort interface This should be the first function called when working with t...
kdriveExpress_API error_t kdrive_ap_set_ind_addr(int32_t ap, uint16_t address)
Sets the Individual Address of the Local Device (KNX Interface Device)
kdriveExpress_API error_t kdrive_ap_close(int32_t ap)
Closes the access port If the access port is not open nothing happens.
kdriveExpress_API error_t kdrive_ap_set_ip_rout_backbone_key(int32_t ap, const char *key)
Sets the backbone key for the KNXnet/IP routing connection.
kdriveExpress_API error_t kdrive_ap_open_ip_rout(int32_t ap, const char *multicast_address, const char *iface_address, bool_t secured)
Creates an KNXnet/IP Routing access port.
kdriveExpress_API error_t kdrive_lic_set_license(const char *configuration)
Sets the commercial license If you have a commercial SDK you will have received a license key.
kdriveExpress_API void kdrive_logger(uint8_t level, const char *message)
Writes to the kdrive express logger.
kdriveExpress_API void kdrive_logger_console(void)
Sets the logger to write to the console.
kdriveExpress_API void kdrive_logger_set_level(uint8_t level)
Sets the root logger level This is once of:
unsigned short uint16_t
16 bit unsigned char
Definition: kdrive_express_config.h:30
int int32_t
32 bit signed int
Definition: kdrive_express_config.h:34
int32_t error_t
Definition: kdrive_express_config.h:46
int32_t bool_t
Definition: kdrive_express_config.h:57
unsigned char uint8_t
8 bit unsigned char
Definition: kdrive_express_config.h:29
#define KDRIVE_INVALID_DESCRIPTOR
Indicates an invalid descriptor.
Definition: kdrive_express_defs.h:39
#define KDRIVE_ERROR_NONE
No Error, Everything OK.
Definition: kdrive_express_error.h:22
#define KDRIVE_LOGGER_FATAL
A fatal error.
Definition: kdrive_express_logger.h:26
#define KDRIVE_LOGGER_INFORMATION
An informational message, usually denoting the successful completion of an operation.
Definition: kdrive_express_logger.h:31