Example #1
0
void cmd_receive_byte(uint8_t character)
{
	static uint8_t lineIdx;

	uart_write( &character, sizeof(character) );

	if (character == 0x8 )
	{
		if(lineIdx>0)
			lineIdx--;
	}
	else if (character == '\n')
	{
	}
	else if (character == '\r')
	{
		// Line completed
		DEBUG("\r\n");
		cmd_line[lineIdx] = '\0';
		cmd_process((char*)cmd_line);
		strcpy_P(cmd_line, PSTR("\r\nroot@plc:~> "));
		cmd_flush();
		lineIdx=0;
		cmd_line[lineIdx] = '\0';
	}
	else if (character == '\0')
	{
		io_toggle_red_led();
	}
	else
	{
		cmd_line[lineIdx] = character;
		lineIdx++;
	}
}
Example #2
0
void cmd_process( const char* cmd )
{	
	switch( cmd[0] )
	{
		case WELCOME:
			cmd_welcome();
		break;
		case 'b':
			cmd_reboot();
		break;
		case 'e':
			cmd_eeprom(cmd);
		break;
		case 'i':
			cmd_current();
		break;
		case 'l':
			cmd_line_voltage();
		break;
		case 'm':
			cmd_stack_memory();
		break;
		case 'p':
			cmd_power(cmd);
		break;
		case 'q':
			cmd_capacity();
		break;
		case 'r':
			cmd_reset();
		break;
		case 't':
			cmd_temperatur();
		break;
		case 'u':
			cmd_voltage();
		break;
		case 'x':
			eMode = eTwike;
			plc_force_busy(0);
		break;
		case '?':
			cmd_help();
		break;
		default:
			strcpy_P(cmd_line, PSTR("<Unknown command, try ? for help."));
	}
	cmd_flush();
}
Example #3
0
void cmd_stack_memory(void)
{
	uint16_t result;
		
	result = cmd_get_max_stack_usage();	
	strcpy_P(cmd_line, PSTR("command_thread's max stack usage: "));
	cmd_print_unsigned_fix(result);
	strcat_P(cmd_line, PSTR(" bytes\r\n"));

	cmd_flush();

	result = idle_get_max_stack_usage();	
	strcpy_P(cmd_line, PSTR("idle_thread's max stack usage: "));
	cmd_print_unsigned_fix(result);
	strcat_P(cmd_line, PSTR(" bytes\r\n"));
}
Example #4
0
bool config_read(FILE *file)
{
  int line_number = 0;
  char *line;
  while (!feof(file)) {
    line = read_line(file);
    line_number++;
    line = strip_whitespace(line);
    if (line[0] == '#' || strlen(line) < 1) {
      free(line);
      continue;
    }
    cmd_eval(NULL, line);
    free(line);
  }
  cmd_flush();
  return 1;
}
Example #5
0
void stop_ex_cmd()
{
  log_msg("EXCMD", "stop_ex_cmd");
  if (ex.ex_state == EX_CMD_STATE)
    menu_stop(ex.menu);
  ex.lm = NULL;
  ex.fil = NULL;
  free(ex.line);
  cmdline_cleanup(&ex.cmd);

  if (!message_pending) {
    werase(ex.nc_win);
    wnoutrefresh(ex.nc_win);
  }
  ex.ex_state = EX_OFF_STATE;
  window_ex_cmd_end();
  cmd_flush();
  window_refresh();
}
Example #6
0
void cmd_help(void)
{
	strcpy_P(cmd_line, PSTR("\n\rAvailable commands:\n\r"));
	cmd_flush();
	strcpy_P(cmd_line, PSTR("b:\tReboot\n\r"));
	cmd_flush();
	strcpy_P(cmd_line, PSTR("i:\tCurrent\n\r"));
	cmd_flush();
	strcpy_P(cmd_line, PSTR("l:\tLine voltage\n\r"));
	cmd_flush();
	strcpy_P(cmd_line, PSTR("m\tMemory info\n\r"));
	cmd_flush();
	strcpy_P(cmd_line, PSTR("p:\tPower state {on|off}\n\r"));
	cmd_flush();
	strcpy_P(cmd_line, PSTR("q:\tCapacity\n\r"));
	cmd_flush();
	strcpy_P(cmd_line, PSTR("r:\tReset\n\r"));
	cmd_flush();
	strcpy_P(cmd_line, PSTR("t:\tTemperatur\n\r"));
	cmd_flush();
	strcpy_P(cmd_line, PSTR("u:\tVoltage\n\r"));
	cmd_flush();
	strcpy_P(cmd_line, PSTR("x:\tExit\n\r"));
	cmd_flush();
	strcpy_P(cmd_line, PSTR("?:\tHelp\n\r"));
}
Example #7
0
void rdp_update(void)
{
    uint32_t** dp_reg = plugin_get_dp_registers();
    uint32_t dp_current_al = (*dp_reg[DP_CURRENT] & ~7) >> 2;
    uint32_t dp_end_al = (*dp_reg[DP_END] & ~7) >> 2;

    // don't do anything if the RDP has crashed or the registers are not set up correctly
    if (rdp_pipeline_crashed || dp_end_al <= dp_current_al) {
        return;
    }

    // while there's data in the command buffer...
    while (dp_end_al - dp_current_al > 0) {
        uint32_t i, toload;
        bool xbus_dma = (*dp_reg[DP_STATUS] & DP_STATUS_XBUS_DMA) != 0;
        uint32_t* dmem = (uint32_t*)plugin_get_dmem();
        uint32_t* cmd_buf = rdp_cmd_buf[rdp_cmd_buf_pos];

        // when reading the first int, extract the command ID and update the buffer length
        if (rdp_cmd_pos == 0) {
            if (xbus_dma) {
                cmd_buf[rdp_cmd_pos++] = dmem[dp_current_al++ & 0x3ff];
            } else {
                cmd_buf[rdp_cmd_pos++] = rdram_read_idx32(dp_current_al++);
            }

            rdp_cmd_id = CMD_ID(cmd_buf);
            rdp_cmd_len = rdp_commands[rdp_cmd_id].length >> 2;
        }

        // copy more data from the N64 to the local command buffer
        toload = MIN(dp_end_al - dp_current_al, rdp_cmd_len - 1);

        if (xbus_dma) {
            for (i = 0; i < toload; i++) {
                cmd_buf[rdp_cmd_pos++] = dmem[dp_current_al++ & 0x3ff];
            }
        } else {
            for (i = 0; i < toload; i++) {
                cmd_buf[rdp_cmd_pos++] = rdram_read_idx32(dp_current_al++);
            }
        }

        // if there's enough data for the current command...
        if (rdp_cmd_pos == rdp_cmd_len) {
            // check if parallel processing is enabled
            if (config.parallel) {
                // special case: sync_full always needs to be run in main thread
                if (rdp_cmd_id == CMD_ID_SYNC_FULL) {
                    // first, run all pending commands
                    cmd_flush();

                    // parameters are unused, so NULL is fine
                    rdp_sync_full(NULL, NULL);
                } else {
                    // increment buffer position
                    rdp_cmd_buf_pos++;

                    // flush buffer when it is full or when the current command requires a sync
                    if (rdp_cmd_buf_pos >= CMD_BUFFER_SIZE || rdp_commands[rdp_cmd_id].sync) {
                        cmd_flush();
                    }
                }
            } else {
                // run command directly
                cmd_run(&rdp_states[0], cmd_buf);
            }

            // reset current command buffer to prepare for the next one
            cmd_init();
        }
    }

    // update DP registers to indicate that all bytes have been read
    *dp_reg[DP_START] = *dp_reg[DP_CURRENT] = *dp_reg[DP_END];
}