aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorTobias Jahnke <tobias.jahnke@microchip.com>2018-05-09 11:11:31 +0200
committerTobias Jahnke <tobias.jahnke@microchip.com>2018-05-09 11:19:17 +0200
commit216ae6b4e1c6eac62dea123816ccb1314c8362c9 (patch)
treecf6999a740850d287420d6e739d8a52cdc74f7b5
parent84c3e1b169038e181526b4fbadab3d8f9322717c (diff)
agl-service-unicens: support base64 Tx/Rx
Bug-AGL: SPEC-1177 Implement function to transmit control messages with base64 encoded payload string. Modify control message reception providing the payload as base64. Change-Id: I78fb600e75cef3083220da202d2274df729083d9 Signed-off-by: Tobias Jahnke <tobias.jahnke@microchip.com>
-rw-r--r--.gitmodules3
m---------afb-helpers0
-rw-r--r--htdocs/UNICENS.html3
-rw-r--r--ucs2-afb/CMakeLists.txt1
-rw-r--r--ucs2-afb/ucs_binding.c65
5 files changed, 49 insertions, 23 deletions
diff --git a/.gitmodules b/.gitmodules
index 9d64e35..54be31c 100644
--- a/.gitmodules
+++ b/.gitmodules
@@ -4,3 +4,6 @@
[submodule "ucs2-lib/unicens"]
path = ucs2-lib/unicens
url = https://github.com/MicrochipTech/unicens.git
+[submodule "afb-helpers"]
+ path = afb-helpers
+ url = https://gerrit.automotivelinux.org/gerrit/apps/app-afb-helpers-submodule
diff --git a/afb-helpers b/afb-helpers
new file mode 160000
+Subproject 98d9f99624775129e850bed93d04a52e79c051d
diff --git a/htdocs/UNICENS.html b/htdocs/UNICENS.html
index bc01401..fd2e89c 100644
--- a/htdocs/UNICENS.html
+++ b/htdocs/UNICENS.html
@@ -42,6 +42,9 @@
</ol>
<ol>
<li><button onclick="callbinder('UNICENS','sendmessageb64', {node: 0x270, msgid: 0x5AC4, data:'ESIzRA=='})">Send ControlMsgB64 to 0x270</button></li>
+ <li><button onclick="callbinder('UNICENS','sendmessageb64', {node: 0x270, msgid: 0x5AC4})">Send ControlMsgB64 to 0x270 (no data)</button></li>
+ <!--<li><button onclick="callbinder('UNICENS','sendmessageb64', {node: 0x270, msgid: 0x5AC4, data: null})">Send ControlMsgB64 to 0x270 (data: null)</button></li>-->
+ <!--<li><button onclick="callbinder('UNICENS','sendmessageb64', {node: 0x270, msgid: 0x5AC4, data: ''})">Send ControlMsgB64 to 0x270 (data: '')</button></li>-->
</ol>
<br>
<br>
diff --git a/ucs2-afb/CMakeLists.txt b/ucs2-afb/CMakeLists.txt
index 31d8c0d..2f5141d 100644
--- a/ucs2-afb/CMakeLists.txt
+++ b/ucs2-afb/CMakeLists.txt
@@ -35,5 +35,6 @@ PROJECT_TARGET_ADD(ucs2-afb)
# Library dependencies (include updates automatically)
TARGET_LINK_LIBRARIES(${TARGET_NAME}
ucs2-inter
+ afb-helpers
${link_libraries}
)
diff --git a/ucs2-afb/ucs_binding.c b/ucs2-afb/ucs_binding.c
index ddf44b1..bc783aa 100644
--- a/ucs2-afb/ucs_binding.c
+++ b/ucs2-afb/ucs_binding.c
@@ -41,6 +41,7 @@
#include "ucs_binding.h"
#include "ucs_interface.h"
+#include "wrap-json.h"
#define MAX_FILENAME_LEN (100)
#define RX_BUFFER (64)
@@ -223,30 +224,19 @@ STATIC void NotifyEventRxMsg(uint16_t src_addr, uint16_t msg_id, uint8_t *data_p
return;
}
- json_object *j_event_info = json_object_new_object();
- json_object *j_array = json_object_new_array();
+ json_object *j_query = NULL;
+ int node = (int)src_addr;
+ int msgid = (int)msg_id;
+ size_t data_size = (size_t)data_sz;
- if (!j_event_info || !j_array) {
- if (j_event_info) {
- json_object_put(j_event_info);
- }
- if (j_array) {
- json_object_put(j_array);
- }
- AFB_ERROR("Failed to create json objects");
- return;
- }
-
- uint32_t cnt = 0U;
- for (cnt = 0U; cnt < data_sz; cnt++) {
- json_object_array_add(j_array, json_object_new_int(data_ptr[cnt]));
- }
-
- json_object_object_add(j_event_info, "node", json_object_new_int(src_addr));
- json_object_object_add(j_event_info, "msgid", json_object_new_int(msg_id));
- json_object_object_add(j_event_info, "data", j_array);
+ /* skip data attribute if possible, wrap_json_unpack may fail to deal with
+ * an empty Base64 string */
+ if (data_size > 0)
+ wrap_json_pack(&j_query, "{s:i, s:i, s:Y*}", "node", node, "msgid", msgid, "data", data_ptr, data_size);
+ else
+ wrap_json_pack(&j_query, "{s:i, s:i}", "node", node, "msgid", msgid);
- afb_event_push(eventDataRx->rx_event, j_event_info);
+ afb_event_push(eventDataRx->rx_event, j_query);
}
/** Asynchronous processing of Rx messages in mainloop is recommended */
@@ -858,7 +848,36 @@ PUBLIC void ucs2_sendmessage(struct afb_req request) {
}
PUBLIC void ucs2_sendmessageb64(struct afb_req req) {
- afb_req_fail_f(req, "not-implemented", "Function not yet implemented.");
+ uint8_t *data_ptr = NULL;
+ size_t data_sz = 0;
+ int ret, node_addr, msg_id = 0;
+ struct json_object *j_obj;
+
+ j_obj = ucs2_validate_command(req, "sendmessageb64");
+
+ if (!j_obj) {
+ AFB_NOTICE("validation of command failed");
+ goto OnErrorExit;
+ }
+
+ ret = wrap_json_unpack(j_obj, "{s:i, s:i, s?Y}", "node", &node_addr, "msgid", &msg_id, "data", &data_ptr, &data_sz);
+
+ if ((ret==0) &&
+ UCSI_SendAmsMessage(&ucsContextS->ucsiData, msg_id, node_addr, &data_ptr[0], data_sz)
+ ) {
+ afb_req_success(req, NULL, "sendmessageb64 started successful");
+ }
+ else {
+ AFB_ERROR("sendmessageb64: scheduling command failed. ret: %d", ret);
+ afb_req_fail_f(req, "query-command-queue","ambiguous command or queue overload");
+ goto OnErrorExit;
+ }
+
+OnErrorExit:
+ if (data_ptr) {
+ free(data_ptr);
+ }
+ return;
}
PUBLIC int ucs2_initbinding(void) {