restructuring packages
This commit is contained in:
commit
086b479e43
@ -12,6 +12,80 @@ import (
|
||||
"time"
|
||||
)
|
||||
|
||||
func (m *Meta) NewScan() *Scan {
|
||||
// Here we are creating an "anonymous" instance of a Scan struct
|
||||
// You'll notice it doesn't contain most of the data that actually is supposed to live within that struct
|
||||
|
||||
// This works because the integer ID is being used as a key that will have a global scope
|
||||
//
|
||||
// See: Remember function as it is defined in eros/eros.go
|
||||
// Remember usage in this file (scanStuff/scanStuff.go
|
||||
//
|
||||
// In these examples we are sending an instance of a struct with some data to eros; allowing it to finish filling out the rest
|
||||
// This can be done with just structs, but becomes problematic when trying to refer to them later
|
||||
//
|
||||
//TODO: implement Mutex locking from sync in most of these structs to prevent concurrent read/write operations from causing a race w̶a̶r̶ condition
|
||||
// ref: https://gobyexample.com/mutexes
|
||||
// ref: https://golang.org/pkg/sync/#Mutex
|
||||
// ref: https://www.geeksforgeeks.org/mutex-in-golang-with-examples/
|
||||
|
||||
newid := len(m.Scans)
|
||||
|
||||
m.Scans[newid] = &Scan{
|
||||
ID: newid,
|
||||
Started: time.Now(),
|
||||
}
|
||||
|
||||
scan := m.Scans[newid]
|
||||
scan.Devices = make(map[int]*eros.Device)
|
||||
|
||||
m.Count = len(m.Scans)
|
||||
return scan
|
||||
}
|
||||
|
||||
func (s *Scan) NewDevice(name string, addr string, manuf string, rssi int16) *eros.Device {
|
||||
newid := len(s.Devices)
|
||||
s.Devices[newid] = &eros.Device{
|
||||
Name: name,
|
||||
Addr: addr,
|
||||
Manufacturer: manuf,
|
||||
RSSIlast: rssi,
|
||||
}
|
||||
|
||||
s.Count = len(s.Devices)
|
||||
return s.Devices[newid]
|
||||
}
|
||||
|
||||
/*
|
||||
func ManfCheck(TargetAdvertData bluetooth.AdvertisementPayload) string {
|
||||
|
||||
uuids := TargetAdvertData.ServiceUUIDOut()
|
||||
|
||||
var ManufacturerOut string
|
||||
|
||||
for _, i := uuids, 0; i < len(uuids); i++ {
|
||||
//very closse to getting this
|
||||
|
||||
for lines, i := manuF.ManufS, 0; i < len(lines); i++ {
|
||||
|
||||
curUUID := lines[i].UUID
|
||||
curUUID16Bit := bluetooth.New16BitUUID(curUUID.Get16Bit())
|
||||
curMan := lines[i].WhosIts
|
||||
curCheck := TargetAdvertData.HasServiceUUID(curUUID16Bit)
|
||||
if curCheck == true {
|
||||
println(curMan)
|
||||
ManufacturerOut = curMan
|
||||
} else {
|
||||
ManufacturerOut = "No Manufacturer Data in UUID"
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
return ManufacturerOut
|
||||
}
|
||||
*/
|
||||
|
||||
// resultHandler is called by the bluetooth library upon device discovery to handle the result
|
||||
func (s *Scan) resultHandler(scanAdapter *bluetooth.Adapter, result bluetooth.ScanResult) {
|
||||
projVars.ScanAdapter.SetConnectHandler(func(Result bluetooth.Addresser, connected bool) {
|
||||
|
@ -32,46 +32,3 @@ type Scan struct {
|
||||
Devices map[int]*eros.Device
|
||||
}
|
||||
|
||||
func (m *Meta) NewScan() *Scan {
|
||||
// Here we are creating an "anonymous" instance of a Scan struct
|
||||
// You'll notice it doesn't contain most of the data that actually is supposed to live within that struct
|
||||
|
||||
// This works because the integer ID is being used as a key that will have a global scope
|
||||
//
|
||||
// See: Remember function as it is defined in eros/eros.go
|
||||
// Remember usage in this file (scanStuff/scanStuff.go
|
||||
//
|
||||
// In these examples we are sending an instance of a struct with some data to eros; allowing it to finish filling out the rest
|
||||
// This can be done with just structs, but becomes problematic when trying to refer to them later
|
||||
//
|
||||
//TODO: implement Mutex locking from sync in most of these structs to prevent concurrent read/write operations from causing a race w̶a̶r̶ condition
|
||||
// ref: https://gobyexample.com/mutexes
|
||||
// ref: https://golang.org/pkg/sync/#Mutex
|
||||
// ref: https://www.geeksforgeeks.org/mutex-in-golang-with-examples/
|
||||
|
||||
newid := len(m.Scans)
|
||||
|
||||
m.Scans[newid] = &Scan{
|
||||
ID: newid,
|
||||
Started: time.Now(),
|
||||
}
|
||||
|
||||
scan := m.Scans[newid]
|
||||
scan.Devices = make(map[int]*eros.Device)
|
||||
|
||||
m.Count = len(m.Scans)
|
||||
return scan
|
||||
}
|
||||
|
||||
func (s *Scan) NewDevice(name string, addr string, manuf string, rssi int16) *eros.Device {
|
||||
newid := len(s.Devices)
|
||||
s.Devices[newid] = &eros.Device{
|
||||
Name: name,
|
||||
Addr: addr,
|
||||
Manufacturer: manuf,
|
||||
RSSIlast: rssi,
|
||||
}
|
||||
|
||||
s.Count = len(s.Devices)
|
||||
return s.Devices[newid]
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user