Skip to content
This repository has been archived by the owner on Nov 11, 2024. It is now read-only.

Commit

Permalink
Adjustments for new ucx version (#1088)
Browse files Browse the repository at this point in the history
The apis in the ucx module have changed and hence update was required
here. We now support version 1.1.0 of u-ConnectXpress

It is no longer necessary to block the AT-log during BLE and Wifi
scan operations. The problem earlier was due to hardware problems
in the test system.
  • Loading branch information
plerup authored Jan 31, 2024
1 parent 2a4e559 commit 7261fd7
Show file tree
Hide file tree
Showing 12 changed files with 73 additions and 101 deletions.
19 changes: 7 additions & 12 deletions ble/src/gen2/u_ble_gap_extmod.c
Original file line number Diff line number Diff line change
Expand Up @@ -134,8 +134,8 @@ int32_t uBleGapSetConnectCallback(uDeviceHandle_t devHandle, uBleGapConnectCallb
errorCode = checkCreateBleContext(pInstance);
if (errorCode == 0) {
((uBleDeviceState_t *)(pInstance->pBleContext))->connectCallback = cb;
uCxUrcRegisterBluetoothConnect(pUcxHandle, bleConnectCallback);
uCxUrcRegisterBluetoothDisconnect(pUcxHandle, bleDisconnectCallback);
uCxBluetoothRegisterConnect(pUcxHandle, bleConnectCallback);
uCxBluetoothRegisterDisconnect(pUcxHandle, bleDisconnectCallback);
errorCode = (int32_t)U_ERROR_COMMON_SUCCESS;
}
}
Expand Down Expand Up @@ -164,14 +164,12 @@ int32_t uBleGapScan(uDeviceHandle_t devHandle,
uCxType = U_DISCOVERY_TYPE_DISCOVER_ALL;
}
// Need to turn off possible AT debug printouts during the scanning
bool logWasOn = uCxLogIsEnabled();
uCxLogDisable();
// Start and loop over all received discoveries
uCxBeginBluetoothDiscoveryEx3(pUcxHandle, uCxType,
activeScan ? U_DISCOVERY_MODE_ACTIVE : U_DISCOVERY_MODE_PASSIVE,
(int32_t)timeousMs);
uCxBluetoothDiscoveryEx_t uCxResp;
while (uCxBluetoothDiscoveryExGetResponse3(pUcxHandle, &uCxResp)) {
uCxBluetoothDiscovery3Begin(pUcxHandle, uCxType,
activeScan ? U_DISCOVERY_MODE_ACTIVE : U_DISCOVERY_MODE_PASSIVE,
(int32_t)timeousMs);
uCxBluetoothDiscovery_t uCxResp;
while (uCxBluetoothDiscovery3GetNext(pUcxHandle, &uCxResp)) {
uBleScanResult_t result;
uCxBdAddressToString(&uCxResp.bd_addr, result.address, sizeof(result.address));
int32_t length = MIN(sizeof(result.data), uCxResp.data.length);
Expand All @@ -183,9 +181,6 @@ int32_t uBleGapScan(uDeviceHandle_t devHandle,
cb(&result);
}
errorCode = uCxEnd(pUcxHandle);
if (logWasOn) {
uCxLogEnable();
}
if (errorCode == U_CX_ERROR_CMD_TIMEOUT) {
// *** UCX WORKAROUND FIX ***
// Ignore timeout for now, not possible to set ucx timeout value
Expand Down
20 changes: 10 additions & 10 deletions ble/src/gen2/u_ble_gatt_extmod.c
Original file line number Diff line number Diff line change
Expand Up @@ -137,9 +137,9 @@ int32_t uBleGattDiscoverServices(uDeviceHandle_t devHandle, int32_t connHandle,
int32_t errorCode = (int32_t)U_ERROR_COMMON_INVALID_PARAMETER;
uCxHandle_t *pUcxHandle = pShortRangePrivateGetUcxHandle(devHandle);
if ((pUcxHandle != NULL) && (cb != NULL)) {
uCxBeginGattClientDiscoverPrimaryServices(pUcxHandle, connHandle);
uCxGattClientDiscoverPrimaryServicesBegin(pUcxHandle, connHandle);
uCxGattClientDiscoverPrimaryServices_t resp;
while (uCxGattClientDiscoverPrimaryServicesGetResponse(pUcxHandle, &resp)) {
while (uCxGattClientDiscoverPrimaryServicesGetNext(pUcxHandle, &resp)) {
char *pUuid;
if (binToHex(resp.uuid.pData, resp.uuid.length, &pUuid)) {
cb(connHandle, resp.start_handle, resp.end_handle, pUuid);
Expand All @@ -158,9 +158,9 @@ int32_t uBleGattDiscoverChar(uDeviceHandle_t devHandle,
int32_t errorCode = (int32_t)U_ERROR_COMMON_INVALID_PARAMETER;
uCxHandle_t *pUcxHandle = pShortRangePrivateGetUcxHandle(devHandle);
if ((pUcxHandle != NULL) && (cb != NULL)) {
uCxBeginGattClientDiscoverServiceChars(pUcxHandle, connHandle, 1, 65535);
uCxGattClientDiscoverServiceCharsBegin(pUcxHandle, connHandle, 1, 65535);
uCxGattClientDiscoverServiceChars_t resp;
while (uCxGattClientDiscoverServiceCharsGetResponse(pUcxHandle, &resp)) {
while (uCxGattClientDiscoverServiceCharsGetNext(pUcxHandle, &resp)) {
char *pUuid;
if (binToHex(resp.uuid.pData, resp.uuid.length, &pUuid)) {
cb(connHandle, resp.attr_handle, resp.properties.pData[0], resp.value_handle, pUuid);
Expand Down Expand Up @@ -196,7 +196,7 @@ int32_t uBleGattSetNotificationCallback(uDeviceHandle_t devHandle,
errorCode = checkCreateBleContext(pInstance);
if (errorCode == 0) {
((uBleDeviceState_t *)(pInstance->pBleContext))->notifyCallback = cb;
uCxUrcRegisterGattClientNotification(pUcxHandle, notificationCallback);
uCxGattClientRegisterNotification(pUcxHandle, notificationCallback);
errorCode = (int32_t)U_ERROR_COMMON_SUCCESS;
}
}
Expand All @@ -217,7 +217,7 @@ int32_t uBleGattSetWriteCallback(uDeviceHandle_t devHandle,
errorCode = checkCreateBleContext(pInstance);
if (errorCode == 0) {
((uBleDeviceState_t *)(pInstance->pBleContext))->writeCallback = cb;
uCxUrcRegisterGattServerNotification(pUcxHandle, writeCallback);
uCxGattServerRegisterNotification(pUcxHandle, writeCallback);
errorCode = (int32_t)U_ERROR_COMMON_SUCCESS;
}
}
Expand All @@ -233,14 +233,14 @@ int32_t uBleGattReadValue(uDeviceHandle_t devHandle,
int32_t errorCode = (int32_t)U_ERROR_COMMON_INVALID_PARAMETER;
uCxHandle_t *pUcxHandle = pShortRangePrivateGetUcxHandle(devHandle);
if (pUcxHandle != NULL) {
uCxGattClientRead_t resp;
errorCode = uCxBeginGattClientRead(pUcxHandle, connHandle, valueHandle, &resp);
uByteArray_t resp;
errorCode = uCxGattClientReadBegin(pUcxHandle, connHandle, valueHandle, &resp);
if (errorCode == 0) {
int32_t len = resp.hex_data.length;
int32_t len = resp.length;
if (len > valueLength) {
len = valueLength;
}
memcpy(pValue, resp.hex_data.pData, len);
memcpy(pValue, resp.pData, len);
}
errorCode = uCxEnd(pUcxHandle);
}
Expand Down
14 changes: 7 additions & 7 deletions ble/src/gen2/u_ble_sps_extmod.c
Original file line number Diff line number Diff line change
Expand Up @@ -170,14 +170,14 @@ int32_t uBleSpsConnectSps(uDeviceHandle_t devHandle,
uCxHandle_t *pUcxHandle = pShortRangePrivateGetUcxHandle(devHandle);
if ((pUcxHandle != NULL) && (pInstance != NULL)) {
uPortMutexLock(gMutex);
uCxUrcRegisterBluetoothConnect(pUcxHandle, bleConnectCallback);
uCxBluetoothRegisterConnect(pUcxHandle, bleConnectCallback);
errorCode = uBleGapConnect(devHandle, pAddress);
if (errorCode == 0) {
errorCode = uPortSemaphoreTryTake(gSemaphore, 5000);
if (errorCode == 0) {
uCxUrcRegisterSpsConnect(pUcxHandle, spsConnectCallback);
uCxUrcRegisterSpsDisconnect(pUcxHandle, spsDisconnectCallback);
uCxUrcRegisterSpsDataAvailable(pUcxHandle, spsDataAvailableCallback);
uCxSpsRegisterConnect(pUcxHandle, spsConnectCallback);
uCxSpsRegisterDisconnect(pUcxHandle, spsDisconnectCallback);
uCxSpsRegisterDataAvailable(pUcxHandle, spsDataAvailableCallback);
if (pConnParams != NULL) {
// Setup the parameters currently available in uCx
errorCode = uCxBluetoothSetConnectionIntervalMin(pUcxHandle,
Expand Down Expand Up @@ -223,7 +223,7 @@ int32_t uBleSpsReceive(uDeviceHandle_t devHandle, int32_t channel, char *pData,
uBleDeviceState_t *pState = pGetBleContext(pUShortRangePrivateGetInstance(devHandle));
uCxHandle_t *pUcxHandle = pShortRangePrivateGetUcxHandle(devHandle);
if ((pUcxHandle != NULL) && (pState != NULL)) {
errorCodeOrLength = uCxSpsReadBinary(pUcxHandle, pState->spsConnHandle, length, (uint8_t *)pData);
errorCodeOrLength = uCxSpsRead(pUcxHandle, pState->spsConnHandle, length, (uint8_t *)pData);
}
return errorCodeOrLength;
}
Expand All @@ -237,8 +237,8 @@ int32_t uBleSpsSend(uDeviceHandle_t devHandle, int32_t channel, const char *pDat
if ((pUcxHandle != NULL) && (pInstance != NULL) && (pState != NULL)) {
int32_t received = 0;
do {
errorCodeOrLength = uCxSpsWriteBinary(pUcxHandle, pState->spsConnHandle,
(uint8_t *)pData, MIN(1000, length - received));
errorCodeOrLength = uCxSpsWrite(pUcxHandle, pState->spsConnHandle,
(uint8_t *)pData, MIN(1000, length - received));
if (errorCodeOrLength > 0) {
received += errorCodeOrLength;
pData += errorCodeOrLength;
Expand Down
3 changes: 2 additions & 1 deletion ble/test/u_ble_nus_test.c
Original file line number Diff line number Diff line change
Expand Up @@ -216,7 +216,8 @@ U_PORT_TEST_FUNCTION("[bleNus]", "bleNusClient")
U_TEST_PRINT_LINE("try #%d", i + 1);
U_PORT_TEST_ASSERT(uBleGapScan(gDeviceHandle,
U_BLE_GAP_SCAN_DISCOVER_ALL_ONCE,
true, 10000,
true,
9500, // This value is due to the current fixed AT-timeout in ucx (10s)
scanResponse) == 0);
}
U_PORT_TEST_ASSERT(SERVER_FOUND);
Expand Down
8 changes: 0 additions & 8 deletions common/mqtt_client/test/u_mqtt_client_test.c
Original file line number Diff line number Diff line change
Expand Up @@ -161,16 +161,8 @@ static char gSerialNumber[U_SECURITY_SERIAL_NUMBER_MAX_LENGTH_BYTES];
/** Data to send over MQTT; all printable characters.
*/
static const char gSendData[] =
#ifndef U_UCONNECT_GEN2
"abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ"
"0123456789\"!#$%&'()*+,-./:;<=>?@[\\]^_`{|}~";
#else
// *** UCX WORKAROUND FIX ***
// Ucx currently only supports publishing data as strings.
// Hence we must avoid quote character for now.
"abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ"
"0123456789!#$%&'()*+,-./:;<=>?@[\\]^_`{|}~";
#endif

/** Flag to indicate that the disconnect callback
* has been called.
Expand Down
4 changes: 2 additions & 2 deletions common/security/src/u_security_credential.c
Original file line number Diff line number Diff line change
Expand Up @@ -447,10 +447,10 @@ int32_t uSecurityCredentialStore(uDeviceHandle_t devHandle,
uCxHandle_t *pUcxHandle = pShortRangePrivateGetUcxHandle(devHandle);
if (pUcxHandle != NULL) {
if (pPassword == NULL) {
errorCode = uCxSecurityUploadCertificate2(pUcxHandle, (uCertType_t)type, pName,
errorCode = uCxSecurityCertificateUpload2(pUcxHandle, (uCertType_t)type, pName,
(uint8_t *)pContents, size);
} else {
errorCode = uCxSecurityUploadCertificate3(pUcxHandle, (uCertType_t)type, pName,
errorCode = uCxSecurityCertificateUpload3(pUcxHandle, (uCertType_t)type, pName,
pPassword, (uint8_t *)pContents, size);
}
}
Expand Down
6 changes: 3 additions & 3 deletions common/short_range/src/gen2/u_short_range.c
Original file line number Diff line number Diff line change
Expand Up @@ -407,7 +407,7 @@ uShortRangeModuleType_t uShortRangeDetectModule(uDeviceHandle_t devHandle)
uCxHandle_t *pUcxHandle = pShortRangePrivateGetUcxHandle(devHandle);
if (pUcxHandle != NULL) {
const char *pIdStr;
if (uCxBeginGeneralGetDeviceModelIdentification(pUcxHandle, &pIdStr)) {
if (uCxGeneralGetDeviceModelIdentificationBegin(pUcxHandle, &pIdStr)) {
for (int32_t i = 0; i < (int32_t)gModuleInfoCount; ++i) {
if (!strncmp(pIdStr, gModuleInfo[i].pName, strlen(gModuleInfo[i].pName))) {
moduleType = gModuleInfo[i].moduleType;
Expand Down Expand Up @@ -459,7 +459,7 @@ int32_t uShortRangeGetFirmwareVersionStr(uDeviceHandle_t devHandle,
uCxHandle_t *pUcxHandle = pShortRangePrivateGetUcxHandle(devHandle);
if (pUcxHandle != NULL) {
const char *pVersion;
if (uCxBeginGeneralGetSoftwareVersion(pUcxHandle, &pVersion)) {
if (uCxGeneralGetSoftwareVersionBegin(pUcxHandle, &pVersion)) {
memset(pStr, 0, size);
strncpy(pStr, pVersion, size - 1);
errorCodeOrLength = strlen(pVersion);
Expand All @@ -476,7 +476,7 @@ int32_t uShortRangeGetSerialNumber(uDeviceHandle_t devHandle, char *pSerialNumbe
uCxHandle_t *pUcxHandle = pShortRangePrivateGetUcxHandle(devHandle);
if (pUcxHandle != NULL) {
const char *pSerial;
if (uCxBeginGeneralGetSerialNumber(pUcxHandle, &pSerial)) {
if (uCxGeneralGetSerialNumberBegin(pUcxHandle, &pSerial)) {
strcpy(pSerialNumber, pSerial);
errorCodeOrLength = strlen(pSerial);
}
Expand Down
2 changes: 1 addition & 1 deletion common/short_range/test/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,4 +2,4 @@
The u-connectExpress versions that these tests are run on are as follows:

- NINA-W15: 5.2.2.
- NORA-W36: u-connectExpress second generation, version 1.0.0.
- NORA-W36: u-connectExpress second generation, version 1.1.0.
29 changes: 11 additions & 18 deletions wifi/src/gen2/u_wifi.c
Original file line number Diff line number Diff line change
Expand Up @@ -190,8 +190,8 @@ int32_t uWifiSetConnectionStatusCallback(uDeviceHandle_t devHandle,
uShortRangePrivateInstance_t *pInstance = pUShortRangePrivateGetInstance(devHandle);
if ((pUcxHandle != NULL) && (pInstance != NULL)) {
errorCode = (int32_t)U_ERROR_COMMON_SUCCESS;
uCxUrcRegisterWifiLinkUp(pUcxHandle, WiFiLinkUpCallback);
uCxUrcRegisterWifiLinkDown(pUcxHandle, WiFiLinkDownCallback);
uCxWifiRegisterLinkUp(pUcxHandle, WiFiLinkUpCallback);
uCxWifiRegisterLinkDown(pUcxHandle, WiFiLinkDownCallback);
pInstance->pWifiConnectionStatusCallback = pCallback;
pInstance->pWifiConnectionStatusCallbackParameter = pCallbackParameter;
}
Expand All @@ -211,10 +211,10 @@ int32_t uWifiSetNetworkStatusCallback(uDeviceHandle_t devHandle,
uShortRangePrivateInstance_t *pInstance = pUShortRangePrivateGetInstance(devHandle);
if ((pUcxHandle != NULL) && (pInstance != NULL)) {
errorCode = (int32_t)U_ERROR_COMMON_SUCCESS;
uCxUrcRegisterWifiStationNetworkUp(pUcxHandle, wiFiUpCallback);
uCxUrcRegisterWifiStationNetworkDown(pUcxHandle, wiFiDownCallback);
uCxUrcRegisterWifiApNetworkUp(pUcxHandle, wiFiUpCallback);
uCxUrcRegisterWifiApNetworkDown(pUcxHandle, wiFiUpCallback);
uCxWifiRegisterStationNetworkUp(pUcxHandle, wiFiUpCallback);
uCxWifiRegisterStationNetworkDown(pUcxHandle, wiFiDownCallback);
uCxWifiRegisterApNetworkUp(pUcxHandle, wiFiUpCallback);
uCxWifiRegisterApNetworkDown(pUcxHandle, wiFiUpCallback);
pInstance->pNetworkStatusCallback = pCallback;
pInstance->pNetworkStatusCallbackParameter = pCallbackParameter;
uShortRangeUnlock();
Expand All @@ -237,7 +237,7 @@ int32_t uWifiStationConnect(uDeviceHandle_t devHandle, const char *pSsid,
if (pSsid != NULL) {
uCxWifiStationStatus_t resp;
resp.type = U_CX_WIFI_STATION_STATUS_RSP_TYPE_WIFI_STATUS_ID_STR;
if (uCxBeginWifiStationStatus(pUcxHandle, U_WIFI_STATUS_ID_SSID, &resp) &&
if (uCxWifiStationStatusBegin(pUcxHandle, U_WIFI_STATUS_ID_SSID, &resp) &&
(resp.rspWifiStatusIdStr.ssid[0] != 0)) {
// Already connected, check if same ssid
if (strcmp(resp.rspWifiStatusIdStr.ssid, pSsid) == 0) {
Expand Down Expand Up @@ -315,7 +315,7 @@ bool uWifiStationHasStoredConfig(uDeviceHandle_t devHandle)
uCxHandle_t *pUcxHandle = pShortRangePrivateGetUcxHandle(devHandle);
if (pUcxHandle != NULL) {
uCxWifiStationGetConnectionParams_t params;
int32_t errorCode = uCxBeginWifiStationGetConnectionParams(pUcxHandle,
int32_t errorCode = uCxWifiStationGetConnectionParamsBegin(pUcxHandle,
WLAN_HANDLE, &params);
has = errorCode == 0 && strlen(params.ssid) > 0;
uCxEnd(pUcxHandle);
Expand Down Expand Up @@ -373,8 +373,7 @@ bool uWifiAccessPointHasStoredConfig(uDeviceHandle_t devHandle)
uCxHandle_t *pUcxHandle = pShortRangePrivateGetUcxHandle(devHandle);
if (pUcxHandle != NULL) {
uCxWifiApGetConnectionParams_t params;
int32_t errorCode =
uCxBeginWifiApGetConnectionParams(pUcxHandle, &params);
int32_t errorCode = uCxWifiApGetConnectionParamsBegin(pUcxHandle, &params);
has = errorCode == 0 && strlen(params.ssid) > 0;
}
return has;
Expand All @@ -386,13 +385,10 @@ int32_t uWifiStationScan(uDeviceHandle_t devHandle, const char *pSsid,
int32_t errorCode = (int32_t)U_ERROR_COMMON_INVALID_PARAMETER;
uCxHandle_t *pUcxHandle = pShortRangePrivateGetUcxHandle(devHandle);
if ((pUcxHandle != NULL) && (pCallback != NULL)) {
// Need to turn off possible AT debug printouts during the scanning
bool logWasOn = uCxLogIsEnabled();
uCxLogDisable();
uCxBeginWifiStationScan(pUcxHandle);
uCxWifiStationScanBegin(pUcxHandle);
uCxWifiStationScan_t uCxresult;
uWifiScanResult_t result;
while (uCxWifiStationScanGetResponse(pUcxHandle, &uCxresult)) {
while (uCxWifiStationScanGetNext(pUcxHandle, &uCxresult)) {
result.authSuiteBitmask = uCxresult.authentication_suites;
memcpy(result.bssid, uCxresult.bssid.address, sizeof(result.bssid));
result.channel = uCxresult.channel;
Expand All @@ -406,9 +402,6 @@ int32_t uWifiStationScan(uDeviceHandle_t devHandle, const char *pSsid,
}
}
errorCode = uCxEnd(pUcxHandle);
if (logWasOn) {
uCxLogEnable();
}
}
return errorCode;
}
Expand Down
Loading

0 comments on commit 7261fd7

Please sign in to comment.