b6max

package module
v0.0.0-...-492aed3 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Jul 9, 2019 License: Apache-2.0 Imports: 8 Imported by: 0

README

package b6max

This is a Go library and CLI for interfacing with SkyRC iMAX style chargers over USB.

Basic library usage

package main

import (
  "fmt"
  "github.com/buxtronix/b6max
)

func main() {
  device, err := b6max.OpenFirst()
  if err != nil {
    fmt.Error(err.Error())
    return
  }
  defer device.Close()

  di, err := device.ReadDevInfo()
  if err != nil {
    fmt.Error(err.Error())
    return
  }
  fmt.Printf("Device info:\n%s", di)

  si, err := device.ReadSysInfo()
  if err != nil {
    fmt.Error(err.Error())
    return
  }
  fmt.Printf("System info:\n%s", si)
}

CLI basic usage

$ ./main 
Control program for SkyRC IMAX battery chargers.

Allows for querying and controlling these battery chargers
including charging, discharging, repeaking, rebalancing and more.

Supports chargers with direct USB connection, tested with
SkyRC IMAX B6AC V2.

Usage:
  b6max [command]

Available Commands:
  balance     Rebalance the cells of a battery (Li* only)
  charge      Run a battery charge program
  discharge   Run a battery discharge cycle
  help        Help about any command
  info        Query and display info about the attached charger
  repeak      Run a repeak cycle of the battery (NiMh/NiCd only)
  stop        Stop the currently running program
  storage     Charge or discharge the battery to a storage voltage (Li* only)
  watch       Watch status of currently running program

Flags:
      --config string   config file (default is $HOME/.cli.yaml)
  -d, --device string   Open specific USB device
  -h, --help            help for b6max
      --verbose         verbose logging

Use "b6max [command] --help" for more information about a command.
$ b6max info
Core Type : 100084
Versions  : hw: 1.00    sw: 0.11
Time Limit     : 300m (enabled: false)
Capacity Limit : 8000mV (enabled: false)
Beeps          : key (true), system (true)
Vin low limit  : 11.00v
Temp limit     : 80C
Current voltage: 0.98v
Cell voltages  : C1:0.53v C2:0.27v C3:0.28v C4:0.28v C5:0.28v C6:0.28v
State      Time    mAh       Voltage  Current   TempExt  TempInt  Imp    C1     C2      C3      C4     C5     C6
Idle           0       0    8.000v     0.26A     42C       248C      0Ω   20.483v  53.506v  4.865v  3.841v  5.633v  7.425v
$

USB device access

To access the USB device, you need to either run the binary as 'root' (discouraged), or add the following udev rule:

SUBSYSTEM=="usb", ATTRS{idVendor}=="0000", ATTRS{idProduct}=="0001", MODE:="666", GROUP="plugdev"
KERNEL=="hidraw*", ATTRS{idVendor}=="0000", ATTRS{idProduct}=="0001", MODE="0666", GROUP="plugdev"

TODO

  • Include standard battery profiles
  • Add a web server with graphs, etc.
  • Write settings back to device
  • Log charge data for analysis, etc
  • Unit tests

Etc...

Copyright 2019 Ben Buxton bbuxton@gmail.com.

Licenced under the Apache 2.0 licence.

PRs gladly accepted!

Documentation

Overview

Package b6max provides for communication to SkyRC iMAX and compatible battery chargers.

Tested on SkyRC iMAX B6V2. May work with others.

Index

Constants

View Source
const (
	ChargeDischarge = iota
	DischargeCharge
)

Variables

This section is empty.

Functions

This section is empty.

Types

type B6Max

type B6Max struct {
	// UsbInfo is the underlying USB information.
	UsbInfo usb.DeviceInfo
	// UsbDevice is the opened USB connection.
	UsbDevice usb.Device
}

B6Max represents a B6Max device.

func Find

func Find() ([]*B6Max, error)

Find searches for connected B6Max devices.

func OpenFirst

func OpenFirst() (*B6Max, error)

OpenFirst finds and opens the first available device.

func (*B6Max) Close

func (b *B6Max) Close() error

Close closes the USB connection.

func (*B6Max) Open

func (b *B6Max) Open() error

Open opens the USB connection.

func (*B6Max) ReadDevInfo

func (b *B6Max) ReadDevInfo() (*DevInfo, error)

ReadDevInfo reads device hardware and software parameters.

func (*B6Max) ReadProgramState

func (b *B6Max) ReadProgramState() (*ProgramState, error)

ReadProgramState reads the current (dis)charging status.

func (*B6Max) ReadSysInfo

func (b *B6Max) ReadSysInfo() (*SysInfo, error)

ReadSysInfo reads the system config information from the device.

func (*B6Max) Start

func (b *B6Max) Start(p *ProgramStart) error

Start tells the device to start a program per the provided parameters.

func (*B6Max) Stop

func (b *B6Max) Stop() (*ProgramStop, error)

Stop sends a stop command to the device.

type BatteryType

type BatteryType uint8

BatteryType is the battery type connected.

const (
	LiPo BatteryType = iota
	LiIo
	LiFe
	// LiHv slots in here for newer chargers (changes const values)
	NiMh
	NiCd
	Pb
)

func (BatteryType) String

func (b BatteryType) String() string

type CycleType

type CycleType uint8

Cycle types.

func (CycleType) String

func (c CycleType) String() string

type DevInfo

type DevInfo struct {

	// CoreType is the core type of the device.
	CoreType [6]byte
	// UpgradeType is ??
	UpgradeType uint8
	// IsEncrypt is ??
	IsEncrypt uint8
	// CustomerID is ??
	CustomerID uint16
	// LanguageID is ??
	LanguageID uint8
	// SwVersion is the current software version.
	SwVersion uint16
	// HwVersion is the current hardware version.
	HwVersion uint8
	// contains filtered or unexported fields
}

DevInfo represents device hardware configuration.

func (*DevInfo) String

func (d *DevInfo) String() string

String returns the string format of DevInfo returned data.

type ProgramStart

type ProgramStart struct {

	// The battery type connected.
	BatteryType BatteryType
	// Number of cells.
	Cells byte
	// Program type requested.
	PwmMode ProgramType
	// Maximum charge current requested.
	ChargeCurrent uint16
	// Maximum discharge current requested.
	DischargeCurrent uint16
	// Discharge cutoff voltage, millivolts.
	DischargeCutoff uint16
	// Cutoff voltage for charging.
	// For Ni* batteries, this is the delta-v end-of-charge detection (typically 4mv)
	ChargeCutoff uint16
	// Thie field depends on the charge mode. If RePeak, it's the number of
	// cycles to perform. If Cycle, it's the cycle type.
	RePeakCycleInfo uint8
	// Number of charge/discharge cycles in Cycle mode. 1-5
	CycleCount uint8
	// Trickle charge (mA).
	Trickle uint16
	// contains filtered or unexported fields
}

ProgramStart is a request to start a program.

type ProgramState

type ProgramState struct {

	// WorkState is the current device state.
	WorkState State
	// ErrorCode is the error code, if WorkState is StateError.
	// If not errored, the total (dis)charge current at this moment.
	ErrorCodeMah uint16
	// Number of seconds the program has been running.
	Time uint16
	// The voltage at this moment.
	MilliVolt uint16
	// The current at this moment.
	MilliAmp uint16
	// Temperature of the external sensor.
	TemperatureExternal uint8
	// Temperature of the internal sensor.
	TemperatureInternal uint8
	// Impedance of the attached battery.
	Impedance uint16
	// Voltage of the attached cells at the balance port.
	Cells [6]uint16
	// contains filtered or unexported fields
}

ProgramState represents current program info.

func (*ProgramState) Header

func (p *ProgramState) Header() string

Header returns a header string for displaying ProgramState.

func (*ProgramState) String

func (p *ProgramState) String() string

String returns a string of the current ProgramState.

type ProgramStop

type ProgramStop struct {
}

ProgramStop implements a stop program command.

type ProgramType

type ProgramType uint8

ProgramType is the requested program type.

const (
	Charge ProgramType = iota
	Discharge
	Storage
	FastCharge
	Balance
	AutoCharge
	RePeak
	Cycle
)

func (ProgramType) String

func (p ProgramType) String() string

type State

type State uint8

State is the current operating state.

const (
	StateRunning State
	StateIdle
	StateFinish
	StateError
)

func (State) String

func (s State) String() string

type SysInfo

type SysInfo struct {

	// CycleTime is the rest time between charge->discharge cycles (minutes, max 60).
	CycleTime uint8
	// TimeLimitOn is whether the time limit is enabled.
	TimeLimitOn uint8
	// TimeLimit is the maximum duration of a program (minutes).
	TimeLimit uint16
	// CapLimitOn is whether the Cap limit is enabled.
	CapLimitOn uint8
	// CapLimit is the maximum charge mAh for a program.
	CapLimit uint16
	// KeyBuzz is whether the keypress sound is enabled.
	KeyBuzz uint8
	// SysBuzz is whether system sounds are enabled.
	SysBuzz uint8
	// InDCLow is the lower DC input voltage limit.
	InDCLowLimit uint16
	// TempLimit is the maximum allowed operating temperature (Celcius).
	TemperatureLimit uint8
	// Voltage represents the current voltage of ??
	Millivolts uint16
	// Cells are the current voltages of the cells at the balance port.
	Cells [6]uint16
	// contains filtered or unexported fields
}

SysInfo represents system configuration information.

func (*SysInfo) String

func (s *SysInfo) String() string

String returns the string format of SysInfo returned data.

Directories

Path Synopsis
cli
cmd

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL