CANPort provides a higher level interface to a CAN communication channel, and provides timestamping, servicing additional hardware interfaces (optional activity LED, CAN transceiver slope control)

Revision:
3:4c780c641125
Parent:
1:f0b4e47d948d
--- a/CANPort.cpp	Fri Aug 30 21:44:31 2019 +0000
+++ b/CANPort.cpp	Thu Sep 19 21:46:28 2019 +0000
@@ -28,9 +28,10 @@
 #define FLASH_RX_LEVEL 1.00
 
 
-CANPort::CANPort(CANCHANNEL_T chNum, PinName rd, PinName td, PinName _activityPin, PinName _slopePin, CANSlopeControl_T slope) {
+CANPort::CANPort(CANCHANNEL_T chNum, PinName rd, PinName td, PinName _activityPin, PinName _slopePin, CANSlopeControl_T slope) 
+    : CAN(rd,td) {
     channel = chNum;
-    can = new CAN(rd, td);
+    //can = new CAN(rd, td);
     if (_activityPin != NC) {
         activityPin = new PwmOut(_activityPin);
         activityPin->pulsewidth_us(100);
@@ -53,11 +54,11 @@
         delete slopePin;
     if (activityPin)
         delete activityPin;
-    if (can)
-        delete can;
+    //if (can)
+    //    delete can;
     slopePin = NULL;
     activityPin = NULL;
-    can = NULL;
+    //can = NULL;
 }
 
 
@@ -66,7 +67,7 @@
 
     if (msg.dir == xmt) {   // we have to have indicated our intent to transmit
         msg.ch = channel;
-        if (can->write(CANMessage(msg.id, (char *)&msg.data, msg.len, CANData, msg.format))) {
+        if ( write(CANMessage(msg.id, (char *)&msg.data, msg.len, CANData, msg.format))) {
             txCounter++;
             Flash(msg.dir);
             success = true;
@@ -80,7 +81,7 @@
     bool success = false;
     CANMessage _msg;
 
-    if (can->read(_msg)) {
+    if (read(_msg)) {
         /// @TODO This looks like a very inefficient method, but it works.
         CANmsg Xmsg(channel, rcv, _msg);
         msg = Xmsg;
@@ -92,9 +93,9 @@
 }
 
 
-void CANPort::Attach( void (*fptr)(void)) {
-    can->attach(fptr);
-}
+//void CANPort::Attach( void (*fptr)(void) ) {
+//    can->attach(fptr);
+//}
 
 
 void CANPort::Extinguish(void) {
@@ -125,11 +126,11 @@
 bool CANPort::SetBusMode(CANBusMode_T mode) {
     switch (mode) {
         case MONITOR:
-            can->monitor(true);
+            monitor(true);
             busMode = mode;
             break;
         case ACTIVE:
-            can->monitor(false);
+            monitor(false);
             busMode = mode;
             break;
         default:
@@ -139,7 +140,7 @@
 }
 
 
-CANBusMode_T CANPort::GetBusMode() {
+CANPort::CANBusMode_T CANPort::GetBusMode() {
     return busMode;
 }
 
@@ -169,13 +170,13 @@
 }
 
 
-CANSlopeControl_T CANPort::GetSlopeControl() {
+CANPort::CANSlopeControl_T CANPort::GetSlopeControl() {
     return slopeMode;
 }
 
 
-bool CANPort::SetBitRate(int rate) {
-    if (can->frequency(rate)) {
+bool CANPort::SetBitRate(uint32_t rate) {
+    if (frequency(rate)) {
         bitRate = rate;
         return true;
     } else {
@@ -184,7 +185,7 @@
 }
 
 
-int CANPort::GetBitRate() {
+uint32_t CANPort::GetBitRate() {
     return bitRate;
 }
 
@@ -200,17 +201,17 @@
 
 
 int CANPort::GetTxErrorCounter() {
-    return can->tderror();
+    return tderror();
 }
 
 
 int CANPort::GetRxErrorCounter() {
-    return can->rderror();
+    return rderror();
 }
 
 
 bool CANPort::ResetChip() {
-    can->reset();
+    reset();
     return true;
 }