Skip to content

Commit

Permalink
Code updates & harmonization (#1201)
Browse files Browse the repository at this point in the history
  • Loading branch information
tekka007 authored Oct 21, 2018
1 parent b6ab7aa commit 8e8f44b
Show file tree
Hide file tree
Showing 101 changed files with 2,114 additions and 557 deletions.
9 changes: 8 additions & 1 deletion MyASM.S
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,14 @@
*
*/

#if defined(ARDUINO_ARCH_NRF5)
#if defined(ARDUINO_ARCH_SAMD)
/* workaround to prevent compiler error */
.thumb_func
doNothing:
nop
.size doNothing, .-doNothing

#elif defined(ARDUINO_ARCH_NRF5)
/* workaround to prevent compiler error */
.thumb_func
doNothing:
Expand Down
1 change: 1 addition & 0 deletions MyConfig.h
Original file line number Diff line number Diff line change
Expand Up @@ -1641,6 +1641,7 @@
* | @ref MY_SIGNING_SOFT_RANDOMSEED_PIN | Change default software RNG seed pin | "#define" in the top of your sketch | Not supported
* | @ref MY_RF24_ENABLE_ENCRYPTION | Enables encryption on RF24 radios | "#define" in the top of your sketch | @verbatim --my-rf24-encryption-enabled @endverbatim
* | @ref MY_RFM69_ENABLE_ENCRYPTION | Enables encryption on %RFM69 radios | "#define" in the top of your sketch | @verbatim --my-rfm69-encryption-enabled @endverbatim
* | @ref MY_RFM95_ENABLE_ENCRYPTION | Enables encryption on %RFM95 radios | "#define" in the top of your sketch | @verbatim --my-rfm95-encryption-enabled @endverbatim
* | @ref MY_NRF5_ESB_ENABLE_ENCRYPTION | Enables encryption on nRF5 radios | "#define" in the top of your sketch | Not supported
* | @ref MY_NODE_LOCK_FEATURE | Enables the node locking feature | "#define" in the top of your sketch | Not supported
* | @ref MY_NODE_UNLOCK_PIN | Change default unlock pin | "#define" in the top of your sketch | Not supported
Expand Down
18 changes: 9 additions & 9 deletions MySensors.h
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@
#endif

// HARDWARE
#include "hal/architecture/MyHw.h"
#include "hal/architecture/MyHwHAL.h"
#include "hal/crypto/MyCryptoHAL.h"
#if defined(ARDUINO_ARCH_ESP8266)
#include "hal/architecture/ESP8266/MyHwESP8266.cpp"
Expand All @@ -58,7 +58,7 @@
#include "hal/architecture/ESP32/MyHwESP32.cpp"
#include "hal/crypto/ESP32/MyCryptoESP32.cpp"
#elif defined(ARDUINO_ARCH_AVR)
#include "drivers/AVR/DigitalWriteFast/digitalWriteFast.h"
#include "hal/architecture/AVR/drivers/DigitalWriteFast/digitalWriteFast.h"
#include "hal/architecture/AVR/MyHwAVR.cpp"
#include "hal/crypto/AVR/MyCryptoAVR.cpp"
#elif defined(ARDUINO_ARCH_SAMD)
Expand Down Expand Up @@ -338,7 +338,7 @@ MY_DEFAULT_RX_LED_PIN in your sketch instead to enable LEDs
#if defined(ARDUINO_ARCH_ESP8266)
#error Soft SPI is not available on ESP8266
#endif
#include "drivers/AVR/DigitalIO/DigitalIO.h"
#include "hal/architecture/AVR/drivers/DigitalIO/DigitalIO.h"
#endif

// SOFTSERIAL
Expand All @@ -361,14 +361,14 @@ MY_DEFAULT_RX_LED_PIN in your sketch instead to enable LEDs

// Transport drivers
#if defined(MY_RADIO_RF24)
#include "drivers/RF24/RF24.cpp"
#include "hal/transport/RF24/driver/RF24.cpp"
#include "hal/transport/RF24/MyTransportRF24.cpp"
#elif defined(MY_RADIO_NRF5_ESB)
#if !defined(ARDUINO_ARCH_NRF5)
#error No support for nRF5 radio on this platform
#endif
#include "drivers/NRF5/Radio.cpp"
#include "drivers/NRF5/Radio_ESB.cpp"
#include "hal/transport/NRF5_ESB/driver/Radio.cpp"
#include "hal/transport/NRF5_ESB/driver/Radio_ESB.cpp"
#include "hal/transport/NRF5_ESB/MyTransportNRF5_ESB.cpp"
#elif defined(MY_RS485)
#if !defined(MY_RS485_HWSERIAL)
Expand All @@ -380,13 +380,13 @@ MY_DEFAULT_RX_LED_PIN in your sketch instead to enable LEDs
#include "hal/transport/RS485/MyTransportRS485.cpp"
#elif defined(MY_RADIO_RFM69)
#if defined(MY_RFM69_NEW_DRIVER)
#include "drivers/RFM69/new/RFM69_new.cpp"
#include "hal/transport/RFM69/driver/new/RFM69_new.cpp"
#else
#include "drivers/RFM69/old/RFM69_old.cpp"
#include "hal/transport/RFM69/driver/old/RFM69_old.cpp"
#endif
#include "hal/transport/RFM69/MyTransportRFM69.cpp"
#elif defined(MY_RADIO_RFM95)
#include "drivers/RFM95/RFM95.cpp"
#include "hal/transport/RFM95/driver/RFM95.cpp"
#include "hal/transport/RFM95/MyTransportRFM95.cpp"
#endif

Expand Down
4 changes: 2 additions & 2 deletions core/MyEepromAddresses.h
Original file line number Diff line number Diff line change
Expand Up @@ -83,9 +83,9 @@
/** @brief Address RF AES encryption key. This is set with @ref SecurityPersonalizer.ino */
#define EEPROM_RF_ENCRYPTION_AES_KEY_ADDRESS (EEPROM_SIGNING_SOFT_SERIAL_ADDRESS + SIZE_SIGNING_SOFT_SERIAL)
/** @brief Address node lock counter. This is set with @ref SecurityPersonalizer.ino */
#define EEPROM_NODE_LOCK_COUNTER (EEPROM_RF_ENCRYPTION_AES_KEY_ADDRESS + SIZE_RF_ENCRYPTION_AES_KEY)
#define EEPROM_NODE_LOCK_COUNTER_ADDRESS (EEPROM_RF_ENCRYPTION_AES_KEY_ADDRESS + SIZE_RF_ENCRYPTION_AES_KEY)
/** @brief First free address for sketch static configuration */
#define EEPROM_LOCAL_CONFIG_ADDRESS (EEPROM_NODE_LOCK_COUNTER + SIZE_NODE_LOCK_COUNTER)
#define EEPROM_LOCAL_CONFIG_ADDRESS (EEPROM_NODE_LOCK_COUNTER_ADDRESS + SIZE_NODE_LOCK_COUNTER)

#endif // MyEepromAddresses_h

Expand Down
36 changes: 18 additions & 18 deletions core/MyMessage.h
Original file line number Diff line number Diff line change
Expand Up @@ -479,9 +479,9 @@ typedef union {
struct {

#endif
uint8_t last; ///< 8 bit - Id of last node this message passed
uint8_t sender; ///< 8 bit - Id of sender node (origin)
uint8_t destination; ///< 8 bit - Id of destination node
uint8_t last; //!< 8 bit - Id of last node this message passed
uint8_t sender; //!< 8 bit - Id of sender node (origin)
uint8_t destination; //!< 8 bit - Id of destination node

/**
* 2 bit - Protocol version<br>
Expand All @@ -498,35 +498,35 @@ typedef union {
*/
uint8_t command_ack_payload;

uint8_t type; ///< 8 bit - Type varies depending on command
uint8_t sensor; ///< 8 bit - Id of sensor that this message concerns.
uint8_t type; //!< 8 bit - Type varies depending on command
uint8_t sensor; //!< 8 bit - Id of sensor that this message concerns.

/*
* Each message can transfer a payload. We add one extra byte for string
* terminator \0 to be "printable" this is not transferred OTA
* This union is used to simplify the construction of the binary data types transferred.
*/
union {
uint8_t bValue; ///< unsigned byte value (8-bit)
uint16_t uiValue; ///< unsigned integer value (16-bit)
int16_t iValue; ///< signed integer value (16-bit)
uint32_t ulValue; ///< unsigned long value (32-bit)
int32_t lValue; ///< signed long value (32-bit)
struct { //< Float messages
uint8_t bValue; //!< unsigned byte value (8-bit)
uint16_t uiValue; //!< unsigned integer value (16-bit)
int16_t iValue; //!< signed integer value (16-bit)
uint32_t ulValue; //!< unsigned long value (32-bit)
int32_t lValue; //!< signed long value (32-bit)
struct { //!< Float messages
float fValue;
uint8_t fPrecision; ///< Number of decimals when serializing
uint8_t fPrecision; //!< Number of decimals when serializing
};
struct { //< Presentation messages
uint8_t version; ///< Library version
uint8_t sensorType; ///< Sensor type hint for controller, see table above
struct { //!< Presentation messages
uint8_t version; //!< Library version
uint8_t sensorType; //!< Sensor type hint for controller, see table above
};
char data[MAX_PAYLOAD + 1]; ///< Buffer for raw payload data
} __attribute__((packed)); ///< Doxygen will complain without this comment
char data[MAX_PAYLOAD + 1]; //!< Buffer for raw payload data
} __attribute__((packed)); //!< Doxygen will complain without this comment
#if defined(__cplusplus) || defined(DOXYGEN)
} __attribute__((packed));
#else
};
uint8_t array[HEADER_SIZE + MAX_PAYLOAD + 1]; ///< buffer for entire message
uint8_t array[HEADER_SIZE + MAX_PAYLOAD + 1]; //!< buffer for entire message
} __attribute__((packed)) MyMessage;
#endif

Expand Down
10 changes: 5 additions & 5 deletions core/MySensorsCore.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -706,7 +706,7 @@ void _nodeLock(const char* str)
{
#ifdef MY_NODE_LOCK_FEATURE
// Make sure EEPROM is updated to locked status
hwWriteConfig(EEPROM_NODE_LOCK_COUNTER, 0);
hwWriteConfig(EEPROM_NODE_LOCK_COUNTER_ADDRESS, 0);
while (1) {
setIndication(INDICATION_ERR_LOCKED);
CORE_DEBUG(PSTR("MCO:NLK:NODE LOCKED. TO UNLOCK, GND PIN %" PRIu8 " AND RESET\n"),
Expand All @@ -730,15 +730,15 @@ void _checkNodeLock(void)
{
#ifdef MY_NODE_LOCK_FEATURE
// Check if node has been locked down
if (hwReadConfig(EEPROM_NODE_LOCK_COUNTER) == 0) {
if (hwReadConfig(EEPROM_NODE_LOCK_COUNTER_ADDRESS) == 0) {
// Node is locked, check if unlock pin is asserted, else hang the node
hwPinMode(MY_NODE_UNLOCK_PIN, INPUT_PULLUP);
// Make a short delay so we are sure any large external nets are fully pulled
uint32_t enter = hwMillis();
while (hwMillis() - enter < 2) {}
if (hwDigitalRead(MY_NODE_UNLOCK_PIN) == 0) {
// Pin is grounded, reset lock counter
hwWriteConfig(EEPROM_NODE_LOCK_COUNTER, MY_NODE_LOCK_COUNTER_MAX);
hwWriteConfig(EEPROM_NODE_LOCK_COUNTER_ADDRESS, MY_NODE_LOCK_COUNTER_MAX);
// Disable pullup
hwPinMode(MY_NODE_UNLOCK_PIN, INPUT);
setIndication(INDICATION_ERR_LOCKED);
Expand All @@ -748,9 +748,9 @@ void _checkNodeLock(void)
hwPinMode(MY_NODE_UNLOCK_PIN, INPUT);
_nodeLock("LDB"); //Locked during boot
}
} else if (hwReadConfig(EEPROM_NODE_LOCK_COUNTER) == 0xFF) {
} else if (hwReadConfig(EEPROM_NODE_LOCK_COUNTER_ADDRESS) == 0xFF) {
// Reset value
hwWriteConfig(EEPROM_NODE_LOCK_COUNTER, MY_NODE_LOCK_COUNTER_MAX);
hwWriteConfig(EEPROM_NODE_LOCK_COUNTER_ADDRESS, MY_NODE_LOCK_COUNTER_MAX);
}
#endif
}
Expand Down
10 changes: 4 additions & 6 deletions core/MyTransport.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -90,7 +90,7 @@ void stInitTransition(void)
#endif

// Read node settings (ID, parent ID, GW distance) from EEPROM
hwReadConfigBlock((void*)&_transportConfig, (void*)EEPROM_NODE_ID_ADDRESS,
hwReadConfigBlock((void *)&_transportConfig, (void *)EEPROM_NODE_ID_ADDRESS,
sizeof(transportConfig_t));
}

Expand Down Expand Up @@ -360,7 +360,7 @@ void stFailureUpdate(void)
}
}

void transportSwitchSM(transportState_t& newState)
void transportSwitchSM(transportState_t &newState)
{
if (_transportSM.currentState != &newState) {
_transportSM.stateRetries = 0u; // state change, reset retry counter
Expand Down Expand Up @@ -411,7 +411,6 @@ void resetMessageReceived(void)
_transportSM.msgReceived = false;
}


void transportInitialise(void)
{
_transportSM.failureCounter = 0u; // reset failure counter
Expand All @@ -431,6 +430,7 @@ void transportDisable(void)
transportSleep();
}
}

void transportReInitialise(void)
{
if (RADIO_CAN_POWER_OFF == true) {
Expand All @@ -443,7 +443,6 @@ void transportReInitialise(void)
}
}


bool transportWaitUntilReady(const uint32_t waitingMS)
{
// check if transport ready
Expand All @@ -467,7 +466,6 @@ void transportProcess(void)
transportProcessFIFO();
}


bool transportCheckUplink(const bool force)
{
if (!force && (hwMillis() - _transportSM.lastUplinkCheck) < MY_TRANSPORT_CHKUPL_INTERVAL_MS) {
Expand Down Expand Up @@ -717,7 +715,7 @@ void transportProcessMessage(void)
// Is message addressed to this node?
if (destination == _transportConfig.nodeId) {
// prevent buffer overflow by limiting max. possible message length (5 bits=31 bytes max) to MAX_PAYLOAD (25 bytes)
mSetLength(_msg, min(mGetLength(_msg),(uint8_t)MAX_PAYLOAD));
mSetLength(_msg, min(mGetLength(_msg), (uint8_t)MAX_PAYLOAD));
// null terminate data
_msg.data[msgLength] = 0u;
// Check if sender requests an ack back.
Expand Down
4 changes: 2 additions & 2 deletions core/MyTransport.h
Original file line number Diff line number Diff line change
Expand Up @@ -253,7 +253,7 @@ typedef int16_t transportRSSI_t; //!< Datatype for internal RSSI storage
*/
typedef struct {
// SM variables
transportState_t* currentState; //!< pointer to current FSM state
transportState_t *currentState; //!< pointer to current FSM state
uint32_t stateEnter; //!< state enter timepoint
// general transport variables
uint32_t lastUplinkCheck; //!< last uplink check, required to prevent GW flooding
Expand Down Expand Up @@ -334,7 +334,7 @@ void stFailureUpdate(void);
* @brief Switch SM state
* @param newState New state to switch SM to
*/
void transportSwitchSM(transportState_t& newState);
void transportSwitchSM(transportState_t &newState);
/**
* @brief Update SM state
*/
Expand Down
4 changes: 2 additions & 2 deletions core/Version.h
Original file line number Diff line number Diff line change
Expand Up @@ -49,8 +49,8 @@
#define MYSENSORS_LIBRARY_VERSION_MAJOR 2 //!< Major release version
#define MYSENSORS_LIBRARY_VERSION_MINOR 3 //!< Minor release version
#define MYSENSORS_LIBRARY_VERSION_PATCH 1 //!< Patch version
#define MYSENSORS_LIBRARY_VERSION_PRERELEASE "beta" //!< Pre-release suffix, i.e. alpha, beta, rc.1, etc
#define MYSENSORS_LIBRARY_VERSION_PRERELEASE_NUMBER 0x01 //!< incremental counter, starting at 0x00. 0xFF for final release
#define MYSENSORS_LIBRARY_VERSION_PRERELEASE "beta" //!< Pre-release suffix, i.e. alpha, beta, rc.1, etc
#define MYSENSORS_LIBRARY_VERSION_PRERELEASE_NUMBER 0x02 //!< incremental counter, starting at 0x00. 0xFF for final release


#if (MYSENSORS_LIBRARY_VERSION_PRERELEASE_NUMBER != 0xFF)
Expand Down
Loading

0 comments on commit 8e8f44b

Please sign in to comment.