FazBrowse GitHub Viewer
|
Trending
|
URL:
|
Home
Tools:
[Download Repo ZIP]
[View Raw Code]
[Original HTTPS Page]
STM32duinoBLE/src/BLETypedCharacteristic.h at main · stm32duino/STM32duinoBLE · GitHub
Uh oh!
There was an error while loading.
Please reload this page
.
stm32duino
/
STM32duinoBLE
Public
forked from
arduino-libraries/ArduinoBLE
Notifications
You must be signed in to change notification settings
Fork
23
Star
21
Code
Issues
3
Pull requests
0
Actions
Projects
Wiki
Security and quality
0
Insights
Additional navigation options
Code
Issues
Pull requests
Actions
Projects
Wiki
Security and quality
Insights
Expand file tree
Breadcrumbs
STM32duinoBLE
/
src
/
BLETypedCharacteristic.h
Copy path
More file actions
More file actions
Latest commit
History
History
History
102 lines (78 loc) · 2.65 KB
Breadcrumbs
STM32duinoBLE
/
src
/
BLETypedCharacteristic.h
Copy path
File metadata and controls
102 lines (78 loc) · 2.65 KB
Raw
Copy raw file
Download raw file
Open symbols panel
Edit and raw actions
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
/*
This file is part of the ArduinoBLE library.
Copyright (c) 2018 Arduino SA. All rights reserved.
This library is free software; you can redistribute it and/or
modify it under the terms of the GNU Lesser General Public
License as published by the Free Software Foundation; either
version 2.1 of the License, or (at your option) any later version.
This library is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
Lesser General Public License for more details.
You should have received a copy of the GNU Lesser General Public
License along with this library; if not, write to the Free Software
Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
*/
#
ifndef
_BLE_TYPED_CHARACTERISTIC_H_
#
define
_BLE_TYPED_CHARACTERISTIC_H_
#
include
"
BLECharacteristic.h
"
template
<
typename
T>
class
BLETypedCharacteristic
:
public
BLECharacteristic
{
public:
BLETypedCharacteristic
(
const
char
* uuid,
unsigned
int
permissions);
int
writeValue
(T value);
int
setValue
(T value) {
return
writeValue
(value); }
T
value
(
void
);
int
writeValueLE
(T value);
int
setValueLE
(T value) {
return
writeValueLE
(value); }
T
valueLE
(
void
);
int
writeValueBE
(T value);
int
setValueBE
(T value) {
return
writeValueBE
(value); }
T
valueBE
(
void
);
private:
T
byteSwap
(T value);
};
template
<
typename
T> BLETypedCharacteristic<T>::BLETypedCharacteristic(
const
char
* uuid,
unsigned
int
permissions) :
BLECharacteristic
(uuid, permissions,
sizeof
(T), true)
{
T value;
memset
(&value,
0x00
,
sizeof
(value));
writeValue
(value);
}
template
<
typename
T>
int
BLETypedCharacteristic<T>::writeValue(T value)
{
return
BLECharacteristic::writeValue
((
uint8_t
*)&value,
sizeof
(T));
}
template
<
typename
T> T BLETypedCharacteristic<T>::value()
{
T value;
memcpy
(&value, (
unsigned
char
*)
BLECharacteristic::value
(),
BLECharacteristic::valueSize
());
return
value;
}
template
<
typename
T>
int
BLETypedCharacteristic<T>::writeValueLE(T value)
{
return
writeValue
(value);
}
template
<
typename
T> T BLETypedCharacteristic<T>::valueLE()
{
return
value
();
}
template
<
typename
T>
int
BLETypedCharacteristic<T>::writeValueBE(T value)
{
return
writeValue
(
byteSwap
(value));
}
template
<
typename
T> T BLETypedCharacteristic<T>::valueBE()
{
return
byteSwap
(
value
());
}
template
<
typename
T> T BLETypedCharacteristic<T>::byteSwap(T value)
{
T result;
unsigned
char
* src = (
unsigned
char
*)&value;
unsigned
char
* dst = (
unsigned
char
*)&result;
for
(
int
i =
0
; i <
sizeof
(T); i++) {
dst[i] = src[
sizeof
(T) - i -
1
];
}
return
result;
}
#
endif
Back
|
FazBrowse Home
|
New Git URL