mirror of
https://github.com/halleysfifthinc/AVCLAN-Mockingboard.git
synced 2026-08-11 16:32:52 +00:00
Shift Device/Action enums to avclan.h
This commit is contained in:
+35
-25
@@ -4,7 +4,7 @@
|
||||
// SPDX-License-Identifier: GPL-3.0-or-later
|
||||
#pragma once
|
||||
|
||||
#include "avclan_defs.h"
|
||||
#include "avclan.h"
|
||||
#include "bus.hpp"
|
||||
#include "device.hpp"
|
||||
#include "frame.hpp"
|
||||
@@ -14,7 +14,7 @@
|
||||
#include <tuple>
|
||||
|
||||
namespace avclan {
|
||||
template <Device... Devs> class Peripheral {
|
||||
template <DeviceInterface... Devs> class Peripheral {
|
||||
public:
|
||||
using Error = detail::Error;
|
||||
|
||||
@@ -38,6 +38,8 @@ public:
|
||||
#define PACK3(a, b, c) (((uint32_t)(a) << 16) | ((uint32_t)(b) << 8) | (c))
|
||||
|
||||
void route(const Frame *in, Frame *out) {
|
||||
using enum Device;
|
||||
using enum Action;
|
||||
out->reaction = 0;
|
||||
|
||||
if (AVCLAN_ismuted() || in->length < 3)
|
||||
@@ -45,8 +47,8 @@ public:
|
||||
|
||||
// 0xFF placeholders are variant bytes filled by writing directly to
|
||||
// out->data[N] after memcpy.
|
||||
static const uint8_t lancheck_resp[] = {0x00, dev_COMM_CTRL, dev_LAN, 0xFF,
|
||||
0xFF};
|
||||
static const uint8_t lancheck_resp[] = {0x00, to_underlying(COMM_CTRL),
|
||||
to_underlying(LAN), 0xFF, 0xFF};
|
||||
|
||||
out->peripheral_addr = controller_;
|
||||
|
||||
@@ -62,51 +64,58 @@ public:
|
||||
// Broadcast: bytes are (from, to, action, [extra...]).
|
||||
// peripheral_addr unchecked — always 0xFFF or 0x1FF in known traffic.
|
||||
switch (PACK3(b0, b1, b2)) {
|
||||
case PACK3(dev_LAN, dev_COMM_CTRL, Lancheck_Scan_Req):
|
||||
case PACK3(LAN, COMM_CTRL, to_underlying(Lancheck_Scan_Req)):
|
||||
out->length = sizeof(lancheck_resp);
|
||||
out->is_unicast = true;
|
||||
memcpy(out->data, lancheck_resp, sizeof(lancheck_resp));
|
||||
out->data[3] = Lancheck_Scan_Resp;
|
||||
out->data[3] = to_underlying(Lancheck_Scan_Resp);
|
||||
out->data[4] = 0x01;
|
||||
out->reaction = 1;
|
||||
break;
|
||||
case PACK3(dev_LAN, dev_COMM_CTRL, Lancheck_Req):
|
||||
case PACK3(LAN, COMM_CTRL, to_underlying(Lancheck_Req)):
|
||||
out->length = sizeof(lancheck_resp);
|
||||
out->is_unicast = true;
|
||||
memcpy(out->data, lancheck_resp, sizeof(lancheck_resp));
|
||||
out->data[3] = Lancheck_Resp;
|
||||
out->data[3] = to_underlying(Lancheck_Resp);
|
||||
out->data[4] = 0x00;
|
||||
out->reaction = 1;
|
||||
break;
|
||||
case PACK3(dev_LAN, dev_COMM_CTRL, Lancheck_End_Req):
|
||||
case PACK3(LAN, COMM_CTRL, to_underlying(Lancheck_End_Req)):
|
||||
out->is_unicast = true;
|
||||
out->length = sizeof(lancheck_resp) - 1;
|
||||
memcpy(out->data, lancheck_resp, out->length);
|
||||
out->data[3] = Lancheck_End_Resp;
|
||||
out->data[3] = to_underlying(Lancheck_End_Resp);
|
||||
out->reaction = 1;
|
||||
break;
|
||||
case PACK3(dev_COMM_v1, dev_COMM_CTRL, Current_Function):
|
||||
case PACK3(dev_COMM_v2, dev_COMM_CTRL, Current_Function):
|
||||
((Devs::id == b3 ? std::get<Devs>(devices_).enable(out), 0 : 0), ...);
|
||||
case PACK3(COMM_v1, COMM_CTRL, to_underlying(Current_Function)):
|
||||
case PACK3(COMM_v2, COMM_CTRL, to_underlying(Current_Function)):
|
||||
((Devs::id == static_cast<Device>(b3)
|
||||
? std::get<Devs>(devices_).enable(out),
|
||||
0 : 0),
|
||||
...);
|
||||
break;
|
||||
case PACK3(dev_COMM_v1, dev_COMM_CTRL, Ping_Req):
|
||||
case PACK3(dev_COMM_v2, dev_COMM_CTRL, Ping_Req): {
|
||||
case PACK3(COMM_v1, COMM_CTRL, to_underlying(Ping_Req)):
|
||||
case PACK3(COMM_v2, COMM_CTRL, to_underlying(Ping_Req)): {
|
||||
out->is_unicast = true;
|
||||
const uint8_t ping_resp[] = {0x00, dev_COMM_CTRL, dev_COMM_v1,
|
||||
Ping_Resp, 0xFF, b3};
|
||||
const uint8_t ping_resp[] = {0x00,
|
||||
to_underlying(COMM_CTRL),
|
||||
to_underlying(COMM_v1),
|
||||
to_underlying(Ping_Resp),
|
||||
0xFF,
|
||||
b3};
|
||||
out->length = sizeof(ping_resp);
|
||||
memcpy(out->data, ping_resp, sizeof(ping_resp));
|
||||
out->reaction = 1;
|
||||
break;
|
||||
}
|
||||
case PACK3(dev_COMM_v1, dev_COMM_CTRL, List_Functions_Req):
|
||||
case PACK3(dev_COMM_v2, dev_COMM_CTRL, List_Functions_Req): {
|
||||
case PACK3(COMM_v1, COMM_CTRL, to_underlying(List_Functions_Req)):
|
||||
case PACK3(COMM_v2, COMM_CTRL, to_underlying(List_Functions_Req)): {
|
||||
controller_ = in->controller_addr;
|
||||
out->peripheral_addr = controller_;
|
||||
out->is_unicast = true;
|
||||
const uint8_t list_functions_resp[] = {
|
||||
0x00, dev_COMM_CTRL, dev_COMM_v1, List_Functions_Resp,
|
||||
dev_CD_CHANGER};
|
||||
0x00, to_underlying(COMM_CTRL), to_underlying(COMM_v1),
|
||||
to_underlying(List_Functions_Resp), to_underlying(CD_CHANGER)};
|
||||
out->length = sizeof(list_functions_resp);
|
||||
memcpy(out->data, list_functions_resp, sizeof(list_functions_resp));
|
||||
out->reaction = 1;
|
||||
@@ -115,8 +124,9 @@ public:
|
||||
// case Restart_Lan: not handled
|
||||
}
|
||||
} else if (in->peripheral_addr == address_ && b0 == 0x00) {
|
||||
((Devs::id == b2 ? device_preroute(std::get<Devs>(devices_), in, out),
|
||||
0 : 0),
|
||||
((Devs::id == static_cast<Device>(b2)
|
||||
? device_preroute(std::get<Devs>(devices_), in, out),
|
||||
0 : 0),
|
||||
...);
|
||||
}
|
||||
}
|
||||
@@ -143,11 +153,11 @@ private:
|
||||
out->control = 0xF;
|
||||
}
|
||||
|
||||
template <Device Dev, class F> void poller(Dev &dev, F &&fun) {
|
||||
template <DeviceInterface Dev, class F> void poller(Dev &dev, F &&fun) {
|
||||
if (dev.pending() && fun(dev))
|
||||
dev.resolvepending();
|
||||
}
|
||||
template <Device Dev>
|
||||
template <DeviceInterface Dev>
|
||||
void device_preroute(Dev &dev, const Frame *in, Frame *out) {
|
||||
out->owning_device = Dev::id;
|
||||
dev.handle(in, out);
|
||||
|
||||
Reference in New Issue
Block a user