One user-space repair task per eligible HWE debug-diag / compile-deploy base ID: 320 admitted (C 218, C++ 97, build scripts 5), 1 skipped by the content filter. Each ships a public spec with a check-to-basis table, at least two defects with single-fix fixtures, a symptom-masking fixture and an alternative correct implementation. Claude re-checked all 320: structure, the HWE quality items and trace6 Docker calibration receipts against current digests (320/320 USABLE). Difficulty is unmeasured. Known follow-up: 212 tasks use 120 ad-hoc family names; the next batch maps them to the canonical list. The batch's 1,256-line progress log stays in its factory report and the 36-local branch batch15-hwe. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
129 lines
3.7 KiB
C
129 lines
3.7 KiB
C
#include "scan.h"
|
|
#include <inttypes.h>
|
|
#include <string.h>
|
|
|
|
void scanner_init(Scanner *scanner, Port *port)
|
|
{
|
|
scanner->port = port;
|
|
for (int slot = 0; slot < SESSION_COUNT; slot++) {
|
|
Session *session = &scanner->sessions[slot];
|
|
session->handle = -1;
|
|
session->bus = -1;
|
|
session->sweeps = 0;
|
|
session->discoveries = 0;
|
|
}
|
|
}
|
|
|
|
int scanner_close(Scanner *scanner, int slot)
|
|
{
|
|
if (slot < 0 || slot >= SESSION_COUNT) {
|
|
return ERR_INVALID;
|
|
}
|
|
Session *session = &scanner->sessions[slot];
|
|
int result = 0;
|
|
if (session->handle >= 0) {
|
|
result = port_close(scanner->port, session->handle);
|
|
}
|
|
session->handle = -1;
|
|
session->bus = -1;
|
|
return result;
|
|
}
|
|
|
|
static int prepare(Scanner *scanner, int slot, int bus)
|
|
{
|
|
Session *session = &scanner->sessions[slot];
|
|
if (session->handle >= 0 && session->bus != bus) {
|
|
scanner_close(scanner, slot);
|
|
}
|
|
if (session->handle < 0) {
|
|
int descriptor = port_open(scanner->port, bus);
|
|
if (descriptor < 0) {
|
|
return descriptor;
|
|
}
|
|
session->handle = descriptor;
|
|
session->bus = bus;
|
|
}
|
|
return 0;
|
|
}
|
|
|
|
int scanner_run(Scanner *scanner, int slot, int bus, int low, int high,
|
|
int reverse, ScanResult *result)
|
|
{
|
|
memset(result, 0, sizeof(*result));
|
|
if (slot < 0 || slot >= SESSION_COUNT || bus < 0 || bus >= BUS_COUNT) {
|
|
return ERR_INVALID;
|
|
}
|
|
if (low < 3 || high > 119 || low > high || (reverse != 0 && reverse != 1)) {
|
|
return ERR_INVALID;
|
|
}
|
|
int status = prepare(scanner, slot, bus);
|
|
if (status < 0) {
|
|
return status;
|
|
}
|
|
int itinerary[ADDRESS_COUNT];
|
|
int length = high - low + 1;
|
|
for (int offset = 0; offset < length; offset++) {
|
|
itinerary[offset] = reverse ? high - offset : low + offset;
|
|
}
|
|
enum CursorState { SELECT, FETCH, ADVANCE, DONE, BROKEN } state = SELECT;
|
|
int cursor = 0;
|
|
int value = 0;
|
|
while (state != DONE && state != BROKEN) {
|
|
int address = itinerary[cursor];
|
|
switch (state) {
|
|
case SELECT:
|
|
status = port_select(scanner->port, scanner->sessions[slot].handle, address);
|
|
state = status < 0 ? BROKEN : FETCH;
|
|
break;
|
|
case FETCH:
|
|
status = port_read(scanner->port, scanner->sessions[slot].handle, &value);
|
|
result->visited++;
|
|
if (status < 0) {
|
|
state = BROKEN;
|
|
break;
|
|
}
|
|
if (status > 0) {
|
|
result->seen[address] = 1;
|
|
result->values[address] = value;
|
|
result->found++;
|
|
result->digest = result->digest * UINT64_C(131) +
|
|
(uint64_t)(address * 65536 + value + 1);
|
|
}
|
|
state = ADVANCE;
|
|
break;
|
|
case ADVANCE:
|
|
cursor++;
|
|
state = cursor == length ? DONE : SELECT;
|
|
break;
|
|
default:
|
|
state = BROKEN;
|
|
break;
|
|
}
|
|
}
|
|
if (state == BROKEN) {
|
|
scanner_close(scanner, slot);
|
|
return status;
|
|
}
|
|
Session *session = &scanner->sessions[slot];
|
|
session->sweeps++;
|
|
session->discoveries += (uint64_t)result->found;
|
|
return 0;
|
|
}
|
|
|
|
void scanner_finish(Scanner *scanner)
|
|
{
|
|
for (int slot = 0; slot < SESSION_COUNT; slot++) {
|
|
scanner_close(scanner, slot);
|
|
}
|
|
}
|
|
|
|
void scanner_dump(const Scanner *scanner, FILE *output)
|
|
{
|
|
for (int slot = 0; slot < SESSION_COUNT; slot++) {
|
|
const Session *session = &scanner->sessions[slot];
|
|
fprintf(output, "Q %d %d %d %" PRIu64 " %" PRIu64 "\n", slot,
|
|
session->handle, session->bus, session->sweeps,
|
|
session->discoveries);
|
|
}
|
|
}
|