Batch 24 (20261102-C-bos-seed-24) screened all 3078 Bos seed queries. Only 23 themes were in scope (pure user-space reliability, at most one task per theme); the rest were single operations or explanations, installs and networking, system administration, ROS2, board-only or GUI requests. Two finished drafts were withdrawn as too close to existing tasks. Seeds supply direction only: all sources, contracts and tests are new, and no task shares more than 14 characters with its seed text. Each task passed the local gate and the trace6 Docker gate (5 runs per sample class). Claude rebuilt the catalog from the calibration receipts: 23/23 USABLE. 16 of 23 are C/C++. Only the task directories are taken; the batch worktree's lowered disk floor in rollout/core.py stays out of main. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
139 lines
3.3 KiB
C
139 lines
3.3 KiB
C
#include "canburst.h"
|
|
|
|
#include <string.h>
|
|
|
|
const char *cb_error_name(cb_error error)
|
|
{
|
|
static const char *const names[] = {
|
|
"OK", "ID", "FLAGS", "OPCODE", "CHANNEL", "VALUE", "LENGTH",
|
|
"CAPACITY", "STATE", "POLICY", "BUSY", "BUDGET", "PORT", "FRAME", "SCRIPT"
|
|
};
|
|
if ((unsigned)error >= sizeof(names) / sizeof(names[0])) {
|
|
return "UNKNOWN";
|
|
}
|
|
return names[error];
|
|
}
|
|
|
|
const char *cb_state_name(cb_state state)
|
|
{
|
|
switch (state) {
|
|
case CB_READY:
|
|
return "READY";
|
|
case CB_DONE:
|
|
return "DONE";
|
|
case CB_FAULT:
|
|
return "FAULT";
|
|
}
|
|
return "UNKNOWN";
|
|
}
|
|
|
|
static int valid_value(const cb_request *request)
|
|
{
|
|
switch (request->opcode) {
|
|
case 1:
|
|
return request->value == 0;
|
|
case 2:
|
|
return request->value >= -1000000 && request->value <= 1000000;
|
|
case 3:
|
|
return request->value >= -32768 && request->value <= 32767;
|
|
case 4:
|
|
return request->value >= 0 && request->value <= 65535;
|
|
default:
|
|
return 0;
|
|
}
|
|
}
|
|
|
|
static int valid_length(const cb_request *request)
|
|
{
|
|
if (request->data_length > CB_MAX_DATA) {
|
|
return 0;
|
|
}
|
|
switch (request->opcode) {
|
|
case 1:
|
|
case 2:
|
|
return request->data_length == 0;
|
|
case 3:
|
|
return request->data_length >= 2 && request->data_length <= 12 &&
|
|
request->data_length % 2 == 0;
|
|
case 4:
|
|
return 1;
|
|
default:
|
|
return 0;
|
|
}
|
|
}
|
|
|
|
cb_error cb_request_validate(const cb_request *request)
|
|
{
|
|
uint32_t maximum = (request->flags & CB_EXT) ? 0x1fffffffu : 0x7ffu;
|
|
if (request->id > maximum) {
|
|
return CB_ID;
|
|
}
|
|
if ((request->flags & ~(CB_EXT | CB_BRS)) != 0) {
|
|
return CB_FLAGS;
|
|
}
|
|
if (request->opcode < 1 || request->opcode > 4) {
|
|
return CB_OPCODE;
|
|
}
|
|
if (request->channel > 15) {
|
|
return CB_CHANNEL;
|
|
}
|
|
if (!valid_value(request)) {
|
|
return CB_VALUE;
|
|
}
|
|
if (!valid_length(request)) {
|
|
return CB_LENGTH;
|
|
}
|
|
return CB_OK;
|
|
}
|
|
|
|
size_t cb_payload_length(const cb_request *request)
|
|
{
|
|
switch (request->opcode) {
|
|
case 1:
|
|
return 4;
|
|
case 2:
|
|
return 8;
|
|
case 3:
|
|
case 4:
|
|
return 8 + request->data_length;
|
|
default:
|
|
return 0;
|
|
}
|
|
}
|
|
|
|
static void put_u16(uint8_t *bytes, uint16_t value)
|
|
{
|
|
bytes[0] = (uint8_t)value;
|
|
bytes[1] = (uint8_t)(value >> 8);
|
|
}
|
|
|
|
static void put_u32(uint8_t *bytes, uint32_t value)
|
|
{
|
|
bytes[0] = (uint8_t)value;
|
|
bytes[1] = (uint8_t)(value >> 8);
|
|
bytes[2] = (uint8_t)(value >> 16);
|
|
bytes[3] = (uint8_t)(value >> 24);
|
|
}
|
|
|
|
cb_error cb_build(const cb_request *request, cb_frame *output)
|
|
{
|
|
uint8_t payload[64];
|
|
size_t length;
|
|
cb_error error = cb_request_validate(request);
|
|
if (error != CB_OK) {
|
|
return error;
|
|
}
|
|
memset(payload, 0, sizeof(payload));
|
|
payload[0] = (uint8_t)request->opcode;
|
|
payload[1] = (uint8_t)request->channel;
|
|
put_u16(payload + 2, request->sequence);
|
|
length = cb_payload_length(request);
|
|
if (request->opcode != 1) {
|
|
put_u32(payload + 4, (uint32_t)request->value);
|
|
}
|
|
if (request->opcode == 3 || request->opcode == 4) {
|
|
memcpy(payload + 8, request->data, request->data_length);
|
|
}
|
|
return cb_frame_pack(request->id, request->flags, payload, length, output);
|
|
}
|