xmodem 0.1.0 → 0.1.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: e62cc5ccbbce783916e98a6d66ec6b54f7fbb6b0
4
- data.tar.gz: 769b8532fbcba742e1b9004c532cfda1092db3f1
3
+ metadata.gz: 6f7f3521ab6749bb39dd3e4eeea3461415202291
4
+ data.tar.gz: 584c4d042ecc4e33579920c2e5aad0153bed3eb8
5
5
  SHA512:
6
- metadata.gz: 7cc854f7451a5e03e4a976991d746ececcd0ffb93f2727bcda8bc358ab2fbefc9d8ca7c66e1d914a91eeed21678a3003cf7f590ebebf4c93078b99d39b625874
7
- data.tar.gz: 8c692ded57abbbbd37f56c3ec53d7b486e4d73561eb66dd4dae5d8b0774142ee66faf007894fe9cee8d8d37216ca71964140a7f22354358e490cd48fce47d192
6
+ metadata.gz: 078560c1b718c310acbd13e148cb783d4f4868ed7db0aa6da38b5ed17827732278a4288bce4f856af0b843a8a8d9e905a2b273252ad365ce9998960860957f91
7
+ data.tar.gz: 03cc944a4f0876bbf41dd88776e09aa14e16fd856b4de4f2d6fc03a990e6a26503c2b9d0ba690a9d6284226014450ff9b17fa3e24ff00c075adec8e565638456
data/README.md CHANGED
@@ -1,5 +1,10 @@
1
1
  ## Synopsis
2
2
 
