Initial import, lots of hard coding
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/.hgignore Wed Feb 27 00:21:12 2019 -0600
@@ -0,0 +1,3 @@
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/commands/byteslice.go Wed Feb 27 00:21:12 2019 -0600
@@ -0,0 +1,23 @@
+// overwrite will overwrite the a with the entire run of b +func overwrite(a, b []byte) { +// equal checks if byte slice a starts with b +func equal(a, b []byte) bool { --- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/commands/commands.go Wed Feb 27 00:21:12 2019 -0600
@@ -0,0 +1,49 @@
+ "bitbucket.org/rw_grim/gousb2snes/protocol" +type Command interface { + Send(rwc io.ReadWriteCloser) error +func sync(rwc io.ReadWriteCloser, opcode protocol.OpCode, ns protocol.Namespace, flags protocol.Flag) ([]byte, error) { + req := make([]byte, 512) + header := []byte{'U', 'S', 'B', 'A', byte(opcode), byte(ns), byte(flags)} + n, err := rwc.Write(req) + return nil, errors.New("failed to write!") + resp := make([]byte, 512) + n, err = rwc.Read(resp[total:]) + if !equal(resp, []byte{'U', 'S', 'B', 'A', byte(protocol.OpCodeResponse)}) { + return nil, errors.New("Bad response") + return nil, errors.New("Bad response") --- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/commands/info.go Wed Feb 27 00:21:12 2019 -0600
@@ -0,0 +1,86 @@
+ "bitbucket.org/rw_grim/gousb2snes/protocol" + InfoFeatureDSPX InfoFeature = 1 << iota +func (f InfoFeature) String() string { + if f&InfoFeatureDSPX != 0 { + r = append(r, "FEAT_DSPX") + if f&InfoFeatureST0010 != 0 { + r = append(r, "FEAT_ST0010") + if f&InfoFeatureSRTC != 0 { + r = append(r, "FEAT_SRTC") + if f&InfoFeatureMSU1 != 0 { + r = append(r, "FEAT_MSU1") + if f&InfoFeature213F != 0 { + r = append(r, "FEAT_213F") + if f&InfoFeatureCmdUnlock != 0 { + r = append(r, "FEAT_CMD_UNLOCK") + if f&InfoFeatureUSB1 != 0 { + r = append(r, "FEAT_USB1") + if f&InfoFeatureDMA1 != 0 { + r = append(r, "FEAT_DMA1") + return strings.Join(r, "|") +func (i *Info) Send(rwc io.ReadWriteCloser) error { + resp, err := sync(rwc, protocol.OpCodeInfo, protocol.NamespaceSNES, protocol.FlagNone) + fwver := binary.BigEndian.Uint32(resp[256:]) + i.fwver = fmt.Sprintf("%08x", fwver) + i.version = nullTerminated(resp[260:]) + i.features = InfoFeature(resp[6]) + i.rom = nullTerminated(resp[16:]) +func (i *Info) String() string { + "version: %s\nfwver: %s\nfeatures: %s\nrom: %s", --- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/commands/string.go Wed Feb 27 00:21:12 2019 -0600
@@ -0,0 +1,15 @@
+func nullTerminated(buffer []byte) string { + for _, b := range buffer { --- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/main.go Wed Feb 27 00:21:12 2019 -0600
@@ -0,0 +1,37 @@
+ "github.com/jacobsa/go-serial/serial" + "bitbucket.org/rw_grim/gousb2snes/commands" + opts := serial.OpenOptions{ + PortName: "/dev/ttyACM0", + sock, err := serial.Open(opts) + fmt.Printf("failed to open serial device : %v\n", err) + info := &commands.Info{} + fmt.Printf("error: %v\n", err) + fmt.Printf("-----\n%s\n", info) --- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/protocol/consts.go Wed Feb 27 00:21:12 2019 -0600
@@ -0,0 +1,45 @@
+ OpCodeGet OpCode = iota + FlagNone Flag = 1 << iota + NamespaceFile Namespace = iota