module
Version:
v0.0.3
Opens a new window with list of versions in this module.
Published: Oct 23, 2023
License: Apache-2.0
Opens a new window with license information.
README
¶
gotap
介绍
易盛 iTap 北斗星接口 golang 封装
软件架构
软件架构说明
安装教程
- 接口下载
使用说明
- C++ -> C
- go 调用 C
- 生成器生成 .go 文件
- 复制 .h 文件到
go
目录下
- 在 go 目录下, 运行 go run main
- 根据提示修改 .h 文件的内容
- 类型转换 c -> go C 函数返回值转换为 go 变量
- void* -> string : 返回 地址转换为字串
- C.GoString((*C.char)(c 的返回函数)
- 类型转换 go -> c go 中的变量传递给 c 函数
- *TAPIINT32 -> *C.int : go 中的变量地址给 c 使用
- (*C.int)(unsafe.Pointer(res))
- string -> char*
str := C.CString(IP)
C.SetHostAddress(t.api, str, C.ushort(port))
defer C.free(unsafe.Pointer(str))
- TAPIUINT16 -> C.ushort
- []byte -> char*
(*C.char)(unsafe.Pointer(&bt[0]))
- 删除多余的 amp; (由&转换造成)
- go 测试
- lib 目录下
g++ -shared -fPIC -Wl,-rpath . -o libtaptrade.so ../c/trade.cpp ../c/trade_fn.cpp libiTapTradeAPI.so
- 复制库
cp ../lib/lib*.so lnx
- go run main.go
- c++ 测试
- 修改官方 Makefile
# cento 7.8 用以下方法
g++ -o demo Demo.cpp trade.cpp SimpleEvent.cpp ./libiTapTradeAPI.so`
- QA
- trade_on.go
previous declaration of ‘OnRtnCombinePosition’ was here
- 检查是否 .go 文件中的定义与 .h 中的不同
- trade.h 文件中定义的响应, 是否增加了 spi 作为第一个参数.
- [弃]增加 spi 是为了支持多帐号,增加了复杂性,暂
不
支持
- [弃]删除 trade.h 中的响应定义中的 const
- cgo 不支持 const char*
- const structXXX 等带 const 的类型不受影响
- trade_lnx.go 中重新定义 C 的响应函数
- 所有类型转换为 c 的基础类型,不使用自定义类型
- 重新定义所有 struct, 字段类型改为 C 原始类型
- 登录 Login 返回 0,没有收到 OnConnected 响应,却报错:ignal: segmentation fault
- Login 之前,注册 SPI 则会触发异常
- c 返回 spi,用 new Trade(),对 make 时报错的函数先注销掉,确保编译通过
参与贡献
- Fork 本仓库
- 新建 Feat_xxx 分支
- 提交代码
- 新建 Pull Request
特技
- 使用 Readme_XXX.md 来支持不同的语言,例如 Readme_en.md, Readme_zh.md
- Gitee 官方博客 blog.gitee.com
- 你可以 https://gitee.com/explore 这个地址来了解 Gitee 上的优秀开源项目
- GVP 全称是 Gitee 最有价值开源项目,是综合评定出的优秀开源项目
- Gitee 官方提供的使用手册 https://gitee.com/help
- Gitee 封面人物是一档用来展示 Gitee 会员风采的栏目 https://gitee.com/gitee-stars/
Directories
¶
Click to show internal directories.
Click to hide internal directories.