Bind key initialized and loaded from EEPROM
This commit is contained in:
@@ -15,6 +15,7 @@ Copyright (c) 20xx, MPL Contributor1 contrib1@example.net
|
|||||||
#include "qsp.h"
|
#include "qsp.h"
|
||||||
#include "sbus.h"
|
#include "sbus.h"
|
||||||
#include "platform_node.h"
|
#include "platform_node.h"
|
||||||
|
#include "platform_config.h"
|
||||||
|
|
||||||
#ifdef ARDUINO_AVR_FEATHER32U4
|
#ifdef ARDUINO_AVR_FEATHER32U4
|
||||||
#define LORA_SS_PIN 8
|
#define LORA_SS_PIN 8
|
||||||
@@ -36,6 +37,7 @@ Copyright (c) 20xx, MPL Contributor1 contrib1@example.net
|
|||||||
|
|
||||||
RadioNode radioNode;
|
RadioNode radioNode;
|
||||||
PlatformNode platformNode;
|
PlatformNode platformNode;
|
||||||
|
PlatformConfig platformConfig;
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* Main defines for device working in TX mode
|
* Main defines for device working in TX mode
|
||||||
@@ -176,6 +178,8 @@ void setup(void)
|
|||||||
|
|
||||||
#ifdef DEVICE_MODE_TX
|
#ifdef DEVICE_MODE_TX
|
||||||
|
|
||||||
|
platformConfig.seed();
|
||||||
|
|
||||||
#ifdef FEATURE_TX_OLED
|
#ifdef FEATURE_TX_OLED
|
||||||
oled.init();
|
oled.init();
|
||||||
oled.page(TX_PAGE_INIT);
|
oled.page(TX_PAGE_INIT);
|
||||||
@@ -206,14 +210,7 @@ void setup(void)
|
|||||||
|
|
||||||
pinMode(LED_BUILTIN, OUTPUT);
|
pinMode(LED_BUILTIN, OUTPUT);
|
||||||
|
|
||||||
/*
|
platformConfig.loadBindKey();
|
||||||
* Setup salt bind key
|
|
||||||
*/
|
|
||||||
platformNode.bindKey[0] = 0x12;
|
|
||||||
platformNode.bindKey[1] = 0x0a;
|
|
||||||
platformNode.bindKey[2] = 0x36;
|
|
||||||
platformNode.bindKey[3] = 0xa7;
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
uint8_t currentSequenceIndex = 0;
|
uint8_t currentSequenceIndex = 0;
|
||||||
|
|||||||
27
crossbow/platform_config.cpp
Normal file
27
crossbow/platform_config.cpp
Normal file
@@ -0,0 +1,27 @@
|
|||||||
|
#include "platform_config.h"
|
||||||
|
#include "Arduino.h"
|
||||||
|
|
||||||
|
PlatformConfig::PlatformConfig(void) {
|
||||||
|
randomSeed(analogRead(0));
|
||||||
|
};
|
||||||
|
|
||||||
|
void PlatformConfig::seed(void) {
|
||||||
|
uint8_t val;
|
||||||
|
|
||||||
|
val = EEPROM.read(EEPROM_ADDRESS_BIND_KEY_SEEDED);
|
||||||
|
|
||||||
|
if (val != 0xf1) {
|
||||||
|
EEPROM.write(EEPROM_ADDRESS_BIND_0, random(1, 255)); //Yes, from 1 to 254
|
||||||
|
EEPROM.write(EEPROM_ADDRESS_BIND_1, random(1, 255)); //Yes, from 1 to 254
|
||||||
|
EEPROM.write(EEPROM_ADDRESS_BIND_2, random(1, 255)); //Yes, from 1 to 254
|
||||||
|
EEPROM.write(EEPROM_ADDRESS_BIND_3, random(1, 255)); //Yes, from 1 to 254
|
||||||
|
EEPROM.write(EEPROM_ADDRESS_BIND_KEY_SEEDED, 0xf1);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
void PlatformConfig::loadBindKey(void) {
|
||||||
|
platformNode.bindKey[0] = EEPROM.read(EEPROM_ADDRESS_BIND_0);
|
||||||
|
platformNode.bindKey[1] = EEPROM.read(EEPROM_ADDRESS_BIND_1);
|
||||||
|
platformNode.bindKey[2] = EEPROM.read(EEPROM_ADDRESS_BIND_2);
|
||||||
|
platformNode.bindKey[3] = EEPROM.read(EEPROM_ADDRESS_BIND_3);
|
||||||
|
}
|
||||||
27
crossbow/platform_config.h
Normal file
27
crossbow/platform_config.h
Normal file
@@ -0,0 +1,27 @@
|
|||||||
|
#pragma once
|
||||||
|
|
||||||
|
#ifndef PLATFORM_CONFIG_H
|
||||||
|
#define PLATFORM_CONFIG_H
|
||||||
|
|
||||||
|
#include <EEPROM.h>
|
||||||
|
#include "platform_node.h"
|
||||||
|
|
||||||
|
extern PlatformNode platformNode;
|
||||||
|
|
||||||
|
enum platformConfigMemoryLayout {
|
||||||
|
EEPROM_ADDRESS_BIND_KEY_SEEDED = 0x00,
|
||||||
|
EEPROM_ADDRESS_BIND_0,
|
||||||
|
EEPROM_ADDRESS_BIND_1,
|
||||||
|
EEPROM_ADDRESS_BIND_2,
|
||||||
|
EEPROM_ADDRESS_BIND_3,
|
||||||
|
PLATFORM_CONFIG_LAST_BYTE
|
||||||
|
};
|
||||||
|
|
||||||
|
class PlatformConfig {
|
||||||
|
public:
|
||||||
|
PlatformConfig(void);
|
||||||
|
void seed(void);
|
||||||
|
void loadBindKey();
|
||||||
|
};
|
||||||
|
|
||||||
|
#endif
|
||||||
Reference in New Issue
Block a user