From 044828c43097362973c82088a7afee760eab06ec Mon Sep 17 00:00:00 2001 From: fulup Date: Fri, 21 Jul 2017 23:46:49 +0200 Subject: Added HAL selection in HTML page Started SetCtl implementation WIP Only --- ALSA-afb/Alsa-RegEvt.c | 60 +++++-- ALSA-afb/Alsa-SetGet.c | 2 +- ALSA-afb/CMakeLists.txt | 8 +- HAL-afb/HAL-interface/CMakeLists.txt | 8 +- HAL-afb/HAL-interface/hal-interface.c | 233 +++++++++++++++++++++------- HAL-afb/HAL-plugin/HalPlugCtl.c | 2 +- HAL-afb/HDA-intel/CMakeLists.txt | 8 +- HAL-afb/Scarlett-Focusrite/CMakeLists.txt | 6 +- HAL-afb/Scarlett-Focusrite/ScarlettUsbHAL.c | 2 +- HAL-afb/Unicens-USB/CMakeLists.txt | 42 +++++ HAL-afb/Unicens-USB/UnicensHAL.c | 73 +++++++++ HAL-afb/Unicens-USB/UnicensVol.c | 37 +++++ Shared-Interface/CMakeLists.txt | 8 +- conf.d/app-templates | 2 +- conf.d/autobuild/agl/autobuild | 21 ++- conf.d/autobuild/linux/autobuild | 21 ++- htdocs/AudioBinding.js | 75 +++++++-- htdocs/alsa-hal.html | 29 ++-- nbproject/configurations.xml | 115 ++++++++------ 19 files changed, 569 insertions(+), 183 deletions(-) create mode 100644 HAL-afb/Unicens-USB/CMakeLists.txt create mode 100644 HAL-afb/Unicens-USB/UnicensHAL.c create mode 100644 HAL-afb/Unicens-USB/UnicensVol.c diff --git a/ALSA-afb/Alsa-RegEvt.c b/ALSA-afb/Alsa-RegEvt.c index 61885f7..6344e2d 100644 --- a/ALSA-afb/Alsa-RegEvt.c +++ b/ALSA-afb/Alsa-RegEvt.c @@ -36,8 +36,10 @@ typedef struct { } sndHandleT; typedef struct { + char *devid; char *apiprefix; - char *shortname; + char *shortname; + char *longname; }cardRegistryT; cardRegistryT *cardRegistry[MAX_SND_CARD+1]; @@ -111,7 +113,7 @@ STATIC int sndCtlEventCB (sd_event_source* src, int fd, uint32_t revents, void* // Subscribe to every Alsa CtlEvent send by a given board PUBLIC void alsaEvtSubcribe (afb_req request) { static sndHandleT sndHandles[MAX_SND_CARD]; - evtHandleT *evtHandle; + evtHandleT *evtHandle=NULL; snd_ctl_t *ctlDev=NULL; int err, idx, cardId, idxFree=-1; snd_ctl_card_info_t *cardinfo; @@ -207,7 +209,7 @@ PUBLIC void alsaEvtSubcribe (afb_req request) { } // Subscribe to every Alsa CtlEvent send by a given board -PUBLIC void alsaGetCardId (afb_req request) { +STATIC json_object *alsaProbeCardId (afb_req request) { char devid [10]; const char *devname, *shortname, *longname; int card, err, index, idx; @@ -265,11 +267,17 @@ PUBLIC void alsaGetCardId (afb_req request) { } } - afb_req_success(request, responseJ, NULL); - return; + return responseJ; - OnErrorExit: - return; + OnErrorExit: + return NULL; +} + +// Make alsaProbeCardId compatible with AFB request +PUBLIC void alsaGetCardId (afb_req request) { + + json_object *responseJ = alsaProbeCardId (request); + if (responseJ) afb_req_success(request, responseJ, NULL); } // Return list of active resgistrated HAL with corresponding sndcard @@ -281,7 +289,9 @@ PUBLIC void alsaActiveHal (afb_req request) { json_object *haldevJ = json_object_new_object(); json_object_object_add(haldevJ, "api", json_object_new_string(cardRegistry[idx]->apiprefix)); - json_object_object_add(haldevJ, "devid", json_object_new_string(cardRegistry[idx]->shortname)); + if (cardRegistry[idx]->devid) json_object_object_add(haldevJ, "devid", json_object_new_string(cardRegistry[idx]->devid)); + if (cardRegistry[idx]->shortname)json_object_object_add(haldevJ, "shortname", json_object_new_string(cardRegistry[idx]->shortname)); + if (cardRegistry[idx]->longname) json_object_object_add(haldevJ, "longname", json_object_new_string(cardRegistry[idx]->longname)); json_object_array_add (responseJ, haldevJ); } @@ -292,6 +302,7 @@ PUBLIC void alsaActiveHal (afb_req request) { // Register loaded HAL with board Name and API prefix PUBLIC void alsaRegisterHal (afb_req request) { static int index=0; + json_object *responseJ; const char *shortname, *apiPrefix; apiPrefix = afb_req_value(request, "prefix"); @@ -310,15 +321,32 @@ PUBLIC void alsaRegisterHal (afb_req request) { afb_req_fail_f (request, "alsahal-toomany", "Fail to register sndname=[%s]", shortname); goto OnErrorExit; } - + // alsaGetCardId should be check to register only valid card - cardRegistry[index]= malloc (sizeof(cardRegistry)); - cardRegistry[index]->apiprefix=strdup(apiPrefix); - cardRegistry[index]->shortname=strdup(shortname); - index++;cardRegistry[index]=NULL; - - alsaGetCardId(request); - + responseJ= alsaProbeCardId(request); + if (responseJ) { + json_object *tmpJ; + int done; + + cardRegistry[index]= malloc (sizeof(cardRegistry)); + cardRegistry[index]->apiprefix=strdup(apiPrefix); + cardRegistry[index]->shortname=strdup(shortname); + + done= json_object_object_get_ex (responseJ, "devid" , &tmpJ); + if (done) cardRegistry[index]->devid = strdup (json_object_get_string(tmpJ)); + else cardRegistry[index]->devid=NULL; + + done = json_object_object_get_ex (responseJ, "longname" , &tmpJ); + if (done) cardRegistry[index]->longname = strdup (json_object_get_string(tmpJ)); + else cardRegistry[index]->longname=NULL; + + // make sure register close with a null value + index++; + cardRegistry[index]=NULL; + + afb_req_success(request, responseJ, NULL); + } + // If OK return sound card Alsa ID+Info return; diff --git a/ALSA-afb/Alsa-SetGet.c b/ALSA-afb/Alsa-SetGet.c index 56dc32f..31406f3 100644 --- a/ALSA-afb/Alsa-SetGet.c +++ b/ALSA-afb/Alsa-SetGet.c @@ -448,7 +448,7 @@ STATIC json_object *getControlAcl (snd_ctl_elem_info_t *info) { PUBLIC int alsaSetSingleCtl (snd_ctl_t *ctlDev, snd_ctl_elem_id_t *elemId, ctlRequestT *ctlRequest) { snd_ctl_elem_value_t *elemData; snd_ctl_elem_info_t *elemInfo; - int count, length, err, valueIsArray; + int count, length, err, valueIsArray=0; // let's make sure we are processing the right control if (ctlRequest->numId != snd_ctl_elem_id_get_numid (elemId)) goto OnErrorExit; diff --git a/ALSA-afb/CMakeLists.txt b/ALSA-afb/CMakeLists.txt index 4ca7158..443acbd 100644 --- a/ALSA-afb/CMakeLists.txt +++ b/ALSA-afb/CMakeLists.txt @@ -20,10 +20,10 @@ PROJECT_TARGET_ADD(alsa-lowlevel) # Define project Targets - ADD_LIBRARY(alsa-lowlevel MODULE Alsa-ApiHat.c Alsa-SetGet.c Alsa-Ucm.c Alsa-AddCtl.c Alsa-RegEvt.c) + ADD_LIBRARY(${TARGET_NAME} MODULE Alsa-ApiHat.c Alsa-SetGet.c Alsa-Ucm.c Alsa-AddCtl.c Alsa-RegEvt.c) # Binder exposes a unique public entry point - SET_TARGET_PROPERTIES(alsa-lowlevel PROPERTIES + SET_TARGET_PROPERTIES(${TARGET_NAME} PROPERTIES PREFIX "afb-" LABELS "BINDING" LINK_FLAGS ${BINDINGS_LINK_FLAG} @@ -31,11 +31,11 @@ PROJECT_TARGET_ADD(alsa-lowlevel) ) # Library dependencies (include updates automatically) - TARGET_LINK_LIBRARIES(alsa-lowlevel + TARGET_LINK_LIBRARIES(${TARGET_NAME} audio-interface ${link_libraries} ) # installation directory - INSTALL(TARGETS alsa-lowlevel + INSTALL(TARGETS ${TARGET_NAME} LIBRARY DESTINATION ${BINDINGS_INSTALL_DIR}) diff --git a/HAL-afb/HAL-interface/CMakeLists.txt b/HAL-afb/HAL-interface/CMakeLists.txt index 0ea298f..d4dba4b 100644 --- a/HAL-afb/HAL-interface/CMakeLists.txt +++ b/HAL-afb/HAL-interface/CMakeLists.txt @@ -21,17 +21,17 @@ PROJECT_TARGET_ADD(hal-interface) # Define targets - ADD_LIBRARY(hal-interface STATIC hal-interface.c) + ADD_LIBRARY(${TARGET_NAME} STATIC hal-interface.c) # Library properties - SET_TARGET_PROPERTIES(hal-interface PROPERTIES OUTPUT_NAME halinterface) + SET_TARGET_PROPERTIES(${TARGET_NAME} PROPERTIES OUTPUT_NAME halinterface) # Library dependencies (include updates automatically) - TARGET_LINK_LIBRARIES(hal-interface + TARGET_LINK_LIBRARIES(${TARGET_NAME} audio-interface ) # Define target includes - TARGET_INCLUDE_DIRECTORIES(hal-interface + TARGET_INCLUDE_DIRECTORIES(${TARGET_NAME} PUBLIC ${CMAKE_CURRENT_SOURCE_DIR} ) diff --git a/HAL-afb/HAL-interface/hal-interface.c b/HAL-afb/HAL-interface/hal-interface.c index 19fe191..dd00d1c 100644 --- a/HAL-afb/HAL-interface/hal-interface.c +++ b/HAL-afb/HAL-interface/hal-interface.c @@ -61,15 +61,14 @@ STATIC void halSubscribe(afb_req request) { } } - // HAL normalise volume values to 0-100% -STATIC struct json_object *NormaliseValue(const alsaHalCtlMapT *halCtls, struct json_object *valuesJ) { +STATIC struct json_object *UnNormaliseValue(const alsaHalCtlMapT *halCtls, struct json_object *valuesJ) { int length; // assert response as the right length length = json_object_array_length(valuesJ); if (length != halCtls->count) { - AFB_WARNING ("NormaliseValue invalid ctl=%s values count=%d len=%d", halCtls->name, halCtls->count, length); + AFB_WARNING ("NormaliseValue invalid ctl='%s' values count=%d len=%d", halCtls->name, halCtls->count, length); return NULL; } @@ -93,56 +92,41 @@ STATIC struct json_object *NormaliseValue(const alsaHalCtlMapT *halCtls, struct return (normalisedJ); } -// Remap low level controls into HAL hight level ones -STATIC json_object *CtlGetPrepareResponse(afb_req request, struct json_object *ctlsJ) { - struct json_object *halResponseJ; - // make sure return controls have a valid type - if (json_object_get_type(ctlsJ) != json_type_array) { - afb_req_fail_f(request, "ctls-notarray", "Invalid Controls return from alsa/getcontrol ctlsJ=%s", json_object_get_string(ctlsJ)); - goto OnErrorExit; - } - - // responseJ is a JSON array - halResponseJ = json_object_new_array(); - // loop on array and store values into client context - for (int idx = 0; idx < json_object_array_length(ctlsJ); idx++) { - struct json_object *sndCtlJ, *valJ, *numidJ; - int numid; +// HAL normalise volume values to 0-100% +STATIC struct json_object *NormaliseValue(const alsaHalCtlMapT *halCtls, struct json_object *valuesJ) { + int length; - sndCtlJ = json_object_array_get_idx(ctlsJ, idx); - if (!json_object_object_get_ex(sndCtlJ, "numid", &numidJ) || !json_object_object_get_ex(sndCtlJ, "val", &valJ)) { - afb_req_fail_f(request, "ctl-invalid", "Invalid Control return from alsa/getcontrol ctl=%s", json_object_get_string(sndCtlJ)); - goto OnErrorExit; - } + // assert response as the right length + length = json_object_array_length(valuesJ); + if (length != halCtls->count) { + AFB_WARNING ("NormaliseValue invalid ctl=%s values count=%d len=%d", halCtls->name, halCtls->count, length); + return NULL; + } + + json_object *normalisedJ= json_object_new_array(); + for (int idx=0; idx halCtls->maxval) value= halCtls->maxval; + if (value < halCtls->minval) value= halCtls->minval; + + // If Integer scale to 0/100 + if (halCtls->type == SND_CTL_ELEM_TYPE_INTEGER) { + value = (value * 100) / (halCtls->maxval - halCtls->minval); + } + + json_object_array_add(normalisedJ, json_object_new_int(value)); } - return halResponseJ; - OnErrorExit: - return NULL; + return (normalisedJ); } + + // Return ALL HAL snd controls PUBLIC void halListCtls(afb_req request) { struct json_object *ctlsHalJ = json_object_new_array(); @@ -181,7 +165,7 @@ STATIC int halCtlTagToIndex (halCtlsEnumT tag) { return -1; } -STATIC int halGetOneCtls (afb_req request, struct json_object*ctlInJ) { +STATIC int halGetCtlIndex (afb_req request, struct json_object*ctlInJ) { struct json_object *tmpJ; int tag, index; @@ -205,20 +189,149 @@ STATIC int halGetOneCtls (afb_req request, struct json_object*ctlInJ) { } if (index < 0) { - afb_req_fail_f(request, "ctl-invalid", "No Label/Tag given ctl=[%s]", json_object_get_string(ctlInJ)); + afb_req_fail_f(request, "ctl-invalid", "No Label/Tag given ctl='%s'", json_object_get_string(ctlInJ)); goto OnErrorExit; } // return corresponding lowlevel numid to querylist - return halCtls[index].ctl.numid; + return index; OnErrorExit: return -1; } + +// Translate high level control to low level and call lower layer +PUBLIC void halSetCtls(afb_req request) { + int err, index; + struct json_object *ctlsInJ, *ctlsOutJ, *queryJ, *valuesJ, *responseJ; + + // get query from request + ctlsInJ = afb_req_json(request); + ctlsOutJ = json_object_new_array(); + + switch (json_object_get_type(ctlsInJ)) { + case json_type_object: { + // control is in literal form {tag=xxx, label=xxx, val=xxxx} + index = halGetCtlIndex (request, ctlsInJ); + if (index <=0) goto OnErrorExit; + + err= json_object_object_get_ex (ctlsInJ, "val" , &valuesJ); + if (err) { + afb_req_fail_f(request, "ctl-invalid", "No val=[val1, ...] ctl='%s'", json_object_get_string(ctlsInJ)); + goto OnErrorExit; + } + + json_object_array_add (ctlsOutJ, json_object_new_int(halCtls[index].ctl.numid)); + json_object_array_add (ctlsOutJ, UnNormaliseValue (&halCtls[index].ctl, valuesJ)); + break; + } + + case json_type_array: { + + for (int idx= 0; idx < json_object_array_length (ctlsInJ); idx++) { + struct json_object *ctlInJ = json_object_array_get_idx (ctlsInJ, idx); + index= halGetCtlIndex (request, ctlInJ); + if (index<=0) goto OnErrorExit; + + err= json_object_object_get_ex (ctlInJ, "val" , &valuesJ); + if (err) { + afb_req_fail_f(request, "ctl-invalid", "No val=[val1, ...] ctl='%s'", json_object_get_string(ctlsInJ)); + goto OnErrorExit; + } + // let's create alsa low level set control request + struct json_object *ctlOutJ = json_object_new_array(); + json_object_array_add (ctlOutJ, json_object_new_int(halCtls[index].ctl.numid)); + json_object_array_add (ctlOutJ, UnNormaliseValue (&halCtls[index].ctl, valuesJ)); + + json_object_array_add (ctlsOutJ, ctlOutJ); + } + break; + } + + default: + afb_req_fail_f(request, "ctl-invalid", "Not a valid JSON ctl='%s'", json_object_get_string(ctlsInJ)); + goto OnErrorExit; + } + + // Call now level CTL + queryJ = json_object_new_object(); + json_object_object_add(queryJ, "devid", json_object_new_string (halDevid)); + json_object_object_add(queryJ, "numids", ctlsOutJ); + + err= afb_service_call_sync("alsacore", "setctls", queryJ, &responseJ); + if (err) { + afb_req_fail_f(request, "subcall:alsacore/setctl", "%s", json_object_get_string(responseJ)); + goto OnErrorExit; + } + + // Let ignore info data if any and keep on response + json_object_object_get_ex (responseJ, "response", &responseJ); + + // map back low level response to HAL ctl with normalised values + //struct json_object *halResponse = CtlSetPrepareResponse(request, responseJ); + //if (!halResponse) goto OnErrorExit; + + afb_req_success (request, NULL, NULL); + return; + +OnErrorExit: + return; +}; + +// Remap low level controls into HAL hight level ones +STATIC json_object *CtlGetPrepareResponse(afb_req request, struct json_object *ctlsJ) { + struct json_object *halResponseJ; + + // make sure return controls have a valid type + if (json_object_get_type(ctlsJ) != json_type_array) { + afb_req_fail_f(request, "ctls-notarray", "Invalid Controls return from alsa/getcontrol ctlsJ=%s", json_object_get_string(ctlsJ)); + goto OnErrorExit; + } + + // responseJ is a JSON array + halResponseJ = json_object_new_array(); + + // loop on array and store values into client context + for (int idx = 0; idx < json_object_array_length(ctlsJ); idx++) { + struct json_object *sndCtlJ, *valJ, *numidJ; + int numid; + + sndCtlJ = json_object_array_get_idx(ctlsJ, idx); + if (!json_object_object_get_ex(sndCtlJ, "numid", &numidJ) || !json_object_object_get_ex(sndCtlJ, "val", &valJ)) { + afb_req_fail_f(request, "ctl-invalid", "Invalid Control return from alsa/getcontrol ctl=%s", json_object_get_string(sndCtlJ)); + goto OnErrorExit; + } + + // HAL and Business logic use the same AlsaMixerHal.h direct conversion + numid= (halCtlsEnumT) json_object_get_int(numidJ); + + for (int idx = 0; halCtls[idx].ctl.numid; idx++) { + if (halCtls[idx].ctl.numid == numid) { + + // translate low level numid to HAL one and normalise values + struct json_object *halCtlJ = json_object_new_object(); + json_object_object_add(halCtlJ, "label", json_object_new_string(halCtls[idx].label)); // idx+1 == HAL/NUMID + json_object_object_add(halCtlJ, "tag" , json_object_new_int(halCtls[idx].tag)); // idx+1 == HAL/NUMID + json_object_object_add(halCtlJ, "val" , NormaliseValue(&halCtls[idx].ctl, valJ)); + json_object_array_add(halResponseJ, halCtlJ); + break; + } + } + if ( halCtls[idx].ctl.numid == 0) { + afb_req_fail_f(request, "ctl-invalid", "Invalid Control numid=%d from alsa/getcontrol ctlJ=%s", numid, json_object_get_string(sndCtlJ)); + goto OnErrorExit; + } + } + return halResponseJ; + + OnErrorExit: + return NULL; +} + // Translate high level control to low level and call lower layer PUBLIC void halGetCtls(afb_req request) { - int err, numid; + int err, index; struct json_object *ctlsInJ, *ctlsOutJ, *queryJ, *responseJ; // get query from request @@ -228,9 +341,9 @@ PUBLIC void halGetCtls(afb_req request) { switch (json_object_get_type(ctlsInJ)) { case json_type_object: { - numid = halGetOneCtls (request, ctlsInJ); - if (numid <=0) goto OnErrorExit; - json_object_array_add (ctlsOutJ, json_object_new_int(numid)); + index = halGetCtlIndex (request, ctlsInJ); + if (index <=0) goto OnErrorExit; + json_object_array_add (ctlsOutJ, json_object_new_int(halCtls[index].ctl.numid)); break; } @@ -238,15 +351,15 @@ PUBLIC void halGetCtls(afb_req request) { for (int idx= 0; idx < json_object_array_length (ctlsInJ); idx++) { struct json_object *ctlInJ = json_object_array_get_idx (ctlsInJ, idx); - numid= halGetOneCtls (request, ctlInJ); - if (numid<=0) goto OnErrorExit; - json_object_array_add (ctlsOutJ, json_object_new_int(numid)); + index= halGetCtlIndex (request, ctlInJ); + if (index<=0) goto OnErrorExit; + json_object_array_add (ctlsOutJ, json_object_new_int(halCtls[index].ctl.numid)); } break; } default: - afb_req_fail_f(request, "ctl-invalid", "Not a valid JSON ctl=[%s]", json_object_get_string(ctlsInJ)); + afb_req_fail_f(request, "ctl-invalid", "Not a valid JSON ctl='%s'", json_object_get_string(ctlsInJ)); goto OnErrorExit; } @@ -355,13 +468,13 @@ PUBLIC int halServiceInit (const char *apiPrefix, alsaHalSndCardT *alsaHalSndCar err= afb_service_call_sync ("alsacore", "halregister", queryurl, &responseJ); json_object_put(queryurl); if (err) { - AFB_NOTICE ("Fail to register HAL to ALSA lowlevel binding Response=[%s]", json_object_get_string(responseJ)); + AFB_NOTICE ("Fail to register HAL to ALSA lowlevel binding Response='%s'", json_object_get_string(responseJ)); goto OnErrorExit; } // extract sound devidJ from HAL registration if (!json_object_object_get_ex(responseJ, "response", &tmpJ) || !json_object_object_get_ex(tmpJ, "devid", &devidJ)) { - AFB_ERROR ("Ooops: Internal error no devidJ return from HAL registration Response=[%s]", json_object_get_string(responseJ)); + AFB_ERROR ("Ooops: Internal error no devidJ return from HAL registration Response='%s'", json_object_get_string(responseJ)); goto OnErrorExit; } @@ -400,7 +513,7 @@ PUBLIC int halServiceInit (const char *apiPrefix, alsaHalSndCardT *alsaHalSndCar json_object_object_add(queryurl, "ctls",ctlsJ); err= afb_service_call_sync ("alsacore", "addcustomctl", queryurl, &responseJ); if (err) { - AFB_ERROR ("Fail creating HAL Custom ALSA ctls Response=[%s]", json_object_get_string(responseJ)); + AFB_ERROR ("Fail creating HAL Custom ALSA ctls Response='%s'", json_object_get_string(responseJ)); goto OnErrorExit; } } @@ -408,7 +521,7 @@ PUBLIC int halServiceInit (const char *apiPrefix, alsaHalSndCardT *alsaHalSndCar // Make sure response is valid json_object_object_get_ex (responseJ, "response" , &ctlsJ); if (json_object_get_type(ctlsJ) != json_type_array) { - AFB_ERROR ("Response Invalid JSON array ctls Response=[%s]", json_object_get_string(responseJ)); + AFB_ERROR ("Response Invalid JSON array ctls Response='%s'", json_object_get_string(responseJ)); goto OnErrorExit; } diff --git a/HAL-afb/HAL-plugin/HalPlugCtl.c b/HAL-afb/HAL-plugin/HalPlugCtl.c index 01feedd..181d4f8 100644 --- a/HAL-afb/HAL-plugin/HalPlugCtl.c +++ b/HAL-afb/HAL-plugin/HalPlugCtl.c @@ -48,7 +48,7 @@ static snd_ctl_ext_key_t AfbHalElemFind(snd_ctl_ext_t *ext, const snd_ctl_elem_id_t *id) { snd_ctl_hal_t *plughandle = (snd_ctl_hal_t*) ext->private_data; - snd_ctl_ext_key_t key; + snd_ctl_ext_key_t key=NULL; int numid = snd_ctl_elem_id_get_numid(id); if (numid > 0) { diff --git a/HAL-afb/HDA-intel/CMakeLists.txt b/HAL-afb/HDA-intel/CMakeLists.txt index 4a12aee..efe244d 100644 --- a/HAL-afb/HDA-intel/CMakeLists.txt +++ b/HAL-afb/HDA-intel/CMakeLists.txt @@ -21,10 +21,10 @@ PROJECT_TARGET_ADD(hal-intel-hda) # Define project Targets - ADD_LIBRARY(hal-intel-hda MODULE IntelHdaHAL.c) + ADD_LIBRARY(${TARGET_NAME} MODULE IntelHdaHAL.c) # Binder exposes a unique public entry point - SET_TARGET_PROPERTIES(hal-intel-hda PROPERTIES + SET_TARGET_PROPERTIES(${TARGET_NAME} PROPERTIES PREFIX "afb-" LABELS "BINDING" LINK_FLAGS ${BINDINGS_LINK_FLAG} @@ -32,11 +32,11 @@ PROJECT_TARGET_ADD(hal-intel-hda) ) # Library dependencies (include updates automatically) - TARGET_LINK_LIBRARIES(hal-intel-hda + TARGET_LINK_LIBRARIES(${TARGET_NAME} hal-interface audio-interface ) # installation directory - INSTALL(TARGETS hal-intel-hda + INSTALL(TARGETS ${TARGET_NAME} LIBRARY DESTINATION ${BINDINGS_INSTALL_DIR}) \ No newline at end of file diff --git a/HAL-afb/Scarlett-Focusrite/CMakeLists.txt b/HAL-afb/Scarlett-Focusrite/CMakeLists.txt index a2ca912..4cbac19 100644 --- a/HAL-afb/Scarlett-Focusrite/CMakeLists.txt +++ b/HAL-afb/Scarlett-Focusrite/CMakeLists.txt @@ -24,7 +24,7 @@ PROJECT_TARGET_ADD(hal-scalett-usb) ADD_LIBRARY(hal-scalett-usb MODULE ScarlettUsbHAL.c) # Binder exposes a unique public entry point - SET_TARGET_PROPERTIES(hal-scalett-usb PROPERTIES + SET_TARGET_PROPERTIES(${TARGET_NAME} PROPERTIES PREFIX "afb-" LABELS "BINDING" LINK_FLAGS ${BINDINGS_LINK_FLAG} @@ -32,11 +32,11 @@ PROJECT_TARGET_ADD(hal-scalett-usb) ) # Library dependencies (include updates automatically) - TARGET_LINK_LIBRARIES(hal-scalett-usb + TARGET_LINK_LIBRARIES(${TARGET_NAME} hal-interface audio-interface ) # installation directory - INSTALL(TARGETS hal-scalett-usb + INSTALL(TARGETS ${TARGET_NAME} LIBRARY DESTINATION ${BINDINGS_INSTALL_DIR}) \ No newline at end of file diff --git a/HAL-afb/Scarlett-Focusrite/ScarlettUsbHAL.c b/HAL-afb/Scarlett-Focusrite/ScarlettUsbHAL.c index 99db443..cc62be1 100644 --- a/HAL-afb/Scarlett-Focusrite/ScarlettUsbHAL.c +++ b/HAL-afb/Scarlett-Focusrite/ScarlettUsbHAL.c @@ -58,7 +58,7 @@ STATIC alsaHalSndCardT alsaHalSndCard = { STATIC int sndServiceInit () { int err; AFB_DEBUG ("IntelHalBinding Init"); - + err = halServiceInit (afbBindingV2.api, &alsaHalSndCard); return err; } diff --git a/HAL-afb/Unicens-USB/CMakeLists.txt b/HAL-afb/Unicens-USB/CMakeLists.txt new file mode 100644 index 0000000..5ca563b --- /dev/null +++ b/HAL-afb/Unicens-USB/CMakeLists.txt @@ -0,0 +1,42 @@ +########################################################################### +# Copyright 2015, 2016, 2017 IoT.bzh +# +# author: Fulup Ar Foll +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. +########################################################################### + + +# Add target to project dependency list +PROJECT_TARGET_ADD(hal-unicens-usb) + + # Define project Targets + ADD_LIBRARY(${TARGET_NAME} MODULE UnicensHAL.c UnicensVol.c) + + # Binder exposes a unique public entry point + SET_TARGET_PROPERTIES(${TARGET_NAME} PROPERTIES + PREFIX "afb-" + LABELS "BINDING" + LINK_FLAGS ${BINDINGS_LINK_FLAG} + OUTPUT_NAME ${TARGET_NAME} + ) + + # Library dependencies (include updates automatically) + TARGET_LINK_LIBRARIES(${TARGET_NAME} + hal-interface + audio-interface + ) + + # installation directory + INSTALL(TARGETS ${TARGET_NAME} + LIBRARY DESTINATION ${BINDINGS_INSTALL_DIR}) \ No newline at end of file diff --git a/HAL-afb/Unicens-USB/UnicensHAL.c b/HAL-afb/Unicens-USB/UnicensHAL.c new file mode 100644 index 0000000..66f241f --- /dev/null +++ b/HAL-afb/Unicens-USB/UnicensHAL.c @@ -0,0 +1,73 @@ +/* + * Copyright (C) 2016 "IoT.bzh" + * Author Fulup Ar Foll + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * + * + * To find out which control your sound card uses + * aplay -l # Check sndcard name name in between [] + * amixer -D hw:xx controls # get supported controls + * amixer -D "hw:3" cget numid=xx # get control settings + * + */ +#define _GNU_SOURCE +#include "hal-interface.h" +#include "audio-interface.h" + +STATIC struct json_object* MasterOnOff (alsaHalCtlMapT *control, void* handle, struct json_object *valJ) { + struct json_object *reponseJ; + + AFB_INFO ("Power Set value=%s", json_object_get_string(valJ)); + + reponseJ=json_object_new_object(); + json_object_object_add (reponseJ, "Callback", json_object_new_string("Hello From HAL")); + + return reponseJ; +} + +// Map HAL hight sndctl with Alsa numid and optionally with a custom callback for non Alsa supported functionalities. +STATIC alsaHalMapT alsaHalMap[]= { + { .tag=Master_Playback_Volume, .ctl={.numid=04 } }, + { .tag=PCM_Playback_Volume , .ctl={.numid=06 } }, + { .tag=PCM_Playback_Switch , .ctl={.numid=05 } }, + { .tag=Capture_Volume , .ctl={.numid=12 } }, + { .tag=Master_OnOff_Switch , .ctl={.numid=0, .type=SND_CTL_ELEM_TYPE_BOOLEAN, .count=1, .name="Power-Switch"}, .cb={.callback=MasterOnOff, .handle=NULL}}, + { .tag=Master_Playback_Ramp , .ctl={.numid=0, .type=SND_CTL_ELEM_TYPE_INTEGER, .count=2, .name="Volume-Switch"}, .cb={.callback=MasterOnOff, .handle=NULL}}, + + { .tag=EndHalCrlTag} /* marker for end of the array */ +} ; + +// HAL sound card mapping info +STATIC alsaHalSndCardT alsaHalSndCard = { + .name = "HDA Intel PCH", // WARNING: name MUST match with 'aplay -l' + .info = "Hardware Abstraction Layer for IntelHDA sound card", + .ctls = alsaHalMap, +}; + + +STATIC int sndServiceInit () { + int err; + AFB_DEBUG ("IntelHalBinding Init"); + + err = halServiceInit (afbBindingV2.api, &alsaHalSndCard); + return err; +} + +// API prefix should be unique for each snd card +PUBLIC const struct afb_binding_v2 afbBindingV2 = { + .api = "intel-hda", + .init = sndServiceInit, + .verbs = halServiceApi, + .onevent = halServiceEvent, +}; diff --git a/HAL-afb/Unicens-USB/UnicensVol.c b/HAL-afb/Unicens-USB/UnicensVol.c new file mode 100644 index 0000000..ab9787d --- /dev/null +++ b/HAL-afb/Unicens-USB/UnicensVol.c @@ -0,0 +1,37 @@ +/* + * Copyright (C) 2016 "IoT.bzh" + * Author Fulup Ar Foll + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * + * + * To find out which control your sound card uses + * aplay -l # Check sndcard name name in between [] + * amixer -D hw:xx controls # get supported controls + * amixer -D "hw:3" cget numid=xx # get control settings + * + */ +#define _GNU_SOURCE +#include "hal-interface.h" +#include "audio-interface.h" + +STATIC struct json_object* MasterOnOff (alsaHalCtlMapT *control, void* handle, struct json_object *valJ) { + struct json_object *reponseJ; + + AFB_INFO ("Power Set value=%s", json_object_get_string(valJ)); + + reponseJ=json_object_new_object(); + json_object_object_add (reponseJ, "Callback", json_object_new_string("Hello From HAL")); + + return reponseJ; +} diff --git a/Shared-Interface/CMakeLists.txt b/Shared-Interface/CMakeLists.txt index 9a5c74d..107a0cb 100644 --- a/Shared-Interface/CMakeLists.txt +++ b/Shared-Interface/CMakeLists.txt @@ -20,19 +20,19 @@ PROJECT_TARGET_ADD(audio-interface) # Define targets - ADD_LIBRARY(audio-interface STATIC audio-interface.c) + ADD_LIBRARY(${TARGET_NAME} STATIC audio-interface.c) # Library properties - SET_TARGET_PROPERTIES(audio-interface PROPERTIES + SET_TARGET_PROPERTIES(${TARGET_NAME} PROPERTIES OUTPUT_NAME ${TARGET_NAME} ) # Library dependencies - #TARGET_LINK_LIBRARIES(audio-interface + #TARGET_LINK_LIBRARIES(${TARGET_NAME} # empty #) # Define target includes - TARGET_INCLUDE_DIRECTORIES(audio-interface + TARGET_INCLUDE_DIRECTORIES(${TARGET_NAME} PUBLIC ${CMAKE_CURRENT_SOURCE_DIR} ) \ No newline at end of file diff --git a/conf.d/app-templates b/conf.d/app-templates index f9998cb..db6a07f 160000 --- a/conf.d/app-templates +++ b/conf.d/app-templates @@ -1 +1 @@ -Subproject commit f9998cb5f9f042e3fe2d03e8925f70b5bb9a1c95 +Subproject commit db6a07f636a3f2a381dfcc0f52b16f59127496f0 diff --git a/conf.d/autobuild/agl/autobuild b/conf.d/autobuild/agl/autobuild index 31e29f7..759f6be 100755 --- a/conf.d/autobuild/agl/autobuild +++ b/conf.d/autobuild/agl/autobuild @@ -16,10 +16,24 @@ THISFILE := $(lastword $(MAKEFILE_LIST)) BUILD_DIR := $(abspath $(dir $(THISFILE)/../../../../..)/build) +DEST := ${BUILD_DIR}/target -.PHONY: all clean distclean configure build package +.PHONY: all clean distclean configure build package help -all: build +all: help + +help: + @echo "List of targets available:" + @echo "" + @echo "- all" + @echo "- clean" + @echo "- distclean" + @echo "- configure" + @echo "- build" + @echo "- package" + @echo "" + @echo "Usage: ./conf.d/autobuild/agl/autobuild package DEST=${HOME}/opt" + @echo "Don't use your build dir as DEST as wgt file is generated at this location" clean: @([ -d ${BUILD_DIR} ] && make -C ${BUILD_DIR} clean) || echo Nothing to clean @@ -38,9 +52,8 @@ package: build @mkdir -p ${BUILD_DIR}/$@/lib @mkdir -p ${BUILD_DIR}/$@/htdocs @mkdir -p ${BUILD_DIR}/$@/data - @[ "${DEST}" ] && mkdir -p ${DEST} @cmake --build ${BUILD_DIR} --target widget - @[ "${DEST}" ] && cp ${BUILD_DIR}/*wgt ${DEST} + @mkdir -p ${DEST} && cp ${BUILD_DIR}/*wgt ${DEST} ${BUILD_DIR}/Makefile: @[ -d ${BUILD_DIR} ] || mkdir -p ${BUILD_DIR} diff --git a/conf.d/autobuild/linux/autobuild b/conf.d/autobuild/linux/autobuild index 31e29f7..759f6be 100755 --- a/conf.d/autobuild/linux/autobuild +++ b/conf.d/autobuild/linux/autobuild @@ -16,10 +16,24 @@ THISFILE := $(lastword $(MAKEFILE_LIST)) BUILD_DIR := $(abspath $(dir $(THISFILE)/../../../../..)/build) +DEST := ${BUILD_DIR}/target -.PHONY: all clean distclean configure build package +.PHONY: all clean distclean configure build package help -all: build +all: help + +help: + @echo "List of targets available:" + @echo "" + @echo "- all" + @echo "- clean" + @echo "- distclean" + @echo "- configure" + @echo "- build" + @echo "- package" + @echo "" + @echo "Usage: ./conf.d/autobuild/agl/autobuild package DEST=${HOME}/opt" + @echo "Don't use your build dir as DEST as wgt file is generated at this location" clean: @([ -d ${BUILD_DIR} ] && make -C ${BUILD_DIR} clean) || echo Nothing to clean @@ -38,9 +52,8 @@ package: build @mkdir -p ${BUILD_DIR}/$@/lib @mkdir -p ${BUILD_DIR}/$@/htdocs @mkdir -p ${BUILD_DIR}/$@/data - @[ "${DEST}" ] && mkdir -p ${DEST} @cmake --build ${BUILD_DIR} --target widget - @[ "${DEST}" ] && cp ${BUILD_DIR}/*wgt ${DEST} + @mkdir -p ${DEST} && cp ${BUILD_DIR}/*wgt ${DEST} ${BUILD_DIR}/Makefile: @[ -d ${BUILD_DIR} ] || mkdir -p ${BUILD_DIR} diff --git a/htdocs/AudioBinding.js b/htdocs/AudioBinding.js index 9771726..7105b20 100644 --- a/htdocs/AudioBinding.js +++ b/htdocs/AudioBinding.js @@ -1,5 +1,6 @@ var afb = new AFB("api", "mysecret"); var ws; + var halapi="HALNotSelected"; var evtidx=0; function getParameterByName(name, url) { @@ -26,25 +27,31 @@ var quiet=getParameterByName("quiet"); if (!quiet) quiet="99"; - - function init() { - ws = new afb.ws(onopen, onabort); - } - function onopen() { - document.getElementById("main").style.visibility = "visible"; - document.getElementById("connected").innerHTML = "Binder WS Active"; - document.getElementById("connected").style.background = "lightgreen"; - ws.onevent("*", gotevent); - } + - function onabort() { - document.getElementById("main").style.visibility = "hidden"; - document.getElementById("connected").innerHTML = "Connected Closed"; - document.getElementById("connected").style.background = "red"; + function init(elemid, api, verb, query) { + + function onopen() { + // check for active HALs + probeActiveHal (elemid, api, verb, query); + + document.getElementById("main").style.visibility = "visible"; + document.getElementById("connected").innerHTML = "Binder WS Active"; + document.getElementById("connected").style.background = "lightgreen"; + ws.onevent("*", gotevent); + } + function onabort() { + document.getElementById("main").style.visibility = "hidden"; + document.getElementById("connected").innerHTML = "Connected Closed"; + document.getElementById("connected").style.background = "red"; + + } + + ws = new afb.ws(onopen, onabort); } - + function replyok(obj) { console.log("replyok:" + JSON.stringify(obj)); document.getElementById("output").innerHTML = "OK: "+JSON.stringify(obj); @@ -67,9 +74,43 @@ ws.call(api+"/"+verb, {data:message}).then(replyok, replyerr); } - + + // On button click from HTML page function callbinder(api, verb, query) { console.log ("subscribe api="+api+" verb="+verb+" query=" +query); document.getElementById("question").innerHTML = "apicall: " + api+"/"+verb +" ("+ JSON.stringify(query)+")"; ws.call(api+"/"+verb, query).then(replyok, replyerr); - } \ No newline at end of file + } + + + // Retrieve the list of active HAL + function probeActiveHal (elemid, api, verb, query) { + var selectobj = document.getElementById(elemid); + + // onlick update selected HAL api + selectobj.onclick=function(){ + halapi= this.value; + console.log ("New Default HAL=" + halapi); + }; + + function gotit (result) { + + // display response as for normal onclick action + replyok(result); + var response=result.response; + + // fulfill select with avaliable active HAL + for (idx=0; idx + + + + references -
    -
  1. http://localhost:1234/alsa-core.html?haldev=scarlett-usb
  2. -
+ +

Simple AlsaHAL tests

+ +

+ Selected HAL + +
- -

Hello world test

-
    -
  1. - -
  2. -
    -
  3. -
  4. -
  5. + +
  6. +
  7. +
  8. +

diff --git a/nbproject/configurations.xml b/nbproject/configurations.xml index c02fba8..adb9376 100644 --- a/nbproject/configurations.xml +++ b/nbproject/configurations.xml @@ -27,6 +27,10 @@ ScarlettUsbHAL.c + + UnicensHAL.c + UnicensVol.c + HighLevelApiConf.c @@ -76,10 +80,10 @@ - - - - + + + true @@ -98,37 +102,24 @@ - + - ../../../opt/include ../../../opt/include/alsa - /usr/include/p11-kit-1 /usr/include/json-c - Shared-Interface build/ALSA-afb - - CONTROL_CDEV_RX="/dev/inic-usb-crx" - CONTROL_CDEV_TX="/dev/inic-usb-ctx" - MAX_SND_CARD=16 - alsa_lowlevel_EXPORTS - - + - ../../../opt/include/afb - ALSA-afb build/ALSA-afb - + - ../../../opt/include/afb - ALSA-afb ../../../opt/include/alsa /usr/include/json-c build/ALSA-afb @@ -136,10 +127,8 @@ - + - ../../../opt/include/afb - ALSA-afb ../../../opt/include/alsa /usr/include/json-c build/ALSA-afb @@ -147,10 +136,8 @@ - + - ../../../opt/include/afb - ALSA-afb ../../../opt/include/alsa /usr/include/json-c ../../../opt/include @@ -166,45 +153,72 @@ ex="false" tool="0" flavor2="3"> - + - + + HAL-afb/HAL-plugin + ../../../opt/include/alsa ../../../opt/include build/HAL-afb/HAL-plugin - + + HAL-afb/HAL-plugin + ../../../opt/include/alsa ../../../opt/include build/HAL-afb/HAL-plugin - + + ../../../opt/include/afb + HAL-afb/HAL-plugin + ../../../opt/include/alsa build/HAL-afb/HAL-plugin + + CONTROL_CDEV_RX="/dev/inic-usb-crx" + CONTROL_CDEV_TX="/dev/inic-usb-ctx" + MAX_SND_CARD=16 + - + - + - + + + + ../../../opt/include + build/HAL-afb/Unicens-USB + + + + + + build/HAL-afb/Unicens-USB + + + + + Shared-Interface ../../../opt/include @@ -213,7 +227,7 @@ - + /usr/include/json-c Shared-Interface @@ -257,9 +271,17 @@ - + + + + + ../../../opt/include/afb + ALSA-afb + + + @@ -290,24 +312,15 @@ - ../../../opt/include + HAL-afb/HAL-interface ../../../opt/include/alsa - /usr/include/p11-kit-1 /usr/include/json-c - HAL-afb/HAL-interface Shared-Interface + ../../../opt/include build/HAL-afb/HAL-interface - - - - HAL-afb/HAL-plugin - ../../../opt/include/alsa - - - @@ -332,6 +345,16 @@ + + + + HAL-afb/Unicens-USB + ../../../opt/include/alsa + Shared-Interface + HAL-afb/HAL-interface + + + -- cgit 1.2.3-korg