shutil.move('ble-sdk-arduino-0.9.5.beta/libraries/BLE/', '.')
shutil.rmtree('ble-sdk-arduino-0.9.5.beta')
+ # Apply Nordic lib patches
+ print 'Patching Nordic library...'
+ os.chdir(arduinolib_dir + '/libraries/BLE/')
+ os.system("find . -type f -exec dos2unix {} \;")
+ os.system("patch -p1 < " + src_dir + "/resource/csdk/connectivity/lib/arduino/arduino_due_ble.patch")
+
# Remove downloaded file
os.remove(nordiclib_zip_file)
4.1) ONE TIME ONLY - ADDITIONAL LIBRARIES (Time)
Arduino builds are dependent on latest Time library. Download it from here:
- I. http://playground.arduino.cc/Code/Time
+ I. http://playground.arduino.cc/uploads/Code/Time.zip
Place this library in the "ARDUINO_DIR/libraries/Time" folder where other libraries are present.
[P.S - The Time library files path should be as follows "ARDUINO_DIR/libraries/Time/Time/{***files***}"]
Some files in this library has windows style line endings, for patch to run properly, please execute following command:
4.2) ONE TIME ONLY - ADDITIONAL LIBRARIES (BLE)
Note: Prior to building for BLE Transport, following additional steps are required:
- (1) Download RedBearLab Arduino RBL_nRF8001 Library from link(https://github.com/RedBearLab/nRF8001/tree/25643e7b1b7da3740406325a471e3faa4b948747)
+ (1) Download RedBearLab Arduino RBL_nRF8001 Library from link(https://github.com/RedBearLab/nRF8001/archive/25643e7b1b7da3740406325a471e3faa4b948747.zip)
(2) Extract zip file and apply RBL patch(connectivity/lib/arduino/RBL_nRF8001.patch) to "RBL_nRF8001" folder by following below steps,
i) Go to downloaded RBL_Library Folder ("nRF8001-master/Arduino/libraries/RBL_nRF8001")
ii) Apply dos2unix for RBL_Library Folder and RBL Patch File (RBL_nRF8001.patch), if we have downloaded Library in Non UNIX Platform.
iii) Apply RBL Patch[connectivity\lib\arduino\RBL_nRF8001.patch] by using the below command
patch -p1 < RBL_Patch_File_Location(RBL_nRF8001.patch)
(3) Copy the patched RBL_nRF8001 Library and place it in "arduino-<x.x.x>/libraries" folder
- (4) Download Nordic Arduino BLE library [Tag: "0.9.5.Beta" Version] from the link (https://github.com/NordicSemiconductor/ble-sdk-arduino).
+ (4) Download Nordic Arduino BLE library [Tag: "0.9.5.Beta" Version] from the link (https://github.com/NordicSemiconductor/ble-sdk-arduino/archive/0.9.5.beta.zip).
Extract the zip file and copy the "BLE" folder available under "libraries" folder and place it in "arduino-<x.x.x>/libraries" folder
i) Apply dos2unix for the "BLE" folder.
ii) Go to the BLE folder and apply the patch[connectivity\lib\arduino\arduino_due_ble.patch] using the below command.
* @retval #CA_STATUS_FAILED Operation failed
*/
CALEData_t *CACreateBLEData(const CARemoteEndpoint_t *remoteEndpoint, const void *data,
- uint32_t dataLength);
+ uint32_t dataLength);
/**
* @brief Used to free the BLE information stored in the sender/receiver queues.
* @retval #CA_STATUS_FAILED Operation failed
*/
typedef CAResult_t (*CABLEClientDataReceivedCallback)(const char *remoteAddress,
- const char *serviceUUID, const void *data, uint32_t dataLength, uint32_t *sentLength);
+ const char *serviceUUID, const void *data, uint32_t dataLength,
+ uint32_t *sentLength);
/**
* @brief This will be used to notify that network packet recieved from GATTServer to adapter layer.
/**
* @brief Provides the BD address of the local adapter.
- * @param local_address [IN] pointer to the location where bd address needs to be stored.
+ * @param local_address [OUT] pointer to the location where bd address needs to be stored.
*
- * @return NONE
+ * @return #CA_STATUS_OK or Appropriate error code
+ * @retval #CA_STATUS_OK Successful
+ * @retval #CA_STATUS_INVALID_PARAM Invalid input argumets
+ * @retval #CA_STATUS_FAILED Operation failed
*/
-void CAGetLEAddress(char **local_address);
+CAResult_t CAGetLEAddress(char **local_address);
/**
* @brief Used to start Gatt Server thread for service creation and advertise ble service.
* @retval #CA_STATUS_INVALID_PARAM Invalid input argumets
* @retval #CA_STATUS_FAILED Operation failed
*/
-CAResult_t CAUpdateCharacteristicsInGattServer(const char *charValue,
- uint32_t charValueLen);
+CAResult_t CAUpdateCharacteristicsToAllGattClients(const char *charValue,
+ uint8_t charValueLen);
/**
* @brief Used to start CAStartBleGattClientThread for initializing Gatt Client
* @retval #CA_STATUS_FAILED Operation failed
*/
CAResult_t CAUpdateCharacteristicsToGattServer(const char *remoteAddress, const char *data,
- const int32_t dataLen, CALETransferType_t type,
+ const uint32_t dataLen, CALETransferType_t type,
const int32_t position);
/**
* @retval #CA_STATUS_INVALID_PARAM Invalid input argumets
* @retval #CA_STATUS_FAILED Operation failed
*/
-CAResult_t CAUpdateCharacteristicsToAllGattServers(const char *data, int32_t dataLen);
+CAResult_t CAUpdateCharacteristicsToAllGattServers(const char *data, uint32_t dataLen);
/**
* @brief Used to store upper layer callback locally which will be used to send the data to
return CA_STATUS_OK;
}
-void CAGetLEAddress(char **leAddress)
+CAResult_t CAGetLEAddress(char **leAddress)
{
OIC_LOG(DEBUG, TAG, "IN");
- VERIFY_NON_NULL_VOID(leAddress, TAG, "leAddress");
+ VERIFY_NON_NULL(leAddress, TAG, "leAddress");
g_leAddress = ble_getAddress();
/**
if (NULL == *leAddress)
{
OIC_LOG(ERROR, TAG, "malloc fail");
- return;
+ return CA_MEMORY_ALLOC_FAILED;
}
memcpy(*leAddress, g_leAddress, CA_MACADDR_SIZE);
OIC_LOG(DEBUG, TAG, "OUT");
- return;
+ return CA_STATUS_OK;
}
CAResult_t CASetLEAdapterStateChangedCb(CALEDeviceStateChangedCallback callback)
return CA_STATUS_OK;
}
-CAResult_t CAUpdateCharacteristicsInGattServer(const char *char_value,
- uint32_t valueLength)
+CAResult_t CAUpdateCharacteristicsToAllGattClients(const char *char_value,
+ uint8_t valueLength)
{
// ble_write_bytes() api can send only max of 255 bytes at a time
// This function shall never be called to send more than 255 bytes by the fragmentation logic.
- if(valueLength > 255)
- {
- OIC_LOG_V(ERROR, TAG, "Error:Max 255");
- return CA_STATUS_INVALID_PARAM;
- }
// Currently ble_write_bytes api returns void.
ble_write_bytes((unsigned char *)char_value, (unsigned char)valueLength);
return CA_STATUS_OK;
* @file
*
* This file contains the APIs related to the GATT Server functionalities.
- * Creation of the GattServer with the characteristics. Enabling the
+ * Creation of the GATT Server with the characteristics. Enabling the
* advertisement and updating the characteristics for the response and
* notifying the change of characteristcs for the request will be done here.
*/
OIC_LOG_V(ERROR, TAG, "ble init fail: %d", result);
return CA_STATUS_FAILED;
}
- uint32_t iter = 0;
/**
* Below for loop is to process the BLE Events received from BLE Shield.
* BLE Events includes BLE Shield Address Added as a patch to RBL Library.
*/
- for (iter = 0; iter < MAX_EVENT_COUNT; iter++)
+ for (int iter = 0; iter < MAX_EVENT_COUNT; iter++)
{
CACheckData();
}
}
char *leAddress = NULL;
- CAGetLEAddress(&leAddress);
+ CAResult_t res = CAGetLEAddress(&leAddress);
+ if (CA_STATUS_OK != res)
+ {
+ OIC_LOG(ERROR, TAG, "CAGetLEAddress has failed");
+ return res;
+ }
+
+ if (NULL == leAddress)
+ {
+ OIC_LOG(ERROR, TAG, "Failed to get Le addr");
+ return CA_STATUS_FAILED;
+ }
+
OIC_LOG_V(DEBUG, TAG, "leAddress = %s", leAddress);
/**
return;
}
- g_coapBuffer = (char *)OICCalloc(g_packetDataLen, sizeof(char));
+ g_coapBuffer = (char *)OICCalloc((size_t)g_packetDataLen, sizeof(char));
if (NULL == g_coapBuffer)
{
OIC_LOG(ERROR, TAG, "malloc");
if (CA_STATUS_OK != result)
{
+ OIC_LOG(ERROR, TAG, "Generate header failed");
return -1;
}
if (!CAIsBleConnected())
{
- OIC_LOG(DEBUG, TAG, "le not conn");
+ OIC_LOG(ERROR, TAG, "le not conn");
+ return -1;
+ }
+
+ result = CAUpdateCharacteristicsToAllGattClients(header, CA_HEADER_LENGTH);
+ if (CA_STATUS_OK != result)
+ {
+ OIC_LOG(ERROR, TAG, "Update characteristics failed");
return -1;
}
- CAUpdateCharacteristicsInGattServer(header, CA_HEADER_LENGTH);
int32_t dataLimit = dataLen / CA_SUPPORTED_BLE_MTU_SIZE;
- int32_t iter = 0;
- for (iter = 0; iter < dataLimit; iter++)
+ for (int32_t iter = 0; iter < dataLimit; iter++)
{
- CAUpdateCharacteristicsInGattServer((data + (iter * CA_SUPPORTED_BLE_MTU_SIZE)),
- CA_SUPPORTED_BLE_MTU_SIZE);
+ result = CAUpdateCharacteristicsToAllGattClients((data +
+ (iter * CA_SUPPORTED_BLE_MTU_SIZE)),
+ CA_SUPPORTED_BLE_MTU_SIZE);
+ if (CA_STATUS_OK != result)
+ {
+ OIC_LOG(ERROR, TAG, "Update characteristics failed");
+ return -1;
+ }
+ CABleDoEvents();
+ }
+
+ uint8_t remainingLen = dataLen % CA_SUPPORTED_BLE_MTU_SIZE;
+ if(remainingLen)
+ {
+ result = CAUpdateCharacteristicsToAllGattClients((data +
+ (dataLimit * CA_SUPPORTED_BLE_MTU_SIZE)),
+ remainingLen);
+ if (CA_STATUS_OK != result)
+ {
+ OIC_LOG(ERROR, TAG, "Update characteristics failed");
+ return -1;
+ }
CABleDoEvents();
}
- CAUpdateCharacteristicsInGattServer((data + (dataLimit * CA_SUPPORTED_BLE_MTU_SIZE)),
- dataLen % CA_SUPPORTED_BLE_MTU_SIZE);
- CABleDoEvents();
OIC_LOG(DEBUG, TAG, "writebytes done");
OIC_LOG(DEBUG, TAG, "OUT");
// Arduino BLEWrite doesnot return value. So, Return the received DataLength