Skip to content

Commit e675a09

Browse files
authored
Merge pull request #20 from mac-can/development
Release candidate 1 for version 0.3
2 parents a1d9719 + 90ce8a1 commit e675a09

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

57 files changed

+2365
-566
lines changed

Examples/C++/Makefile

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,7 @@ LDFLAGS =
3030
CXX = g++
3131
LD = g++
3232
RM = rm -f
33+
CP = cp
3334

3435
all: $(TARGET1) $(TARGET2)
3536

@@ -41,3 +42,9 @@ $(TARGET2): $(SOURCE2)
4142

4243
clean:
4344
@-$(RM) *.o *~ $(TARGET1) $(TARGET2)
45+
pristine:
46+
@-$(RM) *.o *~ $(TARGET1) $(TARGET2)
47+
48+
install:
49+
@-$(CP) $(TARGET1) /usr/local/bin
50+
@-$(CP) $(TARGET2) /usr/local/bin

Examples/C++/can_send.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@ int main(int argc, const char * argv[]) {
3838

3939
can_sio_param_t port;
4040
port.name = (char*)SERIAL_PORT;
41-
port.attr.options = CANSIO_SLCAN;
41+
port.attr.protocol = CANSIO_LAWICEL;
4242
port.attr.baudrate = CANSIO_BD57600;
4343
port.attr.bytesize = CANSIO_8DATABITS;
4444
port.attr.parity = CANSIO_NOPARITY;

Examples/Makefile

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
all:
2+
# if any Makefile failed, stop building all...
3+
@for m in `find . -mindepth 2 -name Makefile`; do\
4+
$(MAKE) -C `dirname $$m`; \
5+
if [ $$? -ne 0 ]; then exit 1; fi; \
6+
done
7+
8+
clean:
9+
-@for m in `find . -mindepth 2 -name Makefile`; do\
10+
$(MAKE) -C `dirname $$m` clean; \
11+
done
12+
13+
pristine:
14+
-@for m in `find . -mindepth 2 -name Makefile`; do\
15+
$(MAKE) -C `dirname $$m` pristine; \
16+
done

Examples/Python/CANAPI.py

Lines changed: 89 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -52,9 +52,9 @@
5252
Interface API for various CAN interfaces from different
5353
vendors running under multiple operating systems.
5454
55-
$Author: makemake $
55+
$Author: quaoar $
5656
57-
$Rev: 1274 $
57+
$Rev: 1278 $
5858
"""
5959
from ctypes import *
6060
import platform
@@ -69,7 +69,7 @@
6969

7070
# CAN API V3 - Python Wrapper
7171
#
72-
CAN_API_V3_PYTHON = {'major': 0, 'minor': 2, 'patch': 2}
72+
CAN_API_V3_PYTHON = {'major': 0, 'minor': 3, 'patch': 1}
7373

7474
# CAN Identifier Ranges
7575
#
@@ -122,6 +122,13 @@
122122
(49, 50, 51, 52, 53, 54, 55, 56, 57, 58, 59, 60, 61, 62, 63, 64): c_uint8(0xF)
123123
}
124124

125+
# CAN Acceptance Filter: (code ^ id) & mask == 0
126+
#
127+
CANACC_CODE_11BIT = 0x000 # mask for 11-bit acceptance code
128+
CANACC_MASK_11BIT = 0x000 # mask for 11-bit acceptance mask
129+
CANACC_CODE_29BIT = 0x00000000 # mask for 29-bit acceptance code
130+
CANACC_MASK_29BIT = 0x00000000 # mask for 29-bit acceptance mask
131+
125132
# CAN 2.0 Predefined Bit-rates (as index acc. CiA)
126133
#
127134
CANBTR_INDEX_1M = c_int32(0) # bit-rate: 1000 kbit/s
@@ -638,6 +645,70 @@ def bitrate(self):
638645
print('+++ exception: {}'.format(e))
639646
raise
640647

648+
def filter11bit(self, code, mask):
649+
"""
650+
sets a 11-bit filter for the CAN controller.
651+
652+
:param code: 11-bit code for the filter (or None)
653+
:param mask: 11-bit mask for the filter (or None)
654+
:return: result, code, mask
655+
result: 0 if successful, or a negative value on error
656+
code: 11-bit code for the filter
657+
mask: 11-bit mask for the filter
658+
"""
659+
try:
660+
# set the 11-bit filter (if code or mask are not None)
661+
if code is not None or mask is not None:
662+
__filter = c_uint64(0)
663+
if code is not None:
664+
__filter.value = code << 32
665+
if mask is not None:
666+
__filter.value |= mask & 0xFFFFFFFF
667+
result = self.__m_library.can_property(self.__m_handle, 42, byref(__filter), 8)
668+
if result < 0:
669+
return int(result), None, None
670+
# get the 11-bit filter
671+
__value = c_uint64(0)
672+
result = self.__m_library.can_property(self.__m_handle, 40, byref(__value), 8)
673+
if result < 0:
674+
return int(result), None, None
675+
return int(result), int(__filter.value >> 32), int(__filter.value & 0xFFFFFFFF)
676+
except Exception as e:
677+
print('+++ exception: {}'.format(e))
678+
raise
679+
680+
def filter29bit(self, code, mask):
681+
"""
682+
sets a 29-bit filter for the CAN controller.
683+
684+
:param code: 29-bit code for the filter (or None)
685+
:param mask: 29-bit mask for the filter (or None)
686+
:return: result, code, mask
687+
result: 0 if successful, or a negative value on error
688+
code: 29-bit code for the filter
689+
mask: 29-bit mask for the filter
690+
"""
691+
try:
692+
# set the 29-bit filter (if code or mask are not None)
693+
if code is not None or mask is not None:
694+
__filter = c_uint64(0)
695+
if code is not None:
696+
__filter.value = code << 32
697+
if mask is not None:
698+
__filter.value |= mask & 0xFFFFFFFF
699+
result = self.__m_library.can_property(self.__m_handle, 43, byref(__filter), 8)
700+
if result < 0:
701+
return int(result), None, None
702+
# get the 29-bit filter
703+
__value = c_uint64(0)
704+
result = self.__m_library.can_property(self.__m_handle, 41, byref(__value), 8)
705+
if result < 0:
706+
return int(result), None, None
707+
return int(result), int(__filter.value >> 32), int(__filter.value & 0xFFFFFFFF)
708+
except Exception as e:
709+
print('+++ exception: {}'.format(e))
710+
raise
711+
641712
def hardware(self):
642713
"""
643714
retrieves the hardware version of the CAN controller
@@ -780,6 +851,20 @@ def len2dlc(length):
780851
else:
781852
print('>>> can.status() >>> 0x{:02X}'.format(status.byte))
782853

854+
# set acceptance filter
855+
code = CANACC_CODE_11BIT
856+
mask = CANACC_MASK_11BIT
857+
print('>>> can.filter11bit(0x{:03X}, 0x{:03X})'.format(code, mask))
858+
res, code, mask = can.filter11bit(code=code, mask=mask)
859+
if res < CANERR_NOERROR:
860+
print('+++ error: can.filter11bit returned {}'.format(res))
861+
code = CANACC_CODE_29BIT
862+
mask = CANACC_MASK_29BIT
863+
print('>>> can.filter29bit(0x{:08X}, 0x{:08X})'.format(code, mask))
864+
res, code, mask = can.filter29bit(code=code, mask=mask)
865+
if res < CANERR_NOERROR:
866+
print('+++ error: can.filter29bit returned {}'.format(res))
867+
783868
# start the CAN controller
784869
if bitRate.index > 0: # FIXME: Expected type 'int', got 'c_int32[int]' instead
785870
print('>>> can.start([{},[{},{},{},{},{}],[{},{},{},{},])'.format(bitRate.btr.frequency,
@@ -831,5 +916,5 @@ def len2dlc(length):
831916
# have a great time
832917
print('Bye, bye!')
833918

834-
# * $Id: CANAPI.py 1274 2024-04-21 17:34:21Z makemake $ *** (c) UV Software, Berlin ***
919+
# * $Id: CANAPI.py 1278 2024-04-23 08:34:36Z quaoar $ *** (c) UV Software, Berlin ***
835920
#

Examples/Python/CANAPI_SerialCAN.py

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -54,7 +54,7 @@
5454
5555
$Author: makemake $
5656
57-
$Rev: 1261 $
57+
$Rev: 1397 $
5858
"""
5959
from CANAPI import *
6060
from ctypes import *
@@ -66,7 +66,10 @@
6666

6767
# SerialCAN protocol options
6868
#
69-
CANSIO_SLCAN = 0x00 # Lawicel SLCAN protocol
69+
CANSIO_LAWICEL = 0x00 # Lawicel SLCAN protocol
70+
CANSIO_CANABLE = 0x01 # CANable SLCAN protocol
71+
CANSIO_AUTO = 0xFF # auto detect (not realized yet)
72+
CANSIO_SLCAN = CANSIO_LAWICEL # Lawicel SLCAN protocol (default)
7073

7174
# Baud rate (CBAUDEX compatible, e.g. CygWin)
7275
#
@@ -112,10 +115,10 @@ class SerialAttr(LittleEndianStructure):
112115
('bytesize', c_uint8),
113116
('parity', c_uint8),
114117
('stopbits', c_uint8),
115-
('options', c_uint8)
118+
('protocol', c_uint8)
116119
]
117120
def __init__(self):
118-
self.options = CANSIO_SLCAN
121+
self.protocol = CANSIO_SLCAN
119122
self.baudrate = CANSIO_BD57600
120123
self.bytesize = CANSIO_8DATABITS
121124
self.parity = CANSIO_NOPARITY

Examples/Python/Makefile

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
all:
2+
@-echo python3 Nothing to be done for ''all''
3+
4+
clean:
5+
@-rm -f *.pyc
6+
7+
pristine:
8+
@-rm -f *.pyc
9+
@-rm -rf __pycache__

Examples/Python/can_recv.py

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,8 @@ def sigterm(signo, frame):
4242
help='CAN API V3 driver library, default=\'' + lib + '\'')
4343
parser.add_argument('--port', type=str, nargs=1, default=[com],
4444
help='Serial port, default=' + str(com))
45+
parser.add_argument('--protocol', type=str, nargs=1, default='LAWICEL',
46+
help='SLCAN protocol LAWICEL or CANable, default=LAWICEL')
4547
args = parser.parse_args()
4648
lib = args.input
4749
com = args.port[0]
@@ -63,11 +65,15 @@ def sigterm(signo, frame):
6365
# serial port settings
6466
port = SerialPort()
6567
port.name = c_char_p(com.encode('utf-8'))
66-
port.attr.options = CANSIO_SLCAN
6768
port.attr.baudrate = CANSIO_BD57600
6869
port.attr.bytesize = CANSIO_8DATABITS
6970
port.attr.parity = CANSIO_NOPARITY
7071
port.attr.stopbits = CANSIO_1STOPBIT
72+
if args.protocol[0] == 'CANable':
73+
print('!!! Using {} protocol'.format(args.protocol[0]))
74+
port.attr.protocol = CANSIO_CANABLE
75+
else:
76+
port.attr.protocol = CANSIO_LAWICEL
7177

7278
# initialize the CAN interface
7379
print('>>> can.init({}, 0x{:02X})'.format(port.name, opMode.byte))

Examples/Python/can_send.py

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,8 @@ def sigterm(signo, frame):
4646
help='Serial port, default=' + str(com))
4747
parser.add_argument('--frames', type=int, nargs=1, default=[num],
4848
help='number of CAN frames to be sent, default=' + str(num))
49+
parser.add_argument('--protocol', type=str, nargs=1, default='LAWICEL',
50+
help='SLCAN protocol LAWICEL or CANable, default=LAWICEL')
4951
args = parser.parse_args()
5052
lib = args.input
5153
com = args.port[0]
@@ -76,11 +78,15 @@ def sigterm(signo, frame):
7678
# serial port settings
7779
port = SerialPort()
7880
port.name = c_char_p(com.encode('utf-8'))
79-
port.attr.options = CANSIO_SLCAN
8081
port.attr.baudrate = CANSIO_BD57600
8182
port.attr.bytesize = CANSIO_8DATABITS
8283
port.attr.parity = CANSIO_NOPARITY
8384
port.attr.stopbits = CANSIO_1STOPBIT
85+
if args.protocol[0] == 'CANable':
86+
print('!!! Using {} protocol'.format(args.protocol[0]))
87+
port.attr.protocol = CANSIO_CANABLE
88+
else:
89+
port.attr.protocol = CANSIO_LAWICEL
8490

8591
# initialize the CAN interface
8692
print('>>> can.init({}, 0x{:02X})'.format(port.name, opMode.byte))

Libraries/CANAPI/Makefile

Lines changed: 13 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,7 @@ current_OS := $(patsubst MINGW%,MinGW,$(current_OS))
5151
current_OS := $(patsubst MSYS%,MinGW,$(current_OS))
5252

5353
MAJOR = 0
54-
MINOR = 2
54+
MINOR = 3
5555
PATCH = 0
5656

5757
ifeq ($(PATCH),0)
@@ -70,14 +70,16 @@ WRAPPER_DIR = $(HOME_DIR)/Sources/Wrapper
7070

7171
OBJECTS = $(OUTDIR)/can_api.o $(OUTDIR)/can_btr.o \
7272
$(OUTDIR)/slcan.o $(OUTDIR)/serial.o \
73-
$(OUTDIR)/buffer.o $(OUTDIR)/queue.o $(OUTDIR)/logger.o
73+
$(OUTDIR)/buffer.o $(OUTDIR)/queue.o \
74+
$(OUTDIR)/timer.o $(OUTDIR)/logger.o \
7475

7576
DEFINES = -DOPTION_CAN_2_0_ONLY=0 \
7677
-DOPTION_CANAPI_DRIVER=1 \
7778
-DOPTION_CANAPI_RETVALS=1 \
7879
-DOPTION_CANAPI_COMPANIONS=1 \
7980
-DOPTION_CANAPI_DEBUG_LEVEL=0 \
8081
-DOPTION_SERIAL_DEBUG_LEVEL=0 \
82+
-DOPTION_SLCAN_FAKE_COMMANDS=1 \
8183
-DOPTION_SLCAN_DEBUG_LEVEL=0
8284

8385
HEADERS = -I$(SOURCE_DIR) \
@@ -200,18 +202,18 @@ incdir:
200202
$(CP) $(CANAPI_DIR)/can_btr.h $(INCDIR)
201203

202204
clean:
203-
$(RM) $(TARGET) $(STATIC) $(OUTDIR)/*.o $(OUTDIR)/*.d
205+
@-$(RM) $(TARGET) $(STATIC) $(OUTDIR)/*.o $(OUTDIR)/*.d
204206

205207
pristine:
206208
ifeq ($(current_OS),Darwin)
207-
$(RM) *.dylib *.a $(OUTDIR)/*.o $(OUTDIR)/*.d
208-
$(RM) $(BINDIR)/*.dylib $(BINDIR)/*.a
209+
@-$(RM) *.dylib *.a $(OUTDIR)/*.o $(OUTDIR)/*.d
210+
@-$(RM) $(BINDIR)/*.dylib $(BINDIR)/*.a
209211
endif
210212
ifeq ($(current_OS),$(filter $(current_OS),Linux Cygwin))
211-
$(RM) *.so.* *.a $(OUTDIR)/*.o $(OUTDIR)/*.d
212-
$(RM) $(BINDIR)/*.so.* $(BINDIR)/*.a
213+
@-$(RM) *.so.* *.a $(OUTDIR)/*.o $(OUTDIR)/*.d
214+
@-$(RM) $(BINDIR)/*.so.* $(BINDIR)/*.a
213215
endif
214-
$(RM) $(INCDIR)/*.h
216+
@-$(RM) $(INCDIR)/*.h
215217

216218
install:
217219
@echo "Copying library file..."
@@ -243,6 +245,9 @@ $(OUTDIR)/buffer.o: $(SERIAL_DIR)/buffer.c $(SERIAL_DIR)/buffer_p.c
243245
$(OUTDIR)/queue.o: $(SERIAL_DIR)/queue.c $(SERIAL_DIR)/queue_p.c
244246
$(CC) $(CFLAGS) -MMD -MF $*.d -o $@ -c $<
245247

248+
$(OUTDIR)/timer.o: $(SERIAL_DIR)/timer.c $(SERIAL_DIR)/timer_p.c
249+
$(CC) $(CFLAGS) -MMD -MF $*.d -o $@ -c $<
250+
246251
$(OUTDIR)/logger.o: $(SERIAL_DIR)/logger.c $(SERIAL_DIR)/logger_p.c
247252
$(CC) $(CFLAGS) -MMD -MF $*.d -o $@ -c $<
248253

Libraries/CANAPI/uvcanslc.rc

0 Bytes
Binary file not shown.

0 commit comments

Comments
 (0)