Beefy Boxes and Bandwidth Generously Provided by pair Networks
Do you know where your variables are?
 
PerlMonks  

Bixolon Ethernet Interface Setup Utility

by grep (Monsignor)
on Apr 18, 2008 at 14:49 UTC ( #681526=CUFP: print w/ replies, xml ) Need Help??

Spent about a day reverse engineering the Bixolon ethernet interface setup protocol, so I could have a utility available on *nix systems.

Written with help from dylan and another co-worker.

Comments/critiques welcome.

#! /usr/bin/perl use strict; use warnings; use IO::Socket 'inet_aton'; use Getopt::Std 'getopts'; $Getopt::Std::STANDARD_HELP_VERSION++; use constant CMD => 'SETT'; my %speeds = ( 1200 => 160, 2400 => 208, 4800 => 232, 9600 => 244, 19200 => 250, 57600 => 254, 115200 => 255, 230400 => 187, ); my $speed_re = join( '|', map( quotemeta, keys %speeds ) ); my @checks = ( { opt => 'm', name => 'mac', req => 1, re => qr/00:15:94:[0-9a +-f]{2}:[0-9a-f]{2}:[0-9a-f]{2}/i }, { opt => 'a', name => 'ip', req => 1, re => qr/\d{1,3}\.\d{1, +3}\.\d{1,3}\.\d{1,3}/ }, { opt => 'g', name => 'gateway', req => 1, re => qr/\d{1,3}\.\d{1, +3}\.\d{1,3}\.\d{1,3}/ }, { opt => 'n', name => 'netmask', req => 0, re => qr/\d{1,3}\.\d{1, +3}\.\d{1,3}\.\d{1,3}/, d +efault => '255.255.255.0' }, { opt => 'p', name => 'port', req => 0, re => qr/\d+/, d +efault => 9100 }, { opt => 's', name => 'speed', req => 0, re => qr/$speed_re/, d +efault => 9600 }, { opt => 'd', name => 'dhcp', d +efault => 0 }, ); my %opts; my $opt_str = join( '', map { defined $_->{re} ? "$_->{opt}:" : $_->{o +pt} } @checks ); getopts( $opt_str, \%opts ); foreach my $check (@checks) { if ( not $check->{re} ) { $opts{ $check->{opt} } ||= 0; } else { $opts{ $check->{opt} } = $check->{default} if ( not $check->{req} and not defined $opts{ $check->{opt +} } ); HELP_MESSAGE( "$check->{name} (-$check->{opt}) is required" ) if ( not defined $opts{ $check->{opt} } ); HELP_MESSAGE( "$opts{ $check->{opt} } is invalid input for $ch +eck->{name}" ) if ( not $opts{ $check->{opt} } =~ /^$check->{re}$/ ); } } my $sock = IO::Socket::INET->new( PeerAddr => '255.255.255.255', PeerPort => 48781, Proto => 'udp', Broadcast => 1, LocalPort => 48780, ) or die "Can't bind : $@\n"; my $cmd = pack( 'aaaa', split( //, CMD ) ); my $mac = pack( 'H2H2H2H2H2H2', split( /:/, $opts{m} ) ); my $port = pack( 'n', $opts{p} ); my $ip = inet_aton( $opts{a} ); my $nm = inet_aton( $opts{n} ); my $gw = inet_aton( $opts{g} ); my $baud = pack( 'C', $speeds{ $opts{s} } ); my $dhcp = pack( 'C', $opts{d} ); my $payload = join('', $cmd, $mac, $ip, $nm, $gw, $port, $baud, "\x01\ +x01", $dhcp, "\x00\x00" ); $sock->send($payload); printf "%10s: %-25s\n", uc( $_->{name} ), $opts{ $_->{opt} } foreach +(@checks); sub HELP_MESSAGE { my $die_message = shift; print "bix.pl - Setup a Bixolon Ethernet Interface\n"; print "Usage:\n"; print " bix.pl -m <mac> -a <ip> -n <netmask> -g <gateway> -p <p +ort> [ -d ] [-s <speed> ]\n\n"; print "\t\t-m\tMAC Address ex. ff:ff:ff:ff:ff:ff\n"; print "\t\t-a\tIP Address ex. 192.168.1.200\n"; print "\t\t-g\tGateway ex. 192.168.1.1\n"; print "\t\t-n\tNetmask (default:255.255.255.0)\n"; print "\t\t-p\tPort 1-65535 (default:9100)\n"; print "\t\t-d\tDHCP Enable (default:off)\n"; print "\t\t-s\tBaud Rate 1200,2400,4800,9600,19200,57600,115200 +,230400 (default:9600)\n"; print "\n\t\t--help\tThis Message\n"; die "$die_message\n" if (defined $die_message); }
grep
One dead unjugged rabbit fish later...

Comment on Bixolon Ethernet Interface Setup Utility
Download Code
Re: Bixolon Ethernet Interface Setup Utility
by Anonymous Monk on Jul 05, 2008 at 13:44 UTC
    Good Job, grep. If you develop POS systems or are interested in this would you drop me an email, please? gene@viewtouch.com

Log In?
Username:
Password:

What's my password?
Create A New User
Node Status?
node history
Node Type: CUFP [id://681526]
Approved by moritz
help
Chatterbox?
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others lurking in the Monastery: (7)
As of 2015-03-03 00:37 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    When putting a smiley right before a closing parenthesis, do you:









    Results (61 votes), past polls