Skip to content
GitLab
Explore
Sign in
Register
Primary navigation
Search or go to…
Project
A
APEX APRS
Manage
Activity
Members
Labels
Plan
Issues
0
Issue boards
Milestones
Iterations
Wiki
Requirements
Code
Merge requests
0
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Locked files
Build
Pipelines
Jobs
Pipeline schedules
Test cases
Artifacts
Deploy
Releases
Package Registry
Container Registry
Model registry
Operate
Environments
Terraform modules
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Code review analytics
Issue analytics
Insights
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
Digipex
APEX APRS
Commits
6b3cf860
Commit
6b3cf860
authored
8 years ago
by
Jeffrey Phillips Freeman
Browse files
Options
Downloads
Patches
Plain Diff
fixed some bugs and wrote the first unit test.
parent
8b87b85c
No related branches found
No related tags found
No related merge requests found
Changes
3
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
lib/kiss/kiss.rb
+29
-20
29 additions, 20 deletions
lib/kiss/kiss.rb
test/tc_kiss.rb
+62
-0
62 additions, 0 deletions
test/tc_kiss.rb
test/tc_something.rb
+0
-7
0 additions, 7 deletions
test/tc_something.rb
with
91 additions
and
27 deletions
lib/kiss/kiss.rb
+
29
−
20
View file @
6b3cf860
...
@@ -16,10 +16,15 @@ module KISS
...
@@ -16,10 +16,15 @@ module KISS
private
private
def
self
.
strip_df_start
(
frame
)
def
self
.
strip_df_start
(
frame
)
while
frame
[
0
]
==
KISS
::
DATA_FRAME
while
frame
[
0
]
==
DATA_FRAME
frame
.
shift
frame
.
shift
end
end
frame
.
strip
while
frame
[
0
]
&
.
chr
==
' '
frame
.
shift
end
while
frame
[
-
1
]
&
.
chr
==
' '
frame
.
pop
end
return
frame
return
frame
end
end
...
@@ -27,10 +32,10 @@ module KISS
...
@@ -27,10 +32,10 @@ module KISS
def
self
.
escape_special_codes
(
raw_code_bytes
)
def
self
.
escape_special_codes
(
raw_code_bytes
)
encoded_bytes
=
[]
encoded_bytes
=
[]
raw_code_bytes
.
each
do
|
raw_code_byte
|
raw_code_bytes
.
each
do
|
raw_code_byte
|
if
raw_code_byte
==
KISS
::
FESC
if
raw_code_byte
==
FESC
encoded_bytes
+=
KISS
::
FESC_TFESC
encoded_bytes
+=
FESC_TFESC
elsif
raw_code_byte
==
KISS
::
FEND
elsif
raw_code_byte
==
FEND
encoded_bytes
+=
KISS
::
FESC_TFEND
encoded_bytes
+=
FESC_TFEND
else
else
encoded_bytes
+=
[
raw_code_byte
]
encoded_bytes
+=
[
raw_code_byte
]
end
end
...
@@ -62,11 +67,11 @@ module KISS
...
@@ -62,11 +67,11 @@ module KISS
def
fill_buffer
def
fill_buffer
new_frames
=
[]
new_frames
=
[]
read_buffer
=
[]
read_buffer
=
[]
read_data
=
self
.
read_interface
read_data
=
read_interface
while
read_data
&
.
length
while
read_data
&
.
length
and
read_data
.
length
>
0
split_data
=
[[]]
split_data
=
[[]]
read_data
.
each
do
|
read_byte
|
read_data
.
each
do
|
read_byte
|
if
read_byte
==
KISS
::
FEND
if
read_byte
==
FEND
split_data
<<
[]
split_data
<<
[]
else
else
split_data
[
-
1
]
<<
read_byte
split_data
[
-
1
]
<<
read_byte
...
@@ -79,7 +84,7 @@ module KISS
...
@@ -79,7 +84,7 @@ module KISS
read_buffer
+=
split_data
[
0
]
read_buffer
+=
split_data
[
0
]
# Single FEND in frame
# Single FEND in frame
elsif
len_fend
==
2
elsif
len_fend
==
2
# Closing FEND found
# Closing FEND found
if
split_data
[
0
]
if
split_data
[
0
]
# Partial frame continued, otherwise drop
# Partial frame continued, otherwise drop
new_frames
<<
read_buffer
+
split_data
[
0
]
new_frames
<<
read_buffer
+
split_data
[
0
]
...
@@ -93,7 +98,7 @@ module KISS
...
@@ -93,7 +98,7 @@ module KISS
elsif
len_fend
>=
3
elsif
len_fend
>=
3
(
0
...
len_fend
-
1
).
each
do
|
i
|
(
0
...
len_fend
-
1
).
each
do
|
i
|
read_buffer_tmp
=
read_buffer
+
split_data
[
i
]
read_buffer_tmp
=
read_buffer
+
split_data
[
i
]
if
read_buffer_tmp
.
length
if
read_buffer_tmp
.
length
>
0
new_frames
<<
read_buffer_tmp
new_frames
<<
read_buffer_tmp
read_buffer
=
[]
read_buffer
=
[]
end
end
...
@@ -103,11 +108,11 @@ module KISS
...
@@ -103,11 +108,11 @@ module KISS
end
end
end
end
# Get anymore data that is waiting
# Get anymore data that is waiting
read_data
=
self
.
read_interface
read_data
=
read_interface
end
end
new_frames
.
each
do
|
new_frame
|
new_frames
.
each
do
|
new_frame
|
if
new_frame
.
length
and
not
new_frame
[
0
]
if
new_frame
.
length
>
0
and
new_frame
[
0
]
==
0
if
@strip_df_start
if
@strip_df_start
new_frame
=
KISS
.
strip_df_start
(
new_frame
)
new_frame
=
KISS
.
strip_df_start
(
new_frame
)
end
end
...
@@ -116,22 +121,25 @@ module KISS
...
@@ -116,22 +121,25 @@ module KISS
end
end
end
end
public
def
connect
(
mode_init
=
None
,
*
args
,
**
kwargs
)
def
connect
(
mode_init
=
None
,
*
args
,
**
kwargs
)
end
end
public
def
close
def
close
if
@exit_kiss
if
@exit_kiss
self
.
write_interface
(
KISS
::
MODE_END
)
write_interface
(
MODE_END
)
end
end
end
end
public
def
read
def
read
@lock
.
synchronize
do
@lock
.
synchronize
do
if
@frame_buffer
.
length
>
0
if
@frame_buffer
.
length
==
0
self
.
fill_buffer
fill_buffer
end
end
if
@frame_buffer
.
length
if
@frame_buffer
.
length
>
0
return_frame
=
@frame_buffer
[
0
]
return_frame
=
@frame_buffer
[
0
]
@frame_buffer
.
shift
@frame_buffer
.
shift
return
return_frame
return
return_frame
...
@@ -141,10 +149,11 @@ module KISS
...
@@ -141,10 +149,11 @@ module KISS
end
end
end
end
public
def
write
(
frame_bytes
,
port
=
0
)
def
write
(
frame_bytes
,
port
=
0
)
@lock
.
synchronize
do
@lock
.
synchronize
do
kiss_packet
=
[
KISS
:
FEND
]
+
[
self
.
command_byte_combine
(
port
,
KISS
::
DATA_FRAME
)]
+
kiss_packet
=
[
FEND
]
+
[
command_byte_combine
(
port
,
DATA_FRAME
)]
+
self
.
escape_special_codes
(
frame_bytes
)
+
[
KISS
::
FEND
]
escape_special_codes
(
frame_bytes
)
+
[
FEND
]
return
self
.
write_interface
(
kiss_packet
)
return
self
.
write_interface
(
kiss_packet
)
end
end
...
...
This diff is collapsed.
Click to expand it.
test/tc_kiss.rb
0 → 100644
+
62
−
0
View file @
6b3cf860
require
'test/unit'
require_relative
'../lib/kiss/kiss'
module
KISS
# KG6WTF>S7TSUV,MTOSO-2,WIDE2*,qAR,KF6FIR-10:`17El#X-/kg6wtf@gosselinfamily.com
ENCODED_FRAME
=
[
192
,
0
,
75
,
71
,
54
,
87
,
84
,
70
,
62
,
83
,
55
,
84
,
83
,
85
,
86
,
44
,
77
,
84
,
79
,
83
,
79
,
45
,
50
,
44
,
87
,
73
,
68
,
69
,
50
,
42
,
44
,
113
,
65
,
82
,
44
,
75
,
70
,
54
,
70
,
73
,
82
,
45
,
49
,
48
,
58
,
96
,
49
,
55
,
69
,
108
,
35
,
88
,
45
,
47
,
107
,
103
,
54
,
119
,
116
,
102
,
64
,
103
,
111
,
115
,
115
,
101
,
108
,
105
,
110
,
102
,
97
,
109
,
105
,
108
,
121
,
46
,
99
,
111
,
109
,
192
]
DECODED_FRAME
=
[
75
,
71
,
54
,
87
,
84
,
70
,
62
,
83
,
55
,
84
,
83
,
85
,
86
,
44
,
77
,
84
,
79
,
83
,
79
,
45
,
50
,
44
,
87
,
73
,
68
,
69
,
50
,
42
,
44
,
113
,
65
,
82
,
44
,
75
,
70
,
54
,
70
,
73
,
82
,
45
,
49
,
48
,
58
,
96
,
49
,
55
,
69
,
108
,
35
,
88
,
45
,
47
,
107
,
103
,
54
,
119
,
116
,
102
,
64
,
103
,
111
,
115
,
115
,
101
,
108
,
105
,
110
,
102
,
97
,
109
,
105
,
108
,
121
,
46
,
99
,
111
,
109
]
class
KISSMock
<
KISS
def
initialize
(
strip_df_start
=
true
)
super
(
strip_df_start
)
@read_from_interface
=
[]
@sent_to_interface
=
[]
end
protected
def
read_interface
if
@read_from_interface
.
length
==
0
return
nil
end
return
@read_from_interface
.
shift
end
protected
def
write_interface
(
data
)
@sent_to_interface
<<
data
end
public
def
clear_interface
@read_from_interface
=
[]
@sent_to_interface
=
[]
end
public
def
add_read_from_interface
(
raw_frame
)
@read_from_interface
<<
raw_frame
end
public
def
get_sent_to_interface
return
@sent_to_interface
end
end
class
TestKISS
<
Test
::
Unit
::
TestCase
def
test_read
kiss_mock
=
KISSMock
.
new
kiss_mock
.
add_read_from_interface
(
ENCODED_FRAME
)
translated_frame
=
kiss_mock
.
read
assert
DECODED_FRAME
==
translated_frame
end
end
end
\ No newline at end of file
This diff is collapsed.
Click to expand it.
test/tc_something.rb
deleted
100644 → 0
+
0
−
7
View file @
8b87b85c
require
'test/unit'
class
TestSomething
<
Test
::
Unit
::
TestCase
def
test_truth
assert
true
end
end
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment