KNX IoT
KNX IoT Point API stack implementation
lssb_minimal_all.c File Reference

Example device implementing Function Block LSSBExample code for Function Block LSSB Implements only data point 61: switch on/off This implementation is a sensor, e.g. More...

#include "oc_api.h"
#include "oc_core_res.h"
#include "api/oc_knx_fp.h"
#include "port/oc_clock.h"
#include <signal.h>
#include "api/oc_knx_dev.h"
#include <stdio.h>
#include <unistd.h>

Go to the source code of this file.

Macros

#define _WIN32_WINNT   0x8000
 
#define btoa(x)   ((x) ? "true" : "false")
 
#define GetCurrentDir   getcwd
 
#define MY_NAME   "Sensor (LSSB) 421.61"
 The name of the application. More...
 
#define STATIC   static
 

Functions

int app_init (void)
 function to set up the device. More...
 
void factory_presets_cb (size_t device_index, void *data)
 initiate preset for device current implementation: device reset as command line argument More...
 
STATIC void get_o_1_1 (oc_request_t *request, oc_interface_mask_t interfaces, void *user_data)
 GET method for "p/o_1_1" resource. More...
 
void handle_signal (int signal)
 handle Ctrl-C More...
 
void hostname_cb (size_t device_index, oc_string_t host_name, void *data)
 set the host name on the device (application depended) More...
 
void initialize_variables (void)
 initializes the global variables registers and starts the handler More...
 
int main (int argc, char *argv[])
 main application. More...
 
void oc_add_s_mode_response_cb (char *url, oc_rep_t *rep, oc_rep_t *rep_value)
 s-mode response callback will be called when a response is received on an s-mode read request More...
 
void print_usage ()
 print usage and quits More...
 
void register_resources (void)
 register all the resources to the stack this function registers all application level resources: More...
 
void reset_cb (size_t device_index, int reset_value, void *data)
 application reset More...
 
void restart_cb (size_t device_index, void *data)
 restart the device (application depended) More...
 
void swu_cb (size_t device, oc_separate_response_t *response, size_t binary_size, size_t offset, uint8_t *payload, size_t len, void *data)
 software update callback More...
 

Variables

bool g_mystate = false
 the state of the dpa 421.61 More...
 
bool g_reset = false
 reset the device (from startup) More...
 
volatile int quit = 0
 stop variable, used by handle_signal More...
 

Detailed Description

Example device implementing Function Block LSSB

Example code for Function Block LSSB Implements only data point 61: switch on/off This implementation is a sensor, e.g.

transmits data

Application Design

support functions:

  • app_init:
    • initializes the stack values.
  • register_resources:
    • function that registers all endpoints,
    • sets the GET/PUT/POST/DELETE handlers for each end point
  • main starts the stack, with the registered resources. can be compiled out with NO_MAIN

    handlers for the implemented methods (get/post):

    • get_[path]:
      • function that is being called when a GET is called on [path]
      • set the global variables in the output
    • post_[path]
      • function that is being called when a POST is called on [path]
      • checks the input data
      • if input data is correct
        • updates the global variables

Defines

stack specific defines:

  • linux build for linux
  • WIN32 build for windows
  • OC_OSCORE oscore is enabled as compile flag

File specific defines:

  • NO_MAIN compile out the function main()
  • INCLUDE_EXTERNAL includes header file "external_header.h", so that other tools/dependencies can be included without changing this code

Definition in file lssb_minimal_all.c.

Macro Definition Documentation

◆ MY_NAME

#define MY_NAME   "Sensor (LSSB) 421.61"

The name of the application.

Definition at line 100 of file lssb_minimal_all.c.

Function Documentation

◆ app_init()

int app_init ( void  )

function to set up the device.

sets the:

  • serial number
  • base path
  • knx spec version
  • hardware version
  • firmware version
  • hardware type
  • device model

Definition at line 151 of file lssb_minimal_all.c.

