Esempio n. 1
0
unsigned char SetttingsAction(unsigned char mode)
{
	unsigned char i,save = FALSE;
/* mode:
#define SETTINGS_LOAD		0x00
#define SETTINGS_CLEAR		0x01
#define SETTINGS_NEW_ID		0x02
#define SETTINGS_NEW_ENCRYP	0x04	
#define SETTINGS_RESET_ALL	0x07
*/
	// Read settings from eeprom
	EepromRead((unsigned char*)&settings, sizeof(settings_t), SETTINGS_ADDRESS);

	// Check settings are valid first (or changing id will reset all)
	if(settings.checksum != SettingsChecksum())
	{
		mode |= SETTINGS_CLEAR; // Need to clear them
		save = TRUE;
	}

	// Check id is valid
	if(	(settings.deviceId.val32&0x00fffffful) == 0x00ffffffUL || 
		(settings.deviceId.val32&0x00fffffful) == 0x00000000UL ||
		(mode & SETTINGS_NEW_ID) )
	{
		// Make a random id
		settings.deviceId.val8[3] = HEADER_BYTE_MSB; 
		WriteRandom(settings.deviceId.val8, 3);
		save = TRUE;
	}

	// Check for invalid encryption 
	for(i=0;i<AES_KEY_SIZE;i++)
	{
		if(settings.key[i] != 0xff && settings.key[i] != 0x00) 
			break;
	}
	if((mode & SETTINGS_NEW_ENCRYP) || (i == AES_KEY_SIZE))
	{
		// Need to generate encryption mask
		WriteRandom(&settings.key, AES_KEY_SIZE);
		// Save encryption packet	
		save = TRUE;
	}

	// If setting to defaults
	if(mode & SETTINGS_CLEAR)
	{
		settings.batt_min = VBATT_MIN;
		settings.tx_power = RADIO_TX_PWR_DBM;
		settings.pir_threshold = PIR_THRESHOLD;
		settings.pir_suspect_val = PIR_THRESHOLD_SUSPECT_VAL;
		settings.pir_suspect_count = PIR_THRESHOLD_SUSPECT_COUNT;
		settings.pir_suspect_release = PIR_THRESHOLD_SUSPECT_RELEASE;
		settings.pir_disarm_time = PIR_DISARM_TIME;
		settings.pir_led_time = PIR_LED_TIME;
		settings.sensor_settle_time = PIR_SETTLE_TIME;
		settings.sw_led_time = SW_LED_TIME;
		settings.credit_interval = CREDIT_INTERVAL;
		settings.max_pir_credits = MAX_PIR_CREDITS;
		settings.max_switch_credits = MAX_SWITCH_CREDITS;
		settings.sample_interval = SAMPLE_INTERVAL;
		settings.num_tx_repeats = SAMPLE_RETRANSMITS;
		save = TRUE;
	}
	
	// Do we need to save
	if(save)
	{
		SettingsSave();
	}
	return save;
}
Esempio n. 2
0
INT
_cdecl main (
    INT Argc,
    CHAR *Argv[]
    )
{
    UCHAR testCase;

    //
    // Parse cmd line
    //

    if (!ParseCmdLine(Argc,Argv)) {
        return 1;
    }

    //
    // Create the test file
    //

    if (!CreateTestFile()) {
        return 2;
    }

    //
    // Call appropriate test routine.
    //

    testCase = (Test << 1) | Access;
    switch (testCase) {
        case 0:

           if (!ReadSequential(Iterations)) {
               return 3;
           }
            break;

        case 1:

            //
            // Read random
            //

            if (!ReadRandom(Iterations)) {
                return 3;
            }

            break;

        case 2:

            if (!WriteSequential(Iterations)) {
                return 3;
            }

            break;

        case 3:

            //
            // Write random
            //

            if (!WriteRandom(Iterations)) {
                return 3;
            }

            break;

        default:
            printf("Invalid test case\n");
            return 3;
    }



    return 0;

}