I took my program and abbreviated some parts. Still I'm not sure if it counts as pseudocode. Here it is.
#include "mbed.h"
const int BUFFERSIZE = 1024;
int buffer[BUFFERSIZE];
int UTC[10];
int lat[10];
int ns;
int lon[10];
int ew;
int posfix;
int numsats[2];
Serial pc(p9, p10);
Serial gps(p13, p14);
int findStart(int pos)
{
for(int i = pos; i < BUFFERSIZE; i++)
{
if buffer[pos to pos+5] == “$GP”
return pos + 5;
else
return BUFFERSIZE;
}
return BUFFERSIZE;
}
bool code(int pos, char c[3])
{
if(buffer[pos to pos + 2]==c)
return true;
else
return false;
return false;
}
void loadVariables(int pos)
{
assign variables based on relative position to pos
}
void displayVariables()
{
for every variable
print description + value;
}
void parsebuffer()
{
int pos = 0; // current read position in the buffer
while (pos < BUFFERSIZE - 1)
{
pos = findStart(pos);
if(pos > BUFFERSIZE - 50) return;
bool codeknown = true;
if (found “GGA”)
{
pc.printf("Found GGA\r\n");
loadVariables(pos+3);
displayVariables();
}
else if (found “GLL”)
{
pc.printf("Found GLL\r\n");
}
else
codeknown = false;
if(!codeknown)
print code found
}
}
int main() {
pc.baud(4800);
pc.format(8,Serial::None,1);
gps.baud(4800);
gps.format(8,Serial::None,1);
pc.putc(0x0c);
while(1) {
put data from GPS into array
parsebuffer();
pc.printf("\r\npress a key to continue\r\n");
pc.getc();
}
}
Pseudocode is anything between code and natural language. I argue it is more beneficial if it isn't so strictly defined in order to have freedom in how to use it. I use it myself to make a short version of what certain code should do, if i expect I may loose my thoughts on what I want to do, or how I want to do something. So my answer is yes, if it helps memorize / define what you are doing.
In some languages you add two slashes for your pseudocode so you comment it out. and add TODO in front if you want to point out you want to code it out still.
//TODO make a function to compute the average height of sample.
//for every individual
// obtain the height, store heights in some variable.
//compute average of all heights
精彩评论