New algorithm for calculating packet name, EMSI/BINKP inbound processing tested, Netmail rejection and intransit processing

This commit is contained in:
Deon George
2021-07-24 00:53:35 +10:00
parent 2fdc6eabad
commit ee30ef92c3
12 changed files with 184 additions and 54 deletions

View File

@@ -75,4 +75,88 @@ if (! function_exists('hexstr')) {
return $x;
}
}
if (! function_exists('timew')) {
/**
* Convert a time into an 32 bit value. This is primarily used to create 8 character hex filenames that
* are unique using 1/10th second precision.
*
* Time is:
* + 02 bits unused
* + 04 bits Month
* + 05 bits Day
* + 05 bits Hour
* + 06 bits Min
* + 06 bits Sec
* + 04 bits 10th Sec
* = 32 (2 bits free)
*
* @param \Carbon\Carbon|null $time
* @return int
*/
function timew(\Carbon\Carbon $time=NULL): int
{
static $delay = 0;
// If we are not passed a time, we'll use the time now
if (! $time) {
// In case we are called twice, we'll delay 1/10th second so we have a unique result.
if (\Carbon\Carbon::now()->getPreciseTimestamp(1) == $delay)
usleep(100000);
$time = \Carbon\Carbon::now();
}
$delay = $time->getPreciseTimestamp(1);
$t = ($time->month & 0xf) << 5;
$t = ($t | ($time->day & 0x1f)) << 5;
$t = ($t | ($time->hour & 0x1f)) << 6;
$t = ($t | ($time->minute & 0x3f)) << 6;
$t = ($t | ($time->second & 0x3f));
return hexdec(sprintf('%07x%1x',$t,(round($time->milli/100) & 0x7f)));
}
}
if (! function_exists('dwtime')) {
/**
* Convert a 40 bit integer into a time.
* @see timew()
*
* @param int $time
* @param int|null $year
* @return \Carbon\Carbon
*/
function wtime(int $time,int $year=NULL): \Carbon\Carbon
{
if (! $year)
$year = \Carbon\Carbon::now()->year;
// Does the time have milli seconds?
if ($time > pow(2,26)-1) {
$milli = ($time & 0xf);
$time = $time >> 4;
} else {
$milli = 0;
}
$sec = ($time & 0x3f);
$time = $time >> 6;
$min = ($time & 0x3f);
$time = $time >> 6;
$hr = ($time & 0x1f);
$time = $time >> 5;
$day = ($time & 0x1f);
$time = $time >> 5;
$month = ($time & 0x1f);
return \Carbon\Carbon::create($year,$month,$day,$hr,$min,$sec+$milli/10);
}
}