-
Notifications
You must be signed in to change notification settings - Fork 511
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #2269 from particle-iot/feature/tracker-cache-esp3…
…2-firmware-version [Gen 3] Fix warm boot; [Tracker] Cache ESP32 firmware version
- Loading branch information
Showing
9 changed files
with
230 additions
and
51 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,50 @@ | ||
/* | ||
* Copyright (c) 2020 Particle Industries, Inc. All rights reserved. | ||
* | ||
* This library is free software; you can redistribute it and/or | ||
* modify it under the terms of the GNU Lesser General Public | ||
* License as published by the Free Software Foundation, either | ||
* version 3 of the License, or (at your option) any later version. | ||
* | ||
* This library is distributed in the hope that it will be useful, | ||
* but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU | ||
* Lesser General Public License for more details. | ||
* | ||
* You should have received a copy of the GNU Lesser General Public | ||
* License along with this library; if not, see <http://www.gnu.org/licenses/>. | ||
*/ | ||
|
||
#pragma once | ||
|
||
#include "tlv_file.h" | ||
|
||
namespace particle { namespace services { | ||
|
||
enum class SystemCacheKey : uint16_t { | ||
WIFI_NCP_FIRMWARE_VERSION = 0x0000 | ||
}; | ||
|
||
class SystemCache { | ||
public: | ||
static SystemCache& instance(); | ||
|
||
// Just straight up proxying to TlvFile | ||
// TODO: add support for multiple values for a key? | ||
int get(SystemCacheKey key, void* value, size_t length); | ||
int set(SystemCacheKey key, const void* value, size_t length); | ||
int del(SystemCacheKey key); | ||
|
||
SystemCache(SystemCache const&) = delete; | ||
SystemCache(SystemCache&&) = delete; | ||
SystemCache& operator=(SystemCache const&) = delete; | ||
SystemCache& operator=(SystemCache &&) = delete; | ||
|
||
protected: | ||
SystemCache(); | ||
|
||
private: | ||
settings::TlvFile tlv_; | ||
}; | ||
|
||
} } // particle::service |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,53 @@ | ||
/* | ||
* Copyright (c) 2020 Particle Industries, Inc. All rights reserved. | ||
* | ||
* This library is free software; you can redistribute it and/or | ||
* modify it under the terms of the GNU Lesser General Public | ||
* License as published by the Free Software Foundation, either | ||
* version 3 of the License, or (at your option) any later version. | ||
* | ||
* This library is distributed in the hope that it will be useful, | ||
* but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU | ||
* Lesser General Public License for more details. | ||
* | ||
* You should have received a copy of the GNU Lesser General Public | ||
* License along with this library; if not, see <http://www.gnu.org/licenses/>. | ||
*/ | ||
|
||
#include "hal_platform.h" | ||
|
||
#if HAL_PLATFORM_FILESYSTEM | ||
|
||
#include "system_cache.h" | ||
#include "enumclass.h" | ||
#include "check.h" | ||
|
||
namespace particle { namespace services { | ||
|
||
SystemCache::SystemCache() | ||
: tlv_("/sys/cache.dat") { | ||
} | ||
|
||
SystemCache& SystemCache::instance() { | ||
static SystemCache cache; | ||
cache.tlv_.init(); | ||
return cache; | ||
} | ||
|
||
int SystemCache::get(SystemCacheKey key, void* value, size_t length) { | ||
return tlv_.get(to_underlying(key), (uint8_t*)value, length); | ||
} | ||
|
||
int SystemCache::set(SystemCacheKey key, const void* value, size_t length) { | ||
CHECK_TRUE(length <= sizeof(uint16_t), SYSTEM_ERROR_TOO_LARGE); | ||
return tlv_.set(to_underlying(key), (const uint8_t*)value, length); | ||
} | ||
|
||
int SystemCache::del(SystemCacheKey key) { | ||
return tlv_.del(to_underlying(key)); | ||
} | ||
|
||
} } // particle::services | ||
|
||
#endif // HAL_PLATFORM_FILESYSTEM |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.