我需要一些帮助来从 SD 卡中提取数据,我基于本节中的代码。
当我从 SD 卡读取数据并将其显示到串行端口时,代码有效,但是当我将数据传递到 char* 数组并调用将循环数组的函数时,数组显示垃圾(一些不可读的数据) . 我正在尝试制作一个函数,可以用来调用以文本文件格式从 SD 卡存储的不同设置。
我有一个名为的全局变量:
char* tempStoreParam[10];
它将存储要处理的临时数据。文本文件中存储的数据就是这种格式
-n.command
其中: n = int 数和要存储在tempStoreParam[10]
and 命令中的数据的索引位置是要存储在 中的 char* 数组tempStoreParam[10]
。
例子:
-1.readTempC
-2.readTempF
-3.setdelay:10
-4.getIpAddr
这是代码片段:
while (sdFiles.available()) {
char sdData[datalen + 1];
byte byteSize = sdFiles.read(sdData, datalen);
sdData[byteSize] = 0;
char* mList = strtok(sdData, "-");
while (mList != 0)
{
// Split the command in 2 values
char* lsParam = strchr(mList, '.');
if (lsParam != 0)
{
*lsParam = 0;
int index = atoi(mList);
++lsParam;
tempStoreParam[index] = lsParam;
Serial.println(index);
Serial.println(tempStoreParam[index]);
}
mList = strtok(0, "-");
}
}
我试图得到以下结果:
char* tempStoreParam[10] = {"readTempC","readTempF","setdelay:10","getIpAddr"};