152 {
153  int ret = oc_init_platform("Cascoda", NULL, NULL);
154 
155  /* set the application name, version, base url, device serial number */
156  ret |= oc_add_device(MY_NAME, "1.0.0", "//", "00FA10010401", NULL, NULL);
157 
159  PRINT("Serial Number: %s\n", oc_string_checked(device->serialnumber));
160 
161  /* set the hardware version 1.0.0 */
162  oc_core_set_device_hwv(0, 1, 0, 0);
163 
164  /* set the firmware version 1.0.0 */
165  oc_core_set_device_fwv(0, 1, 0, 0);
166 
167  /* set the hardware type*/
168  oc_core_set_device_hwt(0, "Pi");
169 
170  /* set the model */
171  oc_core_set_device_model(0, "my model");
172 
173  /* set the application info*/
174  oc_core_set_device_ap(0, 1, 0, 0);
175 
176  /* set the manufacturer info*/
177  oc_core_set_device_mid(0, 12);
178 
180 
181 #ifdef OC_SPAKE
182 #define PASSWORD "LETTUCE"
183  oc_spake_set_password(PASSWORD);
184  PRINT(" SPAKE password %s\n", PASSWORD);
185 #endif
186  return ret;
187 }
bool oc_set_s_mode_response_cb(oc_s_mode_response_cb_t my_func)
set the s-mode response callback e.g.
#define MY_NAME
The name of the application.
void oc_add_s_mode_response_cb(char *url, oc_rep_t *rep, oc_rep_t *rep_value)
s-mode response callback will be called when a response is received on an s-mode read request
int oc_add_device(const char *name, const char *version, const char *base, const char *serial_number, oc_add_device_cb_t add_device_cb, void *data)
Add an a device to the stack.
int oc_init_platform(const char *mfg_name, oc_init_platform_cb_t init_platform_cb, void *data)
Initialize the platform.
int oc_core_set_device_fwv(size_t device_index, int major, int minor, int patch)
set the firmware version
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 l...
int oc_core_set_device_model(size_t device_index, const char *model)
sets the model (string)
int oc_core_set_device_mid(size_t device_index, uint32_t mid)
sets the manufacturer id
int oc_core_set_device_hwv(size_t device_index, int major, int minor, int patch)
sets the hardware version number
int oc_core_set_device_ap(size_t device_index, int major, int minor, int patch)
sets the application version number
oc_device_info_t * oc_core_get_device_info(size_t device)
retrieve the device info from the device index
#define oc_string_checked(ocstring)
cast oc_string to string, replace null pointer results with a pointer to "NULL"
Definition: oc_helpers.h:56
device information
Definition: oc_core_res.h:158
oc_string_t serialnumber
knx serial number
Definition: oc_core_res.h:159

References MY_NAME, oc_add_device(), oc_core_get_device_info(), and oc_init_platform().

◆ factory_presets_cb()

void factory_presets_cb ( size_t  device_index,
void *  data 
)

initiate preset for device current implementation: device reset as command line argument

Parameters
device_indexthe device identifier of the list of devices
datathe supplied data.

Definition at line 347 of file lssb_minimal_all.c.

348 {
349  (void)device_index;
350  (void)data;
351 
352  if (g_reset) {
353  PRINT("factory_presets_cb: resetting device\n");
355  }
356 }
bool g_reset
reset the device (from startup)
void oc_knx_device_storage_reset(size_t device_index, int reset_mode)
clear the persistent storage reset behavior according to the supplied erase code

References g_reset.

◆ get_o_1_1()

STATIC void get_o_1_1 ( oc_request_t request,
oc_interface_mask_t  interfaces,
void *  user_data 
)

GET method for "p/o_1_1" resource.

function is called to initialize the return values of the GET method. initialization of the returned values are done from the global property values. Resource Description: This Resource describes a binary switch (on/off). The Property "value" is a boolean. A value of 'true' means that the switch is on. A value of 'false' means that the switch is off.

Parameters
requestthe request representation.
interfacesthe interface used for this call
user_datathe user data.

Definition at line 202 of file lssb_minimal_all.c.

