示例#1
0
uint8_t receiveSingleFrame() { 
    
    uint8_t ret = LW232_OK;
    uint8_t idx = 0;
    if (CAN_OK == readMsgBufID(&lw232_CanId, &lw232_PacketLen, lw232_Buffer)) {
        if (lw232_CanId > 0x1FFFFFFF) {
            ret = LW232_ERR; // address if totally wrong
        }
        else if (checkPassFilter(lw232_CanId)) {// do we want to skip some addresses?
            if (isExtendedFrame()) {
                printChar(LW232_TR29);
                printFullByte(HIGH_BYTE(HIGH_WORD(lw232_CanId)));
                printFullByte(LOW_BYTE(HIGH_WORD(lw232_CanId)));
                printFullByte(HIGH_BYTE(LOW_WORD(lw232_CanId)));
                printFullByte(LOW_BYTE(LOW_WORD(lw232_CanId)));
            }
            else {
                printChar(LW232_TR11);
                printNibble(HIGH_BYTE(LOW_WORD(lw232_CanId)));
                printFullByte(LOW_BYTE(LOW_WORD(lw232_CanId)));
            }
            //write data len
            printNibble(lw232_PacketLen);
            //write data
            for (idx = 0; idx < lw232_PacketLen; idx++) {
                printFullByte(lw232_Buffer[idx]);
            }
            //write timestamp if needed
            if (lw232_TimeStamp != LW232_TIMESTAMP_OFF) {
                uint32_t time = 0; //millis();
                if (lw232_TimeStamp == LW232_TIMESTAMP_ON_NORMAL) { 
                    // standard LAWICEL protocol. two bytes.
                    time %= 60000;  
                } else {
                    // non standard protocol - 4 bytes timestamp
                    printFullByte(HIGH_BYTE(HIGH_WORD(time)));
                    printFullByte(LOW_BYTE(HIGH_WORD(time)));
                }
                printFullByte(HIGH_BYTE(LOW_WORD(time)));
                printFullByte(LOW_BYTE(LOW_WORD(time)));
            }
        }
    }
    else {
        ret = LW232_ERR;
    }
    return ret;
}
示例#2
0
文件: USCI.c 项目: robwasab/TV_B_GONE
void printInt(void * foo, uint8_t bytes)
{
	uint8_t * b = (uint8_t *) foo;
    bytes -= 1;
	USCI_printString("0x");
	do {
	   printNibble(b[bytes] >> 4);
	   printNibble(b[bytes]);
	}
	while (bytes--);
	RET();
}
示例#3
0
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);
        }
    }
}