diff --git a/.gitattributes b/.gitattributes new file mode 100644 index 0000000..bf5e415 --- /dev/null +++ b/.gitattributes @@ -0,0 +1,5 @@ +# Auto detect text files and perform LF normalization +* text=auto + +# Never modify line endings of bash scripts +*.sh text eol=lf diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..00cd112 --- /dev/null +++ b/.gitignore @@ -0,0 +1,11 @@ +# .gitignore +.svn +.objects +build_no.h +checker_*.txt +Utilities/Driver +Utilities/Binaries +Utilities/can_moni/can_moni +Utilities/can_test/can_test +Utilities/can_moni/build_no.h +Utilities/can_test/build_no.h diff --git a/LICENSE.GPL-2.0-only b/LICENSE.GPL-2.0-only new file mode 100644 index 0000000..9efa6fb --- /dev/null +++ b/LICENSE.GPL-2.0-only @@ -0,0 +1,338 @@ + GNU GENERAL PUBLIC LICENSE + Version 2, June 1991 + + Copyright (C) 1989, 1991 Free Software Foundation, Inc., + + Everyone is permitted to copy and distribute verbatim copies + of this license document, but changing it is not allowed. + + Preamble + + The licenses for most software are designed to take away your +freedom to share and change it. By contrast, the GNU General Public +License is intended to guarantee your freedom to share and change free +software--to make sure the software is free for all its users. This +General Public License applies to most of the Free Software +Foundation's software and to any other program whose authors commit to +using it. (Some other Free Software Foundation software is covered by +the GNU Lesser General Public License instead.) You can apply it to +your programs, too. + + When we speak of free software, we are referring to freedom, not +price. Our General Public Licenses are designed to make sure that you +have the freedom to distribute copies of free software (and charge for +this service if you wish), that you receive source code or can get it +if you want it, that you can change the software or use pieces of it +in new free programs; and that you know you can do these things. + + To protect your rights, we need to make restrictions that forbid +anyone to deny you these rights or to ask you to surrender the rights. +These restrictions translate to certain responsibilities for you if you +distribute copies of the software, or if you modify it. + + For example, if you distribute copies of such a program, whether +gratis or for a fee, you must give the recipients all the rights that +you have. You must make sure that they, too, receive or can get the +source code. And you must show them these terms so they know their +rights. + + We protect your rights with two steps: (1) copyright the software, and +(2) offer you this license which gives you legal permission to copy, +distribute and/or modify the software. + + Also, for each author's protection and ours, we want to make certain +that everyone understands that there is no warranty for this free +software. If the software is modified by someone else and passed on, we +want its recipients to know that what they have is not the original, so +that any problems introduced by others will not reflect on the original +authors' reputations. + + Finally, any free program is threatened constantly by software +patents. We wish to avoid the danger that redistributors of a free +program will individually obtain patent licenses, in effect making the +program proprietary. To prevent this, we have made it clear that any +patent must be licensed for everyone's free use or not licensed at all. + + The precise terms and conditions for copying, distribution and +modification follow. + + GNU GENERAL PUBLIC LICENSE + TERMS AND CONDITIONS FOR COPYING, DISTRIBUTION AND MODIFICATION + + 0. This License applies to any program or other work which contains +a notice placed by the copyright holder saying it may be distributed +under the terms of this General Public License. The "Program", below, +refers to any such program or work, and a "work based on the Program" +means either the Program or any derivative work under copyright law: +that is to say, a work containing the Program or a portion of it, +either verbatim or with modifications and/or translated into another +language. (Hereinafter, translation is included without limitation in +the term "modification".) Each licensee is addressed as "you". + +Activities other than copying, distribution and modification are not +covered by this License; they are outside its scope. The act of +running the Program is not restricted, and the output from the Program +is covered only if its contents constitute a work based on the +Program (independent of having been made by running the Program). +Whether that is true depends on what the Program does. + + 1. You may copy and distribute verbatim copies of the Program's +source code as you receive it, in any medium, provided that you +conspicuously and appropriately publish on each copy an appropriate +copyright notice and disclaimer of warranty; keep intact all the +notices that refer to this License and to the absence of any warranty; +and give any other recipients of the Program a copy of this License +along with the Program. + +You may charge a fee for the physical act of transferring a copy, and +you may at your option offer warranty protection in exchange for a fee. + + 2. You may modify your copy or copies of the Program or any portion +of it, thus forming a work based on the Program, and copy and +distribute such modifications or work under the terms of Section 1 +above, provided that you also meet all of these conditions: + + a) You must cause the modified files to carry prominent notices + stating that you changed the files and the date of any change. + + b) You must cause any work that you distribute or publish, that in + whole or in part contains or is derived from the Program or any + part thereof, to be licensed as a whole at no charge to all third + parties under the terms of this License. + + c) If the modified program normally reads commands interactively + when run, you must cause it, when started running for such + interactive use in the most ordinary way, to print or display an + announcement including an appropriate copyright notice and a + notice that there is no warranty (or else, saying that you provide + a warranty) and that users may redistribute the program under + these conditions, and telling the user how to view a copy of this + License. (Exception: if the Program itself is interactive but + does not normally print such an announcement, your work based on + the Program is not required to print an announcement.) + +These requirements apply to the modified work as a whole. If +identifiable sections of that work are not derived from the Program, +and can be reasonably considered independent and separate works in +themselves, then this License, and its terms, do not apply to those +sections when you distribute them as separate works. But when you +distribute the same sections as part of a whole which is a work based +on the Program, the distribution of the whole must be on the terms of +this License, whose permissions for other licensees extend to the +entire whole, and thus to each and every part regardless of who wrote it. + +Thus, it is not the intent of this section to claim rights or contest +your rights to work written entirely by you; rather, the intent is to +exercise the right to control the distribution of derivative or +collective works based on the Program. + +In addition, mere aggregation of another work not based on the Program +with the Program (or with a work based on the Program) on a volume of +a storage or distribution medium does not bring the other work under +the scope of this License. + + 3. You may copy and distribute the Program (or a work based on it, +under Section 2) in object code or executable form under the terms of +Sections 1 and 2 above provided that you also do one of the following: + + a) Accompany it with the complete corresponding machine-readable + source code, which must be distributed under the terms of Sections + 1 and 2 above on a medium customarily used for software interchange; or, + + b) Accompany it with a written offer, valid for at least three + years, to give any third party, for a charge no more than your + cost of physically performing source distribution, a complete + machine-readable copy of the corresponding source code, to be + distributed under the terms of Sections 1 and 2 above on a medium + customarily used for software interchange; or, + + c) Accompany it with the information you received as to the offer + to distribute corresponding source code. (This alternative is + allowed only for noncommercial distribution and only if you + received the program in object code or executable form with such + an offer, in accord with Subsection b above.) + +The source code for a work means the preferred form of the work for +making modifications to it. For an executable work, complete source +code means all the source code for all modules it contains, plus any +associated interface definition files, plus the scripts used to +control compilation and installation of the executable. However, as a +special exception, the source code distributed need not include +anything that is normally distributed (in either source or binary +form) with the major components (compiler, kernel, and so on) of the +operating system on which the executable runs, unless that component +itself accompanies the executable. + +If distribution of executable or object code is made by offering +access to copy from a designated place, then offering equivalent +access to copy the source code from the same place counts as +distribution of the source code, even though third parties are not +compelled to copy the source along with the object code. + + 4. You may not copy, modify, sublicense, or distribute the Program +except as expressly provided under this License. Any attempt +otherwise to copy, modify, sublicense or distribute the Program is +void, and will automatically terminate your rights under this License. +However, parties who have received copies, or rights, from you under +this License will not have their licenses terminated so long as such +parties remain in full compliance. + + 5. You are not required to accept this License, since you have not +signed it. However, nothing else grants you permission to modify or +distribute the Program or its derivative works. These actions are +prohibited by law if you do not accept this License. Therefore, by +modifying or distributing the Program (or any work based on the +Program), you indicate your acceptance of this License to do so, and +all its terms and conditions for copying, distributing or modifying +the Program or works based on it. + + 6. Each time you redistribute the Program (or any work based on the +Program), the recipient automatically receives a license from the +original licensor to copy, distribute or modify the Program subject to +these terms and conditions. You may not impose any further +restrictions on the recipients' exercise of the rights granted herein. +You are not responsible for enforcing compliance by third parties to +this License. + + 7. If, as a consequence of a court judgment or allegation of patent +infringement or for any other reason (not limited to patent issues), +conditions are imposed on you (whether by court order, agreement or +otherwise) that contradict the conditions of this License, they do not +excuse you from the conditions of this License. If you cannot +distribute so as to satisfy simultaneously your obligations under this +License and any other pertinent obligations, then as a consequence you +may not distribute the Program at all. For example, if a patent +license would not permit royalty-free redistribution of the Program by +all those who receive copies directly or indirectly through you, then +the only way you could satisfy both it and this License would be to +refrain entirely from distribution of the Program. + +If any portion of this section is held invalid or unenforceable under +any particular circumstance, the balance of the section is intended to +apply and the section as a whole is intended to apply in other +circumstances. + +It is not the purpose of this section to induce you to infringe any +patents or other property right claims or to contest validity of any +such claims; this section has the sole purpose of protecting the +integrity of the free software distribution system, which is +implemented by public license practices. Many people have made +generous contributions to the wide range of software distributed +through that system in reliance on consistent application of that +system; it is up to the author/donor to decide if he or she is willing +to distribute software through any other system and a licensee cannot +impose that choice. + +This section is intended to make thoroughly clear what is believed to +be a consequence of the rest of this License. + + 8. If the distribution and/or use of the Program is restricted in +certain countries either by patents or by copyrighted interfaces, the +original copyright holder who places the Program under this License +may add an explicit geographical distribution limitation excluding +those countries, so that distribution is permitted only in or among +countries not thus excluded. In such case, this License incorporates +the limitation as if written in the body of this License. + + 9. The Free Software Foundation may publish revised and/or new versions +of the General Public License from time to time. Such new versions will +be similar in spirit to the present version, but may differ in detail to +address new problems or concerns. + +Each version is given a distinguishing version number. If the Program +specifies a version number of this License which applies to it and "any +later version", you have the option of following the terms and conditions +either of that version or of any later version published by the Free +Software Foundation. If the Program does not specify a version number of +this License, you may choose any version ever published by the Free Software +Foundation. + + 10. If you wish to incorporate parts of the Program into other free +programs whose distribution conditions are different, write to the author +to ask for permission. For software which is copyrighted by the Free +Software Foundation, write to the Free Software Foundation; we sometimes +make exceptions for this. Our decision will be guided by the two goals +of preserving the free status of all derivatives of our free software and +of promoting the sharing and reuse of software generally. + + NO WARRANTY + + 11. BECAUSE THE PROGRAM IS LICENSED FREE OF CHARGE, THERE IS NO WARRANTY +FOR THE PROGRAM, TO THE EXTENT PERMITTED BY APPLICABLE LAW. EXCEPT WHEN +OTHERWISE STATED IN WRITING THE COPYRIGHT HOLDERS AND/OR OTHER PARTIES +PROVIDE THE PROGRAM "AS IS" WITHOUT WARRANTY OF ANY KIND, EITHER EXPRESSED +OR IMPLIED, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF +MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. THE ENTIRE RISK AS +TO THE QUALITY AND PERFORMANCE OF THE PROGRAM IS WITH YOU. SHOULD THE +PROGRAM PROVE DEFECTIVE, YOU ASSUME THE COST OF ALL NECESSARY SERVICING, +REPAIR OR CORRECTION. + + 12. IN NO EVENT UNLESS REQUIRED BY APPLICABLE LAW OR AGREED TO IN WRITING +WILL ANY COPYRIGHT HOLDER, OR ANY OTHER PARTY WHO MAY MODIFY AND/OR +REDISTRIBUTE THE PROGRAM AS PERMITTED ABOVE, BE LIABLE TO YOU FOR DAMAGES, +INCLUDING ANY GENERAL, SPECIAL, INCIDENTAL OR CONSEQUENTIAL DAMAGES ARISING +OUT OF THE USE OR INABILITY TO USE THE PROGRAM (INCLUDING BUT NOT LIMITED +TO LOSS OF DATA OR DATA BEING RENDERED INACCURATE OR LOSSES SUSTAINED BY +YOU OR THIRD PARTIES OR A FAILURE OF THE PROGRAM TO OPERATE WITH ANY OTHER +PROGRAMS), EVEN IF SUCH HOLDER OR OTHER PARTY HAS BEEN ADVISED OF THE +POSSIBILITY OF SUCH DAMAGES. + + END OF TERMS AND CONDITIONS + + How to Apply These Terms to Your New Programs + + If you develop a new program, and you want it to be of the greatest +possible use to the public, the best way to achieve this is to make it +free software which everyone can redistribute and change under these terms. + + To do so, attach the following notices to the program. It is safest +to attach them to the start of each source file to most effectively +convey the exclusion of warranty; and each file should have at least +the "copyright" line and a pointer to where the full notice is found. + + + Copyright (C) + + This program is free software; you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation; either version 2 of the License, or + (at your option) any later version. + + This program is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License along + with this program; if not, see . + +Also add information on how to contact you by electronic and paper mail. + +If the program is interactive, make it output a short notice like this +when it starts in an interactive mode: + + Gnomovision version 69, Copyright (C) year name of author + Gnomovision comes with ABSOLUTELY NO WARRANTY; for details type `show w'. + This is free software, and you are welcome to redistribute it + under certain conditions; type `show c' for details. + +The hypothetical commands `show w' and `show c' should show the appropriate +parts of the General Public License. Of course, the commands you use may +be called something other than `show w' and `show c'; they could even be +mouse-clicks or menu items--whatever suits your program. + +You should also get your employer (if you work as a programmer) or your +school, if any, to sign a "copyright disclaimer" for the program, if +necessary. Here is a sample; alter the names: + + Yoyodyne, Inc., hereby disclaims all copyright interest in the program + `Gnomovision' (which makes passes at compilers) written by James Hacker. + + , 1 April 1989 + Moe Ghoul, President of Vice + +This General Public License does not permit incorporating your program into +proprietary programs. If your program is a subroutine library, you may +consider it more useful to permit linking proprietary applications with the +library. If this is what you want to do, use the GNU Lesser General +Public License instead of this License. diff --git a/LICENSE b/LICENSE.UVS-Freeware similarity index 100% rename from LICENSE rename to LICENSE.UVS-Freeware diff --git a/README.md b/README.md index af80041..6c01a5c 100644 --- a/README.md +++ b/README.md @@ -1,15 +1,17 @@ -### macOS® Utilities for PCAN-USB Interfaces +### macOS® Utilities for PEAK-System PCAN USB Interfaces -*Copyright © 2012-2024 by UV Software, Berlin.*\ -*All rights reserved.* +*Copyright © 2005-2010 by Uwe Vogt, UV Software, Friedrichshafen.* \ +*Copyright © 2012-2024 by Uwe Vogt, UV Software, Berlin.* + +![macOS Build](https://github.com/mac-can/PCBUSB-Utilities/actions/workflows/macos-build.yml/badge.svg) # Running CAN and CAN FD on Mac® -The PCBUSB library realizes a CAN to USB user-space driver under macOS for PCAN-USB interfaces from PEAK-System Technik, Darmstadt. +The PCBUSB library realizes a CAN to USB user-space driver under macOS for PCAN USB interfaces from PEAK-System Technik, Darmstadt. It supports up to 8 PCAN-USB or PCAN-USB FD devices. The dynamic library libPCBUSB is running under macOS 10.13 and later (x86_64 architecture). -Since version 0.10.1 it is running under macOS Big Sur (11.x) or macOS Monterey (12.x) as Universal macOS Binary. +Since version 0.10.1 it is running under macOS Big Sur (11.x) and later as Universal macOS Binary. See the [MacCAN](https://www.mac-can.com/) website to learn more. @@ -19,8 +21,6 @@ This repo offers two command line tools that are build upon the PCBUSB library: - `can_moni` to view incoming CAN messages - `can_test` to test CAN communication -Both tools run as a standalone program, therefor it is not necessary to install the PCBUSB library to run them. - ### can_moni `can_moni` is a command line tool to view incoming CAN messages. @@ -39,45 +39,68 @@ Type `can_test --help` to display all program options. ### Target Platform -- macOS 12.0 and later (Intel and Apple silicon) +- macOS 13.0 and later (Intel and Apple silicon) ### Development Environment -#### macOS Sonoma +#### macOS Sequoia -- macOS Sonoma (14.5) on a Mac mini (M1, 2020) -- Apple clang version 15.0.0 (clang-1500.3.9.4) -- Xcode Version 15.4 (15F31d) +- macOS Sequoia (15.2) on a Mac mini (M1, 2020) +- Apple clang version 16.0.0 (clang-1600.0.26.6) -#### macOS Monterey +#### macOS Ventura -- macOS Monterey (12.7.5) on a MacBook Pro (2019) -- Apple clang version 13.0.0 (clang-1300.0.29.30) -- Xcode Version 13.2.1 (13C100) +- macOS Ventura (13.7.1) on a MacBook Pro (2019) +- Apple clang version 14.0.3 (clang-1403.0.22.14.1) ### Supported Devices Only the following devices from PEAK-System Technik are supported: - PCAN-USB (product code: IPEH-002021, IPEH-002022) - PCAN-USB FD (product code: IPEH-004022) +- PCAN-USB Pro FD (item no. IPEH-004061), but only the first channel (CAN1) ### Known Bugs and Caveats -For a list of known bugs and caveats in the underlying PCBUSB library read the documentation of the appropriated library version. +- For a list of known bugs and caveats see tab [Issues](https://github.com/mac-can/PCBUSB-Utilities/issues) in the GitHub repo. +- For a list of known bugs and caveats in the underlying PCBUSB library read the documentation of the appropriated library version. + +### Licenses + +This repository contains two versions of the PCBUSB utilities that are licensed under different licences: + +- **Standalone Version**: + This version of the utilities does not require the PCBUSB library to be installed. + The utilities are offered in binary form only. + This version can be found in the folder `$(PROJROOT)/Binaries`. +- **Open-source Version**: + This version links the PCBUSB library at runtime. + The PCBUSB library itself is not part of this work. + See folder `$(PROJROOT)/Utilities`. -PCAN-USB Pro FD devices are supported since version 0.10 of the PCBUSB library, but only the first channel (CAN1). +#### Licence for the Standalone Version -## This and That +This program is freeware without any warranty or support! \ +Please note the copyright and license agreements. -Since version 0.5.3 macOS 11 or newer is required to run the PCBUSB utilities as Universal macOS Binary. +#### Licence for the Open-Source Version -This repo contains only binaries files of the PCBUSB utilities. +This program is free software; you can redistribute it and/or modify +it under the terms of the GNU General Public License as published by +the Free Software Foundation; either version 2 of the License, or +(at your option) any later version. -### License +This program is distributed in the hope that it will be useful, +but WITHOUT ANY WARRANTY; without even the implied warranty of +MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +GNU General Public License for more details. -The PCBUSB utilities are freeware without any warranty or support! +You should have received a copy of the GNU General Public License along +with this program; if not, see . -Please note the copyright and license agreement. +Note: The libPCBUSB is licensed under a freeware license without any +warranty or support. The libPCBUSB is not part of this program. +It can be downloaded from . ### Trademarks diff --git a/Utilities/Makefile b/Utilities/Makefile new file mode 100644 index 0000000..19c99c0 --- /dev/null +++ b/Utilities/Makefile @@ -0,0 +1,45 @@ +# +# CAN Utilities for PEAK-System PCAN USB Interfaces (macOS, x86_64 & arm64) +# +# Copyright (c) 2007-2010 Uwe Vogt, UV Software, Friedrichshafen +# Copyright (c) 2012-2024 Uwe Vogt, UV Software, Berlin (info@mac-can.com) +# +# These utilities are free software: you can redistribute it and/or modify +# it under the terms of the GNU General Public License as published by +# the Free Software Foundation, either version 3 of the License, or +# (at your option) any later version. +# +# These utilities is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU General Public License for more details. +# +# You should have received a copy of the GNU General Public License +# along with these utilities. If not, see . +# +all: + @rm -r build_no.h 2> /dev/null || true + @./build_no.sh + @echo "\033[1mBuilding my beloved CAN Utilities...\033[0m" + $(MAKE) -C can_test $@ + $(MAKE) -C can_moni $@ + +clean: + $(MAKE) -C can_test $@ + $(MAKE) -C can_moni $@ + +pristine: + $(MAKE) -C can_test $@ + $(MAKE) -C can_moni $@ + +install: +# $(MAKE) -C can_test $@ +# $(MAKE) -C can_moni $@ + +check: + $(MAKE) -C can_test $@ 2> checker_test.txt + $(MAKE) -C can_moni $@ 2> checker_moni.txt + +build_no: + @./build_no.sh + @cat ./build_no.h diff --git a/Utilities/PCBUSB.c b/Utilities/PCBUSB.c new file mode 100755 index 0000000..66ca140 --- /dev/null +++ b/Utilities/PCBUSB.c @@ -0,0 +1,263 @@ +// +// PCBUSB.c +// MacCAN Monitor +// Wrapper for libPCBUSB +// +// Created by Uwe Vogt on 18.08.13. +// Copyright (c) 2013-2024 UV Software. All rights reserved. +// +// This software is freeware without any warranty or support! +// +// NO WARRANTIES: You expressly acknowledge and agree that use of the +// SOFTWARE PRODUCT is at your sole risk. The SOFTWARE PRODUCT is provided +// "AS IS" and without warranty of any kind. UV Software hereby EXPRESSLY +// DISCLAIMS ALL WARRANTIES OR CONDITIONS, EITHER EXPRESS OR IMPLIED, +// INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OR CONDITIONS OF +// MERCHANTABILITY, NON INFRINGEMENT AND FITNESS FOR A PARTICULAR PURPOSE. +// You are solely responsible for determining the appropriateness of using +// this SOFTWARE PRODUCT and assume all risks associated with the use of +// this SOFTWARE PRODUCT, including but not limited to the risks of program +// errors, damage to or loss of data, programs or equipment, and +// unavailability or interruption of operations. +// +// NO LIABILITY FOR DAMAGES: UNDER NO CIRCUMSTANCES, INCLUDING NEGLIGENCE, +// SHALL UV Software BE LIABLE FOR ANY INCIDENTAL, SPECIAL, INDIRECT OR +// CONSEQUENTIAL DAMAGES (INCLUDING, WITHOUT LIMITATION, DAMAGES FOR LOSS +// OF BUSINESS PROFITS, BUSINESS INTERRUPTION, LOSS OF BUSINESS INFORMATION, +// OR ANY OTHER PECUNIARY LOSS) ARISING OUT OF OR RELATING TO THIS LICENSE, +// EVEN IF UV Software HAS BEEN ADVISED OF THE POSSIBILITY OF SUCH DAMAGES. +// In no event shall UV Software's total liability to you for all damages +// exceed the amount paid for this license to the SOFTWARE PRODUCT. The +// entire risk arising out of use or performance of the SOFTWARE PRODUCT +// remains with you. +// +#if defined(__APPLE__) +#include "PCBUSB.h" +#define CAN_LIBRARY "libPCBUSB.dylib" +#else +#include "PCANBasic.h" +#define CAN_LIBRARY "libpcanbasic.so" +#endif +#include +#include +#include +#include + +typedef TPCANStatus (*CAN_Initialize_t)(TPCANHandle Channel, TPCANBaudrate Btr0Btr1, TPCANType HwType, DWORD IOPort, WORD Interrupt); +typedef TPCANStatus (*CAN_Uninitialize_t)(TPCANHandle Channel); +typedef TPCANStatus (*CAN_Reset_t)(TPCANHandle Channel); +typedef TPCANStatus (*CAN_GetStatus_t)(TPCANHandle Channel); +typedef TPCANStatus (*CAN_Read_t)(TPCANHandle Channel, TPCANMsg* MessageBuffer, TPCANTimestamp* TimestampBuffer); +typedef TPCANStatus (*CAN_Write_t)(TPCANHandle Channel, TPCANMsg* MessageBuffer); +typedef TPCANStatus (*CAN_FilterMessages_t)(TPCANHandle Channel, DWORD FromID, DWORD ToID, TPCANMode Mode); +typedef TPCANStatus (*CAN_GetValue_t)(TPCANHandle Channel, TPCANParameter Parameter, void* Buffer, DWORD BufferLength); +typedef TPCANStatus (*CAN_SetValue_t)(TPCANHandle Channel, TPCANParameter Parameter, void* Buffer, DWORD BufferLength); +typedef TPCANStatus (*CAN_GetErrorText_t)(TPCANStatus Error, WORD Language, char* Buffer); +typedef TPCANStatus (*CAN_InitializeFD_t)(TPCANHandle Channel, TPCANBitrateFD BitrateFD); +typedef TPCANStatus (*CAN_ReadFD_t)(TPCANHandle Channel, TPCANMsgFD* MessageBuffer, TPCANTimestampFD* TimestampBuffer); +typedef TPCANStatus (*CAN_WriteFD_t)(TPCANHandle Channel, TPCANMsgFD* MessageBuffer); +typedef TPCANStatus (*CAN_LookUpChannel_t)(LPSTR Parameters, TPCANHandle* FoundChannel); + +static CAN_Initialize_t fpCAN_Initialize = NULL; +static CAN_Uninitialize_t fpCAN_Uninitialize = NULL; +static CAN_Reset_t fpCAN_Reset = NULL; +static CAN_GetStatus_t fpCAN_GetStatus = NULL; +static CAN_Read_t fpCAN_Read = NULL; +static CAN_Write_t fpCAN_Write = NULL; +static CAN_FilterMessages_t fpCAN_FilterMessages = NULL; +static CAN_GetValue_t fpCAN_GetValue = NULL; +static CAN_SetValue_t fpCAN_SetValue = NULL; +static CAN_GetErrorText_t fpCAN_GetErrorText = NULL; +static CAN_InitializeFD_t fpCAN_InitializeFD = NULL; +static CAN_ReadFD_t fpCAN_ReadFD = NULL; +static CAN_WriteFD_t fpCAN_WriteFD = NULL; +static CAN_LookUpChannel_t fpCAN_LookUpChannel = NULL; + +static void *hLibrary = NULL; + +static int LoadLibrary(void) { + if (!hLibrary) { + errno = 0; + hLibrary = dlopen(CAN_LIBRARY, RTLD_LAZY); + if (!hLibrary) + return -1; + if ((fpCAN_Initialize = (CAN_Initialize_t)dlsym(hLibrary, "CAN_Initialize")) == NULL) + goto err; + if ((fpCAN_Uninitialize = (CAN_Uninitialize_t)dlsym(hLibrary, "CAN_Uninitialize")) == NULL) + goto err; + if ((fpCAN_Reset = (CAN_Reset_t)dlsym(hLibrary, "CAN_Reset")) == NULL) + goto err; + if ((fpCAN_GetStatus = (CAN_GetStatus_t)dlsym(hLibrary, "CAN_GetStatus")) == NULL) + goto err; + if ((fpCAN_Read = (CAN_Read_t)dlsym(hLibrary, "CAN_Read")) == NULL) + goto err; + if ((fpCAN_Write = (CAN_Write_t)dlsym(hLibrary, "CAN_Write")) == NULL) + goto err; + if ((fpCAN_FilterMessages = (CAN_FilterMessages_t)dlsym(hLibrary, "CAN_FilterMessages")) == NULL) + goto err; + if ((fpCAN_GetValue = (CAN_GetValue_t)dlsym(hLibrary, "CAN_GetValue")) == NULL) + goto err; + if ((fpCAN_SetValue = (CAN_SetValue_t)dlsym(hLibrary, "CAN_SetValue")) == NULL) + goto err; + if ((fpCAN_GetErrorText = (CAN_GetErrorText_t)dlsym(hLibrary, "CAN_GetErrorText")) == NULL) + goto err; + if ((fpCAN_InitializeFD = (CAN_InitializeFD_t)dlsym(hLibrary, "CAN_InitializeFD")) == NULL) + goto err; + if ((fpCAN_ReadFD = (CAN_ReadFD_t)dlsym(hLibrary, "CAN_ReadFD")) == NULL) + goto err; + if ((fpCAN_WriteFD = (CAN_WriteFD_t)dlsym(hLibrary, "CAN_WriteFD")) == NULL) + goto err; + if ((fpCAN_LookUpChannel = (CAN_LookUpChannel_t)dlsym(hLibrary, "CAN_LookUpChannel")) == NULL) + fpCAN_LookUpChannel = NULL; // New function w/o implementation: accept the NULL pointer! + } + return 0; +err: + fpCAN_Initialize = NULL; + fpCAN_Uninitialize = NULL; + fpCAN_Reset = NULL; + fpCAN_GetStatus = NULL; + fpCAN_Read = NULL; + fpCAN_Write = NULL; + fpCAN_FilterMessages = NULL; + fpCAN_GetValue = NULL; + fpCAN_SetValue = NULL; + fpCAN_GetErrorText = NULL; +#ifndef CAN_2_0_ONLY + fpCAN_InitializeFD = NULL; + fpCAN_ReadFD = NULL; + fpCAN_WriteFD = NULL; +#endif + fpCAN_LookUpChannel = NULL; + dlclose(hLibrary); + hLibrary = NULL; + return -1; +} + +TPCANStatus CAN_Initialize(TPCANHandle Channel, TPCANBaudrate Btr0Btr1, TPCANType HwType, DWORD IOPort, WORD Interrupt) { + if (LoadLibrary() != 0) + return PCAN_ERROR_NODRIVER; + if (fpCAN_Initialize) + return fpCAN_Initialize(Channel, Btr0Btr1, HwType, IOPort, Interrupt); + else + return PCAN_ERROR_UNKNOWN; +} + +TPCANStatus CAN_Uninitialize(TPCANHandle Channel) { + //if (LoadLibrary() != 0) + // return PCAN_ERROR_NODRIVER; + if (fpCAN_Uninitialize) + return fpCAN_Uninitialize(Channel); + else + return PCAN_ERROR_UNKNOWN; +} + +TPCANStatus CAN_Reset(TPCANHandle Channel) { + if (LoadLibrary() != 0) + return PCAN_ERROR_NODRIVER; + if (fpCAN_Reset) + return fpCAN_Reset(Channel); + else + return PCAN_ERROR_UNKNOWN; +} + +TPCANStatus CAN_GetStatus(TPCANHandle Channel) { + if (LoadLibrary() != 0) + return PCAN_ERROR_NODRIVER; + if (fpCAN_GetStatus) + return fpCAN_GetStatus(Channel); + else + return PCAN_ERROR_UNKNOWN; +} + +TPCANStatus CAN_Read(TPCANHandle Channel, TPCANMsg* MessageBuffer, TPCANTimestamp* TimestampBuffer) { + if (LoadLibrary() != 0) + return PCAN_ERROR_NODRIVER; + if (fpCAN_Read) + return fpCAN_Read(Channel, MessageBuffer, TimestampBuffer); + else + return PCAN_ERROR_UNKNOWN; +} + +TPCANStatus CAN_Write(TPCANHandle Channel, TPCANMsg* MessageBuffer) { + if (LoadLibrary() != 0) + return PCAN_ERROR_NODRIVER; + if (fpCAN_Write) + return fpCAN_Write(Channel, MessageBuffer); + else + return PCAN_ERROR_UNKNOWN; +} + +TPCANStatus CAN_FilterMessages(TPCANHandle Channel, DWORD FromID, DWORD ToID, TPCANMode Mode) { + if (LoadLibrary() != 0) + return PCAN_ERROR_NODRIVER; + if (fpCAN_FilterMessages) + return fpCAN_FilterMessages(Channel, FromID, ToID, Mode); + else + return PCAN_ERROR_UNKNOWN; +} + +TPCANStatus CAN_GetValue(TPCANHandle Channel, TPCANParameter Parameter, void* Buffer, DWORD BufferLength) { + if (LoadLibrary() != 0) + return PCAN_ERROR_NODRIVER; + if (fpCAN_GetValue) + return fpCAN_GetValue(Channel, Parameter, Buffer, BufferLength); + else + return PCAN_ERROR_UNKNOWN; +} + +TPCANStatus CAN_SetValue(TPCANHandle Channel, TPCANParameter Parameter, void* Buffer, DWORD BufferLength) { + if (LoadLibrary() != 0) + return PCAN_ERROR_NODRIVER; + if (fpCAN_SetValue) + return fpCAN_SetValue(Channel, Parameter, Buffer, BufferLength); + else + return PCAN_ERROR_UNKNOWN; +} + +TPCANStatus CAN_GetErrorText(TPCANStatus Error, WORD Language, char* Buffer) { + if (LoadLibrary() != 0) { + if (Buffer) + strcpy(Buffer, "PCBUSB library could not be loaded"); + return PCAN_ERROR_NODRIVER; + } + if (fpCAN_GetErrorText) + return fpCAN_GetErrorText(Error, Language, Buffer); + else + return PCAN_ERROR_UNKNOWN; +} + +TPCANStatus CAN_InitializeFD(TPCANHandle Channel, TPCANBitrateFD BitrateFD) { + if (LoadLibrary() != 0) + return PCAN_ERROR_NODRIVER; + if (fpCAN_InitializeFD) + return fpCAN_InitializeFD(Channel, BitrateFD); + else + return PCAN_ERROR_UNKNOWN; +} + +TPCANStatus CAN_ReadFD(TPCANHandle Channel, TPCANMsgFD* MessageBuffer, TPCANTimestampFD* TimestampBuffer) { + if (LoadLibrary() != 0) + return PCAN_ERROR_NODRIVER; + if (fpCAN_ReadFD) + return fpCAN_ReadFD(Channel, MessageBuffer, TimestampBuffer); + else + return PCAN_ERROR_UNKNOWN; +} + +TPCANStatus CAN_WriteFD(TPCANHandle Channel, TPCANMsgFD* MessageBuffer) { + if (LoadLibrary() != 0) + return PCAN_ERROR_NODRIVER; + if (fpCAN_WriteFD) + return fpCAN_WriteFD(Channel, MessageBuffer); + else + return PCAN_ERROR_UNKNOWN; +} + +TPCANStatus CAN_LookUpChannel(LPSTR Parameters, TPCANHandle* FoundChannel) { + if (LoadLibrary() != 0) + return PCAN_ERROR_NODRIVER; + if (fpCAN_LookUpChannel) + return fpCAN_LookUpChannel(Parameters, FoundChannel); + else + return PCAN_ERROR_UNKNOWN; +} diff --git a/Utilities/PCBUSB.h b/Utilities/PCBUSB.h new file mode 100644 index 0000000..8bf3ce9 --- /dev/null +++ b/Utilities/PCBUSB.h @@ -0,0 +1,600 @@ +/* -- $HeadURL: https://uv-software.net/MacCAN/PCANUSB/Library/trunk/drv/pcan_api.h $ -- + * + * project : CAN - Controller Area Network + * + * purpose : PCAN Application Programming Interface + * + * copyright : (C) 2012-2023 by UV Software, Berlin + * + * compiler : Apple clang version 15.0.0 (clang-1500.0.40.1) + * + * export : TPCANStatus CAN_Initialize(TPCANHandle Channel, TPCANBaudrate Btr0Btr1, TPCANType HwType, DWORD IOPort, WORD Interrupt); + * TPCANStatus CAN_Uninitialize(TPCANHandle Channel); + * TPCANStatus CAN_Reset(TPCANHandle Channel); + * TPCANStatus CAN_GetStatus(TPCANHandle Channel); + * TPCANStatus CAN_Read(TPCANHandle Channel, TPCANMsg* MessageBuffer, TPCANTimestamp* TimestampBuffer); + * TPCANStatus CAN_Write(TPCANHandle Channel, TPCANMsg* MessageBuffer); + * TPCANStatus CAN_FilterMessages(TPCANHandle Channel, DWORD FromID, DWORD ToID, TPCANMode Mode); + * TPCANStatus CAN_GetValue(TPCANHandle Channel, TPCANParameter Parameter, void* Buffer, DWORD BufferLength); + * TPCANStatus CAN_SetValue(TPCANHandle Channel, TPCANParameter Parameter, void* Buffer, DWORD BufferLength); + * TPCANStatus CAN_GetErrorText(TPCANStatus Error, WORD Language, LPSTR Buffer); + * *** CAN FD capable devices *** + * TPCANStatus CAN_InitializeFD(TPCANHandle Channel, TPCANBitrateFD BitrateFD); + * TPCANStatus CAN_ReadFD(TPCANHandle Channel, TPCANMsgFD* MessageBuffer, TPCANTimestampFD* TimestampBuffer); + * TPCANStatus CAN_WriteFD(TPCANHandle Channel, TPCANMsgFD* MessageBuffer); + * + * includes : (none) + * + * author : Uwe Vogt, UV Software + * + * e-mail : uwe.vogt@uv-software.de + * + * + * ----------- description -------------------------------------------- + * + * PCAN API - PEAK CAN Application Programming Interface + * + * This Application Programming Interface (API) is an almost compatible + * implementation of the PEAK PCANBasic DLL on macOS (x86_64 and arm64). + * + * Supported CAN Interfaces: + * - PCAN-USB (item no. IPEH-002021/002022) + * - PCAN-USB FD (item no. IPEH-004022) + * Up to 8 channel handles are supported. + * + * Version of PCAN API: + * - Based on PEAK's version of 2023-08-28 + */ + +#ifndef PCAN_API_H_INCLUDED +#define PCAN_API_H_INCLUDED + +/* ----------- includes ----------------------------------------------- + */ + +#ifdef __APPLE__ +#include // To map Windows integer types +#endif + +/* ----------- defines ------------------------------------------------ + */ + +#ifdef __APPLE__ +#ifndef BYTE +#define BYTE UInt8 +#endif +#ifndef WORD +#define WORD UInt16 +#endif +#ifndef DWORD +#define DWORD UInt32 +#endif +#ifndef UINT64 +#define UINT64 UInt64 +#endif +#ifndef LPSTR +#define LPSTR char* +#endif +#define __T(s) s +#endif + +/* Currently defined and supported PCAN channels + */ +#define PCAN_NONEBUS 0x00U //!< Undefined/default value for a PCAN bus + +#define PCAN_USBBUS1 0x51U //!< PCAN-USB interface, channel 1 +#define PCAN_USBBUS2 0x52U //!< PCAN-USB interface, channel 2 +#define PCAN_USBBUS3 0x53U //!< PCAN-USB interface, channel 3 +#define PCAN_USBBUS4 0x54U //!< PCAN-USB interface, channel 4 +#define PCAN_USBBUS5 0x55U //!< PCAN-USB interface, channel 5 +#define PCAN_USBBUS6 0x56U //!< PCAN-USB interface, channel 6 +#define PCAN_USBBUS7 0x57U //!< PCAN-USB interface, channel 7 +#define PCAN_USBBUS8 0x58U //!< PCAN-USB interface, channel 8 +#ifndef __APPLE__ +#define PCAN_USBBUS9 0x509U //!< PCAN-USB interface, channel 9 +#define PCAN_USBBUS10 0x50AU //!< PCAN-USB interface, channel 10 +#define PCAN_USBBUS11 0x50BU //!< PCAN-USB interface, channel 11 +#define PCAN_USBBUS12 0x50CU //!< PCAN-USB interface, channel 12 +#define PCAN_USBBUS13 0x50DU //!< PCAN-USB interface, channel 13 +#define PCAN_USBBUS14 0x50EU //!< PCAN-USB interface, channel 14 +#define PCAN_USBBUS15 0x50FU //!< PCAN-USB interface, channel 15 +#define PCAN_USBBUS16 0x510U //!< PCAN-USB interface, channel 16 +#endif + + +/* Represent the PCAN error and status codes + */ +#define PCAN_ERROR_OK 0x00000U //!< No error +#define PCAN_ERROR_XMTFULL 0x00001U //!< Transmit buffer in CAN controller is full +#define PCAN_ERROR_OVERRUN 0x00002U //!< CAN controller was read too late +#define PCAN_ERROR_BUSLIGHT 0x00004U //!< Bus error: an error counter reached the 'light' limit +#define PCAN_ERROR_BUSHEAVY 0x00008U //!< Bus error: an error counter reached the 'heavy' limit +#define PCAN_ERROR_BUSWARNING PCAN_ERROR_BUSHEAVY //!< Bus error: an error counter reached the 'warning' limit +#define PCAN_ERROR_BUSPASSIVE 0x40000U //!< Bus error: the CAN controller is error passive +#define PCAN_ERROR_BUSOFF 0x00010U //!< Bus error: the CAN controller is in bus-off state +#define PCAN_ERROR_ANYBUSERR (PCAN_ERROR_BUSWARNING | PCAN_ERROR_BUSLIGHT | PCAN_ERROR_BUSHEAVY | PCAN_ERROR_BUSOFF | PCAN_ERROR_BUSPASSIVE) //!< Mask for all bus errors +#define PCAN_ERROR_QRCVEMPTY 0x00020U //!< Receive queue is empty +#define PCAN_ERROR_QOVERRUN 0x00040U //!< Receive queue was read too late +#define PCAN_ERROR_QXMTFULL 0x00080U //!< Transmit queue is full +#define PCAN_ERROR_REGTEST 0x00100U //!< Test of the CAN controller hardware registers failed (no hardware found) +#define PCAN_ERROR_NODRIVER 0x00200U //!< Driver not loaded +#define PCAN_ERROR_HWINUSE 0x00400U //!< Hardware already in use by a Net +#define PCAN_ERROR_NETINUSE 0x00800U //!< A Client is already connected to the Net +#define PCAN_ERROR_ILLHW 0x01400U //!< Hardware handle is invalid +#define PCAN_ERROR_ILLNET 0x01800U //!< Net handle is invalid +#define PCAN_ERROR_ILLCLIENT 0x01C00U //!< Client handle is invalid +#define PCAN_ERROR_ILLHANDLE (PCAN_ERROR_ILLHW | PCAN_ERROR_ILLNET | PCAN_ERROR_ILLCLIENT) //!< Mask for all handle errors +#define PCAN_ERROR_RESOURCE 0x02000U //!< Resource (FIFO, Client, timeout) cannot be created +#define PCAN_ERROR_ILLPARAMTYPE 0x04000U //!< Invalid parameter +#define PCAN_ERROR_ILLPARAMVAL 0x08000U //!< Invalid parameter value +#define PCAN_ERROR_UNKNOWN 0x10000U //!< Unknown error +#define PCAN_ERROR_ILLDATA 0x20000U //!< Invalid data, function, or action +#define PCAN_ERROR_ILLMODE 0x80000U //!< Driver object state is wrong for the attempted operation +#define PCAN_ERROR_CAUTION 0x2000000U //!< An operation was successfully carried out, however, irregularities were registered +#define PCAN_ERROR_INITIALIZE 0x4000000U //!< Channel is not initialized [Value was changed from 0x40000 to 0x4000000] +#define PCAN_ERROR_ILLOPERATION 0x8000000U //!< Invalid operation [Value was changed from 0x80000 to 0x8000000] + +/* PCAN devices + */ +#define PCAN_NONE 0x00U //!< Undefined, unknown or not selected PCAN device value +#define PCAN_PEAKCAN 0x01U //!< PCAN Non-PnP devices. NOT USED WITHIN PCAN-Basic API +#define PCAN_ISA 0x02U //!< PCAN-ISA, PCAN-PC/104, and PCAN-PC/104-Plus +#define PCAN_DNG 0x03U //!< PCAN-Dongle +#define PCAN_PCI 0x04U //!< PCAN-PCI, PCAN-cPCI, PCAN-miniPCI, and PCAN-PCI Express +#define PCAN_USB 0x05U //!< PCAN-USB and PCAN-USB Pro +#define PCAN_PCC 0x06U //!< PCAN-PC Card +#define PCAN_VIRTUAL 0x07U //!< PCAN Virtual hardware. NOT USED WITHIN PCAN-Basic API +#define PCAN_LAN 0x08U //!< PCAN Gateway devices + +/* PCAN parameters + */ +#define PCAN_DEVICE_ID 0x01U //!< Device identifier parameter +#define PCAN_5VOLTS_POWER 0x02U //!< 5-Volt power parameter +#define PCAN_RECEIVE_EVENT 0x03U //!< PCAN receive event handler parameter +#define PCAN_MESSAGE_FILTER 0x04U //!< PCAN message filter parameter +#define PCAN_API_VERSION 0x05U //!< PCAN-Basic API version parameter +#define PCAN_CHANNEL_VERSION 0x06U //!< PCAN device channel version parameter +#define PCAN_BUSOFF_AUTORESET 0x07U //!< PCAN Reset-On-Busoff parameter +#define PCAN_LISTEN_ONLY 0x08U //!< PCAN Listen-Only parameter +#define PCAN_LOG_LOCATION 0x09U //!< Directory path for log files +#define PCAN_LOG_STATUS 0x0AU //!< Debug-Log activation status +#define PCAN_LOG_CONFIGURE 0x0BU //!< Configuration of the debugged information (LOG_FUNCTION_***) +#define PCAN_LOG_TEXT 0x0CU //!< Custom insertion of text into the log file +#define PCAN_CHANNEL_CONDITION 0x0DU //!< Availability status of a PCAN-Channel +#define PCAN_HARDWARE_NAME 0x0EU //!< PCAN hardware name parameter +#define PCAN_RECEIVE_STATUS 0x0FU //!< Message reception status of a PCAN-Channel +#define PCAN_CONTROLLER_NUMBER 0x10U //!< CAN-Controller number of a PCAN-Channel +#define PCAN_TRACE_LOCATION 0x11U //!< Directory path for PCAN trace files +#define PCAN_TRACE_STATUS 0x12U //!< CAN tracing activation status +#define PCAN_TRACE_SIZE 0x13U //!< Configuration of the maximum file size of a CAN trace +#define PCAN_TRACE_CONFIGURE 0x14U //!< Configuration of the trace file storing mode (TRACE_FILE_***) +#define PCAN_CHANNEL_IDENTIFYING 0x15U //!< Physical identification of a USB based PCAN-Channel by blinking its associated LED +#define PCAN_CHANNEL_FEATURES 0x16U //!< Capabilities of a PCAN device (FEATURE_***) +#define PCAN_BITRATE_ADAPTING 0x17U //!< Using of an existing bit rate (PCAN-View connected to a channel) +#define PCAN_BITRATE_INFO 0x18U //!< Configured bit rate as Btr0Btr1 value +#define PCAN_BITRATE_INFO_FD 0x19U //!< Configured bit rate as TPCANBitrateFD string +#define PCAN_BUSSPEED_NOMINAL 0x1AU //!< Configured nominal CAN Bus speed as Bits per seconds +#define PCAN_BUSSPEED_DATA 0x1BU //!< Configured CAN data speed as Bits per seconds +#define PCAN_IP_ADDRESS 0x1CU //!< Remote address of a LAN channel as string in IPv4 format +#define PCAN_LAN_SERVICE_STATUS 0x1DU //!< Status of the Virtual PCAN-Gateway Service +#define PCAN_ALLOW_STATUS_FRAMES 0x1EU //!< Status messages reception status within a PCAN-Channel +#define PCAN_ALLOW_RTR_FRAMES 0x1FU //!< RTR messages reception status within a PCAN-Channel +#define PCAN_ALLOW_ERROR_FRAMES 0x20U //!< Error messages reception status within a PCAN-Channel +#define PCAN_INTERFRAME_DELAY 0x21U //!< Delay, in microseconds, between sending frames +#define PCAN_ACCEPTANCE_FILTER_11BIT 0x22U //!< Filter over code and mask patterns for 11-Bit messages +#define PCAN_ACCEPTANCE_FILTER_29BIT 0x23U //!< Filter over code and mask patterns for 29-Bit messages +#define PCAN_IO_DIGITAL_CONFIGURATION 0x24U //!< Output mode of 32 digital I/O pin of a PCAN-USB Chip. 1: Output-Active 0 : Output Inactive +#define PCAN_IO_DIGITAL_VALUE 0x25U //!< Value assigned to a 32 digital I/O pins of a PCAN-USB Chip +#define PCAN_IO_DIGITAL_SET 0x26U //!< Value assigned to a 32 digital I/O pins of a PCAN-USB Chip - Multiple digital I/O pins to 1 = High +#define PCAN_IO_DIGITAL_CLEAR 0x27U //!< Clear multiple digital I/O pins to 0 +#define PCAN_IO_ANALOG_VALUE 0x28U //!< Get value of a single analog input pin +#define PCAN_FIRMWARE_VERSION 0x29U //!< Get the version of the firmware used by the device associated with a PCAN-Channel +#define PCAN_ATTACHED_CHANNELS_COUNT 0x2AU //!< Get the amount of PCAN channels attached to a system +#define PCAN_ATTACHED_CHANNELS 0x2BU //!< Get information about PCAN channels attached to a system +#define PCAN_ALLOW_ECHO_FRAMES 0x2CU //!< Echo messages reception status within a PCAN-Channel +#define PCAN_DEVICE_PART_NUMBER 0x2DU //!< Get the part number associated to a device +#define PCAN_HARD_RESET_STATUS 0x2EU //!< Activation status of hard reset processing via CAN_Reset calls +#define PCAN_EXT_BTR0BTR1 0x80U //!< UVS: bit-timing register +#define PCAN_EXT_TX_COUNTER 0x81U //!< UVS: number of transmitted frames +#define PCAN_EXT_RX_COUNTER 0x82U //!< UVS: number of received frames +#define PCAN_EXT_ERR_COUNTER 0x83U //!< UVS: number of error frames +#define PCAN_EXT_RX_QUE_OVERRUN 0x84U //!< UVS: receive queue overrun counter +#define PCAN_EXT_HARDWARE_VERSION 0x85U //!< UVS: version number of the interface firmware +#define PCAN_EXT_SOFTWARE_VERSION 0x86U //!< UVS: version number of the driver respectively library +#define PCAN_EXT_RECEIVE_CALLBACK 0x87U //!< UVS: callback function called on the reception of an URB +#define PCAN_EXT_LOG_USB 0x8FU //!< UVS: Log USB communication (URB buffer <==> CAN messages) + +/* DEPRECATED parameters + */ +#define PCAN_DEVICE_NUMBER PCAN_DEVICE_ID //!< Deprecated parameter. Use PCAN_DEVICE_ID instead + +/* PCAN parameter values + */ +#define PCAN_PARAMETER_OFF 0x00U //!< The PCAN parameter is not set (inactive) +#define PCAN_PARAMETER_ON 0x01U //!< The PCAN parameter is set (active) +#define PCAN_FILTER_CLOSE 0x00U //!< The PCAN filter is closed. No messages will be received +#define PCAN_FILTER_OPEN 0x01U //!< The PCAN filter is fully opened. All messages will be received +#define PCAN_FILTER_CUSTOM 0x02U //!< The PCAN filter is custom configured. Only registered messages will be received +#define PCAN_CHANNEL_UNAVAILABLE 0x00U //!< The PCAN-Channel handle is illegal, or its associated hardware is not available +#define PCAN_CHANNEL_AVAILABLE 0x01U //!< The PCAN-Channel handle is available to be connected (PnP Hardware: it means furthermore that the hardware is plugged-in) +#define PCAN_CHANNEL_OCCUPIED 0x02U //!< The PCAN-Channel handle is valid, and is already being used +#define PCAN_CHANNEL_PCANVIEW (PCAN_CHANNEL_AVAILABLE | PCAN_CHANNEL_OCCUPIED) //!< The PCAN-Channel handle is already being used by a PCAN-View application, but is available to connect + +#define LOG_FUNCTION_DEFAULT 0x00U //!< Logs system exceptions / errors +#define LOG_FUNCTION_ENTRY 0x01U //!< Logs the entries to the PCAN-Basic API functions +#define LOG_FUNCTION_PARAMETERS 0x02U //!< Logs the parameters passed to the PCAN-Basic API functions +#define LOG_FUNCTION_LEAVE 0x04U //!< Logs the exits from the PCAN-Basic API functions +#define LOG_FUNCTION_WRITE 0x08U //!< Logs the CAN messages passed to the CAN_Write function +#define LOG_FUNCTION_READ 0x10U //!< Logs the CAN messages received within the CAN_Read function +#define LOG_FUNCTION_ALL 0xFFFFU //!< Logs all possible information within the PCAN-Basic API functions + +#define TRACE_FILE_SINGLE 0x00U //!< A single file is written until it size reaches PAN_TRACE_SIZE +#define TRACE_FILE_SEGMENTED 0x01U //!< Traced data is distributed in several files with size PAN_TRACE_SIZE +#define TRACE_FILE_DATE 0x02U //!< Includes the date into the name of the trace file +#define TRACE_FILE_TIME 0x04U //!< Includes the start time into the name of the trace file +#define TRACE_FILE_OVERWRITE 0x80U //!< Causes the overwriting of available traces (same name) +#define TRACE_FILE_DATA_LENGTH 0x100U //!< Causes using the data length column ('l') instead of the DLC column ('L') in the trace file + +#define FEATURE_FD_CAPABLE 0x01U //!< Device supports flexible data-rate (CAN-FD) +#define FEATURE_DELAY_CAPABLE 0x02U //!< Device supports a delay between sending frames (FPGA based USB devices) +#define FEATURE_IO_CAPABLE 0x04U //!< Device supports I/O functionality for electronic circuits (USB-Chip devices) + +#define SERVICE_STATUS_STOPPED 0x01U //!< The service is not running +#define SERVICE_STATUS_RUNNING 0x04U //!< The service is running + +/* Other constants + */ +#define MAX_LENGTH_HARDWARE_NAME 33 //!< Maximum length of the name of a device: 32 characters + terminator +#define MAX_LENGTH_VERSION_STRING 256 //!< Maximum length of a version string: 255 characters + terminator + +/* PCAN message types + */ +#define PCAN_MESSAGE_STANDARD 0x00U //!< The PCAN message is a CAN Standard Frame (11-bit identifier) +#define PCAN_MESSAGE_RTR 0x01U //!< The PCAN message is a CAN Remote-Transfer-Request Frame +#define PCAN_MESSAGE_EXTENDED 0x02U //!< The PCAN message is a CAN Extended Frame (29-bit identifier) +#define PCAN_MESSAGE_FD 0x04U //!< The PCAN message represents a FD frame in terms of CiA Specs +#define PCAN_MESSAGE_BRS 0x08U //!< The PCAN message represents a FD bit rate switch (CAN data at a higher bit rate) +#define PCAN_MESSAGE_ESI 0x10U //!< The PCAN message represents a FD error state indicator(CAN FD transmitter was error active) +#define PCAN_MESSAGE_ECHO 0x20U //!< The PCAN message represents an echo CAN Frame +#define PCAN_MESSAGE_ERRFRAME 0x40U //!< The PCAN message represents an error frame +#define PCAN_MESSAGE_STATUS 0x80U //!< The PCAN message represents a PCAN status message + +/* LookUp Parameters + */ +#define LOOKUP_DEVICE_TYPE __T("devicetype") //!< Lookup channel by Device type (see PCAN devices e.g. PCAN_USB) +#define LOOKUP_DEVICE_ID __T("deviceid") //!< Lookup channel by device id +#define LOOKUP_CONTROLLER_NUMBER __T("controllernumber") //!< Lookup channel by CAN controller 0-based index +#define LOOKUP_IP_ADDRESS __T("ipaddress") //!< Lookup channel by IP address (LAN channels only) + +/* Frame Type / Initialization Mode + */ +#define PCAN_MODE_STANDARD PCAN_MESSAGE_STANDARD +#define PCAN_MODE_EXTENDED PCAN_MESSAGE_EXTENDED + +/* Baud rate codes = BTR0/BTR1 register values for the CAN controller. + * You can define your own Baud rate with the BTROBTR1 register. + * Take a look at www.peak-system.com for their free software "BAUDTOOL" + * to calculate the BTROBTR1 register for every bit rate and sample point. + */ +#define PCAN_BAUD_1M 0x0014U //!< 1 MBit/s +#define PCAN_BAUD_800K 0x0016U //!< 800 kBit/s +#define PCAN_BAUD_500K 0x001CU //!< 500 kBit/s +#define PCAN_BAUD_250K 0x011CU //!< 250 kBit/s +#define PCAN_BAUD_125K 0x031CU //!< 125 kBit/s +#define PCAN_BAUD_100K 0x432FU //!< 100 kBit/s +#define PCAN_BAUD_95K 0xC34EU //!< 95,238 kBit/s +#define PCAN_BAUD_83K 0x852BU //!< 83,333 kBit/s +#define PCAN_BAUD_50K 0x472FU //!< 50 kBit/s +#define PCAN_BAUD_47K 0x1414U //!< 47,619 kBit/s +#define PCAN_BAUD_33K 0x8B2FU //!< 33,333 kBit/s +#define PCAN_BAUD_20K 0x532FU //!< 20 kBit/s +#define PCAN_BAUD_10K 0x672FU //!< 10 kBit/s +#define PCAN_BAUD_5K 0x7F7FU //!< 5 kBit/s + +/* Represents the configuration for a CAN bit rate + * Note: + * * Each parameter and its value must be separated with a '='. + * * Each pair of parameter/value must be separated using ','. + * + * Example: + * f_clock=80000000,nom_brp=10,nom_tseg1=5,nom_tseg2=2,nom_sjw=1,data_brp=4,data_tseg1=7,data_tseg2=2,data_sjw=1 + */ +#define PCAN_BR_CLOCK __T("f_clock") +#define PCAN_BR_CLOCK_MHZ __T("f_clock_mhz") +#define PCAN_BR_NOM_BRP __T("nom_brp") +#define PCAN_BR_NOM_TSEG1 __T("nom_tseg1") +#define PCAN_BR_NOM_TSEG2 __T("nom_tseg2") +#define PCAN_BR_NOM_SJW __T("nom_sjw") +#define PCAN_BR_NOM_SAMPLE __T("nom_sam") +#define PCAN_BR_DATA_BRP __T("data_brp") +#define PCAN_BR_DATA_TSEG1 __T("data_tseg1") +#define PCAN_BR_DATA_TSEG2 __T("data_tseg2") +#define PCAN_BR_DATA_SJW __T("data_sjw") +#define PCAN_BR_DATA_SAMPLE __T("data_ssp_offset") + +/* ----------- types -------------------------------------------------- + */ + +#define TPCANHandle WORD //!< Represents a PCAN hardware channel handle +#define TPCANStatus DWORD //!< Represents a PCAN status/error code (ATTENTION: changed from 64-bit to 32-bit) +#define TPCANParameter BYTE //!< Represents a PCAN parameter to be read or set +#define TPCANDevice BYTE //!< Represents a PCAN device +#define TPCANMessageType BYTE //!< Represents the type of a PCAN message +#define TPCANType BYTE //!< Represents the type of PCAN hardware to be initialized +#define TPCANMode BYTE //!< Represents a PCAN filter mode +#define TPCANBaudrate WORD //!< Represents a PCAN Baud rate register value +#define TPCANBitrateFD LPSTR //!< Represents a PCAN-FD bit rate string +#define TPCANTimestampFD UINT64//!< Represents a timestamp of a received PCAN FD message + +/** Represents a PCAN message + */ +typedef struct tagTPCANMsg +{ + DWORD ID; //!< 11/29-bit message identifier + TPCANMessageType MSGTYPE; //!< Type of the message + BYTE LEN; //!< Data Length Code of the message (0..8) + BYTE DATA[8]; //!< Data of the message (DATA[0]..DATA[7]) +} TPCANMsg; + +/** Represents a timestamp of a received PCAN message + * Total Microseconds = micros + 1000 * millis + 0x100000000 * 1000 * millis_overflow + */ +typedef struct tagTPCANTimestamp +{ + DWORD millis; //!< Base-value: milliseconds: 0.. 2^32-1 + WORD millis_overflow; //!< Roll-arounds of millis + WORD micros; //!< Microseconds: 0..999 +} TPCANTimestamp; + +/** Represents a PCAN message from a FD capable hardware + */ +typedef struct tagTPCANMsgFD +{ + DWORD ID; //!< 11/29-bit message identifier + TPCANMessageType MSGTYPE; //!< Type of the message + BYTE DLC; //!< Data Length Code of the message (0..15) + BYTE DATA[64];//!< Data of the message (DATA[0]..DATA[63]) +} TPCANMsgFD; + +/** Describes an available PCAN channel + */ +typedef struct tagTPCANChannelInformation +{ + TPCANHandle channel_handle; //!< PCAN channel handle + TPCANDevice device_type; //!< Kind of PCAN device + BYTE controller_number; //!< CAN-Controller number + DWORD device_features; //!< Device capabilities flag (see FEATURE_*) + char device_name[MAX_LENGTH_HARDWARE_NAME]; //!< Device name + DWORD device_id; //!< Device number + DWORD channel_condition; //!< Availability status of a PCAN-Channel +}TPCANChannelInformation; + + +/* ----------- variables ---------------------------------------------- + */ + + +/* ----------- prototypes --------------------------------------------- + */ + +#ifdef __cplusplus +extern "C" { +#define _DEF_ARG =0 +#else +#define _DEF_ARG +#endif + +/** @brief Initializes a PCAN Channel. + * + * @param[in] Channel The handle of a PCAN Channel. + * @param[in] Btr0Btr1 The speed for the communication (BTR0BTR1 code). + * @param[in] HwType (not used with PCAN USB devices) + * @param[in] IOPort (not used with PCAN USB devices) + * @param[in] Interrupt (not used with PCAN USB devices) + * + * @returns A TPCANStatus error code. + */ +TPCANStatus CAN_Initialize( + TPCANHandle Channel, + TPCANBaudrate Btr0Btr1, + TPCANType HwType _DEF_ARG, + DWORD IOPort _DEF_ARG, + WORD Interrupt _DEF_ARG); + +/** @brief Initializes a FD capable PCAN Channel. + * + * @param[in] Channel The handle of a FD capable PCAN Channel. + * @param[in] BitrateFD The speed for the communication (FD bit rate string). + * + * @remarks See PCAN_BR_* values + *
    + *
  • Parameter and values must be separated by '='.
  • + *
  • Couples of Parameter/value must be separated by ','.
  • + *
  • Following Parameter must be filled out: f_clock, nom_brp, nom_sjw, nom_tseg1, nom_tseg2, + * data_brp, data_sjw, data_tseg1, data_tseg2.
  • + *
  • Following Parameters are optional (not used yet): data_ssp_offset, nom_sam.
  • + *
