diff --git a/Documentation/bluetooth/card10.rst b/Documentation/bluetooth/card10.rst index 08c8b4f6bf23afd49d7413da2a510745aa185735..d41fa01b971e3fc7955fcced689d942a93417b1c 100644 --- a/Documentation/bluetooth/card10.rst +++ b/Documentation/bluetooth/card10.rst @@ -30,6 +30,11 @@ The current draft uses following service specification: UUID: ``42230210-2342-2342-2342-234223422342`` write +- Time update characteristic: + + UUID: ``42230201-2342-2342-2342-234223422342`` + write + light sensor characteristic --------------------------------- @@ -61,3 +66,10 @@ Rocket0 Rocket1 Rocket2 - Enable only Rocket0: ``0xff0000`` - Enable all rockets with 50% brightness: ``0x7f7f7f`` + +time update characteristic +--------------------------------- + +The time update characteristic makes it possible to set the current time given in milliseconds after 1.1.1970 in the UTC timezone. The value is represented as a big endian ``uint64`` + +- Thu Aug 15 19:40:45 UTC 2019 : ``0x0 0x0 0x1 0x6c 0x96 0xcb 0xf8 0xcc`` diff --git a/epicardium/ble/card10.c b/epicardium/ble/card10.c index 1a5dc0655d17550ece37ca29a18a71ded972a9ed..4ad535c147209d3e79187605858627aed82ea0c4 100644 --- a/epicardium/ble/card10.c +++ b/epicardium/ble/card10.c @@ -47,6 +47,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 }; @@ -87,6 +90,17 @@ static const uint8_t UUID_char_light_sensor[] = { static const uint8_t UUID_attChar_light_sensor[] = { CARD10_UUID_SUFFIX, 0xf0, CARD10_UUID_PREFIX }; + +/* 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, CARD10_UUID_PREFIX +}; + +static const uint8_t UUID_attChar_time[] = { + CARD10_UUID_SUFFIX, 0x01, CARD10_UUID_PREFIX +}; /* clang-format on */ /* @@ -174,11 +188,51 @@ 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; + + if (len < sizeof(uint64_t)) { + return ATT_ERR_LENGTH; + } + memcpy(&timeNet, pValue, sizeof(timeNet)); + + time = __bswap64(timeNet); + epic_rtc_set_milliseconds(time); + + return ATT_SUCCESS; +} + /* * BLE card10 write callback. */ @@ -211,6 +265,14 @@ static uint8_t writeCard10CB( pValue[2] ); return ATT_SUCCESS; + case CARD10_TIME_UPDATE_VAL_HDL: + if (operation == ATT_PDU_PREP_WRITE_REQ) { + if (len < sizeof(uint64_t)) { + return ATT_ERR_LENGTH; + } + return ATT_SUCCESS; + } + return setTime(pValue, len); default: APP_TRACE_INFO1( "ble-card10: unsupported characteristic: %c\n", handle