Exemple #1
0
void Storage::readStorage(pstorage_handle_t handle, ps_storage_base_t* item, uint16_t size) {
	pstorage_handle_t block_handle;

	BLE_CALL ( pstorage_block_identifier_get, (&handle, 0, &block_handle) );

	BLE_CALL (pstorage_load, ((uint8_t*)item, &block_handle, size, 0) );

#ifdef PRINT_ITEMS
	_log(INFO, "get struct: \r\n");
	BLEutil::printArray((uint8_t*)item, size);
#endif

}
Exemple #2
0
/**
 * Nordic bug: We have to clear the entire block!
 */
void Storage::clearBlock(pstorage_handle_t handle, ps_storage_id storageID) {

	storage_config_t* config;
	if (!(config = getStorageConfig(storageID))) {
		// if no config was found for the given storage ID return
		return;
	}

	pstorage_handle_t block_handle;
	BLE_CALL ( pstorage_block_identifier_get,(&handle, 0, &block_handle) );

	LOGw("Nordic bug: clear entire block before writing to it");
	BLE_CALL (pstorage_clear, (&block_handle, config->storage_size) );
}
Exemple #3
0
void Storage::readStorage(pstorage_handle_t handle, ps_storage_base_t* item, uint16_t size) {
	pstorage_handle_t block_handle;

	BLE_CALL ( pstorage_block_identifier_get, (&handle, 0, &block_handle) );

	BLE_CALL (pstorage_load, ((uint8_t*)item, &block_handle, size, 0) );

#ifdef PRINT_ITEMS
	uint8_t* ptr = (uint8_t*)item;
	_log(INFO, "getStruct: ");
	for (int i = 0; i < size; i++) {
		_log(INFO, "%X ", ptr[i]);
	}
	_log(INFO, "\r\n");
#endif

}
Exemple #4
0
/**
 * We allocate a single block of size "size". Biggest allocated size is 640 bytes.
 */
void Storage::initBlocks(pstorage_size_t size, pstorage_handle_t& handle) {
	// set parameter
	pstorage_module_param_t param;
	param.block_size = size;
	param.block_count = 1;
	param.cb = pstorage_callback_handler;

	// register
	BLE_CALL ( pstorage_register, (&param, &handle) );
}
Exemple #5
0
void Storage::writeStorage(pstorage_handle_t handle, ps_storage_base_t* item, uint16_t size) {
	pstorage_handle_t block_handle;

#ifdef PRINT_ITEMS
	uint8_t* ptr = (uint8_t*)item;
	_log(INFO, "set struct: ");
	for (int i = 0; i < size; i++) {
		_log(INFO, "%X ", ptr[i]);
	}
	_log(INFO, "\r\n");
#endif

	BLE_CALL ( pstorage_block_identifier_get, (&handle, 0, &block_handle) );

	//	clearBlock(handle);

	BLE_CALL (pstorage_update, (&block_handle, (uint8_t*)item, size, 0) );

}
Exemple #6
0
void Storage::writeStorage(pstorage_handle_t handle, ps_storage_base_t* item, uint16_t size) {
	pstorage_handle_t block_handle;

#ifdef PRINT_ITEMS
	_log(INFO, "set struct: \r\n");
	BLEutil::printArray((uint8_t*)item, size);
#endif

	BLE_CALL ( pstorage_block_identifier_get, (&handle, 0, &block_handle) );

//		clearBlock(handle);

#if CHAR_MESHING==1
	// we need to pause the mesh, otherwise the softdevice won't get time to
	// update the storage
	rbc_mesh_pause();
#endif

	BLE_CALL (pstorage_update, (&block_handle, (uint8_t*)item, size, 0) );

}