/** * Output the contents of the specified buffer (in hex) with the specified priority level. * * @param level - DEBUG, INFO, WARNING, ERROR, FATAL * @param tag - Module name * @param buffer - pointer to buffer of bytes * @param bufferSize - max number of byte in buffer */ void OCLogBuffer(LogLevel level, const char * tag, const uint8_t * buffer, uint16_t bufferSize) { if (!buffer || !tag || (bufferSize == 0)) { return; } // No idea why the static initialization won't work here, it seems the compiler is convinced // that this is a variable-sized object. char lineBuffer[LINE_BUFFER_SIZE]; memset(lineBuffer, 0, sizeof lineBuffer); int lineIndex = 0; int i; for (i = 0; i < bufferSize; i++) { // Format the buffer data into a line snprintf(&lineBuffer[lineIndex*3], sizeof(lineBuffer)-lineIndex*3, "%02X ", buffer[i]); lineIndex++; // Output 16 values per line if (((i+1)%16) == 0) { OCLogv(level, tag, "%s", lineBuffer); memset(lineBuffer, 0, sizeof lineBuffer); lineIndex = 0; } } // Output last values in the line, if any if (bufferSize % 16) { OCLogv(level, tag, "%s", lineBuffer); } }
uint32_t CASendLEMulticastData(void *data, uint32_t dataLen) { OCLog(DEBUG, CALEADAPTER_TAG, "IN"); //Input validation VERIFY_NON_NULL(data, NULL, "Data is null"); if (0 >= dataLen) { OCLog(ERROR, CALEADAPTER_TAG, "Invalid Parameter"); return 0; } CAResult_t result = CA_STATUS_FAILED; #ifdef __TIZEN__ pthread_mutex_lock(&gBleIsServerMutex); if (gIsServer) { result = CAUpdateCharacteristicsInGattServer(data, dataLen); if (CA_STATUS_OK != result) { OCLogv(ERROR, CALEADAPTER_TAG, "[CASendLEMulticastData] updating data in server is failed"); pthread_mutex_unlock(&gBleIsServerMutex); return 0; } } else { result = CAUpdateCharacteristicsToAllGattServers(data, dataLen); if (CA_STATUS_OK != result) { OCLogv(ERROR, CALEADAPTER_TAG, "[SendLEMulticastDataToAll] multicasting data to servers failed" ); pthread_mutex_unlock(&gBleIsServerMutex); return 0; } } pthread_mutex_unlock(&gBleIsServerMutex); #else char *tempPath = "temp_path"; updateCharacteristicsInGattServer(tempPath, (char *) data, dataLen); #endif //#ifdef __TIZEN__ OCLog(DEBUG, CALEADAPTER_TAG, "OUT"); return dataLen; }
uint32_t CASendLEUnicastData(const CARemoteEndpoint_t *endpoint, void *data, uint32_t dataLen) { OCLog(DEBUG, CALEADAPTER_TAG, "IN"); //Input validation VERIFY_NON_NULL(endpoint, NULL, "Remote endpoint is null"); VERIFY_NON_NULL(data, NULL, "Data is null"); CAResult_t result = CA_STATUS_FAILED; #ifdef __TIZEN__ pthread_mutex_lock(&gBleIsServerMutex); if (gIsServer) { result = CAUpdateCharacteristicsInGattServer(data, dataLen); if (CA_STATUS_OK != result) { OCLogv(ERROR, CALEADAPTER_TAG, "[SendLEUnicastData] sending unicast data to [%s] failed\n", endpoint->addressInfo.BT.btMacAddress); pthread_mutex_unlock(&gBleIsServerMutex); return 0; } } else { result = CAUpdateCharacteristicsToGattServer(endpoint->addressInfo.BT.btMacAddress, data, dataLen, UNICAST, 0); if (CA_STATUS_OK != result) { OCLogv(ERROR, CALEADAPTER_TAG, "[SendLEUnicastData] sending unicast data to [%s] failed\n", endpoint->addressInfo.BT.btMacAddress); pthread_mutex_unlock(&gBleIsServerMutex); return 0; } } pthread_mutex_unlock(&gBleIsServerMutex); #else char *tempPath = "temp_path"; updateCharacteristicsInGattServer(tempPath, (char *) data, dataLen); #endif //#ifdef __TIZEN__ OCLog(DEBUG, CALEADAPTER_TAG, "OUT"); return dataLen; }