コード例 #1
0
ファイル: PiLink.cpp プロジェクト: DigitalWarrior/brewpi-avr
void PiLink::receive(void){
	if (Serial.available() > 0){
		char inByte = Serial.read();
		switch(inByte){
		case 't': // temperatures requested
			printTemperatures();      
			break;
		case 'C': // Set default constants
			tempControl.loadDefaultConstants();
			display.printStationaryText(); // reprint stationary text to update to right degree unit
			sendControlConstants(); // update script with new settings
			debugMessage(PSTR("Default constants loaded."));
			break;
		case 'S': // Set default settings
			tempControl.loadDefaultSettings();
			sendControlSettings(); // update script with new settings
			debugMessage(PSTR("Default settings loaded."));
			break;
		case 's': // Control settings requested
			sendControlSettings();
			break;
		case 'c': // Control constants requested
			sendControlConstants();
			break;
		case 'v': // Control variables requested
			sendControlVariables();
			break;	
		case 'l': // Display content requested
			print_P(PSTR("L:"));
			char stringBuffer[21];
			for(uint8_t i=0;i<4;i++){
				display.lcd.getLine(i, stringBuffer);
				print_P(PSTR("%s<BR>"), stringBuffer);
			}				
			print_P(PSTR("\n"));
			break;
		case 'j': // Receive settings as json
			receiveJson();
			break;
		default:
			debugMessage(PSTR("Invalid command Received by Arduino: %c"), inByte);
		}
		//Serial.flush(); Messages can be back to back. Flush should not be necessary.
		// Functions should not read more than what is meant for that function.
	}
}
コード例 #2
0
ファイル: PiLink.cpp プロジェクト: elcojacobs/brewpi-firmware
void PiLink::receiveJson(void){

	parseJson(&processJsonPair, NULL);	
				
#if !BREWPI_SIMULATE	// this is quite an overhead and not needed for the simulator
	sendControlSettings();	// update script with new settings
	sendControlConstants();
#endif
	return;
}
コード例 #3
0
ファイル: PiLink.cpp プロジェクト: elcojacobs/brewpi-firmware
void PiLink::receive(void){
	while (piStream.available() > 0) {
		char inByte = piStream.read();              
		switch(inByte){
		case ' ':
		case '\n':
		case '\r':
			break;

#if BREWPI_SIMULATE==1
		case 'y':
			parseJson(HandleSimulatorConfig);
			break;
		case 'Y':
			printSimulatorSettings();
			break;		
#endif						
		case 'A': // alarm on
			soundAlarm(true);
			break;
		case 'a': // alarm off
			soundAlarm(false);
			break;
			
		case 't': // temperatures requested
			printTemperatures();      
			break;		
		case 'C': // Set default constants
			tempControl.loadDefaultConstants();
			display.printStationaryText(); // reprint stationary text to update to right degree unit
			sendControlConstants(); // update script with new settings
			logInfo(INFO_DEFAULT_CONSTANTS_LOADED);
			break;
		case 'S': // Set default settings
			tempControl.loadDefaultSettings();
			sendControlSettings(); // update script with new settings
			logInfo(INFO_DEFAULT_SETTINGS_LOADED);
			break;
		case 's': // Control settings requested
			sendControlSettings();
			break;
		case 'c': // Control constants requested
			sendControlConstants();
			break;

		case 'v': // Control variables requested, send Control Object as json
		    sendControlVariables();
			break;
		case 'n':
			// v version
			// s shield type
			// y: simulator			
			// b: board
			print_P(PSTR(   "N:{"
                            "\"v\":\"" PRINTF_PROGMEM "\","
                            "\"n\":\"" PRINTF_PROGMEM "\","
                            "\"s\":%d,"
                            "\"y\":%d,"
                            "\"b\":\"%c\","
                            "\"l\":\"%d\""
                            "}"), 
					PSTR(VERSION_STRING),               // v:
					PSTR(stringify(BUILD_NAME)),      // n:                 
					getShieldVersion(),               // s:
					BREWPI_SIMULATE,                    // y:
					BREWPI_BOARD,      // b:
					BREWPI_LOG_MESSAGES_VERSION);       // l:
			printNewLine();
			break;
		case 'l': // Display content requested
			printResponse('L');						
			piStream.print('[');
			char stringBuffer[21];
			for(uint8_t i=0;i<4;i++){
				display.getLine(i, stringBuffer);
				print_P(PSTR("\"%s\""), stringBuffer);
				char close = (i<3) ? ',':']';
				piStream.print(close);
			}							
			printNewLine();						
			break;
		case 'j': // Receive settings as json
			receiveJson();
			break;

#if BREWPI_EEPROM_HELPER_COMMANDS
		case 'e': // dump contents of eeprom						
			openListResponse('E');
			for (uint16_t i=0; i<1024;) {
				if (i>0) {
					piLink.printNewLine();
					piLink.print(',');
				}
				piLink.print('\"');
				for (uint8_t j=0; j<64; j++) {
					uint8_t d = eepromAccess.readByte(i++);
					printNibble(d>>4);
					printNibble(d);
				}				
				piLink.print('\"');
			}
			closeListResponse();
			break;
#endif
			
		case 'E': // initialize eeprom
			eepromManager.initializeEeprom();
			logInfo(INFO_EEPROM_INITIALIZED);
			settingsManager.loadSettings();
			break;

		case 'd': // list devices in eeprom order
			openListResponse('d');
			deviceManager.listDevices(piStream);
			closeListResponse();
			break;

		case 'U': // update device		
			deviceManager.parseDeviceDefinition(piStream);
			break;
			
		case 'h': // hardware query
			openListResponse('h');
			deviceManager.enumerateHardwareToStream(piStream);
			closeListResponse();
			break;

#if (BREWPI_DEBUG > 0)			
		case 'Z': // zap eeprom
			eepromManager.zapEeprom();
			logInfo(INFO_EEPROM_ZAPPED);
			break;
#endif

		case 'R': // reset 
            handleReset();
            break;
            
        case 'F': // flash firmware
            flashFirmware();
            break;
            
        default:
        logWarningInt(WARNING_INVALID_COMMAND, inByte);
        }
    }
}
コード例 #4
0
ファイル: PiLink.cpp プロジェクト: DigitalWarrior/brewpi-avr
void PiLink::receiveJson(void){
	char key[30];
	char val[30];
	uint8_t index=0;
	char character=0;
	delay(1);
	while(Serial.available() > 0){ // outer while loop can process multiple pairs
		index=0;
		while(Serial.available() > 0) // get key
		{
			delay(1);
			character = Serial.read();
			if(character == ':'){		
				// value comes now
				break;
			}
			else if(character == ' ' || character == '{' || character == '"'){
				;
			}
			else{
				key[index++] = character;
			}
			if(index>=29)
			{
				return; // value was too long, don't process anything
			}
		}
		key[index]=0; // null terminate string
		index = 0;
		while(Serial.available() > 0) // get value
		{
			delay(1);
			character = Serial.read();
			if(character == ',' || character == '}'){
				// end of value
				break;
			}
			else if(character == ' ' || character == '"'){
				; // skip spaces and apostrophes
			}
			else{
				val[index++] = character;
			}
			if(index>=29)
			{
				return; // value was too long, don't process anything
			}
		}
		val[index]=0; // null terminate string
		processJsonPair(key,val);
		
		if(character == '}'){
			// this was the last pair.
			tempControl.storeSettings(); // store new settings to EEPROM
			tempControl.storeConstants();
			sendControlSettings(); // update script with new settings
			sendControlConstants();
			return;
		}
	}
}