mirror of
https://github.com/halleysfifthinc/AVCLAN-Mockingboard.git
synced 2026-08-07 01:13:18 +00:00
Fix (centralize) setting of controller/peripheral addrs
This commit is contained in:
@@ -319,7 +319,8 @@ void CDChanger::enable(Frame *out) {
|
|||||||
bool CDChanger::pending() { return statustimer_tickPending(); }
|
bool CDChanger::pending() { return statustimer_tickPending(); }
|
||||||
void CDChanger::resolvepending() { statustimer_clearTick(); }
|
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);
|
generateStatus(out, true, dev_STATUS);
|
||||||
out->reaction = r_StateReport;
|
out->reaction = r_StateReport;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -66,7 +66,7 @@ public:
|
|||||||
void disable(Frame *out);
|
void disable(Frame *out);
|
||||||
static bool pending();
|
static bool pending();
|
||||||
static void resolvepending();
|
static void resolvepending();
|
||||||
void emit(Frame *out);
|
void emit(Frame *out, uint16_t peripheral);
|
||||||
void incrementTime();
|
void incrementTime();
|
||||||
bool isPlaying() const;
|
bool isPlaying() const;
|
||||||
|
|
||||||
|
|||||||
@@ -11,15 +11,15 @@
|
|||||||
|
|
||||||
namespace avclan {
|
namespace avclan {
|
||||||
template <class T>
|
template <class T>
|
||||||
concept Device = requires {
|
concept Device = requires { std::integral_constant<uint8_t, T::id>{}; } &&
|
||||||
std::integral_constant<uint8_t, T::id>{};
|
requires(T dev, const Frame *in, Frame *out,
|
||||||
} && requires(T dev, const Frame *in, Frame *out, detail::Error::Send err) {
|
detail::Error::Send err, uint16_t peripheral) {
|
||||||
dev.init();
|
dev.init();
|
||||||
dev.handle(in, out);
|
dev.handle(in, out);
|
||||||
dev.enable(out);
|
dev.enable(out);
|
||||||
dev.react(out, err);
|
dev.react(out, err);
|
||||||
{ dev.pending() } -> std::convertible_to<bool>;
|
{ dev.pending() } -> std::convertible_to<bool>;
|
||||||
dev.resolvepending();
|
dev.resolvepending();
|
||||||
dev.emit(out);
|
dev.emit(out, peripheral);
|
||||||
};
|
};
|
||||||
} // namespace avclan
|
} // namespace avclan
|
||||||
|
|||||||
@@ -29,7 +29,9 @@ public:
|
|||||||
Error::Read read(Frame *in, Frame::Print print) {
|
Error::Read read(Frame *in, Frame::Print print) {
|
||||||
return bus.read(address_, in, 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);
|
return bus.send(out, print);
|
||||||
};
|
};
|
||||||
|
|
||||||
@@ -46,9 +48,7 @@ public:
|
|||||||
static const uint8_t lancheck_resp[] = {0x00, dev_COMM_CTRL, dev_LAN, 0xFF,
|
static const uint8_t lancheck_resp[] = {0x00, dev_COMM_CTRL, dev_LAN, 0xFF,
|
||||||
0xFF};
|
0xFF};
|
||||||
|
|
||||||
out->controller_addr = address_;
|
|
||||||
out->peripheral_addr = controller_;
|
out->peripheral_addr = controller_;
|
||||||
out->control = 0xF;
|
|
||||||
|
|
||||||
const uint8_t *data = in->data;
|
const uint8_t *data = in->data;
|
||||||
const uint8_t b0 = *data++;
|
const uint8_t b0 = *data++;
|
||||||
@@ -138,6 +138,11 @@ public:
|
|||||||
}
|
}
|
||||||
|
|
||||||
private:
|
private:
|
||||||
|
void postmark(Frame *out) const {
|
||||||
|
out->controller_addr = address_;
|
||||||
|
out->control = 0xF;
|
||||||
|
}
|
||||||
|
|
||||||
template <Device Dev, class F> void poller(Dev &dev, F &&fun) {
|
template <Device Dev, class F> void poller(Dev &dev, F &&fun) {
|
||||||
if (dev.pending() && fun(dev))
|
if (dev.pending() && fun(dev))
|
||||||
dev.resolvepending();
|
dev.resolvepending();
|
||||||
|
|||||||
+1
-4
@@ -101,7 +101,7 @@ int main() {
|
|||||||
|
|
||||||
peripheral.poll_devices([&](auto &dev) {
|
peripheral.poll_devices([&](auto &dev) {
|
||||||
if (auto status = cache.pop()) {
|
if (auto status = cache.pop()) {
|
||||||
dev.emit(status.get());
|
dev.emit(status.get(), peripheral.controller());
|
||||||
outgoing.push(std::move(status));
|
outgoing.push(std::move(status));
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
@@ -138,7 +138,6 @@ int main() {
|
|||||||
case 'E': // Beep
|
case 'E': // Beep
|
||||||
if (auto out = cache.pop()) {
|
if (auto out = cache.pop()) {
|
||||||
out->is_unicast = true;
|
out->is_unicast = true;
|
||||||
out->controller_addr = peripheral.address();
|
|
||||||
out->peripheral_addr = peripheral.controller();
|
out->peripheral_addr = peripheral.controller();
|
||||||
{
|
{
|
||||||
const uint8_t beep[] = {0x00, dev_CD_CHANGER, dev_BEEP_SPEAKERS,
|
const uint8_t beep[] = {0x00, dev_CD_CHANGER, dev_BEEP_SPEAKERS,
|
||||||
@@ -153,7 +152,6 @@ int main() {
|
|||||||
case 'P':
|
case 'P':
|
||||||
if (auto out = cache.pop()) {
|
if (auto out = cache.pop()) {
|
||||||
out->is_unicast = true;
|
out->is_unicast = true;
|
||||||
out->controller_addr = peripheral.address();
|
|
||||||
out->peripheral_addr = peripheral.controller();
|
out->peripheral_addr = peripheral.controller();
|
||||||
{
|
{
|
||||||
const uint8_t play[] = {0x00, dev_COMM_CTRL, dev_COMM_v1,
|
const uint8_t play[] = {0x00, dev_COMM_CTRL, dev_COMM_v1,
|
||||||
@@ -236,7 +234,6 @@ int main() {
|
|||||||
} else {
|
} else {
|
||||||
if (auto out = cache.pop()) {
|
if (auto out = cache.pop()) {
|
||||||
out->is_unicast = seqIsUnicast;
|
out->is_unicast = seqIsUnicast;
|
||||||
out->controller_addr = peripheral.address();
|
|
||||||
out->peripheral_addr =
|
out->peripheral_addr =
|
||||||
seqIsUnicast ? peripheral.controller() : 0x1FF;
|
seqIsUnicast ? peripheral.controller() : 0x1FF;
|
||||||
out->length = seqIdx;
|
out->length = seqIdx;
|
||||||
|
|||||||
Reference in New Issue
Block a user