Skip to content

Commit

Permalink
add examples, refactor tests, simplify API
Browse files Browse the repository at this point in the history
  • Loading branch information
driftregion committed Jul 4, 2022
1 parent 383ce0f commit 8625dce
Show file tree
Hide file tree
Showing 25 changed files with 2,374 additions and 1,080 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1 +1,2 @@
.bazel-*
.rsync-filter
35 changes: 27 additions & 8 deletions BUILD
Original file line number Diff line number Diff line change
Expand Up @@ -51,16 +51,35 @@ cc_test(
copts = ["-Wall", "-Wextra", "-Werror"],
)

cc_library(
name = "example_host_linux",
filegroup(
name="example_srcs",
srcs = [
"example/linux_host.c",
"example/host.h",
],
"examples/server.c",
"examples/server.h",
"examples/client.c",
"examples/client.h",
"examples/shared.h",
"examples/port.h",
]
)

cc_binary(
name = "example_server",
srcs = [ "example/server.c" ],
deps = [ ":server", ":example_host_linux"],
name = "example",
srcs = [
":example_srcs",
"examples/port_socketcan.c",
"examples/main.c",
],
deps = [ ":server", ":client"],
)

cc_test(
name = "test_example",
srcs = [
":example_srcs",
"examples/port_socketcan.c",
"examples/test_example.c",
],
deps = [ ":server", ":client"],
copts = ["-Wall", "-Wextra", "-Werror"],
)
29 changes: 17 additions & 12 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,9 @@ isotp-c/isotp_defines.h
INCLUDES= \
isotp-c


# Tests (Run locally on linux)
#
# Unit tests
#
DEFINES=\

TEST_CFLAGS += $(foreach i,$(INCLUDES),-I$(i))
Expand All @@ -38,24 +39,28 @@ test_interactive: test_bin
clean:
rm -rf test_bin


# Example

#
# Example program
#
EXAMPLE_SRCS=\
example/linux_host.c \
example/simpleserver.c
examples/client.c \
examples/main.c \
examples/server.c \
examples/port_socketcan.c

EXAMPLE_HDRS=
EXAMPLE_HDRS=\
examples/client.h \
examples/server.h \
examples/port.h \
examples/shared.h

EXAMPLE_INCLUDES=\
example
examples

EXAMPLE_CFLAGS += $(foreach i,$(INCLUDES),-I$(i))
EXAMPLE_CFLAGS += $(foreach i,$(EXAMPLE_INCLUDES),-I$(i))
EXAMPLE_CFLAGS += $(foreach d,$(DEFINES),-D$(d))
EXAMPLE_CFLAGS += -g

example/linux: $(SRCS) $(EXAMPLE_SRCS) $(HDRS) $(EXAMPLE_HDRS) Makefile
example: $(SRCS) $(EXAMPLE_SRCS) $(HDRS) $(EXAMPLE_HDRS) Makefile
$(CC) $(EXAMPLE_CFLAGS) -o $@ $(EXAMPLE_SRCS) $(SRCS)

.phony: py_requirements
116 changes: 53 additions & 63 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,15 +4,23 @@ iso14229是个针对嵌入式系统的UDS(ISO14229-1:2013)服务器和客户端

