-
Notifications
You must be signed in to change notification settings - Fork 0
/
blueReceiv.c
43 lines (35 loc) · 985 Bytes
/
blueReceiv.c
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
#define MaxSizeOfMessage 35// 34 byte of data max (+ terminator)
const TMailboxIDs queue = mailbox1;//the mailbox where the PC will send the message
void readDataMsg()
{
int mSizeOfMessage = cCmdMessageGetSize(queue);
ubyte mBuffer[MaxSizeOfMessage];// no malloc with RobotC :(
if (mSizeOfMessage <= 0)//there's no message
{
wait1Msec(1);//wait before we check again
return;
}
if (mSizeOfMessage > MaxSizeOfMessage)// shouldn't happen but well, then we'll only read the first part of the message
{
mSizeOfMessage = MaxSizeOfMessage;
}
if (cCmdMessageRead(mBuffer, mSizeOfMessage, queue) == ioRsltSuccess)//we've successfully copied the message
{
mSizeOfMessage -= 1;// skip the terminator
// do whatever you want here
for (int i = 0; i < mSizeOfMessage; i++)
{
nxtDisplayBigTextLine(2," %d ", mBuffer[i]);
wait(2);
}
}
return;
}
task main ()
{
eraseDisplay();
while (true)
{
readDataMsg();
}
}