类和构造函数中的函数根本不起作用,并且不返回任何错误
Functions inside class and constructor don't work at all and don't return any errors
TL;DR:我在 ESP32 上有以下类,但功能无法按预期工作:
class Wiegand {
private:
std::vector<bool> _array{0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0};
uint8_t facilityCode = 0;
uint16_t cardNumber = 0;
void calculate(uint32_t decimal) {
for (uint8_t i = 23; i >= 0; --i) {
_array[i] = decimal & 1;
decimal >>= 1;
}
}
public:
Wiegand(uint32_t id) {
calculate(id);
facilityCode = id >> 16;
cardNumber = id & 0xffff;
}
std::vector<bool> getCardID() {
return _array;
}
uint8_t getFacilityCode() {
if(facilityCode == 0) {
return 0;
}
return facilityCode;
}
uint16_t getCardNumber() {
if(cardNumber == 0) {
return 0;
}
return cardNumber;
}
};
下面的代码没有输出任何东西:
Wiegand card(86840);
std::vector<bool> cardID = card.getCardID();
for(bool i : cardID) {
Serial.print(i);
}
int foo = card.getFacilityCode();
Serial.println(foo);
Serial.println(card.getCardNumber());
说来话长:
我正在尝试将 1 和 2^24-1 范围内的任何十进制数转换为我放入cardID
的 24 位二进制数。
例如:86840
应返回000000010101001100111000
。接下来,我想获取first 8 bits
和last 16 bits
,将它们转换为decimal
形式并将它们存储在其他变量中。现在剩下的事情是按照韦根协议,将整个二进制数并添加其奇偶校验位以将其转换为 26 位韦根数。
对于无符号变量,这是无限循环,因为无符号变量总是零或更多:
for (uint8_t i = 23; i >= 0; --i)
相反,请使用例如:
for (uint8_t i = 23; i + 1 > 0; --i)
相关文章:
- (C++)分析树以计算返回错误值的简单算术表达式
- glad 导致 glfwSwapBuffers 返回错误消息
- 我的模板类方法返回错误类型?
- 共享内存:MapViewOfFile 返回错误 5
- 使用 std::forward_list 返回错误的队列实现
- FFMPEG:sws_scale返回错误:切片参数 0, 2160 无效
- __int64 CString 返回错误的值 - C++ MFC
- C++ OpenGL 中,绘制形状返回错误
- Python os.system() 返回错误值
- 函数从指针 c++ 中获取错误的值并返回错误的答案
- LibClang clang_getArgType() 返回错误的类型
- 除法函数返回错误的值
- 当命令失败时,gzip 会在 C++ 中返回错误代码吗?
- 矩阵逆变器返回错误的反转
- openCL-创建子缓冲区返回错误代码13
- Qt SQL LIKE语句返回错误
- GetLastError()从FtpPutFile()返回错误6
- PfCreateInterface返回错误120(未实现)
- 为什么 Pa_GetStreamTime() 返回错误?
- G++ 在尝试使用 G++ 使用 openCV 进行编译后返回错误