unfinished changes, just to be able to transfer files

This commit is contained in:
Dirk Jahnke 2018-11-13 08:07:54 +01:00
parent 7ad2d6e404
commit 08a8edb68a
5 changed files with 167 additions and 129 deletions

15
mos.yml
View File

@ -11,19 +11,25 @@ platform: esp8266
sources:
- src
- src/RadioHead
#- src/RadioHead
- src/RF24
includes:
- src/RadioHead
#- src/RadioHead
- src/RF24
filesystem:
- fs
cdefs:
MPIDE: 0
TEENSYDUINO: 0
#RF_RadioHead
# MPIDE: 0
RH_PLATFORM: RH_PLATFORM_ESP8266
MONGOOSE_OS: 1
ESP_PLATFORM:
RF_RF24:
RF24_SPI_TRANSACTIONS:
FAILURE_HANDLING:
libs:
# common mgos libs
@ -55,6 +61,7 @@ config_schema:
- ["i2c.scl_gpio", 5]
- ["i2c.sda_gpio", 4]
- ["i2c.freq", 1000000]
- ["spi.enable", true]
- ["wifi.ap.ssid", "Fastclock-Master-??????"]
- ["wifi.ap.pass", "Fastclock-Master"]
- ["wifi.sta.ssid", "Pinguin"]

View File

@ -41,7 +41,7 @@ void RF24::csn(bool mode)
#if !defined (SOFTSPI)
_SPI.setBitOrder(MSBFIRST);
_SPI.setDataMode(SPI_MODE0);
_SPI.setClockDivider(SPI_CLOCK_DIV2);
//_SPI.setClockDivider(SPI_CLOCK_DIV2);
#endif
#elif defined (RF24_RPi)
if(!mode)

View File

@ -146,11 +146,13 @@
typedef uint16_t prog_uint16_t;
#if !defined(PSTR)
#define PSTR(x) (x)
#define printf_P printf
#define strlen_P strlen
#define PROGMEM
#define pgm_read_word(p) (*(p))
#endif
#define PRIPSTR "%s"
@ -161,4 +163,3 @@
#endif // __RF24_CONFIG_H__

View File

@ -886,7 +886,7 @@
// Try to be compatible with systems that support yield() and multitasking
// instead of spin-loops
// Recent Arduino IDE or Teensy 3 has yield()
#if (RH_PLATFORM == RH_PLATFORM_ARDUINO && ARDUINO >= 155 && !defined(RH_PLATFORM_ATTINY)) || (TEENSYDUINO && defined(__MK20DX128__))
#if (RH_PLATFORM == RH_PLATFORM_ARDUINO && ARDUINO >= 155 && !defined(RH_PLATFORM_ATTINY)) || (defined(TEENSYDUINO) && TEENSYDUINO && defined(__MK20DX128__))
#define YIELD yield();
#elif (RH_PLATFORM == RH_PLATFORM_ESP8266)
// ESP8266 also hash it

View File