204 {
205  (void)user_data; /* variable not used */
206 
207  /* TODO: SENSOR add here the code to talk to the HW if one implements a
208  sensor. the call to the HW needs to fill in the global variable before it
209  returns to this function here. alternative is to have a callback from the
210  hardware that sets the global variables.
211  */
212  bool error_state = false; /* the error state, the generated code */
214 
215  PRINT("-- Begin get_dpa_421_61: interface %d\n", interfaces);
216  /* check if the accept header is CBOR */
217  if (oc_check_accept_header(request, APPLICATION_CBOR) == false) {
219  return;
220  }
221 
222  // check the query parameter m with the various values
223  char *m;
224  char *m_key;
225  size_t m_key_len;
226  size_t m_len = (int)oc_get_query_value(request, "m", &m);
227  if (m_len != -1) {
228  PRINT(" Query param: %.*s", (int)m_len, m);
230  size_t device_index = request->resource->device;
231  oc_device_info_t *device = oc_core_get_device_info(device_index);
232  if (device != NULL) {
234  while (oc_iterate_query(request, &m_key, &m_key_len, &m, &m_len) != -1) {
235  // unique identifier
236  if ((strncmp(m, "id", m_len) == 0) | (strncmp(m, "*", m_len) == 0)) {
237  char mystring[100];
238  snprintf(mystring, 99, "urn:knx:sn:%s%s",
239  oc_string(device->serialnumber),
240  oc_string(request->resource->uri));
241  oc_rep_i_set_text_string(root, 0, mystring);
242  }
243  // resource types
244  if ((strncmp(m, "rt", m_len) == 0) | (strncmp(m, "*", m_len) == 0)) {
245  oc_rep_set_text_string(root, rt, "urn:knx:dpa.421.6");
246  }
247  // interfaces
248  if ((strncmp(m, "if", m_len) == 0) | (strncmp(m, "*", m_len) == 0)) {
249  oc_rep_set_text_string(root, if, "if.s");
250  }
251  if ((strncmp(m, "dpt", m_len) == 0) | (strncmp(m, "*", m_len) == 0)) {
252  oc_rep_set_text_string(root, dpt, oc_string(request->resource->dpt));
253  }
254  // ga
255  if ((strncmp(m, "ga", m_len) == 0) | (strncmp(m, "*", m_len) == 0)) {
257  oc_string(request->resource->uri));
258  if (index > -1) {
259  oc_group_object_table_t *got_table_entry =
261  if (got_table_entry) {
262  oc_rep_set_int_array(root, ga, got_table_entry->ga,
263  got_table_entry->ga_len);
264  }
265  }
266  }
267  } /* query iterator */
269  } else {
270  /* device is NULL */
272  }
274  return;
275  }
276 
277  CborError error;
281  error = g_err;
282 
283  if (error) {
284  oc_status_code = true;
285  }
286  PRINT("CBOR encoder size %d\n", oc_rep_get_encoded_payload_size());
287 
288  if (error_state == false) {
290  } else {
292  }
293  PRINT("-- End get_dpa_421_61\n");
294 }
void oc_init_query_iterator(void)
This resets the query iterator to the start of the URI query parameter.
void oc_send_response_no_format(oc_request_t *request, oc_status_t response_code)
Called after the response to a GET, PUT, POST or DELETE call has been prepared completed.
int oc_iterate_query(oc_request_t *request, char **key, size_t *key_len, char **value, size_t *value_len)
Iterate through the URI query parameters and get each key=value pair.
void oc_send_cbor_response(oc_request_t *request, oc_status_t response_code)
Called after the response to a GET, PUT, POST or DELETE call has been prepared completed.
int oc_get_query_value(oc_request_t *request, const char *key, char **value)
Get a pointer to the start of the value in a URL query parameter key=value pair.
bool g_mystate
the state of the dpa 421.61
#define oc_string(ocstring)
cast oc_string to string
Definition: oc_helpers.h:49
int oc_core_find_group_object_table_url(const char *url)
find (first) index in the group address table via url
oc_group_object_table_t * oc_core_get_group_object_table_entry(int index)
retrieve the group object table entry
#define oc_rep_set_text_string(object, key, value)
Add an string value to the cbor object under the key name Example:
Definition: oc_rep.h:401
#define oc_rep_i_set_boolean(object, key, value)
Add an boolean value to the cbor object under the integer key name Example:
Definition: oc_rep.h:378
#define oc_rep_end_root_object()
End the root object.
Definition: oc_rep.h:624
#define oc_rep_begin_root_object()
Begin the root object.
Definition: oc_rep.h:607
#define oc_rep_i_set_text_string(object, key, value)
Add an string value to the cbor object under the integer key name Example:
Definition: oc_rep.h:428
int oc_rep_get_encoded_payload_size(void)
Get the size of the cbor encoded data.
#define oc_rep_set_int_array(object, key, values, length)
Add an integer array with values of length to the cbor object under the key name.
Definition: oc_rep.h:1103
@ OC_STATUS_OK
OK 2.00.
Definition: oc_ri.h:153
@ OC_STATUS_BAD_OPTION
Bad Option 4.02.
Definition: oc_ri.h:160
bool oc_check_accept_header(oc_request_t *request, oc_content_format_t accept)
checks if the accept header is correct note that if the accept header is not there,...
@ APPLICATION_CBOR
application/cbor
Definition: oc_ri.h:207
int oc_status_code(oc_status_t key)
convert the (internal) status code to coap status as integer
Group Object Table Resource (/fp/g) The payload is an array of objects.
Definition: oc_knx_fp.h:119
int ga_len
length of the array of ga identifiers
Definition: oc_knx_fp.h:123
uint32_t * ga
array of group addresses (unsigned integers)
Definition: oc_knx_fp.h:124
const oc_resource_t * resource
resource structure
Definition: oc_ri.h:414
size_t device
device index
Definition: oc_ri.h:484
oc_string_t dpt
dpt of the resource
Definition: oc_ri.h:488
oc_string_t uri
uri of the resource
Definition: oc_ri.h:486

