KNX IoT
KNX IoT Point API stack implementation
oc_core_res.h File Reference

KNX mandatory resources implementation. More...

#include "oc_ri.h"
#include "oc_programming_mode.h"
#include "oc_knx.h"
#include <stdint.h>

Go to the source code of this file.

Data Structures

struct  oc_device_info_t
 device information More...
 
struct  oc_knx_version_info_t
 version information e.g. More...
 
struct  oc_platform_info_t
 platform information More...
 

Macros

#define OC_CORE_CREATE_CONST_RESOURCE_FINAL(resource_name, ...)
 Create const CORE linked to a final, non-const dummy. More...
 
#define OC_CORE_CREATE_CONST_RESOURCE_INTERNAL( resource_name, next_resource, device_index, uri, iface_mask, content_format, properties, get_cb, put_cb, post_cb, delete_cb, dpt, num_resource_types, ...)
 Create const CORE resource Should only be used internally! More...
 
#define OC_CORE_CREATE_CONST_RESOURCE_LINKED(resource_name, next_resource, ...)
 Create const CORE linked to the next one. More...
 
#define OC_CORE_EXTERN_CONST_RESOURCE(resource_name)    extern const oc_resource_t core_resource_##resource_name;
 generate an extern declaration of a core const resource More...
 
#define OC_CORE_RESOURCE_NAME(name)   core_resource_##name
 get the internal name of a core const resource More...
 

Typedefs

typedef void(* oc_core_add_device_cb_t) (void *data)
 callback for adding a device More...
 
typedef void(* oc_core_init_platform_cb_t) (void *data)
 callback for initializing the platform More...
 
typedef struct oc_device_info_t oc_device_info_t
 device information More...
 
typedef struct oc_knx_version_info_t oc_knx_version_info_t
 version information e.g. More...
 
typedef struct oc_platform_info_t oc_platform_info_t
 platform information More...
 

Functions

void oc_check_uri (const char *uri)
 Ensure that the given URI starts with a forward slash. More...
 
oc_device_info_toc_core_add_device (const char *name, const char *version, const char *base, const char *serial_number, oc_core_add_device_cb_t add_device_cb, void *data)
 Add device to the platform. More...
 
void oc_core_bind_dpt_resource (int core_resource, size_t device_index, const char *dpt)
 bind dpt to a core resource More...
 
void oc_core_encode_interfaces_mask (CborEncoder *parent, oc_interface_mask_t iface_mask)
 encode the interfaces with the cbor (payload) encoder More...
 
uint64_t oc_core_get_device_iid (size_t device_index)
 sets the installation identifier (iid) (unsigned int) More...
 
oc_device_info_toc_core_get_device_info (size_t device)
 retrieve the device info from the device index More...
 
size_t oc_core_get_num_devices (void)
 retrieve the amount of devices More...
 
oc_platform_info_toc_core_get_platform_info (void)
 retrieve the platform information More...
 
