Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Code doesn't properly handles sends that are bigger than 256 packets #11

Open
drorcohen opened this issue Jul 10, 2018 · 0 comments
Open

Comments

@drorcohen
Copy link

thanks for this project.
Here's my suggested patch that fixes the problem:

commit 5e62af2aa8680164e5b7bd19642ef406054c55cd (HEAD -> handle_files_larger_than_256_packets)
Author: Dror Cohen [email protected]
Date: Tue Jul 10 14:52:28 2018 -0700

This fixes an issue when dealing with files that are bigger than 256 packets

diff --git a/xmodem/xmodem.go b/xmodem/xmodem.go
index 54e6ad3..1b8b62f 100644
--- a/xmodem/xmodem.go
+++ b/xmodem/xmodem.go
@@ -115,18 +115,18 @@ func ModemSend(c io.ReadWriter, data []byte) error {
}

    if oBuffer[0] == POLL {
  •           var blocks uint8 = uint8(len(data) / LONG_PACKET_PAYLOAD_LEN)
    
  •           blocks := len(data) / LONG_PACKET_PAYLOAD_LEN
              if len(data) > int(int(blocks)*int(LONG_PACKET_PAYLOAD_LEN)) {
                      blocks++
              }
    
              failed := 0
    
  •           var currentBlock uint8 = 0
    
  •           currentBlock := 0
              for currentBlock < blocks && failed < 10 {
                      if int(int(currentBlock+1)*int(LONG_PACKET_PAYLOAD_LEN)) > len(data) {
    
  •                           sendBlock(c, currentBlock+1, data[int(currentBlock)*int(LONG_PACKET_PAYLOAD_LEN):])
    
  •                           sendBlock(c, uint8(currentBlock+1), data[int(currentBlock)*int(LONG_PACKET_PAYLOAD_LEN):])
                      } else {
    
  •                           sendBlock(c, currentBlock+1, data[int(currentBlock)*int(LONG_PACKET_PAYLOAD_LEN):(int(currentBlock)+1)*int(LONG_PACKET_PAYLOAD_LEN)])
    
  •                           sendBlock(c, uint8(currentBlock+1), data[int(currentBlock)*int(LONG_PACKET_PAYLOAD_LEN):(int(currentBlock)+1)*int(LONG_PACKET_PAYLOAD_LEN)])
                      }
    
                      if _, err := c.Read(oBuffer); err != nil {
    
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant