Ersa Wearable Platform
Embedded smartwatch firmware and application framework
Loading...
Searching...
No Matches
apple_media.h
Go to the documentation of this file.
1#pragma once
2#include <stdint.h>
3#include <stddef.h>
4#include <string.h>
5
6namespace ersa { namespace protocols {
13struct AmsMedia {
15 char title[32]{};
17 char artist[32]{};
19 bool playing{false};
29 bool update(const uint8_t* bytes, size_t length) {
30 if (length < 3) return false;
31 const uint8_t entity = bytes[0], attribute = bytes[1];
32 const uint8_t* text = bytes + 3;
33 const size_t size = length - 3;
34 if (entity == 2 && (attribute == 0 || attribute == 2)) {
35 char* target = attribute == 0 ? artist : title;
36 const size_t count = size < 31 ? size : 31;
37 char next[32]{};
38 memcpy(next, text, count);
39 if (strcmp(target, next) == 0) return false;
40 memcpy(target, next, sizeof(next));
41 return true;
42 }
43 if (entity == 0 && attribute == 1 && size >= 2 && text[1] == ',' && text[0] >= '0' && text[0] <= '3') {
44 const bool nextPlaying = text[0] != '0';
45 if (playing == nextPlaying) return false;
46 playing = nextPlaying;
47 return true;
48 }
49 return false;
50 }
51};
52} }
Definition application.h:10
size_t size
Definition ota_service.cpp:47
size_t length
Definition ota_service.cpp:34
Definition apple_media.h:13
char title[32]
Definition apple_media.h:15
bool playing
Definition apple_media.h:19
char artist[32]
Definition apple_media.h:17
bool update(const uint8_t *bytes, size_t length)
Definition apple_media.h:29