+ int32_t i;
+ int32_t val;
+ struct json_object *j_elem;
+
+ for (i = 0; i < size; i++) {
+
+ j_elem = json_object_array_get_idx(j_tmp, i);
+ val = json_object_get_int(j_elem);
+ if ((val < 0) && (val > 0xFF)){
+ i = 0;
+ break;
+ }
+ i2c_data[i] = (uint8_t)json_object_get_int(j_elem);
+ }
+
+ i2c_data_sz = (uint8_t)i;
+ }
+ }
+
+ 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;
+ }
+
+ 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*/
+ 0u, /* block count */
+ 0x2Au, /* i2c slave address */
+ 0x03E8u, /* timeout 1000 milliseconds */
+ 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 write: scheduling command failed");
+ afb_req_fail_f(request, "query-command-queue","command queue overload");
+ free(async_req_ptr);
+ async_req_ptr = NULL;
+ goto OnErrorExit;
+ }
+
+OnErrorExit:
+ return;
+}
+
+/* parse array or single command */
+PUBLIC void ucs2_writei2c (struct afb_req request) {
+
+ struct json_object *j_obj;
+
+ j_obj = ucs2_validate_command(request, "writei2c");
+
+ if (j_obj) {
+ ucs2_writei2c_cmd(request, j_obj);
+ }
+}
+
+/* write a single control message */
+STATIC void ucs2_sendmessage_cmd(struct afb_req request, json_object *j_obj) {
+
+ static uint8_t ctrl_data[CTRL_MAX_DATA_SZ];
+ uint8_t ctrl_data_sz = 0;
+ uint16_t node_addr = 0;
+ uint16_t msg_id = 0;
+ json_object *j_tmp;
+
+ if (json_object_object_get_ex(j_obj, "node", &j_tmp)) {
+ node_addr = (uint16_t)json_object_get_int(j_tmp);
+ AFB_NOTICE("node_address: 0x%02X", node_addr);
+ if (node_addr == 0) {
+ afb_req_fail_f(request, "query-params","param node invalid type");