+ * @remarks Example: + * @verbatim + * f_clock=80000000,nom_brp=10,nom_tseg1=5,nom_tseg2=2,nom_sjw=1,data_brp=4,data_tseg1=7,data_tseg2=2,data_sjw=1 + * @endverbatim + * @returns A TPCANStatus error code. + */ +TPCANStatus CAN_InitializeFD( + TPCANHandle Channel, + TPCANBitrateFD BitrateFD); + +/** @brief Uninitializes one or all PCAN Channels initialized by CAN_Initialize + * + * @remarks Giving the TPCANHandle value "PCAN_NONEBUS", uninitializes all initialized channels. + * + * @param[in] Channel The handle of a PCAN Channel. + * + * @returns A TPCANStatus error code. + */ +TPCANStatus CAN_Uninitialize( + TPCANHandle Channel); + +/** @brief Resets the receive and transmit queues of the PCAN Channel. + * + * @remarks A reset of the CAN controller is not performed. + * + * @param[in] Channel The handle of a PCAN Channel. + * + * @returns A TPCANStatus error code. + */ +TPCANStatus CAN_Reset( + TPCANHandle Channel); + +/** @brief Gets the current status of a PCAN Channel. + * + * @param[in] Channel The handle of a PCAN Channel. + * + * @returns A TPCANStatus error code. + */ +TPCANStatus CAN_GetStatus( + TPCANHandle Channel); + +/** @brief Reads a CAN message from the receive queue of a PCAN Channel. + * + * @param[in] Channel The handle of a PCAN Channel. + * @param[out] MessageBuffer A TPCANMsg structure buffer to store the CAN message. + * @param[out] TimestampBuffer A TPCANTimestamp structure buffer to get the reception time of the message. + * If this value is not desired, this parameter should be passed as NULL. + * + * @returns A TPCANStatus error code. + */ +TPCANStatus CAN_Read( + TPCANHandle Channel, + TPCANMsg* MessageBuffer, + TPCANTimestamp* TimestampBuffer); + +/** @brief Reads a CAN message from the receive queue of a FD capable PCAN Channel. + * + * @param[in] Channel The handle of a FD capable PCAN Channel. + * @param[out] MessageBuffer A TPCANMsgFD structure buffer to store the CAN message. + * @param[out] TimestampBuffer A TPCANTimestampFD buffer to get the reception time of the message. + * If this value is not desired, this parameter should be passed as NULL. + * + * @returns A TPCANStatus error code. + */ +TPCANStatus CAN_ReadFD( + TPCANHandle Channel, + TPCANMsgFD* MessageBuffer, + TPCANTimestampFD* TimestampBuffer); + +/** @brief Transmits a CAN message. + * + * @param[in] Channel The handle of a PCAN Channel. + * @param[in] MessageBuffer A TPCANMsg buffer with the message to be sent. + * + * @returns A TPCANStatus error code. + */ +TPCANStatus CAN_Write( + TPCANHandle Channel, + TPCANMsg* MessageBuffer); + +/** @brief Transmits a CAN message over a FD capable PCAN Channel. + * + * @param[in] Channel The handle of a FD capable PCAN Channel. + * @param[in] MessageBuffer A TPCANMsgFD buffer with the message to be sent. + * + * @returns A TPCANStatus error code. + */ +TPCANStatus CAN_WriteFD( + TPCANHandle Channel, + TPCANMsgFD* MessageBuffer); + +/** @brief Configures the reception filter. + * + * @remarks The message filter will be expanded with every call to this function. + * If it is desired to reset the filter, please use the CAN_SetValue function. + * + * @param[in] Channel The handle of a PCAN Channel. + * @param[in] FromID The lowest CAN ID to be received. + * @param[in] ToID The highest CAN ID to be received. + * @param[in] Mode Message type, Standard (11-bit identifier) or Extended (29-bit identifier). + * + * @returns A TPCANStatus error code. + */ +TPCANStatus CAN_FilterMessages( + TPCANHandle Channel, + DWORD FromID, + DWORD ToID, + TPCANMode Mode); + +/** @brief Retrieves a PCAN Channel value. + * + * @remarks Parameters can be present or not according with the kind of Hardware (PCAN Channel) being used. + * If a parameter is not available, a PCAN_ERROR_ILLPARAMTYPE error will be returned. + * + * @param[in] Channel The handle of a PCAN Channel. + * @param[in] Parameter The TPCANParameter parameter to get. + * @param[out] Buffer Buffer for the parameter value. + * @param[in] BufferLength Size in bytes of the buffer. + * + * @returns A TPCANStatus error code. + */ +TPCANStatus CAN_GetValue( + TPCANHandle Channel, + TPCANParameter Parameter, + void* Buffer, + DWORD BufferLength); + + +/** @brief Configures or sets a PCAN Channel value. + * + * @remarks Parameters can be present or not according with the kind of Hardware (PCAN Channel) being used. + * If a parameter is not available, a PCAN_ERROR_ILLPARAMTYPE error will be returned. + * + * @param[in] Channel The handle of a PCAN Channel. + * @param[in] Parameter The TPCANParameter parameter to set. + * @param[in] Buffer Buffer with the value to be set. + * @param[in] BufferLength Size in bytes of the buffer. + * + * @returns A TPCANStatus error code. + */ +TPCANStatus CAN_SetValue( + TPCANHandle Channel, + TPCANParameter Parameter, + void* Buffer, + DWORD BufferLength); + +/** @brief Returns a descriptive text of a given TPCANStatus error code, in any desired language. + * + * @remarks The current languages available for translation are: + * Neutral (0x00), German (0x07), English (0x09), Spanish (0x0A), Italian (0x10) and French (0x0C). + * + * @param[in] Error A TPCANStatus error code. + * @param[in] Language Indicates a 'Primary language ID'. + * @param[out] Buffer Buffer for a null terminated char array. + * + * @returns A TPCANStatus error code. + */ +TPCANStatus CAN_GetErrorText( + TPCANStatus Error, + WORD Language, + LPSTR Buffer); + +/** @brief Finds a PCAN-Basic channel that matches with the given parameters + * + * @param[in] Parameters A comma separated string contained pairs of parameter-name/value + * to be matched within a PCAN-Basic channel + * @param[out] FoundChannel Buffer for returning the PCAN-Basic channel, when found + * + * @returns A TPCANStatus error code. + */ +TPCANStatus CAN_LookUpChannel( + LPSTR Parameters, + TPCANHandle* FoundChannel); + +#ifdef __cplusplus +} +#endif +#endif /* PCAN_API_H_INCLUDED */ + +/* ---------------------------------------------------------------------- + * Uwe Vogt, UV Software, Chausseestrasse 33 A, 10115 Berlin, Germany + * Tel.: +49-30-46799872, Fax: +49-30-46799873, Mobile: +49-170-3801903 + * E-Mail: uwe.vogt@uv-software.de, Homepage: http://www.uv-software.de/ + */ diff --git a/Utilities/build_no.sh b/Utilities/build_no.sh new file mode 100755 index 0000000..facccfc --- /dev/null +++ b/Utilities/build_no.sh @@ -0,0 +1,32 @@ +echo "/* -- Do not commit this file --" > ./build_no.h +echo " *" >> ./build_no.h +echo " * project : CAN - Controller Area Network" >> ./build_no.h +echo " *" >> ./build_no.h +echo " * purpose : CAN Tester (based on macOS Library for PCAN-USB Interfaces)" >> ./build_no.h +echo " *" >> ./build_no.h +echo " * copyright : (C) 2019,2023 UV Software, Berlin" >> ./build_no.h +echo " *" >> ./build_no.h +echo " * author(s) : Uwe Vogt, UV Software" >> ./build_no.h +echo " *" >> ./build_no.h +echo " * e-mail : info@mac-can.com" >> ./build_no.h +echo " *" >> ./build_no.h +echo " */" >> ./build_no.h +echo "#ifndef BUILD_NO_H_INCLUDED" >> ./build_no.h +echo "#define BUILD_NO_H_INCLUDED" >> ./build_no.h +git log -1 --pretty=format:%h > /dev/null 2> /dev/null +if [ $? -eq 0 ] +then + echo "#define BUILD_NO 0x"$(git log -1 --pretty=format:%h) >> ./build_no.h +else + echo "#define BUILD_NO 0xDEADC0DE" >> ./build_no.h +fi +echo "#define STRINGIFY(X) #X" >> ./build_no.h +echo "#define TOSTRING(X) STRINGIFY(X)" >> ./build_no.h +echo "#define SVN_REV_INT (BUILD_NO)" >> ./build_no.h +echo "#define SVN_REV_STR TOSTRING(BUILD_NO)" >> ./build_no.h +echo "#endif" >> ./build_no.h +echo "/* ----------------------------------------------------------------------" >> ./build_no.h +echo " * Uwe Vogt, UV Software, Chausseestrasse 33 A, 10115 Berlin, Germany" >> ./build_no.h +echo " * Tel.: +49-30-46799872, Fax: +49-30-46799873, Mobile: +49-170-3801903" >> ./build_no.h +echo " * E-Mail: uwe.vogt@uv-software.de, Homepage: http://www.uv-software.de/" >> ./build_no.h +echo " */" >> ./build_no.h diff --git a/Utilities/can_moni/.gitignore b/Utilities/can_moni/.gitignore new file mode 100644 index 0000000..b985485 --- /dev/null +++ b/Utilities/can_moni/.gitignore @@ -0,0 +1,11 @@ +# ignore all the old crap from svn +.project +.cproject +build.sh +build_no.h +build_no.sh +deploy.sh +install.sh +LICENSE +COPYRIGHT +IMPORTANT diff --git a/Utilities/can_moni/COPYING b/Utilities/can_moni/COPYING new file mode 100644 index 0000000..9efa6fb --- /dev/null +++ b/Utilities/can_moni/COPYING @@ -0,0 +1,338 @@ + GNU GENERAL PUBLIC LICENSE + Version 2, June 1991 + + Copyright (C) 1989, 1991 Free Software Foundation, Inc., + + Everyone is permitted to copy and distribute verbatim copies + of this license document, but changing it is not allowed. + + Preamble + + The licenses for most software are designed to take away your +freedom to share and change it. By contrast, the GNU General Public +License is intended to guarantee your freedom to share and change free +software--to make sure the software is free for all its users. This +General Public License applies to most of the Free Software +Foundation's software and to any other program whose authors commit to +using it. (Some other Free Software Foundation software is covered by +the GNU Lesser General Public License instead.) You can apply it to +your programs, too. + + When we speak of free software, we are referring to freedom, not +price. Our General Public Licenses are designed to make sure that you +have the freedom to distribute copies of free software (and charge for +this service if you wish), that you receive source code or can get it +if you want it, that you can change the software or use pieces of it +in new free programs; and that you know you can do these things. + + To protect your rights, we need to make restrictions that forbid +anyone to deny you these rights or to ask you to surrender the rights. +These restrictions translate to certain responsibilities for you if you +distribute copies of the software, or if you modify it. + + For example, if you distribute copies of such a program, whether +gratis or for a fee, you must give the recipients all the rights that +you have. You must make sure that they, too, receive or can get the +source code. And you must show them these terms so they know their +rights. + + We protect your rights with two steps: (1) copyright the software, and +(2) offer you this license which gives you legal permission to copy, +distribute and/or modify the software. + + Also, for each author's protection and ours, we want to make certain +that everyone understands that there is no warranty for this free +software. If the software is modified by someone else and passed on, we +want its recipients to know that what they have is not the original, so +that any problems introduced by others will not reflect on the original +authors' reputations. + + Finally, any free program is threatened constantly by software +patents. We wish to avoid the danger that redistributors of a free +program will individually obtain patent licenses, in effect making the +program proprietary. To prevent this, we have made it clear that any +patent must be licensed for everyone's free use or not licensed at all. + + The precise terms and conditions for copying, distribution and +modification follow. + + GNU GENERAL PUBLIC LICENSE + TERMS AND CONDITIONS FOR COPYING, DISTRIBUTION AND MODIFICATION + + 0. This License applies to any program or other work which contains +a notice placed by the copyright holder saying it may be distributed +under the terms of this General Public License. The "Program", below, +refers to any such program or work, and a "work based on the Program" +means either the Program or any derivative work under copyright law: +that is to say, a work containing the Program or a portion of it, +either verbatim or with modifications and/or translated into another +language. (Hereinafter, translation is included without limitation in +the term "modification".) Each licensee is addressed as "you". + +Activities other than copying, distribution and modification are not +covered by this License; they are outside its scope. The act of +running the Program is not restricted, and the output from the Program +is covered only if its contents constitute a work based on the +Program (independent of having been made by running the Program). +Whether that is true depends on what the Program does. + + 1. You may copy and distribute verbatim copies of the Program's +source code as you receive it, in any medium, provided that you +conspicuously and appropriately publish on each copy an appropriate +copyright notice and disclaimer of warranty; keep intact all the +notices that refer to this License and to the absence of any warranty; +and give any other recipients of the Program a copy of this License +along with the Program. + +You may charge a fee for the physical act of transferring a copy, and +you may at your option offer warranty protection in exchange for a fee. + + 2. You may modify your copy or copies of the Program or any portion +of it, thus forming a work based on the Program, and copy and +distribute such modifications or work under the terms of Section 1 +above, provided that you also meet all of these conditions: + + a) You must cause the modified files to carry prominent notices + stating that you changed the files and the date of any change. + + b) You must cause any work that you distribute or publish, that in + whole or in part contains or is derived from the Program or any + part thereof, to be licensed as a whole at no charge to all third + parties under the terms of this License. + + c) If the modified program normally reads commands interactively + when run, you must cause it, when started running for such + interactive use in the most ordinary way, to print or display an + announcement including an appropriate copyright notice and a + notice that there is no warranty (or else, saying that you provide + a warranty) and that users may redistribute the program under + these conditions, and telling the user how to view a copy of this + License. (Exception: if the Program itself is interactive but + does not normally print such an announcement, your work based on + the Program is not required to print an announcement.) + +These requirements apply to the modified work as a whole. If +identifiable sections of that work are not derived from the Program, +and can be reasonably considered independent and separate works in +themselves, then this License, and its terms, do not apply to those +sections when you distribute them as separate works. But when you +distribute the same sections as part of a whole which is a work based +on the Program, the distribution of the whole must be on the terms of +this License, whose permissions for other licensees extend to the +entire whole, and thus to each and every part regardless of who wrote it. + +Thus, it is not the intent of this section to claim rights or contest +your rights to work written entirely by you; rather, the intent is to +exercise the right to control the distribution of derivative or +collective works based on the Program. + +In addition, mere aggregation of another work not based on the Program +with the Program (or with a work based on the Program) on a volume of +a storage or distribution medium does not bring the other work under +the scope of this License. + + 3. You may copy and distribute the Program (or a work based on it, +under Section 2) in object code or executable form under the terms of +Sections 1 and 2 above provided that you also do one of the following: + + a) Accompany it with the complete corresponding machine-readable + source code, which must be distributed under the terms of Sections + 1 and 2 above on a medium customarily used for software interchange; or, + + b) Accompany it with a written offer, valid for at least three + years, to give any third party, for a charge no more than your + cost of physically performing source distribution, a complete + machine-readable copy of the corresponding source code, to be + distributed under the terms of Sections 1 and 2 above on a medium + customarily used for software interchange; or, + + c) Accompany it with the information you received as to the offer + to distribute corresponding source code. (This alternative is + allowed only for noncommercial distribution and only if you + received the program in object code or executable form with such + an offer, in accord with Subsection b above.) + +The source code for a work means the preferred form of the work for +making modifications to it. For an executable work, complete source +code means all the source code for all modules it contains, plus any +associated interface definition files, plus the scripts used to +control compilation and installation of the executable. However, as a +special exception, the source code distributed need not include +anything that is normally distributed (in either source or binary +form) with the major components (compiler, kernel, and so on) of the +operating system on which the executable runs, unless that component +itself accompanies the executable. + +If distribution of executable or object code is made by offering +access to copy from a designated place, then offering equivalent +access to copy the source code from the same place counts as +distribution of the source code, even though third parties are not +compelled to copy the source along with the object code. + + 4. You may not copy, modify, sublicense, or distribute the Program +except as expressly provided under this License. Any attempt +otherwise to copy, modify, sublicense or distribute the Program is +void, and will automatically terminate your rights under this License. +However, parties who have received copies, or rights, from you under +this License will not have their licenses terminated so long as such +parties remain in full compliance. + + 5. You are not required to accept this License, since you have not +signed it. However, nothing else grants you permission to modify or +distribute the Program or its derivative works. These actions are +prohibited by law if you do not accept this License. Therefore, by +modifying or distributing the Program (or any work based on the +Program), you indicate your acceptance of this License to do so, and +all its terms and conditions for copying, distributing or modifying +the Program or works based on it. + + 6. Each time you redistribute the Program (or any work based on the +Program), the recipient automatically receives a license from the +original licensor to copy, distribute or modify the Program subject to +these terms and conditions. You may not impose any further +restrictions on the recipients' exercise of the rights granted herein. +You are not responsible for enforcing compliance by third parties to +this License. + + 7. If, as a consequence of a court judgment or allegation of patent +infringement or for any other reason (not limited to patent issues), +conditions are imposed on you (whether by court order, agreement or +otherwise) that contradict the conditions of this License, they do not +excuse you from the conditions of this License. If you cannot +distribute so as to satisfy simultaneously your obligations under this +License and any other pertinent obligations, then as a consequence you +may not distribute the Program at all. For example, if a patent +license would not permit royalty-free redistribution of the Program by +all those who receive copies directly or indirectly through you, then +the only way you could satisfy both it and this License would be to +refrain entirely from distribution of the Program. + +If any portion of this section is held invalid or unenforceable under +any particular circumstance, the balance of the section is intended to +apply and the section as a whole is intended to apply in other +circumstances. + +It is not the purpose of this section to induce you to infringe any +patents or other property right claims or to contest validity of any +such claims; this section has the sole purpose of protecting the +integrity of the free software distribution system, which is +implemented by public license practices. Many people have made +generous contributions to the wide range of software distributed +through that system in reliance on consistent application of that +system; it is up to the author/donor to decide if he or she is willing +to distribute software through any other system and a licensee cannot +impose that choice. + +This section is intended to make thoroughly clear what is believed to +be a consequence of the rest of this License. + + 8. If the distribution and/or use of the Program is restricted in +certain countries either by patents or by copyrighted interfaces, the +original copyright holder who places the Program under this License +may add an explicit geographical distribution limitation excluding +those countries, so that distribution is permitted only in or among +countries not thus excluded. In such case, this License incorporates +the limitation as if written in the body of this License. + + 9. The Free Software Foundation may publish revised and/or new versions +of the General Public License from time to time. Such new versions will +be similar in spirit to the present version, but may differ in detail to +address new problems or concerns. + +Each version is given a distinguishing version number. If the Program +specifies a version number of this License which applies to it and "any +later version", you have the option of following the terms and conditions +either of that version or of any later version published by the Free +Software Foundation. If the Program does not specify a version number of +this License, you may choose any version ever published by the Free Software +Foundation. + + 10. If you wish to incorporate parts of the Program into other free +programs whose distribution conditions are different, write to the author +to ask for permission. For software which is copyrighted by the Free +Software Foundation, write to the Free Software Foundation; we sometimes +make exceptions for this. Our decision will be guided by the two goals +of preserving the free status of all derivatives of our free software and +of promoting the sharing and reuse of software generally. + + NO WARRANTY + + 11. BECAUSE THE PROGRAM IS LICENSED FREE OF CHARGE, THERE IS NO WARRANTY +FOR THE PROGRAM, TO THE EXTENT PERMITTED BY APPLICABLE LAW. EXCEPT WHEN +OTHERWISE STATED IN WRITING THE COPYRIGHT HOLDERS AND/OR OTHER PARTIES +PROVIDE THE PROGRAM "AS IS" WITHOUT WARRANTY OF ANY KIND, EITHER EXPRESSED +OR IMPLIED, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF +MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. THE ENTIRE RISK AS +TO THE QUALITY AND PERFORMANCE OF THE PROGRAM IS WITH YOU. SHOULD THE +PROGRAM PROVE DEFECTIVE, YOU ASSUME THE COST OF ALL NECESSARY SERVICING, +REPAIR OR CORRECTION. + + 12. IN NO EVENT UNLESS REQUIRED BY APPLICABLE LAW OR AGREED TO IN WRITING +WILL ANY COPYRIGHT HOLDER, OR ANY OTHER PARTY WHO MAY MODIFY AND/OR +REDISTRIBUTE THE PROGRAM AS PERMITTED ABOVE, BE LIABLE TO YOU FOR DAMAGES, +INCLUDING ANY GENERAL, SPECIAL, INCIDENTAL OR CONSEQUENTIAL DAMAGES ARISING +OUT OF THE USE OR INABILITY TO USE THE PROGRAM (INCLUDING BUT NOT LIMITED +TO LOSS OF DATA OR DATA BEING RENDERED INACCURATE OR LOSSES SUSTAINED BY +YOU OR THIRD PARTIES OR A FAILURE OF THE PROGRAM TO OPERATE WITH ANY OTHER +PROGRAMS), EVEN IF SUCH HOLDER OR OTHER PARTY HAS BEEN ADVISED OF THE +POSSIBILITY OF SUCH DAMAGES. + + END OF TERMS AND CONDITIONS + + How to Apply These Terms to Your New Programs + + If you develop a new program, and you want it to be of the greatest +possible use to the public, the best way to achieve this is to make it +free software which everyone can redistribute and change under these terms. + + To do so, attach the following notices to the program. It is safest +to attach them to the start of each source file to most effectively +convey the exclusion of warranty; and each file should have at least +the "copyright" line and a pointer to where the full notice is found. + + + Copyright (C) + + This program is free software; you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation; either version 2 of the License, or + (at your option) any later version. + + This program is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License along + with this program; if not, see . + +Also add information on how to contact you by electronic and paper mail. + +If the program is interactive, make it output a short notice like this +when it starts in an interactive mode: + + Gnomovision version 69, Copyright (C) year name of author + Gnomovision comes with ABSOLUTELY NO WARRANTY; for details type `show w'. + This is free software, and you are welcome to redistribute it + under certain conditions; type `show c' for details. + +The hypothetical commands `show w' and `show c' should show the appropriate +parts of the General Public License. Of course, the commands you use may +be called something other than `show w' and `show c'; they could even be +mouse-clicks or menu items--whatever suits your program. + +You should also get your employer (if you work as a programmer) or your +school, if any, to sign a "copyright disclaimer" for the program, if +necessary. Here is a sample; alter the names: + + Yoyodyne, Inc., hereby disclaims all copyright interest in the program + `Gnomovision' (which makes passes at compilers) written by James Hacker. + + , 1 April 1989 + Moe Ghoul, President of Vice + +This General Public License does not permit incorporating your program into +proprietary programs. If your program is a subroutine library, you may +consider it more useful to permit linking proprietary applications with the +library. If this is what you want to do, use the GNU Lesser General +Public License instead of this License. diff --git a/Utilities/can_moni/Makefile b/Utilities/can_moni/Makefile new file mode 100644 index 0000000..95e6068 --- /dev/null +++ b/Utilities/can_moni/Makefile @@ -0,0 +1,190 @@ +# +# CAN Monitor for PEAK-System PCAN USB Interfaces (macOS, x86_64 & arm64) +# +# Copyright (c) 2007 by Uwe Vogt, UV Software, Friedrichshafen +# Copyright (c) 2012-2024 Uwe Vogt, UV Software, Berlin (info@uv-software.com) +# +# This program is free software: you can redistribute it and/or modify +# it under the terms of the GNU General Public License as published by +# the Free Software Foundation, either version 3 of the License, or +# (at your option) any later version. +# +# This program is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU General Public License for more details. +# +# You should have received a copy of the GNU General Public License +# along with this program If not, see . +# +current_OS := $(shell sh -c 'uname 2>/dev/null || echo Unknown OS') +current_OS := $(patsubst CYGWIN%,Cygwin,$(current_OS)) +current_OS := $(patsubst MINGW%,MinGW,$(current_OS)) +current_OS := $(patsubst MSYS%,MinGW,$(current_OS)) + +TARGET = can_moni + +INSTALL = ~/bin + +PROJ_DIR = ../.. +HOME_DIR = .. +MAIN_DIR = . + +MISC_DIR = $(HOME_DIR)/misc +DRIVER_DIR = $(HOME_DIR)/driver + +OBJECTS = $(OUTDIR)/main.o $(OUTDIR)/bitrates.o $(OUTDIR)/timer.o $(OUTDIR)/printmsg.o + +DEFINES = + +HEADERS = -I$(MAIN_DIR) \ + -I$(HOME_DIR) \ + -I$(MISC_DIR) + +ifneq ($(VARIANT),STANDALONE) + DEFINES += -DOPTION_PCBUSB_STANDALONE=0 + + HEADERS += + + OBJECTS += $(OUTDIR)/PCBUSB.o + + BIN_DIR = $(HOME_DIR)/Binaries +else + DEFINES += -DOPTION_PCBUSB_STANDALONE=1 + + HEADERS += -I$(DRIVER_DIR) + + OBJECTS += $(OUTDIR)/pcan_api.o \ + $(OUTDIR)/pcan_drv.o \ + $(OUTDIR)/pcan_que.o \ + $(OUTDIR)/pcan_flt.o \ + $(OUTDIR)/pcan_trc.o \ + $(OUTDIR)/pcan_btr.o \ + $(OUTDIR)/pcan_log.o \ + $(OUTDIR)/pcan_usb.o \ + $(OUTDIR)/pcan_usbfd.o + + BIN_DIR = $(HOME_DIR)/../Binaries/$(TARGET) +endif + +CFLAGS += -O2 -Wall -Wextra -Wno-parentheses \ + -fno-strict-aliasing \ + $(DEFINES) \ + $(HEADERS) + +CXXFLAGS += -O2 -g -Wall -Wextra -pthread \ + $(DEFINES) \ + $(HEADERS) + +LDFLAGS += -rpath /usr/local/lib + +LIBRARIES = -lpthread + +ifeq ($(VARIANT),STANDALONE) + LDFLAGS += -Wl,-framework -Wl,IOKit -Wl,-framework -Wl,CoreFoundation +endif + +ifeq ($(BINARY),UNIVERSAL) +CFLAGS += -arch arm64 -arch x86_64 +CXXFLAGS += -arch arm64 -arch x86_64 +LDFLAGS += -arch arm64 -arch x86_64 +endif + +CHECKER = warning,information +IGNORE = -i tester.c -i dosopt.c + +CXX = clang++ +CC = clang +LD = clang + +RM = rm -f +CP = cp -f + +OUTDIR = .objects +BINDIR = $(BIN_DIR) + +.PHONY: info outdir bindir + + +all: info outdir bindir $(TARGET) + +info: + @echo $(CC)" on "$(current_OS) + @echo "target: "$(TARGET) + @echo "install: "$(INSTALL) + +outdir: + @mkdir -p $(OUTDIR) + +bindir: + @mkdir -p $(BINDIR) + +incdir: + @mkdir -p $(INCDIR) + +check: + cppcheck --enable=$(CHECKER) --suppressions-list=$(HOME_DIR)/suppress.txt \ + -D__APPLE__ $(DEFINES) $(HEADERS) $(IGNORE) $(MAIN_DIR) $(MISC_DIR) + +clean: + @-$(RM) $(TARGET) $(OUTDIR)/*.o $(OUTDIR)/*.d + +pristine: + @-$(RM) $(TARGET) $(OUTDIR)/*.o $(OUTDIR)/*.d + @-$(RM) $(BINDIR)/$(TARGET) + +install: + @echo "Copying binary file..." + @-$(CP) $(TARGET) $(INSTALL) + + +$(OUTDIR)/main.o: $(MAIN_DIR)/main.c + $(CC) $(CFLAGS) -MMD -MF $*.d -o $@ -c $< + +$(OUTDIR)/PCBUSB.o: $(HOME_DIR)/PCBUSB.c + $(CC) $(CFLAGS) -MMD -MF $*.d -o $@ -c $< + +$(OUTDIR)/bitrates.o: $(MISC_DIR)/bitrates.c + $(CC) $(CFLAGS) -MMD -MF $*.d -o $@ -c $< + +$(OUTDIR)/timer.o: $(MISC_DIR)/timer.c + $(CC) $(CFLAGS) -MMD -MF $*.d -o $@ -c $< + +$(OUTDIR)/printmsg.o: $(MISC_DIR)/printmsg.c + $(CC) $(CFLAGS) -MMD -MF $*.d -o $@ -c $< + +$(OUTDIR)/pcan_api.o: $(DRIVER_DIR)/pcan_api.c + $(CC) $(CFLAGS) -MMD -MF $*.d -o $@ -c $< + +$(OUTDIR)/pcan_drv.o: $(DRIVER_DIR)/pcan_drv.c + $(CC) $(CFLAGS) -MMD -MF $*.d -o $@ -c $< + +$(OUTDIR)/pcan_usb.o: $(DRIVER_DIR)/pcan_usb.c + $(CC) $(CFLAGS) -MMD -MF $*.d -o $@ -c $< + +$(OUTDIR)/pcan_usbfd.o: $(DRIVER_DIR)/pcan_usbfd.c + $(CC) $(CFLAGS) -MMD -MF $*.d -o $@ -c $< + +$(OUTDIR)/pcan_btr.o: $(DRIVER_DIR)/pcan_btr.c + $(CC) $(CFLAGS) -MMD -MF $*.d -o $@ -c $< + +$(OUTDIR)/pcan_flt.o: $(DRIVER_DIR)/pcan_flt.c + $(CC) $(CFLAGS) -MMD -MF $*.d -o $@ -c $< + +$(OUTDIR)/pcan_que.o: $(DRIVER_DIR)/pcan_que.c + $(CC) $(CFLAGS) -MMD -MF $*.d -o $@ -c $< + +$(OUTDIR)/pcan_trc.o: $(DRIVER_DIR)/pcan_trc.c + $(CC) $(CFLAGS) -MMD -MF $*.d -o $@ -c $< + +$(OUTDIR)/pcan_log.o: $(DRIVER_DIR)/pcan_log.c + $(CC) $(CFLAGS) -MMD -MF $*.d -o $@ -c $< + + +$(TARGET): $(OBJECTS) + $(LD) $(LDFLAGS) -o $@ $(OBJECTS) $(LIBRARIES) + $(CP) $(TARGET) $(BINDIR) +ifeq ($(current_OS),Darwin) + @lipo -archs $@ +endif + @echo "\033[1mTarget '"$@"' successfully build\033[0m" diff --git a/Utilities/can_moni/README b/Utilities/can_moni/README new file mode 100644 index 0000000..de796d7 --- /dev/null +++ b/Utilities/can_moni/README @@ -0,0 +1,122 @@ +CAN Monitor for PEAK-System PCAN USB Interfaces (macOS, x86_64 & arm64) + +Copyright (c) 2007,2012-2024 by Uwe Vogt, UV Software, Berlin. + +Usage: can_moni [