NMEA2000 Library
0.1
Library to handle NMEA 2000 Communication written in C++
|
The file contains function and classes for best timing performance. More...
Go to the source code of this file.
Classes | |
class | tN2kScheduler |
Un synchronized Scheduler which can roll over. More... | |
class | tN2kSyncScheduler |
Synchronized Scheduler for timed message sending. More... | |
Macros | |
#define | N2kScheduler64Disabled 0xffffffffffffffffULL |
#define | N2kSchedulerDisabled 0xffffffffUL |
Defined Value for disabling the scheduler. More... | |
Typedefs | |
using | tN2kSchedulerTime = uint32_t |
Functions | |
bool | N2kHasElapsed (uint32_t Start, uint32_t Elapsed, uint32_t Now=N2kMillis()) |
Has time elapsed since start. More... | |
bool | N2kIsTimeBefore (uint32_t T1, uint32_t T2) |
Comparing 2 values even after 32 bit time roll over situation. More... | |
uint32_t | N2kMillis () |
uint64_t | N2kMillis64 () |
The file contains function and classes for best timing performance.
Module is designed to hide millis() function from library and provide best performance way for timings.
N2kMillis64() is 64 bit millisecond timer, which practically never roll over.
tN2kSyncScheduler uses 64 bit timer for message scheduling. It has offset as defined by NMEA2000. It uses global offset for synchronizing messages to open. Use this for scheduling message sending.
For proper synchronization you define tN2kSyncScheduler for each of your messages as disabled (default constructor) at beginning. On library setup define OnOpen call back with tNMEA2000::SetOnOpen. When OnOpen will be called, it initializes each message scheduler with period and offset. As default offsets it is good to use different value for each message so that your system will not try to send them exactly at same time. For single frame message 5-10 ms offset difference is enough. For message after multiframe message offset should be (multiframe message frame count)/2+(5 to 10). NMEA encourages manufacturers to provide the capability of altering, save and restore period and offset for NMEA certified products on the network. See tN2kGroupFunctionHandlerForPGN126993::HandleRequest in module N2kGroupFunctionDefaultHandlers
tN2kScheduler uses fastest method for scheduling next event. Tested for Teensy and ESP32.
Both schedulers solves roll over problem, which was caused with simple use of millis()
Definition in file N2kTimer.h.
#define N2kScheduler64Disabled 0xffffffffffffffffULL |
Definition at line 83 of file N2kTimer.h.
#define N2kSchedulerDisabled 0xffffffffUL |
Defined Value for disabling the scheduler.
Definition at line 271 of file N2kTimer.h.
using tN2kSchedulerTime = uint32_t |
Definition at line 272 of file N2kTimer.h.
|
inline |
Has time elapsed since start.
N2kHasElapsed tests has time elapsed since start. Test works even after 32 bit time roll over situation.
Start | Start time |
Elapsed | How much should be elapsed from start |
Now | Compare (current) time, optional, default N2kMillis() |
Definition at line 111 of file N2kTimer.h.
|
inline |
Comparing 2 values even after 32 bit time roll over situation.
N2kIsTimeBefore is for comparing T1 and T2 even after 32 bit time roll over situation.
T1 | Time value 1 |
T2 | Time value 2 |
Definition at line 96 of file N2kTimer.h.
uint32_t N2kMillis | ( | ) |
Definition at line 48 of file N2kTimer.cpp.
uint64_t N2kMillis64 | ( | ) |
Definition at line 51 of file N2kTimer.cpp.