iso14229 is a UDS server and client implementation (ISO14229-1:2013) targeting embedded systems. It embeds the [`isotp-c`](https://github.com/lishen2/isotp-c) transport layer.

**Stability: Unstable**

- callback functions give you complete control
- statically allocated
- aims to be toolchain-independent: no toolchain-specific extensions
- tested: gcc
- aims to be architecture-independent
API状态: **不稳定** / API status: **unstable**

特点:
- 依赖性注入
- 静态内存分配
- 独立于处理器架构
- 测试了: arm, x86-64, ppc
- 可以用qemu测试更多
- 单元测试又多又容易扩展

Features:
- dependency injection gives you complete control
- uses only static memory allocation
- architecture-independent
- tested: arm, x86-64, ppc
- tests run under qemu
- has many existing unit-tests and tests are easy to extend

# iso14229 文档 / Documentation

Expand Down Expand Up @@ -47,44 +55,9 @@ iso14229 is a UDS server and client implementation (ISO14229-1:2013) targeting e
| 0x86 | response on event ||


## 服务器:例子 / Server: Example (linux)

See [example/server.c](/example/server.c) for a simple server with socketCAN bindings

```sh
# 设置虚拟socketCAN接口
# setup a virtual socketCAN interface
sudo ip link add name vcan0 type vcan
sudo ip link set vcan0 up

# 构建例子服务器
# build the example server
make example/linux

# 在vcan0接口上运行例子服务器
# run the example server on vcan0
./example/linux vcan0
```

```sh
# (可选)在另外一个终端,看看虚拟CAN母线上的数据
# (Optional) In a another shell, monitor the virtual link
candump vcan0
```

```sh
# 在另外一个终端,安装python依赖性
# In another shell, install the required python packages
pip3 install -r example/requirements.txt

# 然后运行客户端
# then run the client
./example/client.py vcan0
```

## 客户端:怎么用 / Client: Basic Usage
## 例子 / Examples

Currently undocumented. See `test_iso14229.c` for usage examples
[examples/README.md](examples/README.md)

## 贡献/contributing

Expand All @@ -95,46 +68,63 @@ Currently undocumented. See `test_iso14229.c` for usage examples

- [`isotp`](https://github.com/lishen2/isotp-c) which this project embeds

# License
# 许可 / License

MIT

# 变更记录 / Changelog


## 0.0.0
- initial release
- 初次发布 / initial release

## 0.1.0
- Add client
- Add server SID 0x27 SecurityAccess
- API changes
- 加客户端 / Add client
- 加服务器SID 0x27安全访问 / Add server SID 0x27 SecurityAccess
- API更改 / API changes

## 0.2.0
- removed all instances of `__attribute__((packed))`
- refactored server download functional unit API to simplify testing
- refactored tests:
- ordered by service
- documented macros
- removed middleware because it made no sense after the above refactoring
- simplified server routine control API
- removed redundant function iso14229ServerEnableService: Services are enabled by registering user handlers.
- updated example

-
- 删除所有`__attribute__((packed))` / removed all instances of `__attribute__((packed))`
- 为了简化测试、重构服务器下载功能单元 / refactored server download functional unit API to simplify testing
- 重构测试 / refactored tests
- 按服务排列 / ordered by service
- 给宏定义写文档 / documented macros
- 删掉了中间件 / removed middleware
- 简化了服务器例程控制API / simplified server routine control API
- 删掉了重复函数`iso14229ServerEnableService` / removed redundant function `iso14229ServerEnableService`
- 更新例子 / updated example

## 0.3.0
-`iso14229ClientRunSequenceBlocking(...)` / added `iso14229ClientRunSequenceBlocking(...)`
- 加了服务器和客户端例子 / added server and client examples
- 简化测试流程、删掉了过分模糊宏定义和switch结构 / simplified test flow, deleted opaque macros and switch statements
- 服务器和客户端结构体简化:尽量用一层深度 / flattened client and server main structs
- 简化使用、放isotp-c初始化参数到服务器/客户端配置里面 / simplified usage by moving isotp-c initialization parameters into server/client config structs
- 删除重复服务器缓冲器 / remove redundant buffers in server

---

# 运行测试 / running tests

# iso14229开发文档 / design docs
```sh
make test
```

## Running Tests
## qemu

```sh
CC=powerpc-linux-gnu-gcc make test_bin
qemu-ppc -L /usr/powerpc-linux-gnu test_bin
```
## wine

```sh
bazel test --compilation_mode=dbg //...
CC=x86_64-w64-mingw32-gcc make test_bin
wine test_bin.exe
```

# iso14229开发文档 / design docs


## 客户端请求状态机

Expand Down
65 changes: 65 additions & 0 deletions examples/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,65 @@
# 例子 / Examples

这个例子用linux socketcan. Windows用户可以用个linux虚拟机。WSL应该也可以。

This example uses linux socketcan. Windows users can run it in a linux VM. It might work under WSL.


# socketcan 虚拟接口设置 / virtual interface setup
```sh
# 设置虚拟socketCAN接口
# setup a virtual socketCAN interface
sudo ip link add name vcan0 type vcan
sudo ip link set vcan0 up
```
# 构建例子 / building the example
```
make example
```

# 在vcan0接口上运行例子服务器 / run the server on vcan0
```sh
./example server vcan0
# 服务器会一直跑。用 ctrl+c 推出
# The server will run continuously. Use ctrl+c to exit
```

# 在vcan0接口上运行客户端 (打开另一个终端) / run the client on vcan0 (open another shell)
```sh
./example client vcan0
# 客户端跑完流程后会自动退出
# The client will exit after it has executed its sequence
```

# 用candump看看输出
```sh
> candump -tz vcan0
(000.000000) vcan0 111 [4] 01 02 03 04
(000.000028) vcan0 111 [4] 01 02 03 04
(000.000090) vcan0 701 [8] 02 11 01 00 00 00 00 00 # 0x11 ECU复位请求
(000.010199) vcan0 700 [8] 02 51 01 00 00 00 00 00 # 0x11 ECU复位肯定响应
(000.010213) vcan0 701 [8] 05 22 00 01 00 08 00 00 # 0x22 RDBI请求
(000.020318) vcan0 700 [8] 10 1B 62 00 01 00 00 08 # ISO-TP流控框
(000.020326) vcan0 701 [8] 30 08 00 00 00 00 00 00 # 0x22 RDBI请求
(000.030416) vcan0 700 [8] 21 49 27 6D 20 61 20 55 # 0x22 RDBI响应 (1)
(000.040674) vcan0 700 [8] 22 44 53 20 73 65 72 76 # 0x22 RDBI响应 (2)
(000.050829) vcan0 700 [8] 23 65 72 20 20 20 20 00 # 0x22 RDBI响应 (3)
(000.051509) vcan0 701 [8] 02 10 03 00 00 00 00 00 # 0x10 会话控制
(000.072713) vcan0 700 [8] 03 7F 10 33 00 00 00 00 # 0x10 会话控制否定响应
(000.072979) vcan0 701 [8] 02 11 04 00 00 00 00 00 # 0x11 ECU复位请求
(000.124015) vcan0 700 [8] 03 51 04 FF 00 00 00 00 # 0x11 ECU复位肯定响应

```


# 也可以用python-udsoncan实现客户端 / You can also use python-udsoncan to implement a client

```sh
# 在另外一个终端,安装python依赖性
# In another shell, install the required python packages
pip3 install -r example/requirements.txt

# 然后运行客户端
# then run the client
./example/client.py vcan0
```
Loading

0 comments on commit 8625dce

Please sign in to comment.