[Asterisk-Users] Grandstream bin cfg.txt generator
Steve Edwards
asterisk.org at sedwards.com
Wed Sep 22 13:09:27 MST 2004
Way cool :)
I noticed a couple of differences between Grandstream's GAPSLITE tool and
your tool:
1) GS ignores multiple occurrences of a parameter, only using the last.
For example:
P30=time.nist.gov
P30=clock1.redhat.com
GS's tool only puts "P30=clock1.redhat.com" in the cfg file while yours
puts both.
2) GS keeps spaces in a parameter. For example:
P3=George W Bush
GS puts "P3=George W Bush" in the cfg file while yours puts
"P3=GeorgeWBush"
3) GS lets you specify the MAC, input, and output files on the command
line while yours is "in the code."
This is probably the most important difference as it would allow easy
scripting to support a bunch of devices.
On Wed, 22 Sep 2004, Leon de Rooij wrote:
> Hi,
>
> I needed to create config files for downloading to Grandstream devices and
> made a little script for it. It seems to work fine for the HT486.
> The script needs a config file (cfg.in) which is in this format:
>
> P2 = blah
> P10 = hrm
> ...etc...
>
> The configfile may contain comments (starting with '#') and empty lines. Mind
> that the 'gnkey=0b82' shouldn't be in the configfile, as it's already
> appended by the script.
>
> Hope it's useful..
>
> Thanks to Stephen R. Besch for information about the format of this file !
>
> (One thing I am not 100% sure of: do I have to append zeros to the end of the
> body until it has an even amount of bytes, or an even amount of words ? Right
> now, I do both.)
>
> Regards,
>
> Leon de Rooij
>
> --------------
>
> #!/usr/bin/perl -w
> use strict;
>
> my $h_mac = '000b82014e20'; # hexadecimal mac address
> my $f_in = 'cfg.in'; # file body, configfile containing all
> parameters
> my $f_out = 'cfg.txt'; # the configfile that will be written to
>
> my $h_crlf = '0d0a'; # hexadecimal crlf
>
> # convert some things to binary
> my $b_mac = pack("H12", $h_mac); # convert 12 hex numbers to bin
> my $b_crlf = pack("H4", $h_crlf); # convert 4 hex numbers to bin
>
> # open configfile and make body in ascii (a_body)
> my $a_body;
> open F,$f_in;
> while (<F>) {
> chomp; # remove trailing lf
> s/\#.*$//g; # remove comments
> s/\s//g; # remove all whitespace
> $a_body .= $_.'&' if length > 0;
> }
> close F;
> $a_body .='gnkey=0b82';
>
> # add an extra byte to make the body even (bytewise)
> $a_body .= "\0" if ((length($a_body) % 2) ne 0);
>
> # add an extra word ( = two bytes) to make the body even (wordwise)
> $a_body .= "\0\0" if ((length($a_body) % 4) ne 0);
>
> # generate a d_length (length of the complete message, counting words, in
> dec)
> # ( header is always 8 words lang ) + ( body in ascii (bytes) / 2 = in words
> )
> my $d_length = 8 + (length($a_body)/2);
>
> # make that a binary dword
> my $b_length = pack("N", $d_length);
>
> # generate a checksum
> my $d_checksum;
> foreach ($b_length,$b_mac,$b_crlf,$b_crlf,$a_body) {
> $d_checksum += unpack("%16n*", $_);
> }
> #$d_checksum %= 65536;
>
> $d_checksum = 65536-$d_checksum;
>
> # and make a binary word of that
> my $b_checksum = pack("n", $d_checksum);
>
> # and write the config back to disk, in a grandstream readable format
> open F,">$f_out";
> binmode F;
> print F $b_length;
> print F $b_checksum;
> print F $b_mac;
> print F $b_crlf;
> print F $b_crlf;
> print F $a_body;
> close F;
>
> _______________________________________________
> Asterisk-Users mailing list
> Asterisk-Users at lists.digium.com
> http://lists.digium.com/mailman/listinfo/asterisk-users
> To UNSUBSCRIBE or update options visit:
> http://lists.digium.com/mailman/listinfo/asterisk-users
>
Thanks in advance,
------------------------------------------------------------------------
Steve Edwards sedwards at sedwards.com Voice: +1-760-468-3867 PST
Newline pagesteve at sedwards.com Fax: +1-760-731-3000
More information about the asterisk-users
mailing list