kdriveExpress SDK 23.2.0
kdrive_express_ip_tunneling_keyring.c
//
// Copyright (c) 2002-2023 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>
/*******************************
** Main
********************************/
int main(int argc, char* argv[])
{
uint16_t address = 0x901;
uint8_t value = 0;
int32_t ap = 0;
int32_t keyring = 0;
const char* keyring_file = "data/keyring.knxkeys";
const char* keyring_password = "123456";
uint32_t project_name_length = 128;
char project_name[128];
uint32_t project_creator_length = 32;
char project_creator[32];
/* Configure the logging level and console logger */
/*
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;
}
/*
Import the ETS keyring project
*/
if (kdrive_keyring_import_knxkeys(keyring_file, keyring_password, &keyring) != KDRIVE_ERROR_NONE)
{
kdrive_logger(KDRIVE_LOGGER_FATAL, "Unable to import the keyring file");
return -1;
}
/*
Trace some keyring project info
*/
kdrive_keyring_get_proj_name(keyring, project_name, &project_name_length);
kdrive_logger_ex(KDRIVE_LOGGER_INFORMATION, "Project name %s", project_name);
kdrive_keyring_get_proj_creator(keyring, project_creator, &project_creator_length);
kdrive_logger_ex(KDRIVE_LOGGER_INFORMATION, "Created by: %s", project_creator);
/*
Use the keyring project for the tunneling port
(The password, etc will set automatic from the keyring project)
*/
{
kdrive_logger(KDRIVE_LOGGER_FATAL, "Unable to use the keyring project");
return -1;
}
/* sets security user id (optional; default is 1)*/
{
kdrive_logger(KDRIVE_LOGGER_FATAL, "Unable to set the user id");
}
/*
Open a Tunneling connection with a specific IP Interface,
you will probably have to change the IP address
*/
if (kdrive_ap_open_ip_tunn(ap, "192.168.1.6", 0, 0) == KDRIVE_ERROR_NONE)
{
/*
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_ip_tunn_user_id(int32_t ap, uint8_t user_id)
Sets the security user id for the KNXnet/IP tunneling connection.
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_keyring(int32_t ap, int32_t keyring)
Sets the used knx keyring project.
kdriveExpress_API error_t kdrive_ap_open_ip_tunn(int32_t ap, const char *ip_address, uint16_t port, const char *iface_address)
Opens a connection to a KNX IP Tunneling Interface device on a specific network interface or default ...
kdriveExpress_API error_t kdrive_keyring_get_proj_creator(int32_t keyring, char creator[], uint32_t *creator_length)
Gets keyring project creator (e.g.
kdriveExpress_API error_t kdrive_keyring_import_knxkeys(const char *filename, const char *password, int32_t *keyring)
Imports an ETS keyring project file (*.knxkeys)
kdriveExpress_API error_t kdrive_keyring_get_proj_name(int32_t keyring, char name[], uint32_t *name_length)
Gets keyring project name Null-terminated string in utf8 encoding.
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:
unsigned short uint16_t
16 bit unsigned char
Definition: kdrive_express_config.h:31
int int32_t
32 bit signed int
Definition: kdrive_express_config.h:35
unsigned int uint32_t
32 bit unsigned char
Definition: kdrive_express_config.h:32
int32_t error_t
Definition: kdrive_express_config.h:47
unsigned char uint8_t
8 bit unsigned char
Definition: kdrive_express_config.h:30
#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