EAFDSS
view release on metacpan or search on metacpan
lib/EAFDSS/Base.pm view on Meta::CPAN
$self->_validateFilesC();
$self->debug("Issue Recovery Report operation");
my($reply1) = $self->PROTO_IssueReport();
if ($reply1 != 0) {
return $self->error($reply1);
}
my($reply2, $status1, $status2, $totalSigns, $dailySigns, $date, $time, $z, $sn, $closure) = $self->PROTO_ReadClosure(0);
$self->_createFileC($z, $deviceDir, $date, $time, $closure);
return $z;
}
sub _checkCharacters {
my($self) = shift @_;
my($invoice) = shift @_;
my($c);
foreach $c (unpack('C*', $invoice)) {
if (grep $_ == ord($c), qw/0 1 2 3 4 5 6 7 8 11 14 15 16 17 18 19 20 21 22 23 24 25 27 28 29 30 31 127 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 173 210 255/ ) {
$self->debug(" Found invalid character [%d]", ord($c));
return 1;
}
}
return 0;
}
sub _createSignDir {
my($self) = shift @_;
my($result) = $self->_Recover();
if ($result != 0) {
return ($result, undef);
}
# Create The signs Dir
if (! -d $self->{DIR} ) {
$self->debug(" Creating Base Dir [%s]", $self->{DIR});
mkdir($self->{DIR});
}
my($deviceDir) = sprintf("%s/%s", $self->{DIR}, $self->{SN});
if (! -d $deviceDir ) {
$self->debug(" Creating Device Dir [%s]", $deviceDir);
mkdir($deviceDir);
}
return (0, $deviceDir);
}
sub _Recover {
my($self) = shift @_;
my($reply, $status1, $status2, $lastZ, $total, $daily, $signBlock, $remainDaily);
($reply, $status1, $status2) = $self->PROTO_GetStatus();
if ($reply ne "0") { return $reply };
my($busy, $fatal, $paper, $cmos, $printer, $user, $fiscal, $battery) = $self->UTIL_devStatus($status1);
if ($cmos != 1) { return 0 };
my($day, $signature, $recovery, $fiscalWarn, $dailyFull, $fiscalFull) = $self->UTIL_appStatus($status1);
$self->debug(" CMOS is set, going for recovery!");
($reply, $status1, $status2, $lastZ, $total, $daily, $signBlock, $remainDaily) = $self->PROTO_ReadSummary(0);
if ($reply != 0) {
$self->debug(" Aborting recovery because of ReadClosure reply [%d]", $reply);
return $reply
};
my($regexA) = sprintf("%s\\d{6}%04d\\d{4}_a.txt", $self->{SN}, $lastZ + 1);
my($deviceDir) = sprintf("%s/%s", $self->{DIR}, $self->{SN});
opendir(DIR, $deviceDir) || croak "can't opendir $deviceDir: $!";
my(@afiles) = grep { /$regexA/ } readdir(DIR);
closedir(DIR);
foreach my $curA (@afiles) {
$self->debug(" Checking [%s]", $curA);
my($curFileA) = sprintf("%s/%s", $deviceDir, $curA);
my($curFileB) = $curFileA;
$curFileB =~ s/_a/_b/;
my($curB) = $curA; $curB =~ s/_a/_b/;
my($curIndex) = substr($curA, 21, 4); $curIndex =~ s/^0*//;
$self->debug(" Resigning file A [%s]", $curA);
open(FH, $curFileA);
my($reply, $totalSigns, $dailySigns, $date, $time, $nextZ, $sign) = $self->PROTO_GetSign(*FH);
my($fullSign) = sprintf("%s %04d %08d %s%s %s", $sign, $dailySigns, $totalSigns, $self->UTIL_date6ToHost($date), substr($time, 0, 4), $self->{SN});
close(FH);
$self->debug(" Updating file B [%s] -- Index [%d]", $curB, $curIndex);
open(FB, ">>", $curFileB) || croak "Error: $!";
print(FB "\n" . $fullSign);
close(FB);
}
my($z) = $self->_RecoveryReport();
if ($z) {
return(0);
} else {
my($errNo) = $self->error();
return $self->error($errNo);
}
}
sub _createFileA {
my($self) = shift @_;
my($invoice) = shift @_;
my($dir) = shift @_;
my($date) = shift @_;
my($ds) = shift @_;
my($curZ) = shift @_;
( run in 2.373 seconds using v1.01-cache-2.11-cpan-39bf76dae61 )