#!/usr/bin/perl # listen on the UDP port used by the TESS gateway for TESS messages # and print contents use strict; use IO::Socket::INET; use Socket; use POSIX; use Term::ANSIColor qw(:constants); use constant GW_LISTEN_PORT => 3123; use constant SG90_UL_COMMAND => 2; my $sock = IO::Socket::INET->new(Proto=>'udp', LocalPort=>GW_LISTEN_PORT) or die "Could not create Socket : $!\n"; my $sg90Message; my $peer_address; my $peer_port; while (1) { next unless $sock->recv($sg90Message, 2048); #get the peerhost and peerport at which the recent data received. $peer_address = $sock->peerhost(); $peer_port = $sock->peerport(); printf "Received Message from $peer_address:$peer_port at %s\n", POSIX::strftime("%m/%d/%Y %H:%M:%S", localtime); # get the array of bytes # (I couldn't get the unpack to work with a template to extract the correct numbers) my @rawBytes = unpack('C*', $sg90Message); my $messageType = $rawBytes[0]; my $formatID = ($rawBytes[2] << 8) + $rawBytes[1]; if ($messageType == SG90_UL_COMMAND) { print "Format ID: $formatID\n"; print "Msg Length: ",scalar(@rawBytes),"\n\n" } else { print "ILLEGAL COMMAND\n"; } } close $sock;