Skip to content

Commit

Permalink
Merge pull request #5 from mac-can/development
Browse files Browse the repository at this point in the history
Merge latest development branch for release v0.2
  • Loading branch information
mac-can authored Feb 28, 2021
2 parents 4113cb2 + 41068b0 commit 52f784a
Show file tree
Hide file tree
Showing 13 changed files with 71 additions and 27 deletions.
2 changes: 1 addition & 1 deletion Libraries/CANAPI/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -136,7 +136,7 @@ incdir:
clean:
$(RM) $(TARGET) $(OUTDIR)/*.o $(OUTDIR)/*.d

distclean:
pristine:
$(RM) $(TARGET) $(OUTDIR)/*.o $(OUTDIR)/*.d
$(RM) $(BINDIR)/$(TARGET) $(BINDIR)/$(STATIC) $(BINDIR)/$(LIBRARY).dylib

Expand Down
2 changes: 1 addition & 1 deletion Libraries/TouCAN/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -134,7 +134,7 @@ incdir:
clean:
$(RM) $(TARGET) $(OUTDIR)/*.o $(OUTDIR)/*.d

distclean:
pristine:
$(RM) $(TARGET) $(OUTDIR)/*.o $(OUTDIR)/*.d
$(RM) $(BINDIR)/$(TARGET) $(BINDIR)/$(STATIC) $(BINDIR)/$(LIBRARY).dylib

Expand Down
2 changes: 1 addition & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ clean:
$(MAKE) -C Utilities/can_test $@
$(MAKE) -C Utilities/can_moni $@

distclean:
pristine:
$(MAKE) -C Trial $@
$(MAKE) -C Libraries/TouCAN $@
$(MAKE) -C Libraries/CANAPI $@
Expand Down
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -119,7 +119,7 @@ Type `can_test --help` to display all program options.
#### macOS Big Sur
- macOS Big Sur (11.2) on a MacBook Pro (2019)
- macOS Big Sur (11.2.2) on a MacBook Pro (2019)
- Apple clang version 12.0.0 (clang-1200.0.32.29)
- Xcode Version 12.4 (12D4e)
Expand Down
4 changes: 2 additions & 2 deletions Sources/MacCAN_Core/MacCAN.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@
///
/// \author $Author: eris $
///
/// \version $Rev: 981 $
/// \version $Rev: 986 $
///
/// \addtogroup mac_can
/// \{
Expand Down Expand Up @@ -81,7 +81,7 @@ MacCAN_Return_t CMacCAN::MapBitrate2Speed(MacCAN_Bitrate_t bitrate, MacCAN_BusSp
// Methods for DLC conversion
//
EXPORT
uint8_t CMacCAN::DLc2Len(uint8_t dlc) {
uint8_t CMacCAN::Dlc2Len(uint8_t dlc) {
const static uint8_t dlc_table[16] = {
0U, 1U, 2U, 3U, 4U, 5U, 6U, 7U, 8U, 12U, 16U, 20U, 24U, 32U, 48U, 64U
};
Expand Down
6 changes: 3 additions & 3 deletions Sources/MacCAN_Core/MacCAN.h
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@
*
* @author $Author: eris $
*
* @version $Rev: 979 $
* @version $Rev: 986 $
*
* @defgroup mac_can macOS User-Space Driver for CAN to USB Interfaces
* @{
Expand Down Expand Up @@ -327,7 +327,7 @@ class CMacCAN {
/// \brief Methods for DLC conversion.
/// \{
public:
static uint8_t DLc2Len(uint8_t dlc);
static uint8_t Dlc2Len(uint8_t dlc);
static uint8_t Len2Dlc(uint8_t len);
/// \}

Expand Down Expand Up @@ -382,5 +382,5 @@ extern char *MacCAN_GetVersion(void); /**< retrieves version information. */
*/
#endif /* MACCAN_H_INCLUDED */

/* * $Id: MacCAN.h 979 2021-01-04 20:16:55Z eris $ *** (C) UV Software, Berlin ***
/* * $Id: MacCAN.h 986 2021-02-25 21:17:24Z eris $ *** (C) UV Software, Berlin ***
*/
13 changes: 10 additions & 3 deletions Sources/MacCAN_Core/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

