<commit_before>#!/usr/bin/perl -w

use Device::SerialPort;
use Term::ReadKey;
use Getopt::Long;
use Time::HiRes qw(usleep);

use strict;

my $filename = '';
my $second = '';
my $term = '/dev/ttyUSB0';
my $baud = '115200';
my $verbose;

GetOptions ('file=s' => \$filename,
	    'secondfile=s' => \$second,
	    'terminal=s' => \$term, 
	    'verbose' => \$verbose, 
	    'baud=s' => \$baud,
    );

$| = 1;

if($filename eq '') {
    print "Example usage: mc1322x-load.pl -f foo.bin -t /dev/ttyS0 -b 9600\n";
    print "          or : mc1322x-load.pl -f flasher.bin -s flashme.bin  0x1e000,0x11223344,0x55667788\n";
    print "       -f required: binary file to load\n";
    print "       -s optional: secondary binary file to send\n";
    print "       -t default: /dev/ttyUSB0\n";
    print "       -b default: 115200\n";
    print "  anything on the command line is sent serial device\n";
    print "  after all of the files have been sent\n";
    exit;
}

my $ob = Device::SerialPort->new ($term) or die "Can't start $term\n";
    # next test will die at runtime unless $ob

if ($filename eq '') { die "you must specify a file with -f\n"; }

$ob->baudrate($baud);
$ob->parity('none');
$ob->databits(8);
$ob->stopbits(1);
$ob->handshake("rts");
$ob->read_const_time(1000); # 1 second per unfulfilled "read" call

my $s = 0;

while(1) { 
    
    my $c; my $count; my $ret = ''; my $test='';
    
    if($s == 1) { print "secondary send...\n"; }
    
    $ob->write(pack('C','0'));
    
    if($s == 1) { 
	$test = 'ready'; 
    } else {
	$test = 'CONNECT';
    }
    
    until($ret =~ /$test$/) {
	($count,$c) = $ob->read(1);
	if ($count == 0) { 
	    print '.';
	    $ob->write(pack('C','0')); 
	    next;
	}
	$ret .= $c;
    }
    print $ret . "\n";
    
    if (-e $filename) {
	
	my $size = -s $filename;

	print ("Size: $size bytes\n");
	$ob->write(pack('V',$size));

	open(FILE, $filename) or die($!);
	print "Sending $filename\n";
	
	my $i = 1;
	while(read(FILE, $c, 1)) {
	    $i++;
	    usleep(50); # this is as fast is it can go... 
	    usleep(25) if ($s==1);
	    $ob->write($c);
	}
    }
    
    last if ($s==1);
    if((-e $second)) {
	$s=1; $filename = $second;
    } else {
	last;
    }

} 

print "done sending files.\n";

print "sending " ;
print @ARGV;
print "\n";

$ob->write(@ARGV);

while(1) {
    print $ob->input;
}

$ob -> close or die "Close failed: $!\n";
ReadMode 0;
undef $ob;  # closes port AND frees memory in perl
exit;

<commit_msg>terminate extra data string with a comma for flasher.c<commit_after>#!/usr/bin/perl -w

use Device::SerialPort;
use Term::ReadKey;
use Getopt::Long;
use Time::HiRes qw(usleep);

use strict;

my $filename = '';
my $second = '';
my $term = '/dev/ttyUSB0';
my $baud = '115200';
my $verbose;

GetOptions ('file=s' => \$filename,
	    'secondfile=s' => \$second,
	    'terminal=s' => \$term, 
	    'verbose' => \$verbose, 
	    'baud=s' => \$baud,
    );

$| = 1;

if($filename eq '') {
    print "Example usage: mc1322x-load.pl -f foo.bin -t /dev/ttyS0 -b 9600\n";
    print "          or : mc1322x-load.pl -f flasher.bin -s flashme.bin  0x1e000,0x11223344,0x55667788\n";
    print "       -f required: binary file to load\n";
    print "       -s optional: secondary binary file to send\n";
    print "       -t default: /dev/ttyUSB0\n";
    print "       -b default: 115200\n";
    print "  anything on the command line is sent serial device\n";
    print "  after all of the files have been sent\n";
    exit;
}

my $ob = Device::SerialPort->new ($term) or die "Can't start $term\n";
    # next test will die at runtime unless $ob

if ($filename eq '') { die "you must specify a file with -f\n"; }

$ob->baudrate($baud);
$ob->parity('none');
$ob->databits(8);
$ob->stopbits(1);
$ob->handshake("rts");
$ob->read_const_time(1000); # 1 second per unfulfilled "read" call

my $s = 0;

while(1) { 
    
    my $c; my $count; my $ret = ''; my $test='';
    
    if($s == 1) { print "secondary send...\n"; }
    
    $ob->write(pack('C','0'));
    
    if($s == 1) { 
	$test = 'ready'; 
    } else {
	$test = 'CONNECT';
    }
    
    until($ret =~ /$test$/) {
	($count,$c) = $ob->read(1);
	if ($count == 0) { 
	    print '.';
	    $ob->write(pack('C','0')); 
	    next;
	}
	$ret .= $c;
    }
    print $ret . "\n";
    
    if (-e $filename) {
	
	my $size = -s $filename;

	print ("Size: $size bytes\n");
	$ob->write(pack('V',$size));

	open(FILE, $filename) or die($!);
	print "Sending $filename\n";
	
	my $i = 1;
	while(read(FILE, $c, 1)) {
	    $i++;
	    usleep(50); # this is as fast is it can go... 
	    usleep(25) if ($s==1);
	    $ob->write($c);
	}
    }
    
    last if ($s==1);
    if((-e $second)) {
	$s=1; $filename = $second;
    } else {
	last;
    }

} 

print "done sending files.\n";

print "sending " ;
print @ARGV;
print "\n";

$ob->write(@ARGV);
$ob->write(',');

while(1) {
    print $ob->input;
}

$ob -> close or die "Close failed: $!\n";
ReadMode 0;
undef $ob;  # closes port AND frees memory in perl
exit;


{'fraction_non_alphanumeric': 0.20696557245796637, 'fraction_numerical': 0.030824659727782224, 'mean_word_length': 2.543971631205674, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 44, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '2172899', 'n_tokens_mistral': 2135, 'n_tokens_neox': 1982, 'n_words': 533}