forked from H4jen/webasto
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathwbus.h
135 lines (114 loc) · 3.56 KB
/
wbus.h
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
#ifndef WBUS_H
#define WBUS_H
#include <Arduino.h>
#include "webasto.h"
//extern const int TX_MESSAGE_INIT_1[];
//extern const int TX_MESSAGE_INIT_2[];
//extern const int TX_MESSAGE_INIT_3[];
//extern const int TX_MESSAGE_INIT_4[];
//extern const int TX_MESSAGE_INIT_5[];
//extern const int TX_MESSAGE_INIT_6[];
//This struct contains all the status information from webasto
struct webasto_status
{
int status_01 = 0;
int status_03 = 0;
int status_05 = 0;
int status_06 = 0;
int status_07 = 0;
int status_08 = 0;
int status_0A = 0;
int temp = 0;
int status_0F = 0;
int status_10 = 0;
int power = 0;
int resistance = 0;
int comb_fan = 0;
int status_1F = 0;
int status_24 = 0;
int status_27 = 0;
int status_29 = 0;
int status_2A = 0;
int status_2C = 0;
int status_2D = 0;
int status_32 = 0;
int status_34 = 0;
//Status information
int voltage_mV = 0;
//On-off flags (msg 50:03)
/*
bool combustion_fan=false;
bool glow_plug = false;
bool fuel_pump = false;
bool circulation_pump = false;
bool vehicle_fan_relay = false;
bool noozle_stock_heating = false;
bool flame_indicator = false;
//Operational measurements msg 50:05
int temp=-99;
int milliVolt=0;
bool flameDet=false;
int heatPower=0;
int flameRes=0;
*/
};
struct rx_message
{
int rawMessage=0;
int header=0;
int length=0;
int data[MESSAGE_BUFFER_SIZE];
char data_string[MESSAGE_BUFFER_SIZE];
int nr_data_read=0;
int checksum=0;
bool valid_message = false;
};
//Define the wbus class
class w_bus {
//Holds communication object
//CustomSoftwareSerial* mySerial;
//can only be pins 8-13 because prtmapping is hardcoded to PORTB
//Wraparound message buffer;
int message_buffer[MESSAGE_BUFFER_SIZE];
//Tracks were read and write in buffer is. Strategy is to always write to buffer when data availible. Read of buffer is only done when data is avalible.
int *read_ptr,*write_ptr;
int write_array_counter = 0;
int read_array_counter = 0;
struct rx_message rx_msg;
uint8_t rxPin=19;
uint8_t txPin=18;
int BAUDRATE = 2400;
int PARITY = SERIAL_8E1;
int TXHEADER = 0xf4;
int RXHEADER = 0x4f;
enum rx_reception_states {START, FINDHEADER, READLENGTH, READDATA, RESET_STATE, CHECKSUM_CHECK, PARSE_MESSAGE};
enum rx_reception_states rx_state = START;
//indicates if the wbus is initialized and ready to go. (1 = ok, 0 = in progressm, -1 failed)
//The flag below is implemented so that a sent request should result in a RX response.
bool waiting_for_rx_response = false;
//Number of external loops before timeout and rx_response cleared.
int time_out_loops=10;
//Keeps track of the number of times trying to read from RX without reponse. Reset, when a succespul read has been done.
int number_of_rx_loops=0;
//int wbus_ok=0;
String subStringDataMsg(int index);
//This function is called if a type 50 message is received (status)
void parseStatusData();
//struct webasto_status wbus_status;
public:
bool wbus_ok=false;
void parseMessage(void);
w_bus();
void printMsgDebug(void);
void sendSerialBreak(void);
void sendTXmessage(const int msg[],bool need_ack);
void readSerialData(void);
void getSerialMessage(void);
void initSequence(void);
void statusSequence(void);
struct webasto_status wbus_status;
};
//put your function headers here
//void parse_message();
//void sendTXmessage(const int msg[]);
#endif