00001 #include "auc-cd.h"
00002
00003 int is_numeric(const char *p) { int i = strlen(p),j=0;
00004 if (*p) {
00005 char c;
00006 while ((c=*p++)) { j++;
00007 if (!isdigit(c)) {
00008 if (j == i) return 2;
00009 else return 0;
00010 }
00011 }
00012 return 1;
00013 }
00014 return 0;
00015 }
00016 void mdCommander::driver() {
00017
00018 bool rc;
00019 char instrinsic[16],next,rawString[256],work[256];
00020 const char *mdErrCode = "";
00021 int i,commandLength;
00022
00023 greet();
00024 while(acceptingInput) {
00025 putchar('>');
00026 next=0;
00027 i=0;
00028 memset(rawString,0,sizeof(rawString));
00029 while(next != '\012') {
00030 next = getchar();
00031 rawString[i++] = next;
00032 if (i > (sizeof(rawString) - 1)) {
00033 puts("Max length exceeded!");
00034 continue;
00035 }
00036 }
00037 if (!strlen(rawString)) continue;
00038 if (rawString[0] == '?') {
00039 help();
00040 continue;
00041 }
00042 if (is_numeric(rawString) == 2) {
00043 rawString[strlen(rawString)] = 0;
00044 mdStdDevIdx = atoi(rawString);
00045 continue;
00046 }
00047 if (strlen(rawString) >= 4 && strlen(rawString) <= 6 )
00048 {if (!strcmp(rawString,"log\n")) {
00049 system("less /tmp/auc-cd.log");
00050 continue;
00051 }
00052 if (!strcmp(rawString,"rlog\n")) {
00053 system(PULL_MD_LOG);
00054 system("less auc-md.log");
00055 continue;
00056 }
00057 if (!strcmp(rawString,"clips\n")) {
00058 continue;
00059 }
00060 if (!strcmp(rawString,"done\n")) {
00061 return;
00062 }
00063 if (!strcmp(rawString,"mdapi\n")) {
00064 system("mdclient ");
00065 continue;
00066 }
00067 if (!strcmp(rawString,"quit\n")) {
00068 thisConfig->terminateRequest = true;
00069 return;
00070 }
00071 if (!strcmp(rawString,"mdapi\n")) {
00072 continue;
00073 }
00074 if (strlen(rawString) < 3) {
00075 puts("That SCPI command is too short!");
00076 continue;
00077 }
00078 rc = scpi(rawString);
00079 if (!rc) puts("Command transmitted: OK.");
00080 else printf("Command result: %s.",mdErrCode);
00081 continue;
00082 }
00083 }
00084
00085 }
00086 void mdCommander::greet() {
00087
00088 puts("auc-cd command processor");
00089 puts("Enter ? for help or a cliever low level command");
00090 acceptingInput = true;
00091 SCPImode = true;
00092 currentDevice = std::string("ALX");
00093
00094 }
00095 void mdCommander::help() {
00096
00097 const char *banner = "\n" CD_NAME " " CD_VERSION " compiled on " __DATE__ " @ " __TIME__ " (%d)\n";
00098
00099 system("clear");
00100 printf(banner,thisConfig->shellProcess);
00101 printf("Target mdStdDevIdx: %d (0: Master Daemon(MD), 1: Cliever(CD))\n",mdStdDevIdx);
00102 puts("LL (low level) Cliever commands: \n");
00103 puts(" ? - display this screen");
00104 puts(" <n> - make <n> (an integer) the target mdStdDevIdx");
00105 if (*cdOrKb == 'd')
00106 {puts(" clips - character UI on this active rulebase");
00107 puts(" xclips - GUI on this active rulebase via an X server");
00108 puts(" xhost - set the xserver (current: localhost:0)");
00109 }
00110 puts(" done - terminate the command loop but not auc-cd");
00111 puts(" log - display this cliever log");
00112 puts(" rlog - pull and display the MD log");
00113 puts(" mdapi - run mdclient here (xmlrpc-c must be installed)");
00114 printf(" quit - terminate %s (if in md shell CTL-C if finished)\n\n",thisConfig->origCmd);
00115 puts("Anything else is a SCPI cmd for the current target device.");
00116 puts("If the device responds it should show in the log if debug level high enough.\n");
00117 if (*cdOrKb == 'd') {
00118 puts("In the character mode UI:");
00119 puts(" Enter (help) in the rules system for more help.");
00120 puts(" Enter (exit) in the rules system to return here.\n");
00121 }
00122 puts("If in md shell, 'RST' and 'quit' resets the servers for this Cliever group");
00123 puts("(i.e. if the mdStdDevIdx is 0;used to get a fresh epoch with MD");
00124 puts(" and CD initialized and connected for device and data client testing).\n");
00125 puts("NB: USE LL SCPI COMMANDS FOR DEVICE DEV ONLY -\n");
00126 puts("Sending device commands at this level is potentially dangerous and is ");
00127 puts("only for device development. Other users should issue commands using the");
00128 puts("data client XMLRPC API, e.g. thru mdclient which uses the current best");
00129 puts("proven rulebase (when MD is running as daclips-md).");
00130
00131 }
00132 bool mdCommander::scpi(char *cmd) {
00133
00134 char *command,work[256];
00135 bool isDirect=false,rc=true;
00136
00137 if (!mdStdDevIdx && !strncmp(cmd,"RST",3)) {
00138
00139 mdDG mdg;
00140
00141 mdg.dg.hdr.sourceHandle = thisCliever->myHandle;
00142 mdg.dg.hdr.payloadSize = 0;
00143 mdg.dg.hdr.msgType = MDDG_CDRESET;
00144 if (thisCliever->fg->send(mdg.dg)) rc = false;
00145
00146 }
00147
00148 return rc;
00149
00150 }
00151