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

Commit

Permalink
Short-range change only: add uShortRangeGetFirmwareVersionStr(). (#1066)
Browse files Browse the repository at this point in the history
  • Loading branch information
RobMeades authored Jan 11, 2024
1 parent 41349f3 commit 79d4365
Show file tree
Hide file tree
Showing 4 changed files with 64 additions and 1 deletion.
18 changes: 18 additions & 0 deletions common/short_range/api/u_short_range.h
Original file line number Diff line number Diff line change
Expand Up @@ -331,6 +331,24 @@ int32_t uShortRangeAtClientHandleGet(uDeviceHandle_t devHandle,

const uShortRangeModuleInfo_t *uShortRangeGetModuleInfo(int32_t moduleId);

/** Get the firmware version string from the short-range module.
*
* @param devHandle the short range device handle.
* @param[out] pStr a pointer to size bytes of storage into which
* the firmware version string will be copied.
* Room should be allowed for a null terminator,
* which will be added to terminate the string.
* This pointer cannot be NULL.
* @param size the number of bytes available at pStr, including
* room for a null terminator. Must be greater
* than zero.
* @return on success, the number of characters copied into
* pStr NOT including the terminator (as strlen()
* would return), on failure negative error code.
*/
int32_t uShortRangeGetFirmwareVersionStr(uDeviceHandle_t devHandle,
char *pStr, size_t size);

/** Check if a module type supports BLE
*
* @param moduleType the short range module type.
Expand Down
31 changes: 31 additions & 0 deletions common/short_range/src/u_short_range.c
Original file line number Diff line number Diff line change
Expand Up @@ -1062,6 +1062,37 @@ const uShortRangeModuleInfo_t *uShortRangeGetModuleInfo(int32_t moduleType)
return NULL;
}

int32_t uShortRangeGetFirmwareVersionStr(uDeviceHandle_t devHandle,
char *pStr, size_t size)
{
uAtClientHandle_t atHandle;
uShortRangePrivateInstance_t *pInstance;
int32_t readBytes;
int32_t err = (int32_t)U_ERROR_COMMON_INVALID_PARAMETER;

if (gUShortRangePrivateMutex == NULL) {
return (int32_t) U_ERROR_COMMON_NOT_INITIALISED;
}

pInstance = pUShortRangePrivateGetInstance(devHandle);

if ((pInstance != NULL) && (pStr != NULL) && (size > 0)) {
atHandle = pInstance->atHandle;
uAtClientLock(atHandle);
uAtClientCommandStart(atHandle, "AT+CGMR");
uAtClientCommandStop(atHandle);
uAtClientResponseStart(atHandle, NULL);
readBytes = uAtClientReadString(atHandle, pStr, size, false);
uAtClientResponseStop(atHandle);
err = uAtClientUnlock(atHandle);
if ((readBytes >= 0) && (err == (int32_t)U_ERROR_COMMON_SUCCESS)) {
err = readBytes;
}
}

return err;
}

int32_t uShortRangeGetSerialNumber(uDeviceHandle_t devHandle, char *pSerialNumber)
{
uAtClientHandle_t atHandle;
Expand Down
9 changes: 8 additions & 1 deletion common/short_range/test/u_short_range_test.c
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@
#include "stddef.h" // NULL, size_t etc.
#include "stdint.h" // int32_t etc.
#include "stdbool.h"
#include "string.h" // strlen()

#include "u_cfg_sw.h"
#include "u_cfg_app_platform_specific.h"
Expand Down Expand Up @@ -205,6 +206,8 @@ U_PORT_TEST_FUNCTION("[shortRange]", "shortRangeOpenUart")
U_PORT_TEST_FUNCTION("[shortRange]", "shortRangeUartSetBaudrate")
{
uAtClientHandle_t atClient = NULL;
int32_t x;
char buffer[32];
uShortRangeUartConfig_t uart = { .uartPort = U_CFG_APP_SHORT_RANGE_UART,
.baudRate = U_SHORT_RANGE_UART_BAUD_RATE,
.pinTx = U_CFG_APP_PIN_SHORT_RANGE_TXD,
Expand Down Expand Up @@ -249,8 +252,12 @@ U_PORT_TEST_FUNCTION("[shortRange]", "shortRangeUartSetBaudrate")
gHandles.edmStreamHandle = uShortRangeGetEdmStreamHandle(gHandles.devHandle);
U_PORT_TEST_ASSERT(uShortRangeAtClientHandleGet(gHandles.devHandle,
&gHandles.atClientHandle) == 0);
// This should receive a valid response
// These should receive a valid response
U_PORT_TEST_ASSERT(uShortRangeAttention(gHandles.devHandle) == 0);
x = uShortRangeGetFirmwareVersionStr(gHandles.devHandle, buffer, sizeof(buffer));
U_PORT_TEST_ASSERT(x > 0);
U_PORT_TEST_ASSERT(x == strlen(buffer));
U_TEST_PRINT_LINE("after setting baudrate, module FW version reads as \"%s\".", buffer);
}
uShortRangeTestPrivateCleanup(&gHandles);
U_TEST_PRINT_LINE("shortRangeUartSetBaudrate succeded.");
Expand Down
7 changes: 7 additions & 0 deletions common/short_range/test/u_short_range_test_private.c
Original file line number Diff line number Diff line change
Expand Up @@ -88,6 +88,7 @@ int32_t uShortRangeTestPrivatePreamble(uShortRangeModuleType_t moduleType,
{
int32_t errorCodeOrHandle = (int32_t) U_ERROR_COMMON_NOT_INITIALISED;
const uShortRangePrivateModule_t *pModule;
char buffer[32];

// Set some defaults
pParameters->uartHandle = -1;
Expand Down Expand Up @@ -140,6 +141,12 @@ int32_t uShortRangeTestPrivatePreamble(uShortRangeModuleType_t moduleType,
}

if (errorCodeOrHandle == 0) {
if (uShortRangeGetFirmwareVersionStr(pParameters->devHandle,
buffer, sizeof(buffer)) > 0) {
U_TEST_PRINT_LINE("module FW version \"%s\".", buffer);
} else {
U_TEST_PRINT_LINE("unable to read module FW version.");
}
U_TEST_PRINT_LINE("module is powered-up and configured for testing.");
}
}
Expand Down

0 comments on commit 79d4365

Please sign in to comment.