mirror of
https://github.com/lowobservable/coax.git
synced 2026-02-12 19:27:41 +00:00
Add 3299 protocol support to interface2
This commit is contained in:
@@ -28,6 +28,12 @@
|
||||
|
||||
#define COAX_ERROR_NOT_INITIALIZED -1024
|
||||
|
||||
enum class CoaxProtocol
|
||||
{
|
||||
_3270 = 0,
|
||||
_3299 = 1
|
||||
};
|
||||
|
||||
enum class CoaxParity
|
||||
{
|
||||
Odd = 0,
|
||||
@@ -39,13 +45,17 @@ class SPICoaxTransceiver;
|
||||
class Coax
|
||||
{
|
||||
public:
|
||||
Coax(SPICoaxTransceiver &spiCoaxTransceiver, CoaxParity parity,
|
||||
volatile uint16_t *buffer, size_t bufferSize);
|
||||
Coax(SPICoaxTransceiver &spiCoaxTransceiver, volatile uint16_t *buffer,
|
||||
size_t bufferSize);
|
||||
|
||||
bool init();
|
||||
|
||||
void reset();
|
||||
|
||||
void setTXProtocol(CoaxProtocol protocol);
|
||||
void setRXProtocol(CoaxProtocol protocol);
|
||||
void setParity(CoaxParity parity);
|
||||
|
||||
int transmit(const uint16_t *buffer, size_t bufferCount);
|
||||
int receive(uint16_t *buffer, size_t bufferSize, uint16_t timeout);
|
||||
|
||||
@@ -53,6 +63,8 @@ public:
|
||||
|
||||
private:
|
||||
SPICoaxTransceiver &_spiCoaxTransceiver;
|
||||
CoaxProtocol _txProtocol;
|
||||
CoaxProtocol _rxProtocol;
|
||||
CoaxParity _parity;
|
||||
|
||||
bool _isInitialized;
|
||||
@@ -79,7 +91,9 @@ private:
|
||||
|
||||
#define COAX_REGISTER_CONTROL 0x2
|
||||
#define COAX_REGISTER_CONTROL_LOOPBACK 0x01
|
||||
#define COAX_REGISTER_CONTROL_TX_PROTOCOL 0x04
|
||||
#define COAX_REGISTER_CONTROL_TX_PARITY 0x08
|
||||
#define COAX_REGISTER_CONTROL_RX_PROTOCOL 0x20
|
||||
#define COAX_REGISTER_CONTROL_RX_PARITY 0x40
|
||||
|
||||
#define COAX_REGISTER_DEVICE_ID 0xf
|
||||
@@ -100,7 +114,9 @@ public:
|
||||
int receive(uint16_t *buffer, size_t bufferSize);
|
||||
|
||||
void setLoopback(bool loopback);
|
||||
void setTXProtocol(CoaxProtocol protocol);
|
||||
void setTXParity(CoaxParity parity);
|
||||
void setRXProtocol(CoaxProtocol protocol);
|
||||
void setRXParity(CoaxParity parity);
|
||||
|
||||
inline bool isTXComplete()
|
||||
|
||||
@@ -34,6 +34,8 @@
|
||||
#define INFO_MESSAGE_BUFFER_SIZE 0x06
|
||||
#define INFO_FEATURES 0x07
|
||||
|
||||
#define FEATURE_PROTOCOL_3299 0x10
|
||||
|
||||
#define TEST_SUPPORTED_TESTS 0x01
|
||||
|
||||
#define ERROR_INVALID_MESSAGE 1
|
||||
|
||||
@@ -21,10 +21,12 @@
|
||||
|
||||
#include "coax.h"
|
||||
|
||||
Coax::Coax(SPICoaxTransceiver &spiCoaxTransceiver, CoaxParity parity,
|
||||
volatile uint16_t *buffer, size_t bufferSize) :
|
||||
Coax::Coax(SPICoaxTransceiver &spiCoaxTransceiver, volatile uint16_t *buffer,
|
||||
size_t bufferSize) :
|
||||
_spiCoaxTransceiver(spiCoaxTransceiver),
|
||||
_parity(parity),
|
||||
_txProtocol(CoaxProtocol::_3270),
|
||||
_rxProtocol(CoaxProtocol::_3270),
|
||||
_parity(CoaxParity::Even),
|
||||
_buffer(buffer),
|
||||
_bufferSize(bufferSize)
|
||||
{
|
||||
@@ -41,7 +43,10 @@ bool Coax::init()
|
||||
return false;
|
||||
}
|
||||
|
||||
_spiCoaxTransceiver.setTXProtocol(_txProtocol);
|
||||
_spiCoaxTransceiver.setTXParity(_parity);
|
||||
|
||||
_spiCoaxTransceiver.setRXProtocol(_rxProtocol);
|
||||
_spiCoaxTransceiver.setRXParity(_parity);
|
||||
|
||||
_isInitialized = true;
|
||||
@@ -59,10 +64,62 @@ void Coax::reset()
|
||||
|
||||
_spiCoaxTransceiver.reset();
|
||||
|
||||
_spiCoaxTransceiver.setTXProtocol(_txProtocol);
|
||||
_spiCoaxTransceiver.setTXParity(_parity);
|
||||
|
||||
_spiCoaxTransceiver.setRXProtocol(_rxProtocol);
|
||||
_spiCoaxTransceiver.setRXParity(_parity);
|
||||
}
|
||||
|
||||
void Coax::setTXProtocol(CoaxProtocol protocol)
|
||||
{
|
||||
if (!_isInitialized) {
|
||||
_txProtocol = protocol;
|
||||
return;
|
||||
}
|
||||
|
||||
if (_txProtocol == protocol) {
|
||||
return;
|
||||
}
|
||||
|
||||
_spiCoaxTransceiver.setTXProtocol(protocol);
|
||||
|
||||
_txProtocol = protocol;
|
||||
}
|
||||
|
||||
void Coax::setRXProtocol(CoaxProtocol protocol)
|
||||
{
|
||||
if (!_isInitialized) {
|
||||
_rxProtocol = protocol;
|
||||
return;
|
||||
}
|
||||
|
||||
if (_rxProtocol == protocol) {
|
||||
return;
|
||||
}
|
||||
|
||||
_spiCoaxTransceiver.setRXProtocol(protocol);
|
||||
|
||||
_rxProtocol = protocol;
|
||||
}
|
||||
|
||||
void Coax::setParity(CoaxParity parity)
|
||||
{
|
||||
if (!_isInitialized) {
|
||||
_parity = parity;
|
||||
return;
|
||||
}
|
||||
|
||||
if (_parity == parity) {
|
||||
return;
|
||||
}
|
||||
|
||||
_spiCoaxTransceiver.setTXParity(parity);
|
||||
_spiCoaxTransceiver.setRXParity(parity);
|
||||
|
||||
_parity = parity;
|
||||
}
|
||||
|
||||
int Coax::transmit(const uint16_t *buffer, size_t bufferCount)
|
||||
{
|
||||
if (!_isInitialized) {
|
||||
@@ -434,11 +491,21 @@ void SPICoaxTransceiver::setLoopback(bool loopback)
|
||||
writeRegister(COAX_REGISTER_CONTROL, loopback ? COAX_REGISTER_CONTROL_LOOPBACK : 0, COAX_REGISTER_CONTROL_LOOPBACK);
|
||||
}
|
||||
|
||||
void SPICoaxTransceiver::setTXProtocol(CoaxProtocol protocol)
|
||||
{
|
||||
writeRegister(COAX_REGISTER_CONTROL, protocol == CoaxProtocol::_3299 ? COAX_REGISTER_CONTROL_TX_PROTOCOL : 0, COAX_REGISTER_CONTROL_TX_PROTOCOL);
|
||||
}
|
||||
|
||||
void SPICoaxTransceiver::setTXParity(CoaxParity parity)
|
||||
{
|
||||
writeRegister(COAX_REGISTER_CONTROL, parity == CoaxParity::Even ? COAX_REGISTER_CONTROL_TX_PARITY : 0, COAX_REGISTER_CONTROL_TX_PARITY);
|
||||
}
|
||||
|
||||
void SPICoaxTransceiver::setRXProtocol(CoaxProtocol protocol)
|
||||
{
|
||||
writeRegister(COAX_REGISTER_CONTROL, protocol == CoaxProtocol::_3299 ? COAX_REGISTER_CONTROL_RX_PROTOCOL : 0, COAX_REGISTER_CONTROL_RX_PROTOCOL);
|
||||
}
|
||||
|
||||
void SPICoaxTransceiver::setRXParity(CoaxParity parity)
|
||||
{
|
||||
writeRegister(COAX_REGISTER_CONTROL, parity == CoaxParity::Even ? COAX_REGISTER_CONTROL_RX_PARITY : 0, COAX_REGISTER_CONTROL_RX_PARITY);
|
||||
|
||||
@@ -46,6 +46,9 @@ Interface::Interface(Coax &coax, Indicators &indicators) :
|
||||
_coax(coax),
|
||||
_indicators(indicators)
|
||||
{
|
||||
_coax.setTXProtocol(CoaxProtocol::_3270);
|
||||
_coax.setRXProtocol(CoaxProtocol::_3270);
|
||||
_coax.setParity(CoaxParity::Even);
|
||||
}
|
||||
|
||||
void Interface::handleMessage(uint8_t *buffer, size_t bufferCount)
|
||||
@@ -143,6 +146,12 @@ void Interface::handleTransmitReceive(uint8_t *buffer, size_t bufferCount)
|
||||
}
|
||||
}
|
||||
|
||||
if (transmitBuffer[0] & 0x8000) {
|
||||
_coax.setTXProtocol(CoaxProtocol::_3299);
|
||||
} else {
|
||||
_coax.setTXProtocol(CoaxProtocol::_3270);
|
||||
}
|
||||
|
||||
int transmitCount = _coax.transmit(transmitBuffer, transmitBufferCount);
|
||||
|
||||
if (transmitCount < 0) {
|
||||
@@ -214,8 +223,9 @@ void Interface::handleInfo(uint8_t *buffer, size_t bufferCount)
|
||||
buffer[2] = INFO_HARDWARE_TYPE;
|
||||
buffer[3] = INFO_FIRMWARE_VERSION;
|
||||
buffer[4] = INFO_MESSAGE_BUFFER_SIZE;
|
||||
buffer[5] = INFO_FEATURES;
|
||||
|
||||
MessageSender::send(buffer, 5);
|
||||
MessageSender::send(buffer, 6);
|
||||
} else if (query == INFO_HARDWARE_TYPE) {
|
||||
buffer[0] = 0x01;
|
||||
|
||||
@@ -238,6 +248,11 @@ void Interface::handleInfo(uint8_t *buffer, size_t bufferCount)
|
||||
memcpy(buffer + 1, &size, sizeof(uint32_t));
|
||||
|
||||
MessageSender::send(buffer, 5);
|
||||
} else if (query == INFO_FEATURES) {
|
||||
buffer[0] = 0x01;
|
||||
buffer[1] = FEATURE_PROTOCOL_3299;
|
||||
|
||||
MessageSender::send(buffer, 2);
|
||||
} else {
|
||||
sendErrorMessage(ERROR_INVALID_MESSAGE, "HANDLE_INFO_UNKNOWN_QUERY");
|
||||
return;
|
||||
|
||||
@@ -45,7 +45,7 @@ SPICoaxTransceiver spiCoaxTransceiver;
|
||||
|
||||
volatile uint16_t coaxBuffer[COAX_BUFFER_SIZE];
|
||||
|
||||
Coax coax(spiCoaxTransceiver, CoaxParity::Even, coaxBuffer, COAX_BUFFER_SIZE);
|
||||
Coax coax(spiCoaxTransceiver, coaxBuffer, COAX_BUFFER_SIZE);
|
||||
|
||||
volatile uint8_t messageBuffer[MESSAGE_BUFFER_SIZE];
|
||||
|
||||
|
||||
Reference in New Issue
Block a user