From c67078b46f7618f96d02f0b1a702f6b592dc662e Mon Sep 17 00:00:00 2001 From: seojeongmoon <55705552+seojeongmoon@users.noreply.github.com> Date: Mon, 28 Oct 2019 15:37:21 +0100 Subject: [PATCH 01/21] Add "Put" Actuator Data to turn on/off LED --- saul_coap.c | 60 +++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 60 insertions(+) diff --git a/saul_coap.c b/saul_coap.c index 459f71d..3425e16 100644 --- a/saul_coap.c +++ b/saul_coap.c @@ -32,6 +32,7 @@ static ssize_t _saul_dev_handler(coap_pkt_t* pdu, uint8_t *buf, size_t len, void static const coap_resource_t _resources[] = { { "/saul/cnt", COAP_GET, _saul_cnt_handler, NULL }, { "/saul/dev", COAP_POST, _saul_dev_handler, NULL }, + {"/saul/atr", COAP_PUT, _saul_atr_handler, NULL} }; static gcoap_listener_t _listener = { @@ -147,3 +148,62 @@ void saul_coap_init(void) { gcoap_register_listener(&_listener); } + +static ssize_t _saul_atr_handler(coap_pkt_t* pdu, uint8_t *buf, size_t len, void *ctx) +{ + uint8_t type; + + (void)ctx; + + if (pdu->payload_len <= 5) { + char req_payl[6] = { 0 }; + memcpy(req_payl, (char *)pdu->payload, pdu->payload_len); + type = atoi(req_payl); + } + else { + return gcoap_response(pdu, buf, len, COAP_CODE_BAD_REQUEST); + } + + return _atr_type_responder(pdu, buf, len, type); +} + +static ssize_t _atr_type_responder(coap_pkt_t* pdu, uint8_t *buf, size_t len, uint8_t type) +{ + saul_reg_t *dev = saul_reg_find_type(type); + phydat_t res; + phydat_dump(phydat_t *res, type);//phydat.h + int dim; + size_t resp_len; + gcoap_resp_init(pdu, buf, len, COAP_CODE_CONTENT); + coap_opt_add_format(pdu, COAP_FORMAT_TEXT); + resp_len = coap_opt_finish(pdu, COAP_OPT_FINISH_PAYLOAD); + + if (dev == NULL) { + char *err = "device not found"; + if (pdu->payload_len >= strlen(err)) { + memcpy(pdu->payload, err, strlen(err)); + resp_len += gcoap_response(pdu, buf, len, COAP_CODE_404); + return resp_len; + } + else { + return gcoap_response(pdu, buf, len, COAP_CODE_404); + } + } + + dim = saul_reg_write(dev, &res); // &res -as saul_reg_read store location or *res data to write? + if (dim <= 0) { + char *err = "no values found"; + if (pdu->payload_len >= strlen(err)) { + memcpy(pdu->payload, err, strlen(err)); + resp_len += gcoap_response(pdu, buf, len, COAP_CODE_404); + return resp_len; + } + else { + return gcoap_response(pdu, buf, len, COAP_CODE_404); + } + } + + /* write the response buffer with the request device value */ + resp_len += fmt_u16_dec((char *)pdu->payload, res.val[0]); + return resp_len; +} From 92314ad313693c61fe841d2ce532e89ecaf42eaf Mon Sep 17 00:00:00 2001 From: seojeongmoon <55705552+seojeongmoon@users.noreply.github.com> Date: Mon, 28 Oct 2019 16:08:20 +0100 Subject: [PATCH 02/21] Update saul_coap.c --- saul_coap.c | 10 ++++------ 1 file changed, 4 insertions(+), 6 deletions(-) diff --git a/saul_coap.c b/saul_coap.c index 3425e16..d3f4c84 100644 --- a/saul_coap.c +++ b/saul_coap.c @@ -171,7 +171,6 @@ static ssize_t _atr_type_responder(coap_pkt_t* pdu, uint8_t *buf, size_t len, ui { saul_reg_t *dev = saul_reg_find_type(type); phydat_t res; - phydat_dump(phydat_t *res, type);//phydat.h int dim; size_t resp_len; gcoap_resp_init(pdu, buf, len, COAP_CODE_CONTENT); @@ -186,12 +185,12 @@ static ssize_t _atr_type_responder(coap_pkt_t* pdu, uint8_t *buf, size_t len, ui return resp_len; } else { - return gcoap_response(pdu, buf, len, COAP_CODE_404); + phydat_dump(&res, type);//phydat.h + dim = saul_reg_write(dev, &res); // &res -as saul_reg_read store location or *res data to write? + // return gcoap_response(pdu, buf, len, COAP_CODE_404); } } - - dim = saul_reg_write(dev, &res); // &res -as saul_reg_read store location or *res data to write? - if (dim <= 0) { + if (dim <= 0) { char *err = "no values found"; if (pdu->payload_len >= strlen(err)) { memcpy(pdu->payload, err, strlen(err)); @@ -202,7 +201,6 @@ static ssize_t _atr_type_responder(coap_pkt_t* pdu, uint8_t *buf, size_t len, ui return gcoap_response(pdu, buf, len, COAP_CODE_404); } } - /* write the response buffer with the request device value */ resp_len += fmt_u16_dec((char *)pdu->payload, res.val[0]); return resp_len; From 7c9fc115f7ec0569674e233eef5bf78bd16e0568 Mon Sep 17 00:00:00 2001 From: Micha Rosenbaum Date: Mon, 28 Oct 2019 16:48:07 +0100 Subject: [PATCH 03/21] Indent saul_coap.c --- saul_coap.c | 66 ++++++++++++++++++++++++++--------------------------- 1 file changed, 33 insertions(+), 33 deletions(-) diff --git a/saul_coap.c b/saul_coap.c index d3f4c84..fce50e1 100644 --- a/saul_coap.c +++ b/saul_coap.c @@ -32,7 +32,7 @@ static ssize_t _saul_dev_handler(coap_pkt_t* pdu, uint8_t *buf, size_t len, void static const coap_resource_t _resources[] = { { "/saul/cnt", COAP_GET, _saul_cnt_handler, NULL }, { "/saul/dev", COAP_POST, _saul_dev_handler, NULL }, - {"/saul/atr", COAP_PUT, _saul_atr_handler, NULL} + {"/saul/atr", COAP_PUT, _saul_atr_handler, NULL}, }; static gcoap_listener_t _listener = { @@ -83,7 +83,7 @@ static ssize_t _saul_dev_handler(coap_pkt_t* pdu, uint8_t *buf, size_t len, void if (pdu->payload_len >= strlen(payl)) { memcpy(pdu->payload, payl, strlen(payl)); - free(payl); + free(payl); gcoap_response(pdu, buf, len, COAP_CODE_204); return resp_len + strlen(payl); } @@ -91,7 +91,7 @@ static ssize_t _saul_dev_handler(coap_pkt_t* pdu, uint8_t *buf, size_t len, void printf("saul_coap: msg buffer (size: %d) too small" " for payload (size: %d)\n", pdu->payload_len, strlen(payl)); - free(payl); + free(payl); return gcoap_response(pdu, buf, len, COAP_CODE_INTERNAL_SERVER_ERROR); } } @@ -110,22 +110,22 @@ static ssize_t _saul_cnt_handler(coap_pkt_t* pdu, uint8_t *buf, size_t len, void size_t resp_len = coap_opt_finish(pdu, COAP_OPT_FINISH_PAYLOAD); if (!dev) { - payl = make_msg("No devices found"); + payl = make_msg("No devices found"); } else { while (dev) { /* - payl = make_msg("%s%i,%s\n", - payl, - i++, - saul_class_to_str(dev->driver->type), - dev->name); + payl = make_msg("%s%i,%s\n", + payl, + i++, + saul_class_to_str(dev->driver->type), + dev->name); */ i++; dev = dev->next; } - payl = make_msg("%d devices available", i); + payl = make_msg("%d devices available", i); } if (pdu->payload_len >= strlen(payl)) { @@ -163,7 +163,7 @@ static ssize_t _saul_atr_handler(coap_pkt_t* pdu, uint8_t *buf, size_t len, void else { return gcoap_response(pdu, buf, len, COAP_CODE_BAD_REQUEST); } - + return _atr_type_responder(pdu, buf, len, type); } @@ -176,30 +176,30 @@ static ssize_t _atr_type_responder(coap_pkt_t* pdu, uint8_t *buf, size_t len, ui gcoap_resp_init(pdu, buf, len, COAP_CODE_CONTENT); coap_opt_add_format(pdu, COAP_FORMAT_TEXT); resp_len = coap_opt_finish(pdu, COAP_OPT_FINISH_PAYLOAD); - + if (dev == NULL) { - char *err = "device not found"; - if (pdu->payload_len >= strlen(err)) { - memcpy(pdu->payload, err, strlen(err)); - resp_len += gcoap_response(pdu, buf, len, COAP_CODE_404); - return resp_len; - } - else { - phydat_dump(&res, type);//phydat.h - dim = saul_reg_write(dev, &res); // &res -as saul_reg_read store location or *res data to write? - // return gcoap_response(pdu, buf, len, COAP_CODE_404); - } + char *err = "device not found"; + if (pdu->payload_len >= strlen(err)) { + memcpy(pdu->payload, err, strlen(err)); + resp_len += gcoap_response(pdu, buf, len, COAP_CODE_404); + return resp_len; + } + else { + phydat_dump(&res, type);//phydat.h + dim = saul_reg_write(dev, &res); // &res -as saul_reg_read store location or *res data to write? + // return gcoap_response(pdu, buf, len, COAP_CODE_404); + } } - if (dim <= 0) { - char *err = "no values found"; - if (pdu->payload_len >= strlen(err)) { - memcpy(pdu->payload, err, strlen(err)); - resp_len += gcoap_response(pdu, buf, len, COAP_CODE_404); - return resp_len; - } - else { - return gcoap_response(pdu, buf, len, COAP_CODE_404); - } + if (dim <= 0) { + char *err = "no values found"; + if (pdu->payload_len >= strlen(err)) { + memcpy(pdu->payload, err, strlen(err)); + resp_len += gcoap_response(pdu, buf, len, COAP_CODE_404); + return resp_len; + } + else { + return gcoap_response(pdu, buf, len, COAP_CODE_404); + } } /* write the response buffer with the request device value */ resp_len += fmt_u16_dec((char *)pdu->payload, res.val[0]); From 595197aabf7781eb9a95127b9065e33bd7136802 Mon Sep 17 00:00:00 2001 From: seojeongmoon <55705552+seojeongmoon@users.noreply.github.com> Date: Mon, 18 Nov 2019 15:33:41 +0100 Subject: [PATCH 04/21] Update README.md --- README.md | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/README.md b/README.md index 7920822..b1f8404 100644 --- a/README.md +++ b/README.md @@ -45,3 +45,10 @@ Enter shell with board command (Phytec) To distinguish multiple boards using SERIAL number make list-ttys + + +###########TO DO############### + +human readable parameter(input) -> parse it -> phydat +cbor standard format but still parse + From ff1ea4d28c774846214e9087eb12e87d41925dcd Mon Sep 17 00:00:00 2001 From: seojeongmoon <55705552+seojeongmoon@users.noreply.github.com> Date: Mon, 25 Nov 2019 15:20:31 +0100 Subject: [PATCH 05/21] Update saul_coap.c --- saul_coap.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/saul_coap.c b/saul_coap.c index 6412170..5ffa67c 100644 --- a/saul_coap.c +++ b/saul_coap.c @@ -13,7 +13,8 @@ * @file * @brief CoAP endpoint for the SAUL registry * - * @author Micha Rosenbaum + * @author Seojeong Moon + @author Micha Rosenbaum * * @} */ From 1f93d2f0b337f6ea73aba5be132cc9801adbfbd5 Mon Sep 17 00:00:00 2001 From: seojeongmoon <55705552+seojeongmoon@users.noreply.github.com> Date: Mon, 25 Nov 2019 16:15:07 +0100 Subject: [PATCH 06/21] Update saul_coap.c --- saul_coap.c | 60 +++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 60 insertions(+) diff --git a/saul_coap.c b/saul_coap.c index 5ffa67c..2474a01 100644 --- a/saul_coap.c +++ b/saul_coap.c @@ -293,3 +293,63 @@ static ssize_t _atr_type_responder(coap_pkt_t* pdu, uint8_t *buf, size_t len, ui resp_len += fmt_u16_dec((char *)pdu->payload, res.val[0]); return resp_len; } + +static ssize_t _saul_servo_handler(coap_pkt_t* pdu, uint8_t *buf, size_t len, void *ctx) +{ + uint8_t type; + + (void)ctx; + + if (pdu->payload_len <= 5) { + char req_payl[6] = { 0 }; + memcpy(req_payl, (char *)pdu->payload, pdu->payload_len); + type = atoi(req_payl); + } + else { + return gcoap_response(pdu, buf, len, COAP_CODE_BAD_REQUEST); + } + + return _servo_type_responder(pdu, buf, len, type); +} + +static ssize_t _servo_type_responder(coap_pkt_t* pdu, uint8_t *buf, size_t len, uint8_t type) +{ + saul_reg_t *dev = saul_reg_find_type(type); + phydat_t res; + int dim; + size_t resp_len; + gcoap_resp_init(pdu, buf, len, COAP_CODE_CONTENT); + coap_opt_add_format(pdu, COAP_FORMAT_TEXT); + //coap_opt_add_format(pdu, COAP_FORMAT_CBOR); + resp_len = coap_opt_finish(pdu, COAP_OPT_FINISH_PAYLOAD); + + if (dev == NULL) { + char *err = "device not found"; + if (pdu->payload_len >= strlen(err)) { + memcpy(pdu->payload, err, strlen(err)); + resp_len += gcoap_response(pdu, buf, len, COAP_CODE_404); + return resp_len; + } + else { + //parse!*** + //parse whatever to phydat + //functions to execute + //dim = saul_reg_write(dev, res); // &res -as saul_reg_read store location or *res data to write? + // return gcoap_response(pdu, buf, len, COAP_CODE_404); + } + } + if (dim <= 0) { + char *err = "no values found"; + if (pdu->payload_len >= strlen(err)) { + memcpy(pdu->payload, err, strlen(err)); + resp_len += gcoap_response(pdu, buf, len, COAP_CODE_404); + return resp_len; + } + else { + return gcoap_response(pdu, buf, len, COAP_CODE_404); + } + } + /* write the response buffer with the request device value */ + resp_len += fmt_u16_dec((char *)pdu->payload, res.val[0]); + return resp_len; +} From 8fa1d2a378ea32abbacd94ec3539107bcef76e3b Mon Sep 17 00:00:00 2001 From: seojeongmoon <55705552+seojeongmoon@users.noreply.github.com> Date: Fri, 29 Nov 2019 18:37:03 +0100 Subject: [PATCH 07/21] Update saul_coap.c --- saul_coap.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/saul_coap.c b/saul_coap.c index 2474a01..b620bc8 100644 --- a/saul_coap.c +++ b/saul_coap.c @@ -335,7 +335,7 @@ static ssize_t _servo_type_responder(coap_pkt_t* pdu, uint8_t *buf, size_t len, //parse whatever to phydat //functions to execute //dim = saul_reg_write(dev, res); // &res -as saul_reg_read store location or *res data to write? - // return gcoap_response(pdu, buf, len, COAP_CODE_404); + return gcoap_response(pdu, buf, len, COAP_CODE_404); } } if (dim <= 0) { From c443565c8c7a20cc3d0a535c53a538214b095226 Mon Sep 17 00:00:00 2001 From: seojeongmoon <55705552+seojeongmoon@users.noreply.github.com> Date: Fri, 29 Nov 2019 18:40:50 +0100 Subject: [PATCH 08/21] Update saul_coap.c --- saul_coap.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/saul_coap.c b/saul_coap.c index b620bc8..077fd27 100644 --- a/saul_coap.c +++ b/saul_coap.c @@ -333,7 +333,7 @@ static ssize_t _servo_type_responder(coap_pkt_t* pdu, uint8_t *buf, size_t len, else { //parse!*** //parse whatever to phydat - //functions to execute + //functions to execute : winch_control (winch_t *winch, int l_ges) //dim = saul_reg_write(dev, res); // &res -as saul_reg_read store location or *res data to write? return gcoap_response(pdu, buf, len, COAP_CODE_404); } From 37eb3c4b1eb2eef0ce8701a4d9c93a1694d2cccb Mon Sep 17 00:00:00 2001 From: seojeongmoon <55705552+seojeongmoon@users.noreply.github.com> Date: Fri, 29 Nov 2019 18:46:03 +0100 Subject: [PATCH 09/21] Update Makefile --- Makefile | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/Makefile b/Makefile index bab0553..8787f91 100644 --- a/Makefile +++ b/Makefile @@ -40,4 +40,11 @@ DEVELHELP ?= 1 # Change this to 0 show compiler invocation lines by default: QUIET ?= 1 +# Include tinycbor for data representation +USEPKG += tinycbor +INCLUDE += $(RIOTPKG)/tinycbor/cbor.h + +CFLAGS += -DGNRC_IPV6_NIB_CONF_SLAAC=1 + +# Include RIOT Base makefile include $(RIOTBASE)/Makefile.include From f88ce1e7391652d61ecd62a481a8f53f143e70bb Mon Sep 17 00:00:00 2001 From: seojeongmoon <55705552+seojeongmoon@users.noreply.github.com> Date: Sun, 1 Dec 2019 17:58:17 +0100 Subject: [PATCH 10/21] Update saul_coap.c --- saul_coap.c | 100 ++++++++++++++++++++++++++++++++++++++++++++++++++-- 1 file changed, 98 insertions(+), 2 deletions(-) diff --git a/saul_coap.c b/saul_coap.c index 077fd27..8369ea6 100644 --- a/saul_coap.c +++ b/saul_coap.c @@ -294,7 +294,7 @@ static ssize_t _atr_type_responder(coap_pkt_t* pdu, uint8_t *buf, size_t len, ui return resp_len; } -static ssize_t _saul_servo_handler(coap_pkt_t* pdu, uint8_t *buf, size_t len, void *ctx) +static ssize_t _saul_winch_handler(coap_pkt_t* pdu, uint8_t *buf, size_t len, void *ctx) { uint8_t type; @@ -312,7 +312,7 @@ static ssize_t _saul_servo_handler(coap_pkt_t* pdu, uint8_t *buf, size_t len, vo return _servo_type_responder(pdu, buf, len, type); } -static ssize_t _servo_type_responder(coap_pkt_t* pdu, uint8_t *buf, size_t len, uint8_t type) +static ssize_t _winch_type_responder(coap_pkt_t* pdu, uint8_t *buf, size_t len, uint8_t type) { saul_reg_t *dev = saul_reg_find_type(type); phydat_t res; @@ -353,3 +353,99 @@ static ssize_t _servo_type_responder(coap_pkt_t* pdu, uint8_t *buf, size_t len, resp_len += fmt_u16_dec((char *)pdu->payload, res.val[0]); return resp_len; } + + +CborError export_cbor_to_phydat(CborParser *parser, uint8_t *cbor_buf, size_t buf_len, phydat_t data, int dim) +{ + //CborParser parser; + CborValue value, r; + int result; + err = CborNoError; + bool result; + + //initialize Cbor parser + err = cbor_parser_init(cbor_buf, buf_len, 0, parser, &value); + if (err != CborNoError) { + return err; + } + + //check if map exists + if(!cbor_value_is_map(&value) || cbor_value_is_null(&value)){ + return 0; + } + + //enter container if map exists + //CborError cbor_value_enter_container ( const CborValue * it,CborValue * recursed ) + err = cbor_value_enter_container(&value, &r) ; + if (err != CborNoError) { + return err; + } + + //check for values + if(!cbor_value_is_text_string(&r)){ + return 0; + } + + cbor_value_text_string_equals(&r, "values", &result); + + if(!result){ + return 0 + } + cbor_value_advance(&r); + + if(!cbor_value_is_array(&r)){ + return 0; + } + + for (uint8_t i = 0; i < dim; i++) { + err = cbor_value_get_int_checked(&r, &data.val[i]); + if (err != CborNoError) { + return err; + } + } + + //check for unit + + if(!cbor_value_is_text_string(&r)){ + return 0; + } + + cbor_value_text_string_equals(&r, "unit", &result); + + if(!result){ + return 0; + } + cbor_value_advance(&r); + if(!cbor_value_is_array(&r)){ + return 0; + } + + err = cbor_value_get_int_checked(&r, &data.unit); + if (err != CborNoError) { + return err; + } + + //check for scale + + if(!cbor_value_is_text_string(&r)){ + return 0; + } + + cbor_value_text_string_equals(&r, "scale", &result); + + if(!result){ + return 0; + } + cbor_value_advance(&r); + if(!cbor_value_is_array(&r)){ + return 0; + } + + err = cbor_value_get_int_checked(&r, &data.scale); + if (err != CborNoError) { + return err; + } + + return CborNoError; +} + From ab49362b39bcd5cc59ccaa2aae711acac5780d2e Mon Sep 17 00:00:00 2001 From: seojeongmoon <55705552+seojeongmoon@users.noreply.github.com> Date: Sun, 1 Dec 2019 18:12:52 +0100 Subject: [PATCH 11/21] Update saul_coap.c --- saul_coap.c | 21 ++++++++++++++++++++- 1 file changed, 20 insertions(+), 1 deletion(-) diff --git a/saul_coap.c b/saul_coap.c index 8369ea6..7e9eb5c 100644 --- a/saul_coap.c +++ b/saul_coap.c @@ -294,6 +294,23 @@ static ssize_t _atr_type_responder(coap_pkt_t* pdu, uint8_t *buf, size_t len, ui return resp_len; } + +/**********************************************winch***********************************************/ + + +static int set(const void *dev, phydat_t *data) +{ + const winch_saul_driver *w = (const winch_saul_driver *) dev; + winch_set(); + return 1; +} + +const saul_driver_t winch_saul_driver = { + .read = saul_notsup, + .write = set, + .type = SAUL_ACT_SERVO +}; + static ssize_t _saul_winch_handler(coap_pkt_t* pdu, uint8_t *buf, size_t len, void *ctx) { uint8_t type; @@ -316,6 +333,7 @@ static ssize_t _winch_type_responder(coap_pkt_t* pdu, uint8_t *buf, size_t len, { saul_reg_t *dev = saul_reg_find_type(type); phydat_t res; + phydat_t data; int dim; size_t resp_len; gcoap_resp_init(pdu, buf, len, COAP_CODE_CONTENT); @@ -333,8 +351,9 @@ static ssize_t _winch_type_responder(coap_pkt_t* pdu, uint8_t *buf, size_t len, else { //parse!*** //parse whatever to phydat + //CborError export_cbor_to_phydat(CborParser *parser, uint8_t *cbor_buf, size_t buf_len, phydat_t data, int dim) + //functions to set phydat_t data to winch actuator: winch_set(dev, &data); //functions to execute : winch_control (winch_t *winch, int l_ges) - //dim = saul_reg_write(dev, res); // &res -as saul_reg_read store location or *res data to write? return gcoap_response(pdu, buf, len, COAP_CODE_404); } } From d605861809e41c8bed92d3dcfaf6d756e98ec375 Mon Sep 17 00:00:00 2001 From: seojeongmoon <55705552+seojeongmoon@users.noreply.github.com> Date: Sun, 1 Dec 2019 20:19:48 +0100 Subject: [PATCH 12/21] added resource for winch --- saul_coap.c | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/saul_coap.c b/saul_coap.c index 7e9eb5c..b10cf0d 100644 --- a/saul_coap.c +++ b/saul_coap.c @@ -25,6 +25,7 @@ #include "saul_reg.h" #include "fmt.h" #include "net/gcoap.h" +#inculde "winch.h" extern char *make_msg(char *, ...); @@ -32,12 +33,17 @@ static ssize_t _saul_cnt_handler(coap_pkt_t* pdu, uint8_t *buf, size_t len, void static ssize_t _saul_dev_handler(coap_pkt_t* pdu, uint8_t *buf, size_t len, void *ctx); static ssize_t _saul_sensortype_handler(coap_pkt_t* pdu, uint8_t *buf, size_t len, void *ctx); static ssize_t _sense_type_responder(coap_pkt_t* pdu, uint8_t *buf, size_t len, uint8_t type); +static ssize_t _saul_atr_handler(coap_pkt_t* pdu, uint8_t *buf, size_t len, void *ctx); +static ssize_t _atr_type_responder(coap_pkt_t* pdu, uint8_t *buf, size_t len, uint8_t type); + /* specific sense type handlers, shortcut via enum in saul.h */ static ssize_t _sense_temp_handler(coap_pkt_t* pdu, uint8_t *buf, size_t len, void *ctx); static ssize_t _sense_hum_handler(coap_pkt_t* pdu, uint8_t *buf, size_t len, void *ctx); static ssize_t _sense_servo_handler(coap_pkt_t* pdu, uint8_t *buf, size_t len, void *ctx); static ssize_t _sense_press_handler(coap_pkt_t* pdu, uint8_t *buf, size_t len, void *ctx); static ssize_t _sense_voltage_handler(coap_pkt_t* pdu, uint8_t *buf, size_t len, void *ctx); +/* winch handler */ +static ssize_t _saul_winch_handler(coap_pkt_t* pdu, uint8_t *buf, size_t len, void *ctx); /* CoAP resources. Must be sorted by path (ASCII order). */ static const coap_resource_t _resources[] = { @@ -50,6 +56,8 @@ static const coap_resource_t _resources[] = { { "/servo", COAP_GET, _sense_servo_handler, NULL }, { "/temp", COAP_GET, _sense_temp_handler, NULL }, { "/voltage", COAP_GET, _sense_voltage_handler, NULL }, + { "/winch", COAP_PUT, _saul_winch_handler, NULL}, + }; static gcoap_listener_t _listener = { From bad8f358b12befb3a9f2c8145a8ba0dd077dd669 Mon Sep 17 00:00:00 2001 From: seojeongmoon <55705552+seojeongmoon@users.noreply.github.com> Date: Mon, 2 Dec 2019 12:27:41 +0100 Subject: [PATCH 13/21] Update README.md --- README.md | 8 +++----- 1 file changed, 3 insertions(+), 5 deletions(-) diff --git a/README.md b/README.md index b1f8404..ac60658 100644 --- a/README.md +++ b/README.md @@ -45,10 +45,8 @@ Enter shell with board command (Phytec) To distinguish multiple boards using SERIAL number make list-ttys - - -###########TO DO############### -human readable parameter(input) -> parse it -> phydat -cbor standard format but still parse +To test get command + + coap get 5683 From 724541435339bc0fe52bc6e92174fbdd0b8e6933 Mon Sep 17 00:00:00 2001 From: seojeongmoon <55705552+seojeongmoon@users.noreply.github.com> Date: Mon, 2 Dec 2019 12:29:43 +0100 Subject: [PATCH 14/21] Update README on testing with dtls --- README.md | 3 +++ 1 file changed, 3 insertions(+) diff --git a/README.md b/README.md index ac60658..d85d354 100644 --- a/README.md +++ b/README.md @@ -49,4 +49,7 @@ To distinguish multiple boards using SERIAL number To test get command coap get 5683 + +With DTLS, port number is 5684 + From 70929155dc81646abdd8d0778f7928bd6bdc83ba Mon Sep 17 00:00:00 2001 From: seojeongmoon <55705552+seojeongmoon@users.noreply.github.com> Date: Mon, 2 Dec 2019 13:04:13 +0100 Subject: [PATCH 15/21] added cbor.h, TO DO comments TO DO - Change error 404 response in every if conditions in handler and return buffzie resp_len (based on pull request on rosetree) --- saul_coap.c | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/saul_coap.c b/saul_coap.c index b10cf0d..a51b6bb 100644 --- a/saul_coap.c +++ b/saul_coap.c @@ -25,6 +25,7 @@ #include "saul_reg.h" #include "fmt.h" #include "net/gcoap.h" +#include "cbor.h" #inculde "winch.h" extern char *make_msg(char *, ...); @@ -251,6 +252,7 @@ static ssize_t _saul_atr_handler(coap_pkt_t* pdu, uint8_t *buf, size_t len, void (void)ctx; + //payload length has to be bigger - edit according to expected size if (pdu->payload_len <= 5) { char req_payl[6] = { 0 }; memcpy(req_payl, (char *)pdu->payload, pdu->payload_len); @@ -282,8 +284,7 @@ static ssize_t _atr_type_responder(coap_pkt_t* pdu, uint8_t *buf, size_t len, ui } else { phydat_dump(&res, type);//phydat.h - dim = saul_reg_write(dev, &res); // &res -as saul_reg_read store location or *res data to write? - // return gcoap_response(pdu, buf, len, COAP_CODE_404); + dim = saul_reg_write(dev, &res); } } if (dim <= 0) { @@ -324,7 +325,8 @@ static ssize_t _saul_winch_handler(coap_pkt_t* pdu, uint8_t *buf, size_t len, vo uint8_t type; (void)ctx; - + + //change payload size - according to expected parameters etc. if (pdu->payload_len <= 5) { char req_payl[6] = { 0 }; memcpy(req_payl, (char *)pdu->payload, pdu->payload_len); @@ -345,6 +347,7 @@ static ssize_t _winch_type_responder(coap_pkt_t* pdu, uint8_t *buf, size_t len, int dim; size_t resp_len; gcoap_resp_init(pdu, buf, len, COAP_CODE_CONTENT); + /* option of text and cbor format*/ coap_opt_add_format(pdu, COAP_FORMAT_TEXT); //coap_opt_add_format(pdu, COAP_FORMAT_CBOR); resp_len = coap_opt_finish(pdu, COAP_OPT_FINISH_PAYLOAD); From 80f8d5ccedb060410439956e79408044d29989dc Mon Sep 17 00:00:00 2001 From: seojeongmoon <55705552+seojeongmoon@users.noreply.github.com> Date: Mon, 2 Dec 2019 17:23:57 +0100 Subject: [PATCH 16/21] separate winch from saul_coap, error corrections --- saul_coap.c | 86 ++--------------------------------------------------- 1 file changed, 3 insertions(+), 83 deletions(-) diff --git a/saul_coap.c b/saul_coap.c index a51b6bb..93cbd5b 100644 --- a/saul_coap.c +++ b/saul_coap.c @@ -26,7 +26,8 @@ #include "fmt.h" #include "net/gcoap.h" #include "cbor.h" -#inculde "winch.h" +#include "phydat.h" +//#include "winch.h" extern char *make_msg(char *, ...); @@ -304,94 +305,13 @@ static ssize_t _atr_type_responder(coap_pkt_t* pdu, uint8_t *buf, size_t len, ui } -/**********************************************winch***********************************************/ - - -static int set(const void *dev, phydat_t *data) -{ - const winch_saul_driver *w = (const winch_saul_driver *) dev; - winch_set(); - return 1; -} - -const saul_driver_t winch_saul_driver = { - .read = saul_notsup, - .write = set, - .type = SAUL_ACT_SERVO -}; - -static ssize_t _saul_winch_handler(coap_pkt_t* pdu, uint8_t *buf, size_t len, void *ctx) -{ - uint8_t type; - - (void)ctx; - - //change payload size - according to expected parameters etc. - if (pdu->payload_len <= 5) { - char req_payl[6] = { 0 }; - memcpy(req_payl, (char *)pdu->payload, pdu->payload_len); - type = atoi(req_payl); - } - else { - return gcoap_response(pdu, buf, len, COAP_CODE_BAD_REQUEST); - } - - return _servo_type_responder(pdu, buf, len, type); -} - -static ssize_t _winch_type_responder(coap_pkt_t* pdu, uint8_t *buf, size_t len, uint8_t type) -{ - saul_reg_t *dev = saul_reg_find_type(type); - phydat_t res; - phydat_t data; - int dim; - size_t resp_len; - gcoap_resp_init(pdu, buf, len, COAP_CODE_CONTENT); - /* option of text and cbor format*/ - coap_opt_add_format(pdu, COAP_FORMAT_TEXT); - //coap_opt_add_format(pdu, COAP_FORMAT_CBOR); - resp_len = coap_opt_finish(pdu, COAP_OPT_FINISH_PAYLOAD); - - if (dev == NULL) { - char *err = "device not found"; - if (pdu->payload_len >= strlen(err)) { - memcpy(pdu->payload, err, strlen(err)); - resp_len += gcoap_response(pdu, buf, len, COAP_CODE_404); - return resp_len; - } - else { - //parse!*** - //parse whatever to phydat - //CborError export_cbor_to_phydat(CborParser *parser, uint8_t *cbor_buf, size_t buf_len, phydat_t data, int dim) - //functions to set phydat_t data to winch actuator: winch_set(dev, &data); - //functions to execute : winch_control (winch_t *winch, int l_ges) - return gcoap_response(pdu, buf, len, COAP_CODE_404); - } - } - if (dim <= 0) { - char *err = "no values found"; - if (pdu->payload_len >= strlen(err)) { - memcpy(pdu->payload, err, strlen(err)); - resp_len += gcoap_response(pdu, buf, len, COAP_CODE_404); - return resp_len; - } - else { - return gcoap_response(pdu, buf, len, COAP_CODE_404); - } - } - /* write the response buffer with the request device value */ - resp_len += fmt_u16_dec((char *)pdu->payload, res.val[0]); - return resp_len; -} - - CborError export_cbor_to_phydat(CborParser *parser, uint8_t *cbor_buf, size_t buf_len, phydat_t data, int dim) { //CborParser parser; CborValue value, r; int result; - err = CborNoError; bool result; + CborError err = CborNoError; //initialize Cbor parser err = cbor_parser_init(cbor_buf, buf_len, 0, parser, &value); From 0ea1f32674309ae5dc12b1b9873dc5d22a05fa97 Mon Sep 17 00:00:00 2001 From: seojeongmoon <55705552+seojeongmoon@users.noreply.github.com> Date: Mon, 2 Dec 2019 17:24:39 +0100 Subject: [PATCH 17/21] Create winch.c --- winch.c | 82 +++++++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 82 insertions(+) create mode 100644 winch.c diff --git a/winch.c b/winch.c new file mode 100644 index 0000000..4e13b57 --- /dev/null +++ b/winch.c @@ -0,0 +1,82 @@ +/* + + +static int set(const void *dev, phydat_t *data) +{ + const winch_saul_driver *w = (const _saul_driver *) dev; + winch_set(); + return 1; +} + +const saul_driver_t winch_saul_driver = { + .read = saul_notsup, + .write = set, + .type = SAUL_ACT_SERVO +}; + +static ssize_t _saul_winch_handler(coap_pkt_t* pdu, uint8_t *buf, size_t len, void *ctx) +{ + uint8_t type; + + (void)ctx; + + //change payload size - according to expected parameters etc. + if (pdu->payload_len <= 5) { + char req_payl[6] = { 0 }; + memcpy(req_payl, (char *)pdu->payload, pdu->payload_len); + type = atoi(req_payl); + } + else { + return gcoap_response(pdu, buf, len, COAP_CODE_BAD_REQUEST); + } + + return _servo_type_responder(pdu, buf, len, type); +} + +static ssize_t _winch_type_responder(coap_pkt_t* pdu, uint8_t *buf, size_t len, uint8_t type) +{ + saul_reg_t *dev = saul_reg_find_type(type); + phydat_t res; + phydat_t data; + int dim; + size_t resp_len; + gcoap_resp_init(pdu, buf, len, COAP_CODE_CONTENT); + /* option of text and cbor format*/ + coap_opt_add_format(pdu, COAP_FORMAT_TEXT); + //coap_opt_add_format(pdu, COAP_FORMAT_CBOR); + resp_len = coap_opt_finish(pdu, COAP_OPT_FINISH_PAYLOAD); + + if (dev == NULL) { + char *err = "device not found"; + if (pdu->payload_len >= strlen(err)) { + memcpy(pdu->payload, err, strlen(err)); + resp_len += gcoap_response(pdu, buf, len, COAP_CODE_404); + return resp_len; + } + else { + //parse!*** + //parse whatever to phydat + //CborError export_cbor_to_phydat(CborParser *parser, uint8_t *cbor_buf, size_t buf_len, phydat_t data, int dim) + //functions to set phydat_t data to winch actuator: winch_set(dev, &data); + //functions to execute : winch_control (winch_t *winch, int l_ges) + return gcoap_response(pdu, buf, len, COAP_CODE_404); + } + } + if (dim <= 0) { + char *err = "no values found"; + if (pdu->payload_len >= strlen(err)) { + memcpy(pdu->payload, err, strlen(err)); + resp_len += gcoap_response(pdu, buf, len, COAP_CODE_404); + return resp_len; + } + else { + return gcoap_response(pdu, buf, len, COAP_CODE_404); + } + } + /* write the response buffer with the request device value */ + resp_len += fmt_u16_dec((char *)pdu->payload, res.val[0]); + return resp_len; +} + + +*/ From 842fd36cc92b05f5821af449423ad153a2be91fe Mon Sep 17 00:00:00 2001 From: seojeongmoon <55705552+seojeongmoon@users.noreply.github.com> Date: Mon, 2 Dec 2019 17:26:19 +0100 Subject: [PATCH 18/21] Rename winch.c to winch.txt --- winch.c => winch.txt | 0 1 file changed, 0 insertions(+), 0 deletions(-) rename winch.c => winch.txt (100%) diff --git a/winch.c b/winch.txt similarity index 100% rename from winch.c rename to winch.txt From 8e05a98df91db596bc5cbce3f5733d47a4fefdde Mon Sep 17 00:00:00 2001 From: seojeongmoon <55705552+seojeongmoon@users.noreply.github.com> Date: Mon, 2 Dec 2019 18:02:17 +0100 Subject: [PATCH 19/21] error removed --- saul_coap.c | 40 +++++++++++++++++++++++----------------- 1 file changed, 23 insertions(+), 17 deletions(-) diff --git a/saul_coap.c b/saul_coap.c index 93cbd5b..134765f 100644 --- a/saul_coap.c +++ b/saul_coap.c @@ -45,7 +45,7 @@ static ssize_t _sense_servo_handler(coap_pkt_t* pdu, uint8_t *buf, size_t len, v static ssize_t _sense_press_handler(coap_pkt_t* pdu, uint8_t *buf, size_t len, void *ctx); static ssize_t _sense_voltage_handler(coap_pkt_t* pdu, uint8_t *buf, size_t len, void *ctx); /* winch handler */ -static ssize_t _saul_winch_handler(coap_pkt_t* pdu, uint8_t *buf, size_t len, void *ctx); +//static ssize_t _saul_winch_handler(coap_pkt_t* pdu, uint8_t *buf, size_t len, void *ctx); /* CoAP resources. Must be sorted by path (ASCII order). */ static const coap_resource_t _resources[] = { @@ -58,7 +58,7 @@ static const coap_resource_t _resources[] = { { "/servo", COAP_GET, _sense_servo_handler, NULL }, { "/temp", COAP_GET, _sense_temp_handler, NULL }, { "/voltage", COAP_GET, _sense_voltage_handler, NULL }, - { "/winch", COAP_PUT, _saul_winch_handler, NULL}, + //{ "/winch", COAP_PUT, _saul_winch_handler, NULL}, }; @@ -171,7 +171,7 @@ static ssize_t _sense_type_responder(coap_pkt_t* pdu, uint8_t *buf, size_t len, { saul_reg_t *dev = saul_reg_find_type(type); phydat_t res; - int dim; + int dim = 0; size_t resp_len; gcoap_resp_init(pdu, buf, len, COAP_CODE_CONTENT); @@ -270,7 +270,7 @@ static ssize_t _atr_type_responder(coap_pkt_t* pdu, uint8_t *buf, size_t len, ui { saul_reg_t *dev = saul_reg_find_type(type); phydat_t res; - int dim; + int dim = 0; size_t resp_len; gcoap_resp_init(pdu, buf, len, COAP_CODE_CONTENT); coap_opt_add_format(pdu, COAP_FORMAT_TEXT); @@ -309,8 +309,7 @@ CborError export_cbor_to_phydat(CborParser *parser, uint8_t *cbor_buf, size_t bu { //CborParser parser; CborValue value, r; - int result; - bool result; + bool resultbool; CborError err = CborNoError; //initialize Cbor parser @@ -336,19 +335,22 @@ CborError export_cbor_to_phydat(CborParser *parser, uint8_t *cbor_buf, size_t bu return 0; } - cbor_value_text_string_equals(&r, "values", &result); + cbor_value_text_string_equals(&r, "values", &resultbool); - if(!result){ - return 0 + if(!resultbool){ + return 0; } cbor_value_advance(&r); if(!cbor_value_is_array(&r)){ return 0; } - + /***************************************** check ******************************/ for (uint8_t i = 0; i < dim; i++) { - err = cbor_value_get_int_checked(&r, &data.val[i]); + int16_t *p; + p = data.val; + int temp = *p++; + err = cbor_value_get_int_checked(&r, &temp); if (err != CborNoError) { return err; } @@ -360,9 +362,9 @@ CborError export_cbor_to_phydat(CborParser *parser, uint8_t *cbor_buf, size_t bu return 0; } - cbor_value_text_string_equals(&r, "unit", &result); + cbor_value_text_string_equals(&r, "unit", &resultbool); - if(!result){ + if(!resultbool){ return 0; } cbor_value_advance(&r); @@ -370,7 +372,9 @@ CborError export_cbor_to_phydat(CborParser *parser, uint8_t *cbor_buf, size_t bu return 0; } - err = cbor_value_get_int_checked(&r, &data.unit); +/* uint8_t unit; */ + int unit = data.unit; + err = cbor_value_get_int_checked(&r, &unit); if (err != CborNoError) { return err; } @@ -381,9 +385,9 @@ CborError export_cbor_to_phydat(CborParser *parser, uint8_t *cbor_buf, size_t bu return 0; } - cbor_value_text_string_equals(&r, "scale", &result); + cbor_value_text_string_equals(&r, "scale", &resultbool); - if(!result){ + if(!resultbool){ return 0; } cbor_value_advance(&r); @@ -391,7 +395,9 @@ CborError export_cbor_to_phydat(CborParser *parser, uint8_t *cbor_buf, size_t bu return 0; } - err = cbor_value_get_int_checked(&r, &data.scale); + // int8_t scale; + int scale = data.scale; + err = cbor_value_get_int_checked(&r, &scale); if (err != CborNoError) { return err; } From 93d1c1ac7e1747a85992885642af987cbe3b6273 Mon Sep 17 00:00:00 2001 From: seojeongmoon <55705552+seojeongmoon@users.noreply.github.com> Date: Mon, 9 Dec 2019 14:50:04 +0100 Subject: [PATCH 20/21] specify directory --- README.md | 3 +++ 1 file changed, 3 insertions(+) diff --git a/README.md b/README.md index d85d354..a29e019 100644 --- a/README.md +++ b/README.md @@ -38,6 +38,9 @@ The idea of these resources is, to offer similar functionality as the ## Build and Execute + +Directory: X/riot-saul-coap/RIOT/examples/gcoap/ + Enter shell with board command (Phytec) SERIAL=... BOARD=pba-d-01-kw2x BUILD_IN_DOCKER=1 make all flash term From 6a6e086b72a095af52d761e814df7f2a9c487829 Mon Sep 17 00:00:00 2001 From: seojeongmoon <55705552+seojeongmoon@users.noreply.github.com> Date: Mon, 9 Dec 2019 15:47:24 +0100 Subject: [PATCH 21/21] Update winch.txt --- winch.txt | 4 ---- 1 file changed, 4 deletions(-) diff --git a/winch.txt b/winch.txt index 4e13b57..4f58714 100644 --- a/winch.txt +++ b/winch.txt @@ -1,4 +1,3 @@ -/* static int set(const void *dev, phydat_t *data) @@ -77,6 +76,3 @@ static ssize_t _winch_type_responder(coap_pkt_t* pdu, uint8_t *buf, size_t len, resp_len += fmt_u16_dec((char *)pdu->payload, res.val[0]); return resp_len; } - - -*/