mirror of
https://github.com/halleysfifthinc/AVCLAN-Mockingboard.git
synced 2026-09-25 13:22:06 +00:00
Fix compile errors due to non-portable code
This commit is contained in:
+27
-26
@@ -30,6 +30,7 @@
|
|||||||
*/
|
*/
|
||||||
|
|
||||||
#include <concepts>
|
#include <concepts>
|
||||||
|
#include <cstdint>
|
||||||
#include <cstdio>
|
#include <cstdio>
|
||||||
#include <memory>
|
#include <memory>
|
||||||
#include <new>
|
#include <new>
|
||||||
@@ -96,7 +97,7 @@ public:
|
|||||||
if (expect_ack)
|
if (expect_ack)
|
||||||
return read_ACK();
|
return read_ACK();
|
||||||
|
|
||||||
sendbits<1>(1U); // still need to fill the ack bit slot
|
sendbits<1>((uint8_t)1U); // still need to fill the ack bit slot
|
||||||
return Send{0};
|
return Send{0};
|
||||||
};
|
};
|
||||||
|
|
||||||
@@ -197,7 +198,7 @@ void Bus::mute(bool mute) {
|
|||||||
auto Bus::read(uint16_t address, Frame::Print print)
|
auto Bus::read(uint16_t address, Frame::Print print)
|
||||||
-> expected<std::unique_ptr<Frame>, Error::Read> {
|
-> expected<std::unique_ptr<Frame>, Error::Read> {
|
||||||
struct errtype {
|
struct errtype {
|
||||||
Read errno;
|
Read type;
|
||||||
uint16_t val;
|
uint16_t val;
|
||||||
} err = {};
|
} err = {};
|
||||||
|
|
||||||
@@ -205,7 +206,7 @@ auto Bus::read(uint16_t address, Frame::Print print)
|
|||||||
|
|
||||||
std::unique_ptr<Frame> in(new (std::nothrow) Frame);
|
std::unique_ptr<Frame> in(new (std::nothrow) Frame);
|
||||||
if (!in) {
|
if (!in) {
|
||||||
err.errno = POOL_EMPTY;
|
err.type = POOL_EMPTY;
|
||||||
goto handle_err;
|
goto handle_err;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -215,8 +216,8 @@ auto Bus::read(uint16_t address, Frame::Print print)
|
|||||||
bool shouldACK = false;
|
bool shouldACK = false;
|
||||||
uint8_t tmp = 0;
|
uint8_t tmp = 0;
|
||||||
|
|
||||||
err.errno = handle.readstartbit();
|
err.type = handle.readstartbit();
|
||||||
if (err.errno != Read{0})
|
if (err.type != Read{0})
|
||||||
goto handle_err;
|
goto handle_err;
|
||||||
|
|
||||||
handle.read<1>(&tmp, no_parity);
|
handle.read<1>(&tmp, no_parity);
|
||||||
@@ -224,7 +225,7 @@ auto Bus::read(uint16_t address, Frame::Print print)
|
|||||||
|
|
||||||
if (auto rerr = handle.read<12>(&in->controller_addr, with_parity);
|
if (auto rerr = handle.read<12>(&in->controller_addr, with_parity);
|
||||||
rerr == BAD_PARITY) {
|
rerr == BAD_PARITY) {
|
||||||
err.errno = BAD_CONTROLLER_PARITY;
|
err.type = BAD_CONTROLLER_PARITY;
|
||||||
if (print.verbose)
|
if (print.verbose)
|
||||||
err.val = in->controller_addr;
|
err.val = in->controller_addr;
|
||||||
|
|
||||||
@@ -240,7 +241,7 @@ auto Bus::read(uint16_t address, Frame::Print print)
|
|||||||
if (auto rerr =
|
if (auto rerr =
|
||||||
handle.read<12>(&in->peripheral_addr, with_ack, should_ack_lambda);
|
handle.read<12>(&in->peripheral_addr, with_ack, should_ack_lambda);
|
||||||
rerr == BAD_PARITY) {
|
rerr == BAD_PARITY) {
|
||||||
err.errno = BAD_PERIPHERAL_PARITY;
|
err.type = BAD_PERIPHERAL_PARITY;
|
||||||
if (print.verbose)
|
if (print.verbose)
|
||||||
err.val = in->peripheral_addr;
|
err.val = in->peripheral_addr;
|
||||||
|
|
||||||
@@ -249,7 +250,7 @@ auto Bus::read(uint16_t address, Frame::Print print)
|
|||||||
|
|
||||||
if (auto rerr = handle.read<4>(&in->control, with_ack, shouldACK);
|
if (auto rerr = handle.read<4>(&in->control, with_ack, shouldACK);
|
||||||
rerr == BAD_PARITY) {
|
rerr == BAD_PARITY) {
|
||||||
err.errno = BAD_CONTROL_PARITY;
|
err.type = BAD_CONTROL_PARITY;
|
||||||
if (print.verbose)
|
if (print.verbose)
|
||||||
err.val = in->control;
|
err.val = in->control;
|
||||||
|
|
||||||
@@ -258,7 +259,7 @@ auto Bus::read(uint16_t address, Frame::Print print)
|
|||||||
|
|
||||||
if (auto rerr = handle.read<8>(&in->length, with_ack, shouldACK);
|
if (auto rerr = handle.read<8>(&in->length, with_ack, shouldACK);
|
||||||
rerr == BAD_PARITY) {
|
rerr == BAD_PARITY) {
|
||||||
err.errno = BAD_LENGTH_PARITY;
|
err.type = BAD_LENGTH_PARITY;
|
||||||
if (print.verbose)
|
if (print.verbose)
|
||||||
err.val = in->length;
|
err.val = in->length;
|
||||||
|
|
||||||
@@ -266,7 +267,7 @@ auto Bus::read(uint16_t address, Frame::Print print)
|
|||||||
}
|
}
|
||||||
|
|
||||||
if (in->length == 0 || in->length > Frame::MAXLENGTH) {
|
if (in->length == 0 || in->length > Frame::MAXLENGTH) {
|
||||||
err.errno = BAD_LENGTH_RANGE;
|
err.type = BAD_LENGTH_RANGE;
|
||||||
err.val = in->length;
|
err.val = in->length;
|
||||||
goto handle_err;
|
goto handle_err;
|
||||||
}
|
}
|
||||||
@@ -274,7 +275,7 @@ auto Bus::read(uint16_t address, Frame::Print print)
|
|||||||
for (uint8_t i = 0; i < in->length; i++) {
|
for (uint8_t i = 0; i < in->length; i++) {
|
||||||
if (auto rerr = handle.read<8>(&in->data[i], with_ack, shouldACK);
|
if (auto rerr = handle.read<8>(&in->data[i], with_ack, shouldACK);
|
||||||
rerr == BAD_PARITY) {
|
rerr == BAD_PARITY) {
|
||||||
err.errno = BAD_DATA_PARITY;
|
err.type = BAD_DATA_PARITY;
|
||||||
if (print.verbose)
|
if (print.verbose)
|
||||||
err.val = in->data[i];
|
err.val = in->data[i];
|
||||||
|
|
||||||
@@ -286,7 +287,7 @@ auto Bus::read(uint16_t address, Frame::Print print)
|
|||||||
if (false) { // NOLINT(readability-simplify-boolean-expr)
|
if (false) { // NOLINT(readability-simplify-boolean-expr)
|
||||||
handle_err:;
|
handle_err:;
|
||||||
fputs("ERR(read): ", stdout);
|
fputs("ERR(read): ", stdout);
|
||||||
switch (err.errno) {
|
switch (err.type) {
|
||||||
case POOL_EMPTY: puts("failed Frame alloc"); break;
|
case POOL_EMPTY: puts("failed Frame alloc"); break;
|
||||||
case BAD_STARTBIT: fputs("bad start bit (other)", stdout); break;
|
case BAD_STARTBIT: fputs("bad start bit (other)", stdout); break;
|
||||||
case STARTBIT_MISSED: fputs("missed start bit", stdout); break;
|
case STARTBIT_MISSED: fputs("missed start bit", stdout); break;
|
||||||
@@ -315,14 +316,14 @@ auto Bus::read(uint16_t address, Frame::Print print)
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Only print if some data has been correctly received
|
// Only print if some data has been correctly received
|
||||||
if (print.print && (err.errno < STARTBIT_MISSED)) {
|
if (print.print && (err.type < STARTBIT_MISSED)) {
|
||||||
if (err.errno > BAD_DATA_PARITY)
|
if (err.type > BAD_DATA_PARITY)
|
||||||
in->length = 0;
|
in->length = 0;
|
||||||
in->print(print);
|
in->print(print);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (err.errno != Read{0})
|
if (err.type != Read{0})
|
||||||
return unexpected(err.errno);
|
return unexpected(err.type);
|
||||||
|
|
||||||
return in;
|
return in;
|
||||||
}
|
}
|
||||||
@@ -331,14 +332,14 @@ auto Bus::send(const Frame &out, Frame::Print print) -> Send {
|
|||||||
struct errtype {
|
struct errtype {
|
||||||
// Error enum is ordered such that a lower numeric value corresponds to
|
// Error enum is ordered such that a lower numeric value corresponds to
|
||||||
// more success
|
// more success
|
||||||
Send errno;
|
Send type;
|
||||||
uint8_t val;
|
uint8_t val;
|
||||||
} err = {};
|
} err = {};
|
||||||
|
|
||||||
using enum Send;
|
using enum Send;
|
||||||
|
|
||||||
if (is_muted()) {
|
if (is_muted()) {
|
||||||
err.errno = MUTED;
|
err.type = MUTED;
|
||||||
goto handle_err;
|
goto handle_err;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -347,7 +348,7 @@ auto Bus::send(const Frame &out, Frame::Print print) -> Send {
|
|||||||
|
|
||||||
if (handle.sendstartbit() == BUSY) {
|
if (handle.sendstartbit() == BUSY) {
|
||||||
// Some other device is already driving the bus
|
// Some other device is already driving the bus
|
||||||
err.errno = BUSY;
|
err.type = BUSY;
|
||||||
goto handle_err;
|
goto handle_err;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -358,26 +359,26 @@ auto Bus::send(const Frame &out, Frame::Print print) -> Send {
|
|||||||
if (auto serr =
|
if (auto serr =
|
||||||
handle.send<12>(out.peripheral_addr, with_ack, out.is_unicast);
|
handle.send<12>(out.peripheral_addr, with_ack, out.is_unicast);
|
||||||
serr == NAK) {
|
serr == NAK) {
|
||||||
err.errno = NAK_ADDRESS;
|
err.type = NAK_ADDRESS;
|
||||||
goto handle_err;
|
goto handle_err;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (auto serr = handle.send<4>(out.control, with_ack, out.is_unicast);
|
if (auto serr = handle.send<4>(out.control, with_ack, out.is_unicast);
|
||||||
serr == NAK) {
|
serr == NAK) {
|
||||||
err.errno = NAK_CONTROL;
|
err.type = NAK_CONTROL;
|
||||||
goto handle_err;
|
goto handle_err;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (auto serr = handle.send<8>(out.length, with_ack, out.is_unicast);
|
if (auto serr = handle.send<8>(out.length, with_ack, out.is_unicast);
|
||||||
serr == NAK) {
|
serr == NAK) {
|
||||||
err.errno = NAK_MESSAGE_LENGTH;
|
err.type = NAK_MESSAGE_LENGTH;
|
||||||
goto handle_err;
|
goto handle_err;
|
||||||
}
|
}
|
||||||
|
|
||||||
for (uint8_t i = 0; i < out.length; i++) {
|
for (uint8_t i = 0; i < out.length; i++) {
|
||||||
if (auto serr = handle.send<8>(out.data[i], with_ack, out.is_unicast);
|
if (auto serr = handle.send<8>(out.data[i], with_ack, out.is_unicast);
|
||||||
serr == NAK) {
|
serr == NAK) {
|
||||||
err.errno = NAK_DATA;
|
err.type = NAK_DATA;
|
||||||
err.val = i;
|
err.val = i;
|
||||||
goto handle_err;
|
goto handle_err;
|
||||||
}
|
}
|
||||||
@@ -388,7 +389,7 @@ auto Bus::send(const Frame &out, Frame::Print print) -> Send {
|
|||||||
if (false) { // NOLINT(readability-simplify-boolean-expr)
|
if (false) { // NOLINT(readability-simplify-boolean-expr)
|
||||||
handle_err:;
|
handle_err:;
|
||||||
fputs("Error", stdout);
|
fputs("Error", stdout);
|
||||||
switch (err.errno) {
|
switch (err.type) {
|
||||||
case MUTED: fputs(": Device muted", stdout); break;
|
case MUTED: fputs(": Device muted", stdout); break;
|
||||||
case BUSY: fputs(": Busy bus", stdout); break;
|
case BUSY: fputs(": Busy bus", stdout); break;
|
||||||
case NAK_ADDRESS:
|
case NAK_ADDRESS:
|
||||||
@@ -397,7 +398,7 @@ auto Bus::send(const Frame &out, Frame::Print print) -> Send {
|
|||||||
case NAK_DATA:
|
case NAK_DATA:
|
||||||
case NAK:
|
case NAK:
|
||||||
fputs(" NAK: ", stdout);
|
fputs(" NAK: ", stdout);
|
||||||
switch (err.errno) {
|
switch (err.type) {
|
||||||
case NAK_ADDRESS: fputs("address", stdout); break;
|
case NAK_ADDRESS: fputs("address", stdout); break;
|
||||||
case NAK_CONTROL: fputs("Control", stdout); break;
|
case NAK_CONTROL: fputs("Control", stdout); break;
|
||||||
case NAK_MESSAGE_LENGTH: fputs("Message length", stdout); break;
|
case NAK_MESSAGE_LENGTH: fputs("Message length", stdout); break;
|
||||||
@@ -414,7 +415,7 @@ auto Bus::send(const Frame &out, Frame::Print print) -> Send {
|
|||||||
if (print.print)
|
if (print.print)
|
||||||
out.print(print);
|
out.print(print);
|
||||||
|
|
||||||
return err.errno;
|
return err.type;
|
||||||
}
|
}
|
||||||
|
|
||||||
Bus::Handle Bus::get() { return Handle{*this}; };
|
Bus::Handle Bus::get() { return Handle{*this}; };
|
||||||
|
|||||||
+6
-6
@@ -163,14 +163,14 @@ void Frame::print(Frame::Print print) const {
|
|||||||
|
|
||||||
Error::Parse Frame::parse(const uint8_t *bytes, uint8_t len) {
|
Error::Parse Frame::parse(const uint8_t *bytes, uint8_t len) {
|
||||||
struct errtype {
|
struct errtype {
|
||||||
Error::Parse errno;
|
Error::Parse type;
|
||||||
uint8_t val;
|
uint8_t val;
|
||||||
} err = {};
|
} err = {};
|
||||||
|
|
||||||
const uint8_t *last = bytes + len;
|
const uint8_t *last = bytes + len;
|
||||||
|
|
||||||
if (len < Frame::MIN_SIZE) {
|
if (len < Frame::MIN_SIZE) {
|
||||||
err.errno = TOO_SHORT;
|
err.type = TOO_SHORT;
|
||||||
goto handle_err;
|
goto handle_err;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -183,7 +183,7 @@ Error::Parse Frame::parse(const uint8_t *bytes, uint8_t len) {
|
|||||||
length = *bytes++;
|
length = *bytes++;
|
||||||
|
|
||||||
if (length > MAXLENGTH) {
|
if (length > MAXLENGTH) {
|
||||||
err.errno = LENGTH_TOO_BIG;
|
err.type = LENGTH_TOO_BIG;
|
||||||
err.val = length;
|
err.val = length;
|
||||||
goto handle_err;
|
goto handle_err;
|
||||||
}
|
}
|
||||||
@@ -191,14 +191,14 @@ Error::Parse Frame::parse(const uint8_t *bytes, uint8_t len) {
|
|||||||
if ((bytes + length) <= last) {
|
if ((bytes + length) <= last) {
|
||||||
memcpy(data, bytes, length);
|
memcpy(data, bytes, length);
|
||||||
} else {
|
} else {
|
||||||
err.errno = MISMATCH_LENGTH;
|
err.type = MISMATCH_LENGTH;
|
||||||
goto handle_err;
|
goto handle_err;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (false) { // NOLINT(readability-simplify-boolean-expr)
|
if (false) { // NOLINT(readability-simplify-boolean-expr)
|
||||||
handle_err:;
|
handle_err:;
|
||||||
fputs("ERR(parse): ", stdout);
|
fputs("ERR(parse): ", stdout);
|
||||||
switch (err.errno) {
|
switch (err.type) {
|
||||||
case TOO_SHORT: puts("not enough bytes too fill AVCLAN frame"); break;
|
case TOO_SHORT: puts("not enough bytes too fill AVCLAN frame"); break;
|
||||||
case MISMATCH_LENGTH:
|
case MISMATCH_LENGTH:
|
||||||
puts("frame->length is longer than remaining data");
|
puts("frame->length is longer than remaining data");
|
||||||
@@ -211,6 +211,6 @@ Error::Parse Frame::parse(const uint8_t *bytes, uint8_t len) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
return err.errno;
|
return err.type;
|
||||||
}
|
}
|
||||||
} // namespace avclan
|
} // namespace avclan
|
||||||
|
|||||||
@@ -4,6 +4,7 @@
|
|||||||
#pragma once
|
#pragma once
|
||||||
|
|
||||||
#include <stddef.h>
|
#include <stddef.h>
|
||||||
|
#include <stdint.h>
|
||||||
|
|
||||||
#ifdef __cplusplus
|
#ifdef __cplusplus
|
||||||
extern "C" {
|
extern "C" {
|
||||||
|
|||||||
Reference in New Issue
Block a user