Many changes - not yet "controlled" updates.

This commit is contained in:
David
2021-10-04 13:45:39 +00:00
parent 8c1a403008
commit 74543a99f8
42 changed files with 7718 additions and 0 deletions

244
Tools/MakeByteArray.pl Normal file
View File

@@ -0,0 +1,244 @@
# MakeByteArray
#
#
use strict;
use warnings;
use Cwd qw(cwd);
my $maxCols = 16;
my $maxLines = 0;
my $ESP = 0;
my $DIR = 0;
my $file = "";
my $ctrlC = 0; # User induced termination
my $lineT = 0; # Linecount induced termination
$SIG{INT} = \&CtrlCHandler;
$SIG{QUIT} = \&CtrlCHandler;
my %DirInfo; # Name and FileSize
my $prg = $0;
$prg =~ s/^.*[\\\/](.*)/$1/;
$prg =~ s/(.*)\..*/$1/;
my $VERSION = 1.0;
# Extension in this list must be lower case.
my %FileType = (
"htm" => "text/html",
"html" => "text/html",
"gif" => "image/gif",
"svg" => "image/svg+xml",
"css" => "text/css",
"ico" => "image/x-icon",
"png" => "image/png",
"jpg" => "image/jpeg",
"js" => "application/javascript",
);
if (!@ARGV)
{
print <<EOM;
$prg [file|<wildcard> [...]] [-n=##] [-l=##] [-ESP] [-DIR] [-o=outfile]
version $VERSION
Dumps out the contents of the [file] as a c array.
If the file is binary, it emits a hex char-array using
the -n and -l settings.
If the file is text, it emits as an ascii char-array
where each source line is one ascii quoted line.
-ESP adds the PROGMEM attribte to the byte array data.
-DIR adds a 'directory' at the end of the output, providing
a reference to each input file. Most useful for a set
of files.
-o=outfile Writes the output to outfile.
-n=## sets the byte count for each line, defaults 32.
-l=## sets a termination after ## lines have been printed.
Example: MakeByteArray -ESP srcpath\\*.* -o=dstpath\\Web_Resources.h
EOM
exit;
}
my @files;
my $outfile = "";
#printf("ARGS: '%s'\n", join("|", @ARGV));
foreach (@ARGV)
{
if (/-n=(\d+)/)
{ $maxCols = $1; }
elsif (/-l=(\d+)/)
{ $maxLines = $1; }
elsif (/-o=(.*)/)
{ $outfile = $1; }
elsif (/-ESP/)
{ $ESP = 1; }
elsif (/-DIR/)
{ $DIR = 1; }
elsif (-e $_ )
{ push @files, $_; }
elsif (/[\*\?]/)
{
my @gFiles = glob($_);
foreach (@gFiles)
{
push @files, $_ if (-e $_);
}
}
else
{ print "unrecognized command.\n"; exit; }
}
if (!@files)
{
print "No files to process.\n";
exit;
}
my $oldHandle;
if ($outfile ne "") {
#printf("Open for write '%s'\n", $outfile);
open(FO, ">$outfile") || die("Can't write to $outfile");
$oldHandle = select FO;
} else {
printf("No outfile, emitting to console.\n");
}
printf("//\n");
printf("// Command : %s %s\n", $prg, join(" ", @ARGV));
printf("// version: %2.1f\n", $VERSION);
printf("// From cwd : %s\n", cwd);
printf("// Generated: %s\n", scalar localtime());
printf("// Run script in command shell, not PowerShell\n");
my @summary;
foreach my $file (@files) {
push @summary, Process($file);
last if ($ctrlC);
}
print "\n// Prototypes:\n// " . join("\n// ", @summary) . "\n";
if ($DIR) {
print <<EOM;
// Directory of Files
//
// This typedef is used to iterate through the directory listing, until
// an empty "" Filename is reached.
//
typedef struct {
const char * Filename;
const char * Filedata;
const char * Filetype;
uint16_t Filesize;
} DirEntry;
EOM
printf("const DirEntry Directory[] %s= {\n", ($ESP) ? "PROGMEM " : "");
foreach my $file (sort keys %DirInfo) {
#printf(STDERR "file %s, title %s, size %d\n", $file, $DirInfo{$file}{'reference'}, $DirInfo{$file}{'size'});
my $title = $DirInfo{$file}{'reference'};
my $fn = sprintf("\"%s\"", $file);
my $ext = "";
$ext = $1 if ($file =~ /.*\.(.*)/);
my $ftype = sprintf("\"%s\"", $FileType{$ext});
#printf(STDERR "ext: '%s' => '%s'\n", $ext, $FileType{lc($ext)});
printf("\t{ %-20s, %-20s, %24s, %6d },\n", $fn, $title, $ftype, $DirInfo{$file}{'size'});
}
printf("\t{ %-20s, %-20s, %24s, %6d }\n", "\"\"", "NULL", "NULL", 0);
printf("};\n\n");
}
if ($outfile) {
close FO;
select($oldHandle);
}
print "\nTerminated by operator\n" if ($ctrlC == 1);
exit;
# ####################################
sub Process {
my $file = shift;
my $title = $file;
my $isText = 0;
my $prototype;
$title =~ s/\./_/g;
$isText = 1 if (-T $file);
open(FH, "<$file") || die("Can't read $file.\n");
binmode FH if ($isText);
my $cols = 0;
my $c;
my $ascii = "";
my $address = 0;
my $lineCount = 0;
printf("\n");
printf("// File: %s\n", $file);
printf("//\n");
$prototype = sprintf("const char %s[]%s", $title, ($ESP) ? " PROGMEM" : "");
printf("%s = {\n", $prototype);
my $size = 0;
if ($isText) {
while (<FH>) {
my $line = $_;
chomp $line;
$line =~ s/\t/ /g;
$line =~ s/\\"/"/g;
$line =~ s/\r//g;
$line =~ s/"/\\"/g;
printf("\t\"%s\\n\"\n", $line);
$size += length($line);
}
} else {
printf("\t");
while (sysread(FH, $c, 1) && !$ctrlC && !$lineT) {
my $b = ord($c);
printf("0x%02X,", $b);
if ($b >= 0x20 && $b <= 0x7F)
{ $ascii .= chr($b); }
else
{ $ascii .= "."; }
++$cols;
++$address;
$cols %= $maxCols;
if ($cols == 0) {
#print " // $ascii";
print "\n";
$ascii = "";
$lineCount++;
$lineT = 1 if ($maxLines && $lineCount >= $maxLines);
if (!$lineT) {
printf("\t");
}
}
$size += 1;
}
if ($ascii ne "") {
print " " x ($maxCols - $cols);
}
printf("\n");
}
printf("}; // %s, %d bytes\n", $title, $size);
close FH;
$DirInfo{$file}{'reference'} = $title;
$DirInfo{$file}{'size'} = $size;
return $prototype;
}
# If the user presses Control-C, signal it.
#
sub CtrlCHandler {
$ctrlC = 1;
}

View File

@@ -0,0 +1,55 @@
@echo off
REM
REM "Compile" the web resources folder into code modules.
REM
REM Command : MakeByteArray -ESP *.* -o=..\Web_Resources.h
REM From cwd : C:/Projects/SmartSwitch/Firmware/Resources
REM Run script in command shell, not PowerShell
REM
REM External Dependency:
REM MakeByteArray - Converts 1 or more files into a .h file byte array.
REM
REM +------------------------------------------------+
REM | MakeResourceFiles.cmd |
REM +------------------------------------------------+
REM ||
REM +----------+ +-----------+ +-----------+
REM +----------+ | |Make | | |
REM |source | | |Byte | |Resources.h|
REM |.htm | | ==> |Array.pl | ==> | |
REM |.js | | | | | |
REM |.jpg | | | | | |
REM |etc... |-+ | | | |
REM +----------+ +-----------+ +-----------+
setlocal
REM ######################################################################
REM
REM Configuration Options
REM
set SRC=..\Firmware\Resources
set TARG=..\Web_Resources.h
REM
REM End of Configuration
REM
REM ######################################################################
echo.
echo.Make Resource Files
echo.Change to %SRC% ...
pushd %SRC%
echo.Show web resources
dir /b
echo.
echo.Compiling the web resources into code modules...
MakeByteArray -ESP -DIR *.* -o=%TARG%
echo.
echo.Done. %TARG% has been updated and returning to prior folder.
dir %TARG%
popd
endlocal

124
Tools/MoveToServer.pl Normal file
View File

@@ -0,0 +1,124 @@
#
# Move to Server
#
# Monitor the debug and release folders for a new binary.
# If found,
# 1 Read the .ino file to find the current version string.
# 2 Rename the .bin to include the version string.
# 3 Move it to the server.
#
# Searches .ino file for: const String MyVer = "SmartSwitch v1.02.24";
#
use strict;
use warnings;
###################### Configuration ###########################
#
# Target Server Path
#
my $ServerPath = "\\\\server1\\web\\mbed\\ESPbin";
# Sleep Time between checks
#
my $SleepTime = 5;
# Verbose mode
# 0 = off
# 1 = highlights
# 2 = detailed
#
my $Verbose = 1;
#####################
my $continue = 1;
$SIG{INT} = sub { $continue = 0; };
$SIG{TERM} = sub { $continue = 0; };
do {
printf("\n") if ($Verbose > 1);
printf("MoveToServer check at %s\n", scalar localtime()) if ($Verbose == 1);
chdir "../Firmware";
Process();
Pause($SleepTime);
} while ($continue);
exit;
####################################################################
sub Process {
my $slnFile = "";
my @files = glob("*.sln");
foreach (@files) {
$slnFile = $_;
printf(" Found: %s\n", $slnFile) if ($Verbose > 1);
}
if ($slnFile eq "") {
printf(" *** No Solution Files found ...\n") if ($Verbose == 1);
return;
}
my $inoFile = $slnFile;
$inoFile =~ s/(.*)\.sln/$1\.ino/;
if (!-e $inoFile) {
printf(" *** %s not found ...\n", $inoFile) if ($Verbose == 1);
return;
}
printf(" Search %s\n", $inoFile) if ($Verbose > 1);
my $verString = GetVerString($inoFile);
if ($verString eq "") {
printf(" *** No Version string in %s ...\n", $inoFile) if ($Verbose == 1);
return;
}
printf(" Version '%s'\n", $verString) if ($Verbose > 1);
my $targBin = $slnFile;
$targBin =~ s/(.*)\.sln/$1\.bin/;
printf(" Target Bin file is %s\n", $targBin) if ($Verbose > 1);
my @Folders = qw(Debug Release);
foreach my $f (@Folders) {
printf(" Scanning %s\n", $f) if ($Verbose > 1);
my $tF = "$f\\$targBin";
if (-e $tF) {
printf(" Processing %s\n", $tF) if ($Verbose > 1);
my $srvrFile = "$ServerPath\\$verString.bin";
my $cmd = sprintf("move /Y \"%s\" \"%s\"", $tF, $srvrFile);
printf(" > %s\n", $cmd);
`$cmd`;
}
}
}
sub Pause {
my $dly = shift;
my $count = 0;
while ($count++ < $dly && $continue) {
sleep(1);
}
}
sub GetVerString {
my $iF = shift;
my $ver = "";
open(IF, "<$iF") || return $ver;
#const String MyVer = "SmartSwitch v1.02.24";
while (<IF>) {
if (/String MyVer = \"(.*)\"/) {
$ver = $1;
last;
#close IF;
#return $ver;
}
}
close IF;
return $ver;
}