aboutsummaryrefslogtreecommitdiffstats
path: root/ucs2-afb/ucs_binding.c
diff options
context:
space:
mode:
authorTobias Jahnke <tjahnk@users.noreply.github.com>2017-08-03 16:48:18 +0200
committerTobias Jahnke <tjahnk@users.noreply.github.com>2017-08-03 16:48:18 +0200
commite9aa8f0519f75d8dc1d698e11596c4720cd977e5 (patch)
tree7e48967a3b2587cbb898173ba4da49fc0cdb6a50 /ucs2-afb/ucs_binding.c
parent070569777b69eb2d36c4c8a3a4b10ce498f559ff (diff)
adds node-availibility event and subscribe function
Diffstat (limited to 'ucs2-afb/ucs_binding.c')
-rw-r--r--ucs2-afb/ucs_binding.c61
1 files changed, 57 insertions, 4 deletions
diff --git a/ucs2-afb/ucs_binding.c b/ucs2-afb/ucs_binding.c
index fe6e033..8a1174c 100644
--- a/ucs2-afb/ucs_binding.c
+++ b/ucs2-afb/ucs_binding.c
@@ -62,7 +62,13 @@ typedef struct {
UCSI_channelsT *channels;
} ucsContextT;
+typedef struct {
+ struct afb_event node_event;
+
+} EventData_t;
+
static ucsContextT *ucsContextS;
+static EventData_t *eventData = NULL;
PUBLIC void UcsXml_CB_OnError(const char format[], uint16_t vargsCnt, ...) {
/*AFB_DEBUG (afbIface, format, args); */
@@ -200,6 +206,31 @@ void UCSI_CB_OnGpioStateChange(void *pTag, uint16_t nodeAddress, uint8_t gpioPin
{
}
+PUBLIC void UCSI_CB_OnMgrReport(void *pTag, Ucs_MgrReport_t code, uint16_t nodeAddress, Ucs_Rm_Node_t *pNode){
+
+ bool available;
+
+ if (code == UCS_MGR_REP_AVAILABLE) {
+ available = true;
+ }
+ else if (code == UCS_MGR_REP_NOT_AVAILABLE) {
+ available = false;
+ }
+ else {
+ /*untracked event - just exit*/
+ return;
+ }
+
+ if (eventData) {
+
+ json_object *j_event_info = json_object_new_object();
+ json_object_object_add(j_event_info, "node", json_object_new_int(nodeAddress));
+ json_object_object_add(j_event_info, "available", json_object_new_boolean(available));
+
+ afb_event_push(eventData->node_event, j_event_info);
+ }
+}
+
bool Cdev_Init(CdevData_t *d, const char *fileName, bool read, bool write)
{
if (NULL == d || NULL == fileName) goto OnErrorExit;
@@ -531,12 +562,34 @@ PUBLIC void ucs2_listconfig (struct afb_req request) {
return;
}
-PUBLIC void ucs2_monitor (struct afb_req request) {
+PUBLIC void ucs2_subscribe (struct afb_req request) {
- afb_req_success(request,NULL,"UNICENS-to_be_done");
+ if (!eventData) {
+
+ eventData = malloc(sizeof(EventData_t));
+ if (eventData) {
+ eventData->node_event = afb_daemon_make_event ("node-availibility");
+ }
+
+ if (!eventData || !afb_event_is_valid(eventData->node_event)) {
+ afb_req_fail_f (request, "create-event", "Cannot create or register event");
+ goto OnExitError;
+ }
+ }
+
+ if (afb_req_subscribe(request, eventData->node_event) != 0) {
+
+ afb_req_fail_f (request, "subscribe-event", "Cannot subscribe to event");
+ goto OnExitError;
+ }
+
+ afb_req_success(request,NULL,"event subscription successful");
+
+OnExitError:
+ return;
}
-STATIC void ucs2_writei2c_CB(void *result_ptr, void *request_ptr) {
+STATIC void ucs2_writei2c_CB (void *result_ptr, void *request_ptr) {
if (request_ptr){
afb_req *req = (afb_req *)request_ptr;
@@ -560,7 +613,7 @@ STATIC void ucs2_writei2c_CB(void *result_ptr, void *request_ptr) {
}
}
-PUBLIC void ucs2_writei2c(struct afb_req request) {
+PUBLIC void ucs2_writei2c (struct afb_req request) {
struct json_object *j_obj;
static uint8_t i2c_data[I2C_MAX_DATA_SZ];