const oc_resource_toc_core_get_resource_by_index (int type, size_t device)
 retrieve the resource by type (e.g. More...
 
const oc_resource_toc_core_get_resource_by_uri (const char *uri, size_t device)
 retrieve the resource by uri More...
 
void oc_core_init (void)
 initialize the core functionality More...
 
oc_platform_info_toc_core_init_platform (const char *mfg_name, oc_core_init_platform_cb_t init_cb, void *data)
 initialize the platform More...
 
void oc_core_populate_resource (int core_resource, size_t device_index, const char *uri, oc_interface_mask_t iface_mask, oc_content_format_t content_format, int properties, oc_request_callback_t get_cb, oc_request_callback_t put_cb, oc_request_callback_t post_cb, oc_request_callback_t delete_cb, int num_resource_types,...)
 populate core resource mainly used for creation of core resources More...
 
int oc_core_set_and_store_device_ia (size_t device_index, uint32_t ia)
 sets and stores the internal address More...
 
int oc_core_set_and_store_device_iid (size_t device_index, uint64_t iid)
 sets the installation identifier (iid) and store it More...
 
int oc_core_set_device_ap (size_t device_index, int major, int minor, int patch)
 sets the application version number More...
 
int oc_core_set_device_fid (size_t device_index, uint64_t fid)
 sets the fabric identifier (fid) More...
 
int oc_core_set_device_fwv (size_t device_index, int major, int minor, int patch)
 set the firmware version More...
 
int oc_core_set_device_hostname (size_t device_index, const char *host_name)
 sets the host name (string) More...
 
int oc_core_set_device_hwt (size_t device_index, const char *hardware_type)
 sets the hardware type (string) input string should not be larger than 6, note that if the input is larger than 6, it will be truncated to 6 chars More...
 
int oc_core_set_device_hwv (size_t device_index, int major, int minor, int patch)
 sets the hardware version number More...
 
int oc_core_set_device_ia (size_t device_index, uint32_t ia)
 sets the internal address More...
 
int oc_core_set_device_iid (size_t device_index, uint64_t iid)
 sets the installation identifier (iid) (unsigned int) More...
 
int oc_core_set_device_mid (size_t device_index, uint32_t mid)
 sets the manufacturer id More...
 
int oc_core_set_device_model (size_t device_index, const char *model)
 sets the model (string) More...
 
int oc_core_set_device_pm (size_t device_index, bool pm)
 sets the programming mode (boolean) More...
 
int oc_core_set_mid (size_t device_index, int32_t mid)
 sets the manufacturer id More...
 
void oc_core_shutdown (void)
 shutdown the core functionality More...
 
bool oc_filter_resource_by_if (const oc_resource_t *resource, oc_request_t *request)
 filter if the query parameters of the request contains the resource (determined by resource type "if") including wild carts More...
 
bool oc_filter_resource_by_rt (const oc_resource_t *resource, oc_request_t *request)
 filter if the query parameters of the request contains the resource (determined by resource type "rt") including wild carts More...
 
int oc_filter_resource_by_urn (const oc_resource_t *resource, oc_request_t *request)
 remove "urn:knx" from response when already provided in query More...
 
int oc_frame_interfaces_mask_in_response (oc_interface_mask_t iface_mask, int truncated)
 frame the interface mask in the response, as string in the uri example: full tag if= ":if.i" this function frames ":if.i" (truncated) or "urn:knx:if.i" More...
 

Detailed Description

KNX mandatory resources implementation.

Definition in file oc_core_res.h.

Macro Definition Documentation

◆ OC_CORE_CREATE_CONST_RESOURCE_FINAL

#define OC_CORE_CREATE_CONST_RESOURCE_FINAL (   resource_name,
  ... 
)
Value:
oc_resource_dummy_t core_resource_##resource_name##_final = { NULL, -1 }; \
OC_CORE_CREATE_CONST_RESOURCE_INTERNAL(resource_name, resource_name##_final, \
__VA_ARGS__)

Create const CORE linked to a final, non-const dummy.

Parameters
resource_namename of this resource

Definition at line 112 of file oc_core_res.h.

◆ OC_CORE_CREATE_CONST_RESOURCE_INTERNAL

#define OC_CORE_CREATE_CONST_RESOURCE_INTERNAL (   resource_name,
  next_resource,
  device_index,
  uri,
  iface_mask,
  content_format,
  properties,
  get_cb,
  put_cb,
  post_cb,
  delete_cb,
  dpt,
  num_resource_types,
  ... 
)
Value:
_Pragma("GCC diagnostic push"); \
_Pragma("GCC diagnostic ignored \"-Wdiscarded-array-qualifiers\""); \
oc_ri_create_const_resource_internal( \
core_resource_##next_resource, core_resource_##resource_name, \
device_index, NULL, uri, dpt, iface_mask, content_format, properties, \
get_cb, put_cb, post_cb, delete_cb, NULL, 0, 0, num_resource_types, \
__VA_ARGS__); \
_Pragma("GCC diagnostic pop")

