summaryrefslogtreecommitdiff
path: root/src/components/ble/MusicService.cpp
diff options
context:
space:
mode:
authormabuch <marcel.buechler@gmail.com>2022-04-18 14:35:31 +0200
committermabuch <marcel.buechler@gmail.com>2022-04-18 14:35:31 +0200
commit82a4f9aa68c3f8d5f3cfa6de87de078fe680d944 (patch)
treecc83c0af796a029f9464003cda043f373b716749 /src/components/ble/MusicService.cpp
parentea14c580ca6296cb93facf526d65a2db0e3ff1b0 (diff)
parent2607c3d79947e900ce4c5ded296f649677511a34 (diff)
resolved merge conflict after renaming PineTimeStyle to WatchFacePineTimeStyle
Diffstat (limited to 'src/components/ble/MusicService.cpp')
-rw-r--r--src/components/ble/MusicService.cpp21
1 files changed, 18 insertions, 3 deletions
diff --git a/src/components/ble/MusicService.cpp b/src/components/ble/MusicService.cpp
index 3457ce4c..c99aa1e3 100644
--- a/src/components/ble/MusicService.cpp
+++ b/src/components/ble/MusicService.cpp
@@ -17,6 +17,7 @@
*/
#include "components/ble/MusicService.h"
#include "systemtask/SystemTask.h"
+#include <cstring>
namespace {
// 0000yyxx-78fc-48fe-8e23-433b3a1942d0
@@ -47,6 +48,8 @@ namespace {
constexpr ble_uuid128_t msRepeatCharUuid {CharUuid(0x0b, 0x00)};
constexpr ble_uuid128_t msShuffleCharUuid {CharUuid(0x0c, 0x00)};
+ constexpr uint8_t MaxStringSize {40};
+
int MusicCallback(uint16_t conn_handle, uint16_t attr_handle, struct ble_gatt_access_ctxt* ctxt, void* arg) {
return static_cast<Pinetime::Controllers::MusicService*>(arg)->OnCommand(conn_handle, attr_handle, ctxt);
}
@@ -125,9 +128,21 @@ void Pinetime::Controllers::MusicService::Init() {
int Pinetime::Controllers::MusicService::OnCommand(uint16_t conn_handle, uint16_t attr_handle, struct ble_gatt_access_ctxt* ctxt) {
if (ctxt->op == BLE_GATT_ACCESS_OP_WRITE_CHR) {
size_t notifSize = OS_MBUF_PKTLEN(ctxt->om);
- char data[notifSize + 1];
- data[notifSize] = '\0';
- os_mbuf_copydata(ctxt->om, 0, notifSize, data);
+ size_t bufferSize = notifSize;
+ if (notifSize > MaxStringSize) {
+ bufferSize = MaxStringSize;
+ }
+
+ char data[bufferSize + 1];
+ os_mbuf_copydata(ctxt->om, 0, bufferSize, data);
+
+ if (notifSize > bufferSize) {
+ data[bufferSize-1] = '.';
+ data[bufferSize-2] = '.';
+ data[bufferSize-3] = '.';
+ }
+ data[bufferSize] = '\0';
+
char* s = &data[0];
if (ble_uuid_cmp(ctxt->chr->uuid, &msArtistCharUuid.u) == 0) {
artistName = s;