summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorTobias Jahnke <tobias.jahnke@microchip.com>2018-10-04 14:06:16 +0200
committerTobias Jahnke <tobias.jahnke@microchip.com>2018-12-18 13:01:13 +0100
commit3798969ce5771058d9526e2b3cbfec2c74e23fed (patch)
tree917c742ed05bca94eac0301d52966bc412da8fce
parent6c118349a37d3484ef248a7b99415b8a949710bc (diff)
4a-hal-unicens: fixes json parsing issue
Bug-AGL: SPEC-1505 Json parsing error avoids that new nodes are recognized and volume handing is initialized. Signed-off-by: Tobias Jahnke <tobias.jahnke@microchip.com>
-rw-r--r--plugin/most_unicens.c42
1 files changed, 41 insertions, 1 deletions
diff --git a/plugin/most_unicens.c b/plugin/most_unicens.c
index 0bd8ec4..dc92857 100644
--- a/plugin/most_unicens.c
+++ b/plugin/most_unicens.c
@@ -54,6 +54,8 @@ CTLP_CAPI(MasterVol, source, argsJ, queryJ)
int master_volume;
json_object *valueJ;
+
+ AFB_ApiNotice(source->api, "Hal-Unicens: MasterVolume=%s", json_object_to_json_string(queryJ));
if(! initialized) {
AFB_ApiWarning(source->api, "%s: Link to unicens binder is not initialized, can't set master volume, value=%s", __func__, json_object_get_string(queryJ));
@@ -81,6 +83,8 @@ CTLP_CAPI(MasterSwitch, source, argsJ, queryJ)
{
json_bool master_switch;
json_object *valueJ;
+
+ AFB_ApiNotice(source->api, "Hal-Unicens: MasterSwitch=%s", json_object_to_json_string(queryJ));
if(! initialized) {
AFB_ApiWarning(source->api, "%s: Link to unicens binder is not initialized, can't set master switch, value=%s", __func__, json_object_get_string(queryJ));
@@ -120,6 +124,8 @@ CTLP_CAPI(PCMVol, source, argsJ, queryJ)
int pcm_volume[PCM_MAX_CHANNELS];
json_object *valueJ;
+
+ AFB_ApiNotice(source->api, "Hal-Unicens: PCMVolume=%s", json_object_to_json_string(queryJ));
if(! initialized) {
AFB_ApiWarning(source->api, "%s: Link to unicens binder is not initialized, can't set PCM volume, value=%s", __func__, json_object_get_string(queryJ));
@@ -183,6 +189,40 @@ CTLP_CAPI(Init, source, argsJ, queryJ)
// This receive UNICENS events
CTLP_CAPI(Events, source, argsJ, queryJ)
{
+ uint16_t node = 0U;
+ bool available = false;
+ bool error = false;
+ json_object *j_tmp = NULL;
+
+ if (json_object_object_get_ex(queryJ, "node", &j_tmp)) {
+ node = (uint16_t)json_object_get_int(j_tmp);
+ }
+ else {
+ error = true;
+ }
+
+ if (json_object_object_get_ex(queryJ, "available", &j_tmp)) {
+ available = (bool)json_object_get_boolean(j_tmp);
+ }
+ else {
+ error = true;
+ }
+
+ if(!error) {
+ AFB_ApiNotice(source->api, "Node-Availability: node=0x%03X, available=%d", node, available);
+ wrap_volume_node_avail(source->api, node, available);
+ }
+ else {
+ AFB_ApiError(source->api, "Hal-Unicens: Failed to parse events query=%s", json_object_to_json_string(queryJ));
+ }
+
+ return 0;
+}
+
+// This is the former implementation receiving UNICENS events,
+// wrap_json_unpack() seems not to work as expected.
+/*CTLP_CAPI(Events, source, argsJ, queryJ)
+{
int node;
int available;
@@ -192,4 +232,4 @@ CTLP_CAPI(Events, source, argsJ, queryJ)
}
return 0;
-}
+}*/