Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Parse service data from advertisement data. #55

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 12 additions & 3 deletions adv.go
Original file line number Diff line number Diff line change
Expand Up @@ -88,6 +88,12 @@ func (a *Advertisement) unmarshall(b []byte) error {
return u
}

serviceDataList := func(sd []ServiceData, d []byte, w int) []ServiceData {
serviceData := ServiceData {UUID{d[:w]}, make([]byte, len(d) - w)}
copy(serviceData.Data, d[2:])
return append(sd, serviceData)
}

for len(b) > 0 {
if len(b) < 2 {
return errors.New("invalid advertise data")
Expand Down Expand Up @@ -127,9 +133,12 @@ func (a *Advertisement) unmarshall(b []byte) error {
case typeManufacturerData:
a.ManufacturerData = make([]byte, len(d))
copy(a.ManufacturerData, d)
// case typeServiceData16,
// case typeServiceData32,
// case typeServiceData128:
case typeServiceData16:
a.ServiceData = serviceDataList(a.ServiceData, d, 2)
case typeServiceData32:
a.ServiceData = serviceDataList(a.ServiceData, d, 4)
case typeServiceData128:
a.ServiceData = serviceDataList(a.ServiceData, d, 16)
default:
log.Printf("DATA: [ % X ]", d)
}
Expand Down