Ejemplo n.º 1
0
static void parse_get_daytime(void) {
  char buf[18];
  ttoa(settings.daytime[DAYTIME_BEGIN], buf+0);
  ttoa(settings.daytime[DAYTIME_END], buf+9);
  buf[8] = ' ';

  uart_puts_P("+ ");
  uart_puts(buf);
  uart_puts_P(NEWLINE);
}
Ejemplo n.º 2
0
/*
 * display --
 *	print out the file for the user to edit; strange side-effect:
 *	set conditional flag if the user gets to edit the shell.
 */
void
display(char *tempname, int fd, struct passwd *pw)
{
	FILE *fp;
	char *bp, *p;
	char chgstr[256], expstr[256];

	if (!(fp = fdopen(fd, "w")))
		(*Pw_error)(tempname, 1, 1);

	(void)fprintf(fp,
	    "#Changing user %sdatabase information for %s.\n",
	    use_yp ? "YP " : "", pw->pw_name);
	if (!uid) {
		(void)fprintf(fp, "Login: %s\n", pw->pw_name);
		(void)fprintf(fp, "Password: %s\n", pw->pw_passwd);
		(void)fprintf(fp, "Uid [#]: %d\n", pw->pw_uid);
		(void)fprintf(fp, "Gid [# or name]: %d\n", pw->pw_gid);
		(void)fprintf(fp, "Change [month day year]: %s\n",
		    ttoa(chgstr, sizeof chgstr, pw->pw_change));
		(void)fprintf(fp, "Expire [month day year]: %s\n",
		    ttoa(expstr, sizeof expstr, pw->pw_expire));
		(void)fprintf(fp, "Class: %s\n", pw->pw_class);
		(void)fprintf(fp, "Home directory: %s\n", pw->pw_dir);
		(void)fprintf(fp, "Shell: %s\n",
		    *pw->pw_shell ? pw->pw_shell : _PATH_BSHELL);
	}
	/* Only admin can change "restricted" shells. */
	else if (ok_shell(pw->pw_shell))
		/*
		 * Make shell a restricted field.  Ugly with a
		 * necklace, but there's not much else to do.
		 */
		(void)fprintf(fp, "Shell: %s\n",
		    *pw->pw_shell ? pw->pw_shell : _PATH_BSHELL);
	else
		list[E_SHELL].restricted = 1;
	bp = strdup(pw->pw_gecos);
	if (!bp) {
		err(1, "strdup");
		/*NOTREACHED*/
	}
	p = strsep(&bp, ",");
	(void)fprintf(fp, "Full Name: %s\n", p ? p : "");
	p = strsep(&bp, ",");
	(void)fprintf(fp, "Location: %s\n", p ? p : "");
	p = strsep(&bp, ",");
	(void)fprintf(fp, "Office Phone: %s\n", p ? p : "");
	p = strsep(&bp, ",");
	(void)fprintf(fp, "Home Phone: %s\n", p ? p : "");

	(void)fchown(fd, getuid(), getgid());
	(void)fclose(fp);
	free(bp);
}
Ejemplo n.º 3
0
static void parse_get_timers(void) {
  char buf[9];

  for ( uint8_t i = 0; i < N_TIMESWITCHES; i++ ) {
	uart_puts_P("+ ");

	uart_puts(ttoa(settings.timeswitches[i].on, buf));
	uart_puts_P(" ");
	uart_puts(ttoa(settings.timeswitches[i].off, buf));
	uart_puts_P(" ");
	uart_puts(itoa8(settings.timeswitches[i].output & ~OUTPUT_ENABLED_MASK, buf));
	uart_puts_P(" ");
	uart_puts(itoa8(timeswitch_enabled(i), buf));
	uart_puts_P(" ");
	uart_puts(itoa8(timeswitch_active(i), buf));

	uart_puts_P(NEWLINE);
  }
}
Ejemplo n.º 4
0
void runExternalCommandsPersistent(EthernetServer* _server, systemState* _state) 
{
	// local variables
	int i, buffer_ptr;
	int room, radiatorState, automaticMode;
	float temperature;
	int commandError = 0;
	
	
	EthernetClient client = _server->available(); // is non-blocking
	if(client.available() > 2)
	{
		#ifdef DEBUG
		Serial.println("Connection established");
		Serial.print("Available: ");
		Serial.println(client.available());
		#endif
		
		char buffer[32];
		
		// read command field
		if( readParam(buffer, 3, client) < 0 ) {commandError = 1; goto errorHandler;}
		
		// switch case on commands
		if(strcmp(buffer, "STM") == 0) // set temperature
		{
			#ifdef DEBUG
			Serial.println("Set temperature command received");
			#endif
			
			// read fisrt param: room number (one digit)
			if( readParam(buffer, 1, client) < 0 ) {commandError = 1; goto errorHandler;}
			room = atoi(buffer);
			
			// read second param: temperature (format xx.y)
			if( readParam(buffer, 4, client) < 0 ) {commandError = 1; goto errorHandler;}
			temperature = atof(buffer);
			
			_state->desiredTemp[room] = temperature;
			
			client.write((unsigned char*)"STM", 3);
			client.write((unsigned char*)"OOK", 3);
		}
		else if(strcmp(buffer, "RTM") == 0) // read temperature
		{
			#ifdef DEBUG
			Serial.println("Read temperature command received");
			#endif
			// read fisrt param: room number (one digit)
			if( readParam(buffer, 1, client) < 0 ) {commandError = 1; goto errorHandler;}
			
			room = atoi(buffer);
			
			temperature = _state->actualTemp[room];
			//buffer_ptr = sprintf(buffer, "%4.1f", temperature);
			ttoa(buffer, temperature);
			
			client.write((unsigned char*)"RTM", 3);
			client.write((unsigned char*)"OOK", 3);
			client.write((unsigned char*)buffer, 4);
		}
		else if(strcmp(buffer, "SRD") == 0) // set radiator
		{
			#ifdef DEBUG
			Serial.println("Set radiator command received");
			#endif
			// read fisrt param: room number (one digit)
			if( readParam(buffer, 1, client) < 0 ) {commandError = 1; goto errorHandler;}
			room = atoi(buffer);
			
			// read second param: radiator state (one digit)
			if( readParam(buffer, 1, client) < 0 ) {commandError = 1; goto errorHandler;}
			radiatorState = atoi(buffer);
			
			_state->radiatorState[room] = radiatorState;
			digitalWrite(radiatorPinByRoom(room), (radiatorState == 1) ? LOW : HIGH);
			
			// set zone valve
			int someoneIsOn = 0;
			for(room = 0; room < 6; room++) 
			{
				if(_state->radiatorState[room] == ON) someoneIsOn = 1;
			}
			digitalWrite(ZONE_VALVE_NO1, someoneIsOn ? LOW : HIGH);
			
			client.write((unsigned char*)"SRD", 3);
			client.write((unsigned char*)"OOK", 3);
		}
		else if(strcmp(buffer, "RRD") == 0) // read radiator
		{
			#ifdef DEBUG
			Serial.println("Read radiator command received");
			#endif
			// read fisrt param: room number (one digit)
			if( readParam(buffer, 1, client) < 0 ) {commandError = 1; goto errorHandler;}
			room = atoi(buffer);

			radiatorState = _state->radiatorState[room];
			sprintf(buffer, "%d", radiatorState);
			
			client.write((unsigned char*)"RRD", 3);
			client.write((unsigned char*)"OOK", 3);
			client.write((unsigned char*)buffer, 1);
		}
		else if(strcmp(buffer, "SAM") == 0) // set automatic mode
		{
			#ifdef DEBUG
			Serial.println("Set automatic mode command received");
			#endif
			// read second param: radiator state (one digit)
			if( readParam(buffer, 1, client) < 0 ) {commandError = 1; goto errorHandler;}
			automaticMode = atoi(buffer);
			
			_state->automaticMode = automaticMode;
			
			client.write((unsigned char*)"SAM", 3);
			client.write((unsigned char*)"OOK", 3);
		}
		else if(strcmp(buffer, "RAM") == 0) // read automatic mode
		{
			#ifdef DEBUG
			Serial.println("Read automatic mode command received");
			#endif
			automaticMode = _state->automaticMode;
			
			sprintf(buffer, "%d", automaticMode);
			
			client.write((unsigned char*)"RAM", 3);
			client.write((unsigned char*)"OOK", 3);
			client.write((unsigned char*)buffer, 1);
		}
		else if(strcmp(buffer, "RDT") == 0) // read desired temperature
		{
			#ifdef DEBUG
			Serial.println("Read desired temperature command received");
			#endif
			// read fisrt param: room number (one digit)
			if( readParam(buffer, 1, client) < 0 ) {commandError = 1; goto errorHandler;}
			room = atoi(buffer);
			
			temperature = _state->desiredTemp[room];
			//buffer_ptr = sprintf(buffer, "%4.1f", temperature);
			ttoa(buffer, temperature);
			
			client.write((unsigned char*)"RDT", 3);
			client.write((unsigned char*)"OOK", 3);
			client.write((unsigned char*)buffer, 4);
		}
		else if(strcmp(buffer, "CLS") == 0) // Close connection
		{
			#ifdef DEBUG
			Serial.println("Close connection command received");
			#endif
			
			client.write((unsigned char*)"CLS", 3);
			client.write((unsigned char*)"OOK", 3);
			
			client.flush(); // NEW to verify ---> it seems not working
			delay(2000);
			while(client.connected())
			{
				client.stop();
				delay(2000);
			}
		}
		else
		{
			#ifdef DEBUG
			Serial.print("Invalid command received: ");
			Serial.print(buffer[0]);
			Serial.print(buffer[1]);
			Serial.print(buffer[2]);
			Serial.println();
			#endif
			client.write((unsigned char*)"ERR", 3);
			client.write((unsigned char*)"INV", 3);
		}
		
		// =============================================
		errorHandler:
		if(commandError)
		{
			
			#ifdef DEBUG
			Serial.print("Invalid command received: ");
			Serial.print(buffer[0]);
			Serial.print(buffer[1]);
			Serial.print(buffer[2]);
			Serial.println();
			#endif
			client.write((unsigned char*)"ERR", 3);
			client.write((unsigned char*)"GEN", 3);
		}
		// =============================================
	}
	
}
Ejemplo n.º 5
0
/*
 * display --
 *	print out the file for the user to edit; strange side-effect:
 *	set conditional flag if the user gets to edit the shell.
 */
