forked from typhoon-hil/CHAdeMO
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathchademo.h
More file actions
154 lines (130 loc) · 6.11 KB
/
Copy pathchademo.h
File metadata and controls
154 lines (130 loc) · 6.11 KB
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
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
#ifndef CHADEMO_H_
#define CHADEMO_H_
#include "globals.h"
enum CHADEMOSTATE
{
STARTUP, //0
SEND_INITIAL_PARAMS, //1
WAIT_FOR_EVSE_PARAMS, //2
SET_CHARGE_BEGIN, //3
WAIT_FOR_BEGIN_CONFIRMATION, //4
CLOSE_CONTACTORS, //5
RUNNING, //6
CEASE_CURRENT, //7
WAIT_FOR_ZERO_CURRENT, //8
OPEN_CONTACTOR, //9
FAULTED, //10
STOPPED, //11
LIMBO //12
};
typedef struct
{
unsigned char supportWeldCheck;
unsigned short int availVoltage : 16;
unsigned char availCurrent;
unsigned short int thresholdVoltage : 16; //evse calculates this. It is the voltage at which it'll abort charging
//to save the battery pack in case we asked for something stupid
} EVSE_PARAMS;
typedef struct
{
unsigned short int presentVoltage : 16;
unsigned char presentCurrent;
unsigned char status;
unsigned short int remainingChargeSeconds;
unsigned short int remainingChargeMinutes;
} EVSE_STATUS;
typedef struct
{
unsigned short int targetVoltage; //what voltage we want the EVSE to put out
unsigned char targetCurrent; //what current we'd like the EVSE to provide
unsigned char remainingKWH; //report # of KWh in the battery pack (charge level)
unsigned char battOverVolt : 1; //we signal that battery or a cell is too high of a voltage
unsigned char battUnderVolt : 1; //we signal that battery is too low
unsigned char currDeviation : 1; //we signal that measured current is not the same as EVSE is reporting
unsigned char battOverTemp : 1; //we signal that battery is too hot
unsigned char voltDeviation : 1; //we signal that we measure a different voltage than EVSE reports
unsigned char chargingEnabled : 1; //ask EVSE to enable charging
unsigned char notParked : 1; //advise EVSE that we're not in park.
unsigned char chargingFault : 1; //signal EVSE that we found a fault
unsigned char contactorOpen : 1; //tell EVSE whether we've closed the charging contactor
unsigned char stopRequest : 1; //request that the charger cease operation before we really get going
} CARSIDE_STATUS;
//The IDs for chademo comm - both carside and EVSE side, so we know what to
//listen for as well.
#define CARSIDE_BATT_ID 0x100
#define CARSIDE_CHARGETIME_ID 0x101
#define CARSIDE_CONTROL_ID 0x102
#define EVSE_PARAMS_ID 0x108
#define EVSE_STATUS_ID 0x109
#define CARSIDE_FAULT_OVERV 1 //over voltage
#define CARSIDE_FAULT_UNDERV 2 //Under voltage
#define CARSIDE_FAULT_CURR 4 //current mismatch
#define CARSIDE_FAULT_OVERT 8 //over temperature
#define CARSIDE_FAULT_VOLTM 16 //voltage mismatch
#define CARSIDE_STATUS_CHARGE 1 //charging enabled
#define CARSIDE_STATUS_NOTPARK 2 //shifter not in safe state
#define CARSIDE_STATUS_MALFUN 4 //vehicle did something dumb
#define CARSIDE_STATUS_CONTOP 8 //main contactor open
#define CARSIDE_STATUS_CHSTOP 16 //charger stop before even charging
#define EVSE_STATUS_CHARGE 1 //charger is active
#define EVSE_STATUS_ERR 2 //something went wrong
#define EVSE_STATUS_CONNLOCK 4 //connector is currently locked
#define EVSE_STATUS_INCOMPAT 8 //parameters between vehicle and charger not compatible
#define EVSE_STATUS_BATTERR 16 //something wrong with battery?
#define EVSE_STATUS_STOPPED 32 //charger is stopped
class CHADEMO
{
public:
CHADEMO();
void setDelayedState(int newstate, unsigned short int delayTime, unsigned long CurrentMillis);
CHADEMOSTATE getState();
void setTargetAmperage(unsigned char t_amp);
void setTargetVoltage(unsigned short int t_volt);
void loop(unsigned long CurrentMillis);
void doProcessing();
void handleCANFrame(unsigned long CurrentMillis, unsigned int receiveID);
void setChargingFault();
void setBattOverTemp();
void checkChargingState();
unsigned long ChargeTimeRefSecs;
void ResetChargeState();
void updateTargetAV();
unsigned long CurrentMillis;
unsigned char bChademo10Protocol;
unsigned char askingAmps; //how many amps to ask for. Trends toward targetAmperage
unsigned int insertionTime;
CARSIDE_STATUS carStatus;
EVSE_PARAMS evse_params;
EVSE_STATUS evse_status;
CHADEMOSTATE chademoState;
bool sendBatt;
bool sendStatus;
bool sendTime;
unsigned char faults;
unsigned char status;
//these need to be accessed quickly in tight spots so they're public in an attempt at efficiency
unsigned char bChademoMode; //accessed but not modified in ISR so it should be OK non-volatile
unsigned char bChademoSendRequests; //should we be sending periodic status updates?
volatile unsigned char bChademoRequest; //is it time to send one of those updates?
protected:
private:
unsigned char bStartedCharge; //we have started a charge since the plug was inserted. Prevents attempts to restart charging if it stopped previously
//target values are what we send with periodic frames and can be changed.
unsigned char bListenEVSEStatus; //should we pay attention to stop requests and such yet?
unsigned char bDoMismatchChecks; //should we be checking for voltage and current mismatches?
unsigned char vMismatchCount; //count # of consecutive voltage mismatches. Don't trigger until we get enough
unsigned char cMismatchCount; //same but for current
unsigned char vCapCount; //# of EVSE voltage capacity checks that have failed in a row.
unsigned char vOverFault; //over volt fault counter like above.
unsigned char faultCount; //force faults to count up a bit before we actually fault.
unsigned int mismatchStart;
unsigned short int mismatchDelay; //don't start mismatch checks for 10 seconds
unsigned int stateMilli;
unsigned short int stateDelay;
unsigned int lastCommTime;
unsigned short int lastCommTimeout; //allow up to 1 second of comm fault before getting angry
CHADEMOSTATE stateHolder;
void sendCANStatus();
};
extern CHADEMO chademo;
#endif