Skip to content

Commit

Permalink
fxpakpro: attempt to improve vget, vput by using simpler sendSerial m…
Browse files Browse the repository at this point in the history
…ethod
  • Loading branch information
JamesDunne committed Mar 12, 2024
1 parent cfedd9e commit b7e5b0d
Show file tree
Hide file tree
Showing 14 changed files with 30 additions and 18 deletions.
2 changes: 1 addition & 1 deletion devices/snes/drivers/fxpakpro/boot.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ func (d *Device) boot(ctx context.Context, path string) (err error) {
}

// send command:
err = sendSerial(d.f, 512, sb)
err = sendSerialChunked(d.f, 512, sb)
if err != nil {
err = d.FatalError(err)
return
Expand Down
4 changes: 2 additions & 2 deletions devices/snes/drivers/fxpakpro/control.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ func (d *Device) ResetSystem(ctx context.Context) (err error) {
defer d.lock.Unlock()
}

err = sendSerial(d.f, 512, sb)
err = sendSerialChunked(d.f, 512, sb)
if err != nil {
err = d.FatalError(err)
return
Expand Down Expand Up @@ -55,7 +55,7 @@ func (d *Device) ResetToMenu(ctx context.Context) (err error) {
defer d.lock.Unlock()
}

err = sendSerial(d.f, 512, sb)
err = sendSerialChunked(d.f, 512, sb)
if err != nil {
err = d.FatalError(err)
return
Expand Down
4 changes: 2 additions & 2 deletions devices/snes/drivers/fxpakpro/get.go
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ func (d *Device) get(ctx context.Context, space space, address uint32, size uint
}

// send the data to the USB port:
err = sendSerial(d.f, 512, sb)
err = sendSerialChunked(d.f, 512, sb)
if err != nil {
err = d.FatalError(err)
return
Expand All @@ -40,7 +40,7 @@ func (d *Device) get(ctx context.Context, space space, address uint32, size uint
n = copy(dest, data)
data = data[n:]

err = sendSerial(d.f, 512, sb)
err = sendSerialChunked(d.f, 512, sb)
if err != nil {
err = d.FatalError(err)
return
Expand Down
2 changes: 1 addition & 1 deletion devices/snes/drivers/fxpakpro/getfile.go
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ func (d *Device) getFile(ctx context.Context, path string, w io.Writer, sizeRece
}

// send command:
err = sendSerial(d.f, 512, sb)
err = sendSerialChunked(d.f, 512, sb)
if err != nil {
err = d.FatalError(err)
return
Expand Down
2 changes: 1 addition & 1 deletion devices/snes/drivers/fxpakpro/info.go
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ func (d *Device) info(ctx context.Context) (version, device, rom string, err err
}

// send command:
err = sendSerial(d.f, 512, sb)
err = sendSerialChunked(d.f, 512, sb)
if err != nil {
err = d.FatalError(err)
return
Expand Down
2 changes: 1 addition & 1 deletion devices/snes/drivers/fxpakpro/ls.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ func (d *Device) listFiles(ctx context.Context, path string) (files []devices.Di
}

// send the data to the USB port:
err = sendSerial(d.f, 512, sb)
err = sendSerialChunked(d.f, 512, sb)
if err != nil {
err = d.FatalError(err)
return
Expand Down
2 changes: 1 addition & 1 deletion devices/snes/drivers/fxpakpro/mkdir.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ func (d *Device) mkdir(ctx context.Context, path string) (err error) {
}

// send command:
err = sendSerial(d.f, 512, sb)
err = sendSerialChunked(d.f, 512, sb)
if err != nil {
err = d.FatalError(err)
return
Expand Down
2 changes: 1 addition & 1 deletion devices/snes/drivers/fxpakpro/mv.go
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ func (d *Device) mv(ctx context.Context, path, newFilename string) (err error) {
}

// send command:
err = sendSerial(d.f, 512, sb)
err = sendSerialChunked(d.f, 512, sb)
if err != nil {
err = d.FatalError(err)
return
Expand Down
4 changes: 2 additions & 2 deletions devices/snes/drivers/fxpakpro/put.go
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ func (d *Device) put(ctx context.Context, space space, address uint32, data []by
}

// send the data to the USB port:
err = sendSerial(d.f, 512, sb)
err = sendSerialChunked(d.f, 512, sb)
if err != nil {
err = d.FatalError(err)
return
Expand All @@ -41,7 +41,7 @@ func (d *Device) put(ctx context.Context, space space, address uint32, data []by
n = copy(dest, data)
data = data[n:]

err = sendSerial(d.f, 512, sb)
err = sendSerialChunked(d.f, 512, sb)
if err != nil {
err = d.FatalError(err)
return
Expand Down
2 changes: 1 addition & 1 deletion devices/snes/drivers/fxpakpro/putfile.go
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ func (d *Device) putFile(ctx context.Context, path string, size uint32, r io.Rea
}

// send command:
err = sendSerial(d.f, 512, sb)
err = sendSerialChunked(d.f, 512, sb)
if err != nil {
err = d.FatalError(err)
return
Expand Down
2 changes: 1 addition & 1 deletion devices/snes/drivers/fxpakpro/rm.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ func (d *Device) rm(ctx context.Context, path string) (err error) {
}

// send command:
err = sendSerial(d.f, 512, sb)
err = sendSerialChunked(d.f, 512, sb)
if err != nil {
err = d.FatalError(err)
return
Expand Down
14 changes: 13 additions & 1 deletion devices/snes/drivers/fxpakpro/serial.go
Original file line number Diff line number Diff line change
Expand Up @@ -102,7 +102,19 @@ func writeExact(ctx context.Context, w io.Writer, chunkSize uint32, buf []byte)
return
}

func sendSerial(f serial.Port, chunkSize uint32, buf []byte) (err error) {
func sendSerial(f serial.Port, buf []byte) error {
sent := 0
for sent < len(buf) {
n, e := f.Write(buf[sent:])
if e != nil {
return e
}
sent += n
}
return nil
}

func sendSerialChunked(f serial.Port, chunkSize uint32, buf []byte) (err error) {
_, err = sendSerialProgress(f, chunkSize, uint32(len(buf)), bytes.NewReader(buf), nil)
return
}
Expand Down
2 changes: 1 addition & 1 deletion devices/snes/drivers/fxpakpro/vget.go
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ func (d *Device) vget(ctx context.Context, space space, chunks ...vgetChunk) (er
defer d.lock.Unlock()
}

err = sendSerial(d.f, 64, sb)
err = sendSerial(d.f, sb)
if err != nil {
err = d.FatalError(err)
return
Expand Down
4 changes: 2 additions & 2 deletions devices/snes/drivers/fxpakpro/vput.go
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ func (d *Device) vput(ctx context.Context, space space, chunks ...vputChunk) (er
defer d.lock.Unlock()
}

err = sendSerial(d.f, 64, sb)
err = sendSerial(d.f, sb)
if err != nil {
err = d.FatalError(err)
return
Expand All @@ -68,7 +68,7 @@ func (d *Device) vput(ctx context.Context, space space, chunks ...vputChunk) (er
}

// send the expected number of 64-byte packets:
err = sendSerial(d.f, 64, whole)
err = sendSerial(d.f, whole)
if err != nil {
err = d.FatalError(err)
return
Expand Down

0 comments on commit b7e5b0d

Please sign in to comment.