Fix (centralize) setting of controller/peripheral addrs

This commit is contained in:
Allen Hill
2026-07-06 13:01:59 -07:00
parent ce8e1dde92
commit 82cbb126a9
5 changed files with 23 additions and 20 deletions
+2 -1
View File
@@ -319,7 +319,8 @@ void CDChanger::enable(Frame *out) {
bool CDChanger::pending() { return statustimer_tickPending(); }
void CDChanger::resolvepending() { statustimer_clearTick(); }
void CDChanger::emit(Frame *out) {
void CDChanger::emit(Frame *out, uint16_t peripheral) {
out->peripheral_addr = peripheral;
generateStatus(out, true, dev_STATUS);
out->reaction = r_StateReport;
}
+1 -1
View File
@@ -66,7 +66,7 @@ public:
void disable(Frame *out);
static bool pending();
static void resolvepending();
void emit(Frame *out);
void emit(Frame *out, uint16_t peripheral);
void incrementTime();
bool isPlaying() const;
+11 -11
View File
@@ -11,15 +11,15 @@
namespace avclan {
template <class T>
concept Device = requires {
std::integral_constant<uint8_t, T::id>{};
} && requires(T dev, const Frame *in, Frame *out, detail::Error::Send err) {
dev.init();
dev.handle(in, out);
dev.enable(out);
dev.react(out, err);
{ dev.pending() } -> std::convertible_to<bool>;
dev.resolvepending();
dev.emit(out);
};
concept Device = requires { std::integral_constant<uint8_t, T::id>{}; } &&
requires(T dev, const Frame *in, Frame *out,
detail::Error::Send err, uint16_t peripheral) {
dev.init();
dev.handle(in, out);
dev.enable(out);
dev.react(out, err);
{ dev.pending() } -> std::convertible_to<bool>;
dev.resolvepending();
dev.emit(out, peripheral);
};
} // namespace avclan
+8 -3
View File
@@ -29,7 +29,9 @@ public:
Error::Read read(Frame *in, Frame::Print print) {
return bus.read(address_, in, print);
};
Error::Send send(const Frame *out, Frame::Print print) {
// To "forge" a controller_addr, instantiate a new/different Peripheral
Error::Send send(Frame *out, Frame::Print print) {
postmark(out);
return bus.send(out, print);
};
@@ -46,9 +48,7 @@ public:
static const uint8_t lancheck_resp[] = {0x00, dev_COMM_CTRL, dev_LAN, 0xFF,
0xFF};
out->controller_addr = address_;
out->peripheral_addr = controller_;
out->control = 0xF;
const uint8_t *data = in->data;
const uint8_t b0 = *data++;
@@ -138,6 +138,11 @@ public:
}
private:
void postmark(Frame *out) const {
out->controller_addr = address_;
out->control = 0xF;
}
template <Device Dev, class F> void poller(Dev &dev, F &&fun) {
if (dev.pending() && fun(dev))
dev.resolvepending();
+1 -4
View File
@@ -101,7 +101,7 @@ int main() {
peripheral.poll_devices([&](auto &dev) {
if (auto status = cache.pop()) {
dev.emit(status.get());
dev.emit(status.get(), peripheral.controller());
outgoing.push(std::move(status));
return true;
}
@@ -138,7 +138,6 @@ int main() {
case 'E': // Beep
if (auto out = cache.pop()) {
out->is_unicast = true;
out->controller_addr = peripheral.address();
out->peripheral_addr = peripheral.controller();
{
const uint8_t beep[] = {0x00, dev_CD_CHANGER, dev_BEEP_SPEAKERS,
@@ -153,7 +152,6 @@ int main() {
case 'P':
if (auto out = cache.pop()) {
out->is_unicast = true;
out->controller_addr = peripheral.address();
out->peripheral_addr = peripheral.controller();
{
const uint8_t play[] = {0x00, dev_COMM_CTRL, dev_COMM_v1,
@@ -236,7 +234,6 @@ int main() {
} else {
if (auto out = cache.pop()) {
out->is_unicast = seqIsUnicast;
out->controller_addr = peripheral.address();
out->peripheral_addr =
seqIsUnicast ? peripheral.controller() : 0x1FF;
out->length = seqIdx;