From 7261fd74832ebfef553fa9cfa978b5539e635ed9 Mon Sep 17 00:00:00 2001 From: Peter Lerup Date: Wed, 31 Jan 2024 14:55:08 +0100 Subject: [PATCH] Adjustments for new ucx version (#1088) 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. --- ble/src/gen2/u_ble_gap_extmod.c | 19 ++++------ ble/src/gen2/u_ble_gatt_extmod.c | 20 +++++------ ble/src/gen2/u_ble_sps_extmod.c | 14 ++++---- ble/test/u_ble_nus_test.c | 3 +- common/mqtt_client/test/u_mqtt_client_test.c | 8 ----- common/security/src/u_security_credential.c | 4 +-- common/short_range/src/gen2/u_short_range.c | 6 ++-- common/short_range/src/gen2/ucxclient | 2 +- common/short_range/test/README.md | 2 +- wifi/src/gen2/u_wifi.c | 29 ++++++--------- wifi/src/gen2/u_wifi_mqtt.c | 37 +++++++------------- wifi/src/gen2/u_wifi_sock.c | 30 ++++++++-------- 12 files changed, 73 insertions(+), 101 deletions(-) diff --git a/ble/src/gen2/u_ble_gap_extmod.c b/ble/src/gen2/u_ble_gap_extmod.c index 0703b815..8b4572f4 100644 --- a/ble/src/gen2/u_ble_gap_extmod.c +++ b/ble/src/gen2/u_ble_gap_extmod.c @@ -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; } } @@ -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); @@ -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 diff --git a/ble/src/gen2/u_ble_gatt_extmod.c b/ble/src/gen2/u_ble_gatt_extmod.c index 5632c1d9..6a84a878 100644 --- a/ble/src/gen2/u_ble_gatt_extmod.c +++ b/ble/src/gen2/u_ble_gatt_extmod.c @@ -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); @@ -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); @@ -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; } } @@ -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; } } @@ -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); } diff --git a/ble/src/gen2/u_ble_sps_extmod.c b/ble/src/gen2/u_ble_sps_extmod.c index e31af8b0..43272431 100644 --- a/ble/src/gen2/u_ble_sps_extmod.c +++ b/ble/src/gen2/u_ble_sps_extmod.c @@ -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, @@ -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; } @@ -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; diff --git a/ble/test/u_ble_nus_test.c b/ble/test/u_ble_nus_test.c index 67f97588..4f76c40d 100644 --- a/ble/test/u_ble_nus_test.c +++ b/ble/test/u_ble_nus_test.c @@ -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); diff --git a/common/mqtt_client/test/u_mqtt_client_test.c b/common/mqtt_client/test/u_mqtt_client_test.c index e17d71ea..c8a63397 100644 --- a/common/mqtt_client/test/u_mqtt_client_test.c +++ b/common/mqtt_client/test/u_mqtt_client_test.c @@ -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. diff --git a/common/security/src/u_security_credential.c b/common/security/src/u_security_credential.c index a85d06f6..75d7c2c9 100644 --- a/common/security/src/u_security_credential.c +++ b/common/security/src/u_security_credential.c @@ -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); } } diff --git a/common/short_range/src/gen2/u_short_range.c b/common/short_range/src/gen2/u_short_range.c index 55721752..84358cd3 100644 --- a/common/short_range/src/gen2/u_short_range.c +++ b/common/short_range/src/gen2/u_short_range.c @@ -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; @@ -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); @@ -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); } diff --git a/common/short_range/src/gen2/ucxclient b/common/short_range/src/gen2/ucxclient index 8af8e86e..360f1cbc 160000 --- a/common/short_range/src/gen2/ucxclient +++ b/common/short_range/src/gen2/ucxclient @@ -1 +1 @@ -Subproject commit 8af8e86eac13d93912fea164498f234689c4b2da +Subproject commit 360f1cbc1b4b3433670d5ee6abb708bf851615af diff --git a/common/short_range/test/README.md b/common/short_range/test/README.md index ca1c0c08..7c3be626 100644 --- a/common/short_range/test/README.md +++ b/common/short_range/test/README.md @@ -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. \ No newline at end of file +- NORA-W36: u-connectExpress second generation, version 1.1.0. \ No newline at end of file diff --git a/wifi/src/gen2/u_wifi.c b/wifi/src/gen2/u_wifi.c index 28239dfc..78dd0276 100644 --- a/wifi/src/gen2/u_wifi.c +++ b/wifi/src/gen2/u_wifi.c @@ -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; } @@ -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(); @@ -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) { @@ -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, ¶ms); has = errorCode == 0 && strlen(params.ssid) > 0; uCxEnd(pUcxHandle); @@ -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, ¶ms); + int32_t errorCode = uCxWifiApGetConnectionParamsBegin(pUcxHandle, ¶ms); has = errorCode == 0 && strlen(params.ssid) > 0; } return has; @@ -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; @@ -406,9 +402,6 @@ int32_t uWifiStationScan(uDeviceHandle_t devHandle, const char *pSsid, } } errorCode = uCxEnd(pUcxHandle); - if (logWasOn) { - uCxLogEnable(); - } } return errorCode; } diff --git a/wifi/src/gen2/u_wifi_mqtt.c b/wifi/src/gen2/u_wifi_mqtt.c index c2b91d52..6d2e672e 100644 --- a/wifi/src/gen2/u_wifi_mqtt.c +++ b/wifi/src/gen2/u_wifi_mqtt.c @@ -240,9 +240,9 @@ int32_t uWifiMqttConnect(const uMqttClientContext_t *pContext, } } if (errorCode == 0) { - uCxUrcRegisterMqttConnect(pUcxHandle, connectCallback); - uCxUrcRegisterMqttDisconnect(pUcxHandle, disconnectCallback); - uCxUrcRegisterMqttDataAvailable(pUcxHandle, dataAvailableCallback); + uCxMqttRegisterConnect(pUcxHandle, connectCallback); + uCxMqttRegisterDisconnect(pUcxHandle, disconnectCallback); + uCxMqttRegisterDataAvailable(pUcxHandle, dataAvailableCallback); errorCode = uCxMqttConnect(pUcxHandle, MQTT_ID); if (errorCode == 0) { errorCode = uPortSemaphoreTryTake(pMqttDeviceState->semaphore, @@ -250,9 +250,9 @@ int32_t uWifiMqttConnect(const uMqttClientContext_t *pContext, if (errorCode != 0) { disconnectCallback(pUcxHandle, MQTT_ID, (int32_t)U_ERROR_COMMON_TIMEOUT); - uCxUrcRegisterMqttConnect(pUcxHandle, NULL); - uCxUrcRegisterMqttDisconnect(pUcxHandle, NULL); - uCxUrcRegisterMqttDataAvailable(pUcxHandle, NULL); + uCxMqttRegisterConnect(pUcxHandle, NULL); + uCxMqttRegisterDisconnect(pUcxHandle, NULL); + uCxMqttRegisterDataAvailable(pUcxHandle, NULL); } } } @@ -302,18 +302,8 @@ int32_t uWifiMqttPublish(const uMqttClientContext_t *pContext, uCxHandle_t *pUcxHandle = pShortRangePrivateGetUcxHandle(pContext->devHandle); if (pUcxHandle != NULL) { if (pMessage != NULL) { - // *** UCX WORKAROUND FIX *** - // There is currently no binary mqtt publish available in ucx - // hence we have to copy the content into a string. Any quote character - // in the data will result in an error. - char *pMessCopy = pUPortMalloc(messageSizeBytes + 1); - if (pMessCopy != NULL) { - memcpy(pMessCopy, pMessage, messageSizeBytes); - pMessCopy[messageSizeBytes] = 0; - errorCode = uCxMqttPublish(pUcxHandle, MQTT_ID, (uQos_t)qos, (uRetain_t)retain, - pTopicNameStr, pMessCopy); - uPortFree(pMessCopy); - } + errorCode = uCxMqttPublish(pUcxHandle, MQTT_ID, (uQos_t)qos, (uRetain_t)retain, + pTopicNameStr, (uint8_t *)pMessage, messageSizeBytes); } else if (messageSizeBytes == 0) { errorCode = 0; } @@ -414,18 +404,17 @@ int32_t uWifiMqttMessageRead(const uMqttClientContext_t *pContext, uMqttDeviceState_t *pMqttDeviceState = (uMqttDeviceState_t *)pContext->pPriv; uCxHandle_t *pUcxHandle = pShortRangePrivateGetUcxHandle(pContext->devHandle); if ((pMqttDeviceState != NULL) && (pUcxHandle != NULL)) { - uCxMqttReadMessage_t resp; - resp.message_len = *pMessageSizeBytes; - if (uCxBeginMqttReadMessage(pUcxHandle, MQTT_ID, &resp)) { + uCxMqttRead_t resp; + uint32_t len = uCxMqttReadBegin(pUcxHandle, MQTT_ID, (uint8_t *)pMessage, *pMessageSizeBytes, + &resp); + if (len > 0) { pMqttDeviceState->unReadCnt--; if (pQos != NULL) { *pQos = 0; // Not available in the response } memset(pTopicNameStr, 0, topicNameSizeBytes); strncpy(pTopicNameStr, resp.topic, topicNameSizeBytes - 1); - int32_t messageLength = MIN(*pMessageSizeBytes, resp.message_len); - memcpy(pMessage, resp.message, messageLength); - *pMessageSizeBytes = messageLength; + *pMessageSizeBytes = len; } errorCode = uCxEnd(pUcxHandle); } diff --git a/wifi/src/gen2/u_wifi_sock.c b/wifi/src/gen2/u_wifi_sock.c index 3def7efe..132f1e7f 100644 --- a/wifi/src/gen2/u_wifi_sock.c +++ b/wifi/src/gen2/u_wifi_sock.c @@ -243,11 +243,11 @@ int32_t uWifiSockInitInstance(uDeviceHandle_t devHandle) int32_t errorCode = (int32_t)U_ERROR_COMMON_INVALID_PARAMETER; uCxHandle_t *pUcxHandle = pShortRangePrivateGetUcxHandle(devHandle); if (pUcxHandle != NULL) { - uCxUrcRegisterSocketConnect(pUcxHandle, socketConnectCallback); - uCxUrcRegisterSocketDataAvailable(pUcxHandle, socketDataCallback); - uCxUrcRegisterSocketClosed(pUcxHandle, socketClosedCallback); - uCxUrcRegisterSocketIncommingConnection(pUcxHandle, - socketIncomingConnectCallback); + uCxSocketRegisterConnect(pUcxHandle, socketConnectCallback); + uCxSocketRegisterDataAvailable(pUcxHandle, socketDataCallback); + uCxSocketRegisterClosed(pUcxHandle, socketClosedCallback); + uCxSocketRegisterIncomingConnection(pUcxHandle, + socketIncomingConnectCallback); errorCode = (int32_t)U_ERROR_COMMON_SUCCESS; } return errorCode; @@ -258,9 +258,9 @@ int32_t uWifiSockDeinitInstance(uDeviceHandle_t devHandle) int32_t errorCode = (int32_t)U_ERROR_COMMON_INVALID_PARAMETER; uCxHandle_t *pUcxHandle = pShortRangePrivateGetUcxHandle(devHandle); if (pUcxHandle != NULL) { - uCxUrcRegisterSocketConnect(pUcxHandle, NULL); - uCxUrcRegisterSocketDataAvailable(pUcxHandle, NULL); - uCxUrcRegisterSocketClosed(pUcxHandle, NULL); + uCxSocketRegisterConnect(pUcxHandle, NULL); + uCxSocketRegisterDataAvailable(pUcxHandle, NULL); + uCxSocketRegisterClosed(pUcxHandle, NULL); errorCode = (int32_t)U_ERROR_COMMON_SUCCESS; } return errorCode; @@ -333,8 +333,10 @@ int32_t uWifiSockConnect(uDeviceHandle_t devHandle, errorCode = uCxSocketConnect(pUcxHandle, pUWiFiSocket->uCxSockHandle, addrString, pRemoteAddress->port); if (errorCode >= 0 && pUWiFiSocket->protocol == U_SOCK_PROTOCOL_TCP) { - errorCode = uPortSemaphoreTryTake(pUWiFiSocket->semaphore, - U_SOCK_DEFAULT_RECEIVE_TIMEOUT_MS); + // *** UCX WORKAROUND FIX *** + // The timeout for a connection in the under laying LWIP is longer + // than U_SOCK_DEFAULT_RECEIVE_TIMEOUT_MS so we use an explict value here, 30s. + errorCode = uPortSemaphoreTryTake(pUWiFiSocket->semaphore, 30000); } } return errorCode; @@ -463,8 +465,8 @@ int32_t uWifiSockWrite(uDeviceHandle_t devHandle, uCxHandle_t *pUcxHandle = pShortRangePrivateGetUcxHandle(devHandle); uWifiSocket_t *pUWiFiSocket = getSocketByHandle(sockHandle); if ((pUcxHandle != NULL) && (pUWiFiSocket != NULL)) { - errorCodeOrLength = uCxSocketWriteBinary(pUcxHandle, pUWiFiSocket->uCxSockHandle, - (uint8_t *)pData, dataSizeBytes); + errorCodeOrLength = uCxSocketWrite(pUcxHandle, pUWiFiSocket->uCxSockHandle, + (uint8_t *)pData, dataSizeBytes); } return errorCodeOrLength; } @@ -479,8 +481,8 @@ int32_t uWifiSockRead(uDeviceHandle_t devHandle, if ((pUcxHandle != NULL) && (pUWiFiSocket != NULL)) { // ucx limit dataSizeBytes = MIN(dataSizeBytes, 1000); - errorCodeOrLength = uCxSocketReadBinary(pUcxHandle, pUWiFiSocket->uCxSockHandle, - dataSizeBytes, pData); + errorCodeOrLength = uCxSocketRead(pUcxHandle, pUWiFiSocket->uCxSockHandle, + dataSizeBytes, pData); } if (errorCodeOrLength == 0) { // If there is no data available we must return U_SOCK_EWOULDBLOCK