References oc_status_code(), and OC_STATUS_OK.

◆ handle_signal()

void handle_signal ( int  signal)

handle Ctrl-C

Parameters
signalthe captured signal

Definition at line 504 of file lssb_minimal_all.c.

505 {
506  (void)signal;
507  signal_event_loop();
508  quit = 1;
509 }
volatile int quit
stop variable, used by handle_signal

References quit.

Referenced by main().

◆ hostname_cb()

void hostname_cb ( size_t  device_index,
oc_string_t  host_name,
void *  data 
)

set the host name on the device (application depended)

Parameters
device_indexthe device identifier of the list of devices
host_namethe host name to be set on the device
datathe supplied data.

Definition at line 397 of file lssb_minimal_all.c.

398 {
399  (void)device_index;
400  (void)data;
401 
402  PRINT("-----host name ------- %s\n", oc_string_checked(host_name));
403 }

◆ initialize_variables()

void initialize_variables ( void  )

initializes the global variables registers and starts the handler

Definition at line 454 of file lssb_minimal_all.c.

455 {
456  /* initialize global variables for resources */
457  /* if wanted read them from persistent storage */
458 }

◆ main()

int main ( int  argc,
char *  argv[] 
)

main application.

initializes the global variables registers and starts the handler handles (in a loop) the next event. shuts down the stack

Definition at line 535 of file lssb_minimal_all.c.

