Skip to content
Snippets Groups Projects
Commit df091bf8 authored by Lennard Karger's avatar Lennard Karger
Browse files

Merge branch 'Developement_Karger' into 'Merge_Test_123'

Test Merge

See merge request !1
parents b05103fa be45b1b1
No related branches found
No related tags found
1 merge request!1Test Merge
Showing
with 140 additions and 392 deletions
*.ini
sketches/_PIO_Sketches/Karger/BLE_Slae_Test/platformio.ini
.gitignore
...@@ -205,6 +205,10 @@ void BlePoll::setPollAddress(int chnIn, int adrIn, int areaIn, bool masterIn, bo ...@@ -205,6 +205,10 @@ void BlePoll::setPollAddress(int chnIn, int adrIn, int areaIn, bool masterIn, bo
nak = nakIn; nak = nakIn;
} }
bcPduPtr BlePoll::getPduAdress(){
return &pduOut;
}
void BlePoll::setPduAddress() void BlePoll::setPduAddress()
{ {
setPduAddress(&pduOut); setPduAddress(&pduOut);
......
...@@ -355,6 +355,7 @@ private: ...@@ -355,6 +355,7 @@ private:
bool getValues(bcPduPtr pduPtr, PlpType appId); bool getValues(bcPduPtr pduPtr, PlpType appId);
bool getCtrls(bcPduPtr pduPtr, PlpType appId); bool getCtrls(bcPduPtr pduPtr, PlpType appId);
// Zustandsmaschine // Zustandsmaschine
// ----------------------------- // -----------------------------
void smInit(); void smInit();
......
{
"name": "BlePoll",
"version": "0.0.0+20220804174235"
}
\ No newline at end of file
{
"name": "BlePoll",
"version": "0.0.0+20220804174235"
}
\ No newline at end of file
// Demo-Program for using library LoopCheck with Arduino
#include "Arduino.h"
#include "LoopCheck.h"
#define TestLed 13
// The built in LED of some Arduino boards (and similar development boards like
// ESP32 Dev) seem to be connected to a pin (most 13), which is also used for the
// serial transmit (TxD) or other purposes.
// The blink example of Arduino works, because they switch the pin and then
// they freeze the program bei function <delay(milliseconds)>.
// But if you leave loop() for Arduino internal functions, the pin is
// no more valid, it is used for TxD (or some other purpose).
// In other words, with some (many?) boards, the blink example of Arduino does
// not work without the delay in loop-function.
// Because we now use a software-timer instead of a delay,
// we must use another pin to connect our own LED or look for a built-in LED
// which is not used outside loop-function.
// E.g. the blue LED of ESP32 DEVKIT V1 (doit) is connected at pin 2.
LoopCheck loopCheck;
// Creating an instance of class LoopCheck
// Some compilers take a huge basic load of program space, if you use the
// new operator. That is the reason, why we use a static instantiation.
//The setup function is called once at startup of the sketch
//
void setup()
{
pinMode(TestLed, OUTPUT);
// Setting a free pin for output (connect a LED via serial resistor)
}
// The loop function is called in an endless loop
//
void loop()
{
loopCheck.begin();
// This method has to be called, whenever entering the cyclic used function
if(loopCheck.timerMilli(0, 500, 0))
{
// This is a timer of LoopCheck:
// The first argument is an index (0 - NrOfTimerTasks) which is identifying
// a timer. timerMicro and timerMilli use the same function in LooopCheck.cpp
// and so You have only NrOfLoopTasks timers, either timerMilli or timerMicro.
// The second argument is the cycle time (in milliseconds with timerMilli
// and in microseconds with timerMicro.
// The third argument is the number of cycles. The value 0 stands for an
// endless running of the timer.
if(loopCheck.toggle(0))
{
// This is a toggle of LoopCheck:
// This function returns alternating true and false. The argument is an
// index (0 - NrOfToggleTasks) to identify the toggle. There is no relation
// between the indexes of timers and toggles.
digitalWrite(TestLed, HIGH);
// Switching on the LED at pin TestLed
}
else
{
digitalWrite(TestLed, LOW);
// Switching off the LED
}
}
loopCheck.end();
// This method has to be called, whenever leaving the cyclic used function
}
// With using LoopCheck, the blinking of a LED does not freeze the loop function.
// Depending on the speed of your CPU, this programm takes mikroseconds or only
// fractions of microsecond in one loop and the LED is switched on and off every second.
// You can use up to NrOfTimerTask timers (defined in LoopCheck.h) inside loop
// without creating a big load for the CPU.
// The timers do not fire in the same cycle. If You use many timers, they do
// not meet in the same cycle of the loop. So it will not happen, that your
// application creates a long duration of loop if all timers meet the same
// ending time.
// Using LoopCheck-Library for information about the loop
//
#include "Arduino.h"
#include "LoopCheck.h"
LoopCheck loopCheck;
// Creating an instance of class LoopCheck
// Some compilers take a huge basic load of program space, if you use the
// new operator. That is the reason, why we use a static instantiation.
//The setup function is called once at startup of the sketch
//
void setup()
{
Serial.begin(115200);
// Prepare serial interface to print information
Serial.println("Example for using loop statistics");
}
OpHourMeter cpuRunTime;
// This structure will hold the runtime of the CPU since reset
// organised in years,days,hours,minutes,seconds and milliseconds
// after calling <operationTime>
LoopStatistics statistics;
// This structure will hold statistical information about the loop
// after calling <getStatistics>
bool useDelay;
// A marker to show the influence of delay function on LoopCheck operation time
#ifndef smnESP32
char sprintMem[64];
// with ESP32 there is the function Serial.printf defined, but not with DUE
// so we need some memory for preperation of text for using print with DUE
#endif
// The loop function is called in an endless loop
//
void loop()
{
loopCheck.begin();
// This method has to be called, whenever entering the cyclic used function
if(loopCheck.once(0,1))
{
// 1. arg is task index (0-7), 2. arg is loop number
// I.e. : do only once with the first loop
useDelay = true;
// Of course this could be better done in the setup-function (above),
// but it is a chance to show the once-function of LoopCheck.
// Mind the 2. argument, you can do setups subsequently because
// once-function is skipping the entered number of loops
}
if(loopCheck.timerMilli(0, 1000, 25))
{
// The timer-function returns true whenever 1000 milliseconds passed
// but only 25 times
// The example <lcBlink.ino> for more details
loopCheck.operationTime(&cpuRunTime);
#ifdef smnESP32
Serial.printf("%02dH,%02dm,%02ds\r\n",
cpuRunTime.Hours,cpuRunTime.Minutes,cpuRunTime.Seconds);
#else
sprintf(sprintMem, "%02dH,%02dm,%02ds\r\n",
cpuRunTime.Hours,cpuRunTime.Minutes,cpuRunTime.Seconds);
Serial.print(sprintMem);
#endif
}
if(useDelay == true) delay(33);
// To have something to measure for the statistical information
// But see the influence on the operation time at the end of the code
if(loopCheck.timerMilli(1, 2000, 10))
{
// Do the following every 2 seconds but only 10 times
loopCheck.getStatistics(&statistics);
#ifdef smnESP32
Serial.printf("AvgInLoopTime: %05d[us], AvgOutLoopTime: %05d[us]\r\n",
statistics.loopAvgTime,statistics.bgAvgTime);
#else
sprintf(sprintMem, "AvgInLoopTime: %05d[us], AvgOutLoopTime: %05d[us]\r\n",
statistics.loopAvgTime,statistics.bgAvgTime);
Serial.print(sprintMem);
#endif
#ifdef smnESP32
Serial.printf("LoopPeriodAlarm: %d, AlarmCounter: %d\r\n",
statistics.periodAlarm,statistics.alarmCount);
#else
sprintf(sprintMem,"LoopPeriodAlarm: %d, AlarmCounter: %d\r\n",
statistics.periodAlarm,statistics.alarmCount);
Serial.print(sprintMem);
#endif
}
if(loopCheck.timerMilli(2, 10000, 1))
{
// switch off the delay after 10 seconds
useDelay = false;
}
loopCheck.end();
// This method has to be called, whenever leaving the cyclic used function
}
// This example looks rather complex for simply showing the elapsed operation time.
// But it had to be shown, that the operation time counter only works
// if the loop cycle time (time between two following loops) is less than
// 1 millisecond.
// This is not a mistake. LoopCheck was built to watch and control the behaviour
// of the Arduino loop and it shall be handled as a mistake, if you write a
// program that holds the CPU such a long time.
// Check the statistics to observe also the influence of resources running in background.
//============================================================================
// Name : testCppArduino.cpp
// Author : Robert Patzke
// Version :
// Copyright : (c) MFP 2017
// Description : Hello World in C++, Ansi-style
//============================================================================
#include <stdlib.h>
#include <stdio.h>
#include <time.h>
#include "LoopCheck.h"
// environment.h will be included in LoopCheck.h
// You have to #define smnSimLinux there for IDE
// and comment out other definitions
LoopCheck loopCheck;
int main()
{
printf("Test Arduino Software Environment\n");
printf("Endless loop, terminate with Ctrl-C\n");
while(1)
{
loopCheck.begin();
if(loopCheck.timerMilli(0, 1000, 0))
{
printf(".\n");
}
loopCheck.end();
}
return 0;
}
//-----------------------------------------------------------------------------
// Thema: Social Manufacturing Network / Software Loop Checking and Timing
// Datei: testLoopCheck.cpp
// Editor: Robert Patzke
// URI/URL: www.mfp-portal.de
//-----------------------------------------------------------------------------
// Lizenz: CC-BY-SA (see Wikipedia: Creative Commons)
//
// This program was developed and tested with Visual Studio 2010
// Following configuration has to be done in C/C++ -> Preprocessor Definitions
//
// UseGithubPath
// Visual Studio searches for includes in the environment of the sources.
// With the switch UseGithubPath the #include directives in source files are
// relativ to the structure of the tree as it is used on Github repository.
// So it will work after simple copying the tree from Github.
//
// smnDEFBYBUILD
// With this switch the first part of file environment.h will be used.
// It is possible to use environment.h for many purposes.
// Without defining smnDEFBYBUILD the file has to be edited to fit to your IDE
// and your microcontroller targets
//
// smnWIN32_VS
// This switch opens a list of definitions in environment.h controlling
// conditional compilation in many source files
#include <stdlib.h>
#include <stdio.h>
#include <time.h>
#include <sys/timeb.h>
#include "../LoopCheck.h"
LoopCheck loopCheck;
int main(int argc, char *argv[])
{
time_t timeSec;
struct tm *timeStructPtr;
struct timeb ftimeStruct;
lcDateTime dateTime;
int msecOldPC, msecOldLC, msecOldOP;
int secOldPC, secOldLC, secOldOP;
LoopStatistics statistic;
// -------------------------------------------------------------------------
// setup
// -------------------------------------------------------------------------
//
printf("Testing simulation of Arduino with Windows\n");
printf("Check loop behaviour with LoopCheck, demonstrate clocks\n");
// Getting PC time with milliseconds resolution
//
ftime(&ftimeStruct);
timeSec = ftimeStruct.time;
timeStructPtr = gmtime(&timeSec);
// Preparing some Variables to calculate and show time difference
//
msecOldPC = msecOldLC = dateTime.Millisecond = ftimeStruct.millitm;
secOldPC = secOldLC = dateTime.Second = timeStructPtr->tm_sec;
// Setting the software clock of LoopCheck to PC time
//
dateTime.Minute = timeStructPtr->tm_min;
dateTime.Hour = timeStructPtr->tm_hour;
dateTime.Day = timeStructPtr->tm_mday;
dateTime.Month = timeStructPtr->tm_mon + 1;
dateTime.Year = timeStructPtr->tm_year + 1900;
loopCheck.setDateTime(dateTime);
// -------------------------------------------------------------------------
// loop
// -------------------------------------------------------------------------
//
while(1)
{
loopCheck.begin(); // this function has to be called first in loop
// -----------------------------------------------------------------------
// Comparing the software clock with the PC clock and showing the difference
//
if(loopCheck.timerMilli(0,1000,0))
{
//
// This gets true once every second (1000 milliseconds)
// The error is that of the PC counter (clock or performance timer)
// Get the current PC time with milliseconds
//
ftime(&ftimeStruct);
timeSec = ftimeStruct.time;
timeStructPtr = gmtime(&timeSec);
// Get the current time of LoopCheck software clock
//
loopCheck.getDateTime(&dateTime);
// Show the PC time and the LoopCheck time and their differences to the last measurement
// a second back (do not mind the overflow error with the distance)
//
printf("PC Time = %02d:%02d:%02d,%03d Diff=%4d LC Time = %02d:%02d:%02d,%03d Diff=%4d\n",
timeStructPtr->tm_hour, timeStructPtr->tm_min, timeStructPtr->tm_sec, ftimeStruct.millitm,
ftimeStruct.millitm - msecOldPC + 1000*(timeStructPtr->tm_sec - secOldPC),
dateTime.Hour, dateTime.Minute, dateTime.Second, dateTime.Millisecond,
dateTime.Millisecond - msecOldLC + 1000*(dateTime.Second - secOldLC));
//
// You will see, that the timer of LoopCheck is rather accurate.
// The variation of repetition time is less than 1% with some exceptions.
// Also the LoopCheck software clock is nearly perfect, because the
// underlaying counters are synchronised to the OS clock
// preperation for the measurement of next cycle
//
msecOldPC = ftimeStruct.millitm;
msecOldLC = dateTime.Millisecond;
secOldPC = timeStructPtr->tm_sec;
secOldLC = dateTime.Second;
// to show the difference between microcontrollers and OS based computers
// we will look into the statistics of LoopCheck
//
loopCheck.getStatistics(&statistic);
// alarmCount is incremented, whenever the time between 2 loops exceeds PeriodMinTime
// (adjust PeriodMinTime in LoopCheck.h for your target system)
//
printf("Loop violations: %4d ", statistic.alarmCount);
//
// we have also a classification of exceeding the millisecond of loop cycle time
// counting the number of exceedings indexed by number of milliseconds.
//
for(int i = 0; i < LoopScreeningGrades - 1; i++)
printf(" %2dms: %4d", i+1 , statistic.rtSreening[i]);
printf(" >%2dms: %4d\r\n\n", LoopScreeningGrades - 1, statistic.rtSreening[LoopScreeningGrades - 1]);
}
// -----------------------------------------------------------------------
loopCheck.end(); // this function has to be called last in the loop
}
}
{
"name": "LoopCheck",
"version": "0.0.0+20220823165932"
}
\ No newline at end of file
{
"name": "MidiNotes",
"version": "0.0.0+20220823165932"
}
\ No newline at end of file
{
"name": "Monitor",
"version": "0.0.0+20220823165932"
}
\ No newline at end of file
{
"name": "SensorLSM9DS1",
"version": "0.0.0+20220823165932"
}
\ No newline at end of file
{
"name": "SoaapComDue",
"version": "0.0.0+20220804174235"
}
\ No newline at end of file
{
"name": "SoaapMsg",
"version": "0.0.0+20220823165932"
}
\ No newline at end of file
{
"name": "StateMachine",
"version": "0.0.0+20220823165932"
}
\ No newline at end of file
...@@ -131,7 +131,7 @@ public: ...@@ -131,7 +131,7 @@ public:
virtual bool disabled(TxMode txMode); // Abfrage, ob ausgeschaltet virtual bool disabled(TxMode txMode); // Abfrage, ob ausgeschaltet
virtual void cont(TxMode txMode); // aktuellen Vorgang fortsetzen virtual void cont(TxMode txMode); // aktuellen Vorgang fortsetzen
virtual bool fin(TxMode txMode, bool *err); // Abfrage ob aktueller Vorgang beendet virtual bool fin(TxMode txMode, bool *err); // Abfrage ob aktueller Vorgang beendet
virtual int getRecData(bcPduPtr data, TxMode txMode, int max); // virtual int getRecData(bcPduPtr data, TxMode txMode, int max); // Lennard: Deaktiviert
virtual int startRec(); // Datenempfang starten virtual int startRec(); // Datenempfang starten
virtual int contRec(); // Datenempfang fortsetzen virtual int contRec(); // Datenempfang fortsetzen
......
// ----------------------------------------------------------------------------
// SoaapBleMaster.h
// Beispielhafte Anwendung SOAAP / Steuerung optischer und akustischer Ausgaben
// Kommunikation über BLE-Funkanäle mit Bewerbungstelegrammen
// P o l l i n g - M a s t e r
// ----------------------------------------------------------------------------
// Editor: Robert Patzke
// URI/URL: www.mfp-portal.de
//-----------------------------------------------------------------------------
// Lizenz: CC-BY-SA (wikipedia: Creative Commons)
// Datum: 1. November 2021
// Letzte Bearbeitung: 15. März 2022
//
#ifndef SoaapBleMaster_h
#define SoaapBleMaster_h
// Vordefinitionen, Festlegungen zur Kompilierung
//
#define DebugTerminal
// Mit dieser Definition werden die Klasse Monitor und weitere Testmethoden
// eingebunden, womit ein anwendungsorientiertes Debugging möglich ist
//#define TEST001
// Ausgaben an serielle schnittstelle zur Prüfung der ap-Zustandsmaschine
#include "LoopCheck.h"
#include "StateMachine.h"
#include "nRF52840Radio.h"
#include "BlePoll.h"
#include "ComRingBuf.h"
#include "nRF52840Ser.h"
#include "SoaapMsg.h"
#include "Monitor.h"
// ----------------------------------------------------------------------------
// Vorwärtsreferenzen
// ----------------------------------------------------------------------------
//
void apInit();
void apWaitDE();
void apWaitMeas();
void apProcMeas();
#ifdef DebugTerminal
// ----------------------
void smInit() ;
void smCheckJobs() ;
void smDebDword() ;
void smCtrlPolling() ;
void smWaitPolling() ;
void smReadPollValues() ;
void smCheckSer();
// ----------------------
#endif
#endif /* SoaapBleMaster_h */
#ifndef SoaapBleSlave_h
#define SoaapBleSlave_h
#include "SoaapMsg.h"
//#define SlaveACM1
bool sendData(PlpType plpType, byte *dest);
bool getValues(PlpType plpType, byte *dest);
void smInit();
void smCheckJobs();
void smCheckSens();
void smDebDword();
void smCtrlPolling();
void smWaitPolling();
void smSensReset1();
void smSensReset2();
void smSensGetValues1();
void smSensGetValues2();
void smSensGetValues3();
void smSensGetValues4();
void smSensGetValues5();
void smSensGetValues6();
void smSensGetValues7();
void smSensGetSoaapValues();
void smSensDebugValues();
void smSensGetErrors();
void smSensGetTimeOuts();
void smSensGetRunCounts();
#endif
\ No newline at end of file
{
"name": "environment",
"version": "0.0.0+20220823165932"
}
\ No newline at end of file
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment