📄 sendone.c
字号:
/*ダイレクトコントロ〖ルモ〖ドでロボットを拎侯するためのプログラムコマンドラインに、1乖の办忍コマンドを掐蜗すると、それを豺老して鼎铜メモリのダイレクトコントロ〖ルモ〖ド脱バッファに今き哈む。*/#include <stdio.h>#include <string.h>#include <stdlib.h>#include <sys/time.h>#include <sys/types.h>#include <unistd.h>/*鼎铜メモリ脱*/#include <mbuff.h>#include <MemMan.h>#define NAME_OF_MEMORY "DataSharedMemory"SM* pSM;#include "sm_access.h"#define COMMANDLEN 4096void usage();int readret(DUNIT* unit);int main(int argc, char *argv[]){ char buf[COMMANDLEN]; int ret; DUNIT *unit;// printf("program write_SM.\n"); //鼎铜メモリアロケ〖ション pSM = (SM*) mbuff_alloc(NAME_OF_MEMORY, \ sizeof(SM)); if(pSM == NULL) { perror("mbuff_alloc failed"); return -1; } // pSM->VarIF.ResInt = 1; for(;;) { /*办忍コマンドデ〖タ奶慨窗位フラグをチェック*/// if(pSM->VarIF.ResInt == 1) { printf("command:"); /*コマンドラインからの办忍コマンドの掐蜗を略つ*/ if( NULL == fgets(buf, COMMANDLEN, stdin)) { break; } printf("%s", buf); if(strncmp(buf, "q", 1) == 0) { break; } /*办忍コマンドを鼎铜メモリの面のData.IntDat (ダイレクトコントロ〖ルモ〖ド脱バッファ)にセットする*/ unit = (DUNIT*)&(pSM->Data.IntDat); ret = send_sm(buf, unit); if(ret < 0) { usage(); } else { /*办忍コマンドデ〖タ奶慨窗位フラグをクリア*/ pSM->VarIF.ResInt = 0; pSM->VarIF.Mode = IDLE; /*インタ〖ラプトフラグをONにして、 ダイレクトコントロ〖ルモ〖ドの悸乖を回绩する*/ pSM->VarIF.InterruptSend = TRUE; //watch return printf("waiting for return...\n"); readret(unit); }// } } /*メモリ倡庶*/ mbuff_free(NAME_OF_MEMORY, (void*)pSM); return 0;}void usage(){ printf("command:<Step> <Header> <param>...\n"); printf(" : send <Step> 3 <DevID> <CmdAsc> <Arg1>...\n");}int readret(DUNIT* unit){ fd_set rfds; struct timeval tv; int retval; int i; for(;;) { FD_ZERO(&rfds); FD_SET(0, &rfds); tv.tv_sec = 0; tv.tv_usec = 0; retval = select(1, &rfds, NULL, NULL, &tv); if(retval) {// break; printf("canceled\n"); return -1; } if(pSM->VarIF.ResInt) { break; } } printf("Return: "); for(i = 0; i < SnsResMax; i++) { //test// unit->Cmd.ResB[i] = i; printf("%2x ", unit->Cmd.ResB[i]); } printf("\n"); return 0;}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -