Documentation
¶
Index ¶
- Constants
- Variables
- func CopyFile(src string, dst string) error
- func CreatePort(portName string) (io.ReadWriteCloser, error)
- func Dir(useLocal bool, name string) http.FileSystem
- func FS(useLocal bool) http.FileSystem
- func FSByte(useLocal bool, name string) ([]byte, error)
- func FSMustByte(useLocal bool, name string) []byte
- func FSMustString(useLocal bool, name string) string
- func FSString(useLocal bool, name string) (string, error)
- func FenCharToFigurine(piece string) string
- func GetFigurineName(fenChar string) string
- func GetImageName(fenChar string, iCol int, iRow int) string
- func GetImagePath(fenChar string, iCol int, iRow int, size int) string
- func GetSquare(iCol int, iRow int) string
- func SimpleBoardFromFen(fen string) []string
- func UnicodeBoardFromFen(fen string) []string
- func WriteBoardAsPng(fen string, size int, w io.Writer)
- func WritePng(fen string, size int, filename string)
- type BoardUpdate
- type Command
- type DgtBoard
- type FieldUpdate
- type InfoUpdate
- type Message
- type MessageProcessor
- func (mp *MessageProcessor) Air() string
- func (mp *MessageProcessor) AirState() string
- func (mp *MessageProcessor) Dropped() string
- func (mp *MessageProcessor) GetPieceLifted(square chess.Sq) chess.Piece
- func (mp *MessageProcessor) GetSpecialAirState() (chess.Sq, chess.Piece)
- func (mp *MessageProcessor) IsMovePseudoLegal() bool
- func (mp *MessageProcessor) LogAirState()
- func (mp *MessageProcessor) ProcessMessage(m *Message)
- type TimeUpdate
Constants ¶
const BBISHOP = 0x0a
const BCROWN = 0x0a
const BDISK = 0x04
const BKING = 0x0b
const BKNIGHT = 0x09
const BPAWN = 0x07
const BQUEEN = 0x0c
const BROOK = 0x08
const DGT_BATTERY_STATUS = 0x20
Added for Bluetooth board
const DGT_BOARD_DUMP = 0x06
const DGT_BOARD_DUMP_50B = 0x14
Added for Draughts board
const DGT_BOARD_DUMP_50W = 0x15
const DGT_BUSADRES = 0x10
const DGT_BWTIME = 0x0d
const DGT_CLOCK_MESSAGE = 0x2b
const DGT_CMD_CLOCK_ASCII = 0x0c
const DGT_CMD_CLOCK_BEEP = 0x0b
const DGT_CMD_CLOCK_BUTTON = 0x08
const DGT_CMD_CLOCK_DISPLAY = 0x01
const DGT_CMD_CLOCK_END = 0x03
const DGT_CMD_CLOCK_ICONS = 0x02
const DGT_CMD_CLOCK_SETNRUN = 0x0a
const DGT_CMD_CLOCK_VERSION = 0x09
const DGT_EE_MOVES = 0x0f
const DGT_FIELD_UPDATE = 0x0e
const DGT_LONG_SERIALNR = 0x22
const DGT_MSG_BATTERY_STATUS = (MESSAGE_BIT | DGT_BATTERY_STATUS)
------------------------------------------------------------------------ Retrieve the battery status from the Bluetooth board
const DGT_MSG_BOARD_DUMP = (MESSAGE_BIT | DGT_BOARD_DUMP)
------------------------------------------------------------------------ DGT_MSG_BOARD_DUMP is the message that follows on a DGT_SEND_BOARD * command
const DGT_MSG_BOARD_DUMP_50B = (MESSAGE_BIT | DGT_BOARD_DUMP_50B)
------------------------------------------------------------------------ message format DGT_MSG_BOARD_DUMP_50B
const DGT_MSG_BOARD_DUMP_50W = (MESSAGE_BIT | DGT_BOARD_DUMP_50W)
------------------------------------------------------------------------ message format DGT_MSG_BOARD_DUMP_50W
const DGT_MSG_BUSADRES = (MESSAGE_BIT | DGT_BUSADRES)
------------------------------------------------------------------------ Message format DGT_MSG_BUSADRES return message with bus adres
const DGT_MSG_BWTIME = (MESSAGE_BIT | DGT_BWTIME)
------------------------------------------------------------------------ message format DGT_MSG_BWTIME
const DGT_MSG_EE_MOVES = (MESSAGE_BIT | DGT_EE_MOVES)
------------------------------------------------------------------------ DGT_SIZE_EE_MOVES is defined in dgt_ee1.h: current (0x2000-0x100+3)
const DGT_MSG_FIELD_UPDATE = (MESSAGE_BIT | DGT_FIELD_UPDATE)
------------------------------------------------------------------------ message format DGT_MSG_FIELD_UPDATE:
const DGT_MSG_LONG_SERIALNR = (MESSAGE_BIT | DGT_LONG_SERIALNR)
------------------------------------------------------------------------ Message format DGT_LONG_SERIALNR
const DGT_MSG_SERIALNR = (MESSAGE_BIT | DGT_SERIALNR)
------------------------------------------------------------------------ Message format DGT_MSG_SERIALNR return message with bus adres
const DGT_MSG_TRADEMARK = (MESSAGE_BIT | DGT_TRADEMARK)
------------------------------------------------------------------------ message format: DGT_MSG_TRADEMARK which returns a trade mark message
const DGT_MSG_VERSION = (MESSAGE_BIT | DGT_VERSION)
------------------------------------------------------------------------ Message format DGT_MSG_VERSION return message with bus adres
const DGT_NONE = 0x00
ID codes:
const DGT_RETURN_BUSADRES = 0x46
const DGT_RETURN_LONG_SERIALNR = 0x55
const DGT_RETURN_SERIALNR = 0x45
const DGT_SCAN_100 = 0x54
const DGT_SCAN_50B = 0x51
const DGT_SCAN_50W = 0x53
const DGT_SEND_BATTERY_STATUS = 0x4c
const DGT_SEND_BRD = 0x42
const DGT_SEND_BRD_50B = 0x50
const DGT_SEND_BRD_50W = 0x52
const DGT_SEND_CLK = 0x41
const DGT_SEND_EE_MOVES = 0x49
const DGT_SEND_RESET = 0x40
const DGT_SEND_TRADEMARK = 0x47
const DGT_SEND_UPDATE = 0x43
const DGT_SEND_UPDATE_BRD = 0x44
const DGT_SEND_UPDATE_NICE = 0x4b
const DGT_SEND_VERSION = 0x4d
const DGT_SERIALNR = 0x11
const DGT_SET_LEDS = 0x60
const DGT_SIZE_BATTERY_STATUS = 7
const DGT_SIZE_BOARD_DUMP = 67
const DGT_SIZE_BOARD_DUMP_50B = 53
const DGT_SIZE_BOARD_DUMP_50W = 53
const DGT_SIZE_BOARD_DUMP_DRAUGHTS = 103
const DGT_SIZE_BUSADRES = 5
const DGT_SIZE_BWTIME = 10
const DGT_SIZE_FIELD_UPDATE = 5
const DGT_SIZE_LONG_SERIALNR = 13
const DGT_SIZE_SERIALNR = 8
const DGT_SIZE_VERSION = 5
const DGT_STARTBOOTLOADER = 0x4e
const DGT_TO_BUSMODE = 0x4a
const DGT_TRADEMARK = 0x12
const DGT_VERSION = 0x13
const EMPTY = 0x00
Piece codes for chess pieces:
const MESSAGE_BIT = 0x80
the Message ID is the logical OR of MESSAGE_BIT and ID code
const MESSAGE_MASK = 0x7F
const PIECE1 = 0x0d /* Magic piece: Draw */
const PIECE2 = 0x0e /* Magic piece: White win */
const PIECE3 = 0x0f /* Magic piece: Black win */
const WBISHOP = 0x04
const WCROWN = 0x07
const WDISK = 0x01
For the draughts board
const WKING = 0x05
const WKNIGHT = 0x03
const WPAWN = 0x01
const WQUEEN = 0x06
const WROOK = 0x02
Variables ¶
var ERR_CLOCK_ACK = errors.New("Clock ACK (Unhandled)")
var ERR_CLOCK_NOT_CONNECTED = errors.New("Clock Not Connected")
var ERR_CLOCK_NOT_RUNNNING = errors.New("Clock Not Running")
var ERR_NONE_COMMAND = errors.New("NONE Command")
var ERR_NOT_ENOUGH_DATA = errors.New("Not enough data")
var ERR_PARSE_FAILED = errors.New("Failed to parse bytes")
var ERR_UNHANDLED = errors.New("Unhandled")
Functions ¶
func CreatePort ¶
func CreatePort(portName string) (io.ReadWriteCloser, error)
func Dir ¶
func Dir(useLocal bool, name string) http.FileSystem
Dir returns a http.Filesystem for the embedded assets on a given prefix dir. If useLocal is true, the filesystem's contents are instead used.
func FS ¶
func FS(useLocal bool) http.FileSystem
FS returns a http.Filesystem for the embedded assets. If useLocal is true, the filesystem's contents are instead used.
func FSByte ¶
FSByte returns the named file from the embedded assets. If useLocal is true, the filesystem's contents are instead used.
func FSMustByte ¶
FSMustByte is the same as FSByte, but panics if name is not present.
func FSMustString ¶
FSMustString is the string version of FSMustByte.
func FenCharToFigurine ¶
CharToUnicode converts a simple "FEN" character (that is, Q=white queen, p=black pawn, etc) into a single-rune unicode string containing the unicode figurine for that piece.
func GetFigurineName ¶
func SimpleBoardFromFen ¶
func UnicodeBoardFromFen ¶
Types ¶
type BoardUpdate ¶
func NewBoardUpdate ¶
func NewBoardUpdate(board *chess.Board) *BoardUpdate
BoardUpdate contains a full position update from the DGT board. Note that instead of making the Message rely directly on the board representation, we hide the specifics of the representation inside a small wrapper (BoardUpdate), which helps insulate the code from changes to the board representation.
func (*BoardUpdate) ToString ¶
func (b *BoardUpdate) ToString() string
type DgtBoard ¶
type FieldUpdate ¶
FieldUpdate encapsulates a raw field update from a DGT board. It's not a full chess move. It consists of detecting a piece (including the special piece EMPTY) moving into a square.
func NewFieldUpdate ¶
func NewFieldUpdate(square chess.Sq, piece chess.Piece) *FieldUpdate
func (*FieldUpdate) PieceLetter ¶
func (fu *FieldUpdate) PieceLetter() string
func (*FieldUpdate) ToString ¶
func (fu *FieldUpdate) ToString() string
type InfoUpdate ¶
type InfoUpdate struct {
// contains filtered or unexported fields
}
func NewInfoUpdate ¶
func NewInfoUpdate(info string) *InfoUpdate
func (*InfoUpdate) ToString ¶
func (iu *InfoUpdate) ToString() string
type Message ¶
type Message struct { BoardUpdate *BoardUpdate FieldUpdate *FieldUpdate TimeUpdate *TimeUpdate InfoUpdate *InfoUpdate }
Message is really just a way to multiplex three different types of message onto a single channel.
func NewBoardUpdateMessage ¶
func NewBoardUpdateMessage(boardUpdate *BoardUpdate) *Message
func NewFieldUpdateMessage ¶
func NewFieldUpdateMessage(fieldUpdate *FieldUpdate) *Message
func NewInfoUpdateMessage ¶
func NewTimeUpdateMessage ¶
func NewTimeUpdateMessage(timeUpdate *TimeUpdate) *Message
type MessageProcessor ¶
type MessageProcessor struct { Board *chess.Board // The first piece lifted; we use this to help us // signal special configurations from the board. FirstPieceUp *FieldUpdate // Could use interface{}, yadda yadda PiecesInTheAir map[chess.Sq]chess.Piece PiecesDropped map[chess.Sq]chess.Piece }
func NewMessageProcessor ¶
func NewMessageProcessor() *MessageProcessor
func (*MessageProcessor) Air ¶
func (mp *MessageProcessor) Air() string
func (*MessageProcessor) AirState ¶
func (mp *MessageProcessor) AirState() string
func (*MessageProcessor) Dropped ¶
func (mp *MessageProcessor) Dropped() string
func (*MessageProcessor) GetPieceLifted ¶
func (mp *MessageProcessor) GetPieceLifted(square chess.Sq) chess.Piece
GetPieceLifted returns the piece that was lifted from a square. We can't look directly into the Board because until we have decoded an entire move it doesn't get updated. Image the following sequence of meaningless and illegal physical piece moves by White:
e2f3, Ke2, Ke1, f3e2
At the end of the sequence, all the pieces have returned back to their starting square, meaning that White's next legal move *should* be recognised and accepted. However, when White moves his King from e2 back to e1, we need to "know" that the piece being lifted is the King, not the pawn originally on e2! Don't forget, we don't actually receive a message saying, "White King lifted"; we receive a messsage saying, "e2 is now empty", and we have to work out what piece was moved.
func (*MessageProcessor) GetSpecialAirState ¶
func (mp *MessageProcessor) GetSpecialAirState() (chess.Sq, chess.Piece)
func (*MessageProcessor) IsMovePseudoLegal ¶
func (mp *MessageProcessor) IsMovePseudoLegal() bool
func (*MessageProcessor) LogAirState ¶
func (mp *MessageProcessor) LogAirState()
func (*MessageProcessor) ProcessMessage ¶
func (mp *MessageProcessor) ProcessMessage(m *Message)
type TimeUpdate ¶
type TimeUpdate struct { }
TimeUpdate encapsulates a raw time update from a DGT board.
func NewTimeUpdate ¶
func NewTimeUpdate() *TimeUpdate
func (*TimeUpdate) ToString ¶
func (tu *TimeUpdate) ToString() string
Source Files
¶
- assets.go
- boardUpdate.go
- command.go
- copyfile.go
- dgtboard.go
- dgtconstants.go
- fieldUpdate.go
- handleBoardUpdate.go
- handleFieldUpdate.go
- handleTime.go
- handleTrademarkMessage.go
- handleUnhandledCommand.go
- handleVersionMessage.go
- infoUpdate.go
- message.go
- parseBytes.go
- pieces.go
- pngwriter.go
- processMessages.go
- readLoop.go
- serial.go
- timeUpdate.go