3
+ [![Build Status](https://travis-ci.org/exsilium/xmodem.svg?branch=master)](https://travis-ci.org/exsilium/xmodem)
4
+ [![Coverage Status](https://coveralls.io/repos/exsilium/xmodem/badge.svg)](https://coveralls.io/r/exsilium/xmodem)
5
+ [![Dependency Status](https://gemnasium.com/exsilium/xmodem.svg)](https://gemnasium.com/exsilium/xmodem)
6
+ [![Code Climate](https://codeclimate.com/github/exsilium/xmodem/badges/gpa.svg)](https://codeclimate.com/github/exsilium/xmodem)
7
+
3
8
  A pure XMODEM implementation in Ruby for sender and receiver. Compatible with Ruby 1.9.3+
4
9
 
5
10
  ## Code Example
@@ -3,26 +3,19 @@
3
3
  #
4
4
  # License:: Mozilla Public License 1.1
5
5
  #
6
- # Doesn't seem to work for me using Ruby 2.0 - BORKEN unless fixed
7
- #
8
- # Public interface changes:
9
- # - ModemProtocols renamed to XMODEM
10
- # - xmodem_tx renamed to send
11
- # - xmodem_rx renamed to receive
12
- # - Logger outputs reflect the actors sender/receiver
13
6
 
14
7
  require 'log4r'
15
8
  include Log4r
16
9
 
17
10
  module XMODEM
18
11
 
19
- XMODEM_BLOCK_SIZE = 128 #how many bytes (ecluding header & checksum) in each block?
20
12
  XMODEM_MAX_TIMEOUTS = 5 #how many timeouts in a row before the sender gives up?
21
13
  XMODEM_MAX_ERRORS = 10 #how many errors on a single block before the receiver gives up?
22
-
23
14
  XMODEM_CRC_ATTEMPTS = 3 #how many times should receiver attempt to use CRC?
24
15
  LOG_NAME='XModem'
25
- @timeout_seconds = 5.0 #default timeout period
16
+
17
+ @timeout_seconds = 5.0 #default timeout period
18
+ @block_size = 128 #how many bytes (excluding header & checksum) in each block?
26
19
 
27
20
  #how long does the protocol wait before giving up?
28
21
  def XMODEM::timeout_seconds
@@ -30,7 +23,16 @@ module XMODEM
30
23
  end
31
24
 
32
25
  def XMODEM::timeout_seconds=(val)
33
- @timeout_seconds=val
26
+ @timeout_seconds = val
27
+ end
28
+
29
+ #how long does the protocol wait before giving up?
30
+ def XMODEM::block_size
31
+ @block_size
32
+ end
33
+
34
+ def XMODEM::block_size=(val)
35
+ @block_size = val
34
36
  end
35
37
 
36
38
  # receive a file using XMODEM protocol (block size = 128 bytes)
@@ -103,7 +105,7 @@ module XMODEM
103
105
  local<<last_block
104
106
  last_block=""
105
107
  end
106
- XMODEM_BLOCK_SIZE.times do
108
+ block_size.times do
107
109
  b=(receive_getbyte(remote))
108
110
  data<<b
109
111
  Thread.pass
@@ -161,7 +163,7 @@ module XMODEM
161
163
  current_block=""
162
164
  sent_eot=false
163
165
 
164
- XMODEM_BLOCK_SIZE.times do
166
+ block_size.times do
165
167
  b=(local.eof? ? FILLER : local.getc)
166
168
  current_block<<b.chr
167
169
  Thread.pass
@@ -180,7 +182,7 @@ module XMODEM
180
182
  break
181
183
  end
182
184
  tx_cmd=remote.getc.ord
183
- logger.debug "sendder: got 0x#{"%x" % tx_cmd}"
185
+ logger.debug "sender: got 0x#{"%x" % tx_cmd}"
184
186
  if tx_cmd==ACK then
185
187
  if sent_eot then
186
188
  logger.debug "sender: got ACK of EOT"
@@ -195,7 +197,7 @@ module XMODEM
195
197
  end
196
198
  block_number=((block_number+1)%0x100)
197
199
  current_block=""
198
- XMODEM_BLOCK_SIZE.times do
200
+ block_size.times do
199
201
  b=(local.eof? ? FILLER : local.getc)
200
202
  current_block<<b
201
203
  Thread.pass
@@ -231,7 +233,7 @@ module XMODEM
231
233
  #calculate an 8-bit XMODEM checksum
232
234
  #this is just the sum of all bytes modulo 0x100
233
235
  def XMODEM::checksum(block)
234
- raise RXChecksumError.new("checksum requested of invalid block {size should be #{XMODEM_BLOCK_SIZE}, was #{block.length}") unless block.length==XMODEM_BLOCK_SIZE
236
+ raise RXChecksumError.new("checksum requested of invalid block {size should be #{block_size}, was #{block.length}") unless block.length==block_size
235
237
  checksum=0
236
238
  block.each_byte do |b|
237
239
  checksum = (checksum+b) % 0x100
@@ -242,7 +244,7 @@ module XMODEM
242
244
  #calculate a 16-bit CRC
243
245
  def XMODEM::ccitt16_crc(block)
244
246
  # cribbed from http://www.hadermann.be/blog/32/ruby-crc16-implementation/
245
- raise RXChecksumError.new("checksum requested of invalid block {size should be #{XMODEM_BLOCK_SIZE}, was #{block.length}") unless block.length==XMODEM_BLOCK_SIZE
247
+ raise RXChecksumError.new("checksum requested of invalid block {size should be #{block_size}, was #{block.length}") unless block.length==block_size
246
248
  crc=0
247
249
  block.each_byte{|x| crc = ((crc<<8) ^ CCITT_16[(crc>>8) ^ x])&0xffff}
248
250
  crc
@@ -1,3 +1,3 @@
1
1
  module XMODEM
2
- VERSION = "0.1.0"
2
+ VERSION = "0.1.1"
3
3
  end
@@ -227,7 +227,7 @@ class XmodemTests < MiniTest::Test
227
227
 
228
228
  # Test cases
229
229
  def test_version
230
- assert_equal("0.1.0", ::XMODEM::VERSION)
230
+ assert_equal("0.1.1", ::XMODEM::VERSION)
231
231
  end
232
232
 
233
233
  def test_checksum
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: xmodem
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.0
4
+ version: 0.1.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - Jonno Downes
@@ -9,7 +9,7 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2015-02-21 00:00:00.000000000 Z
12
+ date: 2015-02-22 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: log4r