diff --git a/knx_iot_virtual_pb.c b/knx_iot_virtual_pb.c index b9aa618..799c88a 100644 --- a/knx_iot_virtual_pb.c +++ b/knx_iot_virtual_pb.c @@ -64,6 +64,8 @@ */ #include "oc_api.h" #include "oc_core_res.h" +#include "oc_rep.h" +#include "oc_helpers.h" #include "api/oc_knx_fp.h" #include "port/oc_clock.h" #include @@ -114,17 +116,8 @@ volatile int quit = 0; /**< stop variable, used by handle_signal */ bool g_reset = false; /**< reset variable, set by commandline arguments */ char g_serial_number[20] = "00FA10010400"; -/* list all object urls as defines */ -#define CH1_URL_ONOFF_1 "/p/o_1_1" /**< define for url "/p/o_1_1" of "OnOff_1" */ -#define CH1_URL_INFOONOFF_1 "/p/o_2_2" /**< define for url "/p/o_2_2" of "InfoOnOff_1" */ -#define CH2_URL_ONOFF_2 "/p/o_3_3" /**< define for url "/p/o_3_3" of "OnOff_2" */ -#define CH2_URL_INFOONOFF_2 "/p/o_4_4" /**< define for url "/p/o_4_4" of "InfoOnOff_2" */ -#define CH3_URL_ONOFF_3 "/p/o_5_5" /**< define for url "/p/o_5_5" of "OnOff_3" */ -#define CH3_URL_INFOONOFF_3 "/p/o_6_6" /**< define for url "/p/o_6_6" of "InfoOnOff_3" */ -#define CH4_URL_ONOFF_4 "/p/o_7_7" /**< define for url "/p/o_7_7" of "OnOff_4" */ -#define CH4_URL_INFOONOFF_4 "/p/o_8_8" /**< define for url "/p/o_8_8" of "InfoOnOff_4" */ -/* list all parameter urls as defines */ + volatile bool g_OnOff_1; /**< global variable for OnOff_1 */ @@ -143,6 +136,7 @@ volatile bool g_fault_InfoOnOff_4; /**< global variable for fault InfoOnOff_4 + // BOOLEAN code /** @@ -155,28 +149,28 @@ bool app_is_bool_url(char* url) { if ( strcmp(url, URL_ONOFF_1) == 0) { return true; /**< OnOff_1 is a boolean */ - } + } if ( strcmp(url, URL_INFOONOFF_1) == 0) { return true; /**< InfoOnOff_1 is a boolean */ - } + } if ( strcmp(url, URL_ONOFF_2) == 0) { return true; /**< OnOff_2 is a boolean */ - } + } if ( strcmp(url, URL_INFOONOFF_2) == 0) { return true; /**< InfoOnOff_2 is a boolean */ - } + } if ( strcmp(url, URL_ONOFF_3) == 0) { return true; /**< OnOff_3 is a boolean */ - } + } if ( strcmp(url, URL_INFOONOFF_3) == 0) { return true; /**< InfoOnOff_3 is a boolean */ - } + } if ( strcmp(url, URL_ONOFF_4) == 0) { return true; /**< OnOff_4 is a boolean */ - } + } if ( strcmp(url, URL_INFOONOFF_4) == 0) { return true; /**< InfoOnOff_4 is a boolean */ - } + } return false; } @@ -231,133 +225,29 @@ void app_set_bool_variable(char* url, bool value) bool app_retrieve_bool_variable(char* url) { if ( strcmp(url, URL_ONOFF_1) == 0) { - return g_OnOff_1; /**< global variable for OnOff_1 */ - } + return g_OnOff_1; /**< global variable for OnOff_1 */ + } if ( strcmp(url, URL_INFOONOFF_1) == 0) { - return g_InfoOnOff_1; /**< global variable for InfoOnOff_1 */ - } + return g_InfoOnOff_1; /**< global variable for InfoOnOff_1 */ + } if ( strcmp(url, URL_ONOFF_2) == 0) { - return g_OnOff_2; /**< global variable for OnOff_2 */ - } + return g_OnOff_2; /**< global variable for OnOff_2 */ + } if ( strcmp(url, URL_INFOONOFF_2) == 0) { - return g_InfoOnOff_2; /**< global variable for InfoOnOff_2 */ - } + return g_InfoOnOff_2; /**< global variable for InfoOnOff_2 */ + } if ( strcmp(url, URL_ONOFF_3) == 0) { - return g_OnOff_3; /**< global variable for OnOff_3 */ - } + return g_OnOff_3; /**< global variable for OnOff_3 */ + } if ( strcmp(url, URL_INFOONOFF_3) == 0) { - return g_InfoOnOff_3; /**< global variable for InfoOnOff_3 */ - } + return g_InfoOnOff_3; /**< global variable for InfoOnOff_3 */ + } if ( strcmp(url, URL_ONOFF_4) == 0) { - return g_OnOff_4; /**< global variable for OnOff_4 */ - } + return g_OnOff_4; /**< global variable for OnOff_4 */ + } if ( strcmp(url, URL_INFOONOFF_4) == 0) { - return g_InfoOnOff_4; /**< global variable for InfoOnOff_4 */ - } - return false; -} - -// INTEGER code - -/** - * @brief function to check if the url is represented by a integer - * - * @param true = url value is a integer - * @param false = url is not a integer - */ -bool app_is_int_url(char* url) -{ - return false; -} -/** - * @brief sets the global int variable at the url - * - * @param url the url indicating the global variable - * @param value the value to be set - */ -void app_set_int_variable(char* url, int value) -{ -} -void app_set_integer_variable(char* url, int value) -{ - app_set_int_variable(url, value); -} - -/** - * @brief retrieve the global integer variable at the url - * - * @param url the url indicating the global variable - * @return the value of the variable - */ -int app_retrieve_int_variable(char* url) -{ - return -1; -} - -// DOUBLE code - -/** - * @brief function to check if the url is represented by a double - * - * @param true = url value is a double - * @param false = url is not a double - */ -bool app_is_double_url(char* url) -{ - return false; -} -/** - * @brief sets the global double variable at the url - * - * @param url the url indicating the global variable - * @param value the value to be set - */ -void app_set_double_variable(char* url, double value) -{ -} -/** - * @brief retrieve the global double variable at the url - * - * @param url the url indicating the global variable - * @return the value of the variable - */ -double app_retrieve_double_variable(char* url) -{ - return -1; -} - -// STRING code - -/** - * @brief function to check if the url is represented by a string - * - * @param true = url value is a string - * @param false = url is not a string - */ -bool app_is_string_url(char* url) -{ - return false; -} - -/** - * @brief sets the global string variable at the url - * - * @param url the url indicating the global variable - * @param value the value to be set - */ -void app_set_string_variable(char* url, char* value) -{ -} - -/** - * @brief retrieve the global string variable at the url - * - * @param url the url indicating the global variable - * @return the value of the variable - */ -char* app_retrieve_string_variable(char* url) -{ - return NULL; + return g_InfoOnOff_4; /**< global variable for InfoOnOff_4 */ + } } // FAULT code @@ -460,21 +350,22 @@ int app_init(void); * @brief devboard button toggle callback * */ -void dev_btn_toggle_cb(char *url) -{ - PRINT_APP("Handling %s\n", url); - bool val = app_retrieve_bool_variable(url); - if (val == true) - { - val = false; - } - else - { - val = true; - } - app_set_bool_variable(url, val); - oc_do_s_mode_with_scope(5, url, "w"); -} +// we no longer have app_set_bool_variable +//void dev_btn_toggle_cb(char *url) +//{ +// PRINT_APP("Handling %s\n", url); +// bool val = app_retrieve_bool_variable(url); +// if (val == true) +// { +// val = false; +// } +// else +// { +// val = true; +// } +// app_set_bool_variable(url, val); +// oc_do_s_mode_with_scope(5, url, "w"); +//} /** * @brief s-mode response callback @@ -518,8 +409,8 @@ void app_str_to_upper(char *str){ * - base path * - knx spec version * - hardware version : [0, 1, 3] - * - firmware version : [0, 1, 8] - * - hardware type : Linux/windows + * - firmware version : [0, 1, 9] + * - hardware type : LW0001 * - device model : KNX virtual - PB * */ @@ -539,12 +430,12 @@ app_init(void) oc_core_set_device_hwv(0, 0, 1, 3); - /* set the firmware version 0.1.8 */ - oc_core_set_device_fwv(0, 0, 1, 8); + /* set the firmware version 0.1.9 */ + oc_core_set_device_fwv(0, 0, 1, 9); /* set the hardware type*/ - oc_core_set_device_hwt(0, "Linux/windows"); + oc_core_set_device_hwt(0, "LW0001"); /* set the model */ oc_core_set_device_model(0, "KNX virtual - PB"); @@ -552,12 +443,13 @@ app_init(void) oc_set_s_mode_response_cb(oc_add_s_mode_response_cb); #define PASSWORD "ABY8B77J50YXMUDW3DG4" #ifdef OC_SPAKE - oc_spake_set_password(PASSWORD); + if (strlen(oc_spake_get_password()) == 0) + oc_spake_set_password(PASSWORD); strncpy(serial_number_uppercase, oc_string(device->serialnumber), 19); app_str_to_upper(serial_number_uppercase); - printf("\n === QR Code: KNX:S:%s;P:%s ===\n", serial_number_uppercase, PASSWORD); + printf("\n === QR Code: KNX:S:%s;P:%s ===\n", serial_number_uppercase, oc_spake_get_password()); #endif return ret; @@ -619,7 +511,7 @@ get_OnOff_1(oc_request_t *request, oc_interface_mask_t interfaces, oc_rep_begin_root_object(); while (oc_iterate_query(request, &m_key, &m_key_len, &m, &m_len) != -1) { // unique identifier - if ((strncmp(m, "id", m_len) == 0) | + if ((strncmp(m, "id", m_len) == 0) | (strncmp(m, "*", m_len) == 0) ) { char mystring[100]; snprintf(mystring,99,"urn:knx:sn:%s%s",oc_string(device->serialnumber), @@ -627,21 +519,21 @@ get_OnOff_1(oc_request_t *request, oc_interface_mask_t interfaces, oc_rep_i_set_text_string(root, 9, mystring); } // resource types - if ((strncmp(m, "rt", m_len) == 0) | + if ((strncmp(m, "rt", m_len) == 0) | (strncmp(m, "*", m_len) == 0) ) { - oc_rep_set_text_string(root, rt, "urn:knx:dpa.421.61"); + oc_rep_set_text_string(root, rt, "urn:knx:dpa.421.61"); } // interfaces - if ((strncmp(m, "if", m_len) == 0) | + if ((strncmp(m, "if", m_len) == 0) | (strncmp(m, "*", m_len) == 0) ) { oc_rep_set_text_string(root, if, "if.s"); } - if ((strncmp(m, "dpt", m_len) == 0) | + if ((strncmp(m, "dpt", m_len) == 0) | (strncmp(m, "*", m_len) == 0) ) { - oc_rep_set_text_string(root, dpt, oc_string(request->resource->dpt)); + oc_rep_set_text_string(root, dpt, oc_string(request->resource->dpt)); } // ga - if ((strncmp(m, "ga", m_len) == 0) | + if ((strncmp(m, "ga", m_len) == 0) | (strncmp(m, "*", m_len) == 0) ) { int index = oc_core_find_group_object_table_url(oc_string(request->resource->uri)); if (index > -1) { @@ -651,7 +543,7 @@ get_OnOff_1(oc_request_t *request, oc_interface_mask_t interfaces, } } } - if ((strncmp(m, "desc", m_len) == 0) | + if ((strncmp(m, "desc", m_len) == 0) | (strncmp(m, "*", m_len) == 0) ) { oc_rep_set_text_string(root, desc, "On/Off push button 1"); } @@ -663,11 +555,11 @@ get_OnOff_1(oc_request_t *request, oc_interface_mask_t interfaces, } oc_send_cbor_response(request, OC_STATUS_OK); return; - } - + } oc_rep_begin_root_object(); oc_rep_i_set_boolean(root, 1, g_OnOff_1); - oc_rep_end_root_object(); + oc_rep_end_root_object(); + if (g_err) { error_state = true; } @@ -727,7 +619,7 @@ get_InfoOnOff_1(oc_request_t *request, oc_interface_mask_t interfaces, oc_rep_begin_root_object(); while (oc_iterate_query(request, &m_key, &m_key_len, &m, &m_len) != -1) { // unique identifier - if ((strncmp(m, "id", m_len) == 0) | + if ((strncmp(m, "id", m_len) == 0) | (strncmp(m, "*", m_len) == 0) ) { char mystring[100]; snprintf(mystring,99,"urn:knx:sn:%s%s",oc_string(device->serialnumber), @@ -735,21 +627,21 @@ get_InfoOnOff_1(oc_request_t *request, oc_interface_mask_t interfaces, oc_rep_i_set_text_string(root, 9, mystring); } // resource types - if ((strncmp(m, "rt", m_len) == 0) | + if ((strncmp(m, "rt", m_len) == 0) | (strncmp(m, "*", m_len) == 0) ) { - oc_rep_set_text_string(root, rt, "urn:knx:dpa.421.51"); + oc_rep_set_text_string(root, rt, "urn:knx:dpa.421.51"); } // interfaces - if ((strncmp(m, "if", m_len) == 0) | + if ((strncmp(m, "if", m_len) == 0) | (strncmp(m, "*", m_len) == 0) ) { oc_rep_set_text_string(root, if, "if.a"); } - if ((strncmp(m, "dpt", m_len) == 0) | + if ((strncmp(m, "dpt", m_len) == 0) | (strncmp(m, "*", m_len) == 0) ) { - oc_rep_set_text_string(root, dpt, oc_string(request->resource->dpt)); + oc_rep_set_text_string(root, dpt, oc_string(request->resource->dpt)); } // ga - if ((strncmp(m, "ga", m_len) == 0) | + if ((strncmp(m, "ga", m_len) == 0) | (strncmp(m, "*", m_len) == 0) ) { int index = oc_core_find_group_object_table_url(oc_string(request->resource->uri)); if (index > -1) { @@ -759,7 +651,7 @@ get_InfoOnOff_1(oc_request_t *request, oc_interface_mask_t interfaces, } } } - if ((strncmp(m, "desc", m_len) == 0) | + if ((strncmp(m, "desc", m_len) == 0) | (strncmp(m, "*", m_len) == 0) ) { oc_rep_set_text_string(root, desc, "Feedback 1"); } @@ -771,11 +663,11 @@ get_InfoOnOff_1(oc_request_t *request, oc_interface_mask_t interfaces, } oc_send_cbor_response(request, OC_STATUS_OK); return; - } - + } oc_rep_begin_root_object(); oc_rep_i_set_boolean(root, 1, g_InfoOnOff_1); - oc_rep_end_root_object(); + oc_rep_end_root_object(); + if (g_err) { error_state = true; } @@ -811,28 +703,30 @@ put_InfoOnOff_1(oc_request_t *request, oc_interface_mask_t interfaces, bool error_state = true; PRINT("-- Begin put_InfoOnOff_1:\n"); - oc_rep_t *req = NULL; + oc_rep_t *rep = NULL; /* handle the different requests e.g. via s-mode or normal CoAP call*/ if (oc_is_redirected_request(request)) { PRINT(" redirected request..\n"); } - req = request->request_payload; + rep = request->request_payload; /* loop over all the entries in the request */ - while (req != NULL) { + /* handle the type of payload correctly. */ + error_state = true; + while (rep != NULL) { /* handle the type of payload correctly. */ - if ((req->iname == 1) && (req->type == OC_REP_BOOL)) { - PRINT(" put_InfoOnOff_1 received : %d\n", req->value.boolean); - g_InfoOnOff_1 = req->value.boolean; + if ((rep->iname == 1) && (rep->type == OC_REP_BOOL)) { + PRINT(" put_InfoOnOff_1 received : %d\n", rep->value.boolean); + g_InfoOnOff_1 = rep->value.boolean; error_state = false; - if (error_state == false){ - /* input is valid, so handle the response */ - oc_send_cbor_response(request, OC_STATUS_CHANGED); - do_put_cb(URL_INFOONOFF_1); - PRINT("-- End put_InfoOnOff_1\n"); - return; - } + break; } - req = req->next; + } + + if (error_state == false){ + oc_send_cbor_response(request, OC_STATUS_CHANGED); + do_put_cb(URL_INFOONOFF_1); + PRINT("-- End put_InfoOnOff_1\n"); + return; } /* request data was not recognized, so it was a bad request */ oc_send_response(request, OC_STATUS_BAD_REQUEST); @@ -884,7 +778,7 @@ get_OnOff_2(oc_request_t *request, oc_interface_mask_t interfaces, oc_rep_begin_root_object(); while (oc_iterate_query(request, &m_key, &m_key_len, &m, &m_len) != -1) { // unique identifier - if ((strncmp(m, "id", m_len) == 0) | + if ((strncmp(m, "id", m_len) == 0) | (strncmp(m, "*", m_len) == 0) ) { char mystring[100]; snprintf(mystring,99,"urn:knx:sn:%s%s",oc_string(device->serialnumber), @@ -892,21 +786,21 @@ get_OnOff_2(oc_request_t *request, oc_interface_mask_t interfaces, oc_rep_i_set_text_string(root, 9, mystring); } // resource types - if ((strncmp(m, "rt", m_len) == 0) | + if ((strncmp(m, "rt", m_len) == 0) | (strncmp(m, "*", m_len) == 0) ) { - oc_rep_set_text_string(root, rt, "urn:knx:dpa.421.61"); + oc_rep_set_text_string(root, rt, "urn:knx:dpa.421.61"); } // interfaces - if ((strncmp(m, "if", m_len) == 0) | + if ((strncmp(m, "if", m_len) == 0) | (strncmp(m, "*", m_len) == 0) ) { oc_rep_set_text_string(root, if, "if.s"); } - if ((strncmp(m, "dpt", m_len) == 0) | + if ((strncmp(m, "dpt", m_len) == 0) | (strncmp(m, "*", m_len) == 0) ) { - oc_rep_set_text_string(root, dpt, oc_string(request->resource->dpt)); + oc_rep_set_text_string(root, dpt, oc_string(request->resource->dpt)); } // ga - if ((strncmp(m, "ga", m_len) == 0) | + if ((strncmp(m, "ga", m_len) == 0) | (strncmp(m, "*", m_len) == 0) ) { int index = oc_core_find_group_object_table_url(oc_string(request->resource->uri)); if (index > -1) { @@ -916,7 +810,7 @@ get_OnOff_2(oc_request_t *request, oc_interface_mask_t interfaces, } } } - if ((strncmp(m, "desc", m_len) == 0) | + if ((strncmp(m, "desc", m_len) == 0) | (strncmp(m, "*", m_len) == 0) ) { oc_rep_set_text_string(root, desc, "On/Off push button 2"); } @@ -928,11 +822,11 @@ get_OnOff_2(oc_request_t *request, oc_interface_mask_t interfaces, } oc_send_cbor_response(request, OC_STATUS_OK); return; - } - + } oc_rep_begin_root_object(); oc_rep_i_set_boolean(root, 1, g_OnOff_2); - oc_rep_end_root_object(); + oc_rep_end_root_object(); + if (g_err) { error_state = true; } @@ -992,7 +886,7 @@ get_InfoOnOff_2(oc_request_t *request, oc_interface_mask_t interfaces, oc_rep_begin_root_object(); while (oc_iterate_query(request, &m_key, &m_key_len, &m, &m_len) != -1) { // unique identifier - if ((strncmp(m, "id", m_len) == 0) | + if ((strncmp(m, "id", m_len) == 0) | (strncmp(m, "*", m_len) == 0) ) { char mystring[100]; snprintf(mystring,99,"urn:knx:sn:%s%s",oc_string(device->serialnumber), @@ -1000,21 +894,21 @@ get_InfoOnOff_2(oc_request_t *request, oc_interface_mask_t interfaces, oc_rep_i_set_text_string(root, 9, mystring); } // resource types - if ((strncmp(m, "rt", m_len) == 0) | + if ((strncmp(m, "rt", m_len) == 0) | (strncmp(m, "*", m_len) == 0) ) { - oc_rep_set_text_string(root, rt, "urn:knx:dpa.421.51"); + oc_rep_set_text_string(root, rt, "urn:knx:dpa.421.51"); } // interfaces - if ((strncmp(m, "if", m_len) == 0) | + if ((strncmp(m, "if", m_len) == 0) | (strncmp(m, "*", m_len) == 0) ) { oc_rep_set_text_string(root, if, "if.a"); } - if ((strncmp(m, "dpt", m_len) == 0) | + if ((strncmp(m, "dpt", m_len) == 0) | (strncmp(m, "*", m_len) == 0) ) { - oc_rep_set_text_string(root, dpt, oc_string(request->resource->dpt)); + oc_rep_set_text_string(root, dpt, oc_string(request->resource->dpt)); } // ga - if ((strncmp(m, "ga", m_len) == 0) | + if ((strncmp(m, "ga", m_len) == 0) | (strncmp(m, "*", m_len) == 0) ) { int index = oc_core_find_group_object_table_url(oc_string(request->resource->uri)); if (index > -1) { @@ -1024,7 +918,7 @@ get_InfoOnOff_2(oc_request_t *request, oc_interface_mask_t interfaces, } } } - if ((strncmp(m, "desc", m_len) == 0) | + if ((strncmp(m, "desc", m_len) == 0) | (strncmp(m, "*", m_len) == 0) ) { oc_rep_set_text_string(root, desc, "Feedback 2"); } @@ -1036,11 +930,11 @@ get_InfoOnOff_2(oc_request_t *request, oc_interface_mask_t interfaces, } oc_send_cbor_response(request, OC_STATUS_OK); return; - } - + } oc_rep_begin_root_object(); oc_rep_i_set_boolean(root, 1, g_InfoOnOff_2); - oc_rep_end_root_object(); + oc_rep_end_root_object(); + if (g_err) { error_state = true; } @@ -1076,28 +970,30 @@ put_InfoOnOff_2(oc_request_t *request, oc_interface_mask_t interfaces, bool error_state = true; PRINT("-- Begin put_InfoOnOff_2:\n"); - oc_rep_t *req = NULL; + oc_rep_t *rep = NULL; /* handle the different requests e.g. via s-mode or normal CoAP call*/ if (oc_is_redirected_request(request)) { PRINT(" redirected request..\n"); } - req = request->request_payload; + rep = request->request_payload; /* loop over all the entries in the request */ - while (req != NULL) { + /* handle the type of payload correctly. */ + error_state = true; + while (rep != NULL) { /* handle the type of payload correctly. */ - if ((req->iname == 1) && (req->type == OC_REP_BOOL)) { - PRINT(" put_InfoOnOff_2 received : %d\n", req->value.boolean); - g_InfoOnOff_2 = req->value.boolean; + if ((rep->iname == 1) && (rep->type == OC_REP_BOOL)) { + PRINT(" put_InfoOnOff_2 received : %d\n", rep->value.boolean); + g_InfoOnOff_2 = rep->value.boolean; error_state = false; - if (error_state == false){ - /* input is valid, so handle the response */ - oc_send_cbor_response(request, OC_STATUS_CHANGED); - do_put_cb(URL_INFOONOFF_2); - PRINT("-- End put_InfoOnOff_2\n"); - return; - } + break; } - req = req->next; + } + + if (error_state == false){ + oc_send_cbor_response(request, OC_STATUS_CHANGED); + do_put_cb(URL_INFOONOFF_2); + PRINT("-- End put_InfoOnOff_2\n"); + return; } /* request data was not recognized, so it was a bad request */ oc_send_response(request, OC_STATUS_BAD_REQUEST); @@ -1149,7 +1045,7 @@ get_OnOff_3(oc_request_t *request, oc_interface_mask_t interfaces, oc_rep_begin_root_object(); while (oc_iterate_query(request, &m_key, &m_key_len, &m, &m_len) != -1) { // unique identifier - if ((strncmp(m, "id", m_len) == 0) | + if ((strncmp(m, "id", m_len) == 0) | (strncmp(m, "*", m_len) == 0) ) { char mystring[100]; snprintf(mystring,99,"urn:knx:sn:%s%s",oc_string(device->serialnumber), @@ -1157,21 +1053,21 @@ get_OnOff_3(oc_request_t *request, oc_interface_mask_t interfaces, oc_rep_i_set_text_string(root, 9, mystring); } // resource types - if ((strncmp(m, "rt", m_len) == 0) | + if ((strncmp(m, "rt", m_len) == 0) | (strncmp(m, "*", m_len) == 0) ) { - oc_rep_set_text_string(root, rt, "urn:knx:dpa.421.61"); + oc_rep_set_text_string(root, rt, "urn:knx:dpa.421.61"); } // interfaces - if ((strncmp(m, "if", m_len) == 0) | + if ((strncmp(m, "if", m_len) == 0) | (strncmp(m, "*", m_len) == 0) ) { oc_rep_set_text_string(root, if, "if.s"); } - if ((strncmp(m, "dpt", m_len) == 0) | + if ((strncmp(m, "dpt", m_len) == 0) | (strncmp(m, "*", m_len) == 0) ) { - oc_rep_set_text_string(root, dpt, oc_string(request->resource->dpt)); + oc_rep_set_text_string(root, dpt, oc_string(request->resource->dpt)); } // ga - if ((strncmp(m, "ga", m_len) == 0) | + if ((strncmp(m, "ga", m_len) == 0) | (strncmp(m, "*", m_len) == 0) ) { int index = oc_core_find_group_object_table_url(oc_string(request->resource->uri)); if (index > -1) { @@ -1181,7 +1077,7 @@ get_OnOff_3(oc_request_t *request, oc_interface_mask_t interfaces, } } } - if ((strncmp(m, "desc", m_len) == 0) | + if ((strncmp(m, "desc", m_len) == 0) | (strncmp(m, "*", m_len) == 0) ) { oc_rep_set_text_string(root, desc, "On/Off push button 3"); } @@ -1193,11 +1089,11 @@ get_OnOff_3(oc_request_t *request, oc_interface_mask_t interfaces, } oc_send_cbor_response(request, OC_STATUS_OK); return; - } - + } oc_rep_begin_root_object(); oc_rep_i_set_boolean(root, 1, g_OnOff_3); - oc_rep_end_root_object(); + oc_rep_end_root_object(); + if (g_err) { error_state = true; } @@ -1257,7 +1153,7 @@ get_InfoOnOff_3(oc_request_t *request, oc_interface_mask_t interfaces, oc_rep_begin_root_object(); while (oc_iterate_query(request, &m_key, &m_key_len, &m, &m_len) != -1) { // unique identifier - if ((strncmp(m, "id", m_len) == 0) | + if ((strncmp(m, "id", m_len) == 0) | (strncmp(m, "*", m_len) == 0) ) { char mystring[100]; snprintf(mystring,99,"urn:knx:sn:%s%s",oc_string(device->serialnumber), @@ -1265,21 +1161,21 @@ get_InfoOnOff_3(oc_request_t *request, oc_interface_mask_t interfaces, oc_rep_i_set_text_string(root, 9, mystring); } // resource types - if ((strncmp(m, "rt", m_len) == 0) | + if ((strncmp(m, "rt", m_len) == 0) | (strncmp(m, "*", m_len) == 0) ) { - oc_rep_set_text_string(root, rt, "urn:knx:dpa.421.51"); + oc_rep_set_text_string(root, rt, "urn:knx:dpa.421.51"); } // interfaces - if ((strncmp(m, "if", m_len) == 0) | + if ((strncmp(m, "if", m_len) == 0) | (strncmp(m, "*", m_len) == 0) ) { oc_rep_set_text_string(root, if, "if.a"); } - if ((strncmp(m, "dpt", m_len) == 0) | + if ((strncmp(m, "dpt", m_len) == 0) | (strncmp(m, "*", m_len) == 0) ) { - oc_rep_set_text_string(root, dpt, oc_string(request->resource->dpt)); + oc_rep_set_text_string(root, dpt, oc_string(request->resource->dpt)); } // ga - if ((strncmp(m, "ga", m_len) == 0) | + if ((strncmp(m, "ga", m_len) == 0) | (strncmp(m, "*", m_len) == 0) ) { int index = oc_core_find_group_object_table_url(oc_string(request->resource->uri)); if (index > -1) { @@ -1289,7 +1185,7 @@ get_InfoOnOff_3(oc_request_t *request, oc_interface_mask_t interfaces, } } } - if ((strncmp(m, "desc", m_len) == 0) | + if ((strncmp(m, "desc", m_len) == 0) | (strncmp(m, "*", m_len) == 0) ) { oc_rep_set_text_string(root, desc, "Feedback 3"); } @@ -1301,11 +1197,11 @@ get_InfoOnOff_3(oc_request_t *request, oc_interface_mask_t interfaces, } oc_send_cbor_response(request, OC_STATUS_OK); return; - } - + } oc_rep_begin_root_object(); oc_rep_i_set_boolean(root, 1, g_InfoOnOff_3); - oc_rep_end_root_object(); + oc_rep_end_root_object(); + if (g_err) { error_state = true; } @@ -1341,28 +1237,30 @@ put_InfoOnOff_3(oc_request_t *request, oc_interface_mask_t interfaces, bool error_state = true; PRINT("-- Begin put_InfoOnOff_3:\n"); - oc_rep_t *req = NULL; + oc_rep_t *rep = NULL; /* handle the different requests e.g. via s-mode or normal CoAP call*/ if (oc_is_redirected_request(request)) { PRINT(" redirected request..\n"); } - req = request->request_payload; + rep = request->request_payload; /* loop over all the entries in the request */ - while (req != NULL) { + /* handle the type of payload correctly. */ + error_state = true; + while (rep != NULL) { /* handle the type of payload correctly. */ - if ((req->iname == 1) && (req->type == OC_REP_BOOL)) { - PRINT(" put_InfoOnOff_3 received : %d\n", req->value.boolean); - g_InfoOnOff_3 = req->value.boolean; + if ((rep->iname == 1) && (rep->type == OC_REP_BOOL)) { + PRINT(" put_InfoOnOff_3 received : %d\n", rep->value.boolean); + g_InfoOnOff_3 = rep->value.boolean; error_state = false; - if (error_state == false){ - /* input is valid, so handle the response */ - oc_send_cbor_response(request, OC_STATUS_CHANGED); - do_put_cb(URL_INFOONOFF_3); - PRINT("-- End put_InfoOnOff_3\n"); - return; - } + break; } - req = req->next; + } + + if (error_state == false){ + oc_send_cbor_response(request, OC_STATUS_CHANGED); + do_put_cb(URL_INFOONOFF_3); + PRINT("-- End put_InfoOnOff_3\n"); + return; } /* request data was not recognized, so it was a bad request */ oc_send_response(request, OC_STATUS_BAD_REQUEST); @@ -1414,7 +1312,7 @@ get_OnOff_4(oc_request_t *request, oc_interface_mask_t interfaces, oc_rep_begin_root_object(); while (oc_iterate_query(request, &m_key, &m_key_len, &m, &m_len) != -1) { // unique identifier - if ((strncmp(m, "id", m_len) == 0) | + if ((strncmp(m, "id", m_len) == 0) | (strncmp(m, "*", m_len) == 0) ) { char mystring[100]; snprintf(mystring,99,"urn:knx:sn:%s%s",oc_string(device->serialnumber), @@ -1422,21 +1320,21 @@ get_OnOff_4(oc_request_t *request, oc_interface_mask_t interfaces, oc_rep_i_set_text_string(root, 9, mystring); } // resource types - if ((strncmp(m, "rt", m_len) == 0) | + if ((strncmp(m, "rt", m_len) == 0) | (strncmp(m, "*", m_len) == 0) ) { - oc_rep_set_text_string(root, rt, "urn:knx:dpa.421.61"); + oc_rep_set_text_string(root, rt, "urn:knx:dpa.421.61"); } // interfaces - if ((strncmp(m, "if", m_len) == 0) | + if ((strncmp(m, "if", m_len) == 0) | (strncmp(m, "*", m_len) == 0) ) { oc_rep_set_text_string(root, if, "if.s"); } - if ((strncmp(m, "dpt", m_len) == 0) | + if ((strncmp(m, "dpt", m_len) == 0) | (strncmp(m, "*", m_len) == 0) ) { - oc_rep_set_text_string(root, dpt, oc_string(request->resource->dpt)); + oc_rep_set_text_string(root, dpt, oc_string(request->resource->dpt)); } // ga - if ((strncmp(m, "ga", m_len) == 0) | + if ((strncmp(m, "ga", m_len) == 0) | (strncmp(m, "*", m_len) == 0) ) { int index = oc_core_find_group_object_table_url(oc_string(request->resource->uri)); if (index > -1) { @@ -1446,7 +1344,7 @@ get_OnOff_4(oc_request_t *request, oc_interface_mask_t interfaces, } } } - if ((strncmp(m, "desc", m_len) == 0) | + if ((strncmp(m, "desc", m_len) == 0) | (strncmp(m, "*", m_len) == 0) ) { oc_rep_set_text_string(root, desc, "On/Off push button 4"); } @@ -1458,11 +1356,11 @@ get_OnOff_4(oc_request_t *request, oc_interface_mask_t interfaces, } oc_send_cbor_response(request, OC_STATUS_OK); return; - } - + } oc_rep_begin_root_object(); oc_rep_i_set_boolean(root, 1, g_OnOff_4); - oc_rep_end_root_object(); + oc_rep_end_root_object(); + if (g_err) { error_state = true; } @@ -1522,7 +1420,7 @@ get_InfoOnOff_4(oc_request_t *request, oc_interface_mask_t interfaces, oc_rep_begin_root_object(); while (oc_iterate_query(request, &m_key, &m_key_len, &m, &m_len) != -1) { // unique identifier - if ((strncmp(m, "id", m_len) == 0) | + if ((strncmp(m, "id", m_len) == 0) | (strncmp(m, "*", m_len) == 0) ) { char mystring[100]; snprintf(mystring,99,"urn:knx:sn:%s%s",oc_string(device->serialnumber), @@ -1530,21 +1428,21 @@ get_InfoOnOff_4(oc_request_t *request, oc_interface_mask_t interfaces, oc_rep_i_set_text_string(root, 9, mystring); } // resource types - if ((strncmp(m, "rt", m_len) == 0) | + if ((strncmp(m, "rt", m_len) == 0) | (strncmp(m, "*", m_len) == 0) ) { - oc_rep_set_text_string(root, rt, "urn:knx:dpa.421.51"); + oc_rep_set_text_string(root, rt, "urn:knx:dpa.421.51"); } // interfaces - if ((strncmp(m, "if", m_len) == 0) | + if ((strncmp(m, "if", m_len) == 0) | (strncmp(m, "*", m_len) == 0) ) { oc_rep_set_text_string(root, if, "if.a"); } - if ((strncmp(m, "dpt", m_len) == 0) | + if ((strncmp(m, "dpt", m_len) == 0) | (strncmp(m, "*", m_len) == 0) ) { - oc_rep_set_text_string(root, dpt, oc_string(request->resource->dpt)); + oc_rep_set_text_string(root, dpt, oc_string(request->resource->dpt)); } // ga - if ((strncmp(m, "ga", m_len) == 0) | + if ((strncmp(m, "ga", m_len) == 0) | (strncmp(m, "*", m_len) == 0) ) { int index = oc_core_find_group_object_table_url(oc_string(request->resource->uri)); if (index > -1) { @@ -1554,7 +1452,7 @@ get_InfoOnOff_4(oc_request_t *request, oc_interface_mask_t interfaces, } } } - if ((strncmp(m, "desc", m_len) == 0) | + if ((strncmp(m, "desc", m_len) == 0) | (strncmp(m, "*", m_len) == 0) ) { oc_rep_set_text_string(root, desc, "Feedback 4"); } @@ -1566,11 +1464,11 @@ get_InfoOnOff_4(oc_request_t *request, oc_interface_mask_t interfaces, } oc_send_cbor_response(request, OC_STATUS_OK); return; - } - + } oc_rep_begin_root_object(); oc_rep_i_set_boolean(root, 1, g_InfoOnOff_4); - oc_rep_end_root_object(); + oc_rep_end_root_object(); + if (g_err) { error_state = true; } @@ -1606,28 +1504,30 @@ put_InfoOnOff_4(oc_request_t *request, oc_interface_mask_t interfaces, bool error_state = true; PRINT("-- Begin put_InfoOnOff_4:\n"); - oc_rep_t *req = NULL; + oc_rep_t *rep = NULL; /* handle the different requests e.g. via s-mode or normal CoAP call*/ if (oc_is_redirected_request(request)) { PRINT(" redirected request..\n"); } - req = request->request_payload; + rep = request->request_payload; /* loop over all the entries in the request */ - while (req != NULL) { + /* handle the type of payload correctly. */ + error_state = true; + while (rep != NULL) { /* handle the type of payload correctly. */ - if ((req->iname == 1) && (req->type == OC_REP_BOOL)) { - PRINT(" put_InfoOnOff_4 received : %d\n", req->value.boolean); - g_InfoOnOff_4 = req->value.boolean; + if ((rep->iname == 1) && (rep->type == OC_REP_BOOL)) { + PRINT(" put_InfoOnOff_4 received : %d\n", rep->value.boolean); + g_InfoOnOff_4 = rep->value.boolean; error_state = false; - if (error_state == false){ - /* input is valid, so handle the response */ - oc_send_cbor_response(request, OC_STATUS_CHANGED); - do_put_cb(URL_INFOONOFF_4); - PRINT("-- End put_InfoOnOff_4\n"); - return; - } + break; } - req = req->next; + } + + if (error_state == false){ + oc_send_cbor_response(request, OC_STATUS_CHANGED); + do_put_cb(URL_INFOONOFF_4); + PRINT("-- End put_InfoOnOff_4\n"); + return; } /* request data was not recognized, so it was a bad request */ oc_send_response(request, OC_STATUS_BAD_REQUEST); @@ -1916,15 +1816,18 @@ initialize_variables(void) { /* initialize global variables for resources */ /* if wanted read them from persistent storage */ - g_OnOff_1 = false; /**< global variable for OnOff_1 */ - g_InfoOnOff_1 = false; /**< global variable for InfoOnOff_1 */ - g_OnOff_2 = false; /**< global variable for OnOff_2 */ - g_InfoOnOff_2 = false; /**< global variable for InfoOnOff_2 */ - g_OnOff_3 = false; /**< global variable for OnOff_3 */ - g_InfoOnOff_3 = false; /**< global variable for InfoOnOff_3 */ - g_OnOff_4 = false; /**< global variable for OnOff_4 */ - g_InfoOnOff_4 = false; /**< global variable for InfoOnOff_4 */ + //g_OnOff_1 = false; /**< global variable for OnOff_1 */ + //g_InfoOnOff_1 = false; /**< global variable for InfoOnOff_1 */ + //g_OnOff_2 = false; /**< global variable for OnOff_2 */ + //g_InfoOnOff_2 = false; /**< global variable for InfoOnOff_2 */ + //g_OnOff_3 = false; /**< global variable for OnOff_3 */ + //g_InfoOnOff_3 = false; /**< global variable for InfoOnOff_3 */ + //g_OnOff_4 = false; /**< global variable for OnOff_4 */ + //g_InfoOnOff_4 = false; /**< global variable for InfoOnOff_4 */ /* parameter variables */ + uint8_t oc_storage_buf[32]; + long ret; + bool err; } diff --git a/knx_iot_virtual_pb.cpp b/knx_iot_virtual_pb.cpp index 7b735ad..d26e883 100644 --- a/knx_iot_virtual_pb.cpp +++ b/knx_iot_virtual_pb.cpp @@ -16,7 +16,7 @@ -=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-= */ -// 2023-06-29 11:52:14.764097 +// 2023-07-31 10:49:05.497089 // For compilers that support precompilation, includes "wx/wx.h". #include @@ -133,7 +133,7 @@ class MyFrame : public wxFrame void OnClearTables(wxCommandEvent& event); void OnExit(wxCommandEvent& event); void OnAbout(wxCommandEvent& event); - void OnTimer(wxTimerEvent& event); + void OnTimer(wxTimerEvent& event); void OnPressed_OnOff_1(wxCommandEvent& event); void OnPressed_OnOff_2(wxCommandEvent& event); void OnPressed_OnOff_3(wxCommandEvent& event); @@ -164,21 +164,21 @@ class MyFrame : public wxFrame wxTextCtrl* m_hostname_text; // text control for host name wxTextCtrl* m_secured_text; // text secure/not secure //DP_ID_ONOFF_1 bool - wxButton* m_ONOFF_1; // OnOff_1 if.s + wxButton* m_ONOFF_1; // OnOff_1 if.s //DP_ID_INFOONOFF_1 bool - wxCheckBox* m_INFOONOFF_1 ; // InfoOnOff_1 if.a + wxCheckBox* m_INFOONOFF_1 ; // InfoOnOff_1 if.a //DP_ID_ONOFF_2 bool - wxButton* m_ONOFF_2; // OnOff_2 if.s + wxButton* m_ONOFF_2; // OnOff_2 if.s //DP_ID_INFOONOFF_2 bool - wxCheckBox* m_INFOONOFF_2 ; // InfoOnOff_2 if.a + wxCheckBox* m_INFOONOFF_2 ; // InfoOnOff_2 if.a //DP_ID_ONOFF_3 bool - wxButton* m_ONOFF_3; // OnOff_3 if.s + wxButton* m_ONOFF_3; // OnOff_3 if.s //DP_ID_INFOONOFF_3 bool - wxCheckBox* m_INFOONOFF_3 ; // InfoOnOff_3 if.a + wxCheckBox* m_INFOONOFF_3 ; // InfoOnOff_3 if.a //DP_ID_ONOFF_4 bool - wxButton* m_ONOFF_4; // OnOff_4 if.s + wxButton* m_ONOFF_4; // OnOff_4 if.s //DP_ID_INFOONOFF_4 bool - wxCheckBox* m_INFOONOFF_4 ; // InfoOnOff_4 if.a + wxCheckBox* m_INFOONOFF_4 ; // InfoOnOff_4 if.a }; @@ -280,52 +280,52 @@ MyFrame::MyFrame(char* str_serial_number) //DP_ID_ONOFF_1 // if.s ==> sensor == possible to change value in UI m_ONOFF_1 = new wxButton(this, DP_ID_ONOFF_1, _T("OnOff_1 ('/p/o_1_1')"), wxPoint(10 + column*x_width, 10 + (x_height*row)), wxSize(x_width, x_height), 0); - m_ONOFF_1->Bind(wxEVT_BUTTON, &MyFrame::OnPressed_OnOff_1, this); + m_ONOFF_1->Bind(wxEVT_BUTTON, &MyFrame::OnPressed_OnOff_1, this); index = 2-1; row = 1 -1; column = (index % max_dp_count) - column_offset; //DP_ID_INFOONOFF_1 m_INFOONOFF_1 = new wxCheckBox(this, DP_ID_INFOONOFF_1, _T("InfoOnOff_1 ('/p/o_2_2')"), wxPoint(10 + column*x_width, 10 + (x_height*row)), wxSize(x_width, x_height), 0); - m_INFOONOFF_1->Enable(false); + m_INFOONOFF_1->Enable(false); index = 3-1; row = 2 -1; column = (index % max_dp_count) - column_offset; //DP_ID_ONOFF_2 // if.s ==> sensor == possible to change value in UI m_ONOFF_2 = new wxButton(this, DP_ID_ONOFF_2, _T("OnOff_2 ('/p/o_3_3')"), wxPoint(10 + column*x_width, 10 + (x_height*row)), wxSize(x_width, x_height), 0); - m_ONOFF_2->Bind(wxEVT_BUTTON, &MyFrame::OnPressed_OnOff_2, this); + m_ONOFF_2->Bind(wxEVT_BUTTON, &MyFrame::OnPressed_OnOff_2, this); index = 4-1; row = 2 -1; column = (index % max_dp_count) - column_offset; //DP_ID_INFOONOFF_2 m_INFOONOFF_2 = new wxCheckBox(this, DP_ID_INFOONOFF_2, _T("InfoOnOff_2 ('/p/o_4_4')"), wxPoint(10 + column*x_width, 10 + (x_height*row)), wxSize(x_width, x_height), 0); - m_INFOONOFF_2->Enable(false); + m_INFOONOFF_2->Enable(false); index = 5-1; row = 3 -1; column = (index % max_dp_count) - column_offset; //DP_ID_ONOFF_3 // if.s ==> sensor == possible to change value in UI m_ONOFF_3 = new wxButton(this, DP_ID_ONOFF_3, _T("OnOff_3 ('/p/o_5_5')"), wxPoint(10 + column*x_width, 10 + (x_height*row)), wxSize(x_width, x_height), 0); - m_ONOFF_3->Bind(wxEVT_BUTTON, &MyFrame::OnPressed_OnOff_3, this); + m_ONOFF_3->Bind(wxEVT_BUTTON, &MyFrame::OnPressed_OnOff_3, this); index = 6-1; row = 3 -1; column = (index % max_dp_count) - column_offset; //DP_ID_INFOONOFF_3 m_INFOONOFF_3 = new wxCheckBox(this, DP_ID_INFOONOFF_3, _T("InfoOnOff_3 ('/p/o_6_6')"), wxPoint(10 + column*x_width, 10 + (x_height*row)), wxSize(x_width, x_height), 0); - m_INFOONOFF_3->Enable(false); + m_INFOONOFF_3->Enable(false); index = 7-1; row = 4 -1; column = (index % max_dp_count) - column_offset; //DP_ID_ONOFF_4 // if.s ==> sensor == possible to change value in UI m_ONOFF_4 = new wxButton(this, DP_ID_ONOFF_4, _T("OnOff_4 ('/p/o_7_7')"), wxPoint(10 + column*x_width, 10 + (x_height*row)), wxSize(x_width, x_height), 0); - m_ONOFF_4->Bind(wxEVT_BUTTON, &MyFrame::OnPressed_OnOff_4, this); + m_ONOFF_4->Bind(wxEVT_BUTTON, &MyFrame::OnPressed_OnOff_4, this); index = 8-1; row = 4 -1; column = (index % max_dp_count) - column_offset; //DP_ID_INFOONOFF_4 m_INFOONOFF_4 = new wxCheckBox(this, DP_ID_INFOONOFF_4, _T("InfoOnOff_4 ('/p/o_8_8')"), wxPoint(10 + column*x_width, 10 + (x_height*row)), wxSize(x_width, x_height), 0); - m_INFOONOFF_4->Enable(false); + m_INFOONOFF_4->Enable(false); if (strlen(str_serial_number) > 1) { app_set_serial_number(str_serial_number); @@ -751,22 +751,12 @@ void MyFrame::OnParameterList(wxCommandEvent& event) sprintf(line, " name: '%s' ", app_get_parameter_name(index)); strcat(text, line); } - if (app_is_bool_url(url)) { - sprintf(line, " value : '%d' ", app_retrieve_bool_variable(url)); - strcat(text, line); - } - if (app_is_int_url(url)) { - sprintf(line, " value : '%d' ", app_retrieve_int_variable(url)); - strcat(text, line); - } - if (app_is_double_url(url)) { - sprintf(line, " value : '%f' ", (float)app_retrieve_double_variable(url)); - strcat(text, line); - } - if (app_is_string_url(url)) { - sprintf(line, " value : '%s' ", app_retrieve_string_variable(url)); - strcat(text, line); - } + + + //if (app_is_string_url(url)) { + // sprintf(line, " value : '%s' ", app_retrieve_string_variable(url)); + // strcat(text, line); + //} index++; url = app_get_parameter_url(index); } @@ -920,9 +910,9 @@ void MyFrame::OnAbout(wxCommandEvent& event) strcat(text,"\n"); strcat(text,"manufactorer : cascoda\n"); strcat(text,"model : KNX virtual - PB\n"); - strcat(text,"hardware type : Linux/windows\n"); + strcat(text,"hardware type : LW0001\n"); strcat(text,"hardware version : [0, 1, 3]\n"); - strcat(text,"firmware version : [0, 1, 8]\n\n"); + strcat(text,"firmware version : [0, 1, 9]\n\n"); strcat(text, "data points:\n"); strcat(text,"url:/p/o_1_1 rt:urn:knx:dpa.421.61 if:if.s inst:1 name:OnOff_1\n"); @@ -937,7 +927,7 @@ void MyFrame::OnAbout(wxCommandEvent& event) strcat(text, "(c) Cascoda Ltd\n"); strcat(text, "(c) KNX.org\n"); - strcat(text, "2023-06-29 11:52:14.764097"); + strcat(text, "2023-07-31 10:49:05.497089"); CustomDialog("About", text); } @@ -992,15 +982,15 @@ void MyFrame::OnTimer(wxTimerEvent& event) */ void MyFrame::updateInfoCheckBoxes() { - bool p; - p = app_retrieve_bool_variable("/p/o_2_2"); // set toggle of InfoOnOff_1 - m_INFOONOFF_1->SetValue(p); - p = app_retrieve_bool_variable("/p/o_4_4"); // set toggle of InfoOnOff_2 - m_INFOONOFF_2->SetValue(p); - p = app_retrieve_bool_variable("/p/o_6_6"); // set toggle of InfoOnOff_3 - m_INFOONOFF_3->SetValue(p); - p = app_retrieve_bool_variable("/p/o_8_8"); // set toggle of InfoOnOff_4 - m_INFOONOFF_4->SetValue(p); + bool p; + p = app_retrieve_bool_variable(URL_INFOONOFF_1); + m_INFOONOFF_1->SetValue(p); + p = app_retrieve_bool_variable(URL_INFOONOFF_2); + m_INFOONOFF_2->SetValue(p); + p = app_retrieve_bool_variable(URL_INFOONOFF_3); + m_INFOONOFF_3->SetValue(p); + p = app_retrieve_bool_variable(URL_INFOONOFF_4); + m_INFOONOFF_4->SetValue(p); } @@ -1150,23 +1140,32 @@ void MyFrame::updateInfoButtons() char text[200]; bool p; int p_int; + float f; double d; - p = app_retrieve_bool_variable("/p/o_2_2"); // set button text of InfoOnOff_1 - strcpy(text, "InfoOnOff_1 ('/p/o_2_2')"); + p = app_retrieve_bool_variable(URL_ONOFF_1); strcpy(text, "OnOff_1 ('/p/o_1_1')"); + this->bool2text(p, text); + m_ONOFF_1->SetLabel(text); + p = app_retrieve_bool_variable(URL_INFOONOFF_1); strcpy(text, "InfoOnOff_1 ('/p/o_2_2')"); + this->bool2text(p, text); + m_INFOONOFF_1->SetLabel(text); + p = app_retrieve_bool_variable(URL_ONOFF_2); strcpy(text, "OnOff_2 ('/p/o_3_3')"); + this->bool2text(p, text); + m_ONOFF_2->SetLabel(text); + p = app_retrieve_bool_variable(URL_INFOONOFF_2); strcpy(text, "InfoOnOff_2 ('/p/o_4_4')"); + this->bool2text(p, text); + m_INFOONOFF_2->SetLabel(text); + p = app_retrieve_bool_variable(URL_ONOFF_3); strcpy(text, "OnOff_3 ('/p/o_5_5')"); this->bool2text(p, text); - m_INFOONOFF_1->SetLabel(text); - p = app_retrieve_bool_variable("/p/o_4_4"); // set button text of InfoOnOff_2 - strcpy(text, "InfoOnOff_2 ('/p/o_4_4')"); + m_ONOFF_3->SetLabel(text); + p = app_retrieve_bool_variable(URL_INFOONOFF_3); strcpy(text, "InfoOnOff_3 ('/p/o_6_6')"); this->bool2text(p, text); - m_INFOONOFF_2->SetLabel(text); - p = app_retrieve_bool_variable("/p/o_6_6"); // set button text of InfoOnOff_3 - strcpy(text, "InfoOnOff_3 ('/p/o_6_6')"); + m_INFOONOFF_3->SetLabel(text); + p = app_retrieve_bool_variable(URL_ONOFF_4); strcpy(text, "OnOff_4 ('/p/o_7_7')"); this->bool2text(p, text); - m_INFOONOFF_3->SetLabel(text); - p = app_retrieve_bool_variable("/p/o_8_8"); // set button text of InfoOnOff_4 - strcpy(text, "InfoOnOff_4 ('/p/o_8_8')"); + m_ONOFF_4->SetLabel(text); + p = app_retrieve_bool_variable(URL_INFOONOFF_4); strcpy(text, "InfoOnOff_4 ('/p/o_8_8')"); this->bool2text(p, text); - m_INFOONOFF_4->SetLabel(text); + m_INFOONOFF_4->SetLabel(text); } void MyFrame::OnPressed_OnOff_1(wxCommandEvent& event) @@ -1185,7 +1184,7 @@ void MyFrame::OnPressed_OnOff_1(wxCommandEvent& event) oc_do_s_mode_with_scope(5, url, "w"); sprintf(my_text, "OnOff_1 ('%s') pressed: %d", url, (int)p); SetStatusText(my_text); -} +} void MyFrame::OnPressed_OnOff_2(wxCommandEvent& event) { char url[] = "/p/o_3_3"; @@ -1202,7 +1201,7 @@ void MyFrame::OnPressed_OnOff_2(wxCommandEvent& event) oc_do_s_mode_with_scope(5, url, "w"); sprintf(my_text, "OnOff_2 ('%s') pressed: %d", url, (int)p); SetStatusText(my_text); -} +} void MyFrame::OnPressed_OnOff_3(wxCommandEvent& event) { char url[] = "/p/o_5_5"; @@ -1219,7 +1218,7 @@ void MyFrame::OnPressed_OnOff_3(wxCommandEvent& event) oc_do_s_mode_with_scope(5, url, "w"); sprintf(my_text, "OnOff_3 ('%s') pressed: %d", url, (int)p); SetStatusText(my_text); -} +} void MyFrame::OnPressed_OnOff_4(wxCommandEvent& event) { char url[] = "/p/o_7_7"; @@ -1236,7 +1235,7 @@ void MyFrame::OnPressed_OnOff_4(wxCommandEvent& event) oc_do_s_mode_with_scope(5, url, "w"); sprintf(my_text, "OnOff_4 ('%s') pressed: %d", url, (int)p); SetStatusText(my_text); -} +} diff --git a/knx_iot_virtual_pb.h b/knx_iot_virtual_pb.h index 509b23a..db4b764 100644 --- a/knx_iot_virtual_pb.h +++ b/knx_iot_virtual_pb.h @@ -45,6 +45,8 @@ extern "C" { #define URL_ONOFF_4 "/p/o_7_7" // define URL OnOff_4 for /p/o_7_7 #define URL_INFOONOFF_4 "/p/o_8_8" // define URL InfoOnOff_4 for /p/o_8_8 + + /** * Callback invoked by the stack when a successfull put is done * @@ -85,123 +87,32 @@ int app_initialize_stack(); */ int app_set_serial_number(char* serial_number); -/** - * @brief checks if the url depicts an boolean - * - * @param url the url to check - * @return true: url conveys a boolean - */ -bool app_is_bool_url(char* url); +// Getters/Setters for bool /** - * @brief retrieve the boolean variable of the url/data point - * the caller needs to know if the resource/data point is conveying a boolean - * "/p/o_1_1" of OnOff_1 - * "/p/o_2_2" of InfoOnOff_1 - * "/p/o_3_3" of OnOff_2 - * "/p/o_4_4" of InfoOnOff_2 - * "/p/o_5_5" of OnOff_3 - * "/p/o_6_6" of InfoOnOff_3 - * "/p/o_7_7" of OnOff_4 - * "/p/o_8_8" of InfoOnOff_4 + * @brief Checks if the url depicts a bool * - * @param url the url of the resource/data point - * @return true value is true - * @return false value is false or error. + * @param url the url + * @return true: url conveys a bool */ -bool app_retrieve_bool_variable(char* url); +bool app_is_bool_url(char* url); /** - * @brief set the boolean variable that belongs to the url - * The caller needs to know if the resource/data point is conveying a boolean - * "/p/o_2_2" of InfoOnOff_1 - * "/p/o_4_4" of InfoOnOff_2 - * "/p/o_6_6" of InfoOnOff_3 - * "/p/o_8_8" of InfoOnOff_4 + * @brief Set a bool * - * @param url the url of the resource/data point - * @param value the boolean value to be set + * @param url the url for the bool to set + * @param in value to set */ void app_set_bool_variable(char* url, bool value); /** - * @brief checks if the url depicts an int + * @brief Get a bool * - * @param url the url to check - * @return true: url conveys a int - */ -bool app_is_int_url(char* url); - -/** - * @brief retrieve the int variable of the url/data point - * the caller needs to know if the resource/data point is conveying a integer - * - * @param url the url of the resource/data point - * @return the integer value of the global variable - */ -int app_retrieve_int_variable(char* url); - -/** - * @brief set the integer variable that belongs to the url - * The caller needs to know if the resource/data point is conveying a integer - * - * @param url the url of the resource/data point - * @param value the integer value to be set + * @param url the url for the bool to get + * @return boolean variable */ +bool app_retrieve_bool_variable(char *url); -void app_set_int_variable(char* url, int value); - -void app_set_integer_variable(char* url, int value); - -/** - * @brief checks if the url depicts an double - * - * @param url the url to check - * @return true: url conveys a double - */ -bool app_is_double_url(char* url); - -/** - * @brief retrieve the double variable of the url/data point - * the caller needs to know if the resource/data point is conveying a integer - * - * @param url the url of the resource/data point - * @return the double value of the global variable - */ -double app_retrieve_double_variable(char* url); - -/** - * @brief set the double variable that belongs to the url - * The caller needs to know if the resource/data point is conveying a double - * - * @param url the url of the resource/data point - * @param value the double value to be set - */ -void app_set_double_variable(char* url, double value); - -/** - * @brief function to check if the url is represented by a string - * - * @param url the url value is a string - * @return true = url returns a string, false = url is not a string - */ -bool app_is_string_url(char* url); - -/** - * @brief sets the global string variable at the url - * - * @param url the url indicating the global variable - * @param value the string value to be set - */ -void app_set_string_variable(char* url, char* value); - -/** - * @brief retrieve the global string variable at the url - * - * @param url the url indicating the global variable - * @return the value of the variable - */ -char* app_retrieve_string_variable(char* url); /** * @brief checks if the url represents a parameter diff --git a/knx_iot_virtual_sa.c b/knx_iot_virtual_sa.c index f221757..c5f379b 100644 --- a/knx_iot_virtual_sa.c +++ b/knx_iot_virtual_sa.c @@ -64,6 +64,8 @@ */ #include "oc_api.h" #include "oc_core_res.h" +#include "oc_rep.h" +#include "oc_helpers.h" #include "api/oc_knx_fp.h" #include "port/oc_clock.h" #include @@ -114,17 +116,8 @@ volatile int quit = 0; /**< stop variable, used by handle_signal */ bool g_reset = false; /**< reset variable, set by commandline arguments */ char g_serial_number[20] = "00FA10010700"; -/* list all object urls as defines */ -#define CH1_URL_ONOFF_1 "/p/o_1_1" /**< define for url "/p/o_1_1" of "OnOff_1" */ -#define CH1_URL_INFOONOFF_1 "/p/o_2_2" /**< define for url "/p/o_2_2" of "InfoOnOff_1" */ -#define CH2_URL_ONOFF_2 "/p/o_3_3" /**< define for url "/p/o_3_3" of "OnOff_2" */ -#define CH2_URL_INFOONOFF_2 "/p/o_4_4" /**< define for url "/p/o_4_4" of "InfoOnOff_2" */ -#define CH3_URL_ONOFF_3 "/p/o_5_5" /**< define for url "/p/o_5_5" of "OnOff_3" */ -#define CH3_URL_INFOONOFF_3 "/p/o_6_6" /**< define for url "/p/o_6_6" of "InfoOnOff_3" */ -#define CH4_URL_ONOFF_4 "/p/o_7_7" /**< define for url "/p/o_7_7" of "OnOff_4" */ -#define CH4_URL_INFOONOFF_4 "/p/o_8_8" /**< define for url "/p/o_8_8" of "InfoOnOff_4" */ -/* list all parameter urls as defines */ + volatile bool g_OnOff_1; /**< global variable for OnOff_1 */ @@ -143,6 +136,7 @@ volatile bool g_fault_OnOff_4; /**< global variable for fault OnOff_4 */ + // BOOLEAN code /** @@ -155,28 +149,28 @@ bool app_is_bool_url(char* url) { if ( strcmp(url, URL_ONOFF_1) == 0) { return true; /**< OnOff_1 is a boolean */ - } + } if ( strcmp(url, URL_INFOONOFF_1) == 0) { return true; /**< InfoOnOff_1 is a boolean */ - } + } if ( strcmp(url, URL_ONOFF_2) == 0) { return true; /**< OnOff_2 is a boolean */ - } + } if ( strcmp(url, URL_INFOONOFF_2) == 0) { return true; /**< InfoOnOff_2 is a boolean */ - } + } if ( strcmp(url, URL_ONOFF_3) == 0) { return true; /**< OnOff_3 is a boolean */ - } + } if ( strcmp(url, URL_INFOONOFF_3) == 0) { return true; /**< InfoOnOff_3 is a boolean */ - } + } if ( strcmp(url, URL_ONOFF_4) == 0) { return true; /**< OnOff_4 is a boolean */ - } + } if ( strcmp(url, URL_INFOONOFF_4) == 0) { return true; /**< InfoOnOff_4 is a boolean */ - } + } return false; } @@ -231,133 +225,29 @@ void app_set_bool_variable(char* url, bool value) bool app_retrieve_bool_variable(char* url) { if ( strcmp(url, URL_ONOFF_1) == 0) { - return g_OnOff_1; /**< global variable for OnOff_1 */ - } + return g_OnOff_1; /**< global variable for OnOff_1 */ + } if ( strcmp(url, URL_INFOONOFF_1) == 0) { - return g_InfoOnOff_1; /**< global variable for InfoOnOff_1 */ - } + return g_InfoOnOff_1; /**< global variable for InfoOnOff_1 */ + } if ( strcmp(url, URL_ONOFF_2) == 0) { - return g_OnOff_2; /**< global variable for OnOff_2 */ - } + return g_OnOff_2; /**< global variable for OnOff_2 */ + } if ( strcmp(url, URL_INFOONOFF_2) == 0) { - return g_InfoOnOff_2; /**< global variable for InfoOnOff_2 */ - } + return g_InfoOnOff_2; /**< global variable for InfoOnOff_2 */ + } if ( strcmp(url, URL_ONOFF_3) == 0) { - return g_OnOff_3; /**< global variable for OnOff_3 */ - } + return g_OnOff_3; /**< global variable for OnOff_3 */ + } if ( strcmp(url, URL_INFOONOFF_3) == 0) { - return g_InfoOnOff_3; /**< global variable for InfoOnOff_3 */ - } + return g_InfoOnOff_3; /**< global variable for InfoOnOff_3 */ + } if ( strcmp(url, URL_ONOFF_4) == 0) { - return g_OnOff_4; /**< global variable for OnOff_4 */ - } + return g_OnOff_4; /**< global variable for OnOff_4 */ + } if ( strcmp(url, URL_INFOONOFF_4) == 0) { - return g_InfoOnOff_4; /**< global variable for InfoOnOff_4 */ - } - return false; -} - -// INTEGER code - -/** - * @brief function to check if the url is represented by a integer - * - * @param true = url value is a integer - * @param false = url is not a integer - */ -bool app_is_int_url(char* url) -{ - return false; -} -/** - * @brief sets the global int variable at the url - * - * @param url the url indicating the global variable - * @param value the value to be set - */ -void app_set_int_variable(char* url, int value) -{ -} -void app_set_integer_variable(char* url, int value) -{ - app_set_int_variable(url, value); -} - -/** - * @brief retrieve the global integer variable at the url - * - * @param url the url indicating the global variable - * @return the value of the variable - */ -int app_retrieve_int_variable(char* url) -{ - return -1; -} - -// DOUBLE code - -/** - * @brief function to check if the url is represented by a double - * - * @param true = url value is a double - * @param false = url is not a double - */ -bool app_is_double_url(char* url) -{ - return false; -} -/** - * @brief sets the global double variable at the url - * - * @param url the url indicating the global variable - * @param value the value to be set - */ -void app_set_double_variable(char* url, double value) -{ -} -/** - * @brief retrieve the global double variable at the url - * - * @param url the url indicating the global variable - * @return the value of the variable - */ -double app_retrieve_double_variable(char* url) -{ - return -1; -} - -// STRING code - -/** - * @brief function to check if the url is represented by a string - * - * @param true = url value is a string - * @param false = url is not a string - */ -bool app_is_string_url(char* url) -{ - return false; -} - -/** - * @brief sets the global string variable at the url - * - * @param url the url indicating the global variable - * @param value the value to be set - */ -void app_set_string_variable(char* url, char* value) -{ -} - -/** - * @brief retrieve the global string variable at the url - * - * @param url the url indicating the global variable - * @return the value of the variable - */ -char* app_retrieve_string_variable(char* url) -{ - return NULL; + return g_InfoOnOff_4; /**< global variable for InfoOnOff_4 */ + } } // FAULT code @@ -504,21 +394,22 @@ int app_init(void); * @brief devboard button toggle callback * */ -void dev_btn_toggle_cb(char *url) -{ - PRINT_APP("Handling %s\n", url); - bool val = app_retrieve_bool_variable(url); - if (val == true) - { - val = false; - } - else - { - val = true; - } - app_set_bool_variable(url, val); - oc_do_s_mode_with_scope(5, url, "w"); -} +// we no longer have app_set_bool_variable +//void dev_btn_toggle_cb(char *url) +//{ +// PRINT_APP("Handling %s\n", url); +// bool val = app_retrieve_bool_variable(url); +// if (val == true) +// { +// val = false; +// } +// else +// { +// val = true; +// } +// app_set_bool_variable(url, val); +// oc_do_s_mode_with_scope(5, url, "w"); +//} /** * @brief s-mode response callback @@ -562,8 +453,8 @@ void app_str_to_upper(char *str){ * - base path * - knx spec version * - hardware version : [0, 1, 3] - * - firmware version : [0, 1, 8] - * - hardware type : Windows + * - firmware version : [0, 1, 9] + * - hardware type : LW0001 * - device model : KNX virtual - SA * */ @@ -583,12 +474,12 @@ app_init(void) oc_core_set_device_hwv(0, 0, 1, 3); - /* set the firmware version 0.1.8 */ - oc_core_set_device_fwv(0, 0, 1, 8); + /* set the firmware version 0.1.9 */ + oc_core_set_device_fwv(0, 0, 1, 9); /* set the hardware type*/ - oc_core_set_device_hwt(0, "Windows"); + oc_core_set_device_hwt(0, "LW0001"); /* set the model */ oc_core_set_device_model(0, "KNX virtual - SA"); @@ -596,12 +487,13 @@ app_init(void) oc_set_s_mode_response_cb(oc_add_s_mode_response_cb); #define PASSWORD "0MK4U5LV950ST3VRXL8G" #ifdef OC_SPAKE - oc_spake_set_password(PASSWORD); + if (strlen(oc_spake_get_password()) == 0) + oc_spake_set_password(PASSWORD); strncpy(serial_number_uppercase, oc_string(device->serialnumber), 19); app_str_to_upper(serial_number_uppercase); - printf("\n === QR Code: KNX:S:%s;P:%s ===\n", serial_number_uppercase, PASSWORD); + printf("\n === QR Code: KNX:S:%s;P:%s ===\n", serial_number_uppercase, oc_spake_get_password()); #endif return ret; @@ -663,7 +555,7 @@ get_OnOff_1(oc_request_t *request, oc_interface_mask_t interfaces, oc_rep_begin_root_object(); while (oc_iterate_query(request, &m_key, &m_key_len, &m, &m_len) != -1) { // unique identifier - if ((strncmp(m, "id", m_len) == 0) | + if ((strncmp(m, "id", m_len) == 0) | (strncmp(m, "*", m_len) == 0) ) { char mystring[100]; snprintf(mystring,99,"urn:knx:sn:%s%s",oc_string(device->serialnumber), @@ -671,21 +563,21 @@ get_OnOff_1(oc_request_t *request, oc_interface_mask_t interfaces, oc_rep_i_set_text_string(root, 9, mystring); } // resource types - if ((strncmp(m, "rt", m_len) == 0) | + if ((strncmp(m, "rt", m_len) == 0) | (strncmp(m, "*", m_len) == 0) ) { - oc_rep_set_text_string(root, rt, "urn:knx:dpa.417.61"); + oc_rep_set_text_string(root, rt, "urn:knx:dpa.417.61"); } // interfaces - if ((strncmp(m, "if", m_len) == 0) | + if ((strncmp(m, "if", m_len) == 0) | (strncmp(m, "*", m_len) == 0) ) { oc_rep_set_text_string(root, if, "if.a"); } - if ((strncmp(m, "dpt", m_len) == 0) | + if ((strncmp(m, "dpt", m_len) == 0) | (strncmp(m, "*", m_len) == 0) ) { - oc_rep_set_text_string(root, dpt, oc_string(request->resource->dpt)); + oc_rep_set_text_string(root, dpt, oc_string(request->resource->dpt)); } // ga - if ((strncmp(m, "ga", m_len) == 0) | + if ((strncmp(m, "ga", m_len) == 0) | (strncmp(m, "*", m_len) == 0) ) { int index = oc_core_find_group_object_table_url(oc_string(request->resource->uri)); if (index > -1) { @@ -695,7 +587,7 @@ get_OnOff_1(oc_request_t *request, oc_interface_mask_t interfaces, } } } - if ((strncmp(m, "desc", m_len) == 0) | + if ((strncmp(m, "desc", m_len) == 0) | (strncmp(m, "*", m_len) == 0) ) { oc_rep_set_text_string(root, desc, "On/Off switch 1"); } @@ -707,11 +599,11 @@ get_OnOff_1(oc_request_t *request, oc_interface_mask_t interfaces, } oc_send_cbor_response(request, OC_STATUS_OK); return; - } - + } oc_rep_begin_root_object(); oc_rep_i_set_boolean(root, 1, g_OnOff_1); - oc_rep_end_root_object(); + oc_rep_end_root_object(); + if (g_err) { error_state = true; } @@ -747,41 +639,43 @@ put_OnOff_1(oc_request_t *request, oc_interface_mask_t interfaces, bool error_state = true; PRINT("-- Begin put_OnOff_1:\n"); - oc_rep_t *req = NULL; + oc_rep_t *rep = NULL; /* handle the different requests e.g. via s-mode or normal CoAP call*/ if (oc_is_redirected_request(request)) { PRINT(" redirected request..\n"); } - req = request->request_payload; + rep = request->request_payload; /* loop over all the entries in the request */ - while (req != NULL) { + /* handle the type of payload correctly. */ + error_state = true; + while (rep != NULL) { /* handle the type of payload correctly. */ - if ((req->iname == 1) && (req->type == OC_REP_BOOL)) { - PRINT(" put_OnOff_1 received : %d\n", req->value.boolean); - g_OnOff_1 = req->value.boolean; + if ((rep->iname == 1) && (rep->type == OC_REP_BOOL)) { + PRINT(" put_OnOff_1 received : %d\n", rep->value.boolean); + g_OnOff_1 = rep->value.boolean; error_state = false; - if (error_state == false){ - /* input is valid, so handle the response */ - oc_send_cbor_response(request, OC_STATUS_CHANGED); + break; + } + } + + if (error_state == false){ + oc_send_cbor_response(request, OC_STATUS_CHANGED); /* update the status information of InfoOnOff_1*/ if (g_fault_OnOff_1 == false) { PRINT(" No Fault update feedback to %d'\n", g_OnOff_1); /* no fault hence update the feedback with the current state of the actuator */ - g_OnOff_1 = g_OnOff_1; + g_InfoOnOff_1 = g_OnOff_1; } else { /* fault hence update the feedback with "false" */ PRINT(" Fault'\n"); - g_OnOff_1 = false; + g_InfoOnOff_1 = false; } /* send the status information InfoOnOff_1 to '/p/o_2_2' with flag 'w' */ PRINT(" Send status to '/p/o_2_2' with flag: 'w'\n"); - oc_do_s_mode_with_scope(5, CH1_URL_INFOONOFF_1, "w"); - do_put_cb(URL_ONOFF_1); - PRINT("-- End put_OnOff_1\n"); - return; - } - } - req = req->next; + oc_do_s_mode_with_scope(5, URL_INFOONOFF_1, "w"); + do_put_cb(URL_ONOFF_1); + PRINT("-- End put_OnOff_1\n"); + return; } /* request data was not recognized, so it was a bad request */ oc_send_response(request, OC_STATUS_BAD_REQUEST); @@ -833,7 +727,7 @@ get_InfoOnOff_1(oc_request_t *request, oc_interface_mask_t interfaces, oc_rep_begin_root_object(); while (oc_iterate_query(request, &m_key, &m_key_len, &m, &m_len) != -1) { // unique identifier - if ((strncmp(m, "id", m_len) == 0) | + if ((strncmp(m, "id", m_len) == 0) | (strncmp(m, "*", m_len) == 0) ) { char mystring[100]; snprintf(mystring,99,"urn:knx:sn:%s%s",oc_string(device->serialnumber), @@ -841,21 +735,21 @@ get_InfoOnOff_1(oc_request_t *request, oc_interface_mask_t interfaces, oc_rep_i_set_text_string(root, 9, mystring); } // resource types - if ((strncmp(m, "rt", m_len) == 0) | + if ((strncmp(m, "rt", m_len) == 0) | (strncmp(m, "*", m_len) == 0) ) { - oc_rep_set_text_string(root, rt, "urn:knx:dpa.417.51"); + oc_rep_set_text_string(root, rt, "urn:knx:dpa.417.51"); } // interfaces - if ((strncmp(m, "if", m_len) == 0) | + if ((strncmp(m, "if", m_len) == 0) | (strncmp(m, "*", m_len) == 0) ) { oc_rep_set_text_string(root, if, "if.s"); } - if ((strncmp(m, "dpt", m_len) == 0) | + if ((strncmp(m, "dpt", m_len) == 0) | (strncmp(m, "*", m_len) == 0) ) { - oc_rep_set_text_string(root, dpt, oc_string(request->resource->dpt)); + oc_rep_set_text_string(root, dpt, oc_string(request->resource->dpt)); } // ga - if ((strncmp(m, "ga", m_len) == 0) | + if ((strncmp(m, "ga", m_len) == 0) | (strncmp(m, "*", m_len) == 0) ) { int index = oc_core_find_group_object_table_url(oc_string(request->resource->uri)); if (index > -1) { @@ -865,7 +759,7 @@ get_InfoOnOff_1(oc_request_t *request, oc_interface_mask_t interfaces, } } } - if ((strncmp(m, "desc", m_len) == 0) | + if ((strncmp(m, "desc", m_len) == 0) | (strncmp(m, "*", m_len) == 0) ) { oc_rep_set_text_string(root, desc, "Feedback 1"); } @@ -877,11 +771,11 @@ get_InfoOnOff_1(oc_request_t *request, oc_interface_mask_t interfaces, } oc_send_cbor_response(request, OC_STATUS_OK); return; - } - + } oc_rep_begin_root_object(); oc_rep_i_set_boolean(root, 1, g_InfoOnOff_1); - oc_rep_end_root_object(); + oc_rep_end_root_object(); + if (g_err) { error_state = true; } @@ -941,7 +835,7 @@ get_OnOff_2(oc_request_t *request, oc_interface_mask_t interfaces, oc_rep_begin_root_object(); while (oc_iterate_query(request, &m_key, &m_key_len, &m, &m_len) != -1) { // unique identifier - if ((strncmp(m, "id", m_len) == 0) | + if ((strncmp(m, "id", m_len) == 0) | (strncmp(m, "*", m_len) == 0) ) { char mystring[100]; snprintf(mystring,99,"urn:knx:sn:%s%s",oc_string(device->serialnumber), @@ -949,21 +843,21 @@ get_OnOff_2(oc_request_t *request, oc_interface_mask_t interfaces, oc_rep_i_set_text_string(root, 9, mystring); } // resource types - if ((strncmp(m, "rt", m_len) == 0) | + if ((strncmp(m, "rt", m_len) == 0) | (strncmp(m, "*", m_len) == 0) ) { - oc_rep_set_text_string(root, rt, "urn:knx:dpa.417.61"); + oc_rep_set_text_string(root, rt, "urn:knx:dpa.417.61"); } // interfaces - if ((strncmp(m, "if", m_len) == 0) | + if ((strncmp(m, "if", m_len) == 0) | (strncmp(m, "*", m_len) == 0) ) { oc_rep_set_text_string(root, if, "if.a"); } - if ((strncmp(m, "dpt", m_len) == 0) | + if ((strncmp(m, "dpt", m_len) == 0) | (strncmp(m, "*", m_len) == 0) ) { - oc_rep_set_text_string(root, dpt, oc_string(request->resource->dpt)); + oc_rep_set_text_string(root, dpt, oc_string(request->resource->dpt)); } // ga - if ((strncmp(m, "ga", m_len) == 0) | + if ((strncmp(m, "ga", m_len) == 0) | (strncmp(m, "*", m_len) == 0) ) { int index = oc_core_find_group_object_table_url(oc_string(request->resource->uri)); if (index > -1) { @@ -973,7 +867,7 @@ get_OnOff_2(oc_request_t *request, oc_interface_mask_t interfaces, } } } - if ((strncmp(m, "desc", m_len) == 0) | + if ((strncmp(m, "desc", m_len) == 0) | (strncmp(m, "*", m_len) == 0) ) { oc_rep_set_text_string(root, desc, "On/Off switch 2"); } @@ -985,11 +879,11 @@ get_OnOff_2(oc_request_t *request, oc_interface_mask_t interfaces, } oc_send_cbor_response(request, OC_STATUS_OK); return; - } - + } oc_rep_begin_root_object(); oc_rep_i_set_boolean(root, 1, g_OnOff_2); - oc_rep_end_root_object(); + oc_rep_end_root_object(); + if (g_err) { error_state = true; } @@ -1025,41 +919,43 @@ put_OnOff_2(oc_request_t *request, oc_interface_mask_t interfaces, bool error_state = true; PRINT("-- Begin put_OnOff_2:\n"); - oc_rep_t *req = NULL; + oc_rep_t *rep = NULL; /* handle the different requests e.g. via s-mode or normal CoAP call*/ if (oc_is_redirected_request(request)) { PRINT(" redirected request..\n"); } - req = request->request_payload; + rep = request->request_payload; /* loop over all the entries in the request */ - while (req != NULL) { + /* handle the type of payload correctly. */ + error_state = true; + while (rep != NULL) { /* handle the type of payload correctly. */ - if ((req->iname == 1) && (req->type == OC_REP_BOOL)) { - PRINT(" put_OnOff_2 received : %d\n", req->value.boolean); - g_OnOff_2 = req->value.boolean; + if ((rep->iname == 1) && (rep->type == OC_REP_BOOL)) { + PRINT(" put_OnOff_2 received : %d\n", rep->value.boolean); + g_OnOff_2 = rep->value.boolean; error_state = false; - if (error_state == false){ - /* input is valid, so handle the response */ - oc_send_cbor_response(request, OC_STATUS_CHANGED); + break; + } + } + + if (error_state == false){ + oc_send_cbor_response(request, OC_STATUS_CHANGED); /* update the status information of InfoOnOff_2*/ if (g_fault_OnOff_2 == false) { PRINT(" No Fault update feedback to %d'\n", g_OnOff_2); /* no fault hence update the feedback with the current state of the actuator */ - g_OnOff_2 = g_OnOff_2; + g_InfoOnOff_2 = g_OnOff_2; } else { /* fault hence update the feedback with "false" */ PRINT(" Fault'\n"); - g_OnOff_2 = false; + g_InfoOnOff_2 = false; } /* send the status information InfoOnOff_2 to '/p/o_4_4' with flag 'w' */ PRINT(" Send status to '/p/o_4_4' with flag: 'w'\n"); - oc_do_s_mode_with_scope(5, CH2_URL_INFOONOFF_2, "w"); - do_put_cb(URL_ONOFF_2); - PRINT("-- End put_OnOff_2\n"); - return; - } - } - req = req->next; + oc_do_s_mode_with_scope(5, URL_INFOONOFF_2, "w"); + do_put_cb(URL_ONOFF_2); + PRINT("-- End put_OnOff_2\n"); + return; } /* request data was not recognized, so it was a bad request */ oc_send_response(request, OC_STATUS_BAD_REQUEST); @@ -1111,7 +1007,7 @@ get_InfoOnOff_2(oc_request_t *request, oc_interface_mask_t interfaces, oc_rep_begin_root_object(); while (oc_iterate_query(request, &m_key, &m_key_len, &m, &m_len) != -1) { // unique identifier - if ((strncmp(m, "id", m_len) == 0) | + if ((strncmp(m, "id", m_len) == 0) | (strncmp(m, "*", m_len) == 0) ) { char mystring[100]; snprintf(mystring,99,"urn:knx:sn:%s%s",oc_string(device->serialnumber), @@ -1119,21 +1015,21 @@ get_InfoOnOff_2(oc_request_t *request, oc_interface_mask_t interfaces, oc_rep_i_set_text_string(root, 9, mystring); } // resource types - if ((strncmp(m, "rt", m_len) == 0) | + if ((strncmp(m, "rt", m_len) == 0) | (strncmp(m, "*", m_len) == 0) ) { - oc_rep_set_text_string(root, rt, "urn:knx:dpa.417.51"); + oc_rep_set_text_string(root, rt, "urn:knx:dpa.417.51"); } // interfaces - if ((strncmp(m, "if", m_len) == 0) | + if ((strncmp(m, "if", m_len) == 0) | (strncmp(m, "*", m_len) == 0) ) { oc_rep_set_text_string(root, if, "if.s"); } - if ((strncmp(m, "dpt", m_len) == 0) | + if ((strncmp(m, "dpt", m_len) == 0) | (strncmp(m, "*", m_len) == 0) ) { - oc_rep_set_text_string(root, dpt, oc_string(request->resource->dpt)); + oc_rep_set_text_string(root, dpt, oc_string(request->resource->dpt)); } // ga - if ((strncmp(m, "ga", m_len) == 0) | + if ((strncmp(m, "ga", m_len) == 0) | (strncmp(m, "*", m_len) == 0) ) { int index = oc_core_find_group_object_table_url(oc_string(request->resource->uri)); if (index > -1) { @@ -1143,7 +1039,7 @@ get_InfoOnOff_2(oc_request_t *request, oc_interface_mask_t interfaces, } } } - if ((strncmp(m, "desc", m_len) == 0) | + if ((strncmp(m, "desc", m_len) == 0) | (strncmp(m, "*", m_len) == 0) ) { oc_rep_set_text_string(root, desc, "Feedback 2"); } @@ -1155,11 +1051,11 @@ get_InfoOnOff_2(oc_request_t *request, oc_interface_mask_t interfaces, } oc_send_cbor_response(request, OC_STATUS_OK); return; - } - + } oc_rep_begin_root_object(); oc_rep_i_set_boolean(root, 1, g_InfoOnOff_2); - oc_rep_end_root_object(); + oc_rep_end_root_object(); + if (g_err) { error_state = true; } @@ -1219,7 +1115,7 @@ get_OnOff_3(oc_request_t *request, oc_interface_mask_t interfaces, oc_rep_begin_root_object(); while (oc_iterate_query(request, &m_key, &m_key_len, &m, &m_len) != -1) { // unique identifier - if ((strncmp(m, "id", m_len) == 0) | + if ((strncmp(m, "id", m_len) == 0) | (strncmp(m, "*", m_len) == 0) ) { char mystring[100]; snprintf(mystring,99,"urn:knx:sn:%s%s",oc_string(device->serialnumber), @@ -1227,21 +1123,21 @@ get_OnOff_3(oc_request_t *request, oc_interface_mask_t interfaces, oc_rep_i_set_text_string(root, 9, mystring); } // resource types - if ((strncmp(m, "rt", m_len) == 0) | + if ((strncmp(m, "rt", m_len) == 0) | (strncmp(m, "*", m_len) == 0) ) { - oc_rep_set_text_string(root, rt, "urn:knx:dpa.417.61"); + oc_rep_set_text_string(root, rt, "urn:knx:dpa.417.61"); } // interfaces - if ((strncmp(m, "if", m_len) == 0) | + if ((strncmp(m, "if", m_len) == 0) | (strncmp(m, "*", m_len) == 0) ) { oc_rep_set_text_string(root, if, "if.a"); } - if ((strncmp(m, "dpt", m_len) == 0) | + if ((strncmp(m, "dpt", m_len) == 0) | (strncmp(m, "*", m_len) == 0) ) { - oc_rep_set_text_string(root, dpt, oc_string(request->resource->dpt)); + oc_rep_set_text_string(root, dpt, oc_string(request->resource->dpt)); } // ga - if ((strncmp(m, "ga", m_len) == 0) | + if ((strncmp(m, "ga", m_len) == 0) | (strncmp(m, "*", m_len) == 0) ) { int index = oc_core_find_group_object_table_url(oc_string(request->resource->uri)); if (index > -1) { @@ -1251,7 +1147,7 @@ get_OnOff_3(oc_request_t *request, oc_interface_mask_t interfaces, } } } - if ((strncmp(m, "desc", m_len) == 0) | + if ((strncmp(m, "desc", m_len) == 0) | (strncmp(m, "*", m_len) == 0) ) { oc_rep_set_text_string(root, desc, "On/Off switch 3"); } @@ -1263,11 +1159,11 @@ get_OnOff_3(oc_request_t *request, oc_interface_mask_t interfaces, } oc_send_cbor_response(request, OC_STATUS_OK); return; - } - + } oc_rep_begin_root_object(); oc_rep_i_set_boolean(root, 1, g_OnOff_3); - oc_rep_end_root_object(); + oc_rep_end_root_object(); + if (g_err) { error_state = true; } @@ -1303,41 +1199,43 @@ put_OnOff_3(oc_request_t *request, oc_interface_mask_t interfaces, bool error_state = true; PRINT("-- Begin put_OnOff_3:\n"); - oc_rep_t *req = NULL; + oc_rep_t *rep = NULL; /* handle the different requests e.g. via s-mode or normal CoAP call*/ if (oc_is_redirected_request(request)) { PRINT(" redirected request..\n"); } - req = request->request_payload; + rep = request->request_payload; /* loop over all the entries in the request */ - while (req != NULL) { + /* handle the type of payload correctly. */ + error_state = true; + while (rep != NULL) { /* handle the type of payload correctly. */ - if ((req->iname == 1) && (req->type == OC_REP_BOOL)) { - PRINT(" put_OnOff_3 received : %d\n", req->value.boolean); - g_OnOff_3 = req->value.boolean; + if ((rep->iname == 1) && (rep->type == OC_REP_BOOL)) { + PRINT(" put_OnOff_3 received : %d\n", rep->value.boolean); + g_OnOff_3 = rep->value.boolean; error_state = false; - if (error_state == false){ - /* input is valid, so handle the response */ - oc_send_cbor_response(request, OC_STATUS_CHANGED); + break; + } + } + + if (error_state == false){ + oc_send_cbor_response(request, OC_STATUS_CHANGED); /* update the status information of InfoOnOff_3*/ if (g_fault_OnOff_3 == false) { PRINT(" No Fault update feedback to %d'\n", g_OnOff_3); /* no fault hence update the feedback with the current state of the actuator */ - g_OnOff_3 = g_OnOff_3; + g_InfoOnOff_3 = g_OnOff_3; } else { /* fault hence update the feedback with "false" */ PRINT(" Fault'\n"); - g_OnOff_3 = false; + g_InfoOnOff_3 = false; } /* send the status information InfoOnOff_3 to '/p/o_6_6' with flag 'w' */ PRINT(" Send status to '/p/o_6_6' with flag: 'w'\n"); - oc_do_s_mode_with_scope(5, CH3_URL_INFOONOFF_3, "w"); - do_put_cb(URL_ONOFF_3); - PRINT("-- End put_OnOff_3\n"); - return; - } - } - req = req->next; + oc_do_s_mode_with_scope(5, URL_INFOONOFF_3, "w"); + do_put_cb(URL_ONOFF_3); + PRINT("-- End put_OnOff_3\n"); + return; } /* request data was not recognized, so it was a bad request */ oc_send_response(request, OC_STATUS_BAD_REQUEST); @@ -1389,7 +1287,7 @@ get_InfoOnOff_3(oc_request_t *request, oc_interface_mask_t interfaces, oc_rep_begin_root_object(); while (oc_iterate_query(request, &m_key, &m_key_len, &m, &m_len) != -1) { // unique identifier - if ((strncmp(m, "id", m_len) == 0) | + if ((strncmp(m, "id", m_len) == 0) | (strncmp(m, "*", m_len) == 0) ) { char mystring[100]; snprintf(mystring,99,"urn:knx:sn:%s%s",oc_string(device->serialnumber), @@ -1397,21 +1295,21 @@ get_InfoOnOff_3(oc_request_t *request, oc_interface_mask_t interfaces, oc_rep_i_set_text_string(root, 9, mystring); } // resource types - if ((strncmp(m, "rt", m_len) == 0) | + if ((strncmp(m, "rt", m_len) == 0) | (strncmp(m, "*", m_len) == 0) ) { - oc_rep_set_text_string(root, rt, "urn:knx:dpa.417.51"); + oc_rep_set_text_string(root, rt, "urn:knx:dpa.417.51"); } // interfaces - if ((strncmp(m, "if", m_len) == 0) | + if ((strncmp(m, "if", m_len) == 0) | (strncmp(m, "*", m_len) == 0) ) { oc_rep_set_text_string(root, if, "if.s"); } - if ((strncmp(m, "dpt", m_len) == 0) | + if ((strncmp(m, "dpt", m_len) == 0) | (strncmp(m, "*", m_len) == 0) ) { - oc_rep_set_text_string(root, dpt, oc_string(request->resource->dpt)); + oc_rep_set_text_string(root, dpt, oc_string(request->resource->dpt)); } // ga - if ((strncmp(m, "ga", m_len) == 0) | + if ((strncmp(m, "ga", m_len) == 0) | (strncmp(m, "*", m_len) == 0) ) { int index = oc_core_find_group_object_table_url(oc_string(request->resource->uri)); if (index > -1) { @@ -1421,7 +1319,7 @@ get_InfoOnOff_3(oc_request_t *request, oc_interface_mask_t interfaces, } } } - if ((strncmp(m, "desc", m_len) == 0) | + if ((strncmp(m, "desc", m_len) == 0) | (strncmp(m, "*", m_len) == 0) ) { oc_rep_set_text_string(root, desc, "Feedback 3"); } @@ -1433,11 +1331,11 @@ get_InfoOnOff_3(oc_request_t *request, oc_interface_mask_t interfaces, } oc_send_cbor_response(request, OC_STATUS_OK); return; - } - + } oc_rep_begin_root_object(); oc_rep_i_set_boolean(root, 1, g_InfoOnOff_3); - oc_rep_end_root_object(); + oc_rep_end_root_object(); + if (g_err) { error_state = true; } @@ -1497,7 +1395,7 @@ get_OnOff_4(oc_request_t *request, oc_interface_mask_t interfaces, oc_rep_begin_root_object(); while (oc_iterate_query(request, &m_key, &m_key_len, &m, &m_len) != -1) { // unique identifier - if ((strncmp(m, "id", m_len) == 0) | + if ((strncmp(m, "id", m_len) == 0) | (strncmp(m, "*", m_len) == 0) ) { char mystring[100]; snprintf(mystring,99,"urn:knx:sn:%s%s",oc_string(device->serialnumber), @@ -1505,21 +1403,21 @@ get_OnOff_4(oc_request_t *request, oc_interface_mask_t interfaces, oc_rep_i_set_text_string(root, 9, mystring); } // resource types - if ((strncmp(m, "rt", m_len) == 0) | + if ((strncmp(m, "rt", m_len) == 0) | (strncmp(m, "*", m_len) == 0) ) { - oc_rep_set_text_string(root, rt, "urn:knx:dpa.417.61"); + oc_rep_set_text_string(root, rt, "urn:knx:dpa.417.61"); } // interfaces - if ((strncmp(m, "if", m_len) == 0) | + if ((strncmp(m, "if", m_len) == 0) | (strncmp(m, "*", m_len) == 0) ) { oc_rep_set_text_string(root, if, "if.a"); } - if ((strncmp(m, "dpt", m_len) == 0) | + if ((strncmp(m, "dpt", m_len) == 0) | (strncmp(m, "*", m_len) == 0) ) { - oc_rep_set_text_string(root, dpt, oc_string(request->resource->dpt)); + oc_rep_set_text_string(root, dpt, oc_string(request->resource->dpt)); } // ga - if ((strncmp(m, "ga", m_len) == 0) | + if ((strncmp(m, "ga", m_len) == 0) | (strncmp(m, "*", m_len) == 0) ) { int index = oc_core_find_group_object_table_url(oc_string(request->resource->uri)); if (index > -1) { @@ -1529,7 +1427,7 @@ get_OnOff_4(oc_request_t *request, oc_interface_mask_t interfaces, } } } - if ((strncmp(m, "desc", m_len) == 0) | + if ((strncmp(m, "desc", m_len) == 0) | (strncmp(m, "*", m_len) == 0) ) { oc_rep_set_text_string(root, desc, "On/Off switch 4"); } @@ -1541,11 +1439,11 @@ get_OnOff_4(oc_request_t *request, oc_interface_mask_t interfaces, } oc_send_cbor_response(request, OC_STATUS_OK); return; - } - + } oc_rep_begin_root_object(); oc_rep_i_set_boolean(root, 1, g_OnOff_4); - oc_rep_end_root_object(); + oc_rep_end_root_object(); + if (g_err) { error_state = true; } @@ -1581,41 +1479,43 @@ put_OnOff_4(oc_request_t *request, oc_interface_mask_t interfaces, bool error_state = true; PRINT("-- Begin put_OnOff_4:\n"); - oc_rep_t *req = NULL; + oc_rep_t *rep = NULL; /* handle the different requests e.g. via s-mode or normal CoAP call*/ if (oc_is_redirected_request(request)) { PRINT(" redirected request..\n"); } - req = request->request_payload; + rep = request->request_payload; /* loop over all the entries in the request */ - while (req != NULL) { + /* handle the type of payload correctly. */ + error_state = true; + while (rep != NULL) { /* handle the type of payload correctly. */ - if ((req->iname == 1) && (req->type == OC_REP_BOOL)) { - PRINT(" put_OnOff_4 received : %d\n", req->value.boolean); - g_OnOff_4 = req->value.boolean; + if ((rep->iname == 1) && (rep->type == OC_REP_BOOL)) { + PRINT(" put_OnOff_4 received : %d\n", rep->value.boolean); + g_OnOff_4 = rep->value.boolean; error_state = false; - if (error_state == false){ - /* input is valid, so handle the response */ - oc_send_cbor_response(request, OC_STATUS_CHANGED); + break; + } + } + + if (error_state == false){ + oc_send_cbor_response(request, OC_STATUS_CHANGED); /* update the status information of InfoOnOff_4*/ if (g_fault_OnOff_4 == false) { PRINT(" No Fault update feedback to %d'\n", g_OnOff_4); /* no fault hence update the feedback with the current state of the actuator */ - g_OnOff_4 = g_OnOff_4; + g_InfoOnOff_4 = g_OnOff_4; } else { /* fault hence update the feedback with "false" */ PRINT(" Fault'\n"); - g_OnOff_4 = false; + g_InfoOnOff_4 = false; } /* send the status information InfoOnOff_4 to '/p/o_8_8' with flag 'w' */ PRINT(" Send status to '/p/o_8_8' with flag: 'w'\n"); - oc_do_s_mode_with_scope(5, CH4_URL_INFOONOFF_4, "w"); - do_put_cb(URL_ONOFF_4); - PRINT("-- End put_OnOff_4\n"); - return; - } - } - req = req->next; + oc_do_s_mode_with_scope(5, URL_INFOONOFF_4, "w"); + do_put_cb(URL_ONOFF_4); + PRINT("-- End put_OnOff_4\n"); + return; } /* request data was not recognized, so it was a bad request */ oc_send_response(request, OC_STATUS_BAD_REQUEST); @@ -1667,7 +1567,7 @@ get_InfoOnOff_4(oc_request_t *request, oc_interface_mask_t interfaces, oc_rep_begin_root_object(); while (oc_iterate_query(request, &m_key, &m_key_len, &m, &m_len) != -1) { // unique identifier - if ((strncmp(m, "id", m_len) == 0) | + if ((strncmp(m, "id", m_len) == 0) | (strncmp(m, "*", m_len) == 0) ) { char mystring[100]; snprintf(mystring,99,"urn:knx:sn:%s%s",oc_string(device->serialnumber), @@ -1675,21 +1575,21 @@ get_InfoOnOff_4(oc_request_t *request, oc_interface_mask_t interfaces, oc_rep_i_set_text_string(root, 9, mystring); } // resource types - if ((strncmp(m, "rt", m_len) == 0) | + if ((strncmp(m, "rt", m_len) == 0) | (strncmp(m, "*", m_len) == 0) ) { - oc_rep_set_text_string(root, rt, "urn:knx:dpa.417.51"); + oc_rep_set_text_string(root, rt, "urn:knx:dpa.417.51"); } // interfaces - if ((strncmp(m, "if", m_len) == 0) | + if ((strncmp(m, "if", m_len) == 0) | (strncmp(m, "*", m_len) == 0) ) { oc_rep_set_text_string(root, if, "if.s"); } - if ((strncmp(m, "dpt", m_len) == 0) | + if ((strncmp(m, "dpt", m_len) == 0) | (strncmp(m, "*", m_len) == 0) ) { - oc_rep_set_text_string(root, dpt, oc_string(request->resource->dpt)); + oc_rep_set_text_string(root, dpt, oc_string(request->resource->dpt)); } // ga - if ((strncmp(m, "ga", m_len) == 0) | + if ((strncmp(m, "ga", m_len) == 0) | (strncmp(m, "*", m_len) == 0) ) { int index = oc_core_find_group_object_table_url(oc_string(request->resource->uri)); if (index > -1) { @@ -1699,7 +1599,7 @@ get_InfoOnOff_4(oc_request_t *request, oc_interface_mask_t interfaces, } } } - if ((strncmp(m, "desc", m_len) == 0) | + if ((strncmp(m, "desc", m_len) == 0) | (strncmp(m, "*", m_len) == 0) ) { oc_rep_set_text_string(root, desc, "Feedback 4"); } @@ -1711,11 +1611,11 @@ get_InfoOnOff_4(oc_request_t *request, oc_interface_mask_t interfaces, } oc_send_cbor_response(request, OC_STATUS_OK); return; - } - + } oc_rep_begin_root_object(); oc_rep_i_set_boolean(root, 1, g_InfoOnOff_4); - oc_rep_end_root_object(); + oc_rep_end_root_object(); + if (g_err) { error_state = true; } @@ -2012,15 +1912,18 @@ initialize_variables(void) { /* initialize global variables for resources */ /* if wanted read them from persistent storage */ - g_OnOff_1 = false; /**< global variable for OnOff_1 */ - g_InfoOnOff_1 = false; /**< global variable for InfoOnOff_1 */ - g_OnOff_2 = false; /**< global variable for OnOff_2 */ - g_InfoOnOff_2 = false; /**< global variable for InfoOnOff_2 */ - g_OnOff_3 = false; /**< global variable for OnOff_3 */ - g_InfoOnOff_3 = false; /**< global variable for InfoOnOff_3 */ - g_OnOff_4 = false; /**< global variable for OnOff_4 */ - g_InfoOnOff_4 = false; /**< global variable for InfoOnOff_4 */ + //g_OnOff_1 = false; /**< global variable for OnOff_1 */ + //g_InfoOnOff_1 = false; /**< global variable for InfoOnOff_1 */ + //g_OnOff_2 = false; /**< global variable for OnOff_2 */ + //g_InfoOnOff_2 = false; /**< global variable for InfoOnOff_2 */ + //g_OnOff_3 = false; /**< global variable for OnOff_3 */ + //g_InfoOnOff_3 = false; /**< global variable for InfoOnOff_3 */ + //g_OnOff_4 = false; /**< global variable for OnOff_4 */ + //g_InfoOnOff_4 = false; /**< global variable for InfoOnOff_4 */ /* parameter variables */ + uint8_t oc_storage_buf[32]; + long ret; + bool err; } diff --git a/knx_iot_virtual_sa.cpp b/knx_iot_virtual_sa.cpp index 7312894..8ffe8b2 100644 --- a/knx_iot_virtual_sa.cpp +++ b/knx_iot_virtual_sa.cpp @@ -16,7 +16,7 @@ -=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-= */ -// 2023-06-29 11:52:17.768606 +// 2023-07-31 10:49:06.406279 // For compilers that support precompilation, includes "wx/wx.h". #include @@ -141,7 +141,7 @@ class MyFrame : public wxFrame void OnFault_ONOFF_1(wxCommandEvent& event); void OnFault_ONOFF_2(wxCommandEvent& event); void OnFault_ONOFF_3(wxCommandEvent& event); - void OnFault_ONOFF_4(wxCommandEvent& event); + void OnFault_ONOFF_4(wxCommandEvent& event); void OnPressed_InfoOnOff_1(wxCommandEvent& event); void OnPressed_InfoOnOff_2(wxCommandEvent& event); void OnPressed_InfoOnOff_3(wxCommandEvent& event); @@ -172,21 +172,21 @@ class MyFrame : public wxFrame wxTextCtrl* m_hostname_text; // text control for host name wxTextCtrl* m_secured_text; // text secure/not secure //DP_ID_ONOFF_1 bool - wxCheckBox* m_ONOFF_1 ; // OnOff_1 if.a + wxCheckBox* m_ONOFF_1 ; // OnOff_1 if.a //DP_ID_INFOONOFF_1 bool - wxButton* m_INFOONOFF_1; // InfoOnOff_1 if.s + wxButton* m_INFOONOFF_1; // InfoOnOff_1 if.s //DP_ID_ONOFF_2 bool - wxCheckBox* m_ONOFF_2 ; // OnOff_2 if.a + wxCheckBox* m_ONOFF_2 ; // OnOff_2 if.a //DP_ID_INFOONOFF_2 bool - wxButton* m_INFOONOFF_2; // InfoOnOff_2 if.s + wxButton* m_INFOONOFF_2; // InfoOnOff_2 if.s //DP_ID_ONOFF_3 bool - wxCheckBox* m_ONOFF_3 ; // OnOff_3 if.a + wxCheckBox* m_ONOFF_3 ; // OnOff_3 if.a //DP_ID_INFOONOFF_3 bool - wxButton* m_INFOONOFF_3; // InfoOnOff_3 if.s + wxButton* m_INFOONOFF_3; // InfoOnOff_3 if.s //DP_ID_ONOFF_4 bool - wxCheckBox* m_ONOFF_4 ; // OnOff_4 if.a + wxCheckBox* m_ONOFF_4 ; // OnOff_4 if.a //DP_ID_INFOONOFF_4 bool - wxButton* m_INFOONOFF_4; // InfoOnOff_4 if.s + wxButton* m_INFOONOFF_4; // InfoOnOff_4 if.s wxCheckBox* m_fault_ONOFF_1 ; // OnOff_1 if.a wxCheckBox* m_fault_ONOFF_2 ; // OnOff_2 if.a wxCheckBox* m_fault_ONOFF_3 ; // OnOff_3 if.a @@ -291,7 +291,7 @@ MyFrame::MyFrame(char* str_serial_number) column = (index % max_dp_count) - column_offset; //DP_ID_ONOFF_1 m_ONOFF_1 = new wxCheckBox(this, DP_ID_ONOFF_1, _T("OnOff_1 ('/p/o_1_1')"), wxPoint(10 + column*x_width, 10 + (x_height*row)), wxSize(x_width, x_height), 0); - m_ONOFF_1->Enable(false); + m_ONOFF_1->Enable(false); index = 2-1; row = 1 -1; column = (index % max_dp_count) - column_offset; @@ -299,13 +299,13 @@ MyFrame::MyFrame(char* str_serial_number) // if.s ==> sensor == possible to change value in UI m_INFOONOFF_1 = new wxButton(this, DP_ID_INFOONOFF_1, _T("InfoOnOff_1 ('/p/o_2_2')"), wxPoint(10 + column*x_width, 10 + (x_height*row)), wxSize(x_width, x_height), 0); m_INFOONOFF_1->Bind(wxEVT_BUTTON, &MyFrame::OnPressed_InfoOnOff_1, this); - m_INFOONOFF_1->Enable(false); + m_INFOONOFF_1->Enable(false); index = 3-1; row = 2 -1; column = (index % max_dp_count) - column_offset; //DP_ID_ONOFF_2 m_ONOFF_2 = new wxCheckBox(this, DP_ID_ONOFF_2, _T("OnOff_2 ('/p/o_3_3')"), wxPoint(10 + column*x_width, 10 + (x_height*row)), wxSize(x_width, x_height), 0); - m_ONOFF_2->Enable(false); + m_ONOFF_2->Enable(false); index = 4-1; row = 2 -1; column = (index % max_dp_count) - column_offset; @@ -313,13 +313,13 @@ MyFrame::MyFrame(char* str_serial_number) // if.s ==> sensor == possible to change value in UI m_INFOONOFF_2 = new wxButton(this, DP_ID_INFOONOFF_2, _T("InfoOnOff_2 ('/p/o_4_4')"), wxPoint(10 + column*x_width, 10 + (x_height*row)), wxSize(x_width, x_height), 0); m_INFOONOFF_2->Bind(wxEVT_BUTTON, &MyFrame::OnPressed_InfoOnOff_2, this); - m_INFOONOFF_2->Enable(false); + m_INFOONOFF_2->Enable(false); index = 5-1; row = 3 -1; column = (index % max_dp_count) - column_offset; //DP_ID_ONOFF_3 m_ONOFF_3 = new wxCheckBox(this, DP_ID_ONOFF_3, _T("OnOff_3 ('/p/o_5_5')"), wxPoint(10 + column*x_width, 10 + (x_height*row)), wxSize(x_width, x_height), 0); - m_ONOFF_3->Enable(false); + m_ONOFF_3->Enable(false); index = 6-1; row = 3 -1; column = (index % max_dp_count) - column_offset; @@ -327,13 +327,13 @@ MyFrame::MyFrame(char* str_serial_number) // if.s ==> sensor == possible to change value in UI m_INFOONOFF_3 = new wxButton(this, DP_ID_INFOONOFF_3, _T("InfoOnOff_3 ('/p/o_6_6')"), wxPoint(10 + column*x_width, 10 + (x_height*row)), wxSize(x_width, x_height), 0); m_INFOONOFF_3->Bind(wxEVT_BUTTON, &MyFrame::OnPressed_InfoOnOff_3, this); - m_INFOONOFF_3->Enable(false); + m_INFOONOFF_3->Enable(false); index = 7-1; row = 4 -1; column = (index % max_dp_count) - column_offset; //DP_ID_ONOFF_4 m_ONOFF_4 = new wxCheckBox(this, DP_ID_ONOFF_4, _T("OnOff_4 ('/p/o_7_7')"), wxPoint(10 + column*x_width, 10 + (x_height*row)), wxSize(x_width, x_height), 0); - m_ONOFF_4->Enable(false); + m_ONOFF_4->Enable(false); index = 8-1; row = 4 -1; column = (index % max_dp_count) - column_offset; @@ -341,7 +341,7 @@ MyFrame::MyFrame(char* str_serial_number) // if.s ==> sensor == possible to change value in UI m_INFOONOFF_4 = new wxButton(this, DP_ID_INFOONOFF_4, _T("InfoOnOff_4 ('/p/o_8_8')"), wxPoint(10 + column*x_width, 10 + (x_height*row)), wxSize(x_width, x_height), 0); m_INFOONOFF_4->Bind(wxEVT_BUTTON, &MyFrame::OnPressed_InfoOnOff_4, this); - m_INFOONOFF_4->Enable(false); + m_INFOONOFF_4->Enable(false); m_fault_ONOFF_1 = new wxCheckBox(this, DP_FAULT_ID_ONOFF_1, _T("Fault OnOff_1"), wxPoint(20 + (2* x_width), 10 + ((1/2 ) * x_height)), wxSize(x_width, x_height), 0); m_fault_ONOFF_1->Bind(wxEVT_CHECKBOX, &MyFrame:: OnFault_ONOFF_1, this); m_fault_ONOFF_2 = new wxCheckBox(this, DP_FAULT_ID_ONOFF_2, _T("Fault OnOff_2"), wxPoint(20 + (2* x_width), 10 + ((3/2 ) * x_height)), wxSize(x_width, x_height), 0); @@ -775,22 +775,12 @@ void MyFrame::OnParameterList(wxCommandEvent& event) sprintf(line, " name: '%s' ", app_get_parameter_name(index)); strcat(text, line); } - if (app_is_bool_url(url)) { - sprintf(line, " value : '%d' ", app_retrieve_bool_variable(url)); - strcat(text, line); - } - if (app_is_int_url(url)) { - sprintf(line, " value : '%d' ", app_retrieve_int_variable(url)); - strcat(text, line); - } - if (app_is_double_url(url)) { - sprintf(line, " value : '%f' ", (float)app_retrieve_double_variable(url)); - strcat(text, line); - } - if (app_is_string_url(url)) { - sprintf(line, " value : '%s' ", app_retrieve_string_variable(url)); - strcat(text, line); - } + + + //if (app_is_string_url(url)) { + // sprintf(line, " value : '%s' ", app_retrieve_string_variable(url)); + // strcat(text, line); + //} index++; url = app_get_parameter_url(index); } @@ -944,9 +934,9 @@ void MyFrame::OnAbout(wxCommandEvent& event) strcat(text,"\n"); strcat(text,"manufactorer : cascoda\n"); strcat(text,"model : KNX virtual - SA\n"); - strcat(text,"hardware type : Windows\n"); + strcat(text,"hardware type : LW0001\n"); strcat(text,"hardware version : [0, 1, 3]\n"); - strcat(text,"firmware version : [0, 1, 8]\n\n"); + strcat(text,"firmware version : [0, 1, 9]\n\n"); strcat(text, "data points:\n"); strcat(text,"url:/p/o_1_1 rt:urn:knx:dpa.417.61 if:if.a inst:1 name:OnOff_1\n"); @@ -961,7 +951,7 @@ void MyFrame::OnAbout(wxCommandEvent& event) strcat(text, "(c) Cascoda Ltd\n"); strcat(text, "(c) KNX.org\n"); - strcat(text, "2023-06-29 11:52:17.768606"); + strcat(text, "2023-07-31 10:49:06.406279"); CustomDialog("About", text); } @@ -1017,14 +1007,14 @@ void MyFrame::OnTimer(wxTimerEvent& event) void MyFrame::updateInfoCheckBoxes() { bool p; - p = app_retrieve_bool_variable("/p/o_1_1"); // set toggle of OnOff_1 - m_ONOFF_1->SetValue(p); - p = app_retrieve_bool_variable("/p/o_3_3"); // set toggle of OnOff_2 - m_ONOFF_2->SetValue(p); - p = app_retrieve_bool_variable("/p/o_5_5"); // set toggle of OnOff_3 - m_ONOFF_3->SetValue(p); - p = app_retrieve_bool_variable("/p/o_7_7"); // set toggle of OnOff_4 - m_ONOFF_4->SetValue(p); + p = app_retrieve_bool_variable(URL_ONOFF_1); + m_ONOFF_1->SetValue(p); + p = app_retrieve_bool_variable(URL_ONOFF_2); + m_ONOFF_2->SetValue(p); + p = app_retrieve_bool_variable(URL_ONOFF_3); + m_ONOFF_3->SetValue(p); + p = app_retrieve_bool_variable(URL_ONOFF_4); + m_ONOFF_4->SetValue(p); } @@ -1174,41 +1164,34 @@ void MyFrame::updateInfoButtons() char text[200]; bool p; int p_int; + float f; double d; - p = app_retrieve_bool_variable("/p/o_1_1"); // set button text of OnOff_1 - strcpy(text, "OnOff_1 ('/p/o_1_1')"); + p = app_retrieve_bool_variable(URL_ONOFF_1); strcpy(text, "OnOff_1 ('/p/o_1_1')"); this->bool2text(p, text); - m_ONOFF_1->SetLabel(text); - p = app_retrieve_bool_variable("/p/o_3_3"); // set button text of OnOff_2 - strcpy(text, "OnOff_2 ('/p/o_3_3')"); + m_ONOFF_1->SetLabel(text); + p = app_retrieve_bool_variable(URL_INFOONOFF_1); strcpy(text, "InfoOnOff_1 ('/p/o_2_2')"); this->bool2text(p, text); - m_ONOFF_2->SetLabel(text); - p = app_retrieve_bool_variable("/p/o_5_5"); // set button text of OnOff_3 - strcpy(text, "OnOff_3 ('/p/o_5_5')"); + m_INFOONOFF_1->SetLabel(text); + p = app_retrieve_bool_variable(URL_ONOFF_2); strcpy(text, "OnOff_2 ('/p/o_3_3')"); this->bool2text(p, text); - m_ONOFF_3->SetLabel(text); - p = app_retrieve_bool_variable("/p/o_7_7"); // set button text of OnOff_4 - strcpy(text, "OnOff_4 ('/p/o_7_7')"); + m_ONOFF_2->SetLabel(text); + p = app_retrieve_bool_variable(URL_INFOONOFF_2); strcpy(text, "InfoOnOff_2 ('/p/o_4_4')"); this->bool2text(p, text); - m_ONOFF_4->SetLabel(text); - p = app_retrieve_bool_variable("/p/o_2_2"); // set button text of InfoOnOff_1 - strcpy(text, "InfoOnOff_1 ('/p/o_2_2')"); + m_INFOONOFF_2->SetLabel(text); + p = app_retrieve_bool_variable(URL_ONOFF_3); strcpy(text, "OnOff_3 ('/p/o_5_5')"); this->bool2text(p, text); - m_INFOONOFF_1->SetLabel(text); - p = app_retrieve_bool_variable("/p/o_4_4"); // set button text of InfoOnOff_2 - strcpy(text, "InfoOnOff_2 ('/p/o_4_4')"); + m_ONOFF_3->SetLabel(text); + p = app_retrieve_bool_variable(URL_INFOONOFF_3); strcpy(text, "InfoOnOff_3 ('/p/o_6_6')"); this->bool2text(p, text); - m_INFOONOFF_2->SetLabel(text); - p = app_retrieve_bool_variable("/p/o_6_6"); // set button text of InfoOnOff_3 - strcpy(text, "InfoOnOff_3 ('/p/o_6_6')"); + m_INFOONOFF_3->SetLabel(text); + p = app_retrieve_bool_variable(URL_ONOFF_4); strcpy(text, "OnOff_4 ('/p/o_7_7')"); this->bool2text(p, text); - m_INFOONOFF_3->SetLabel(text); - p = app_retrieve_bool_variable("/p/o_8_8"); // set button text of InfoOnOff_4 - strcpy(text, "InfoOnOff_4 ('/p/o_8_8')"); + m_ONOFF_4->SetLabel(text); + p = app_retrieve_bool_variable(URL_INFOONOFF_4); strcpy(text, "InfoOnOff_4 ('/p/o_8_8')"); this->bool2text(p, text); - m_INFOONOFF_4->SetLabel(text); + m_INFOONOFF_4->SetLabel(text); -} +} void MyFrame::OnPressed_InfoOnOff_1(wxCommandEvent& event) { char url[] = "/p/o_2_2"; @@ -1225,7 +1208,7 @@ void MyFrame::OnPressed_InfoOnOff_1(wxCommandEvent& event) oc_do_s_mode_with_scope(5, url, "w"); sprintf(my_text, "InfoOnOff_1 ('%s') pressed: %d", url, (int)p); SetStatusText(my_text); -} +} void MyFrame::OnPressed_InfoOnOff_2(wxCommandEvent& event) { char url[] = "/p/o_4_4"; @@ -1242,7 +1225,7 @@ void MyFrame::OnPressed_InfoOnOff_2(wxCommandEvent& event) oc_do_s_mode_with_scope(5, url, "w"); sprintf(my_text, "InfoOnOff_2 ('%s') pressed: %d", url, (int)p); SetStatusText(my_text); -} +} void MyFrame::OnPressed_InfoOnOff_3(wxCommandEvent& event) { char url[] = "/p/o_6_6"; @@ -1259,7 +1242,7 @@ void MyFrame::OnPressed_InfoOnOff_3(wxCommandEvent& event) oc_do_s_mode_with_scope(5, url, "w"); sprintf(my_text, "InfoOnOff_3 ('%s') pressed: %d", url, (int)p); SetStatusText(my_text); -} +} void MyFrame::OnPressed_InfoOnOff_4(wxCommandEvent& event) { char url[] = "/p/o_8_8"; @@ -1276,7 +1259,7 @@ void MyFrame::OnPressed_InfoOnOff_4(wxCommandEvent& event) oc_do_s_mode_with_scope(5, url, "w"); sprintf(my_text, "InfoOnOff_4 ('%s') pressed: %d", url, (int)p); SetStatusText(my_text); -} +} void MyFrame::OnFault_ONOFF_1(wxCommandEvent& event) { char url[] = "/p/o_1_1"; @@ -1332,7 +1315,7 @@ void MyFrame::OnFault_ONOFF_4(wxCommandEvent& event) sprintf(my_text, "Actuator OnOff_4 (/p/o_7_7) Fault: %d to: /p/o_8_8", (int)p1); SetStatusText(my_text); -} +} diff --git a/knx_iot_virtual_sa.h b/knx_iot_virtual_sa.h index 57485d7..db4b764 100644 --- a/knx_iot_virtual_sa.h +++ b/knx_iot_virtual_sa.h @@ -45,6 +45,8 @@ extern "C" { #define URL_ONOFF_4 "/p/o_7_7" // define URL OnOff_4 for /p/o_7_7 #define URL_INFOONOFF_4 "/p/o_8_8" // define URL InfoOnOff_4 for /p/o_8_8 + + /** * Callback invoked by the stack when a successfull put is done * @@ -85,123 +87,32 @@ int app_initialize_stack(); */ int app_set_serial_number(char* serial_number); -/** - * @brief checks if the url depicts an boolean - * - * @param url the url to check - * @return true: url conveys a boolean - */ -bool app_is_bool_url(char* url); +// Getters/Setters for bool /** - * @brief retrieve the boolean variable of the url/data point - * the caller needs to know if the resource/data point is conveying a boolean - * "/p/o_1_1" of OnOff_1 - * "/p/o_2_2" of InfoOnOff_1 - * "/p/o_3_3" of OnOff_2 - * "/p/o_4_4" of InfoOnOff_2 - * "/p/o_5_5" of OnOff_3 - * "/p/o_6_6" of InfoOnOff_3 - * "/p/o_7_7" of OnOff_4 - * "/p/o_8_8" of InfoOnOff_4 + * @brief Checks if the url depicts a bool * - * @param url the url of the resource/data point - * @return true value is true - * @return false value is false or error. + * @param url the url + * @return true: url conveys a bool */ -bool app_retrieve_bool_variable(char* url); +bool app_is_bool_url(char* url); /** - * @brief set the boolean variable that belongs to the url - * The caller needs to know if the resource/data point is conveying a boolean - * "/p/o_1_1" of OnOff_1 - * "/p/o_3_3" of OnOff_2 - * "/p/o_5_5" of OnOff_3 - * "/p/o_7_7" of OnOff_4 + * @brief Set a bool * - * @param url the url of the resource/data point - * @param value the boolean value to be set + * @param url the url for the bool to set + * @param in value to set */ void app_set_bool_variable(char* url, bool value); /** - * @brief checks if the url depicts an int + * @brief Get a bool * - * @param url the url to check - * @return true: url conveys a int - */ -bool app_is_int_url(char* url); - -/** - * @brief retrieve the int variable of the url/data point - * the caller needs to know if the resource/data point is conveying a integer - * - * @param url the url of the resource/data point - * @return the integer value of the global variable - */ -int app_retrieve_int_variable(char* url); - -/** - * @brief set the integer variable that belongs to the url - * The caller needs to know if the resource/data point is conveying a integer - * - * @param url the url of the resource/data point - * @param value the integer value to be set + * @param url the url for the bool to get + * @return boolean variable */ +bool app_retrieve_bool_variable(char *url); -void app_set_int_variable(char* url, int value); - -void app_set_integer_variable(char* url, int value); - -/** - * @brief checks if the url depicts an double - * - * @param url the url to check - * @return true: url conveys a double - */ -bool app_is_double_url(char* url); - -/** - * @brief retrieve the double variable of the url/data point - * the caller needs to know if the resource/data point is conveying a integer - * - * @param url the url of the resource/data point - * @return the double value of the global variable - */ -double app_retrieve_double_variable(char* url); - -/** - * @brief set the double variable that belongs to the url - * The caller needs to know if the resource/data point is conveying a double - * - * @param url the url of the resource/data point - * @param value the double value to be set - */ -void app_set_double_variable(char* url, double value); - -/** - * @brief function to check if the url is represented by a string - * - * @param url the url value is a string - * @return true = url returns a string, false = url is not a string - */ -bool app_is_string_url(char* url); - -/** - * @brief sets the global string variable at the url - * - * @param url the url indicating the global variable - * @param value the string value to be set - */ -void app_set_string_variable(char* url, char* value); - -/** - * @brief retrieve the global string variable at the url - * - * @param url the url indicating the global variable - * @return the value of the variable - */ -char* app_retrieve_string_variable(char* url); /** * @brief checks if the url represents a parameter