Create const CORE resource Should only be used internally!

Definition at line 63 of file oc_core_res.h.

◆ OC_CORE_CREATE_CONST_RESOURCE_LINKED

#define OC_CORE_CREATE_CONST_RESOURCE_LINKED (   resource_name,
  next_resource,
  ... 
)
Value:
extern const oc_resource_t core_resource_##next_resource; \
OC_CORE_CREATE_CONST_RESOURCE_INTERNAL(resource_name, next_resource, \
__VA_ARGS__)
resource structure
Definition: oc_ri.h:482

Create const CORE linked to the next one.

Parameters
resource_namename of this resource
next_resourcename of next resource

Definition at line 91 of file oc_core_res.h.

◆ OC_CORE_EXTERN_CONST_RESOURCE

#define OC_CORE_EXTERN_CONST_RESOURCE (   resource_name)     extern const oc_resource_t core_resource_##resource_name;

generate an extern declaration of a core const resource

Parameters
resource_namename of resource to create decl for

Definition at line 38 of file oc_core_res.h.

◆ OC_CORE_RESOURCE_NAME

#define OC_CORE_RESOURCE_NAME (   name)    core_resource_##name

get the internal name of a core const resource

Parameters
namename of resource

Definition at line 45 of file oc_core_res.h.

Typedef Documentation

◆ oc_core_add_device_cb_t

typedef void(* oc_core_add_device_cb_t) (void *data)

callback for adding a device

Definition at line 128 of file oc_core_res.h.

◆ oc_core_init_platform_cb_t

typedef void(* oc_core_init_platform_cb_t) (void *data)

callback for initializing the platform

Definition at line 122 of file oc_core_res.h.

◆ oc_device_info_t

device information

This structure contains

◆ oc_knx_version_info_t

version information e.g.

[major, minor, patch]

◆ oc_platform_info_t

platform information

Function Documentation

◆ oc_check_uri()

void oc_check_uri ( const char *  uri)

Ensure that the given URI starts with a forward slash.

Parameters
urithe URI to check

◆ oc_core_add_device()

oc_device_info_t* oc_core_add_device ( const char *  name,
const char *  version,
const char *  base,
const char *  serial_number,
oc_core_add_device_cb_t  add_device_cb,
void *  data 
)

Add device to the platform.

Parameters
namethe name of the device
versionthe version of the KNX spec
basethe base url
serial_numberthe serial number of the device
add_device_cbdevice callback
datathe supplied user data
Returns
oc_device_info_t* the device structure

◆ oc_core_bind_dpt_resource()

void oc_core_bind_dpt_resource ( int  core_resource,
size_t  device_index,
const char *  dpt 
)

bind dpt to a core resource

Parameters
core_resourcethe resource index
device_indexthe device index
dptthe DPT value of the resource

◆ oc_core_encode_interfaces_mask()

void oc_core_encode_interfaces_mask ( CborEncoder *  parent,
oc_interface_mask_t  iface_mask 
)

encode the interfaces with the cbor (payload) encoder

Parameters
parentthe cbor encoder
iface_maskthe interfaces (as bit mask)

◆ oc_core_get_device_iid()

uint64_t oc_core_get_device_iid ( size_t  device_index)

sets the installation identifier (iid) (unsigned int)

Parameters
device_indexthe device index
Returns
The KNX installation id

◆ oc_core_get_device_info()

oc_device_info_t* oc_core_get_device_info ( size_t  device)

retrieve the device info from the device index

Parameters
devicethe device index
Returns
oc_device_info_t* the device info

Referenced by app_init().

◆ oc_core_get_num_devices()

size_t oc_core_get_num_devices ( void  )

retrieve the amount of devices

Returns
size_t the amount of devices

◆ oc_core_get_platform_info()

