diff options
-rw-r--r-- | htdocs/UNICENS.html | 6 | ||||
-rw-r--r-- | ucs2-afb/ucs_apidef.h | 18 | ||||
-rw-r--r-- | ucs2-afb/ucs_apidef.json | 6 | ||||
-rw-r--r-- | ucs2-afb/ucs_binding.c | 99 |
4 files changed, 58 insertions, 71 deletions
diff --git a/htdocs/UNICENS.html b/htdocs/UNICENS.html index 1a21b41..176e11d 100644 --- a/htdocs/UNICENS.html +++ b/htdocs/UNICENS.html @@ -32,9 +32,9 @@ </ol> <br> <ol> - <li><button onclick="callbinder('UNICENS','write_i2c', {node_address: 0x270, i2c_data:[0x07,0x03,0xFF]})">Write I2C to 0x270 (mute)</button></li> - <li><button onclick="callbinder('UNICENS','write_i2c', {node_address: 0x271, i2c_data:[0x07,0x03,0xFF]})">Write I2C to 0x271 (mute)</button></li> - <li><button onclick="callbinder('UNICENS','write_i2c', {node_address: 0x272, i2c_data:[0x07,0x03,0xFF]})">Write I2C to 0x272 (mute)</button></li> + <li><button onclick="callbinder('UNICENS','writei2c', {node: 0x270, data:[0x07,0x03,0xFF]})">WriteI2c to 0x270 (mute)</button></li> + <li><button onclick="callbinder('UNICENS','writei2c', {node: 0x271, data:[0x07,0x03,0xFF]})">WriteI2c to 0x271 (mute)</button></li> + <li><button onclick="callbinder('UNICENS','writei2c', {node: 0x272, data:[0x07,0x03,0xFF]})">WriteI2c to 0x272 (mute)</button></li> </ol> <br> <br> diff --git a/ucs2-afb/ucs_apidef.h b/ucs2-afb/ucs_apidef.h index f1b0c13..d32a6dc 100644 --- a/ucs2-afb/ucs_apidef.h +++ b/ucs2-afb/ucs_apidef.h @@ -40,14 +40,14 @@ static const char _afb_description_v2_UNICENS[] = "\":{\"$ref\":\"#/components/responses/200\"}}}},\"/monitor\":{\"descript" "ion\":\"Subscribe to Unicens Event.\",\"get\":{\"x-permissions\":{\"$ref" "\":\"#/components/x-permissions/monitor\"},\"responses\":{\"200\":{\"$re" - "f\":\"#/components/responses/200\"}}}},\"/write_i2c\":{\"description\":\"" + "f\":\"#/components/responses/200\"}}}},\"/writei2c\":{\"description\":\"" "Writes I2C command to remote node.\",\"get\":{\"x-permissions\":{\"$ref\"" ":\"#/components/x-permissions/monitor\"},\"parameters\":[{\"in\":\"query" - "\",\"name\":\"node_address\",\"required\":true,\"schema\":{\"type\":\"in" - "teger\",\"format\":\"int32\"}},{\"in\":\"query\",\"name\":\"i2c_data\",\"" - "required\":true,\"schema\":{\"type\":\"array\",\"format\":\"int32\"},\"s" - "tyle\":\"simple\"}],\"responses\":{\"200\":{\"$ref\":\"#/components/resp" - "onses/200\"}}}}}}" + "\",\"name\":\"node\",\"required\":true,\"schema\":{\"type\":\"integer\"," + "\"format\":\"int32\"}},{\"in\":\"query\",\"name\":\"data\",\"required\":" + "true,\"schema\":{\"type\":\"array\",\"format\":\"int32\"},\"style\":\"si" + "mple\"}],\"responses\":{\"200\":{\"$ref\":\"#/components/responses/200\"" + "}}}}}}" ; static const struct afb_auth _afb_auths_v2_UNICENS[] = { @@ -59,7 +59,7 @@ static const struct afb_auth _afb_auths_v2_UNICENS[] = { void ucs2_initialise(struct afb_req req); void ucs2_volume(struct afb_req req); void ucs2_monitor(struct afb_req req); - void ucs2_write_i2c(struct afb_req req); + void ucs2_writei2c(struct afb_req req); static const struct afb_verb_v2 _afb_verbs_v2_UNICENS[] = { { @@ -91,8 +91,8 @@ static const struct afb_verb_v2 _afb_verbs_v2_UNICENS[] = { .session = AFB_SESSION_NONE_V2 }, { - .verb = "write_i2c", - .callback = ucs2_write_i2c, + .verb = "writei2c", + .callback = ucs2_writei2c, .auth = &_afb_auths_v2_UNICENS[1], .info = NULL, .session = AFB_SESSION_NONE_V2 diff --git a/ucs2-afb/ucs_apidef.json b/ucs2-afb/ucs_apidef.json index 2d9001f..24474e6 100644 --- a/ucs2-afb/ucs_apidef.json +++ b/ucs2-afb/ucs_apidef.json @@ -170,7 +170,7 @@ } } }, - "/write_i2c": { + "/writei2c": { "description": "Writes I2C command to remote node.", "get": { "x-permissions": { @@ -179,7 +179,7 @@ "parameters": [ { "in": "query", - "name": "node_address", + "name": "node", "required": true, "schema": { "type": "integer", @@ -188,7 +188,7 @@ }, { "in": "query", - "name": "i2c_data", + "name": "data", "required": true, "schema": { "type": "array", diff --git a/ucs2-afb/ucs_binding.c b/ucs2-afb/ucs_binding.c index dffacd3..fe6e033 100644 --- a/ucs2-afb/ucs_binding.c +++ b/ucs2-afb/ucs_binding.c @@ -23,6 +23,7 @@ #define BUFFER_FRAME_COUNT 10 /* max frames in buffer */ #define WAIT_TIMER_US 1000000 /* default waiting timer 1s */ +#define I2C_MAX_DATA_SZ 32 /* max. number of bytes to be written to i2c */ #include <systemd/sd-event.h> #include <sys/types.h> @@ -39,8 +40,6 @@ #include "ucs_binding.h" #include "ucs_interface.h" - - #define MAX_FILENAME_LEN (100) #define RX_BUFFER (64) @@ -65,8 +64,6 @@ typedef struct { static ucsContextT *ucsContextS; -STATIC void ucs2_write_i2c_response(void *result_ptr, void *request_ptr); - PUBLIC void UcsXml_CB_OnError(const char format[], uint16_t vargsCnt, ...) { /*AFB_DEBUG (afbIface, format, args); */ va_list args; @@ -539,21 +536,35 @@ PUBLIC void ucs2_monitor (struct afb_req request) { afb_req_success(request,NULL,"UNICENS-to_be_done"); } -#define MUTE_VALUE 0x03FFU -#define MUTE_VALUE_HB 0x03U -#define MUTE_VALUE_LB 0xFFU - -#define CONTROL_MASTER 0x07U -#define CONTROL_CH_1 0x08U -#define CONTROL_CH_2 0x09U - -#define UCSB_I2C_MAX_PAYLOAD 32 +STATIC void ucs2_writei2c_CB(void *result_ptr, void *request_ptr) { + + if (request_ptr){ + afb_req *req = (afb_req *)request_ptr; + Ucs_I2c_ResultCode_t *res = (Ucs_I2c_ResultCode_t *)result_ptr; + + if (!res) { + afb_req_fail(*req, "processing","busy or lost initialization"); + } + else if (*res != UCS_I2C_RES_SUCCESS){ + afb_req_fail_f(*req, "error-result", "result code: %d", *res); + } + else { + afb_req_success(*req, NULL, "success"); + } + + afb_req_unref(*req); + free(request_ptr); + } + else { + AFB_NOTICE("write_i2c: ambiguous response data"); + } +} -PUBLIC void ucs2_write_i2c (struct afb_req request) { +PUBLIC void ucs2_writei2c(struct afb_req request) { struct json_object *j_obj; - static uint8_t tx_payload[UCSB_I2C_MAX_PAYLOAD]; - uint8_t tx_payload_sz = 0; + static uint8_t i2c_data[I2C_MAX_DATA_SZ]; + uint8_t i2c_data_sz = 0; uint16_t node_addr = 0; struct afb_req *async_req_ptr = NULL; @@ -569,7 +580,7 @@ PUBLIC void ucs2_write_i2c (struct afb_req request) { goto OnErrorExit; }; - node_addr = (uint16_t)json_object_get_int(json_object_object_get(j_obj, "node_address")); + node_addr = (uint16_t)json_object_get_int(json_object_object_get(j_obj, "node")); AFB_NOTICE("node_address: 0x%02X", node_addr); if (node_addr == 0) { @@ -577,14 +588,14 @@ PUBLIC void ucs2_write_i2c (struct afb_req request) { goto OnErrorExit; } - if (json_object_get_type(json_object_object_get(j_obj, "i2c_data"))==json_type_array) { - int size = json_object_array_length(json_object_object_get(j_obj, "i2c_data")); - if ((size > 0) && (size <= UCSB_I2C_MAX_PAYLOAD)) { + if (json_object_get_type(json_object_object_get(j_obj, "data"))==json_type_array) { + int size = json_object_array_length(json_object_object_get(j_obj, "data")); + if ((size > 0) && (size <= I2C_MAX_DATA_SZ)) { int32_t i; int32_t val; struct json_object *j_elem; - struct json_object *j_arr = json_object_object_get(j_obj, "i2c_data"); + struct json_object *j_arr = json_object_object_get(j_obj, "data"); for (i = 0; i < size; i++) { @@ -595,15 +606,15 @@ PUBLIC void ucs2_write_i2c (struct afb_req request) { i = 0; break; } - tx_payload[i] = (uint8_t)json_object_get_int(j_elem); + i2c_data[i] = (uint8_t)json_object_get_int(j_elem); } - tx_payload_sz = (uint8_t)i; + i2c_data_sz = (uint8_t)i; } } - if (tx_payload_sz == 0) { - AFB_NOTICE("i2c_data: invalid or not found"); + if (i2c_data_sz == 0) { + AFB_NOTICE("data: invalid or not found"); afb_req_fail_f(request, "query-params","params wrong or missing"); goto OnErrorExit; } @@ -611,22 +622,22 @@ PUBLIC void ucs2_write_i2c (struct afb_req request) { async_req_ptr = malloc(sizeof(afb_req)); *async_req_ptr = request; - if (UCSI_I2CWrite( &ucsContextS->ucsiData, /*UCSI_Data_t *pPriv*/ - node_addr, /*uint16_t targetAddress*/ - false, /*bool isBurst*/ + if (UCSI_I2CWrite( &ucsContextS->ucsiData, /* UCSI_Data_t *pPriv*/ + node_addr, /* uint16_t targetAddress*/ + false, /* bool isBurst*/ 0u, /* block count */ 0x2Au, /* i2c slave address */ 0x03E8u, /* timeout 1000 milliseconds */ - tx_payload_sz, /* uint8_t dataLen */ - &tx_payload[0], /* uint8_t *pData */ - &ucs2_write_i2c_response, /* callback*/ + i2c_data_sz, /* uint8_t dataLen */ + &i2c_data[0], /* uint8_t *pData */ + &ucs2_writei2c_CB, /* callback*/ (void*)async_req_ptr /* callback argument */ )) { /* asynchronous command is running */ afb_req_addref(request); } else { - AFB_NOTICE("i2c_data: scheduling command failed"); + AFB_NOTICE("i2c write: scheduling command failed"); afb_req_fail_f(request, "query-command-queue","command queue overload"); free(async_req_ptr); async_req_ptr = NULL; @@ -636,27 +647,3 @@ PUBLIC void ucs2_write_i2c (struct afb_req request) { OnErrorExit: return; } - -STATIC void ucs2_write_i2c_response(void *result_ptr, void *request_ptr) { - - if (request_ptr){ - afb_req *req = (afb_req *)request_ptr; - Ucs_I2c_ResultCode_t *res = (Ucs_I2c_ResultCode_t *)result_ptr; - - if (!res) { - afb_req_fail(*req, "processing","busy or lost initialization"); - } - else if (*res != UCS_I2C_RES_SUCCESS){ - afb_req_fail_f(*req, "error-result", "result code: %d", *res); - } - else { - afb_req_success(*req, NULL, "success"); - } - - afb_req_unref(*req); - free(request_ptr); - } - else { - AFB_NOTICE("write_i2c: ambiguous response data"); - } -} |