@ -2,13 +2,14 @@
* Copyright (c) 2014-2017 Cesanta Software Limited
* All rights reserved
*/
#define RF_RadioHead
//#define RF_RadioHead
//#define RF_RF24
#include <Arduino.h>
#include <Wire.h>
#include <Adafruit_GFX.h>
#include <Adafruit_SSD1306.h>
//#include <SPI.h>
#ifdef RF_RadioHead
#include "RadioHead/RH_NRF24.h"
#include "RadioHead/RHDatagram.h"
@ -67,17 +68,18 @@ RHDatagram Datagram(nrf24, THIS_ADRESS);
#endif
#ifdef RF_RF24
RF24 radio(PIN_NRF24_CSN,PIN_NRF24_CE); // Set up nRF24L01 radio on SPI bus plus pins 7 & 8
RF24 radio(PIN_NRF24_CE, PIN_NRF24_CSN); // Set up nRF24L01 radio on SPI bus plus pins 7 & 8
const uint64_t pipes[2] = { 0xABCDABCD71LL, 0x544d52687CLL }; // Radio pipe addresses for the 2 nodes to communicate.
byte data[32]; //Data buffer for testing data transfer speeds
unsigned long sendFailedCounter=0, rxTimer; //Counter and timer for keeping track transfer info
unsigned long receivedCounter=0;
unsigned long startTime, stopTime;
unsigned long startTime, stopTime, pauseTime;
bool TX=1,RX=0,role=0;
#endif
//static SPIImpl SPI;
static void setSmallTextSize(void) { display->setFont(&TomThumb); }
@ -91,6 +93,8 @@ static uint8_t getNormalTextHeight() { return Org_01.yAdvance; }
static void setLargeTextSize(void) { display->setFont(&FreeMonoBold9pt7b); }
//static uint8_t getLargeTextHeight() { return FreeMonoBold9pt7b.yAdvance; }
//static uint8_t getLargeTextCharsPerLine() { return 12; }
// Forward declarations:
static void updateDisplay_cb(void *arg);
static void fastclockRF_receive_cb(void *arg);
static void fastclockRF_send_cb(void *arg);
@ -140,19 +144,25 @@ static void initDisplay_cb(void *arg) {
break;
}
++step;
if (step <= 3) mgos_set_timer(600 /* ms */, false /* repeat */, initDisplay_cb, NULL);
if (step <= 3) mgos_set_timer(400 /* ms */, false /* repeat */, initDisplay_cb, NULL);
}
void setup(void) {
LOG(LL_INFO, ("*** Setup started"));
#ifdef RF_RadioHead
if (!Datagram.init())
LOG(LL_ERROR, ("*** Datagram init failed"));
#if 0
struct mgos_spi *spi;
spi = mgos_spi_get_global();
if (spi == NULL) {
LOG(LL_ERROR, ("SPI is not configured, make sure spi.enable is true"));
return;
}
#endif
LOG(LL_INFO, ("*** Setting timer"));
mgos_set_timer(2000 /* ms */, false /* repeat */, initDisplay_cb, NULL);
mgos_set_timer(7000 /* ms */, false /* repeat */, initFastclockRF_cb, NULL);
mgos_set_timer(1000 /* ms */, false /* repeat */, initDisplay_cb, NULL);
mgos_set_timer(5000 /* ms */, false /* repeat */, initFastclockRF_cb, NULL);
LOG(LL_INFO, ("*** Setup done"));
}
@ -267,6 +277,7 @@ static void switchToReceiverRole()
static void fastclockRF_receive_cb(void *arg) {
(void) arg;
LOG(LL_INFO, ("*** Rcv RF"));
#ifdef RF_RadioHead
// check for incoming messages
if (Datagram.available())
@ -287,20 +298,22 @@ static void fastclockRF_receive_cb(void *arg) {
#endif
#ifdef RF_RF24
uint8_t buf[RH_MAX_MESSAGE_LEN];
#define RF24_MAX_MESSAGE_LEN 32
uint8_t buf[RF24_MAX_MESSAGE_LEN];
uint8_t len = sizeof(buf);
unsigned int counger=0;
unsigned int counter=0;
switchToReceiverRole();
while (radio.available()) {
if (radio.available()) {
radio.read(buf, len);
counter++;
LOG(LL_INFO, ("%04d: %02x %02x %02x %02x %02x %02x", counter, buf[0], buf[1], buf[2], buf[3], buf[4], buf[5]));
}
if (millis() - rxTimer > 1000) {
rxTimer = millis();
receivedCounter += counter;
unsigned long numBytes = counter*len;
LOG(LL_INFO, ("Bytes: %d, Msg count: %d", numBytes, counter));
LOG(LL_INFO, ("Bytes: %ld, Msg count: %d", numBytes, counter));
counter = 0;
}
#endif
@ -327,8 +340,8 @@ static void fastclockRF_send_cb(void *arg) {
#ifdef RF_RF24
switchToSenderRole();
if (!radio.writeFast(&clockMsg,sizeof(clockMsg))) { //Write to the FIFO buffers
sendFailedCounter++; //Keep count of failed payloads
if (!radio.write(&clockMsg, sizeof(clockMsg), true /*multicast*/)) {
sendFailedCounter++;
}
//This is only required when NO ACK ( enableAutoAck(0) ) payloads are used
@ -342,6 +355,7 @@ static void fastclockRF_send_cb(void *arg) {
if (!radio.txStandBy()) { sendFailedCounter += 3; } //Standby, block only until FIFO empty or auto-retry timeout. Flush TX FIFO if failed
//radio.txStandBy(1000); //Standby, using extended timeout period of 1 second
#endif
LOG(LL_INFO, ("*** send finished"));
}
static void timeTick_cb(void *arg) {
@ -352,23 +366,32 @@ static void timeTick_cb(void *arg) {
incrementClockByMilliseconds(fastclockTimeAdvance);
//lastSentTimeTick += fastclockTimeAdvance * msPerModelSecond/1000;
lastSentTimeTick = newTimeTick;
LOG(LL_INFO, ("*** tick (adv=%d)", fastclockTimeAdvance));
}
static void initFastclockRF_cb(void *arg) {
(void) arg;
LOG(LL_INFO, ("*** Setting up RF"));
lastSentTimeTick = millis();
LOG(LL_INFO, ("*** Setting up RF, init lastSentTimeTick=%ld", lastSentTimeTick));
fastclock.day = 0;
fastclock.hour = 0;
fastclock.minute = 0;
fastclock.second = 0;
fastclock.millisecond = 0;
#ifdef RF_RadioHead
if (!Datagram.init()) {
LOG(LL_ERROR, ("*** Datagram init failed"));
}
#endif
#ifdef RF_RF24
radio.begin();
if (radio.isChipConnected()) { LOG(LL_INFO, ("*** RF chip found")); }
else { LOG(LL_ERROR, ("*** ERROR: RF chip not found!")); }
radio.setChannel(1);
radio.setPALevel(RF24_PA_MAX);
radio.setDataRate(RF24_1MBPS);
radio.setDataRate(RF24_2MBPS);
radio.setAutoAck(0);
//radio.setRetries(2,15); // Optionally, increase the delay between retries & # of retries
radio.setCRCLength(RF24_CRC_8);
@ -376,14 +399,21 @@ static void initFastclockRF_cb(void *arg) {
radio.openReadingPipe(1,pipes[1]);
radio.startListening();
radio.printDetails();
randomSeed(analogRead(0));
// @TODO: real random seed!
//randomSeed(analogRead(0));
//randomSeed(22);
radio.powerUp();
LOG(LL_INFO, ("*** RF payload size=%d bytes", radio.getPayloadSize()));
if (radio.testCarrier() || radio.testRPD()) { LOG(LL_INFO, ("*** Carrier/RPD seen on radio")); }
if (radio.failureDetected) { LOG(LL_ERROR, ("*** Radio error detected!")); }
#endif
LOG(LL_INFO, ("*** Setting up timer tasks"));
mgos_set_timer(100 /* ms */, true /* repeat */, fastclockRF_receive_cb, NULL);
mgos_set_timer(500 /* ms */, true /* repeat */, timeTick_cb, NULL);
mgos_set_timer(3000 /* ms */, true /* repeat */, fastclockRF_send_cb, NULL);
mgos_set_timer(1000 /* ms */, true /* repeat */, updateDisplay_cb, NULL);
LOG(LL_INFO, ("*** Setting up RF done"));
}
static void updateDisplay_cb(void *arg) {