# List all packet types that this script knows about
my %Idents = (
Rotation_Marker => 0x90,
Format_7 => 0x87,
);
# List packet lengths of each of the packet types (Ident char to checksum, inclusive)
my %Packet_Length = (
$Idents{ Rotation_Marker } => 30,
$Idents{ Format_7 } => 28,
);
# unpack templates to use for each packet type (not including the packet Ident)
my %packet_template = (
$Idents{ Rotation_Marker } => "C3 n n n n n n n n n n n n C3",
$Idents{ Format_7 } => "C B16 n2 A4 A8 A2 A A A3 C2",
);
####
my @packet_fields = qw( ident
flags
x
y
mode3
callsign
route
spare1
spare2
flight_level
terminator
chksum
);
my @rotation_packet_fields = qw(ident
RDP_Ident
Radar_Site_Ident
site_x
site_y
Useful_Vol_Upper
Useful_Vol_Lower
Useful_Vol_North
Useful_Vol_South
Useful_Vol_East
Useful_Vol_West
Rotation
Rotation_x
Rotation_y
Reserved
QNH_Datum
terminator
chksum
);
####
if ($ident == $Idents{ Rotation_Marker }) {
@packet{ @rotation_packet_fields } = unpack (
$packet_template{ $ident }, $buffer);
...
if ($ident == $Idents{ Format_7 }) {
@packet{ @packet_fields } = unpack (
$packet_template{ $ident }, $buffer);
####
my %packet_fields = (
$Idents{ Format_7 } => qw( ident
flags
x
y
mode3
callsign
route
spare1
spare2
flight_level
terminator
chksum
),
$Idents{ Format_7 } => qw(ident
RDP_Ident
Radar_Site_Ident
site_x
site_y
Useful_Vol_Upper
Useful_Vol_Lower
Useful_Vol_North
Useful_Vol_South
Useful_Vol_East
Useful_Vol_West
Rotation
Rotation_x
Rotation_y
Reserved
QNH_Datum
terminator
chksum
),
);
####
@packet{$%packet_fields{ $ident} } = unpack (
$packet_template{ $ident }, $buffer);