This commit is contained in:
caternuson 2023-04-07 10:07:01 -07:00
parent 4fb204ef8d
commit 51d890da25
2 changed files with 36 additions and 94 deletions

View file

@ -1,38 +1,27 @@
// Copyright (c) Sandeep Mistry. All rights reserved. // Copyright (c) Sandeep Mistry. All rights reserved.
// Licensed under the MIT license. See LICENSE file in the project root for full license information. // Licensed under the MIT license. See LICENSE file in the project root for full
// license information.
#include "CANController.h" #include "CANController.h"
CANControllerClass::CANControllerClass() : CANControllerClass::CANControllerClass()
_onReceive(NULL), : _onReceive(NULL),
_packetBegun(false), _packetBegun(false), _txId(-1), _txExtended(-1), _txRtr(false), _txDlc(0),
_txId(-1), _txLength(0),
_txExtended(-1),
_txRtr(false),
_txDlc(0),
_txLength(0),
_rxId(-1), _rxId(-1), _rxExtended(false), _rxRtr(false), _rxDlc(0), _rxLength(0),
_rxExtended(false), _rxIndex(0) {
_rxRtr(false),
_rxDlc(0),
_rxLength(0),
_rxIndex(0)
{
// overide Stream timeout value // overide Stream timeout value
setTimeout(0); setTimeout(0);
} }
CANControllerClass::~CANControllerClass() CANControllerClass::~CANControllerClass() {}
{
}
int CANControllerClass::begin(long /*baudRate*/) int CANControllerClass::begin(long /*baudRate*/) {
{
_packetBegun = false; _packetBegun = false;
_txId = -1; _txId = -1;
_txRtr =false; _txRtr = false;
_txDlc = 0; _txDlc = 0;
_txLength = 0; _txLength = 0;
@ -45,12 +34,9 @@ int CANControllerClass::begin(long /*baudRate*/)
return 1; return 1;
} }
void CANControllerClass::end() void CANControllerClass::end() {}
{
}
int CANControllerClass::beginPacket(int id, int dlc, bool rtr) int CANControllerClass::beginPacket(int id, int dlc, bool rtr) {
{
if (id < 0 || id > 0x7FF) { if (id < 0 || id > 0x7FF) {
return 0; return 0;
} }
@ -71,8 +57,7 @@ int CANControllerClass::beginPacket(int id, int dlc, bool rtr)
return 1; return 1;
} }
int CANControllerClass::beginExtendedPacket(long id, int dlc, bool rtr) int CANControllerClass::beginExtendedPacket(long id, int dlc, bool rtr) {
{
if (id < 0 || id > 0x1FFFFFFF) { if (id < 0 || id > 0x1FFFFFFF) {
return 0; return 0;
} }
@ -93,8 +78,7 @@ int CANControllerClass::beginExtendedPacket(long id, int dlc, bool rtr)
return 1; return 1;
} }
int CANControllerClass::endPacket() int CANControllerClass::endPacket() {
{
if (!_packetBegun) { if (!_packetBegun) {
return 0; return 0;
} }
@ -107,38 +91,21 @@ int CANControllerClass::endPacket()
return 1; return 1;
} }
int CANControllerClass::parsePacket() int CANControllerClass::parsePacket() { return 0; }
{
return 0;
}
long CANControllerClass::packetId() long CANControllerClass::packetId() { return _rxId; }
{
return _rxId;
}
bool CANControllerClass::packetExtended() bool CANControllerClass::packetExtended() { return _rxExtended; }
{
return _rxExtended;
}
bool CANControllerClass::packetRtr() bool CANControllerClass::packetRtr() { return _rxRtr; }
{
return _rxRtr;
}
int CANControllerClass::packetDlc() int CANControllerClass::packetDlc() { return _rxDlc; }
{
return _rxDlc;
}
size_t CANControllerClass::write(uint8_t byte) size_t CANControllerClass::write(uint8_t byte) {
{
return write(&byte, sizeof(byte)); return write(&byte, sizeof(byte));
} }
size_t CANControllerClass::write(const uint8_t *buffer, size_t size) size_t CANControllerClass::write(const uint8_t *buffer, size_t size) {
{
if (!_packetBegun) { if (!_packetBegun) {
return 0; return 0;
} }
@ -153,13 +120,9 @@ size_t CANControllerClass::write(const uint8_t *buffer, size_t size)
return size; return size;
} }
int CANControllerClass::available() int CANControllerClass::available() { return (_rxLength - _rxIndex); }
{
return (_rxLength - _rxIndex);
}
int CANControllerClass::read() int CANControllerClass::read() {
{
if (!available()) { if (!available()) {
return -1; return -1;
} }
@ -167,8 +130,7 @@ int CANControllerClass::read()
return _rxData[_rxIndex++]; return _rxData[_rxIndex++];
} }
int CANControllerClass::peek() int CANControllerClass::peek() {
{
if (!available()) { if (!available()) {
return -1; return -1;
} }
@ -176,41 +138,20 @@ int CANControllerClass::peek()
return _rxData[_rxIndex]; return _rxData[_rxIndex];
} }
void CANControllerClass::flush() void CANControllerClass::flush() {}
{
}
void CANControllerClass::onReceive(void(*callback)(int)) void CANControllerClass::onReceive(void (*callback)(int)) {
{
_onReceive = callback; _onReceive = callback;
} }
int CANControllerClass::filter(int /*id*/, int /*mask*/) int CANControllerClass::filter(int /*id*/, int /*mask*/) { return 0; }
{
return 0;
}
int CANControllerClass::filterExtended(long /*id*/, long /*mask*/) int CANControllerClass::filterExtended(long /*id*/, long /*mask*/) { return 0; }
{
return 0;
}
int CANControllerClass::observe() int CANControllerClass::observe() { return 0; }
{
return 0;
}
int CANControllerClass::loopback() int CANControllerClass::loopback() { return 0; }
{
return 0;
}
int CANControllerClass::sleep() int CANControllerClass::sleep() { return 0; }
{
return 0;
}
int CANControllerClass::wakeup() int CANControllerClass::wakeup() { return 0; }
{
return 0;
}

View file

@ -1,5 +1,6 @@
// Copyright (c) Sandeep Mistry. All rights reserved. // Copyright (c) Sandeep Mistry. All rights reserved.
// Licensed under the MIT license. See LICENSE file in the project root for full license information. // Licensed under the MIT license. See LICENSE file in the project root for full
// license information.
#ifndef CAN_CONTROLLER_H #ifndef CAN_CONTROLLER_H
#define CAN_CONTROLLER_H #define CAN_CONTROLLER_H
@ -32,7 +33,7 @@ public:
virtual int peek(); virtual int peek();
virtual void flush(); virtual void flush();
virtual void onReceive(void(*callback)(int)); virtual void onReceive(void (*callback)(int));
virtual int filter(int id) { return filter(id, 0x7ff); } virtual int filter(int id) { return filter(id, 0x7ff); }
virtual int filter(int id, int mask); virtual int filter(int id, int mask);