_Copyright &copy; 2012-2021 Uwe Vogt, UV Software, Berlin ([email protected])_

Version $Rev: 983 $
Version $Rev: 985 $

# Running CAN and CAN FD on a Mac&reg;

Expand All @@ -25,7 +25,7 @@ But that poor boy only owned a Mac.
In the absence of a CAN driver for Mac, I started developing an OS X user space driver for my PEAK USB-to-CAN dongle.
Many thanks to Uwe Wilhelm, CEO of PEAK-System Technik GmbH, who had supported me with technical information and several hardware.

### PCBUSB Library
### PCBUSB Library for PEAK´s PCAN-USB Interfaces

The _PCBUSB_ library realizes a USB user-space driver under macOS for PCAN&reg; USB interfaces from PEAK-System Technik.
See the [MacCAN](https://www.mac-can.com) website for further information, downloads and links.
Expand All @@ -49,6 +49,12 @@ The driver for TouCAN USB interfaces from Rusoku is the first driver implementat
And it is open source;
goto https://github.com/mac-can/RusokuCAN/.

### CAN Leaf Interfaces from Kvaser

Welcome the MacCAN-KvaserCAN driver for CAN Leaf interfaces from [Kvaser](https://www.kvaser.com) as the next member of the MacCAN family.
Find its source code on GitHub;
goto https://github.com/mac-can/MacCAN-KvaserCAN/.

## HowTo

### MacCAN API Specification
Expand Down Expand Up @@ -321,7 +327,8 @@ along with MacCAN-Core. If not, see <http://www.gnu.org/licenses/>.
Mac and macOS are trademarks of Apple Inc., registered in the U.S. and other countries. \
PCAN is a registered trademark of PEAK-System Technik GmbH, Darmstadt, Germany. \
Qt is a registered trademark of The Qt Company Ltd. and its subsidiaries.
Qt is a registered trademark of The Qt Company Ltd. and its subsidiaries. \
All other company, product and service names mentioned herein are trademarks, registered trademarks or service marks of their respective owners.
### Contact
Expand Down
5 changes: 5 additions & 0 deletions Sources/TouCAN.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -339,6 +339,7 @@ MacCAN_Return_t CTouCAN::WriteMessage(MacCAN_Message_t message, uint16_t timeout

int size = TouCAN_EncodeMessage(buffer, &message);

MACCAN_LOG_WRITE(buffer, (UInt32)size, ">");
retVal = CANUSB_WritePipe(m_hDevice, TOUCAN_USB_TX_DATA_PIPE_REF, buffer, (UInt32)size, timeout);
m_Status.transmitter_busy = (retVal != CANERR_NOERROR) ? 1 : 0;
m_Counter.u64TxMessages += (retVal == CANERR_NOERROR) ? 1U : 0U;
Expand Down Expand Up @@ -386,6 +387,10 @@ MacCAN_Return_t CTouCAN::ReadMessage(MacCAN_Message_t &message, uint16_t timeout
m_Status.queue_overrun = CANQUE_OverflowFlag(m_pTouCAN->m_ReceiveData.m_MsgQueue) ? 1 : 0;
m_Counter.u64RxMessages += ((retVal == CANERR_NOERROR) && !message.sts) ? 1U : 0U;
m_Counter.u64ErrorFrames += ((retVal == CANERR_NOERROR) && message.sts) ? 1U : 0U;

// issue #2: Reading asynchronous reception pipe occasionally stalls
if (!CANUSB_IsPipeAsyncRunning(m_pTouCAN->m_ReceivePipe))
MACCAN_LOG_PRINTF("! error: asynchronous reception pipe stalled\n");
} else
retVal = CMacCAN::ControllerOffline;
}
Expand Down
2 changes: 2 additions & 0 deletions Sources/TouCAN_Driver/TouCAN_USB.c
Original file line number Diff line number Diff line change
Expand Up @@ -711,6 +711,8 @@ static void ReceptionCallback(void *refCon, UInt8 *buffer, UInt32 length) {
assert(refCon);
assert(buffer);

MACCAN_LOG_WRITE(buffer, length, "<");

while (length >= TOUCAN_USB_RX_DATA_FRAME_SIZE) {
bzero(&message, sizeof(MacCAN_Message_t));
(void) TouCAN_DecodeMessage(&message, &buffer[index], &context->m_MsgParam);
Expand Down
2 changes: 1 addition & 1 deletion Trial/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -102,7 +102,7 @@ outdir:
clean:
$(RM) $(TARGET) $(OUTDIR)/*.o $(OUTDIR)/*.d

distclean:
pristine:
$(RM) $(TARGET) $(OUTDIR)/*.o $(OUTDIR)/*.d

install:
Expand Down
54 changes: 42 additions & 12 deletions Trial/Sources/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -74,10 +74,15 @@ int main(int argc, const char * argv[]) {
int option_test = OPTION_NO;
int option_exit = OPTION_NO;
int option_echo = OPTION_YES;
// int option_stop = OPTION_NO;
// int option_check = OPTION_NO;
int option_stop = OPTION_NO;
int option_check = OPTION_NO;
int option_retry = OPTION_NO;
int option_repeat = OPTION_NO;
int option_transmit = OPTION_NO;
// int option_trace = OPTION_NO;
int option_log = OPTION_NO;
uint64_t received = 0ULL;
uint64_t expected = 0ULL;

for (int i = 1, opt = 0; i < argc; i++) {
/* TouCAN-USB channel */
Expand Down Expand Up @@ -107,8 +112,9 @@ int main(int argc, const char * argv[]) {
if (!strncmp(argv[i], "C:", 2) && sscanf(argv[i], "C:%i", &opt) == 1) delay = (useconds_t)opt * 1000U;
if (!strncmp(argv[i], "U:", 2) && sscanf(argv[i], "U:%i", &opt) == 1) delay = (useconds_t)opt;
/* receive messages */
// if (!strcmp(argv[i], "STOP")) option_stop = OPTION_YES;
// if (!strcmp(argv[i], "CHECK")) option_check = OPTION_YES;
if (!strcmp(argv[i], "STOP")) option_stop = OPTION_YES;
if (!strcmp(argv[i], "CHECK")) option_check = OPTION_YES;
if (!strcmp(argv[i], "RETRY")) option_retry = OPTION_YES;
if (!strcmp(argv[i], "REPEAT")) option_repeat = OPTION_YES;
if (!strcmp(argv[i], "SILENT")) option_echo = OPTION_NO;
/* time-stamps */
Expand All @@ -117,7 +123,7 @@ int main(int argc, const char * argv[]) {
// if (!strcmp(argv[i], "REL") || !strcmp(argv[i], "RELATIVE")) option_time = OPTION_TIME_REL;
/* logging and debugging */
// if (!strcmp(argv[i], "TRACE")) option_trace = OPTION_YES;
// if (!strcmp(argv[i], "LOG")) option_log = OPTION_YES;
if (!strcmp(argv[i], "LOG")) option_log = OPTION_YES;
/* query some informations: hw, sw, etc. */
if (!strcmp(argv[i], "INFO")) option_info = OPTION_YES;
if (!strcmp(argv[i], "STAT")) option_stat = OPTION_YES;
Expand All @@ -142,7 +148,8 @@ int main(int argc, const char * argv[]) {
perror("+++ error");
return errno;
}
MACCAN_LOG_OPEN();
if (option_log)
MACCAN_LOG_OPEN();
MACCAN_LOG_PRINTF("# MacCAN-PeakCAN - %s", ctime(&now));
retVal = CMacCAN::Initializer();
if (retVal != CMacCAN::NoError) {
Expand Down Expand Up @@ -283,8 +290,11 @@ int main(int argc, const char * argv[]) {
#endif
fprintf(stdout, "Press Ctrl+C to abort...\n");
while (running && (option_transmit-- > 0)) {
retry:
retVal = myDriver.WriteMessage(message);
if (retVal != CMacCAN::NoError) {
if ((retVal == CMacCAN::TransmitterBusy) && option_retry)
goto retry;
else if (retVal != CMacCAN::NoError) {
fprintf(stderr, "+++ error: myDriver.WriteMessage returned %i\n", retVal);
goto teardown;
}
Expand All @@ -294,8 +304,8 @@ int main(int argc, const char * argv[]) {
while (running) {
if ((retVal = myDriver.ReadMessage(message, timeout)) == CMacCAN::NoError) {
if (option_echo) {
fprintf(stdout, ">>> %i\t", frames++);
fprintf(stdout, "%7li.%04li\t%03x\t%c%c [%i]",
fprintf(stdout, ">>> %-6i ", frames++);
fprintf(stdout, "%7li.%04li %03x %c%c [%i]",
message.timestamp.tv_sec, message.timestamp.tv_nsec / 100000,
message.id, message.xtd? 'X' : 'S', message.rtr? 'R' : ' ', message.dlc);
for (int i = 0; i < message.dlc; i++)
Expand All @@ -316,15 +326,34 @@ int main(int argc, const char * argv[]) {
fflush(stdout);
}
}
if (option_check && !message.sts) {
received = 0;
if(message.dlc > 0) received |= (uint64_t)message.data[0] << 0;
if(message.dlc > 1) received |= (uint64_t)message.data[1] << 8;
if(message.dlc > 2) received |= (uint64_t)message.data[2] << 16;
if(message.dlc > 3) received |= (uint64_t)message.data[3] << 24;
if(message.dlc > 4) received |= (uint64_t)message.data[4] << 32;
if(message.dlc > 5) received |= (uint64_t)message.data[5] << 40;
if(message.dlc > 6) received |= (uint64_t)message.data[6] << 48;
if(message.dlc > 7) received |= (uint64_t)message.data[7] << 56;
if(received != expected) {
fprintf(stderr, "+++ error: received data is not equal to expected data (%" PRIu64 " : %" PRIu64 ")\n", received, expected);
if(expected > received)
fprintf(stderr, " issue #198: old messages read again (offset -%" PRIu64 ")\a\n", expected - received);
if(option_stop)
goto teardown;
}
expected = received + 1;
}
}
else if (retVal != CMacCAN::ReceiverEmpty) {
goto teardown;
}
#ifdef SECOND_CHANNEL
if ((retVal = mySecond.ReadMessage(message, 0U)) == CMacCAN::NoError) {
if (option_echo) {
fprintf(stdout, ">2> %i\t", frames++);
fprintf(stdout, "%7li.%04li\t%03x\t%c%c [%i]",
fprintf(stdout, ">2> %-6i ", frames++);
fprintf(stdout, "%7li.%04li %03x %c%c [%i]",
message.timestamp.tv_sec, message.timestamp.tv_nsec / 100000,
message.id, message.xtd? 'X' : 'S', message.rtr? 'R' : ' ', message.dlc);
for (int i = 0; i < message.dlc; i++)
Expand Down Expand Up @@ -399,7 +428,8 @@ int main(int argc, const char * argv[]) {
}
now = time(NULL);
MACCAN_LOG_PRINTF("# MacCAN-PeakCAN - %s", ctime(&now));
MACCAN_LOG_CLOSE();
if (option_log)
MACCAN_LOG_CLOSE();
fprintf(stdout, "Cheers!\n");
return retVal;
}
Expand Down
2 changes: 1 addition & 1 deletion Utilities/can_moni/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -99,7 +99,7 @@ incdir:
clean:
$(RM) $(TARGET) $(OUTDIR)/*.o $(OUTDIR)/*.d

distclean:
pristine:
$(RM) $(TARGET) $(OUTDIR)/*.o $(OUTDIR)/*.d
$(RM) $(BINDIR)/$(TARGET)

Expand Down
2 changes: 1 addition & 1 deletion Utilities/can_test/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -98,7 +98,7 @@ incdir:
clean:
$(RM) $(TARGET) $(OUTDIR)/*.o $(OUTDIR)/*.d

distclean:
pristine:
$(RM) $(TARGET) $(OUTDIR)/*.o $(OUTDIR)/*.d
$(RM) $(BINDIR)/$(TARGET)

Expand Down

0 comments on commit 52f784a

Please sign in to comment.