Skip to content
Snippets Groups Projects

change(ble): Add Time Update service

Closed Hauke Mehrtens requested to merge hauke/firmware:ble-time-update into master
1 unresolved thread
+ 69
0
@@ -15,6 +15,9 @@
#include "FreeRTOS.h"
#include "crc32.h"
#include "mxc_errors.h"
#include "rtc.h"
#include "epicardium.h"
#include <stdio.h>
@@ -46,6 +49,9 @@ enum {
/*!< \brief light sensor characteristic */
CARD10_LIGHT_SENSOR_CH_HDL,
CARD10_LIGHT_SENSOR_VAL_HDL,
/*!< \brief time update characteristic */
CARD10_TIME_UPDATE_CH_HDL,
CARD10_TIME_UPDATE_VAL_HDL,
/*!< \brief Maximum handle. */
CARD10_MAX_HDL
};
@@ -86,6 +92,17 @@ static const uint8_t UUID_char_light_sensor[] = {
static const uint8_t UUID_attChar_light_sensor[] = {
CARD10_UUID_SUFFIX, 0xf0, 0xf0, 0x0, 0x0
};
/* BLE UUID for card10 time update */
static const uint8_t UUID_char_time[] = {
ATT_PROP_WRITE,
UINT16_TO_BYTES(CARD10_TIME_UPDATE_VAL_HDL),
CARD10_UUID_SUFFIX, 0x01, 0xf0, 0x0, 0x0
};
static const uint8_t UUID_attChar_time[] = {
CARD10_UUID_SUFFIX, 0x01, 0xf0, 0x0, 0x0
};
/* clang-format on */
/*
@@ -173,11 +190,61 @@ static void *addCard10GroupDyn(void)
ATTS_PERMIT_READ
);
// TIME UPDTAE
AttsDynAddAttrConst(
pSHdl,
attChUuid,
UUID_char_time,
sizeof(UUID_char_time),
0,
ATTS_PERMIT_READ
);
AttsDynAddAttr(
pSHdl,
UUID_attChar_time,
NULL,
0,
sizeof(uint64_t),
ATTS_SET_WRITE_CBACK,
ATTS_PERMIT_WRITE
);
APP_TRACE_INFO0("ble-card10: services bound\n");
}
return pSHdl;
}
/*
* Set the time given in milliseconds since 1.1.1970 as 64 bit integer.
*/
static uint8_t setTime(uint8_t *pValue, uint16_t len)
{
uint64_t timeNet;
uint64_t time;
uint32_t sec;
uint32_t ssec;
int res;
if (len < sizeof(uint64_t)) {
return ATT_ERR_LENGTH;
}
memcpy(&timeNet, pValue, sizeof(timeNet));
time = __ntohl(timeNet);
sec = time / 1000;
ssec = (time % 1000);
ssec *= 256;
ssec /= 1000;
Please register or sign in to reply
+1
res = RTC_Init(MXC_RTC, sec, ssec, NULL);
if (res != E_SUCCESS) {
return ATT_ERR_WRITE;
}
return ATT_SUCCESS;
}
/*
* BLE card10 write callback.
*/
@@ -210,6 +277,8 @@ static uint8_t writeCard10CB(
pValue[2]
);
return ATT_SUCCESS;
case CARD10_TIME_UPDATE_VAL_HDL:
return setTime(pValue, len);
default:
APP_TRACE_INFO1(
"ble-card10: unsupported characteristic: %c\n", handle
Loading