Device-TNC

 view release on metacpan or  search on metacpan

lib/Device/TNC/KISS.pm  view on Meta::CPAN

						# we have an empty frame or we got the end of one frame and the start of another.
						# So start the search again.
						$fend_count--;
						@frame = ($saw);
					}
				}
			}
		}
	}
	$self->{'LAST_KISS_FRAME_LENGTH'} = scalar @frame;

	if (wantarray)
	{
		return @frame;
	}
	else
	{
		my $frame = join '', @frame;
		return $frame;
	}
}

################################################################################

=head2 B<read_hdlc_frame()>

 my ($kiss_type, $hdlc_frame) = $kiss_tnc->read_hdlc_frame();
 my ($kiss_type, @hdlc_frame) = $kiss_tnc->read_hdlc_frame();

This method reads a KISS frame from the TNC and strips out the KISS FEND, FESC,
TFEND and TFESC bytes and returns the KISS type byte followed by the HDLC frame.

The value of type indicator byte is use to distinguish between command and data
frames.

From: The KISS TNC: A simple Host-to-TNC communications protocol
L<http://people.qualcomm.com/karn/papers/kiss.html>

To distinguish between command and data frames on the host/TNC link, the first
byte of each asynchronous frame between host and TNC is a "type" indicator. This
type indicator byte is broken into two 4-bit nibbles so that the low-order
nibble indicates the command number (given in the table below) and the
high-order nibble indicates the port number for that particular command.
In systems with only one HDLC port, it is by definition Port 0. In multi-port
TNCs, the upper 4 bits of the type indicator byte can specify one of up to
sixteen ports. The following commands are defined in frames to the TNC (the
"Command" field is in hexadecimal):

 Command       Function         Comments
   0           Data frame       The  rest  of the frame is data to
                                be sent on the HDLC channel.

   1           TXDELAY          The next  byte  is  the  transmitter
                                keyup  delay  in  10 ms units.
                		The default start-up value is 50
                                (i.e., 500 ms).

   2           P                The next byte  is  the  persistence
                                parameter,  p, scaled to the range
                                0 - 255 with the following
                                formula:

                                         P = p * 256 - 1

                                The  default  value  is  P  =  63
                                (i.e.,  p  =  0.25).

   3           SlotTime         The next byte is the slot interval
                                in 10 ms units.
                                The default is 10 (i.e., 100ms).

   4           TXtail           The next byte is the time to hold
                                up the TX after the FCS has been
                                sent, in 10 ms units.  This command
                                is obsolete, and is included  here
                                only for  compatibility  with  some
                                existing  implementations.

   5          FullDuplex        The next byte is 0 for half duplex,
                                nonzero  for full  duplex.
                                The  default  is  0
                                (i.e.,  half  duplex).

   6          SetHardware       Specific for each TNC.  In the
                                TNC-1, this command  sets  the
                                modem speed.  Other implementations
                                may use this function  for   other
                                hardware-specific   functions.

   FF         Return            Exit KISS and return control to a
                                higher-level program. This is useful
                                only when KISS is  incorporated
                                into  the TNC along with other
                                applications.

The following types are defined in frames to the host:

Type			Function		Comments

  0                 Data frame       Rest of frame is data from
                                     the HDLC channel.

No other types are defined; in particular, there is no provision for
acknowledging data or command frames sent to the TNC. KISS implementations must
ignore any unsupported command types. All KISS implementations must implement
commands 0,1,2,3 and 5; the others are optional.

=cut

sub read_hdlc_frame
{
	my $self = shift;

	# This is what we will return
	my @frame;
	my $type;

	# This is not the simplest method of getting the data but it allows for
	# for catching errors.
	my @kiss = $self->read_kiss_frame();
	for (my $location = 0; $location <= $#kiss; $location++)



( run in 1.697 second using v1.01-cache-2.11-cpan-d06a3f9ecfd )