Example #1
0
static void shell_network(char *str)
{
char *pos = str + sizeof("network");
uint8_t is_error = 0;
char dstr[DSTR_BUF];


	if (strncmp_P(pos, PSTR("set "), 4) == 0)
	{
        pos += 4;
		if (strncmp_P(pos, PSTR("ip "), 3) == 0)
		{
        	pos += 3;
			is_error = net_conf_set_ip_string(pos);
		}
		else if (strncmp_P(pos, PSTR("gw "), 3) == 0)
		{
        	pos += 3;
			is_error = net_conf_set_gw_string(pos);
		}
		else if (strncmp_P(pos, PSTR("nm "), 3) == 0)
		{
        	pos += 3;
			is_error = net_conf_set_nm_string(pos);
		}
		else if (strncmp_P(pos, PSTR("dhcp "), 5) == 0)
		{
        	pos += 5;
			is_error = net_conf_set_dhcpc_string(pos);
		}
		else
		{
			shell_output("unknown set operation: ", pos);
		}
	}
	else if (strncmp_P(pos, PSTR("show"), 4) == 0)
	{
        pos += 5;
		net_conf_get_mac_string(dstr, DSTR_BUF);
		shell_output("MAC: ", dstr);
		net_conf_get_ip_string(dstr, DSTR_BUF);
		shell_output("IP: ", dstr);
		net_conf_get_nm_string(dstr, DSTR_BUF);
		shell_output("NM: ", dstr);
		net_conf_get_gw_string(dstr, DSTR_BUF);
		shell_output("GW: ", dstr);
	}
	else if (strncmp_P(pos, PSTR("load"), 4) == 0)
	{
		net_conf_load();
	}
	else if (strncmp_P(pos, PSTR("save"), 4) == 0)
	{
		net_conf_save();
	}
	else
	{
		shell_output_P(PSTR("options: show, set, load, save"),PSTR(""));
	}
}
Example #2
0
static int tftpupdate_iofunc(struct tftp_state *s, uint32_t offset,
		uint16_t size, void *buf)
{
	int err;

	// Write the flash block
	err = flashmgt_sec_write_block(buf, offset, size);
	if (err) {
		shell_output_P(&tftpupdate_command,
			PSTR("\rWrite error %d at block %d\n"),
			err, s->block);
	}
	else {
		shell_output_P(&tftpupdate_command,
			PSTR("\r%c"),
			pgm_read_byte(&progress[s->block % sizeof(progress)]));
	}

	return err;
}
Example #3
0
static PT_THREAD(read_temp(struct pt *pt, const ow_addr_t *addr)) {
	int err;
	uint8_t scratch[9];
	uint8_t crc = 0;

	PT_BEGIN(pt);

	// Reset the bus
	err = ow_reset();
	if (err != 1) {
		shell_output_P(&owtest_command, PSTR("Reset failed.\n"));
		PT_EXIT(pt);
	}

	// Match ROM
	err = ow_write_byte(0x55);
	if (err) {
		shell_output_P(&owtest_command, PSTR("Match ROM failed\n"));
		PT_EXIT(pt);
	}
	for (int i = 0; i < sizeof(*addr); i++) {
		err = ow_write_byte(addr->u[i]);
		if (err) {
			shell_output_P(&owtest_command, PSTR("Match ROM failed\n"));
			PT_EXIT(pt);
		}
	}

	// Start temperature conversion
	err = ow_write_byte(0x44);
	if (err) {
		shell_output_P(&owtest_command, PSTR("Convert T failed\n"));
		PT_EXIT(pt);
	}

	// Conversion timeout
	timer_set(&timeout, DS18B20_CONV_TIMEOUT);
	while (1) {
		_delay_ms(10); // for good measure

		// Read a bit from the bus
		int ret = ow_read_bit();

		// Check for stop conditions
		if (ret == 1) {
			break;
		}
		else if (ret == -1) {
			shell_output_P(&owtest_command, PSTR("Read status failed.\n"));
			PT_EXIT(pt);
		}
		else if (timer_expired(&timeout)) {
			shell_output_P(&owtest_command, PSTR("Conversion has taken too long. Giving up.\n"));
			PT_EXIT(pt);
		}

		// Poll the process and yield the thread
		process_poll(&shell_owtest_process);
		PT_YIELD(pt);
	}

	// Reset and MATCH ROM again
	err = ow_reset();
	if (err != 1) {
		shell_output_P(&owtest_command, PSTR("Reset failed.\n"));
		PT_EXIT(pt);
	}

	// Match ROM
	err = ow_write_byte(0x55);
	if (err) {
		shell_output_P(&owtest_command, PSTR("Match ROM failed\n"));
		PT_EXIT(pt);
	}
	for (int i = 0; i < sizeof(*addr); i++) {
		err = ow_write_byte(addr->u[i]);
		if (err) {
			shell_output_P(&owtest_command, PSTR("Match ROM failed\n"));
			PT_EXIT(pt);
		}
	}

	// Read the scratch pad
	err = ow_write_byte(0xBE);
	if (err) {
		shell_output_P(&owtest_command, PSTR("Read scratch pad failed\n"));
		PT_EXIT(pt);
	}

	for (int i = 0; i < sizeof(scratch); i++) {
		err = ow_read_byte();
		if (err < 0) {
			shell_output_P(&owtest_command, PSTR("Read byte failed\n"));
			PT_EXIT(pt);
		}

		scratch[i] = err;
		crc = _crc_ibutton_update(crc, scratch[i]);
	}

	// Make sure the CRC is valid
	if (crc) {
		shell_output_P(&owtest_command, PSTR("CRC check failed!\n"));
		PT_EXIT(pt);
	}

	// Convert temperature to floating point
	int16_t rawtemp = scratch[0] | (scratch[1] << 8);
	float temp = (float)rawtemp * 0.0625;

	shell_output_P(&owtest_command, 
		PSTR("Scratchpad: %02x%02x %02x%02x %02x %02x%02x%02x %02x\n"),
		scratch[0], scratch[1], // temperature
		scratch[2], scratch[3], // TH,TL alarm thresholds
		scratch[4], // config
		scratch[5], scratch[6], scratch[7], // reserved
		scratch[8]); // CRC

	shell_output_P(&owtest_command, PSTR("Reading: %0.2fC\n"), temp);

	PT_END(pt);
}
Example #4
0
PROCESS_THREAD(shell_owtest_process, ev, data) {
	int err;

	PROCESS_BEGIN();

	// Attempt to acquire 1-Wire lock
	while (!ow_lock()) {
		PROCESS_PAUSE();
	}

	// Reset the bus
	err = ow_reset();
	if (err < 0) {
		shell_output_P(&owtest_command, PSTR("Bus reset failed.\n"));
		PROCESS_EXIT();
	}
	else if (err == 0) {
		shell_output_P(&owtest_command, PSTR("No presence detected.\n"));
		PROCESS_EXIT();
	}

	// Start the search
	err = ow_search_first(&search, 0);
	do {
		if (err < 0) {
			shell_output_P(&owtest_command, PSTR("Search error: %d\n"), err);
			PROCESS_EXIT();
		}
		else if (err == 0) {
			shell_output_P(&owtest_command, PSTR("No devices found.\n"));
			break;
		}

		// Print search result
		shell_output_P(&owtest_command,
			PSTR("Found: %02x.%02x%02x%02x%02x%02x%02x\n"),
			search.rom_no.family, // family code
			search.rom_no.id[0], search.rom_no.id[1], search.rom_no.id[2],
			search.rom_no.id[3], search.rom_no.id[4], search.rom_no.id[5]);

		// If it's a DS18B20, read it
		if (search.rom_no.family == 0x28) {
			shell_output_P(&owtest_command, PSTR("Reading temperature...\n"));
			PROCESS_PT_SPAWN(&ow_pt, read_temp(&ow_pt, &search.rom_no));
		}

		// If we found the last device on the bus, break out of the loop
		if (search.last_device_flag) {
			break;
		}

		// Find the next device on the bus
		err = ow_search_next(&search);
	} while (1);

	// Relinquish bus lock
	ow_unlock();

	shell_output_P(&owtest_command, PSTR("Search complete.\n"));

	PROCESS_END();
}
Example #5
0
PROCESS_THREAD(shell_tftpupdate_process, ev, data) {
	char *s;
	int err;

	PROCESS_BEGIN();

	// Make sure we got some arguments
	if ((data == NULL) || (strlen(data) == 0)) {
		tftpupdate_usage();
		PROCESS_EXIT();
	}

	// Find the space between the server and the filename
	s = strchr(data, ' ');

	// Check we got <server><SPACE><filename>
	if (s == NULL) {
		tftpupdate_usage();
		PROCESS_EXIT();
	}

	// Clean up after a previous run
	if (tftpupdate) {
		shell_output_P(&tftpupdate_command,
			PSTR("Previous run failed to clean up after itself! Clobbering.\n"));
		tftpupdate_cleanup();
	}

	// Allocate our memory block if necessary
	tftpupdate = malloc(sizeof(*tftpupdate));
	if (tftpupdate == NULL) {
		shell_output_P(&tftpupdate_command,
			PSTR("Out of memory!\n"));
		PROCESS_EXIT();
	}
	tftpupdate->s.conn = NULL;

	// Copy out the server name
	int len = s - (char *)data;
	if (len >= sizeof(tftpupdate->res.name)) {
		len = sizeof(tftpupdate->res.name) - 1;
	}
	strncpy(tftpupdate->res.name, data, len);
	tftpupdate->res.name[len] = '\0';

	// Copy out the filename
	strncpy(tftpupdate->filename, s + 1, sizeof(tftpupdate->filename) - 1);
	tftpupdate->filename[sizeof(tftpupdate->filename) - 1] = '\0';

	// Check there is something in the filename
	if (strlen(tftpupdate->filename) == 0) {
		tftpupdate_usage();
		tftpupdate_cleanup();
		PROCESS_EXIT();
	}

	// Tell the user what's going on
	shell_output_P(&tftpupdate_command,
		PSTR("Looking up '%s'...\n"), tftpupdate->res.name);

	// Start the lookup
	resolv_helper_lookup(&tftpupdate->res);
	while (1) {
		PROCESS_WAIT_EVENT();
		resolv_helper_appcall(&tftpupdate->res, ev, data);

		if (tftpupdate->res.state == RESOLV_HELPER_STATE_ASKING) {
			continue;
		}
		else if (tftpupdate->res.state == RESOLV_HELPER_STATE_DONE) {
			break;
		}
		else if (tftpupdate->res.state == RESOLV_HELPER_STATE_ERROR) {
			shell_output_P(&tftpupdate_command,
				PSTR("Error during DNS lookup.\n"));
			tftpupdate_cleanup();
			PROCESS_EXIT();
		}
		else {
			shell_output_P(&tftpupdate_command,
				PSTR("Error during DNS lookup. (unknown state)\n"));
			tftpupdate_cleanup();
			PROCESS_EXIT();
		}
	}

	// Tell the user what's going on
	shell_output_P(&tftpupdate_command,
		PSTR("Preparing to write to flash...\n"));

	// Start the flash write
	err = flashmgt_sec_write_start();
	if (err) {
		shell_output_P(&tftpupdate_command,
			PSTR("Could not set up flash write (%d).\n"), err);
		tftpupdate_cleanup();
		PROCESS_EXIT();
	}

	// More user info
	shell_output_P(&tftpupdate_command,
		PSTR("Requesting '%s' from %u.%u.%u.%u...\n"),
		tftpupdate->filename,
		uip_ipaddr_to_quad(&tftpupdate->res.ipaddr));

	// Start the TFTP transfer
	tftpupdate->s.addr = tftpupdate->res.ipaddr;
	tftpupdate->s.iofunc = tftpupdate_iofunc;
	tftp_init(&tftpupdate->s);
	tftp_get(&tftpupdate->s, tftpupdate->filename);
	while (1) {
		PROCESS_WAIT_EVENT();

		if (ev == tcpip_event) {
			tftp_appcall(&tftpupdate->s);

			if (tftpupdate->s.state == TFTP_STATE_CLOSE) {
				shell_output_P(&tftpupdate_command,
					PSTR("\rTransfer complete (%lu bytes read).\n"),
					tftpupdate->s.size);

				// Send final ACK
				PROCESS_WAIT_EVENT();
				break;
			}
			else if (tftpupdate->s.state == TFTP_STATE_ERR) {
				shell_output_P(&tftpupdate_command,
					PSTR("\rAborting due to error.\n"));

				// Abort the flash write
				flashmgt_sec_write_abort();

				// Make sure error message is sent
				PROCESS_WAIT_EVENT();

				tftpupdate_cleanup();
				PROCESS_EXIT();
			}
			else if (tftpupdate->s.state == TFTP_STATE_TIMEOUT) {
				shell_output_P(&tftpupdate_command,
					PSTR("\rTransfer timed out.\n"));

				// Abort the flash write
				flashmgt_sec_write_abort();

				// Make sure error message is sent
				PROCESS_WAIT_EVENT();

				tftpupdate_cleanup();
				PROCESS_EXIT();
			}
		}
	}

	// Tell the user what's going on
	shell_output_P(&tftpupdate_command,
		PSTR("Completing update process...\n"));

	// Finish the flash write process
	err = flashmgt_sec_write_finish();
	if (err) {
		shell_output_P(&tftpupdate_command,
			PSTR("Could not apply firmware update (%d)\n"),
			err);
	}
	else {
		shell_output_P(&tftpupdate_command,
			PSTR("New firmware image is in flash. "
				"Please reboot to apply the upgrade.\n"),
			err);
	}

	tftpupdate_cleanup();
	PROCESS_END();
}
Example #6
0
static void tftpupdate_usage(void) {
	shell_output_P(&tftpupdate_command,
		PSTR("Usage: tftpupdate <server> <filename>\n"));
}
Example #7
0
/*---------------------------------------------------------------------------*/
void shell_start(void)
{
  shell_output_P(PSTR("uIP command shell"), PSTR(""));
  shell_output_P(PSTR("Type '?' and return for help"), PSTR(""));
  shell_prompt(SHELL_PROMPT);
}
Example #8
0
/*---------------------------------------------------------------------------*/
static void help(char *str)
{
  // TEXT HERE CAN ONLY BE 40 chars / output! based on telnetd.h
  shell_output_P(PSTR("Available commands:"), PSTR(""));
#ifdef TELNETD_TIME_CMD
  shell_output_P(PSTR("isotime - sys time, iso format"), PSTR(""));
  shell_output_P(PSTR("settime - set sys time"), PSTR(""));
  shell_output_P(PSTR("gettime - get sys time"), PSTR(""));
  shell_output_P(PSTR("rtcisotime - show RTC time, iso format"), PSTR(""));
  shell_output_P(PSTR("rtcsettime - set the current RTC time"), PSTR(""));
  shell_output_P(PSTR("rtcgettime - get the current RTC time"), PSTR(""));
  shell_output_P(PSTR("rtctosys   - copy RTC time to sys"), PSTR(""));
  shell_output_P(PSTR("systortc   - copy sys time to RTC"), PSTR(""));
#endif
#ifdef NETWORK_CMD
  shell_output_P(PSTR("network - get/set network settings"), PSTR(""));
#endif
#ifdef UDPDS_CMD
  shell_output_P(PSTR("udpds - set/enable/disable"),PSTR(""));
#endif
//  shell_output("stats   - show network statistics", "");
//  shell_output("conn    - show TCP connections", "");
  shell_output_P(PSTR("help, ? - show help"), PSTR(""));
  shell_output_P(PSTR("exit    - exit shell"), PSTR(""));
}