Polishing code (#803)
This commit is contained in:
committed by
Embedded Innovation
parent
f84960dc28
commit
818f887926
@@ -1,12 +1,12 @@
|
||||
/**
|
||||
/*
|
||||
* The MySensors Arduino library handles the wireless radio link and protocol
|
||||
* between your home built sensors/actuators and HA controller of choice.
|
||||
* The sensors forms a self healing radio network with optional repeaters. Each
|
||||
* repeater and gateway builds a routing tables in EEPROM which keeps track of the
|
||||
* network topology allowing messages to be routed to nodes.
|
||||
*
|
||||
* Created by Tomas Hozza <thozza@gmail.com>
|
||||
* Copyright (C) 2015 Tomas Hozza
|
||||
* Created by Henrik Ekblad <henrik.ekblad@mysensors.org>
|
||||
* Copyright (C) 2013-2017 Sensnology AB
|
||||
* Full contributor list: https://github.com/mysensors/Arduino/graphs/contributors
|
||||
*
|
||||
* Documentation: http://www.mysensors.org
|
||||
|
||||
@@ -428,7 +428,7 @@ void gatewayTransportRenewIP(void)
|
||||
3 - rebinf failed
|
||||
4 - rebind success
|
||||
*/
|
||||
static unsigned long next_time = hwMillis() + MY_IP_RENEWAL_INTERVAL;
|
||||
static unsigned long next_time = hwMillis() + MY_IP_RENEWAL_INTERVAL_MS;
|
||||
unsigned long now = hwMillis();
|
||||
|
||||
// http://playground.arduino.cc/Code/TimingRollover
|
||||
@@ -441,6 +441,6 @@ void gatewayTransportRenewIP(void)
|
||||
return;
|
||||
}
|
||||
_w5100_spi_en(false);
|
||||
next_time = now + MY_IP_RENEWAL_INTERVAL;
|
||||
next_time = now + MY_IP_RENEWAL_INTERVAL_MS;
|
||||
}
|
||||
#endif
|
||||
|
||||
@@ -26,14 +26,6 @@
|
||||
#ifndef MyHw_h
|
||||
#define MyHw_h
|
||||
|
||||
#include "MyConfig.h"
|
||||
#include "MyMessage.h"
|
||||
|
||||
|
||||
#ifdef __cplusplus
|
||||
#include <Arduino.h>
|
||||
#endif
|
||||
|
||||
// Implement these as functions or macros
|
||||
/*
|
||||
#define hwInit() MY_SERIALDEVICE.begin(BAUD_RATE)
|
||||
|
||||
+28
-13
@@ -559,12 +559,13 @@ bool transportRouteMessage(MyMessage &message)
|
||||
_transportSM.failedUplinkTransmissions++;
|
||||
} else {
|
||||
_transportSM.failedUplinkTransmissions = 0u;
|
||||
#if defined(MY_SIGNAL_REPORT_ENABLED)
|
||||
// update uplink quality monitor
|
||||
const int16_t signalStrengthRSSI = transportGetSignalReport(SR_TX_RSSI);
|
||||
_transportSM.uplinkQualityRSSI = static_cast<transportRSSI_t>((1 - UPLINK_QUALITY_WEIGHT) *
|
||||
_transportSM.uplinkQualityRSSI
|
||||
+ (UPLINK_QUALITY_WEIGHT * transportRSSItoInternal(signalStrengthRSSI)));
|
||||
|
||||
#endif
|
||||
}
|
||||
}
|
||||
#else
|
||||
@@ -791,21 +792,27 @@ void transportProcessMessage(void)
|
||||
return; // no further processing required
|
||||
}
|
||||
if (type == I_SIGNAL_REPORT_REVERSE) {
|
||||
if (_msg.data[1] == '!') {
|
||||
const int16_t value = transportSignalReport(_msg.data[0]);
|
||||
(void)_msg.set(value);
|
||||
_msg.type = I_SIGNAL_REPORT_RESPONSE;
|
||||
}
|
||||
return; // no further processing required
|
||||
}
|
||||
if (type == I_SIGNAL_REPORT_REQUEST) {
|
||||
const char command = _msg.data[0];
|
||||
int16_t value = INVALID_RSSI;
|
||||
#if defined(MY_SIGNAL_REPORT_ENABLED)
|
||||
if (_msg.data[1] != '!') {
|
||||
const int16_t value = transportSignalReport(_msg.data[0]);
|
||||
(void)transportRouteMessage(build(_msgTmp, GATEWAY_ADDRESS, NODE_SENSOR_ID, C_INTERNAL,
|
||||
I_SIGNAL_REPORT_RESPONSE).set(value));
|
||||
value = transportSignalReport(command);
|
||||
} else {
|
||||
(void)transportRouteMessage(build(_msgTmp, _msg.sender, NODE_SENSOR_ID, C_INTERNAL,
|
||||
I_SIGNAL_REPORT_REVERSE).set(_msg.data, 2));
|
||||
// send request
|
||||
if (transportRouteMessage(build(_msgTmp, _msg.last, NODE_SENSOR_ID, C_INTERNAL,
|
||||
I_SIGNAL_REPORT_REVERSE).set((uint8_t)255))) {
|
||||
// S>s, R>r, ascii delta = 32
|
||||
value = transportSignalReport(command + 32); // reverse
|
||||
};
|
||||
}
|
||||
#else
|
||||
(void)command;
|
||||
#endif
|
||||
(void)transportRouteMessage(build(_msgTmp, GATEWAY_ADDRESS, NODE_SENSOR_ID, C_INTERNAL,
|
||||
I_SIGNAL_REPORT_RESPONSE).set(value));
|
||||
return;
|
||||
}
|
||||
} else if (command == C_STREAM) {
|
||||
@@ -1117,13 +1124,21 @@ int16_t transportSignalReport(const char command)
|
||||
signalReport_t reportCommand;
|
||||
switch (command) {
|
||||
case 'S':
|
||||
// SNR (if available) of incoming message (this)
|
||||
// SNR (if available) of incoming message
|
||||
reportCommand = SR_RX_SNR;
|
||||
break;
|
||||
case 's':
|
||||
// SNR (if available) of incoming ACK message
|
||||
reportCommand = SR_TX_SNR;
|
||||
break;
|
||||
case 'R':
|
||||
// RSSI (if available) of incoming message (this)
|
||||
// RSSI (if available) of incoming message
|
||||
reportCommand = SR_RX_RSSI;
|
||||
break;
|
||||
case 'r':
|
||||
// RSSI (if available) of incoming ACK message
|
||||
reportCommand = SR_TX_RSSI;
|
||||
break;
|
||||
case 'P':
|
||||
// TX powerlevel in %
|
||||
reportCommand = SR_TX_POWER_PERCENT;
|
||||
|
||||
+9
-8
@@ -159,7 +159,6 @@
|
||||
#ifndef MyTransport_h
|
||||
#define MyTransport_h
|
||||
|
||||
#include "MySensorsCore.h"
|
||||
#include "hal/transport/MyTransportHAL.h"
|
||||
|
||||
#ifndef MY_TRANSPORT_MAX_TX_FAILURES
|
||||
@@ -520,13 +519,15 @@ void transportDisable(void);
|
||||
void transportReInitialise(void);
|
||||
/**
|
||||
* @brief Get transport signal report
|
||||
* @param command
|
||||
* S=SNR (if available) of incoming message (this)
|
||||
* R=RSSI (if available) of incoming message (this)
|
||||
* P=TX powerlevel in %
|
||||
* T=TX powerlevel in dBm
|
||||
* U=Uplink quality
|
||||
* @return report
|
||||
* @param command:
|
||||
* R = RSSI (if available) of incoming @ref I_SIGNAL_REPORT_REQUEST message (from last hop)
|
||||
* R! = RSSI (if available) of ACK to @ref I_SIGNAL_REPORT_REVERSE message received from last hop
|
||||
* S = SNR (if available) of incoming @ref I_SIGNAL_REPORT_REQUEST message (from last hop)
|
||||
* S! = SNR (if available) of ACK to @ref I_SIGNAL_REPORT_REVERSE message received from last hop
|
||||
* P = TX powerlevel in %
|
||||
* T = TX powerlevel in dBm
|
||||
* U = Uplink quality (via ACK from parent node), avg. RSSI
|
||||
* @return Signal report (if report is not available, INVALID_RSSI, INVALID_SNR, INVALID_PERCENT, or INVALID_LEVEL is sent instead)
|
||||
*/
|
||||
int16_t transportSignalReport(const char command);
|
||||
|
||||
|
||||
@@ -1,93 +0,0 @@
|
||||
/*
|
||||
* The MySensors Arduino library handles the wireless radio link and protocol
|
||||
* between your home built sensors/actuators and HA controller of choice.
|
||||
* The sensors forms a self healing radio network with optional repeaters. Each
|
||||
* repeater and gateway builds a routing tables in EEPROM which keeps track of the
|
||||
* network topology allowing messages to be routed to nodes.
|
||||
*
|
||||
* Created by Henrik Ekblad <henrik.ekblad@mysensors.org>
|
||||
* Copyright (C) 2013-2017 Sensnology AB
|
||||
* Full contributor list: https://github.com/mysensors/Arduino/graphs/contributors
|
||||
*
|
||||
* Documentation: http://www.mysensors.org
|
||||
* Support Forum: http://forum.mysensors.org
|
||||
*
|
||||
* This program is free software; you can redistribute it and/or
|
||||
* modify it under the terms of the GNU General Public License
|
||||
* version 2 as published by the Free Software Foundation.
|
||||
*/
|
||||
|
||||
#include "MyConfig.h"
|
||||
#include "MyTransport.h"
|
||||
#include <stdint.h>
|
||||
#include "drivers/RFM69/RFM69.h"
|
||||
|
||||
RFM69 _radio(MY_RF69_SPI_CS, MY_RF69_IRQ_PIN, MY_RFM69HW, MY_RF69_IRQ_NUM);
|
||||
uint8_t _address;
|
||||
|
||||
|
||||
bool transportInit(void)
|
||||
{
|
||||
#ifdef MY_RF69_RESET
|
||||
pinMode(MY_RF69_RESET, OUTPUT);
|
||||
digitalWrite(MY_RF69_RESET, LOW);
|
||||
#endif
|
||||
#ifdef MY_RF69_DIO5
|
||||
pinMode(MY_RF69_DIO5, INPUT);
|
||||
#endif
|
||||
// Start up the radio library (_address will be set later by the MySensors library)
|
||||
if (_radio.initialize(MY_RFM69_FREQUENCY, _address, MY_RFM69_NETWORKID)) {
|
||||
#ifdef MY_RFM69_ENABLE_ENCRYPTION
|
||||
uint8_t _psk[16];
|
||||
hwReadConfigBlock((void*)_psk, (void*)EEPROM_RF_ENCRYPTION_AES_KEY_ADDRESS, 16);
|
||||
_radio.encrypt((const char*)_psk);
|
||||
memset(_psk, 0, 16); // Make sure it is purged from memory when set
|
||||
#endif
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
void transportSetAddress(const uint8_t address)
|
||||
{
|
||||
_address = address;
|
||||
_radio.setAddress(address);
|
||||
}
|
||||
|
||||
uint8_t transportGetAddress(void)
|
||||
{
|
||||
return _address;
|
||||
}
|
||||
|
||||
bool transportSend(const uint8_t to, const void* data, const uint8_t len)
|
||||
{
|
||||
return _radio.sendWithRetry(to,data,len);
|
||||
}
|
||||
|
||||
bool transportAvailable(void)
|
||||
{
|
||||
return _radio.receiveDone();
|
||||
}
|
||||
|
||||
bool transportSanityCheck(void)
|
||||
{
|
||||
// not implemented yet
|
||||
return true;
|
||||
}
|
||||
|
||||
uint8_t transportReceive(void* data)
|
||||
{
|
||||
memcpy(data,(const void *)_radio.DATA, _radio.DATALEN);
|
||||
// save payload length
|
||||
const uint8_t dataLen = _radio.DATALEN;
|
||||
// Send ack back if this message wasn't a broadcast
|
||||
if(_radio.ACKRequested()) {
|
||||
_radio.sendACK();
|
||||
}
|
||||
return dataLen;
|
||||
}
|
||||
|
||||
void transportPowerDown(void)
|
||||
{
|
||||
_radio.sleep();
|
||||
}
|
||||
@@ -1,92 +0,0 @@
|
||||
/*
|
||||
* The MySensors Arduino library handles the wireless radio link and protocol
|
||||
* between your home built sensors/actuators and HA controller of choice.
|
||||
* The sensors forms a self healing radio network with optional repeaters. Each
|
||||
* repeater and gateway builds a routing tables in EEPROM which keeps track of the
|
||||
* network topology allowing messages to be routed to nodes.
|
||||
*
|
||||
* Created by Henrik Ekblad <henrik.ekblad@mysensors.org>
|
||||
* Copyright (C) 2013-2017 Sensnology AB
|
||||
* Full contributor list: https://github.com/mysensors/Arduino/graphs/contributors
|
||||
*
|
||||
* Documentation: http://www.mysensors.org
|
||||
* Support Forum: http://forum.mysensors.org
|
||||
*
|
||||
* This program is free software; you can redistribute it and/or
|
||||
* modify it under the terms of the GNU General Public License
|
||||
* version 2 as published by the Free Software Foundation.
|
||||
*
|
||||
*/
|
||||
|
||||
#include "MyConfig.h"
|
||||
#include "MyTransport.h"
|
||||
#include "drivers/RFM95/RFM95.h"
|
||||
|
||||
bool transportInit(void)
|
||||
{
|
||||
const bool result = RFM95_initialise(MY_RFM95_FREQUENCY);
|
||||
#if !defined(MY_GATEWAY_FEATURE) && !defined(MY_RFM95_ATC_MODE_DISABLED)
|
||||
// only enable ATC mode nodes
|
||||
RFM95_ATCmode(true, MY_RFM95_ATC_TARGET_RSSI);
|
||||
#endif
|
||||
return result;
|
||||
}
|
||||
|
||||
void transportSetAddress(const uint8_t address)
|
||||
{
|
||||
RFM95_setAddress(address);
|
||||
}
|
||||
|
||||
uint8_t transportGetAddress(void)
|
||||
{
|
||||
return RFM95_getAddress();
|
||||
}
|
||||
|
||||
bool transportSend(const uint8_t to, const void* data, const uint8_t len)
|
||||
{
|
||||
return RFM95_sendWithRetry(to, data, len);
|
||||
}
|
||||
|
||||
bool transportAvailable(void)
|
||||
{
|
||||
return RFM95_available();
|
||||
}
|
||||
|
||||
bool transportSanityCheck(void)
|
||||
{
|
||||
return RFM95_sanityCheck();
|
||||
}
|
||||
|
||||
uint8_t transportReceive(void* data)
|
||||
{
|
||||
return RFM95_recv((uint8_t*)data);
|
||||
}
|
||||
|
||||
void transportPowerDown(void)
|
||||
{
|
||||
(void)RFM95_sleep();
|
||||
}
|
||||
|
||||
// experimental
|
||||
// **********************************************
|
||||
int16_t transportGetReceivingSignalStrength(void)
|
||||
{
|
||||
return RFM95_getReceivingRSSI();
|
||||
}
|
||||
int16_t transportGetSendingSignalStrength(void)
|
||||
{
|
||||
return RFM95_getSendingRSSI();
|
||||
}
|
||||
int8_t transportGetReceivingSNR(void)
|
||||
{
|
||||
return RFM95_getReceivingSNR();
|
||||
}
|
||||
int8_t transportGetSendingSNR(void)
|
||||
{
|
||||
return RFM95_getSendingSNR();
|
||||
}
|
||||
uint8_t transportGetTxPower(void)
|
||||
{
|
||||
return RFM95_getTxPowerPercent();
|
||||
}
|
||||
// **********************************************
|
||||
Reference in New Issue
Block a user