diff --git a/README.md b/README.md index 7d697eb..949f3e6 100644 --- a/README.md +++ b/README.md @@ -12,20 +12,22 @@ Variables and functions are accessed via indexes which need to be known to their The muCom protocol does not define master or slave ECUs. Both act as equal partners and define their capabilities but the variables and functions they link to the muCom interface. -##### Benchmark results ##### +##### Benchmark results from v2.0 ##### | Function | Execution time in us | | --- | --- | -| writeByte() | 35 | -| writeShort() | 55 | -| writeLong() | 92 | -| writeLongLong() | 156 | -| writeFloat() | 93 | -| readByte() | 255 | -| readShort() | 340 | -| readLong() | 458 | -| readLongLong() | 701 | -| readFloat() | 456 | -| invokeFunction() | 40 | +| writeByte() | 42 | +| writeShort() | 62 | +| writeLong() | 99 | +| writeLongLong() | 164 | +| writeFloat() | 100 | +| writeDouble() | 100 | +| readByte() | 307 | +| readShort() | 411 | +| readLong() | 527 | +| readLongLong() | 767 | +| readFloat() | 527 | +| readDouble() | 527 | +| invokeFunction() | 42 | Executed on an Atmega328p with a 250000kBaud serial interface in loopback mode. @@ -33,3 +35,5 @@ Executed on an Atmega328p with a 250000kBaud serial interface in loopback mode. ##### Frame structure ##### See muComBase.cpp for details regarding the binary structure of muCom frames. +Each muCom frame is tuned for maximum transmission speed and efficiency resulting in a binary efficiency of 87.5% when comparing the useful transmitted data (frame type, payload byte count and target variable ID are considered useful) to the overall frame length. +The muCom protocol has no need for wait times for frame synchronization, allowing the serial interface to run at 100% load when streaming data as fast as possible. diff --git a/examples/Benchmark/Benchmark.ino b/examples/Benchmark/Benchmark.ino index 661a373..807f742 100644 --- a/examples/Benchmark/Benchmark.ino +++ b/examples/Benchmark/Benchmark.ino @@ -1,14 +1,15 @@ #include "muCom.h" -muCom Device(Serial, 6, 1); +MUCOM_CREATE(Device, Serial, 6, 1); -long timestamps[12] = {0}; //Timestamps for benchmark +long timestamps[14] = {0}; //Timestamps for benchmark uint8_t u8Dummy = 0; uint16_t u16Dummy = 0; uint32_t u32Dummy = 0; uint64_t u64Dummy = 0; float f32Dummy = 0.0; +double f64Dummy = 0.0; void DoNothing(uint8_t *data, uint8_t cnt) @@ -35,6 +36,7 @@ void setup() Device.linkVariable(2, &u32Dummy); Device.linkVariable(3, &u64Dummy); Device.linkVariable(4, &f32Dummy); + Device.linkVariable(5, &f64Dummy); //Link function Device.linkFunction(0, DoNothing); @@ -73,32 +75,42 @@ void setup() delay(5); Device.handle(); + tmpTime = micros(); + Device.writeDouble(5, -666.66); + timestamps[5] += (int)micros() - tmpTime; + delay(5); + Device.handle(); + // ------- Benchmark reading variables ------- tmpTime = micros(); u8Dummy = Device.readByte(0); - timestamps[5] += (int)micros() - tmpTime; + timestamps[6] += (int)micros() - tmpTime; tmpTime = micros(); u16Dummy = Device.readShort(1); - timestamps[6] += (int)micros() - tmpTime; + timestamps[7] += (int)micros() - tmpTime; tmpTime = micros(); u32Dummy = Device.readLong(2); - timestamps[7] += (int)micros() - tmpTime; + timestamps[8] += (int)micros() - tmpTime; tmpTime = micros(); u64Dummy = Device.readLongLong(3); - timestamps[8] += (int)micros() - tmpTime; + timestamps[9] += (int)micros() - tmpTime; tmpTime = micros(); f32Dummy = Device.readFloat(4); - timestamps[9] += (int)micros() - tmpTime; + timestamps[10] += (int)micros() - tmpTime; + + tmpTime = micros(); + f32Dummy = Device.readDouble(5); + timestamps[11] += (int)micros() - tmpTime; // ------- Benchmark invoking functions ------- tmpTime = micros(); Device.invokeFunction(0); - timestamps[10] += (int)micros() - tmpTime; + timestamps[12] += (int)micros() - tmpTime; delay(5); Device.handle(); } @@ -106,10 +118,10 @@ void setup() //Calculate average benchmark result tmpTime = micros(); __asm__("nop\n\t"); //Ensure that micros is actually stored in tmpTime - timestamps[11] = (int)micros() - tmpTime; - for(i = 0; i < 11; i++) + timestamps[13] = (int)micros() - tmpTime; + for(i = 0; i < 14; i++) { - timestamps[i] = (timestamps[i] / 100) - timestamps[11]; + timestamps[i] = (timestamps[i] / 100) - timestamps[13]; } digitalWrite(LED_BUILTIN, HIGH); @@ -124,13 +136,15 @@ void loop() Serial.print("writeLong(): "); Serial.println(timestamps[2]); Serial.print("writeLongLong(): "); Serial.println(timestamps[3]); Serial.print("writeFloat(): "); Serial.println(timestamps[4]); - Serial.print("readByte(): "); Serial.println(timestamps[5]); - Serial.print("readShort(): "); Serial.println(timestamps[6]); - Serial.print("readLong(): "); Serial.println(timestamps[7]); - Serial.print("readLongLong(): "); Serial.println(timestamps[8]); - Serial.print("readFloat(): "); Serial.println(timestamps[9]); - Serial.print("invokeFunction(): "); Serial.println(timestamps[10]); + Serial.print("writeDouble(): "); Serial.println(timestamps[5]); + Serial.print("readByte(): "); Serial.println(timestamps[6]); + Serial.print("readShort(): "); Serial.println(timestamps[7]); + Serial.print("readLong(): "); Serial.println(timestamps[8]); + Serial.print("readLongLong(): "); Serial.println(timestamps[9]); + Serial.print("readFloat(): "); Serial.println(timestamps[10]); + Serial.print("readDouble(): "); Serial.println(timestamps[11]); + Serial.print("invokeFunction(): "); Serial.println(timestamps[12]); Serial.println(); delay(5000); -} \ No newline at end of file +} diff --git a/examples/Example_1/Example_1.ino b/examples/Example_1/Example_1.ino index 239f090..c01b5b0 100644 --- a/examples/Example_1/Example_1.ino +++ b/examples/Example_1/Example_1.ino @@ -6,7 +6,7 @@ void setLED(uint8_t *data, uint8_t cnt); //Create muCom interface -muCom Device(Serial, 2, 1); +MUCOM_CREATE(Device, Serial, 2, 1); //Global variables diff --git a/extras/Doxyfile b/extras/Doxyfile index 5b4f790..b7b3ae2 100644 --- a/extras/Doxyfile +++ b/extras/Doxyfile @@ -38,7 +38,7 @@ PROJECT_NAME = muCom # could be handy for archiving the generated documentation or if some version # control system is used. -PROJECT_NUMBER = 1.1 +PROJECT_NUMBER = 2.0 # Using the PROJECT_BRIEF tag one can provide an optional one line description # for a project that appears at the top of each page and should give viewer a diff --git a/extras/html/annotated.html b/extras/html/annotated.html index f679984..d39857a 100644 --- a/extras/html/annotated.html +++ b/extras/html/annotated.html @@ -19,7 +19,7 @@
CmuCom | File containing the main class for the muCom interface when being used for an Arduino |
CmuCom | Main class for the muCom interface when being used for an Arduino |
CmuCom_LinkedVariable_str | Internal structure to store references to linked variables |
CmuComBase | Base muCom class |
CmuComBase | Base muCom class |
File containing the main class for the muCom interface when being used for an Arduino. +
Main class for the muCom interface when being used for an Arduino. More...
#include <muCom.h>
Public Member Functions | |
- | muCom (Stream &ser, uint8_t num_var, uint8_t num_func) |
+ | muCom (UARTClass &ser, struct muCom_LinkedVariable_str *var_buf, uint8_t num_var, muComFunc *func_buf, uint8_t num_func) |
![]() | |
muComBase (uint8_t num_var, uint8_t num_func) | |
Constructor of the base class. More... | |
- | ~muComBase (void) |
Destructor of the base class. | |
muComBase (struct muCom_LinkedVariable_str *var_buf, uint8_t num_var, muComFunc *func_buf, uint8_t num_func) | |
Constructor of the base class. More... | |
uint32_t | getLastCommTime (void) |
Get timestamp of last successful communication. More... | |
Set timeout for read requests. More... | |
uint8_t | handle (void) |
Handle the muCom interface. More... | |
Handle the muCom interface. More... | |
int8_t | linkFunction (uint8_t index, muComFunc function) |
Link function to the muCom interface. More... | |
Link function to the muCom interface. More... | |
int8_t | linkVariable (uint8_t index, uint8_t *var, uint8_t size) |
Link a variable or a buffer to the muCom interface. More... | |
Link a variable or a buffer to the muCom interface. More... | |
-void | linkVariable (uint8_t index, uint8_t *var) |
-void | linkVariable (uint8_t index, int8_t *var) |
-void | linkVariable (uint8_t index, uint16_t *var) |
-void | linkVariable (uint8_t index, int16_t *var) |
-void | linkVariable (uint8_t index, uint32_t *var) |
-void | linkVariable (uint8_t index, int32_t *var) |
-void | linkVariable (uint8_t index, uint64_t *var) |
-void | linkVariable (uint8_t index, int64_t *var) |
-void | linkVariable (uint8_t index, float *var) |
+int8_t | linkVariable (uint8_t index, uint8_t *var) |
+int8_t | linkVariable (uint8_t index, int8_t *var) |
+int8_t | linkVariable (uint8_t index, uint16_t *var) |
+int8_t | linkVariable (uint8_t index, int16_t *var) |
+int8_t | linkVariable (uint8_t index, uint32_t *var) |
+int8_t | linkVariable (uint8_t index, int32_t *var) |
+int8_t | linkVariable (uint8_t index, uint64_t *var) |
+int8_t | linkVariable (uint8_t index, int64_t *var) |
+int8_t | linkVariable (uint8_t index, float *var) |
+int8_t | linkVariable (uint8_t index, double *var) |
void | invokeFunction (uint8_t index, uint8_t *data, uint8_t cnt) |
Invoke a function at the communication partner. More... | |
void | writeFloat (uint8_t index, float data) |
Write a float to the communication partner. More... | |
void | writeDouble (uint8_t index, double data) |
Write a double to the communication partner (not available on AVR microcontrollers) More... | |
int8_t | read (uint8_t index, uint8_t *data, uint8_t cnt) |
Read data from the communication partner. More... | |
int8_t | readFloat (uint8_t index, float *data) |
Read a float from the communication partner. More... | |
int8_t | readDouble (uint8_t index, double *data) |
Read a double from the communication partner (not available on AVR microcontrollers) More... | |
uint8_t | readByte (uint8_t index) |
Read a byte from the communication partner. More... | |
float | readFloat (uint8_t index) |
Read a float from the communication partner. More... | |
double | readDouble (uint8_t index) |
Read a float from the communication partner. More... | |
File containing the main class for the muCom interface when being used for an Arduino.
-Main class for the muCom interface when being used for an Arduino
-This class inherits all functions from the muCom base class (see muComBase) and additionally implements the interface for the HW access when using the muCom interface on an Arduino. It uses the Stream class for communication which can be implemented by the hardware and software UARTS, as well as USB serial emulations.
-Main class for the muCom interface when being used for an Arduino.
+This class inherits all functions from the muCom base class (see muComBase) and additionally implements the interface for the HW access when using the muCom interface on an Arduino. It uses the Stream class for communication which can be implemented by the hardware and software UARTS, as well as USB serial emulations.
+Public Member Functions | |
muComBase (uint8_t num_var, uint8_t num_func) | |
Constructor of the base class. More... | |
- | ~muComBase (void) |
Destructor of the base class. | |
muComBase (struct muCom_LinkedVariable_str *var_buf, uint8_t num_var, muComFunc *func_buf, uint8_t num_func) | |
Constructor of the base class. More... | |
uint32_t | getLastCommTime (void) |
Get timestamp of last successful communication. More... | |
Set timeout for read requests. More... | |
uint8_t | handle (void) |
Handle the muCom interface. More... | |
Handle the muCom interface. More... | |
int8_t | linkFunction (uint8_t index, muComFunc function) |
Link function to the muCom interface. More... | |
Link function to the muCom interface. More... | |
int8_t | linkVariable (uint8_t index, uint8_t *var, uint8_t size) |
Link a variable or a buffer to the muCom interface. More... | |
Link a variable or a buffer to the muCom interface. More... | |
-void | linkVariable (uint8_t index, uint8_t *var) |
-void | linkVariable (uint8_t index, int8_t *var) |
-void | linkVariable (uint8_t index, uint16_t *var) |
-void | linkVariable (uint8_t index, int16_t *var) |
-void | linkVariable (uint8_t index, uint32_t *var) |
-void | linkVariable (uint8_t index, int32_t *var) |
-void | linkVariable (uint8_t index, uint64_t *var) |
-void | linkVariable (uint8_t index, int64_t *var) |
-void | linkVariable (uint8_t index, float *var) |
+int8_t | linkVariable (uint8_t index, uint8_t *var) |
+int8_t | linkVariable (uint8_t index, int8_t *var) |
+int8_t | linkVariable (uint8_t index, uint16_t *var) |
+int8_t | linkVariable (uint8_t index, int16_t *var) |
+int8_t | linkVariable (uint8_t index, uint32_t *var) |
+int8_t | linkVariable (uint8_t index, int32_t *var) |
+int8_t | linkVariable (uint8_t index, uint64_t *var) |
+int8_t | linkVariable (uint8_t index, int64_t *var) |
+int8_t | linkVariable (uint8_t index, float *var) |
+int8_t | linkVariable (uint8_t index, double *var) |
void | invokeFunction (uint8_t index, uint8_t *data, uint8_t cnt) |
Invoke a function at the communication partner. More... | |
void | writeFloat (uint8_t index, float data) |
Write a float to the communication partner. More... | |
void | writeDouble (uint8_t index, double data) |
Write a double to the communication partner (not available on AVR microcontrollers) More... | |
int8_t | read (uint8_t index, uint8_t *data, uint8_t cnt) |
Read data from the communication partner. More... | |
int8_t | readFloat (uint8_t index, float *data) |
Read a float from the communication partner. More... | |
int8_t | readDouble (uint8_t index, double *data) |
Read a double from the communication partner (not available on AVR microcontrollers) More... | |
uint8_t | readByte (uint8_t index) |
Read a byte from the communication partner. More... | |
float | readFloat (uint8_t index) |
Read a float from the communication partner. More... | |
double | readDouble (uint8_t index) |
Read a float from the communication partner. More... | |
Base muCom class.
-This class implements the muCom protocol itself and relies on being inherited in order to implement the actual serial interface.
+Base muCom class.
+This class implements the muCom protocol itself and relies on being inherited in order to implement the actual serial interface.
[in] | var_buf | Fixed buffer for linked variables |
[in] | num_var | Max. number of variables to be linked |
[in] | func_buf | Fixed buffer for linked functions |
[in] | num_func | Max. number of functions to be linked |
Handle the muCom interface.
-This function handles the muCom interface and decodes the received data. It should be executed as often as possible and will handle writing to and reading from linked variables as well as executing requested functions. This function is also used during reading data from the communication partner.
Handle the muCom interface.
+This function handles the muCom interface and decodes the received data. It should be executed as often as possible and will handle writing to and reading from linked variables as well as executing requested functions. This function is also used during reading data from the communication partner.
Link function to the muCom interface.
+Link function to the muCom interface.