static int
display(const char *tfn, struct passwd *pw)
{
	FILE *fp;
	char *bp, *gecos, *p;

	if ((fp = fopen(tfn, "w")) == NULL) {
		warn("%s", tfn);
		return (-1);
	}

	fprintf(fp, "#Changing user information for %s.\n", pw->pw_name);
	if (master_mode) {
		fprintf(fp, "Login: %s\n", pw->pw_name);
		fprintf(fp, "Password: %s\n", pw->pw_passwd);
		fprintf(fp, "Uid [#]: %lu\n", (unsigned long)pw->pw_uid);
		fprintf(fp, "Gid [# or name]: %lu\n",
		    (unsigned long)pw->pw_gid);
		fprintf(fp, "Change [month day year]: %s\n",
		    ttoa(pw->pw_change));
		fprintf(fp, "Expire [month day year]: %s\n",
		    ttoa(pw->pw_expire));
		fprintf(fp, "Class: %s\n", pw->pw_class);
		fprintf(fp, "Home directory: %s\n", pw->pw_dir);
		fprintf(fp, "Shell: %s\n",
		    *pw->pw_shell ? pw->pw_shell : _PATH_BSHELL);
	}
	/* Only admin can change "restricted" shells. */
#if 0
	else if (ok_shell(pw->pw_shell))
		/*
		 * Make shell a restricted field.  Ugly with a
		 * necklace, but there's not much else to do.
		 */
#else
	else if ((!list[E_SHELL].restricted && ok_shell(pw->pw_shell)) ||
	    master_mode)
		/*
		 * If change not restrict (table.c) and standard shell
		 *	OR if root, then allow editing of shell.
		 */
#endif
		fprintf(fp, "Shell: %s\n",
		    *pw->pw_shell ? pw->pw_shell : _PATH_BSHELL);
	else
		list[E_SHELL].restricted = 1;

	if ((bp = gecos = strdup(pw->pw_gecos)) == NULL) {
		warn(NULL);
		fclose(fp);
		return (-1);
	}

	p = strsep(&bp, ",");
	p = strdup(p ? p : "");
	list[E_NAME].save = p;
	if (!list[E_NAME].restricted || master_mode)
		fprintf(fp, "Full Name: %s\n", p);

	p = strsep(&bp, ",");
	p = strdup(p ? p : "");
	list[E_LOCATE].save = p;
	if (!list[E_LOCATE].restricted || master_mode)
		fprintf(fp, "Office Location: %s\n", p);

	p = strsep(&bp, ",");
	p = strdup(p ? p : "");
	list[E_BPHONE].save = p;
	if (!list[E_BPHONE].restricted || master_mode)
		fprintf(fp, "Office Phone: %s\n", p);

	p = strsep(&bp, ",");
	p = strdup(p ? p : "");
	list[E_HPHONE].save = p;
	if (!list[E_HPHONE].restricted || master_mode)
		fprintf(fp, "Home Phone: %s\n", p);

	bp = strdup(bp ? bp : "");
	list[E_OTHER].save = bp;
	if (!list[E_OTHER].restricted || master_mode)
		fprintf(fp, "Other information: %s\n", bp);

	free(gecos);

	fchown(fileno(fp), getuid(), getgid());
	fclose(fp);
	return (0);
}
Ejemplo n.º 6
0
static void parse_get_time(void) {
  char buf[9];
  uart_puts_P("+ ");
  uart_puts(ttoa(time_now(), buf));
  uart_puts_P(NEWLINE);
}
Ejemplo n.º 7
0
void gHistogram::draw(float value) {
	uint32_t l = millis()-_chrono;
	if ( (_lapse>0) && (l<_lapse) ) return;
	_chrono = millis();
	
	uint16_t y = _y0+1+_dy-2 - (uint16_t)( (value-_valueMin)*(_dy-2)/(_valueMax-_valueMin) );
	if (y<_y0+2)     y = _y0+2;
	if (y>_y0+_dy-4) y = _y0+_dy-4;
	
	// continuity management
	if (_continous) {
		// right-most side
		if (_n>_dx-4) {
			// move
			_pscreen->copyPaste(_x0+2, _y0, _x0+1, _y0, _dx-3, _dy);
			// new 
			_pscreen->line(_x0+_n+1, _y0+1, _x0+_n+1, _y0+_dy-2, _backColour);
			
			// gridY
			if (_gridY>0) { 
				if (_gridC==0) _pscreen->line(_x0+_n+1, _y0+1, _x0+_n+1, _y0+_dy-2, _pscreen->halfColour(_gridColour));
				_gridC++;
				_gridC %= _gridY;
			} // gridY
			
			// gridX
			if (_gridX>0) for (uint16_t i=1; i<_gridX; i++) 
				_pscreen->point(_x0+_n+1, _y0+map(i, 0, _gridX, 0, _dy), _pscreen->halfColour(_gridColour));
		} 
		else {
			_n++;
		} // right-most side
	} 
	else {
		// right 
		if (_n>_dx-4) {
			_n=1;
		} 
		else {
			_n++;
		} // right 
		
		_pscreen->line(_x0+_n+1, _y0+1, _x0+_n+1, _y0+_dy-2, _backColour);
		_pscreen->line(_x0+_n+2, _y0+1, _x0+_n+2, _y0+_dy-2, _gridColour);
		
		// gridY
		if (_gridY>0) { 
			if (_gridC==0) _pscreen->line(_x0+_n+1, _y0+1, _x0+_n+1, _y0+_dy-2, _pscreen->halfColour(_gridColour));
			_gridC++;
			_gridC %= _gridY;
		} // gridY
		
		// gridX
		if (_gridX>0) for (uint16_t i=1; i<_gridX; i++) 
			_pscreen->point(_x0+_n+1, _y0+map(i, 0, _gridX, 0, _dy), _pscreen->halfColour(_gridColour));
		
	} // continuity management
	
	// value
    _pscreen->setPenSolid(true);    
	_pscreen->dRectangle(_x0+_n, y, 2, 2, _valueColour);
	
	// min and max memory
	if (_memory>0) {
		
		// first time
		if (_n==0) {
			_max = y;
			_min = y;
		}
		
		// max - coordinates in reverse scale
		if (y<=_max) {
			_max = y;
			_amnesiaMax = _memory;
		} 
		else if (_amnesiaMax>0) {
			_pscreen->dRectangle(_x0+_n, _max, 2, 2, _maxColour);
			_amnesiaMax--;
		} 
		else {
			_max = y;
		} // max
		
		// min - coordinates in reverse scale
		if (y>=_min) {
			_min = y;
			_amnesiaMin = _memory;
		} 
		else if (_amnesiaMin>0) {  
			_pscreen->dRectangle(_x0+_n, _min, 2, 2, _minColour);
			_amnesiaMin--;
		} 
		else {
			_min = y;
		} // min
	} // min and max memory
	
	_pscreen->setFont(0);
	_pscreen->setFontSolid(true);
	_pscreen->gText(_x0+3, _y0+2, ftoa(_valueMax, 1, 0), _frontColour);
	_pscreen->gText(_x0+3, _y0+_dy-2-_pscreen->fontY(), ftoa(_valueMin, 1, 0), _frontColour);
	
	// lapse error
	if (_lapse>0) {
		if (l>_lapse) {
			if (_gridY>0) {
				_pscreen->setBackGroundColour(_frontColour);
				_pscreen->gText(_x0+_dx-2-7*_pscreen->fontX(), _y0+_dy-2-_pscreen->fontY(), ttoa(l*_gridY, 1, 7), _backColour);
				_pscreen->setBackGroundColour(_backColour);
			} 
			else {
				_pscreen->setBackGroundColour(_frontColour);
				_pscreen->gText(_x0+_dx-2-7*_pscreen->fontX(), _y0+_dy-2-_pscreen->fontY(), ttoa(l, 0, 7), _backColour);
				_pscreen->setBackGroundColour(_backColour);
			} // _gridY
			
		} 
		else {
			if (_gridY>0) {
				_pscreen->gText(_x0+_dx-2-7*_pscreen->fontX(), _y0+_dy-2-_pscreen->fontY(), ttoa(l*_gridY, 1, 7), _frontColour);
			} 
			else {
				_pscreen->gText(_x0+_dx-2-7*_pscreen->fontX(), _y0+_dy-2-_pscreen->fontY(), ttoa(l, 0, 7), _frontColour);
			} // _gridY
		} // lapse error
	}
	else {
		_pscreen->setBackGroundColour(_frontColour);
		_pscreen->gText(_x0+_dx-2-7*_pscreen->fontX(), _y0+_dy-2-_pscreen->fontY(), ttoa(l, 0, 7), _backColour);
		_pscreen->setBackGroundColour(_backColour);
	} // end _lapse>0
	
}