kdriveExpress SDK 22.1.1
kdrive_express_ip_routing_enumerate.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>
#define ERROR_MESSAGE_LEN (128)
#define MAX_ITEMS (50)
/*******************************
** Private Functions
********************************/
static error_t set_license();
static void enumerate_routing_devices(int32_t ap);
static void error_callback(error_t e, void* user_data);
/*******************************
** Main
********************************/
int main(int argc, char* argv[])
{
int32_t ap = 0;
/*
Configure the logging level and console logger
*/
/*
We register an error callback as a convenience logger function to
print out the error message when an error occurs.
*/
kdrive_register_error_callback(&error_callback, NULL);
/*
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.
*/
{
printf("Unable to create access port. This is a terminal failure\n");
return -1;
}
/* enumerate the KNXnet/IP routing devices */
enumerate_routing_devices(ap);
/* 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);
}
void enumerate_routing_devices(int32_t ap)
{
ip_rout_info_t items[MAX_ITEMS];
uint32_t items_length = MAX_ITEMS;
uint32_t index = 0;
kdrive_logger(KDRIVE_LOGGER_INFORMATION, "Enumerating KNXnet/IP Routing devices");
kdrive_logger(KDRIVE_LOGGER_INFORMATION, "=====================================");
if (kdrive_ap_enum_ip_rout(ap, items, &items_length) == KDRIVE_ERROR_NONE)
{
kdrive_logger_ex(KDRIVE_LOGGER_INFORMATION, "Found %d used multicast addresse(s)", items_length);
for (index = 0; index < items_length; ++index)
{
kdrive_logger_ex(KDRIVE_LOGGER_INFORMATION, "%s on %s", items[index].multicast_address, items[index].iface_address);
kdrive_logger_ex(KDRIVE_LOGGER_INFORMATION, "Found %u devices", items[index].number_of_devices);
}
}
}
void error_callback(error_t e, void* user_data)
{
{
static char error_message[ERROR_MESSAGE_LEN];
kdrive_get_error_message(e, error_message, ERROR_MESSAGE_LEN);
kdrive_logger_ex(KDRIVE_LOGGER_ERROR, "kdrive error: %s", error_message);
}
}
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_enum_ip_rout(int32_t ap, ip_rout_info_t items[], uint32_t *items_length)
Scans for all KNX IP Routing devices The items array must exist (should be pre-allocated by the user)...
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_ex(uint8_t level, const char *fmt,...)
Writes to the kdrive express logger.
kdriveExpress_API void kdrive_logger_set_level(uint8_t level)
Sets the root logger level This is once of:
int int32_t
32 bit signed int
Definition: kdrive_express_config.h:34
unsigned int uint32_t
32 bit unsigned char
Definition: kdrive_express_config.h:31
int32_t error_t
Definition: kdrive_express_config.h:46
#define KDRIVE_INVALID_DESCRIPTOR
Indicates an invalid descriptor.
Definition: kdrive_express_defs.h:39
kdriveExpress_API void kdrive_register_error_callback(kdrive_error_callback c, void *user_data)
Registers the error callback function.
#define KDRIVE_TIMEOUT_ERROR
Timeout.
Definition: kdrive_express_error.h:26
#define KDRIVE_ERROR_NONE
No Error, Everything OK.
Definition: kdrive_express_error.h:22
kdriveExpress_API void kdrive_get_error_message(error_t e, char *str, uint32_t str_len)
Gets the error message.
#define KDRIVE_LOGGER_FATAL
A fatal error.
Definition: kdrive_express_logger.h:26
#define KDRIVE_LOGGER_ERROR
An error.
Definition: kdrive_express_logger.h:28
#define KDRIVE_LOGGER_INFORMATION
An informational message, usually denoting the successful completion of an operation.
Definition: kdrive_express_logger.h:31
Structure holding ip routing information.
Definition: kdrive_express_access.h:407