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 - handle disconnects via exit
- sets up cleaner device handling via multiplexing - 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 // basic manager
// I dont think I actually need this interface, package manager has a point
type Manager interface { type Manager interface {
Start() error Start() error
Exit() error Exit() error

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

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

Loading…
Cancel
Save