Dataset storage (#866)

* Store active dataset and pending dataset in non-volatile memory.

  * Retrieve active dataset and pending dataset from non-volatile memory after each reboot.

  * Leader will generate the active dataset if it is not initialized.

  * Clear pending dataset after it replaces active dataset.

  * Create different pseudo flash files for posix nodes.
This commit is contained in:
Shu Chen
2016-10-24 22:13:23 -07:00
committed by Jonathan Hui
parent 82ab677049
commit 46f920cf6a
15 changed files with 271 additions and 14 deletions
+2
View File
@@ -33,6 +33,7 @@
*/
#include <platform/uart.h>
#include <platform/flash.h>
#include "platform-cc2538.h"
otInstance *sInstance;
@@ -43,6 +44,7 @@ void PlatformInit(int argc, char *argv[])
cc2538RandomInit();
cc2538RadioInit();
otPlatUartEnable();
otPlatFlashInit();
(void)argc;
(void)argv;
@@ -0,0 +1,59 @@
/*
* Copyright (c) 2016, The OpenThread Authors.
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions are met:
* 1. Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
* 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution.
* 3. Neither the name of the copyright holder nor the
* names of its contributors may be used to endorse or promote products
* derived from this software without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
* AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
* ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE
* LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
* CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
* SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
* INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
* CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
* ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
* POSSIBILITY OF SUCH DAMAGE.
*/
#include "platform-posix.h"
ThreadError otPlatFlashInit(void)
{
return kThreadError_NotImplemented;
}
uint32_t otPlatFlashGetSize(void)
{
return 0;
}
ThreadError otPlatFlashErasePage(uint32_t aAddress)
{
return kThreadError_NotImplemented;
}
ThreadError otPlatFlashStatusWait(uint32_t aTimeout)
{
return kThreadError_None;
}
uint32_t otPlatFlashWrite(uint32_t aAddress, uint8_t *aData, uint32_t aSize)
{
return 0;
}
uint32_t otPlatFlashRead(uint32_t aAddress, uint8_t *aData, uint32_t aSize)
{
return 0;
}
+5 -2
View File
@@ -53,9 +53,12 @@ enum
ThreadError otPlatFlashInit(void)
{
ThreadError error = kThreadError_None;
char fileName[16];
char fileName[20];
struct stat st;
bool create = false;
struct timeval tv;
gettimeofday(&tv, NULL);
memset(&st, 0, sizeof(st));
@@ -64,7 +67,7 @@ ThreadError otPlatFlashInit(void)
mkdir("tmp", 0777);
}
snprintf(fileName, sizeof(fileName), "tmp/%d.flash", NODE_ID);
snprintf(fileName, sizeof(fileName), "tmp/%d_%d.flash", NODE_ID, (uint32_t)tv.tv_usec);
if (access(fileName, 0))
{
+2
View File
@@ -43,6 +43,7 @@
#include <openthread.h>
#include <platform/alarm.h>
#include <platform/flash.h>
#include <platform/uart.h>
uint32_t NODE_ID = 1;
@@ -68,6 +69,7 @@ void PlatformInit(int argc, char *argv[])
platformAlarmInit();
platformRadioInit();
platformRandomInit();
otPlatFlashInit();
}
bool UartInitialized = false;