broken checkpoint, switching to rust micro core

main
KeeganForelight 2 years ago
parent ec160cd2d8
commit dad0f8ac2b

@ -27,3 +27,23 @@ I can take advantage of the private network created via wireguard to allow the s
- handle disconnects via exit
- sets up cleaner device handling via multiplexing
# Jan 24
### Proto changes
It's time to refactor the current protobuf stuff to make more sense from the servers perspective. In this sense, I am going to have the reactor provide connection details to the server on connect, and then the server can connect/disconnect at will.
### Outline
- Update the server to connect to the reactor itself for the information
- Decide what information is important enough to send to the server consistently, vs what only is needed upon "further inspection"
- need reactor information on connect
- need basic device information such as address and status
- when selected
- need specific device breakouts with advanced functions per device
- this can be multiplexed over the same gRPC connection and can be fulfilled by the device coordinator
- dc will catch all incoming requests and forward to the correct DM based on address
### TODO
- reverse monitoring stuff
- make it so reactor manager has a timeout/ recognizes disconnects gracefully
- convert monitoring to a stream as opposed to consistent calls

@ -19,6 +19,7 @@ import (
)
// basic manager
// I dont think I actually need this interface, package manager has a point
type Manager interface {
Start() error
Exit() error

@ -46,16 +46,11 @@ type ReactorManager struct {
func NewReactorManager(cl *Client, config *viper.Viper, errCh chan error) *ReactorManager {
// making managers
m := NewManager(6)
//dm := make(map[int]DeviceManager)
//rd := &ReactorDevices{Devices: dm}
//cm := NewClientManager(cl)
r := &ReactorManager{
//ClientManager: cm,
Manager: m,
Client: cl,
//ReactorDevices: rd,
Config: config,
Err: errCh,
Config: config,
Err: errCh,
}
return r
}

@ -1,3 +1,4 @@
// package system uses linux commands to get hardware info from devices
package system
import (
@ -10,20 +11,9 @@ import (
"strings"
)
// this package serves to add in wrappers for system commands to get hwinfo from the board
// this package does not actually use the hwinfo command, but rather gathers hardware info from a variety of commands
// command for model :
// lshw -C system 2>/dev/null | head -n 1
// command for ip && mac address :
// ifconfig eth0 | awk '/inet |ether / {print $2}'
// can combine and dump into file using
// lshw -C system 2>/dev/null | head -n 1 > hwinfo.txt && ifconfig eth0 | awk '/inet |ether / {print $2}' >> hwinfo.txt
// *** will just replace info in file everytime
func GetId(eth string) (int, error) {
maccmd := fmt.Sprintf("ifconfig %v | awk '/ether / {print $2}'", eth)
func GetId() (int, error) {
// gets the mac address and hashes into consistent id
maccmd := fmt.Sprintf("ifconfig %v | awk '/ether / {print $2}'", et)
var stderr bytes.Buffer
var out bytes.Buffer
cmd := exec.Command("bash", "-c", maccmd)
@ -38,8 +28,8 @@ func GetId(eth string) (int, error) {
return int(id), nil
}
func GetIp(eth string) (string, error) {
ipcmd := fmt.Sprintf("ifconfig %v | awk '/inet / {print $2}'", eth)
func GetIp() (string, error) {
ipcmd := "ip route get 1 | sed 's/^.*src \([^ ]*\).*$/\1/;q'"
var stderr bytes.Buffer
var out bytes.Buffer
cmd := exec.Command("bash", "-c", ipcmd)
@ -54,6 +44,7 @@ func GetIp(eth string) (string, error) {
}
func GetPort() (int, error) {
// obsolete
if addr, err := net.ResolveTCPAddr("tcp", ":0"); err != nil {
return 0, err
} else if lis, err := net.ListenTCP("tcp", addr); err != nil {
@ -65,28 +56,25 @@ func GetPort() (int, error) {
}
func GetBus() (int, error) {
bus := map[string]int{"raspberrypi": 1, "beaglebone": 2}
devname := "lshw -C system 2>/dev/null | head -n 1"
var stderr, out bytes.Buffer
cmd := exec.Command("bash", "-c", devname)
cmd.Stdout = &out
cmd.Stderr = &stderr
if err := cmd.Run(); err != nil {
return 0, err
}
b := out.String()
b = strings.Trim(b, " \n")
if bs, ok := bus[b]; !ok {
return 0, errors.New(fmt.Sprintf("No bus for dev %v", b))
} else {
return bs, nil
// preset busses
busList := map[string]int{"raspberrypi": 1, "beaglebone": 2}
// vars
var bus int
var ok bool
if name, err =: GetModel(); err != nil {
return bus, err
} else if bus, ok = busList[b]; !ok {
return 0, errors.New(fmt.Sprintf("No bus for dev %s", b))
}
// returns correct bus
return bus, nil
}
func GetModel() (string, error) {
devname := "lshw -C system 2>/dev/null | head -n 1"
var stderr, out bytes.Buffer
cmd := exec.Command("bash", "-c", devname)
cmd := exec.Command("bash", "-c", "hostname")
cmd.Stdout = &out
cmd.Stderr = &stderr
if err := cmd.Run(); err != nil {

Loading…
Cancel
Save