536 {
537  int init;
538  oc_clock_time_t next_event;
539  bool do_send_s_mode = false;
540  char *fname = "my_software_image";
541 
542 #ifdef WIN32
543  /* windows specific */
544  InitializeCriticalSection(&cs);
545  InitializeConditionVariable(&cv);
546  /* install Ctrl-C */
547  signal(SIGINT, handle_signal);
548 #endif
549 #ifdef __linux__
550  /* Linux specific */
551  struct sigaction sa;
552  sigfillset(&sa.sa_mask);
553  sa.sa_flags = 0;
554  sa.sa_handler = handle_signal;
555  /* install Ctrl-C */
556  sigaction(SIGINT, &sa, NULL);
557 #endif
558 
559  for (int i = 0; i < argc; i++) {
560  PRINT("argv[%d] = %s\n", i, argv[i]);
561  }
562  if (argc > 1) {
563  PRINT("s-mode: %s\n", argv[1]);
564  if (strcmp(argv[1], "s-mode") == 0) {
565  do_send_s_mode = true;
566  }
567  if (strcmp(argv[1], "reset") == 0) {
568  PRINT(" internal reset\n");
569  g_reset = true;
570  }
571  if (strcmp(argv[1], "-help") == 0) {
572  print_usage();
573  }
574  }
575 
576  PRINT("KNX-IOT Server name : \"%s\"\n", MY_NAME);
577 
578  // show the current working folder
579  char buff[FILENAME_MAX];
580  char *retbuf = NULL;
581  retbuf = GetCurrentDir(buff, FILENAME_MAX);
582  if (retbuf != NULL) {
583  PRINT("Current working dir: %s\n", buff);
584  }
585 
586  /*
587  The storage folder depends on the build system
588  the folder is created in the makefile, with $target as name with _cred as
589  post fix.
590  */
591  PRINT("\tstorage at './LSSB_minimal_all_creds' \n");
592  oc_storage_config("./LSSB_minimal_all_creds");
593 
594  /*initialize the variables */
596 
597  /* initializes the handlers structure */
598  STATIC oc_handler_t handler = { .init = app_init,
599  .signal_event_loop = signal_event_loop,
600  .register_resources = register_resources,
601  .requests_entry = NULL };
602 
603  if (do_send_s_mode) {
604 
605  handler.requests_entry = issue_requests_s_mode;
606  }
607 
608  /* set the application callbacks */
610  oc_set_reset_cb(reset_cb, NULL);
613  oc_set_swu_cb(swu_cb, (void *)fname);
614 
615  /* start the stack */
616  init = oc_main_init(&handler);
617 
618  if (init < 0) {
619  PRINT("oc_main_init failed %d, exiting.\n", init);
620  return init;
621  }
622 
623 #ifdef OC_OSCORE
624  PRINT("OSCORE - Enabled\n");
625 #else
626  PRINT("OSCORE - Disabled\n");
627 #endif /* OC_OSCORE */
628 
630  PRINT("serial number: %s\n", oc_string_checked(device->serialnumber));
631 
633  if (my_ep != NULL) {
634  PRINTipaddr(*my_ep);
635  PRINT("\n");
636  }
637  PRINT("Server \"%s\" running, waiting on incoming "
638  "connections.\n",
639  MY_NAME);
640 
641 #ifdef WIN32
642  /* windows specific loop */
643  while (quit != 1) {
644  next_event = oc_main_poll();
645  if (next_event == 0) {
646  SleepConditionVariableCS(&cv, &cs, INFINITE);
647  } else {
648  oc_clock_time_t now = oc_clock_time();
649  if (now < next_event) {
650  SleepConditionVariableCS(
651  &cv, &cs, (DWORD)((next_event - now) * 1000 / OC_CLOCK_SECOND));
652  }
653  }
654  }
655 #endif
656 
657 #ifdef __linux__
658  /* Linux specific loop */
659  while (quit != 1) {
660  next_event = oc_main_poll();
661  pthread_mutex_lock(&mutex);
662  if (next_event == 0) {
663  pthread_cond_wait(&cv, &mutex);
664  } else {
665  ts.tv_sec = (next_event / OC_CLOCK_SECOND);
666  ts.tv_nsec = (next_event % OC_CLOCK_SECOND) * 1.e09 / OC_CLOCK_SECOND;
667  pthread_cond_timedwait(&cv, &mutex, &ts);
668  }
669  pthread_mutex_unlock(&mutex);
670  }
671 #endif
672 
673  /* shut down the stack */
674 
676  return 0;
677 }
void initialize_variables(void)
initializes the global variables registers and starts the handler
int app_init(void)
function to set up the device.
void swu_cb(size_t device, oc_separate_response_t *response, size_t binary_size, size_t offset, uint8_t *payload, size_t len, void *data)
software update callback
void reset_cb(size_t device_index, int reset_value, void *data)
application reset
void handle_signal(int signal)
handle Ctrl-C
void print_usage()
print usage and quits
void register_resources(void)
register all the resources to the stack this function registers all application level resources:
void factory_presets_cb(size_t device_index, void *data)
initiate preset for device current implementation: device reset as command line argument
void restart_cb(size_t device_index, void *data)
restart the device (application depended)
void hostname_cb(size_t device_index, oc_string_t host_name, void *data)
set the host name on the device (application depended)
void oc_set_reset_cb(oc_reset_cb_t cb, void *data)
Set the reset callback.
void oc_set_restart_cb(oc_restart_cb_t cb, void *data)
Set the restart callback.
void oc_set_factory_presets_cb(oc_factory_presets_cb_t cb, void *data)
Set the factory presets callback.
void oc_main_shutdown(void)
Shutdown and free all stack related resources.
oc_clock_time_t oc_main_poll(void)
poll to process tasks
int oc_main_init(const oc_handler_t *handler)
Register and call handler functions responsible for controlling the stack.
void oc_set_hostname_cb(oc_hostname_cb_t cb, void *data)
Set the host name callback.
oc_clock_time_t oc_clock_time(void)
Get the current clock time.
oc_endpoint_t * oc_connectivity_get_endpoints(size_t device)
retrieve list of endpoints for the device
void oc_set_swu_cb(oc_swu_cb_t cb, void *data)
Set the software update callback.
int oc_storage_config(const char *store)
open the storage NOTE: For embedded devices, this function doesn't do anything.
the endpoint information
Definition: oc_endpoint.h:78
Call back handlers that are invoked in response to oc_main_init()
Definition: oc_api.h:116
int(* init)(void)
Device initialization callback that is invoked to initialize the platform and device(s).
Definition: oc_api.h:141

