Skip to content
Snippets Groups Projects
Commit f4972798 authored by nrs1g15's avatar nrs1g15
Browse files

Properly serialized the data before transmission

parent db2bf9a1
No related branches found
No related tags found
No related merge requests found
<?xml version="1.0" encoding="UTF-8"?>
<project version="4">
<component name="JavaScriptSettings">
<option name="languageLevel" value="ES6" />
</component>
</project>
\ No newline at end of file
<?xml version="1.0" encoding="UTF-8"?>
<project version="4">
<component name="ProjectModuleManager">
<modules>
<module fileurl="file://$PROJECT_DIR$/.idea/sufst-controller.iml" filepath="$PROJECT_DIR$/.idea/sufst-controller.iml" />
</modules>
</component>
</project>
\ No newline at end of file
<?xml version="1.0" encoding="UTF-8"?>
<module type="CPP_MODULE" version="4">
<component name="NewModuleRootManager">
<content url="file://$MODULE_DIR$" />
<orderEntry type="inheritedJdk" />
<orderEntry type="sourceFolder" forTests="false" />
</component>
</module>
\ No newline at end of file
<?xml version="1.0" encoding="UTF-8"?>
<project version="4">
<component name="VcsDirectoryMappings">
<mapping directory="$PROJECT_DIR$/.." vcs="Git" />
</component>
</project>
\ No newline at end of file
......@@ -6,14 +6,8 @@
#define DASH_SERIAL_START_BYTE 0x55
struct DashSerialFrame {
uint8_t startByte;
uint16_t waterTemp;
uint16_t rpm;
// uint8_t crc;
} __attribute__((packed));
uint16_t gRpm = 0;
uint16_t gWaterTemp = 0;
void dashBegin()
......@@ -40,17 +34,16 @@ void dashControllerProcess()
static uint32_t lastSerialMs = 0;
if ((currentMs - lastSerialMs) >= DASH_REFRESH_MS)
{
if ((currentMs - lastSerialMs) >= DASH_REFRESH_MS) {
static uint8_t serialPayload[5];
serialPayload[0] = DASH_SERIAL_START_BYTE;
Serial.println(gRpm);
memcpy(&(serialPayload[1]), &gWaterTemp, 2);
DashSerialFrame dashSerialFrame;
dashSerialFrame.startByte = DASH_SERIAL_START_BYTE;
dashSerialFrame.rpm = gRpm;
dashSerialFrame.waterTemp = gWaterTemp;
memcpy(&(serialPayload[3]), &gRpm, 2);
Serial2.write((uint8_t *)(&dashSerialFrame), sizeof(DashSerialFrame));
Serial2.flush();
Serial2.write(serialPayload, 5);
}
}
......@@ -256,6 +256,9 @@ void serialProcess()
{
while(Serial.available() > 0) {
switch (dashSerialState) {
case checkStart: case startError:
if (Serial.read() == DASH_SERIAL_START_BYTE) {
......@@ -273,8 +276,6 @@ void serialProcess()
dashSerialState = checkRpm;
Serial.println(gDashWaterTemp);
break;
case checkRpm:
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment