File: hci_updown.go

package info (click to toggle)
golang-github-muka-go-bluetooth 5.60-3
  • links: PTS, VCS
  • area: main
  • in suites: bookworm, forky, sid, trixie
  • size: 2,688 kB
  • sloc: makefile: 92; sh: 2
file content (36 lines) | stat: -rw-r--r-- 670 bytes parent folder | download
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
package hci_updown_example

import (
	"fmt"
	"strconv"
	"strings"

	"github.com/muka/go-bluetooth/hw/linux/hci"
	log "github.com/sirupsen/logrus"
)

//HciUpDownExample hciconfig up / down
func Run(rawAdapterID string) error {

	log.Info("Turn down")

	adapterID, err := strconv.Atoi(strings.Replace(rawAdapterID, "hci", "", 1))
	if err != nil {
		return err
	}

	err = hci.Down(adapterID)
	if err != nil {
		return fmt.Errorf("Failed to stop device hci%d: %s", adapterID, err.Error())
	}

	log.Info("Turn on")
	err = hci.Up(adapterID)
	if err != nil {
		return fmt.Errorf("Failed to start device hci%d: %s", adapterID, err.Error())
	}

	log.Info("Done.")

	return nil
}