コード例 #1
0
/* Saves only the TimeParams (a subset of Config Params) for speed/power efficiency
 * Platform-specific implementation for persistence on the nRF5x. Based on the
 * pstorage module provided by the Nordic SDK. */
void saveEddystoneTimeParams(const TimeParams_t *timeP)
{
    // Copy the time params object to the main datastructure
    memcpy(&persistentParams.params.timeParams, timeP, sizeof(TimeParams_t));
    // Test if this is the first pstorage update, or an update
    if (persistentParams.persistenceSignature != PersistentParams_t::MAGIC) {
        persistentParams.persistenceSignature = PersistentParams_t::MAGIC;
        pstorage_store(&pstorageHandle,
                       reinterpret_cast<uint8_t *>(&persistentParams),
                       sizeof(TimeParams_t),
                       offsetof(PersistentParams_t, params.timeParams) /* offset */);  
    } else {
        pstorage_update(&pstorageHandle,
                        reinterpret_cast<uint8_t *>(&persistentParams),
                        sizeof(TimeParams_t),
                        offsetof(PersistentParams_t, params.timeParams) /* offset */); 
    }
}
コード例 #2
0
/* Platform-specific implementation for persistence on the nRF5x. Based on the
 * pstorage module provided by the Nordic SDK. */
void saveURIBeaconConfigParams(const EddystoneService::EddystoneParams_t *paramsP)
{
    PersistentParams_t persistentParams;
    memcpy(&persistentParams.params, paramsP, sizeof(EddystoneService::EddystoneParams_t));
    if (persistenceSignature != PersistentParams_t::MAGIC) {
        persistentParams.persistenceSignature = PersistentParams_t::MAGIC;
        persistenceSignature = PersistentParams_t::MAGIC;
        pstorage_store(&pstorageHandle,
                       reinterpret_cast<uint8_t *>(&persistentParams),
                       sizeof(PersistentParams_t),
                       0 /* offset */);
    } else {
        persistentParams.persistenceSignature = PersistentParams_t::MAGIC;
        pstorage_update(&pstorageHandle,
                        reinterpret_cast<uint8_t *>(&persistentParams),
                        sizeof(PersistentParams_t),
                        0 /* offset */);
    }
}
コード例 #3
0
void pstorage_driver_run(void) 
{
    uint32_t err_code;
    
	  // Check whether the currently waiting for pstorage event.
    if(pstorage_driver_store.wait_flag) 
    {
        return;
    } 
    
    switch(pstorage_driver_store.state) 
    {
      
			  // Idle state
        case STORE_STATE_IDLE: 
        {
					  // Check whether the storing process is running.
            if(!pstorage_driver_store.run_flag) 
            {
                return;
            }
						
            pstorage_driver_set_next_state();                                  // Go to next state.
        }
        
				// Clear PSTORAGE_DRIVER_MAGIC_NUM from corresponding block.
        case STORE_STATE_CLEAR_MAGIC: 
        {
            uint16_t tmp_size;
					
					  // Calculate offset of PSTORAGE_DRIVER_MAGIC_NUM in block.
            tmp_size = pstorage_driver_store.block->size;
            if((tmp_size % 4) != 0) 
            {
                tmp_size += 4 - (tmp_size % 4);
            }
						
						// Start storing "clear" value.
            tmp_magic_number = 0xFFFFFFFF;
            err_code = pstorage_update(&pstorage_driver_store.block->block_id, (uint8_t *)&tmp_magic_number, 4, tmp_size);
            if(err_code != NRF_SUCCESS) 
            {
							  // Stop storing process.
                pstorage_driver_update_store_status();
                pstorage_driver_set_idle_state();
                return;
            }
            pstorage_driver_store.wait_flag = true;
            break;
        }
          
				// Store data.
        case STORE_STATE_STORE_DATA: 
        {
            uint16_t tmp_size;
					
					  // Size of storing data must be divisible by 4.
            tmp_size = pstorage_driver_store.block->size;
            if((tmp_size % 4) != 0) 
            {
                tmp_size += 4 - (tmp_size % 4);
            } 
						
						// Start storing data.
            err_code = pstorage_update(&pstorage_driver_store.block->block_id, pstorage_driver_store.block->data, tmp_size, 0);
            if(err_code != NRF_SUCCESS) 
            {
							  // Stop storing process.
                pstorage_driver_update_store_status();
                pstorage_driver_set_idle_state();
                return;
            }
            pstorage_driver_store.wait_flag = true;
            break;
        }
        
				// Store PSTORAGE_DRIVER_MAGIC_NUM at the end of data.
        case STORE_STATE_ADD_MAGIC: 
        {
            uint16_t tmp_size;
					  
					  // Calculate offset of PSTORAGE_DRIVER_MAGIC_NUM in block.
            tmp_size = pstorage_driver_store.block->size;
            if((tmp_size % 4) != 0) 
            {
                tmp_size += 4 - (tmp_size % 4);
            }
            tmp_magic_number = PSTORAGE_DRIVER_MAGIC_NUM;
						// Start storing PSTORAGE_DRIVER_MAGIC_NUM value.
            err_code = pstorage_update(&pstorage_driver_store.block->block_id, (uint8_t *)&tmp_magic_number, 4, tmp_size);
            if(err_code != NRF_SUCCESS) 
            {
							  // Stop storing process.
                pstorage_driver_update_store_status();
                pstorage_driver_set_idle_state();
                return;
            }
            pstorage_driver_store.wait_flag = true;
            break;
        }
    }
}