- android - 多次调用 OnPrimaryClipChangedListener
- android - 无法更新 RecyclerView 中的 TextView 字段
- android.database.CursorIndexOutOfBoundsException : Index 0 requested, 光标大小为 0
- android - 使用 AppCompat 时,我们是否需要明确指定其 UI 组件(Spinner、EditText)颜色
我有 3 个完全相同的 PCB 容纳 ATmega2560 MCU。我将 Atmel Studio 7 用于 fuse 和闪烁 HEX。我正在使用 Visual Studio 和 Visual Micro 插件,混合使用 C 和 Arduino 编码。
我有一个结构数组定义。我将数据从 MCU 串行端口提供的 json 填充到这个结构数组中。 Json 解析器是 ArduinoJson。
定义:
#define MAX_RECORDS 20 //Max number of records in the struct
typedef struct Record {
uint8_t id;//unique number to define data sequence
uint8_t sec;
uint8_t obj;
uint16_t xs;
uint16_t ys;
uint16_t xe;
uint16_t ye;
uint8_t clr;
uint8_t tsz;
uint8_t tid;
} tRecord;
struct Record recordsOut[MAX_RECORDS];
主循环:
void loop() {
if (IsNetworkAlertState == 0) {
if (setupProg[0].gid == 255 || setupProg[0].bnr == 255 || recordsOut[0].id == 255) {
if (IsNoSetupAlertState == 0) {
IsNoSetupAlertState = 1;
}
}
else {
if (IsNoSetupAlertState == 1) {
IsNoSetupAlertState = 0; // Nothing to alert
RefreshScreen(); //Redraw data on screen after the setup is done!
}
}
}
}
从串行接收的示例数据:
const char* json = "{\"id\":1,\"sec\":1,\"obj\":1,\"xs\":1,\"ys\":0,\"xe\":158,\"ye\":62,\"clr\":0,\"tsz\":0,\"tid\":-1}";
来电者:
为了存储所有数据,这可能会被调用 20 次。最后写入非 volatile 存储器。
ApplyDesignSettings(json);
存储传入数据的函数:
void ApplyDesignSettings(char buffer[]) {
const size_t bufferSize = JSON_OBJECT_SIZE(10) + 70;
DynamicJsonBuffer jsonBuffer(bufferSize);
if (IsDebugOn == 1) {
Serial.print("buffer:");
Serial.println(buffer);
}
JsonObject& root = jsonBuffer.parseObject(const_cast<char*>(buffer));
if (!root.success()) {
Serial.println("parseObject() failed#1");
return;
}
uint8_t id = root["id"];
uint8_t sec = root["sec"];
uint8_t obj = root["obj"];
uint16_t xs = root["xs"];
uint16_t ys = root["ys"];
uint16_t xe = root["xe"];
uint16_t ye = root["ye"];
uint8_t clr = root["clr"];
uint8_t tsz = root["tsz"];
uint8_t tid = root["tid"];
int ref = id;
int idx = ref - 1;
recordsOut[idx].id = id;
recordsOut[idx].sec = sec;
recordsOut[idx].obj = obj;
recordsOut[idx].xs = xs;
recordsOut[idx].ys = ys;
recordsOut[idx].xe = xe;
recordsOut[idx].ye = ye;
recordsOut[idx].clr = clr;
recordsOut[idx].tsz = tsz;
recordsOut[idx].tid = tid;
}
到目前为止一切顺利。到目前为止我对此很满意。这里是“但是”;
有时,在刷新一些 ATmega2560 并推送上述数据后,它会丢失/覆盖/删除 struct 数组的第一个索引,我发现它是空的 (255)尽管其余记录都很好。
这是结果:
通过 for-loop 调试,我得到了下面的结果。这只发生在某些 ATmega2560 上。
(注意:在 ID:8(索引 7)之后都是空的,这在这个给定的样本中是预期的)
========================================
Design data in non-volatile memory:
========================================
id:255, sec:255, obj:255
id:2, sec:1, obj:2
id:3, sec:1, obj:3
id:4, sec:1, obj:3
id:5, sec:2, obj:1
id:6, sec:2, obj:2
id:7, sec:2, obj:3
id:8, sec:2, obj:3
id:255, sec:255, obj:255
id:255, sec:255, obj:255
id:255, sec:255, obj:255
id:255, sec:255, obj:255
id:255, sec:255, obj:255
id:255, sec:255, obj:255
id:255, sec:255, obj:255
id:255, sec:255, obj:255
id:255, sec:255, obj:255
id:255, sec:255, obj:255
id:255, sec:255, obj:255
id:255, sec:255, obj:255
========================================
一般第一个索引应该是这样的;
id:1, sec:1, obj:1
我希望我能解释清楚,让您知道哪里出了问题?
感谢您从现在开始的投入。
最佳答案
最终在将代码(将近 2000 行)缩小到某个点后,我可以解决它。还要感谢@Andy 帮助我继续在这个问题上四处寻找。
在 Loop
的 Else
中,RefreshScreen();
再次从 EEPROM
重新加载 recordsOut,这正在覆盖 struct array recordsOut
和下一轮 JSON,数据从那里继续。
我已经从 RefreshScreen();
中删除了 EEPROM 读取功能,它已经开始工作了。
关于c++ - 某些 ATmega 2560 的第一个索引中的结构数组数据被重置,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/48284856/
我目前正在尝试基于哈希表构建字典。逻辑是:有一个名为 HashTable 的结构,其中包含以下内容: HashFunc HashFunc; PrintFunc PrintEntry; CompareF
如果我有一个指向结构/对象的指针,并且该结构/对象包含另外两个指向其他对象的指针,并且我想删除“包含这两个指针的对象而不破坏它所持有的指针”——我该怎么做这样做吗? 指向对象 A 的指针(包含指向对象
像这样的代码 package main import "fmt" type Hello struct { ID int Raw string } type World []*Hell
我有一个采用以下格式的 CSV: Module, Topic, Sub-topic 它需要能够导入到具有以下格式的 MySQL 数据库中: CREATE TABLE `modules` ( `id
通常我使用类似的东西 copy((uint8_t*)&POD, (uint8_t*)(&POD + 1 ), back_inserter(rawData)); copy((uint8_t*)&PODV
错误 : 联合只能在具有兼容列类型的表上执行。 结构(层:字符串,skyward_number:字符串,skyward_points:字符串)<> 结构(skyward_number:字符串,层:字符
我有一个指向结构的指针数组,我正在尝试使用它们进行 while 循环。我对如何准确初始化它并不完全有信心,但我一直这样做: Entry *newEntry = malloc(sizeof(Entry)
我正在学习 C,我的问题可能很愚蠢,但我很困惑。在这样的函数中: int afunction(somevariables) { if (someconditions)
我现在正在做一项编程作业,我并没有真正完全掌握链接,因为我们还没有涉及它。但是我觉得我需要它来做我想做的事情,因为数组还不够 我创建了一个结构,如下 struct node { float coef;
给定以下代码片段: #include #include #define MAX_SIZE 15 typedef struct{ int touchdowns; int intercepti
struct contact list[3]; int checknullarray() { for(int x=0;x<10;x++) { if(strlen(con
这个问题在这里已经有了答案: 关闭 11 年前。 Possible Duplicate: Empty “for” loop in Facebook ajax what does AJAX call
我刚刚在反射器中浏览了一个文件,并在结构构造函数中看到了这个: this = new Binder.SyntaxNodeOrToken(); 我以前从未见过该术语。有人能解释一下这个赋值在 C# 中的
我经常使用字符串常量,例如: DICT_KEY1 = 'DICT_KEY1' DICT_KEY2 = 'DICT_KEY2' ... 很多时候我不介意实际的文字是什么,只要它们是独一无二的并且对人类读
我是 C 的新手,我不明白为什么下面的代码不起作用: typedef struct{ uint8_t a; uint8_t* b; } test_struct; test_struct
您能否制作一个行为类似于内置类之一的结构,您可以在其中直接分配值而无需调用属性? 前任: RoundedDouble count; count = 5; 而不是使用 RoundedDouble cou
这是我的代码: #include typedef struct { const char *description; float value; int age; } swag
在创建嵌套列表时,我认为 R 具有对列表元素有用的命名结构。我有一个列表列表,并希望应用包含在任何列表中的每个向量的函数。 lapply这样做但随后剥离了列表的命名结构。我该怎么办 lapply嵌套列
我正在做一个用于学习目的的个人组织者,我从来没有使用过 XML,所以我不确定我的解决方案是否是最好的。这是我附带的 XML 文件的基本结构:
我是新来的 nosql概念,所以当我开始学习时 PouchDB ,我找到了这个转换表。我的困惑是,如何PouchDB如果可以说我有多个表,是否意味着我需要创建多个数据库?因为根据我在 pouchdb
我是一名优秀的程序员,十分优秀!