apex.rb 1.57 KB
Newer Older
1
require 'colorize'
2
3
require 'kiss/kiss_serial'
require 'aprs/aprs_kiss'
4
require 'apex/app_info'
5
6

module Apex
7
    def self.echo_color_frame(frame, port_name, direction_in)
8
9
10
11
12
        formatted_aprs = [frame[:source].colorize(:green), frame[:destination].colorize(:blue)].join('>')
        paths = []
        frame[:path].each do |path|
            paths << path.colorize(:cyan)
        end
13
14
15
        paths = paths.join(',')
        if frame[:path] and frame[:path].length > 0
            formatted_aprs = [formatted_aprs, paths].join(',')
16
17
        end
        formatted_aprs += ':'
18
        formatted_aprs += frame[:text]
19
        if direction_in
20
            puts (port_name + ' << ').colorize(:magenta) + formatted_aprs
21
        else
22
            # TODO : make this bold and/or blink
23
            puts (port_name + ' >> ').colorize(:color => :magenta, :mode => :bold) + formatted_aprs
24
25
        end
    end
26

27
    def self.main
28
        kiss = Kiss::KissSerial.new('/dev/ttyUSB1', 9600)
29
30
        aprs_kiss = Aprs::AprsKiss.new(kiss)
        aprs_kiss.connect(Kiss::MODE_INIT_KENWOOD_D710)
31

32
33
34
35
36
37
38
        beacon_frame = {:source => 'WI2ARD-2',
                        :destination => 'APRS',
                        :path => ['WIDE1-1', 'WIDE2-2'],
                        :text => '!/:=i@;N.G& --PHG5790/G/D R-I-R H24 C30'}
        aprs_kiss.write(beacon_frame)
        echo_color_frame(beacon_frame, 'TNC', false)

39
40
41
        while true
            frame = aprs_kiss.read
            if frame
42
                echo_color_frame(frame, 'TNC',  true)
43
44
45
46
47
            else
                sleep(1)
            end
        end
    end
48
end