#include<conio.h> #include<unistd.h> #include<lnp/lnp.h> // link networking protocol function is inclued tid_t t_stop; int stop(){ // rcx stop function int stopchar; stopchar=getchar(); if(stopchar==KEY_RUN){ cputs("stop"); killall(20); } return 0; } int main(int argc,char **argv){ t_stop=execi(&stop,0,NULL,20,DEFAULT_STACK_SIZE); char sendmsg; cputs("send"); while(1){ sendmsg='a'; // set message send_msg(sendmsg); // send message cputs("sn a"); sleep(3); sendmsg='b'; // set message send_msg(sendmsg); // send message cputs("sn b"); sleep(3); } return 0; } |
#include<conio.h> #include<unistd.h> #include<lnp/lnp.h> // link networking protocol function is inclued tid_t t_stop; int stop(){ // rcx stop function int stopchar; stopchar=getchar(); if(stopchar==KEY_RUN){ cputs("stop"); killall(20); } return 0; } int main(int argc,char **argv){ char getmsg[4]; t_stop=execi(&stop,0,NULL,20,DEFAULT_STACK_SIZE); while(1){ getmsg[0]=get_msg(); // get message cputs(&getmsg); } return 0; } |
//! read received message from standard firmware extern inline unsigned char get_msg(void) { clear_msg(); wait_event(msg_received, 0); return lnp_rcx_message; } |
では、これらを使って先ほどと同じ動作をするプログラムを作ってみます。
次のプログラムを作成してください。ここでは作成ファイル名をirc_get2.cとします。
作成したプログラムirc_get2.c
#include<conio.h> #include<unistd.h> #include<lnp/lnp.h> // link networking protocol function is inclued wakeup_t irc_wakeup(wakeup_t data); // ir message check int main(int argc,char **argv){ char getmsg; while(1){ clear_msg(); wait_event(&irc_wakeup,0); cputs(&lnp_rcx_message); } return 0; } wakeup_t irc_wakeup(wakeup_t data){ // ir message check return lnp_rcx_message!=0; } |