You are reading a single comment by @JumJum and its replies. Click here to read the full conversation.
  • During porting jswrap_nrf_bluetooth_updateServices to ESP32, I found calls to nrf relevant functions.
    ESP32 uses different walks through all of this. Most common point is use of UUIDs and handles.

    Searching for a better solution, found this jsvObjectGetChild(execInfo.hiddenRoot,"B­LE_SVC_D",0);
    Idea now is to move UUIDs and handles to this object to be more general. Value is already there.

    For testing of concept, this function was born. In my eyes it looks very complex.
    So I've 2 questions:

    • whats your feedback to hold uuids and handle in BLE_SVC_D
    • is there a better way to read value from BLE_SVC_D ?

      JsVar *jswrap_ESP32_get_Char_Value(JsVar *serviceUUID,JsVar *charUUID){
      	JsVar *serviceKey; JsvObjectIterator serviceIt; JsVar *serviceData;
      	JsVar *servicesData = jsvObjectGetChild(execInfo.hiddenRoot,"B­LE_SVC_D",0);
      	JsVar *charKey; JsvObjectIterator charIt; JsVar *charData;
      	JsVar *value;
      jsvObjectIteratorNew(&serviceIt,services­Data);
      	while(jsvObjectIteratorHasValue(&service­It)){
      		serviceKey = jsvObjectIteratorGetKey(&serviceIt);
      		if(jsvIsEqual(serviceKey,serviceUUID)){
      			serviceData = jsvObjectIteratorGetValue(&serviceIt);
      			jsvObjectIteratorNew(&charIt,serviceData­);
      			while(jsvObjectIteratorHasValue(&charIt)­){
      				charKey = jsvObjectIteratorGetKey(&charIt);
      				if(jsvIsEqual(charKey,charUUID)){
      					charData = jsvObjectIteratorGetValue(&charIt);
      					value = jsvObjectGetChild(charData,"value",0);
      					jsvUnLock(charData);
      				}
      				jsvUnLock(charKey);
      				jsvObjectIteratorNext(&charIt);
      			}
      			jsvObjectIteratorFree(&charIt);
      			jsvUnLock(serviceData);
      		}
          jsvUnLock(serviceKey);
      		jsvObjectIteratorNext(&serviceIt);
      	}
      	jsvObjectIteratorFree(&serviceIt);
      	jsvUnLock(servicesData);
      	return value;
      }
      
About

Avatar for JumJum @JumJum started