- Java 双重比较
- java - 比较器与 Apache BeanComparator
- Objective-C 完成 block 导致额外的方法调用?
- database - RESTful URI 是否应该公开数据库主键?
我正在尝试使用 cryptoauthlib 编译一个 c++ 程序,但我在 atca_iface.h 中遇到了这个(匿名 union 只能有非静态数据成员)错误。我认为这是一个 c11 特性,与 c++ 不兼容:
未命名 union 体中的所有命名结构都会抛出错误。我删除了以下结构的名称:
typedef struct
{
ATCAIfaceType iface_type; // active iface - how to interpret the union below
ATCADeviceType devtype; // explicit device type
union // each instance of an iface cfg defines a single type of interface
{
struct //ATCAI2C
{
uint8_t slave_address; // 8-bit slave address
uint8_t bus; // logical i2c bus number, 0-based - HAL will map this to a pin pair for SDA SCL
uint32_t baud; // typically 400000
} atcai2c;
struct //ATCASWI
{
uint8_t bus; // logical SWI bus - HAL will map this to a pin or uart port
} atcaswi;
struct //ATCAUART
{
int port; // logic port number
uint32_t baud; // typically 115200
uint8_t wordsize; // usually 8
uint8_t parity; // 0 == even, 1 == odd, 2 == none
uint8_t stopbits; // 0,1,2
} atcauart;
struct //ATCAHID
{
int idx; // HID enumeration index
uint32_t vid; // Vendor ID of kit (0x03EB for CK101)
uint32_t pid; // Product ID of kit (0x2312 for CK101)
uint32_t packetsize; // Size of the USB packet
uint8_t guid[16]; // The GUID for this HID device
} atcahid;
struct //ATCACUSTOM
{
ATCA_STATUS (*halinit)(void *hal, void *cfg);
ATCA_STATUS (*halpostinit)(void *iface);
ATCA_STATUS (*halsend)(void *iface, uint8_t *txdata, int txlength);
ATCA_STATUS (*halreceive)(void *iface, uint8_t* rxdata, uint16_t* rxlength);
ATCA_STATUS (*halwake)(void *iface);
ATCA_STATUS (*halidle)(void *iface);
ATCA_STATUS (*halsleep)(void *iface);
ATCA_STATUS (*halrelease)(void* hal_data);
} atcacustom;
};
uint16_t wake_delay; // microseconds of tWHI + tWLO which varies based on chip type
int rx_retries; // the number of retries to attempt for receiving bytes
void * cfg_data; // opaque data used by HAL in device discovery
} ATCAIfaceCfg;
我将这些结构更改为未命名的结构并编译,但不幸的是,在调用 init 函数时出现段错误 ATCA_STATUS atinit(ATCAIface ca_iface);
...我没有直接调用此函数.我调用 atcab_init(&cfg_ateccx08a_i2c_default);
有没有办法像我一样在不修改界面的情况下使用它,为什么会出现段错误?
我的硬件设置是带有连接到 I2C 1 的 ATECC608a 的 CM3。接口(interface)已打开,我可以查询它。我是否需要将默认接口(interface)修改为正确的设备类型和正确的 I2C 接口(interface)?当我这样做时,我会遇到同样的段错误。
编辑:
示例代码
#include <iostream>
#include "cryptoauthlib.h"
int main(int argc, char *argv[])
{
uint8_t random_number;
atcab_init(&cfg_ateccx08a_i2c_default);
ATCA_STATUS status = atcab_random(&random_number);
std::cout << "status: " << (int)status << std::endl;
return 0;
}
编辑2:
github 上有人告诉我必须使用 -DATCA_HAL_I2C 作为 C 编译器标志。但是我现在得到 undefined reference to hal_i2c_init
错误
编辑3:
问题似乎出在 cryptoauthlib 的 cmake 配置上,因为我在 windows 上为 armhf 交叉编译。
查看 cmake 配置
编辑4:
重现最新的错误:
从 here 获取 cryptoauthlib|从 here 获取 VisualGDB安装 VS 2017安装 VisualGDB使用 VisualGDB 创建一个新项目 -> CMAKE 项目从 here 下载最新的工具链在 VisualGDB 中使用它添加 cryptoauthlib 作为对项目的引用在项目的CMakeLists.txt中的project()
后添加如下CMAKE命令:
unset(WIN32)
unset(APPLE)
set(UNIX)
set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -fms-extensions -std=c11 -DATCA_HAL_I2C=on -DATCAPRINTF=on")
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -std=c++17 -DATCA_HAL_I2C=on -DATCAPRINTF=on")
构建。
编辑5:
发现我必须在我的 CMAKE 项目中显式地执行 set(ATCA_HAL_I2C TRUE)
...作为一个选项,它对我不起作用,不幸的是。
现在我在这里再次遇到段错误:
ATCA_STATUS atcab_random(uint8_t *rand_out)
{
...
ATCACommand ca_cmd = _gDevice->mCommands;
...
}
我将其打开为 issue在 github 上。
最佳答案
我发现了错误。硬件抽象层无法连接,因为 i2c 总线 .atcai2c.bus
的默认总线设置设置为 2,它需要为 1,否则将找不到 i2c 设备。
ATCAIfaceCfg cfg_ateccx08a_i2c_default = {
.iface_type = ATCA_I2C_IFACE,
.devtype = ATECC608A,
.atcai2c.slave_address = 0xC0,
.atcai2c.bus = 1,
.atcai2c.baud = 400000,
//.atcai2c.baud = 100000,
.wake_delay = 1500,
.rx_retries = 20
};
我现在可以通过以下方式从芯片中获取修订版、序列号和随机数:
#include <iostream>
#include "cryptoauthlib.h"
int main(int argc, char *argv[])
{
ATCAIfaceCfg *atca_cfg;
atca_cfg = &cfg_ateccx08a_i2c_default;
ATCA_STATUS status = atcab_init(atca_cfg);
std::cout << "status: " << (int)status << std::endl;
uint8_t revision[4];
status = atcab_info(revision);
if (status != ATCA_SUCCESS)
{
return -1;
}
std::cout << "revision: " << (int)revision << std::endl;
uint8_t serial[ATCA_SERIAL_NUM_SIZE];
status = atcab_read_serial_number(serial);
if (status != ATCA_SUCCESS)
{
return - 1;
}
std::cout << "serial: " << (int)serial << std::endl;
uint8_t num[32];
status = atcab_random(num);
if (status != ATCA_SUCCESS)
{
return - 1;
}
std::cout << "random: " << (int)num << std::endl;
return 0;
}
我会在 github 上继续这个。
关于c++ - Cryptoauthlib - 匿名 union 只能有非静态数据成员 - 段错误,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/53817885/
关闭。这个问题是opinion-based .它目前不接受答案。 想要改进这个问题? 更新问题,以便 editing this post 可以用事实和引用来回答它. 关闭 5 年前。 Improve
在 C# 静态方法中是否有一种方法可以引用定义该方法的类型? 在实例方法中,您可以通过以下方式确定类型: public void Foo() { Type type = this.GetTyp
WPF:静态、动态资源以及资源词典 静态资源与动态资源 我们常常会使用样式或者控件模板放在Window.Resources中,比如这样: 静态资源与动态资源使用如下: <Window
任何人都知道如何在共享/静态函数中动态加载控件?该函数本身位于 mustinherit/abstract 类中。 (这是 VB 中的 ASP.NET 项目)我想做这样的事情: VB: Publ
在我看来,静态/强类型编程语言最宝贵的一点是它有助于重构:如果/当您更改任何 API,那么编译器会告诉您该更改破坏了什么。 我可以想象用运行时/弱类型语言编写代码......但我无法想象没有编译器的帮
正如我的名字所暗示的,我是一名 .NET 开发人员,但我对 Java 的兴趣越来越大,并且我有兴趣学习更多其他语言,因为这有助于我学习更多关于编程的知识。 无论如何,我的问题是:不带参数/不使用状态的
我在java中使用WireMock来 stub POST请求。该请求返回一个存储在我本地的 json 正文文件。 stub 看起来像这样: wireMockServer.stubFor(get(url
Python 是否有类构造函数的机制,即每当首次引用类时(而不是创建该对象的实例时)调用的函数?我知道其他一些语言中也存在这种情况,但我还没有在 Python 中遇到过。 基本上,我想初始化该函数中的
Python 是否有类构造函数的机制,即每当首次引用类时(而不是创建该对象的实例时)调用的函数?我知道其他一些语言中也存在这种情况,但我还没有在 Python 中遇到过。 基本上,我想初始化该函数中的
这个问题已经有答案了: What is the difference between dynamic and static polymorphism in Java? (14 个回答) 已关闭 4 年
这个问题已经有答案了: 已关闭10 年前。 Possible Duplicate: Static initializer in Java 我想知道这个静态的东西(抱歉,这是我第一次遇到这个)对一个类有
如果c++应用程序是按以下方式组织的 //file1.cpp static Y sgObj = X::getInitObject(0); //declared in file scope //fil
我有一个抽象类(AvergedDataRecord),我需要进一步抽象(DataRecord),这样我就可以将它扩展到原始类和一个新的具体类(SummedDataRecord),并且我在获取某些方法时
我正在尝试制作一个字符串枚举。这是我到目前为止所得到的, private class TypedEnum : IEnumerable { public IEnumerator GetEnume
我选修了一门名为“安全代码”的类(class),在下一个作业中,我们应该对一些 C 文件和 JavaEE Web 项目进行静态/动态分析。 我检查了“源监视器”并在 C 文件上运行它,但是(除非我不知
我有两个类,一个是登录类,一个是用户类。在 loggedIn 类中,我想显示我在用户登录时所做的共享首选项。 loginPrefs = getSharedPreferences("loginprefe
我在同一个 Activity 中有两个静态 fragment ,在“fragmentA”中我有一个自定义列表,当一个项目被点击时必须在“fragmentB”中出现一个细节,细节只在我改变屏幕方向时出现
在 Java 中是未修改方法变量,缺少final,每次都重新初始化限定符 静态方法 实例方法 如果 1. 或 2.(或两者)的答案是 final 限定符允许 Java 执行优化并存储方法变量只有一次?
我有两个类相互交互。第一个是中心的,如下: public class Datenbank { double winkelPanel = 0; double groessePanel = 0; doub
我有一个 mysql 数据库,它连接基于 Web 的 php 应用程序和 FoxPro 应用程序(是的,foxpro)。在之前的“开发人员”被解雇后开始处理这个问题。 无论如何,我熟悉 AES_Enc
我是一名优秀的程序员,十分优秀!