summaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
Diffstat (limited to 'src')
-rw-r--r--src/bitfield/bitfield.h8
-rw-r--r--src/canutil/read.h16
-rw-r--r--src/canutil/write.c12
-rw-r--r--src/canutil/write.h16
4 files changed, 42 insertions, 10 deletions
diff --git a/src/bitfield/bitfield.h b/src/bitfield/bitfield.h
index 27766733..7d9f3995 100644
--- a/src/bitfield/bitfield.h
+++ b/src/bitfield/bitfield.h
@@ -4,6 +4,10 @@
#include <stdint.h>
#include <stdbool.h>
+#ifdef __cplusplus
+extern "C" {
+#endif
+
/* Public: Reads a subset of bits from a byte array.
*
* data - the bytes in question.
@@ -55,4 +59,8 @@ void setBitField(uint64_t* data, uint64_t value, int startPos, int numBits);
*/
uint8_t nthByte(uint64_t source, int byteNum);
+#ifdef __cplusplus
+}
+#endif
+
#endif // __BITFIELD_H__
diff --git a/src/canutil/read.h b/src/canutil/read.h
index 815f26b0..6ac4eebe 100644
--- a/src/canutil/read.h
+++ b/src/canutil/read.h
@@ -4,10 +4,26 @@
#include <stdint.h>
#include <stdbool.h>
+#ifdef __cplusplus
+extern "C" {
+#endif
+
+/* Public: Parse a CAN signal from a message and apply required transformation.
+ *
+ * signal - The details of the signal to decode and forward.
+ * data - The raw bytes of the CAN message that contains the signal, assumed
+ * to be in big-endian byte order from CAN.
+ *
+ * Returns the final, transformed value of the signal.
+ */
float parseFloat(uint64_t data, uint8_t bitPosition, uint8_t bitSize,
float factor, float offset);
bool parseBoolean(uint64_t data, uint8_t bitPosition, uint8_t bitSize,
float factor, float offset);
+#ifdef __cplusplus
+}
+#endif
+
#endif // __READ_H__
diff --git a/src/canutil/write.c b/src/canutil/write.c
index fdcba1f5..741778c7 100644
--- a/src/canutil/write.c
+++ b/src/canutil/write.c
@@ -1,18 +1,18 @@
#include "write.h"
-uint64_t encodeFloat(float value, float offset, float factor, uint8_t bitPosition,
- uint8_t bitSize) {
+uint64_t encodeFloat(float value, uint8_t bitPosition, uint8_t bitSize,
+ float factor, float offset) {
float rawValue = (value - offset) / factor;
if(rawValue > 0) {
// round up to avoid losing precision when we cast to an int
rawValue += 0.5;
}
uint64_t result = 0;
- setBitField(&result, rawValue, bitPosition, bitSize);
+ setBitField(&result, (uint64_t)rawValue, bitPosition, bitSize);
return result;
}
-uint64_t encodeBoolean(bool value, float offset, float factor,
- uint8_t bitPosition, uint8_t bitSize) {
- return encodeFloat(value, offset, factor, bitPosition, bitSize);
+uint64_t encodeBoolean(bool value, uint8_t bitPosition, uint8_t bitSize,
+ float factor, float offset) {
+ return encodeFloat(value, offset, factor, bitPosition, bitSize);
}
diff --git a/src/canutil/write.h b/src/canutil/write.h
index 85a5c1a0..1b086dbe 100644
--- a/src/canutil/write.h
+++ b/src/canutil/write.h
@@ -4,10 +4,18 @@
#include <stdint.h>
#include <stdbool.h>
-uint64_t encodeFloat(float value, float offset, float factor, uint8_t bitPosition,
- uint8_t bitSize);
+#ifdef __cplusplus
+extern "C" {
+#endif
-uint64_t encodeBoolean(bool value, float offset, float factor,
- uint8_t bitPosition, uint8_t bitSize);
+uint64_t encodeFloat(float value, uint8_t bitPosition, uint8_t bitSize,
+ float factor, float offset);
+
+uint64_t encodeBoolean(bool value, uint8_t bitPosition, uint8_t bitSize,
+ float factor, float offset);
+
+#ifdef __cplusplus
+}
+#endif
#endif // __WRITE_H__