References handle_signal().

◆ oc_add_s_mode_response_cb()

void oc_add_s_mode_response_cb ( char *  url,
oc_rep_t rep,
oc_rep_t rep_value 
)

s-mode response callback will be called when a response is received on an s-mode read request

Parameters
urlthe url
repthe full response
rep_valuethe parsed value of the response

Definition at line 129 of file lssb_minimal_all.c.

130 {
131  (void)rep;
132  (void)rep_value;
133 
134  PRINT("oc_add_s_mode_response_cb %s\n", url);
135 }

◆ print_usage()

void print_usage ( )

print usage and quits

Definition at line 516 of file lssb_minimal_all.c.

517 {
518  PRINT("Usage:\n");
519  PRINT("no arguments : starts the server\n");
520  PRINT("-help : this message\n");
521  PRINT("s-mode : starts the server and issue a s-mode message at start up "
522  "according the application/config\n");
523  PRINT("reset : does an full reset of the device\n");
524  exit(0);
525 }

◆ register_resources()

void register_resources ( void  )

register all the resources to the stack this function registers all application level resources:

  • each resource path is bind to a specific function for the supported methods (GET, POST, PUT, DELETE)
  • each resource is
    • secure
    • observable
    • discoverable
    • used interfaces

URL Table

resource url functional block/dpa GET PUT
p/o_1_1 urn:knx:dpa.421.61 Yes No

Definition at line 313 of file lssb_minimal_all.c.

