예제 #1
0
Status_t Do_IR_Debug(Cmd_Tbl_t *Cmd_Tbl, uint32 flag, uint32 argc, char *argv[])
{
  FuncIN(DO_IR_DEBUG);
  
  if(argc > 0)
  {
    switch(atoi(argv[0]))
    {
      case 0:
        IR_Received_Debug_Set_State(DISABLE);
        printcmd("\r # IR Received sequence debug Disabled!\n");
        break;
      case 1:
        printcmd("\r # IR Received sequence debug Enabled!\n");
        IR_Received_Debug_Set_State(ENABLE);
        break;
      default:
        EXIT_FUNC(CMD_INVALID_ARGUMENT, DO_IR_DEBUG);
    } // switch(argv[0])
  }
  else
    EXIT_FUNC(CMD_MISSING_ARGUMENT, DO_IR_DEBUG);
  
  EXIT_SUCCESS_FUNC(DO_IR_DEBUG);
}
예제 #2
0
pid_t background(char *file, char *argv[])
{
    pid_t pid;

    VERBOSE(printcmd("multirun: backgrounding - %s\n", argv));

#ifdef _WIN32
    {
        char *cmd, *pCmd;
        int i, cmdlen;
        STARTUPINFO si = { 0 };
        PROCESS_INFORMATION pi = { 0 };

        /* convert list of arguments into a command line */
        cmdlen = 1;
        for (i=0; argv[i] != 0; i++) {
            cmdlen += strlen(argv[i]) + 1;
        }
        pCmd = cmd = malloc(cmdlen); /* 1 */
        for (i=0; argv[i] != 0; i++) {
            pCmd += sprintf(pCmd, "%s ", argv[i]);
        }

        /* start the sub-process */
        if (CreateProcess(NULL, cmd, NULL, NULL,
                          TRUE, 0, NULL, NULL, &si, &pi)) {
            pid = pi.hProcess;
        } else {
            pid = (HANDLE) -1;
        }

        free(cmd); /* 1 */
    }
#else
    {
        int res;

        if (NULL != strstr(file, "sh4xrun")) {
            doFreakyKill = 1;
        }

        pid = fork();
        if (0 == pid) {
            res = execvp(file, argv);
            assert(res == -1); /* must have error to run this */
            fprintcmd(stderr,
                      "Error - cannot run sub-process %s", argv);
            fprintf(stderr, " - %s\n", strerror(errno));
            exit(error_code_cannot_exec);
        }
    }
#endif

    VERBOSE(printf("multirun: pid of %s - %d\n", file, pid));

    return pid;
}
예제 #3
0
int builtin_exec_from_history(cmd_t* cmd, job_list_t* jobs, history_t* hist) {
  int index = (int) strtol(cmd->args[0], NULL, 10);
  cmd_t* past_cmd = get_from_history(hist, index);
  if (past_cmd) {
    cmd_t* new_cmd = copycmd(past_cmd);
    printcmd(new_cmd, stdout);
    return executecmd(new_cmd, jobs, hist);
  }
  return COMMAND_NOT_FOUND;
}
예제 #4
0
파일: cmd_ir.c 프로젝트: zare-aw/Smart-Home
Status_t Do_Ir(Cmd_Tbl_t *Cmd_Tbl, uint32 flag, uint32 argc, char *argv[])
{
    FuncIN(DO_IR);

    ir_t IR_Command = {0};
    uint16 i;

    printcmd("\r # Maximum supported general IR commands: %u\n", MAX_IR_COMMANDS - RESERVED_IR_COMMANDS);
    printcmd("\r # IR Commands:\n");

    for(i = 0; i < MAX_IR_COMMANDS; i++)
    {
        VERIFY(IR_Get_Command(i, &IR_Command), -IR_COMMAND_GET_ERROR);
        if((IR_Command.Address != NULL) || (IR_Command.Command != NULL) || (IR_Command.CallMode != NULL) || (IR_Command.Target != NULL))
            printcmd("\r # IR_Command_Number = %u\tAddress = %u\tCommand = %u\tCallMode = %u\tTarget = %u\n", i, IR_Command.Address, IR_Command.Command, IR_Command.CallMode, IR_Command.Target);
    }

    printcmd("\r # Other IR Commands are empty \n");

    EXIT_SUCCESS_FUNC(DO_IR);
}
예제 #5
0
Status_t Do_Try_Read_Time_Response_Cmd(char *argv, TimeAlarm_t *TimeAlarm_p)
{
  FuncIN(DO_TRY_READ_TIME_RESPONSE_CMD);
  
  ASSERT(argv != NULL, -INVALID_INPUT_POINTER);
  ASSERT(TimeAlarm_p != NULL, -INVALID_INPUT_POINTER);
  
  char *CommandString = NULL;
  int i;
  
  CommandString = strstr(argv, "response=");
  if(CommandString != NULL)
  {
    TimeAlarm_p -> Callback = NULL;
    
    CMD_TIMEA_DEBUG(printcmd("\r # (%s) 'response' found!\n", __func__));
    
    for(i = 0; AlarmResponse[i].String != NULL; i++)
    {
      if(!strcmp(AlarmResponse[i].String, CommandString + 9))
      {
        TimeAlarm_p -> Callback = AlarmResponse[i].Callback;
        CMD_TIMEA_DEBUG(printcmd("\r # (%s) 'response' matched to '%s'\n",
                              __func__, AlarmResponse[i].String));
      }
    }
    
    if(TimeAlarm_p -> Callback == NULL)
    {
      printcmd(" # Invalid 'response' parameter!\n");
      EXIT_FUNC(CMD_INVALID_ARGUMENT, DO_TRY_READ_TIME_RESPONSE_CMD);
    }
  } // if(CommandString != NULL)
  
  EXIT_SUCCESS_FUNC(DO_TRY_READ_TIME_RESPONSE_CMD);
}
예제 #6
0
Status_t Do_Set_Time_Alarm_Cmd(TimeAlarm_t *TimeAlarm_p)
{
  FuncIN(DO_SET_TIME_ALARM_CMD);
  
  ASSERT(TimeAlarm_p != NULL, -INVALID_INPUT_POINTER);
  
  CMD_TIMEA_DEBUG(printcmd("\r # (%s) input parameters\n",__func__));
  CMD_TIMEA_DEBUG(printcmd("\r # date = %02u.%02u.%02u\n",  TimeAlarm_p -> DateTime.Day,
                                                            TimeAlarm_p -> DateTime.Month,
                                                            TimeAlarm_p -> DateTime.Year));
  CMD_TIMEA_DEBUG(printcmd("\r # time = %02u:%02u:%02u\n",  TimeAlarm_p -> DateTime.Hour,
                                                            TimeAlarm_p -> DateTime.Minute,
                                                            TimeAlarm_p -> DateTime.Second));
  CMD_TIMEA_DEBUG(printcmd("\r # AlarmID = %u\n", TimeAlarm_p -> AlarmID));
  CMD_TIMEA_DEBUG(printcmd("\r # State = %u\n", TimeAlarm_p -> State));
  CMD_TIMEA_DEBUG(printcmd("\r # Callback = 0x%X\n", TimeAlarm_p -> Callback));
  
  if(TimeAlarm_p -> AlarmID != NO_TIME_ALARM_ID)
  {
    VERIFY(Set_Time_Alarm(TimeAlarm_p), -TIME_SET_ALARM_ERROR);
    printcmd(" # Time Alarm set\n");
  }
  else
  {
    if((TimeAlarm_p -> Callback != NULL) &&
       (TimeAlarm_p -> DateTime.Hour != 0 ||
       TimeAlarm_p -> DateTime.Minute != 0 ||
       TimeAlarm_p -> DateTime.Second != 0))
    {
      VERIFY(Register_Time_Alarm(TimeAlarm_p), -TIME_ALARM_REGISTER_ERROR);
      printcmd("\r # Time Alarm Registered\n");
    }
    else
    {
      printcmd("\r # Time Alarm Not Register\n");
    }
  }
  EXIT_SUCCESS_FUNC(DO_SET_TIME_ALARM_CMD);
}
예제 #7
0
int builtin_history(history_t* hist) {
  // Compute starting index.
  int start = hist->count > MAX_HISTORY ? hist->count - MAX_HISTORY : 0;

  // List them all.
  for (int i = start; i < hist->count; i++) {
    int index = i % MAX_HISTORY;
    cmd_t* cmd = hist->commands[index];
    if (cmd) {
      printf("%5d  ", i + 1);
      printcmd(cmd, stdout);
    } else {
      break;
    }
  }

  // Return success.
  return 0;
}
예제 #8
0
int builtin_jobs(job_list_t* jobs) {
  // List running jobs.
  job_list_t* curr_job_list = jobs;
  while (curr_job_list && curr_job_list->root) {
    // Print current job.
    job_t* curr_job = curr_job_list->root;
    printf("[%d]  + running\t", curr_job->index);
    printcmd(curr_job->cmd, stdout);

    // Update pointer.
    if (curr_job_list->next) {
      curr_job_list = curr_job_list->next;
    } else {
      break;
    }
  }

  // Return success.
  return 0;
}
예제 #9
0
Status_t Do_Time(Cmd_Tbl_t *Cmd_Tbl, uint32 flag, uint32 argc, char *argv[])
{
  FuncIN(DO_TIME);
  
  char String[32] = {0};
  RtcTime_t Time;
  
  RTC_Get_Time(&Time);
  
  if(argc > 0)
  {
    if(strstr(argv[0], "-a") != NULL)
      ASSERT(SUCCESS == Format_Time(2, &Time, String), -RTC_GENERAL_ERROR);
    else
      EXIT_FUNC(CMD_INVALID_ARGUMENT, DO_TIME);
  }
  else
    ASSERT(SUCCESS == Format_Time(1, &Time, String), -RTC_GENERAL_ERROR);
  
  printcmd("\r # %s\n", String);
  
  EXIT_SUCCESS_FUNC(DO_TIME);
}
예제 #10
0
static char *__system(RIO *io, RIODesc *fd, const char *cmd) {
	if (!strncmp (cmd, "?", 1)) {
		eprintf ("dr  : show registers\n");
		eprintf ("dr* : show registers as flags\n");
		eprintf ("drp : show reg profile\n");
		eprintf ("dr8 : show hexpairs with regstate\n");
		eprintf ("ds  : step into\n");
		eprintf ("dp  : show process info\n");
		eprintf ("dc  : continue\n");
		eprintf ("dm  : show maps\n");
		eprintf ("pid : show current process id\n");
	} else if (!strncmp (cmd, "dr8", 3)) {
		struct winedbg_x86_32 r = regState ();
		ut8 *arena = (ut8*)calloc (sizeof (struct winedbg_x86_32), 3);
		if (arena) {
			r_hex_bin2str ((ut8*)&r, sizeof (r), (char *)arena);
			return (char *)arena;
		}
	} else if (!strncmp (cmd, "drp", 3)) {
const char *msg =
"=PC	eip\n"\
"=SP	esp\n"\
"=BP	ebp\n"\
"=A0	eax\n"\
"=A1	ebx\n"\
"=A2	ecx\n"\
"=A3	edx\n"\
"=A4	esi\n"\
"=A5	edi\n"\
"=SN	eax\n"\

"seg	cs	.16	0	0\n"\
"seg	ss	.16	2	0\n"\
"seg	ds	.16	4	0\n"\
"seg	es	.16	6	0\n"\
"seg	fs	.16	8	0\n"\
"seg	gs	.16	10	0\n"\

"gpr	eip	.32	12	0\n"\
"gpr	esp	.32	16	0\n"\
"gpr	ebp	.32	20	0\n"\
"gpr	eflags	.32	24	0\n"\

"gpr	eax	.32	28	0\n"\
"gpr	ebx	.32	32	0\n"\
"gpr	ecx	.32	36	0\n"\
"gpr	edx	.32	40	0\n"\
"gpr	esi	.32	44	0\n"\
"gpr	edi	.32	48	0\n"\

"flg	flags	.16	24	0\n"\
"flg	cf	.1	.192	0\n"\
"flg	pf	.1	.193	0\n"\
"flg	af	.1	.194	0\n"\
"flg	zf	.1	.195	0\n"\
"flg	sf	.1	.196	0\n"\
"flg	tf	.1	.197	0\n"\
"flg	if	.1	.198	0\n"\
"flg	df	.1	.199	0\n"\
"flg	of	.1	.200	0\n"\
"flg	nt	.1	.201	0\n"\
"flg	rf	.1	.202	0\n"\
"flg	vm	.1	.203	0\n";
		return strdup (msg);
	} else if (!strncmp (cmd, "dr", 2)) {
		printcmd (io, "info reg");
	} else if (!strncmp (cmd, "db ", 3)) {
		free (runcmd (sdb_fmt (0, "break *%"PFMT64x, r_num_get (NULL, cmd + 3) || io->off)));
	} else if (!strncmp (cmd, "ds", 2)) {
		free (runcmd ("stepi"));
	} else if (!strncmp (cmd, "dc", 2)) {
		free (runcmd ("cont"));
	} else if (!strncmp (cmd, "dso", 3)) {
		eprintf ("TODO: dso\n");
	} else if (!strncmp (cmd, "dp", 3)) {
		printcmd (io, "info thread");
	} else if (!strncmp (cmd, "dm", 3)) {
		char *wineDbgMaps = runcmd ("info maps");
		char *res = NULL;
		if (wineDbgMaps) {
			const char *perm;
			char *ptr = wineDbgMaps;
			for (;;) {
				char *nl = strchr (ptr, '\n');
				if (!nl) {
					break;
				}
				*nl++ = 0;
				perm = "r-x";
				ut64 from = 0, to = 0;
				if (strstr (ptr, " commit ")) {
					if (strstr (ptr, "RW")) {
						perm = "rw-";
					}
					sscanf (ptr, "%08"PFMT64x" %08"PFMT64x, &from, &to);
				}
				char *row = r_str_newf ("0x%08"PFMT64x" - 0x%08" PFMT64x" %s %s\n", from, to, perm, "");
				ptr = nl + 1;
				res = r_str_append (res, row);
				free (row);
			}
			free (wineDbgMaps);
			return res;
		}
	} else if (!strncmp (cmd, "pid", 3)) {
		return r_str_newf ("%d", fd->fd);
	} else {
		printcmd (io, cmd);
	}
	return NULL;
}
예제 #11
0
파일: qos.c 프로젝트: hajuuk/R7000
int add_iQosRules(char *pcWANIF)
{
	char *buf;
	char *g;
	char *p;
	char *addr_type, *addr;
	char *proto;
	char *port_type, *port;
	char *class_prio;
	char *ipp2p, *layer7;
	char *bcount;
	int class_num;
	int proto_num;
	int i;
	char s[256];
	int inuse;
	int qosox_enable;
	unsigned long min;
	int bcount_enable;
	int method;
	int gum;
	int sticky_enable;
	char acClass[8];
	char acByteCounter[32];
	EVAL_CMD stIptCommand =
	{ 3,
		{
		"iptables",
		"-t",
		"mangle",
		NULL,
		}
	};

	if (pcWANIF == NULL || !nvram_match("qos_enable", "1"))
		return -1;
		printf("\n%s: %s", __FUNCTION__, pcWANIF);

	qosox_enable = bcount_enable = inuse = sticky_enable = 0;
	method = atoi(nvram_safe_get("qos_method"));		  // strict rule ordering
	gum = (method == 0) ? 0x100 : 0;
	if (nvram_match("qos_sticky", "0"))
		sticky_enable = 1;

	eval("iptables", "-t", "mangle", "-N", "QOSO");
	eval("iptables", "-t", "mangle", "-A", "QOSO", "-j",
		"CONNMARK", "--restore-mark", "--mask", "0xff");
	eval("iptables", "-t", "mangle", "-A", "QOSO", "-m",
		"connmark", "!", "--mark", "0/0xff00", "-j", "RETURN");

	g = buf = strdup(nvram_safe_get("qos_orules"));
	while (g) {
		/*	addr_type<addr<proto<port_type<port<<<<desc
		addr_type:
			0 = any
			1 = dest ip
			2 = src ip
			3 = src mac
		addr:
			ip/mac if addr_type == 1-3
		proto:
			0-65535 = protocol
			-1 = tcp or udp
			-2 = any protocol
		port_type:
			if proto == -1,tcp,udp:
				d = dest
				s = src
				x = both
				a = any
		port:
			port # if proto == -1,tcp,udp
		class_prio:
			0-4, 0 being highest
		*/
		if ((p = strsep(&g, ">")) == NULL)
			break;
		i = vstrsep(p, "<", &addr_type, &addr, &proto, &port_type,
			&port, &ipp2p, &layer7, &bcount, &class_prio, &p);
		if (i == 9) {
			class_prio = bcount;
			bcount = NULL;
		}
		else if (i != 10)
			continue;

		class_num = atoi(class_prio);
		if ((class_num < 0) || (class_num > 4))
			continue;
		i = 1 << class_num++;
		if (method == 1) class_num |= 0x200;
		if ((inuse & i) == 0) {
			inuse |= i;
			printf("inuse=%d\n", inuse);
		}

		/* Beginning of the Rule */
		{
			stIptCommand.siCount = 3;
			stIptCommand.apCommand[stIptCommand.siCount++] = "-A";
			if (qosox_enable)
				stIptCommand.apCommand[stIptCommand.siCount++] = "QOSOX"; //Offset 4
			else
			stIptCommand.apCommand[stIptCommand.siCount++] = "QOSO";
		}

		/*
		*	protocol & ports:
		*/

	{
			proto_num = atoi(proto);
		if (proto_num > -2) {
			stIptCommand.apCommand[stIptCommand.siCount++] = "-p";
		if (proto_num == 17)
			stIptCommand.apCommand[stIptCommand.siCount++] = "udp"; //Offset 6
		else if (proto_num != -1)
			stIptCommand.apCommand[stIptCommand.siCount++] = proto;
		else
			stIptCommand.apCommand[stIptCommand.siCount++] = "tcp"; //Offset 6

		if ((proto_num == 6) || (proto_num == 17) || (proto_num == -1)) {
				if (*port_type != 'a') {
				if ((*port_type == 'x') || (strchr(port, ','))) {
		// dst-or-src port matches, and anything with multiple lists "," use mport
			stIptCommand.apCommand[stIptCommand.siCount++] = "-m";
			stIptCommand.apCommand[stIptCommand.siCount++] = "mport";
				if (*port_type == 's')
			stIptCommand.apCommand[stIptCommand.siCount++] = "--sports";
				else
			stIptCommand.apCommand[stIptCommand.siCount++] = "--dports";
					}
					else {
				if (*port_type == 's')
			stIptCommand.apCommand[stIptCommand.siCount++] = "--sport";
				else if (*port_type == 'd')
			stIptCommand.apCommand[stIptCommand.siCount++] = "--dport";
				else
			stIptCommand.apCommand[stIptCommand.siCount++] = "--port";
					}
				if (port && *port)
			stIptCommand.apCommand[stIptCommand.siCount++] = port;
					}
				}
			}
		}

		/*
		*	MAC or IP address match:
		*/
	{
		if ((*addr_type == '1') || (*addr_type == '2')) {	// match ip
			if (strchr(addr, '-') != NULL) {
				stIptCommand.apCommand[stIptCommand.siCount++] = "-m";
				stIptCommand.apCommand[stIptCommand.siCount++] = "iprange";
			if (*addr_type == '1')
				stIptCommand.apCommand[stIptCommand.siCount++] = "--dst-range";
			else
				stIptCommand.apCommand[stIptCommand.siCount++] = "--src-range";
			}
			else {
				if (*addr_type == '1')
				stIptCommand.apCommand[stIptCommand.siCount++] = "-d";
			else
				stIptCommand.apCommand[stIptCommand.siCount++] = "-s";
			}
	}
			else if (*addr_type == '3') {	// match mac
				stIptCommand.apCommand[stIptCommand.siCount++] = "-m";
				stIptCommand.apCommand[stIptCommand.siCount++] = "mac";
				stIptCommand.apCommand[stIptCommand.siCount++] = "--mac-source";
			}
			if (*addr_type != '0')
				stIptCommand.apCommand[stIptCommand.siCount++] = addr;
		}

		/* End of the rule */
		{
			class_num |= gum;
			if (sticky_enable)
				class_num &= 0xFF;
			sprintf(acClass, "0x%x/0xFF", class_num);
			stIptCommand.apCommand[stIptCommand.siCount++] = "-j";
			stIptCommand.apCommand[stIptCommand.siCount++] = "CONNMARK";
			stIptCommand.apCommand[stIptCommand.siCount++] = "--set-mark";		 
			stIptCommand.apCommand[stIptCommand.siCount++] = acClass;
			stIptCommand.apCommand[stIptCommand.siCount++] = NULL;
		}
		printcmd(&stIptCommand);
		_eval(stIptCommand.apCommand, NULL, 4, NULL);
		if (proto_num == -1) {
			stIptCommand.apCommand[6] = "udp";
			printcmd(&stIptCommand);
			_eval(stIptCommand.apCommand, NULL, 4, NULL);
		}
			stIptCommand.siCount = 3;
			stIptCommand.apCommand[stIptCommand.siCount++] = "-A";
		if(qosox_enable)
			stIptCommand.apCommand[stIptCommand.siCount++] = "QOSOX";
		else
			stIptCommand.apCommand[stIptCommand.siCount++] = "QOSO";
			stIptCommand.apCommand[stIptCommand.siCount++] = "-j";
			stIptCommand.apCommand[stIptCommand.siCount++] = "RETURN";	
			stIptCommand.apCommand[stIptCommand.siCount++] = NULL;
			printcmd(&stIptCommand);
		_eval(stIptCommand.apCommand, NULL, 4, NULL);
	}
	free(buf);


	/*
	*	The default class:
	*/

	{	char acClass[4];

		i = atoi(nvram_safe_get("qos_default"));
		if ((i < 0) || (i > 9)) i = 3;	// "low"
		class_num = i + 1;
		if (method == 1) class_num |= 0x200;
		sprintf(acClass, "0x%x", class_num);
		eval("iptables", "-t", "mangle", "-A", qosox_enable ? "QOSOX" : "QOSO",
		"-j", "CONNMARK", "--set-mark", acClass);
		eval("iptables", "-t", "mangle", "-A", qosox_enable ? "QOSOX" : "QOSO",
                "-j", "RETURN");
	}

		eval("iptables", "-t", "mangle", "-A", "FORWARD", "-o", pcWANIF, "-j", qosox_enable ? "QOSOX" : "QOSO");

	/*
	*	Ingress rules:
	*/
	{	i = atoi(nvram_safe_get("qos_default"));
		inuse |= (1 << i) | 1;	// default and highest are always built
		sprintf(s, "%d", inuse);
		nvram_set("qos_inuse", s);	  // create the inuse NVRAM here

		g = buf = strdup(nvram_safe_get("qos_irates"));
		for (i = 0; i < 5; i++) {
			if ((!g) || ((p = strsep(&g, ",")) == NULL)) continue;
			if ((inuse & (1 << i)) == 0) continue;
			if (atoi(p) > 0) {// if ibound rules are set, use the PRE-ROUTE
				eval("iptables", "-t", "mangle", "-A", "PREROUTING",
				"-i", pcWANIF, "-j", "CONNMARK",
				"--restore-mark", "--mask", "0xff");
				break;
			}
		}
		free(buf);
	}

}
예제 #12
0
Status_t Do_Time_Alarm(Cmd_Tbl_t *Cmd_Tbl, uint32 flag, uint32 argc, char *argv[])
{
  FuncIN(DO_TIME_ALARM);
  int i;
  Status_t Status = GENERAL_ERROR;
  TimeAlarm_t TimeAlarm_s = {0};
  char ArgumentTokens[12] = {0};
  char *CommandString = NULL;
  uint8 Remove = FALSE;

  if(argc > 0)
  {
    for(i = 0; i < argc; i++)
    {
      /******** Try for 'date=' ********/
      CommandString = strstr(argv[i], "date=");
      if(CommandString != NULL){
        if(strlen(CommandString + 5) > 10)  // Agument should be in format "DD.MM.YYYY"
        {
          printcmd(" # Invalid 'date' parameter!\n");
          EXIT_FUNC(CMD_INVALID_ARGUMENT, DO_TIME_ALARM);
        }
        strcpy(ArgumentTokens, CommandString + 5);  // strtok is changing the string. We need local copy!
        ArgumentTokens[10] = '.';  // For strtok termination

        TimeAlarm_s.DateTime.Day = atoi(strtok(ArgumentTokens, "."));  // Take first token before first '.' and convert to integer
        TimeAlarm_s.DateTime.Month = atoi(strtok(NULL, "."));  // Take second token before second '.' and convert to integer
        TimeAlarm_s.DateTime.Year = atoi(strtok(NULL, "."));  // Take third token before third '.' and convert to integer
      }

      /******** Try for 'time=' ********/
      CommandString = strstr(argv[i], "time=");
      if(CommandString != NULL){
        if(strlen(CommandString + 5) > 8)  // Agument should be in format "HH:MM:SS"
        {
          printcmd(" # Invalid 'time' parameter!\n");
          EXIT_FUNC(CMD_INVALID_ARGUMENT, DO_TIME_ALARM);
        }
        strcpy(ArgumentTokens, CommandString + 5);  // strtok is changing the string. We need local copy!
        ArgumentTokens[8] = ':';  // For strtok termination

        TimeAlarm_s.DateTime.Hour = atoi(strtok(ArgumentTokens, ":"));  // Take first token before first ':' and convert to integer
        TimeAlarm_s.DateTime.Minute = atoi(strtok(NULL, ":"));  // Take second token before second ':' and convert to integer
        TimeAlarm_s.DateTime.Second = atoi(strtok(NULL, ":"));  // Take third token before third ':' and convert to integer
      }

      /******** Try for 'state=' ********/
      CommandString = strstr(argv[i], "state=");
      if(CommandString != NULL)
      {
        if(!strncmp("ON", CommandString + 6, 2))
          TimeAlarm_s.State = ALARM_ON;
        else if(!strncmp("OFF", CommandString + 6, 3))
          TimeAlarm_s.State = ALARM_OFF;
        else
        {
          printcmd(" # Invalid 'state' parameter!\n");
          EXIT_FUNC(CMD_INVALID_ARGUMENT, DO_TIME_ALARM);
        }
      }

      /******** Try for 'alarmID=' ********/
      CommandString = strstr(argv[i], "alarmID=");
      if(CommandString != NULL)
        TimeAlarm_s.AlarmID = atoi(CommandString + 8);

      /******** Try for '-rm' ********/
      CommandString = strstr(argv[i], "-rm");
      if(CommandString != NULL)
        Remove = TRUE;

      /******** Try for 'repeat=' ********/
      CommandString = strstr(argv[i], "repeat=");
      if(CommandString != NULL)
        TimeAlarm_s.Repeat = strtol(CommandString + 7, NULL, 2);

      /******** Try for 'response=' ********/
      Status = Do_Try_Read_Time_Response_Cmd(argv[i], &TimeAlarm_s);
      VERIFY(Status, Status);
      switch(Status)
      {
        case CMD_INVALID_ARGUMENT:
          EXIT_FUNC(CMD_INVALID_ARGUMENT, DO_TIME_ALARM);
        case SUCCESS:
          break;
        default:
          break;
      } // switch(Status)
       
    } // for(i = 0; i < argc; i++)
    if(Remove == FALSE)
      Do_Set_Time_Alarm_Cmd(&TimeAlarm_s);
    else
      Remove_Time_Alarm(TimeAlarm_s.AlarmID);
    
  } else
  {
    Time_Alarm_Status(NULL);
  }
  
  EXIT_SUCCESS_FUNC(DO_TIME_ALARM);
}
예제 #13
0
Status_t Do_Sw(Cmd_Tbl_t *Cmd_Tbl, uint32 flag, uint32 argc, char *argv[])
{
  FuncIN(DO_SW);
  
  Out_t Out = {0};
  char *CommandString;
  int i, SwUpdate = 0;
  
  if(argc > 0)
  {
    for(i = 0; i < argc; i++)
    {
      CommandString = strstr(argv[i], "sw1=");
      if(CommandString != NULL)
      {
        if(atoi(CommandString + 4))
          Out_1_Set(NULL);
        else
          Out_1_Clr(NULL);
        
        SwUpdate = 1;
      }
      
      CommandString = strstr(argv[i], "sw2=");
      if(CommandString != NULL)
      {
        if(atoi(CommandString + 4))
          Out_2_Set(NULL);
        else
          Out_2_Clr(NULL);
        
        SwUpdate = 1;
      }
      
      CommandString = strstr(argv[i], "sw3=");
      if(CommandString != NULL)
      {
        if(atoi(CommandString + 4))
          Out_3_Set(NULL);
        else
          Out_3_Clr(NULL);
        
        SwUpdate = 1;
      }
      
      CommandString = strstr(argv[i], "sw4=");
      if(CommandString != NULL)
      {
        if(atoi(CommandString + 4))
          Out_4_Set(NULL);
        else
          Out_4_Clr(NULL);
        
        SwUpdate = 1;
      }
      
      CommandString = strstr(argv[i], "sw5=");
      if(CommandString != NULL)
      {
        if(atoi(CommandString + 4))
          Out_5_Set(NULL);
        else
          Out_5_Clr(NULL);
        
        SwUpdate = 1;
      }
      
      CommandString = strstr(argv[i], "sw6=");
      if(CommandString != NULL)
      {
        if(atoi(CommandString + 4))
          Out_6_Set(NULL);
        else
          Out_6_Clr(NULL);
        
        SwUpdate = 1;
      }
    } // for(i = 0; i < argc; i++)
    
    if(SwUpdate == 0)
      EXIT_FUNC(CMD_INVALID_ARGUMENT, DO_SW);
  }
  else
  {
    Out_Get_State(OUTS_TO_SET, &Out);
    
    printcmd("\n # Out switches state:\n");
    printcmd(" # Sw_1 = %u\n", Out.S_1);
    printcmd(" # Sw_2 = %u\n", Out.S_2);
    printcmd(" # Sw_3 = %u\n", Out.S_3);
    printcmd(" # Sw_4 = %u\n", Out.S_4);
    printcmd(" # Sw_5 = %u\n", Out.S_5);
    printcmd(" # Sw_6 = %u\n", Out.S_6);
  }
  
  EXIT_SUCCESS_FUNC(DO_SW);
}