oc_platform_info_t* oc_core_get_platform_info ( void  )

retrieve the platform information

Returns
oc_platform_info_t* the platform information

◆ oc_core_get_resource_by_index()

const oc_resource_t* oc_core_get_resource_by_index ( int  type,
size_t  device 
)

retrieve the resource by type (e.g.

index) on a specific device

Parameters
typethe index of the resource
devicethe device index
Returns
oc_resource_t* the resource handle

◆ oc_core_get_resource_by_uri()

const oc_resource_t* oc_core_get_resource_by_uri ( const char *  uri,
size_t  device 
)

retrieve the resource by uri

Parameters
urithe URI
devicethe device index
Returns
oc_resource_t* the resource handle

◆ oc_core_init()

void oc_core_init ( void  )

initialize the core functionality

◆ oc_core_init_platform()

oc_platform_info_t* oc_core_init_platform ( const char *  mfg_name,
oc_core_init_platform_cb_t  init_cb,
void *  data 
)

initialize the platform

Parameters
mfg_namethe manufacturer name
init_cbthe callback
datathe user data
Returns
oc_platform_info_t* the platform information

◆ oc_core_populate_resource()

void oc_core_populate_resource ( int  core_resource,
size_t  device_index,
const char *  uri,
oc_interface_mask_t  iface_mask,
oc_content_format_t  content_format,
int  properties,
oc_request_callback_t  get_cb,
oc_request_callback_t  put_cb,
oc_request_callback_t  post_cb,
oc_request_callback_t  delete_cb,
int  num_resource_types,
  ... 
)

populate core resource mainly used for creation of core resources

Parameters
core_resourcethe resource index
device_indexthe device index
urithe URI for the resource
iface_maskinterfaces (as mask) to be implemented on the resource
content_formatthe content type that should be listed as ct in link-format responses
propertiesthe properties (as mask)
get_cbget callback function
put_cbput callback function
post_cbpost callback function
delete_cbdelete callback function
num_resource_typesamount of resource types, listed as variable arguments after this argument
...Resource types, passed as zero-terminated strings. In order to save memory, the maximum length of each resource type is 32 bytes.

◆ oc_core_set_and_store_device_ia()

int oc_core_set_and_store_device_ia ( size_t  device_index,
uint32_t  ia 
)

sets and stores the internal address

Parameters
device_indexthe device index
iathe internal address
Returns
int error status, 0 = OK

◆ oc_core_set_and_store_device_iid()

int oc_core_set_and_store_device_iid ( size_t  device_index,
uint64_t  iid 
)

sets the installation identifier (iid) and store it

Parameters
device_indexthe device index
iidthe KNX installation id
Returns
int error status, 0 = OK

◆ oc_core_set_device_ap()

int oc_core_set_device_ap ( size_t  device_index,
int  major,
int  minor,
int  patch 
)

sets the application version number

Parameters
device_indexthe device index
majorthe xxx number of xxx.yyy.zzz
minorthe yyy number of xxx.yyy.zz
patchthe zzz number of xxx.yyy.zzz
Returns
int error status, 0 = OK

◆ oc_core_set_device_fid()

int oc_core_set_device_fid ( size_t  device_index,
uint64_t  fid 
)

sets the fabric identifier (fid)

Parameters
device_indexthe device index
fidthe fabric id
Returns
int error status, 0 = OK

◆ oc_core_set_device_fwv()

int oc_core_set_device_fwv ( size_t  device_index,
int  major,
int  minor,
int  patch 
)

set the firmware version

Parameters
device_indexthe device index
majorthe xxx number of xxx.yyy.zzz
minorthe yyy number of xxx.yyy.zz
patchthe zzz number of xxx.yyy.zzz
Returns
int error status, 0 = OK

◆ oc_core_set_device_hostname()

int oc_core_set_device_hostname ( size_t  device_index,
const char *  host_name 
)

sets the host name (string)

Parameters
device_indexthe device index
host_namethe host name
Returns
int error status, 0 = OK

◆ oc_core_set_device_hwt()

int oc_core_set_device_hwt ( size_t  device_index,
const char *  hardware_type 
)

sets the hardware type (string) input string should not be larger than 6, note that if the input is larger than 6, it will be truncated to 6 chars

Parameters
device_indexthe device index
hardware_typethe hardware type
Returns
int error status, 0 = OK

◆ oc_core_set_device_hwv()

int oc_core_set_device_hwv ( size_t  device_index,
int  major,
int  minor,
int  patch 
)

sets the hardware version number

Parameters
device_indexthe device index
majorthe xxx number of xxx.yyy.zzz
minorthe yyy number of xxx.yyy.zz
patchthe zzz number of xxx.yyy.zzz
Returns
int error status, 0 = OK

◆ oc_core_set_device_ia()

int oc_core_set_device_ia ( size_t  device_index,
uint32_t  ia 
)

sets the internal address

Parameters
device_indexthe device index
iathe internal address
Returns
int error status, 0 = OK

◆ oc_core_set_device_iid()

int oc_core_set_device_iid ( size_t  device_index,
uint64_t  iid 
)

sets the installation identifier (iid) (unsigned int)

Parameters
device_indexthe device index
iidthe KNX installation id
Returns
int error status, 0 = OK

◆ oc_core_set_device_mid()

int oc_core_set_device_mid ( size_t  device_index,
uint32_t  mid 
)

sets the manufacturer id

Parameters
device_indexthe device index
midthe manufacturer id
Returns
int error status, 0 = OK

◆ oc_core_set_device_model()

int oc_core_set_device_model ( size_t  device_index,
const char *  model 
)

sets the model (string)

Parameters
device_indexthe device index
modelthe device model
Returns
int error status, 0 = OK

◆ oc_core_set_device_pm()

int oc_core_set_device_pm ( size_t  device_index,
bool  pm 
)

sets the programming mode (boolean)

Parameters
device_indexthe device index
pmthe programming mode
Returns
int error status, 0 = OK

◆ oc_core_set_mid()

int oc_core_set_mid ( size_t  device_index,
int32_t  mid 
)

sets the manufacturer id

Parameters
device_indexthe device index
midthe manufacturer id
Returns
int error status, 0 = OK

◆ oc_core_shutdown()

void oc_core_shutdown ( void  )

shutdown the core functionality

◆ oc_filter_resource_by_if()

bool oc_filter_resource_by_if ( const oc_resource_t resource,
oc_request_t request 
)

filter if the query parameters of the request contains the resource (determined by resource type "if") including wild carts

Parameters
resourcethe resource to look for
requestthe request to scan
Returns
true interface type of the resource is in the request
false interface type of the resource is not in the request

◆ oc_filter_resource_by_rt()

bool oc_filter_resource_by_rt ( const oc_resource_t resource,
oc_request_t request 
)

filter if the query parameters of the request contains the resource (determined by resource type "rt") including wild carts

Parameters
resourcethe resource to look for
requestthe request to scan
Returns
true resource type (or wild card) is in the request
false resource type is not in the request

◆ oc_filter_resource_by_urn()

int oc_filter_resource_by_urn ( const oc_resource_t resource,
oc_request_t request 
)

remove "urn:knx" from response when already provided in query

Parameters
resourcethe resource to look for
requestthe request to scan
Returns
1 if truncated, 0 otherwise

◆ oc_frame_interfaces_mask_in_response()

int oc_frame_interfaces_mask_in_response ( oc_interface_mask_t  iface_mask,
int  truncated 
)

frame the interface mask in the response, as string in the uri example: full tag if= ":if.i" this function frames ":if.i" (truncated) or "urn:knx:if.i"

Parameters
iface_maskThe interface masks to frame
truncated1 = do not frame "urn:knx"
Returns
int 0 = success