#define MAXITEM 20
int split(char *str, const char *delim, char *outlist[]){
char *tk;
int cnt = 0;
tk = strtok(str, delim);
while(tk != NULL && cnt < MAXITEM){
outlist[cnt++] = tk;
// pc.printf("line(%d) = %s\r\n", cnt, outlist[cnt - 1]);
tk = strtok(NULL, delim);
}
return cnt;
}
void onGsReceive (int cid, int len) {
int i;
char buf[GS_DATA_SIZE + 1];
char *buf2[MAXITEM];
int buf2_c;
myled2 = 1;
i = gs.recv(cid, buf, len);
buf[i] = 0;
buf2_c = split(buf, "\r\n", buf2);
/*
pc.printf("buf2_c=%d\r\n", buf2_c);
for(int c = 0; c < buf2_c; c++){
pc.printf("buf2[%d] = %s\r\n", c, buf2[c]);
}
*/
if(buf2_c){
pc.printf("No. %s\r\n", buf2[buf2_c - 1]);
switch(atoi(buf2[buf2_c - 1])){
case 1:
Red = 1;
Blue = 0;
Green = 0;
break;
case 2:
Red = 0;
Blue = 1;
Green = 0;
break;
case 3:
Red = 0;
Blue = 0;
Green = 1;
break;
}
}
pc.printf(buf);
pc.printf("\r\n");
myled2 = 0;
}
int split(char *str, const char *delim, char *outlist[]){
char *tk;
int cnt = 0;
tk = strtok(str, delim);
while(tk != NULL && cnt < MAXITEM){
outlist[cnt++] = tk;
// pc.printf("line(%d) = %s\r\n", cnt, outlist[cnt - 1]);
tk = strtok(NULL, delim);
}
return cnt;
}
void onGsReceive (int cid, int len) {
int i;
char buf[GS_DATA_SIZE + 1];
char *buf2[MAXITEM];
int buf2_c;
myled2 = 1;
i = gs.recv(cid, buf, len);
buf[i] = 0;
buf2_c = split(buf, "\r\n", buf2);
/*
pc.printf("buf2_c=%d\r\n", buf2_c);
for(int c = 0; c < buf2_c; c++){
pc.printf("buf2[%d] = %s\r\n", c, buf2[c]);
}
*/
if(buf2_c){
pc.printf("No. %s\r\n", buf2[buf2_c - 1]);
switch(atoi(buf2[buf2_c - 1])){
case 1:
Red = 1;
Blue = 0;
Green = 0;
break;
case 2:
Red = 0;
Blue = 1;
Green = 0;
break;
case 3:
Red = 0;
Blue = 0;
Green = 1;
break;
}
}
pc.printf(buf);
pc.printf("\r\n");
myled2 = 0;
}