【发布时间】:2019-04-03 15:25:31
【问题描述】:
我无法完全搜索我想要的东西,因为我不确定如何解决我想要做的事情,所以我只是描述一下。我认为并不真正需要有关 mbed 的知识,因为我无法解释那部分。
我的 mbed 程序中有一个中断函数,每次从 pc 上的串行链路输入时都会执行该函数。
Serial pc(USBTX,USBRX); //makes a serial link with pc
int main() {
pc.attach(&newCommand); //everytime input from pc is detected, this interrupt will make scheduler go to function called 'newCommand'
//here, fetch one array of chars to work with, the oldest in the queue and analyse the command. If there is none available, wait for one to become available
}
void newCommand() {
int inputCount = 0;
int inputBuff[64];
while (pc.readable()) { //check if there is anything to read
if (inputCount < 64) // check for buffer overflow, maximum 64 ints
inputBuff[inputCount] = pc.getc();
else
pc.getc(); // ran out of space, just throw the data away.
inputCount++;
}
//store this char array (inputBuff) in a sort of queue, with the oldest at the front
}
我会寻找什么样的队列?我在想也许我可以有一个全局的向量容器,它存储这些数组,然后主程序获取最旧的一个,但我不确定如何做到这一点?
编辑:我想我也可以做一个向量而不是数组来存储字符,如 someVect.push_back(pc.getc())。这样会更容易存储在向量类型的队列中吗?
【问题讨论】:
标签: c++ serial-port c++98 mbed