314 {
315  PRINT("Register Resource with local path \"/p/o_1_1\"\n");
316  PRINT("Light Switching Sensor 421.61 (LSSB) : SwitchOnOff \n");
317  PRINT("Data point 61 (DPT_Switch) \n");
318  PRINT("Register Resource with local path \"/p/o_1_1\"\n");
319 
320  oc_resource_t *res_pushbutton =
321  oc_new_resource("push button", "/p/o_1_1", 2, 0);
322  oc_resource_bind_resource_type(res_pushbutton, "urn:knx:dpa.421.61");
323  oc_resource_bind_dpt(res_pushbutton, "urn:knx:dpt.Switch");
325  oc_resource_bind_resource_interface(res_pushbutton, OC_IF_S); /* if.s */
326  oc_resource_set_discoverable(res_pushbutton, true);
327  /* periodic observable
328  to be used when one wants to send an event per time slice
329  period is 1 second */
330  // oc_resource_set_periodic_observable(res_pushbutton, 1);
331  /* set observable
332  events are send when oc_notify_observers(oc_resource_t *resource) is
333  called. this function must be called when the value changes, preferable on
334  an interrupt when something is read from the hardware. */
335  /*oc_resource_set_observable(res_352, true); */
336  oc_resource_set_request_handler(res_pushbutton, OC_GET, get_o_1_1, NULL);
337  oc_add_resource(res_pushbutton);
338 }
void oc_resource_set_discoverable(oc_resource_t *resource, bool state)
Specify if a resource can be found using .well-known/core discover mechanisms.
oc_resource_t * oc_new_resource(const char *name, const char *uri, uint8_t num_resource_types, size_t device)
Allocate and populate a new oc_resource_t.
void oc_resource_bind_content_type(oc_resource_t *resource, oc_content_format_t content_type)
set the content type on the resource
void oc_resource_bind_dpt(oc_resource_t *resource, const char *dpt)
Add a Data Point Type "dpt" property to the resource.
bool oc_add_resource(oc_resource_t *resource)
Add a resource to the stack.
void oc_resource_bind_resource_type(oc_resource_t *resource, const char *type)
Add a Resource Type "rt" property to the resource.
void oc_resource_bind_resource_interface(oc_resource_t *resource, oc_interface_mask_t iface_mask)
Add the supported interface(s) to the resource.
void oc_resource_set_request_handler(oc_resource_t *resource, oc_method_t method, oc_request_callback_t callback, void *user_data)
Specify a request_callback for GET, PUT, POST, and DELETE methods.
STATIC void get_o_1_1(oc_request_t *request, oc_interface_mask_t interfaces, void *user_data)
GET method for "p/o_1_1" resource.
@ OC_GET
GET.
Definition: oc_ri.h:125
@ OC_IF_S
if.s (256)
Definition: oc_ri.h:270
resource structure
Definition: oc_ri.h:482

◆ reset_cb()

void reset_cb ( size_t  device_index,
int  reset_value,
void *  data 
)

application reset

Parameters
device_indexthe device identifier of the list of devices
reset_valuethe knx reset value
datathe supplied data.

Definition at line 366 of file lssb_minimal_all.c.

367 {
368  (void)device_index;
369 
370  PRINT("reset_cb %d\n", reset_value);
371 }

◆ restart_cb()

void restart_cb ( size_t  device_index,
void *  data 
)

restart the device (application depended)

Parameters
device_indexthe device identifier of the list of devices
datathe supplied data.

Definition at line 380 of file lssb_minimal_all.c.

381 {
382  (void)device_index;
383  (void)data;
384 
385  PRINT("-----restart_cb -------\n");
386  // exit(0);
387 }

◆ swu_cb()

void swu_cb ( size_t  device,
oc_separate_response_t response,
size_t  binary_size,
size_t  offset,
uint8_t *  payload,
size_t  len,
void *  data 
)

software update callback

Parameters
devicethe device index
responsethe instance of an internal struct that is used to track the state of the separate response
binary_sizethe full size of the binary
offsetthe offset of the image
payloadthe image data
lenthe length of the image data
datathe user data

Definition at line 434 of file lssb_minimal_all.c.

436 {
437  (void)device;
438  (void)binary_size;
439  char filename[] = "./downloaded.bin";
440  PRINT(" swu_cb %s block=%d size=%d \n", filename, (int)offset, (int)len);
441 
442  FILE *write_ptr = fopen("downloaded_bin", "ab");
443  size_t r = fwrite(payload, sizeof(*payload), len, write_ptr);
444  fclose(write_ptr);
445 
446  oc_set_delayed_callback(response, &send_delayed_response, 0);
447 }
void oc_set_delayed_callback(void *cb_data, oc_trigger_t callback, uint16_t seconds)
Schedule a callback to be invoked after a set number of seconds.

Variable Documentation

◆ g_mystate

bool g_mystate = false

the state of the dpa 421.61

Definition at line 116 of file lssb_minimal_all.c.

◆ g_reset

bool g_reset = false

reset the device (from startup)

Definition at line 118 of file lssb_minimal_all.c.

Referenced by factory_presets_cb().

◆ quit

volatile int quit = 0

stop variable, used by handle_signal

Definition at line 117 of file lssb_minimal_all.c.

Referenced by handle_signal().