├── WiFi ├── test.a ├── Data │ ├── test.a │ ├── BGcolor.txt │ ├── Heading.txt │ ├── admin.html │ ├── index.html │ └── highcharts-more.js └── leaf_wifi.ino ├── Software ├── test.a ├── Leaf_Gen1_1.ino ├── Leaf_Gen1_2.ino └── Leaf_Gen1_5.ino ├── Gen3 └── CAN_Logs │ └── test.a ├── Leaf_VCU_V1.pcb ├── Leaf_VCU_V1.sch ├── Leaf_VCU_V1 - PCB.pdf ├── Plots_Leaf_VCU_v1.zip ├── Leaf_Controller_V1Pinout.pdf ├── Leaf_VCU_V1 - Schematic.pdf ├── Leaf_Inv_Controller_V1_BOM.ods ├── Leaf_Inv_Controller_V1Pinout.odt ├── README.md └── LICENSE /WiFi/test.a: -------------------------------------------------------------------------------- 1 | 2 | -------------------------------------------------------------------------------- /Software/test.a: -------------------------------------------------------------------------------- 1 | 2 | -------------------------------------------------------------------------------- /WiFi/Data/test.a: -------------------------------------------------------------------------------- 1 | 2 | -------------------------------------------------------------------------------- /Gen3/CAN_Logs/test.a: -------------------------------------------------------------------------------- 1 | 2 | -------------------------------------------------------------------------------- /WiFi/Data/BGcolor.txt: -------------------------------------------------------------------------------- 1 | #FFFFFF -------------------------------------------------------------------------------- /WiFi/Data/Heading.txt: -------------------------------------------------------------------------------- 1 | Lexus GS450H VCU -------------------------------------------------------------------------------- /Leaf_VCU_V1.pcb: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/damienmaguire/Nissan-Leaf-Inverter-Controller/HEAD/Leaf_VCU_V1.pcb -------------------------------------------------------------------------------- /Leaf_VCU_V1.sch: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/damienmaguire/Nissan-Leaf-Inverter-Controller/HEAD/Leaf_VCU_V1.sch -------------------------------------------------------------------------------- /Leaf_VCU_V1 - PCB.pdf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/damienmaguire/Nissan-Leaf-Inverter-Controller/HEAD/Leaf_VCU_V1 - PCB.pdf -------------------------------------------------------------------------------- /Plots_Leaf_VCU_v1.zip: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/damienmaguire/Nissan-Leaf-Inverter-Controller/HEAD/Plots_Leaf_VCU_v1.zip -------------------------------------------------------------------------------- /Leaf_Controller_V1Pinout.pdf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/damienmaguire/Nissan-Leaf-Inverter-Controller/HEAD/Leaf_Controller_V1Pinout.pdf -------------------------------------------------------------------------------- /Leaf_VCU_V1 - Schematic.pdf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/damienmaguire/Nissan-Leaf-Inverter-Controller/HEAD/Leaf_VCU_V1 - Schematic.pdf -------------------------------------------------------------------------------- /Leaf_Inv_Controller_V1_BOM.ods: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/damienmaguire/Nissan-Leaf-Inverter-Controller/HEAD/Leaf_Inv_Controller_V1_BOM.ods -------------------------------------------------------------------------------- /Leaf_Inv_Controller_V1Pinout.odt: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/damienmaguire/Nissan-Leaf-Inverter-Controller/HEAD/Leaf_Inv_Controller_V1Pinout.odt -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # Nissan-Leaf-Inverter-Controller 2 | OpenSource Control Unit for the Nissan Leaf Gen 1 and Gen 2 inverter.
3 | PCB files in DesignSpark 8.1 format. 4 |
5 |
6 | Software courtesy of Perttu Ahola.
7 | http://productions.8dromeda.net/c55-leaf-inverter-protocol.html 8 |
9 | Slightly modified to run on an Arduino Due with an EV Shield.
10 | Hardware untested as of release.
11 | 12 | 16/08/19 : V1 Hardware built and tested. Software in progress. Latest version uploaded. Works with BMW E46 throttle pedal and sends CAN to E46 body to make dash and other modules work as they should. Still in early alpha. 13 | 14 | 15 | 19/08/19 : Bare PCBs available for those wishing to build their own controller :
16 | http://www.evbmw.com/index.php/evbmw-webshop/miscellaneous-bare-pcbs/leaf-vcm-bare 17 | 18 | 24/08/19 : Testing at full torque : https://www.youtube.com/watch?v=w1eDK8kHOu0 19 | 20 | 21 | 24/11/19 : BOM Updated with corrections. 22 | 23 | 27/03/20 : Uploaded new firmware with the following changes : 24 | 25 | -Now supports the use of ESP8266 Olimex WiFi module and web display 26 | 27 | -Supports ISA 100A CAN based shunt for battery monitoring 28 | 29 | -Precharge and main contactor control 30 | 31 | 32 | 22/02/21 : Now starting work on control of the Gen 3 (2018+) Leaf inverter uploaded a CAN log from bench test of the inverter on its own. 33 | -------------------------------------------------------------------------------- /WiFi/Data/admin.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 129 | 130 | 131 |
132 |
133 | 145 |
146 |
147 | 148 | 187 | 188 | -------------------------------------------------------------------------------- /WiFi/leaf_wifi.ino: -------------------------------------------------------------------------------- 1 | // Import required libraries 2 | #ifdef ESP32 3 | #include 4 | #include 5 | #include 6 | #else 7 | #include 8 | #include 9 | #include 10 | #include 11 | #include 12 | #include 13 | #endif 14 | #include 15 | 16 | // declaration of a variable 17 | String A, B, C, D, E, F; 18 | 19 | // Replace with your network credentials 20 | const char* ssid = ""; 21 | const char* password = ""; 22 | 23 | // Create AsyncWebServer object on port 80 24 | AsyncWebServer server(80); 25 | 26 | String getA() { 27 | return A; 28 | } 29 | String getB() { 30 | return B; 31 | } 32 | String getC() { 33 | return C; 34 | } 35 | String getD() { 36 | return D; 37 | } 38 | String getE() { 39 | return E; 40 | } 41 | String getF() { 42 | return F; 43 | } 44 | 45 | String getBGcolor() { 46 | File BGcolor = SPIFFS.open("/BGcolor.txt", "r"); 47 | String value = BGcolor.readString(); 48 | BGcolor.close(); 49 | return (value); 50 | } 51 | 52 | String getHeading() { 53 | File Heading = SPIFFS.open("/Heading.txt", "r"); 54 | String value = Heading.readString(); 55 | Heading.close(); 56 | return (value); 57 | } 58 | 59 | String getSsid() { 60 | File ssid = SPIFFS.open("/ssid.txt", "r"); 61 | String value = ssid.readString(); 62 | ssid.close(); 63 | return (value); 64 | } 65 | 66 | String getPassword() { 67 | File password = SPIFFS.open("/password.txt", "r"); 68 | String value = password.readString(); 69 | password.close(); 70 | return (value); 71 | } 72 | 73 | void setup() { 74 | // Serial port for debugging purposes 75 | Serial.begin(19200); 76 | 77 | // Initialize SPIFFS 78 | if (!SPIFFS.begin()) { 79 | Serial.println("An Error has occurred while mounting SPIFFS"); 80 | return; 81 | } 82 | 83 | Serial.println(getSsid()); 84 | Serial.println(getPassword()); 85 | //Start WiFi AP mode 86 | WiFi.mode(WIFI_AP); 87 | WiFi.softAP(getSsid(), getPassword()); 88 | 89 | // Route for root / web pages 90 | server.on("/", HTTP_GET, [](AsyncWebServerRequest * request) { 91 | request->send(SPIFFS, "/index.html"); 92 | }); 93 | server.on("/admin", HTTP_GET, [](AsyncWebServerRequest * request) { 94 | request->send(SPIFFS, "/admin.html"); 95 | }); 96 | server.on("/highcharts.js", HTTP_GET, [](AsyncWebServerRequest * request) { 97 | request->send(SPIFFS, "/highcharts.js", "text/javascript"); 98 | }); 99 | server.on("/highcharts-more.js", HTTP_GET, [](AsyncWebServerRequest * request) { 100 | request->send(SPIFFS, "/highcharts-more.js", "text/javascript"); 101 | }); 102 | server.on("/solid-gauge.js", HTTP_GET, [](AsyncWebServerRequest * request) { 103 | request->send(SPIFFS, "/solid-gauge.js", "text/javascript"); 104 | }); 105 | server.on("/getA", HTTP_GET, [](AsyncWebServerRequest * request) { 106 | request->send_P(200, "text/plain", getA().c_str()); 107 | }); 108 | server.on("/getB", HTTP_GET, [](AsyncWebServerRequest * request) { 109 | request->send_P(200, "text/plain", getB().c_str()); 110 | }); 111 | server.on("/getC", HTTP_GET, [](AsyncWebServerRequest * request) { 112 | request->send_P(200, "text/plain", getC().c_str()); 113 | }); 114 | server.on("/getD", HTTP_GET, [](AsyncWebServerRequest * request) { 115 | request->send_P(200, "text/plain", getD().c_str()); 116 | }); 117 | server.on("/getE", HTTP_GET, [](AsyncWebServerRequest * request) { 118 | request->send_P(200, "text/plain", getE().c_str()); 119 | }); 120 | server.on("/getF", HTTP_GET, [](AsyncWebServerRequest * request) { 121 | request->send_P(200, "text/plain", getF().c_str()); 122 | }); 123 | 124 | server.on("/getBGcolor", HTTP_GET, [](AsyncWebServerRequest * request) { 125 | request->send_P(200, "text/plain", getBGcolor().c_str()); 126 | }); 127 | server.on("/getSsid", HTTP_GET, [](AsyncWebServerRequest * request) { 128 | request->send_P(200, "text/plain", getSsid().c_str()); 129 | }); 130 | server.on("/getPassword", HTTP_GET, [](AsyncWebServerRequest * request) { 131 | request->send_P(200, "text/plain", getPassword().c_str()); 132 | }); 133 | server.on("/getHeading", HTTP_GET, [](AsyncWebServerRequest * request) { 134 | request->send_P(200, "text/plain", getHeading().c_str()); 135 | }); 136 | server.on("/setBGcolor", HTTP_GET, [](AsyncWebServerRequest * request) { 137 | //Serial.println(request->getParam("favcolor")->value()); 138 | File BGcolor = SPIFFS.open("/BGcolor.txt", "w"); 139 | BGcolor.print(request->getParam("favcolor")->value()); 140 | BGcolor.close(); 141 | 142 | File Heading = SPIFFS.open("/Heading.txt", "w"); 143 | Heading.print(request->getParam("heading")->value()); 144 | Heading.close(); 145 | 146 | File ssid = SPIFFS.open("/ssid.txt", "w"); 147 | ssid.print(request->getParam("ssid")->value()); 148 | ssid.close(); 149 | 150 | File password = SPIFFS.open("/password.txt", "w"); 151 | password.print(request->getParam("password")->value()); 152 | password.close(); 153 | 154 | request->redirect("/"); 155 | }); 156 | 157 | server.begin(); 158 | } 159 | 160 | void loop() { 161 | String justRates = Serial.readStringUntil('\n'); 162 | //split justrate variable from begining to first "," charactor 163 | int aSpaceIndex = justRates.indexOf(","); 164 | int bSpaceIndex = justRates.indexOf(",", aSpaceIndex + 1); 165 | int cSpaceIndex = justRates.indexOf(",", bSpaceIndex + 1); 166 | int dSpaceIndex = justRates.indexOf(",", cSpaceIndex + 1); 167 | int eSpaceIndex = justRates.indexOf(",", dSpaceIndex + 1); 168 | int fSpaceIndex = justRates.indexOf(",", eSpaceIndex + 1); 169 | int gSpaceIndex = justRates.indexOf(",", fSpaceIndex + 1); 170 | int hSpaceIndex = justRates.indexOf(",", gSpaceIndex + 1); 171 | int iSpaceIndex = justRates.indexOf(",", hSpaceIndex + 1); 172 | int jSpaceIndex = justRates.indexOf(",", iSpaceIndex + 1); 173 | int kSpaceIndex = justRates.indexOf(",", jSpaceIndex + 1); 174 | int lSpaceIndex = justRates.indexOf(",", kSpaceIndex + 1); 175 | A = (justRates.substring(1, aSpaceIndex)); 176 | B = (justRates.substring(aSpaceIndex + 2, bSpaceIndex)); 177 | C = (justRates.substring(bSpaceIndex + 2, cSpaceIndex)); 178 | D = (justRates.substring(cSpaceIndex + 2, dSpaceIndex)); 179 | E = (justRates.substring(dSpaceIndex + 2, eSpaceIndex)); 180 | F = (justRates.substring(eSpaceIndex + 2)); 181 | 182 | Serial.println(); 183 | Serial.print("Serial input - "); 184 | Serial.println(justRates); 185 | Serial.print("Split values - "); 186 | Serial.println("A : " + String(A) + " B : " + String(B) + " C : " + (C) + " D : " + String(D) + " E : " + String(E) + " F : " + String(F)); 187 | } 188 | -------------------------------------------------------------------------------- /WiFi/Data/index.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 73 | 74 | 75 | 76 |

77 |
78 |
79 |

80 |
81 |
82 |
83 |
84 |
85 |
86 |
87 |
88 | 89 | 90 | 91 | 440 | 441 | -------------------------------------------------------------------------------- /Software/Leaf_Gen1_1.ino: -------------------------------------------------------------------------------- 1 | /* 2 | Leaf Gen1 Inverter driver. Alpha software for testing. 3 | Runs on the Arduino Due SAM3X8E MCU. V1 Leaf open source vcu. 4 | Enter torque request on serial window. 5 | As of now only responds to negative torque requests. e.g. -10 6 | Positive torque requests trigger the inverter pwm but do not rotate the motor. 7 | 8 | 9 | Copyright 2019 10 | Perttu Ahola (all the hard work!) 11 | http://productions.8dromeda.net/c55-leaf-inverter-protocol.html 12 | 13 | Damien Maguire (copy and paste). 14 | OpenSource VCU hardware design available on Github : 15 | https://github.com/damienmaguire/Nissan-Leaf-Inverter-Controller 16 | 17 | 2011 Nisan Leaf Gen 1 EV CAN logs on Github: 18 | https://github.com/damienmaguire/LeafLogs 19 | 20 | 21 | This program is free software: you can redistribute it and/or modify 22 | it under the terms of the GNU General Public License as published by 23 | the Free Software Foundation, either version 3 of the License, or 24 | (at your option) any later version. 25 | 26 | This program is distributed in the hope that it will be useful, 27 | but WITHOUT ANY WARRANTY; without even the implied warranty of 28 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 29 | GNU General Public License for more details. 30 | 31 | You should have received a copy of the GNU General Public License 32 | along with this program. If not, see . 33 | 34 | 35 | 36 | */ 37 | 38 | #include 39 | #include 40 | #include 41 | #include 42 | 43 | 44 | 45 | #define Serial SerialUSB 46 | template inline Print &operator <<(Print &obj, T arg) { obj.print(arg); return obj; } 47 | 48 | 49 | CAN_FRAME outFrame; //A structured variable according to due_can library for transmitting CAN data. 50 | CAN_FRAME inFrame; //structure to keep inbound inFrames 51 | 52 | 53 | 54 | int16_t final_torque_request = 0; 55 | #define INVERTER_BITS_PER_VOLT 2 56 | #define INVERTER_BITS_PER_RPM 2 57 | 58 | 59 | ////////////////////Pin Map//////////////////////////////////////////////////// 60 | int led = 13; //onboard led for diagnosis 61 | #define Throttle1 A0 //Analog throttle channel 1 62 | #define Throttle2 A1 //Analog throttle channel 2 63 | #define Brake 61 //Brake pedal switch. High = brake on 64 | #define IN1 6 //General purpose digital input 1. High =12v 65 | #define IN2 7 //General purpose digital input 2. High =12v 66 | #define OUT1 48 //Low side switched general purpose digital output 1. high = on. 67 | #define OUT2 49 //Low side switched general purpose digital output 2. high = on. 68 | #define OUT3 50 //Low side switched general purpose digital output 3. high = on. 69 | ///////////////////////////////////////////////////////////////////////////////// 70 | 71 | 72 | 73 | 74 | struct InverterStatus { 75 | uint16_t voltage = 0; 76 | int16_t speed = 0; 77 | int8_t inverter_temperature = 0; 78 | int8_t motor_temperature = 0; 79 | bool error_state = false; 80 | } inverter_status; 81 | 82 | String readString; 83 | 84 | 85 | 86 | void setup() 87 | { 88 | Can0.begin(CAN_BPS_500K); // Inverter CAN 89 | Can1.begin(CAN_BPS_500K); // Vehicle CAN 90 | Can0.watchFor(); 91 | Can1.watchFor(); 92 | 93 | Serial.begin(115200); //Initialize our USB port which will always be redefined as SerialUSB to use the Native USB port tied directly to the SAM3X processor. 94 | Serial2.begin(115200); //Serial comms with ESP32 WiFi module on serial 2 95 | Timer3.attachInterrupt(Msgs10ms).start(10000); // 10ms CAN Message Timer 96 | Timer4.attachInterrupt(Msgs100ms).start(100000); //100ms CAN Message Timer 97 | 98 | pinMode(led, OUTPUT); 99 | pinMode(Brake, INPUT); 100 | pinMode(IN1, INPUT); 101 | pinMode(IN2, INPUT); 102 | pinMode(OUT1, OUTPUT); 103 | pinMode(OUT2, OUTPUT); 104 | pinMode(OUT3, OUTPUT); 105 | 106 | digitalWrite(led, HIGH); 107 | digitalWrite(OUT1, LOW); 108 | digitalWrite(OUT2, LOW); 109 | digitalWrite(OUT3, LOW); 110 | 111 | 112 | 113 | } 114 | 115 | 116 | 117 | void loop() 118 | { 119 | 120 | delay(10); 121 | checkCAN(); 122 | 123 | while (Serial.available()) { 124 | char c = Serial.read(); //gets one byte from serial buffer 125 | readString += c; //makes the string readString 126 | delay(2); //slow looping to allow buffer to fill with next character 127 | } 128 | 129 | if (readString.length() >0) { 130 | // Serial.println(readString); //so you can see the captured string 131 | final_torque_request = readString.toInt(); //convert readString into a number 132 | 133 | } 134 | 135 | readString=""; //empty for next input 136 | } 137 | 138 | 139 | 140 | 141 | 142 | void Msgs10ms() //10ms messages here 143 | { 144 | 145 | static uint8_t counter_11a_d6 = 0; 146 | static uint8_t counter_1d4 = 0; 147 | static uint8_t counter_1db = 0; 148 | 149 | // Send VCM gear selection signal (gets rid of P3197) 150 | 151 | 152 | outFrame.id = 0x11a; // Set our transmission address ID 153 | outFrame.length = 8; // Data payload 3 bytes 154 | outFrame.extended = 0; // Extended addresses - 0=11-bit 1=29bit 155 | outFrame.rtr=1; //No request 156 | 157 | 158 | 159 | 160 | // CAN_FRAME inFrame; 161 | // inFrame.id = 0x11a; 162 | // inFrame.length = 8; 163 | 164 | // Data taken from a gen1 inFrame where the car is starting to 165 | // move at about 10% throttle: 4E400055 0000017D 166 | 167 | // All possible gen1 values: 00 01 0D 11 1D 2D 2E 3D 3E 4D 4E 168 | // MSB nibble: Selected gear (gen1/LeafLogs) 169 | // 0: some kind of non-gear before driving 170 | // 1: some kind of non-gear after driving 171 | // 2: R 172 | // 3: N 173 | // 4: D 174 | // LSB nibble: ? (LeafLogs) 175 | // 0: sometimes at startup, not always; never when the 176 | // inverted is powered on (0.06%) 177 | // 1: this is the usual value (55% of the time in LeafLogs) 178 | // D: seems to occur for ~90ms when changing gears (0.2%) 179 | // E: this also is a usual value, but never occurs with the 180 | // non-gears 0 and 1 (44% of the time in LeafLogs) 181 | 182 | 183 | 184 | outFrame.data.bytes[0] = 0x4E; 185 | //outFrame.data.bytes[0] = 0x01; 186 | 187 | // 0x40 when car is ON, 0x80 when OFF, 0x50 when ECO 188 | outFrame.data.bytes[1] = 0x40; 189 | 190 | // Usually 0x00, sometimes 0x80 (LeafLogs), 0x04 seen by canmsgs 191 | outFrame.data.bytes[2] = 0x00; 192 | 193 | // Weird value at D3:4 that goes along with the counter 194 | // NOTE: Not actually needed, you can just send constant AA C0 195 | const static uint8_t weird_d34_values[4][2] = { 196 | {0xaa, 0xc0}, 197 | {0x55, 0x00}, 198 | {0x55, 0x40}, 199 | {0xaa, 0x80}, 200 | }; 201 | outFrame.data.bytes[3] = weird_d34_values[counter_11a_d6][0]; 202 | outFrame.data.bytes[4] = weird_d34_values[counter_11a_d6][1]; 203 | 204 | // Always 0x00 (LeafLogs, canmsgs) 205 | outFrame.data.bytes[5] = 0x00; 206 | 207 | // A 2-bit counter 208 | outFrame.data.bytes[6] = counter_11a_d6; 209 | 210 | counter_11a_d6++; 211 | if(counter_11a_d6 >= 4) 212 | counter_11a_d6 = 0; 213 | 214 | // Extra CRC 215 | nissan_crc(outFrame.data.bytes, 0x85); 216 | 217 | /*Serial.print(F("Sending ")); 218 | print_fancy_inFrame(inFrame); 219 | Serial.println();*/ 220 | 221 | Can0.sendFrame(outFrame); 222 | 223 | 224 | 225 | 226 | // Send target motor torque signal 227 | 228 | 229 | outFrame.id = 0x1d4; // Set our transmission address ID 230 | outFrame.length = 8; // Data payload 3 bytes 231 | outFrame.extended = 0; // Extended addresses - 0=11-bit 1=29bit 232 | outFrame.rtr=1; //No request 233 | 234 | // Data taken from a gen1 inFrame where the car is starting to 235 | // move at about 10% throttle: F70700E0C74430D4 236 | 237 | // Usually F7, but can have values between 9A...F7 (gen1) 238 | outFrame.data.bytes[0] = 0xF7; 239 | // 2016: 6E 240 | // outFrame.data.bytes[0] = 0x6E; 241 | 242 | // Usually 07, but can have values between 07...70 (gen1) 243 | outFrame.data.bytes[1] = 0x07; 244 | // 2016: 6E 245 | //outFrame.data.bytes[1] = 0x6E; 246 | 247 | // Requested torque (signed 12-bit value + always 0x0 in low nibble) 248 | static int16_t last_logged_final_torque_request = 0; 249 | if(final_torque_request != last_logged_final_torque_request){ 250 | last_logged_final_torque_request = final_torque_request; 251 | //log_print_timestamp(); 252 | Serial.print(F("Sending torque request ")); 253 | Serial.print(final_torque_request); 254 | Serial.print(F(" (speed: ")); 255 | Serial.print(inverter_status.speed / INVERTER_BITS_PER_RPM); 256 | Serial.print(F(" rpm)")); 257 | Serial.print(inverter_status.voltage / INVERTER_BITS_PER_VOLT); 258 | Serial.print(F(" Volts)")); 259 | Serial.println(); 260 | } 261 | if(final_torque_request >= -2048 && final_torque_request <= 2047){ 262 | outFrame.data.bytes[2] = ((final_torque_request < 0) ? 0x80 : 0) | 263 | ((final_torque_request >> 4) & 0x7f); 264 | outFrame.data.bytes[3] = (final_torque_request << 4) & 0xf0; 265 | } else { 266 | outFrame.data.bytes[2] = 0x00; 267 | outFrame.data.bytes[3] = 0x00; 268 | } 269 | 270 | // MSB nibble: Runs through the sequence 0, 4, 8, C 271 | // LSB nibble: Precharge report (precedes actual precharge 272 | // control) 273 | // 0: Discharging (5%) 274 | // 2: Precharge not started (1.4%) 275 | // 3: Precharging (0.4%) 276 | // 5: Starting discharge (3x10ms) (2.0%) 277 | // 7: Precharged (93%) 278 | outFrame.data.bytes[4] = 0x07 | (counter_1d4 << 6); 279 | //outFrame.data.bytes[4] = 0x02 | (counter_1d4 << 6); 280 | 281 | counter_1d4++; 282 | if(counter_1d4 >= 4) 283 | counter_1d4 = 0; 284 | 285 | // MSB nibble: 286 | // 0: 35-40ms at startup when gear is 0, then at shutdown 40ms 287 | // after the car has been shut off (6% total) 288 | // 4: Otherwise (94%) 289 | // LSB nibble: 290 | // 0: ~100ms when changing gear, along with 11A D0 b3:0 value 291 | // D (0.3%) 292 | // 2: Reverse gear related (13%) 293 | // 4: Forward gear related (21%) 294 | // 6: Occurs always when gear 11A D0 is 01 or 11 (66%) 295 | //outFrame.data.bytes[5] = 0x44; 296 | //outFrame.data.bytes[5] = 0x46; 297 | 298 | // 2016 drive cycle: 06, 46, precharge, 44, drive, 46, discharge, 06 299 | // 0x46 requires ~25 torque to start 300 | //outFrame.data.bytes[5] = 0x46; 301 | // 0x44 requires ~8 torque to start 302 | outFrame.data.bytes[5] = 0x44; 303 | 304 | // MSB nibble: 305 | // In a drive cycle, this slowly changes between values (gen1): 306 | // leaf_on_off.txt: 307 | // 5 7 3 2 0 1 3 7 308 | // leaf_on_rev_off.txt: 309 | // 5 7 3 2 0 6 310 | // leaf_on_Dx3.txt: 311 | // 5 7 3 2 0 2 3 2 0 2 3 2 0 2 3 7 312 | // leaf_on_stat_DRDRDR.txt: 313 | // 0 1 3 7 314 | // leaf_on_Driveincircle_off.txt: 315 | // 5 3 2 0 8 B 3 2 0 8 A B 3 2 0 8 A B A 8 0 2 3 7 316 | // leaf_on_wotind_off.txt: 317 | // 3 2 0 8 A B 3 7 318 | // leaf_on_wotinr_off.txt: 319 | // 5 7 3 2 0 8 A B 3 7 320 | // leaf_ac_charge.txt: 321 | // 4 6 E 6 322 | // Possibly some kind of control flags, try to figure out 323 | // using: 324 | // grep 000001D4 leaf_on_wotind_off.txt | cut -d' ' -f10 | uniq | ~/projects/leaf_tools/util/hex_to_ascii_binary.py 325 | // 2016: 326 | // Has different values! 327 | // LSB nibble: 328 | // 0: Always (gen1) 329 | // 1: (2016) 330 | 331 | // 2016 drive cycle: 332 | // E0: to 0.15s 333 | // E1: 2 messages 334 | // 61: to 2.06s (inverter is powered up and precharge 335 | // starts and completes during this) 336 | // 21: to 13.9s 337 | // 01: to 17.9s 338 | // 81: to 19.5s 339 | // A1: to 26.8s 340 | // 21: to 31.0s 341 | // 01: to 33.9s 342 | // 81: to 48.8s 343 | // A1: to 53.0s 344 | // 21: to 55.5s 345 | // 61: 2 messages 346 | // 60: to 55.9s 347 | // E0: to end of capture (discharge starts during this) 348 | 349 | // This value has been chosen at the end of the hardest 350 | // acceleration in the wide-open-throttle pull, with full-ish 351 | // torque still being requested, in 352 | // LeafLogs/leaf_on_wotind_off.txt 353 | //outFrame.data.bytes[6] = 0x00; 354 | 355 | // This value has been chosen for being seen most of the time 356 | // when, and before, applying throttle in the wide-open-throttle 357 | // pull, in 358 | // LeafLogs/leaf_on_wotind_off.txt 359 | outFrame.data.bytes[6] = 0x30; //brake applied heavilly. 360 | 361 | // Value chosen from a 2016 log 362 | //outFrame.data.bytes[6] = 0x61; 363 | 364 | // Value chosen from a 2016 log 365 | // 2016-24kWh-ev-on-drive-park-off.pcap #12101 / 15.63s 366 | // outFrame.data.bytes[6] = 0x01; 367 | //byte 6 brake signal 368 | 369 | // Extra CRC 370 | nissan_crc(outFrame.data.bytes, 0x85); 371 | 372 | /*Serial.print(F("Sending ")); 373 | print_fancy_inFrame(inFrame); 374 | Serial.println();*/ 375 | 376 | Can0.sendFrame(outFrame); 377 | 378 | //We need to send 0x1db here with voltage measured by inverter 379 | 380 | outFrame.id = 0x1db; // Set our transmission address ID 381 | outFrame.length = 8; // Data payload 3 bytes 382 | outFrame.extended = 0; // Extended addresses - 0=11-bit 1=29bit 383 | outFrame.rtr=1; //No request 384 | outFrame.data.bytes[0]=0x00; 385 | outFrame.data.bytes[1]=0x00; 386 | outFrame.data.bytes[2]=0x00; 387 | outFrame.data.bytes[3]=0x00; 388 | outFrame.data.bytes[4]=0x00; 389 | outFrame.data.bytes[5]=0x00; 390 | outFrame.data.bytes[6]=counter_1db; 391 | outFrame.data.bytes[7]=0x00; 392 | 393 | 394 | counter_1db++; 395 | if(counter_1db >= 4) 396 | counter_1db = 0; 397 | 398 | 399 | 400 | Can0.sendFrame(outFrame); 401 | 402 | 403 | 404 | 405 | //these messages go out on vehicle can and are specific to driving the E46 instrument cluster etc. 406 | 407 | outFrame.id = 0x316; // Set our transmission address ID 408 | outFrame.length = 8; // Data payload 8 bytes 409 | outFrame.extended = 0; // Extended addresses - 0=11-bit 1=29bit 410 | outFrame.rtr=1; //No request 411 | outFrame.data.bytes[0]=0x00; 412 | outFrame.data.bytes[1]=0x07; 413 | outFrame.data.bytes[2]=0xff; //RPM LSB 414 | outFrame.data.bytes[3]=0x4f; //RPM MSB [RPM=(hex2dec("byte3"&"byte2"))/6.4] 415 | outFrame.data.bytes[4]=0x65; 416 | outFrame.data.bytes[5]=0x12; 417 | outFrame.data.bytes[6]=0x00; 418 | outFrame.data.bytes[7]=0x62; 419 | Can1.sendFrame(outFrame); 420 | 421 | 422 | 423 | 424 | //********************temp sense ******************************* 425 | // tempValue=analogRead(tempIN); //read Analog pin voltage 426 | // The sensor and gauge are not linear. So if the sensed 427 | // Voltage is less than the mid point the Map function 428 | // is used to map the input values to output values For the gauge 429 | // output values (in decimal): 430 | // 86 = First visible movment of needle starts 431 | // 93 = Begining of Blue section 432 | // 128 = End of Blue Section 433 | // 169 = Begin Straight up 434 | // 193 = Midpoint of needle straight up values 435 | // 219 = Needle begins to move from center 436 | // 230 = Beginning of Red section 437 | // 254 = needle pegged to the right 438 | // MAP program statement: map(value, fromLow, fromHigh, toLow, toHigh) 439 | 440 | // if(tempValue < 964){ //if pin voltage < mid point value 441 | // tempValue= map(tempValue,22,963,86,173); //Map lower half of range 442 | // } 443 | // else { 444 | // tempValue= map(tempValue,964,1014,219,254); //Map upper half of range 445 | // } 446 | 447 | //Can bus data packet values to be sent 448 | outFrame.id = 0x329; // Set our transmission address ID 449 | outFrame.length = 8; // Data payload 8 bytes 450 | outFrame.extended = 0; // Extended addresses - 0=11-bit 1=29bit 451 | outFrame.rtr=1; //No request 452 | outFrame.data.bytes[0]=0x07; //was D9 453 | outFrame.data.bytes[1]=0x193; //tempValue; //temp bit tdata 454 | outFrame.data.bytes[2]=0xB2; 455 | outFrame.data.bytes[3]=0x19; 456 | outFrame.data.bytes[4]=0x00; 457 | outFrame.data.bytes[5]=0xEE; //Throttle position currently just fixed value 458 | outFrame.data.bytes[6]=0x00; 459 | outFrame.data.bytes[7]=0x00; 460 | Can1.sendFrame(outFrame); 461 | 462 | 463 | 464 | //From ECU, MPG, MIL, overheat light, Cruise 465 | // ErrorState variable controls: 466 | //Check engine(binary 10), Cruise (1000), EML (10000) 467 | //Temp light Variable controls temp light. Hex 08 is on zero off 468 | 469 | 470 | //**************** set Error Lights & cruise light ****** 471 | // hex 08 = Overheat light on 472 | // // hex 08 = Overheat light on 473 | //Set check engine. Binary 0010 (hex 02) 474 | // No error light (zero) 475 | 476 | 477 | // int z = 0x60; // + y; higher value lower MPG 478 | 479 | 480 | //Can bus data packet values to be sent 481 | outFrame.id = 0x545; // Set our transmission address ID 482 | outFrame.length = 8; // Data payload 8 bytes 483 | outFrame.extended = 0; // Extended addresses - 0=11-bit 1=29bit 484 | outFrame.rtr=1; //No request 485 | outFrame.data.bytes[0]=0x00; //2=check ewwngine on , 0=check engine off 486 | outFrame.data.bytes[1]=0x00; //LSB fuel comp 487 | outFrame.data.bytes[2]=0x00; //MSB fuel comp 488 | outFrame.data.bytes[3]=0x00; // hex 08 = Overheat light on 489 | outFrame.data.bytes[4]=0x7E; 490 | outFrame.data.bytes[5]=0x10; 491 | outFrame.data.bytes[6]=0x00; 492 | outFrame.data.bytes[7]=0x18; 493 | Can1.sendFrame(outFrame); 494 | 495 | 496 | 497 | } 498 | 499 | 500 | 501 | 502 | void Msgs100ms() ////100ms messages here 503 | { 504 | digitalWrite(led, !digitalRead(led)); //toggle led everytime we fire the 100ms messages. 505 | 506 | outFrame.id = 0x50b; // Set our transmission address ID 507 | outFrame.length = 7; // Data payload 8 bytes 508 | outFrame.extended = 0; // Extended addresses - 0=11-bit 1=29bit 509 | outFrame.rtr=1; //No request 510 | // Statistics from 2016 capture: 511 | // 10 00000000000000 512 | // 21 000002c0000000 513 | // 122 000000c0000000 514 | // 513 000006c0000000 515 | 516 | // Let's just send the most common one all the time 517 | // FIXME: This is a very sloppy implementation 518 | // hex_to_data(outFrame.data.bytes, "00,00,06,c0,00,00,00"); 519 | outFrame.data.bytes[0]=0x00; 520 | outFrame.data.bytes[1]=0x00; 521 | outFrame.data.bytes[2]=0x06; 522 | outFrame.data.bytes[3]=0xc0; 523 | outFrame.data.bytes[4]=0x00; 524 | outFrame.data.bytes[5]=0x00; 525 | outFrame.data.bytes[6]=0x00; 526 | 527 | /*CONSOLE.print(F("Sending ")); 528 | print_fancy_inFrame(inFrame); 529 | CONSOLE.println();*/ 530 | Can0.sendFrame(outFrame); 531 | 532 | 533 | 534 | 535 | } 536 | 537 | 538 | 539 | 540 | void checkCAN() 541 | { 542 | 543 | while(Can0.available()) 544 | { 545 | Can0.read(inFrame); 546 | // Serial.println(inFrame.id, HEX); 547 | 548 | 549 | if(inFrame.id == 0x1da && inFrame.length == 8){ 550 | // last_received_from_inverter_timestamp = millis(); 551 | 552 | inverter_status.voltage = ((uint16_t)inFrame.data.bytes[0] << 2) | 553 | (inFrame.data.bytes[1] >> 6); 554 | 555 | int16_t parsed_speed = ((uint16_t)inFrame.data.bytes[4] << 8) | 556 | (uint16_t)inFrame.data.bytes[5]; 557 | inverter_status.speed = (parsed_speed == 0x7fff ? 0 : parsed_speed); 558 | 559 | inverter_status.error_state = (inFrame.data.bytes[6] & 0xb0) != 0x00; 560 | } 561 | 562 | if(inFrame.id == 0x55a && inFrame.length == 8){ 563 | // last_received_from_inverter_timestamp = millis(); 564 | 565 | inverter_status.inverter_temperature = fahrenheit_to_celsius(inFrame.data.bytes[2]); 566 | inverter_status.motor_temperature = fahrenheit_to_celsius(inFrame.data.bytes[1]); 567 | } 568 | 569 | } 570 | 571 | } 572 | 573 | 574 | static int8_t fahrenheit_to_celsius(uint16_t fahrenheit) 575 | { 576 | int16_t result = ((int16_t)fahrenheit - 32) * 5 / 9; 577 | if(result < -128) 578 | return -128; 579 | if(result > 127) 580 | return 127; 581 | return result; 582 | } 583 | 584 | 585 | 586 | static void nissan_crc(uint8_t *data, uint8_t polynomial) 587 | { 588 | // We want to process 8 bytes with the 8th byte being zero 589 | data[7] = 0; 590 | uint8_t crc = 0; 591 | for(int b=0; b<8; b++) 592 | { 593 | for(int i=7; i>=0; i--) 594 | { 595 | uint8_t bit = ((data[b] &(1 << i)) > 0) ? 1 : 0; 596 | if(crc >= 0x80) 597 | crc = (byte)(((crc << 1) + bit) ^ polynomial); 598 | else 599 | crc = (byte)((crc << 1) + bit); 600 | } 601 | } 602 | data[7] = crc; 603 | } 604 | -------------------------------------------------------------------------------- /Software/Leaf_Gen1_2.ino: -------------------------------------------------------------------------------- 1 | /* 2 | Leaf Gen1 Inverter driver. Alpha software for testing. 3 | Runs on the Arduino Due SAM3X8E MCU. V1 Leaf open source vcu. 4 | Enter torque request on serial window. 5 | As of now only responds to negative torque requests. e.g. -10 6 | Positive torque requests trigger the inverter pwm but do not rotate the motor. 7 | 8 | 9 | Copyright 2019 10 | Perttu Ahola (all the hard work!) 11 | http://productions.8dromeda.net/c55-leaf-inverter-protocol.html 12 | 13 | Damien Maguire (copy and paste). 14 | OpenSource VCU hardware design available on Github : 15 | https://github.com/damienmaguire/Nissan-Leaf-Inverter-Controller 16 | 17 | 2011 Nisan Leaf Gen 1 EV CAN logs on Github: 18 | https://github.com/damienmaguire/LeafLogs 19 | 20 | 21 | This program is free software: you can redistribute it and/or modify 22 | it under the terms of the GNU General Public License as published by 23 | the Free Software Foundation, either version 3 of the License, or 24 | (at your option) any later version. 25 | 26 | This program is distributed in the hope that it will be useful, 27 | but WITHOUT ANY WARRANTY; without even the implied warranty of 28 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 29 | GNU General Public License for more details. 30 | 31 | You should have received a copy of the GNU General Public License 32 | along with this program. If not, see . 33 | 34 | 35 | 36 | */ 37 | 38 | #include 39 | #include 40 | #include 41 | #include 42 | 43 | 44 | 45 | #define Serial SerialUSB 46 | template inline Print &operator <<(Print &obj, T arg) { obj.print(arg); return obj; } 47 | 48 | 49 | CAN_FRAME outFrame; //A structured variable according to due_can library for transmitting CAN data. 50 | CAN_FRAME inFrame; //structure to keep inbound inFrames 51 | 52 | 53 | 54 | int16_t final_torque_request = 0; 55 | #define INVERTER_BITS_PER_VOLT 2 56 | #define INVERTER_BITS_PER_RPM 2 57 | 58 | 59 | ////////////////////Pin Map//////////////////////////////////////////////////// 60 | int led = 13; //onboard led for diagnosis 61 | #define Throttle1 A0 //Analog throttle channel 1 62 | #define Throttle2 A1 //Analog throttle channel 2 63 | #define Brake 61 //Brake pedal switch. High = brake on 64 | #define IN1 6 //General purpose digital input 1. High =12v 65 | #define IN2 7 //General purpose digital input 2. High =12v 66 | #define OUT1 48 //Low side switched general purpose digital output 1. high = on. 67 | #define OUT2 49 //Low side switched general purpose digital output 2. high = on. 68 | #define OUT3 50 //Low side switched general purpose digital output 3. high = on. 69 | ///////////////////////////////////////////////////////////////////////////////// 70 | 71 | uint16_t ThrotVal =0; //analog value of throttle position. 72 | uint16_t outRPM; //calculated value of rpm for e46 ike 73 | static int16_t MaxTrq=300; //max torque request 74 | struct InverterStatus { 75 | uint16_t voltage = 0; 76 | int16_t speed = 0; 77 | int8_t inverter_temperature = 0; 78 | int8_t motor_temperature = 0; 79 | bool error_state = false; 80 | } inverter_status; 81 | 82 | String readString; 83 | byte ABSMsg=0x11; 84 | uint8_t tempValue; //value to send to e46 temp gauge. 85 | 86 | void setup() 87 | { 88 | Can0.begin(CAN_BPS_500K); // Inverter CAN 89 | Can1.begin(CAN_BPS_500K); // Vehicle CAN 90 | //Can0.watchFor(0x1da); //set message filter for inverter can. Note sure if I can use two seperate values here. it might just pick 1! 91 | Can0.watchFor(); 92 | Can1.watchFor(0x1ff); //just a blank message to block receive from e46 messages. 93 | 94 | Serial.begin(115200); //Initialize our USB port which will always be redefined as SerialUSB to use the Native USB port tied directly to the SAM3X processor. 95 | Serial2.begin(115200); //Serial comms with ESP32 WiFi module on serial 2 96 | Timer4.attachInterrupt(Msgs10ms).start(10000); // 10ms CAN Message Timer 97 | Timer3.attachInterrupt(Msgs100ms).start(100000); //100ms CAN Message Timer 98 | 99 | pinMode(led, OUTPUT); 100 | pinMode(Brake, INPUT); 101 | pinMode(IN1, INPUT); 102 | pinMode(IN2, INPUT); 103 | pinMode(OUT1, OUTPUT); 104 | pinMode(OUT2, OUTPUT); 105 | pinMode(OUT3, OUTPUT); 106 | 107 | digitalWrite(led, HIGH); 108 | digitalWrite(OUT1, LOW); 109 | digitalWrite(OUT2, LOW); 110 | digitalWrite(OUT3, LOW); 111 | 112 | 113 | 114 | } 115 | 116 | 117 | 118 | void loop() 119 | { 120 | 121 | readPedals(); //read throttle and brake pedal status. 122 | SendTorqueRequest(); //send torque request to inverter. 123 | ProcessRPM(); 124 | CheckCAN(); 125 | 126 | } 127 | 128 | void Msgs10ms() //10ms messages here 129 | { 130 | 131 | static uint8_t counter_11a_d6 = 0; 132 | static uint8_t counter_1d4 = 0; 133 | static uint8_t counter_1db = 0; 134 | static uint8_t counter_329 = 0; 135 | 136 | // Send VCM gear selection signal (gets rid of P3197) 137 | 138 | 139 | outFrame.id = 0x11a; // Set our transmission address ID 140 | outFrame.length = 8; // Data payload 3 bytes 141 | outFrame.extended = 0; // Extended addresses - 0=11-bit 1=29bit 142 | outFrame.rtr=1; //No request 143 | 144 | 145 | 146 | 147 | // CAN_FRAME inFrame; 148 | // inFrame.id = 0x11a; 149 | // inFrame.length = 8; 150 | 151 | // Data taken from a gen1 inFrame where the car is starting to 152 | // move at about 10% throttle: 4E400055 0000017D 153 | 154 | // All possible gen1 values: 00 01 0D 11 1D 2D 2E 3D 3E 4D 4E 155 | // MSB nibble: Selected gear (gen1/LeafLogs) 156 | // 0: some kind of non-gear before driving 157 | // 1: some kind of non-gear after driving 158 | // 2: R 159 | // 3: N 160 | // 4: D 161 | // LSB nibble: ? (LeafLogs) 162 | // 0: sometimes at startup, not always; never when the 163 | // inverted is powered on (0.06%) 164 | // 1: this is the usual value (55% of the time in LeafLogs) 165 | // D: seems to occur for ~90ms when changing gears (0.2%) 166 | // E: this also is a usual value, but never occurs with the 167 | // non-gears 0 and 1 (44% of the time in LeafLogs) 168 | 169 | 170 | 171 | outFrame.data.bytes[0] = 0x4E; 172 | //outFrame.data.bytes[0] = 0x01; 173 | 174 | // 0x40 when car is ON, 0x80 when OFF, 0x50 when ECO 175 | outFrame.data.bytes[1] = 0x40; 176 | 177 | // Usually 0x00, sometimes 0x80 (LeafLogs), 0x04 seen by canmsgs 178 | outFrame.data.bytes[2] = 0x00; 179 | 180 | // Weird value at D3:4 that goes along with the counter 181 | // NOTE: Not actually needed, you can just send constant AA C0 182 | const static uint8_t weird_d34_values[4][2] = { 183 | {0xaa, 0xc0}, 184 | {0x55, 0x00}, 185 | {0x55, 0x40}, 186 | {0xaa, 0x80}, 187 | }; 188 | outFrame.data.bytes[3] = weird_d34_values[counter_11a_d6][0]; 189 | outFrame.data.bytes[4] = weird_d34_values[counter_11a_d6][1]; 190 | 191 | // Always 0x00 (LeafLogs, canmsgs) 192 | outFrame.data.bytes[5] = 0x00; 193 | 194 | // A 2-bit counter 195 | outFrame.data.bytes[6] = counter_11a_d6; 196 | 197 | counter_11a_d6++; 198 | if(counter_11a_d6 >= 4) 199 | counter_11a_d6 = 0; 200 | 201 | // Extra CRC 202 | nissan_crc(outFrame.data.bytes, 0x85); 203 | 204 | /*Serial.print(F("Sending ")); 205 | print_fancy_inFrame(inFrame); 206 | Serial.println();*/ 207 | 208 | Can0.sendFrame(outFrame); 209 | 210 | 211 | 212 | 213 | // Send target motor torque signal 214 | 215 | 216 | outFrame.id = 0x1d4; // Set our transmission address ID 217 | outFrame.length = 8; // Data payload 3 bytes 218 | outFrame.extended = 0; // Extended addresses - 0=11-bit 1=29bit 219 | outFrame.rtr=1; //No request 220 | 221 | // Data taken from a gen1 inFrame where the car is starting to 222 | // move at about 10% throttle: F70700E0C74430D4 223 | 224 | // Usually F7, but can have values between 9A...F7 (gen1) 225 | outFrame.data.bytes[0] = 0xF7; 226 | // 2016: 6E 227 | // outFrame.data.bytes[0] = 0x6E; 228 | 229 | // Usually 07, but can have values between 07...70 (gen1) 230 | outFrame.data.bytes[1] = 0x07; 231 | // 2016: 6E 232 | //outFrame.data.bytes[1] = 0x6E; 233 | 234 | // Requested torque (signed 12-bit value + always 0x0 in low nibble) 235 | static int16_t last_logged_final_torque_request = 0; 236 | if(final_torque_request != last_logged_final_torque_request){ 237 | last_logged_final_torque_request = final_torque_request; 238 | //log_print_timestamp(); 239 | Serial.print(F("Sending torque request ")); 240 | Serial.print(final_torque_request); 241 | Serial.print(F(" (speed: ")); 242 | Serial.print(inverter_status.speed / INVERTER_BITS_PER_RPM); 243 | Serial.print(F(" rpm)")); 244 | Serial.print(inverter_status.voltage / INVERTER_BITS_PER_VOLT); 245 | Serial.print(F(" Volts)")); 246 | Serial.println(); 247 | } 248 | if(final_torque_request >= -2048 && final_torque_request <= 2047){ 249 | outFrame.data.bytes[2] = ((final_torque_request < 0) ? 0x80 : 0) | 250 | ((final_torque_request >> 4) & 0x7f); 251 | outFrame.data.bytes[3] = (final_torque_request << 4) & 0xf0; 252 | } else { 253 | outFrame.data.bytes[2] = 0x00; 254 | outFrame.data.bytes[3] = 0x00; 255 | } 256 | 257 | // MSB nibble: Runs through the sequence 0, 4, 8, C 258 | // LSB nibble: Precharge report (precedes actual precharge 259 | // control) 260 | // 0: Discharging (5%) 261 | // 2: Precharge not started (1.4%) 262 | // 3: Precharging (0.4%) 263 | // 5: Starting discharge (3x10ms) (2.0%) 264 | // 7: Precharged (93%) 265 | outFrame.data.bytes[4] = 0x07 | (counter_1d4 << 6); 266 | //outFrame.data.bytes[4] = 0x02 | (counter_1d4 << 6); 267 | 268 | counter_1d4++; 269 | if(counter_1d4 >= 4) 270 | counter_1d4 = 0; 271 | 272 | // MSB nibble: 273 | // 0: 35-40ms at startup when gear is 0, then at shutdown 40ms 274 | // after the car has been shut off (6% total) 275 | // 4: Otherwise (94%) 276 | // LSB nibble: 277 | // 0: ~100ms when changing gear, along with 11A D0 b3:0 value 278 | // D (0.3%) 279 | // 2: Reverse gear related (13%) 280 | // 4: Forward gear related (21%) 281 | // 6: Occurs always when gear 11A D0 is 01 or 11 (66%) 282 | //outFrame.data.bytes[5] = 0x44; 283 | //outFrame.data.bytes[5] = 0x46; 284 | 285 | // 2016 drive cycle: 06, 46, precharge, 44, drive, 46, discharge, 06 286 | // 0x46 requires ~25 torque to start 287 | //outFrame.data.bytes[5] = 0x46; 288 | // 0x44 requires ~8 torque to start 289 | outFrame.data.bytes[5] = 0x44; 290 | 291 | // MSB nibble: 292 | // In a drive cycle, this slowly changes between values (gen1): 293 | // leaf_on_off.txt: 294 | // 5 7 3 2 0 1 3 7 295 | // leaf_on_rev_off.txt: 296 | // 5 7 3 2 0 6 297 | // leaf_on_Dx3.txt: 298 | // 5 7 3 2 0 2 3 2 0 2 3 2 0 2 3 7 299 | // leaf_on_stat_DRDRDR.txt: 300 | // 0 1 3 7 301 | // leaf_on_Driveincircle_off.txt: 302 | // 5 3 2 0 8 B 3 2 0 8 A B 3 2 0 8 A B A 8 0 2 3 7 303 | // leaf_on_wotind_off.txt: 304 | // 3 2 0 8 A B 3 7 305 | // leaf_on_wotinr_off.txt: 306 | // 5 7 3 2 0 8 A B 3 7 307 | // leaf_ac_charge.txt: 308 | // 4 6 E 6 309 | // Possibly some kind of control flags, try to figure out 310 | // using: 311 | // grep 000001D4 leaf_on_wotind_off.txt | cut -d' ' -f10 | uniq | ~/projects/leaf_tools/util/hex_to_ascii_binary.py 312 | // 2016: 313 | // Has different values! 314 | // LSB nibble: 315 | // 0: Always (gen1) 316 | // 1: (2016) 317 | 318 | // 2016 drive cycle: 319 | // E0: to 0.15s 320 | // E1: 2 messages 321 | // 61: to 2.06s (inverter is powered up and precharge 322 | // starts and completes during this) 323 | // 21: to 13.9s 324 | // 01: to 17.9s 325 | // 81: to 19.5s 326 | // A1: to 26.8s 327 | // 21: to 31.0s 328 | // 01: to 33.9s 329 | // 81: to 48.8s 330 | // A1: to 53.0s 331 | // 21: to 55.5s 332 | // 61: 2 messages 333 | // 60: to 55.9s 334 | // E0: to end of capture (discharge starts during this) 335 | 336 | // This value has been chosen at the end of the hardest 337 | // acceleration in the wide-open-throttle pull, with full-ish 338 | // torque still being requested, in 339 | // LeafLogs/leaf_on_wotind_off.txt 340 | //outFrame.data.bytes[6] = 0x00; 341 | 342 | // This value has been chosen for being seen most of the time 343 | // when, and before, applying throttle in the wide-open-throttle 344 | // pull, in 345 | // LeafLogs/leaf_on_wotind_off.txt 346 | outFrame.data.bytes[6] = 0x30; //brake applied heavilly. 347 | 348 | // Value chosen from a 2016 log 349 | //outFrame.data.bytes[6] = 0x61; 350 | 351 | // Value chosen from a 2016 log 352 | // 2016-24kWh-ev-on-drive-park-off.pcap #12101 / 15.63s 353 | // outFrame.data.bytes[6] = 0x01; 354 | //byte 6 brake signal 355 | 356 | // Extra CRC 357 | nissan_crc(outFrame.data.bytes, 0x85); 358 | 359 | /*Serial.print(F("Sending ")); 360 | print_fancy_inFrame(inFrame); 361 | Serial.println();*/ 362 | 363 | Can0.sendFrame(outFrame); 364 | 365 | //We need to send 0x1db here with voltage measured by inverter 366 | 367 | outFrame.id = 0x1db; // Set our transmission address ID 368 | outFrame.length = 8; // Data payload 3 bytes 369 | outFrame.extended = 0; // Extended addresses - 0=11-bit 1=29bit 370 | outFrame.rtr=1; //No request 371 | outFrame.data.bytes[0]=0x00; 372 | outFrame.data.bytes[1]=0x00; 373 | outFrame.data.bytes[2]=0x00; 374 | outFrame.data.bytes[3]=0x00; 375 | outFrame.data.bytes[4]=0x00; 376 | outFrame.data.bytes[5]=0x00; 377 | outFrame.data.bytes[6]=counter_1db; 378 | outFrame.data.bytes[7]=0x00; 379 | 380 | 381 | counter_1db++; 382 | if(counter_1db >= 4) 383 | counter_1db = 0; 384 | 385 | 386 | 387 | Can0.sendFrame(outFrame); 388 | 389 | 390 | 391 | 392 | //these messages go out on vehicle can and are specific to driving the E46 instrument cluster etc. 393 | 394 | //////////////////////DME Messages ////////////////////////////////////////////////////////// 395 | 396 | outFrame.id = 0x316; // Set our transmission address ID 397 | outFrame.length = 8; // Data payload 8 bytes 398 | outFrame.extended = 0; // Extended addresses - 0=11-bit 1=29bit 399 | outFrame.rtr=1; //No request 400 | outFrame.data.bytes[0]=0x05; 401 | outFrame.data.bytes[1]=0x00; 402 | outFrame.data.bytes[2]=lowByte(outRPM); //RPM LSB 403 | outFrame.data.bytes[3]=highByte(outRPM); //RPM MSB [RPM=(hex2dec("byte3"&"byte2"))/6.4] 0x12c0 should be 750rpm on tach 404 | // outFrame.data.bytes[2]=0xc0; //RPM LSB 405 | // outFrame.data.bytes[3]=0x12; //RPM MSB [RPM=(hex2dec("byte3"&"byte2"))/6.4] 0x12c0 should be 750rpm on tach 406 | // outFrame.data.bytes[2]=0xff; //RPM LSB 407 | // outFrame.data.bytes[3]=0x4f; //RPM MSB [RPM=(hex2dec("byte3"&"byte2"))/6.4] 0x4fff gives 3200rpm on tach 408 | outFrame.data.bytes[4]=0x00; 409 | outFrame.data.bytes[5]=0x00; 410 | outFrame.data.bytes[6]=0x00; 411 | outFrame.data.bytes[7]=0x00; 412 | Can1.sendFrame(outFrame); 413 | 414 | 415 | ///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// 416 | 417 | 418 | //********************temp sense ******************************* 419 | // tempValue=analogRead(tempIN); //read Analog pin voltage 420 | // The sensor and gauge are not linear. So if the sensed 421 | // Voltage is less than the mid point the Map function 422 | // is used to map the input values to output values For the gauge 423 | // output values (in decimal): 424 | // 86 = First visible movment of needle starts 425 | // 93 = Begining of Blue section 426 | // 128 = End of Blue Section 427 | // 169 = Begin Straight up 428 | // 193 = Midpoint of needle straight up values 429 | // 219 = Needle begins to move from center 430 | // 230 = Beginning of Red section 431 | // 254 = needle pegged to the right 432 | // MAP program statement: map(value, fromLow, fromHigh, toLow, toHigh) 433 | 434 | // if(tempValue < 964){ //if pin voltage < mid point value 435 | tempValue= inverter_status.inverter_temperature; //read temp from leaf inverter can. 436 | tempValue= map(tempValue,15,80,88,254); //Map to e46 temp gauge 437 | // } 438 | // else { 439 | // tempValue= map(tempValue,964,1014,219,254); //Map upper half of range 440 | // } 441 | 442 | //Can bus data packet values to be sent 443 | outFrame.id = 0x329; // Set our transmission address ID 444 | outFrame.length = 8; // Data payload 8 bytes 445 | outFrame.extended = 0; // Extended addresses - 0=11-bit 1=29bit 446 | outFrame.rtr=1; //No request 447 | outFrame.data.bytes[0]=ABSMsg; //needs to cycle 11,86,d9 448 | outFrame.data.bytes[1]=tempValue; //temp bit tdata 449 | outFrame.data.bytes[2]=0xc5; 450 | outFrame.data.bytes[3]=0x00; 451 | outFrame.data.bytes[4]=0x00; 452 | outFrame.data.bytes[5]=0x00; //Throttle position currently just fixed value 453 | outFrame.data.bytes[6]=0x00; 454 | outFrame.data.bytes[7]=0x00; 455 | Can1.sendFrame(outFrame); 456 | 457 | 458 | counter_329++; 459 | if(counter_329 >= 22) counter_329 = 0; 460 | if(counter_329==0) ABSMsg=0x11; 461 | if(counter_329==8) ABSMsg=0x86; 462 | if(counter_329==15) ABSMsg=0xd9; 463 | 464 | 465 | 466 | 467 | 468 | //From ECU, MPG, MIL, overheat light, Cruise 469 | // ErrorState variable controls: 470 | //Check engine(binary 10), Cruise (1000), EML (10000) 471 | //Temp light Variable controls temp light. Hex 08 is on zero off 472 | 473 | 474 | //**************** set Error Lights & cruise light ****** 475 | // hex 08 = Overheat light on 476 | // // hex 08 = Overheat light on 477 | //Set check engine. Binary 0010 (hex 02) 478 | // No error light (zero) 479 | 480 | 481 | // int z = 0x60; // + y; higher value lower MPG 482 | 483 | 484 | //Can bus data packet values to be sent 485 | outFrame.id = 0x545; // Set our transmission address ID 486 | outFrame.length = 8; // Data payload 8 bytes 487 | outFrame.extended = 0; // Extended addresses - 0=11-bit 1=29bit 488 | outFrame.rtr=1; //No request 489 | outFrame.data.bytes[0]=0x00; //2=check ewwngine on , 0=check engine off 490 | outFrame.data.bytes[1]=0x00; //LSB fuel comp 491 | outFrame.data.bytes[2]=0x00; //MSB fuel comp 492 | outFrame.data.bytes[3]=0x00; // hex 08 = Overheat light on 493 | outFrame.data.bytes[4]=0x7E; 494 | outFrame.data.bytes[5]=0x10; 495 | outFrame.data.bytes[6]=0x00; 496 | outFrame.data.bytes[7]=0x18; 497 | Can1.sendFrame(outFrame); 498 | 499 | 500 | 501 | 502 | 503 | } 504 | 505 | 506 | 507 | 508 | void Msgs100ms() ////100ms messages here 509 | { 510 | digitalWrite(led, !digitalRead(led)); //toggle led everytime we fire the 100ms messages. 511 | 512 | outFrame.id = 0x50b; // Set our transmission address ID 513 | outFrame.length = 7; // Data payload 8 bytes 514 | outFrame.extended = 0; // Extended addresses - 0=11-bit 1=29bit 515 | outFrame.rtr=1; //No request 516 | // Statistics from 2016 capture: 517 | // 10 00000000000000 518 | // 21 000002c0000000 519 | // 122 000000c0000000 520 | // 513 000006c0000000 521 | 522 | // Let's just send the most common one all the time 523 | // FIXME: This is a very sloppy implementation 524 | // hex_to_data(outFrame.data.bytes, "00,00,06,c0,00,00,00"); 525 | outFrame.data.bytes[0]=0x00; 526 | outFrame.data.bytes[1]=0x00; 527 | outFrame.data.bytes[2]=0x06; 528 | outFrame.data.bytes[3]=0xc0; 529 | outFrame.data.bytes[4]=0x00; 530 | outFrame.data.bytes[5]=0x00; 531 | outFrame.data.bytes[6]=0x00; 532 | 533 | /*CONSOLE.print(F("Sending ")); 534 | print_fancy_inFrame(inFrame); 535 | CONSOLE.println();*/ 536 | Can0.sendFrame(outFrame); 537 | 538 | } 539 | 540 | 541 | 542 | void readPedals() 543 | { 544 | ThrotVal = analogRead(Throttle1); //read throttle channel 1 directly 545 | //Serial.println(ThrotVal); //print for calibration. 546 | ThrotVal = map(ThrotVal, 110, 620, 0, MaxTrq); //will need to work here for cal. 547 | //Serial.println(ThrotVal); //print for calibration. 548 | if(ThrotVal<0) ThrotVal=0; //no negative numbers for now. 549 | if(digitalRead(Brake)) ThrotVal=0; //if brake is pressed we zero the throttle value. 550 | //Serial.println(ThrotVal); //print for calibration. 551 | } 552 | 553 | 554 | 555 | void SendTorqueRequest() 556 | { 557 | 558 | final_torque_request = ThrotVal; //send mapped throttle signal to inverter. 559 | 560 | } 561 | 562 | 563 | 564 | void ProcessRPM() //here we convert motor rpm values received from the leaf inverter into BMW E46 RPM can message. 565 | { 566 | outRPM = (inverter_status.speed)*6.4; 567 | if(outRPM<4800) outRPM=4800; //set lowest rpm to 750 displayed on tach to keep car alive thinking engine is running. 568 | if(outRPM>44800) outRPM=44800; //DONT READ MORE THAN 7000RPM! 569 | //Serial.println(outRPM); 570 | } 571 | 572 | 573 | 574 | 575 | static int8_t fahrenheit_to_celsius(uint16_t fahrenheit) 576 | { 577 | int16_t result = ((int16_t)fahrenheit - 32) * 5 / 9; 578 | if(result < -128) 579 | return -128; 580 | if(result > 127) 581 | return 127; 582 | return result; 583 | } 584 | 585 | void CheckCAN() 586 | { 587 | 588 | /////////////////////////////////////////////////////////////////////////////////////////////////////////// 589 | //read incomming data from inverter////////////////// 590 | ////////////////////////////////////////////////////// 591 | if(Can0.available()) 592 | { 593 | Can0.read(inFrame); 594 | //Serial.println(inFrame.id, HEX); 595 | 596 | 597 | if(inFrame.id == 0x1da && inFrame.length == 8){ 598 | // last_received_from_inverter_timestamp = millis(); 599 | 600 | inverter_status.voltage = ((uint16_t)inFrame.data.bytes[0] << 2) | 601 | (inFrame.data.bytes[1] >> 6); 602 | 603 | int16_t parsed_speed = ((uint16_t)inFrame.data.bytes[4] << 8) | 604 | (uint16_t)inFrame.data.bytes[5]; 605 | inverter_status.speed = (parsed_speed == 0x7fff ? 0 : parsed_speed); 606 | 607 | inverter_status.error_state = (inFrame.data.bytes[6] & 0xb0) != 0x00; 608 | } 609 | 610 | if(inFrame.id == 0x55a && inFrame.length == 8){ 611 | // last_received_from_inverter_timestamp = millis(); 612 | 613 | inverter_status.inverter_temperature = fahrenheit_to_celsius(inFrame.data.bytes[2]); 614 | inverter_status.motor_temperature = fahrenheit_to_celsius(inFrame.data.bytes[1]); 615 | Serial.println(inverter_status.inverter_temperature); 616 | } 617 | 618 | } 619 | 620 | //////////////////////////////////////////////////////////////////////////////////////////////// 621 | 622 | 623 | } 624 | 625 | static void nissan_crc(uint8_t *data, uint8_t polynomial) 626 | { 627 | // We want to process 8 bytes with the 8th byte being zero 628 | data[7] = 0; 629 | uint8_t crc = 0; 630 | for(int b=0; b<8; b++) 631 | { 632 | for(int i=7; i>=0; i--) 633 | { 634 | uint8_t bit = ((data[b] &(1 << i)) > 0) ? 1 : 0; 635 | if(crc >= 0x80) 636 | crc = (byte)(((crc << 1) + bit) ^ polynomial); 637 | else 638 | crc = (byte)((crc << 1) + bit); 639 | } 640 | } 641 | data[7] = crc; 642 | } 643 | -------------------------------------------------------------------------------- /Software/Leaf_Gen1_5.ino: -------------------------------------------------------------------------------- 1 | /* 2 | Leaf Gen1 Inverter driver. Alpha software for testing. 3 | Runs on the Arduino Due SAM3X8E MCU. V1 Leaf open source vcu. 4 | Enter torque request on serial window. 5 | As of now only responds to negative torque requests. e.g. -10 6 | Positive torque requests trigger the inverter pwm but do not rotate the motor. 7 | 8 | V5 incorporates ISA can shunt on CAN0. Let's hope the leaf inverter doesnt mind the isa messages and vice versa:) 9 | WiFi on Serial2. 10 | Precharge control : out1 = precharge , out2= main contactor 11 | 12 | 13 | Copyright 2019 14 | Perttu Ahola (all the hard work!) 15 | http://productions.8dromeda.net/c55-leaf-inverter-protocol.html 16 | 17 | Damien Maguire (copy and paste). 18 | OpenSource VCU hardware design available on Github : 19 | https://github.com/damienmaguire/Nissan-Leaf-Inverter-Controller 20 | 21 | 2011 Nisan Leaf Gen 1 EV CAN logs on Github: 22 | https://github.com/damienmaguire/LeafLogs 23 | 24 | 25 | This program is free software: you can redistribute it and/or modify 26 | it under the terms of the GNU General Public License as published by 27 | the Free Software Foundation, either version 3 of the License, or 28 | (at your option) any later version. 29 | 30 | This program is distributed in the hope that it will be useful, 31 | but WITHOUT ANY WARRANTY; without even the implied warranty of 32 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 33 | GNU General Public License for more details. 34 | 35 | You should have received a copy of the GNU General Public License 36 | along with this program. If not, see . 37 | 38 | 39 | 40 | */ 41 | #include 42 | #include 43 | #include 44 | #include 45 | #include 46 | #include //isa can shunt library 47 | 48 | 49 | 50 | #define Serial SerialUSB 51 | template inline Print &operator <<(Print &obj, T arg) { obj.print(arg); return obj; } 52 | 53 | 54 | CAN_FRAME outFrame; //A structured variable according to due_can library for transmitting CAN data. 55 | CAN_FRAME inFrame; //structure to keep inbound inFrames 56 | 57 | //////timers////////////////////////////// 58 | Metro timer_Frames10 = Metro(10); 59 | Metro timer_Frames100 = Metro(100); 60 | Metro timer_wifi = Metro(1100); 61 | Metro timer_hv = Metro(1000); 62 | 63 | 64 | int inv_volts_local; 65 | int16_t final_torque_request = 0; 66 | #define INVERTER_BITS_PER_VOLT 2 67 | #define INVERTER_BITS_PER_RPM 2 68 | 69 | 70 | ////////////////////Pin Map//////////////////////////////////////////////////// 71 | int led = 13; //onboard led for diagnosis 72 | #define Throttle1 A0 //Analog throttle channel 1 73 | #define Throttle2 A1 //Analog throttle channel 2 74 | #define Brake 61 //Brake pedal switch. High = brake on 75 | #define IN1 6 //General purpose digital input 1. High =12v 76 | #define IN2 7 //General purpose digital input 2. High =12v 77 | #define OUT1 48 //Low side switched general purpose digital output 1. high = on. 78 | #define OUT2 49 //Low side switched general purpose digital output 2. high = on. 79 | #define OUT3 50 //Low side switched general purpose digital output 3. high = on. 80 | ///////////////////////////////////////////////////////////////////////////////// 81 | 82 | #define HVPreset 340 //voltage at which to enable main contactor 83 | 84 | uint16_t ThrotVal =0; //analog value of throttle position. 85 | uint16_t outRPM; //calculated value of rpm for e46 ike 86 | static int16_t MaxTrq=2000; //max torque request 87 | struct InverterStatus { 88 | uint16_t voltage = 0; 89 | int16_t speed = 0; 90 | int8_t inverter_temperature = 0; 91 | int8_t motor_temperature = 0; 92 | bool error_state = false; 93 | } inverter_status; 94 | 95 | String readString; 96 | byte ABSMsg=0x11; 97 | uint8_t tempValue; //value to send to e46 temp gauge. 98 | 99 | bool T15Status; //flag to keep status of Terminal 15 from In1 100 | bool can_status; //flag for turning off and on can sending. 101 | bool Pch_Flag; //precharge status flag 102 | bool HV_Flag; //hv on flag 103 | 104 | ISA Sensor; //Instantiate ISA Module Sensor object to measure current and voltage 105 | 106 | void setup() 107 | { 108 | Can0.begin(CAN_BPS_500K); // Inverter CAN 109 | Can1.begin(CAN_BPS_500K); // Vehicle CAN 110 | //Can0.watchFor(0x1da); //set message filter for inverter can. Note sure if I can use two seperate values here. it might just pick 1! 111 | Can0.watchFor(); 112 | Can1.watchFor(0x1ff); //just a blank message to block receive from e46 messages. 113 | 114 | Serial.begin(115200); //Initialize our USB port which will always be redefined as SerialUSB to use the Native USB port tied directly to the SAM3X processor. 115 | Serial2.begin(19200); //Serial comms with ESP32 WiFi module on serial 2 116 | // Timer3.attachInterrupt(Msgs10ms).start(10000); // 10ms CAN Message Timer 117 | // Timer4.attachInterrupt(Msgs100ms).start(100000); //100ms CAN Message Timer 118 | 119 | pinMode(led, OUTPUT); 120 | pinMode(Brake, INPUT); 121 | pinMode(IN1, INPUT); //T15 input from ign on switch 122 | pinMode(IN2, INPUT); 123 | pinMode(OUT1, OUTPUT); 124 | pinMode(OUT2, OUTPUT); 125 | pinMode(OUT3, OUTPUT); 126 | 127 | //digitalWrite(led, HIGH); 128 | digitalWrite(OUT1, LOW); //precharge 129 | digitalWrite(OUT2, LOW); //main contactor 130 | digitalWrite(OUT3, LOW); //inverter power 131 | 132 | 133 | 134 | } 135 | 136 | 137 | 138 | void loop() 139 | { 140 | Check_T15(); //is the ignition on? 141 | if (timer_hv.check()) HV_Con(); //control hv system 142 | Msgs100ms(); //fire the 100ms can messages 143 | Msgs10ms(); //fire the 10ms can messages 144 | readPedals(); //read throttle and brake pedal status. 145 | SendTorqueRequest(); //send torque request to inverter. 146 | ProcessRPM(); //send rpm and temp to e46 instrument cluster 147 | CheckCAN(); //check for incoming can 148 | handle_wifi(); //send wifi data 149 | 150 | } 151 | 152 | void Check_T15() 153 | { 154 | if (digitalRead(IN1)) 155 | { 156 | T15Status=true; 157 | can_status=true; 158 | } 159 | else 160 | { 161 | T15Status=false; 162 | can_status=false; 163 | Pch_Flag=false; 164 | HV_Flag=false; 165 | inv_volts_local==0; 166 | } 167 | 168 | } 169 | 170 | void HV_Con() 171 | { 172 | 173 | inv_volts_local=(inverter_status.voltage / INVERTER_BITS_PER_VOLT); 174 | 175 | 176 | if (T15Status && !Pch_Flag) //if terminal 15 is on and precharge not enabled 177 | { 178 | digitalWrite(OUT3, HIGH); //inverter power on 179 | if(inv_volts_local<200) 180 | { 181 | digitalWrite(OUT1, HIGH); //precharge on 182 | Pch_Flag=true; 183 | } 184 | } 185 | if (T15Status && !HV_Flag && Pch_Flag) //using inverter measured hv for initial tests. Will use ISA derived voltage in final version. 186 | { 187 | if (inv_volts_local>340) 188 | { 189 | digitalWrite(OUT2, HIGH); //main contactor on 190 | HV_Flag=true; //hv on flag 191 | } 192 | } 193 | 194 | if (!T15Status) 195 | { 196 | digitalWrite(OUT1, LOW); //precharge off 197 | digitalWrite(OUT2, LOW); //main contactor off 198 | digitalWrite(OUT3, LOW); //inverter power off 199 | 200 | } 201 | 202 | } 203 | 204 | void handle_wifi(){ 205 | if (timer_wifi.check()) 206 | { 207 | /* 208 | * 209 | * Routine to send data to wifi on serial 2 210 | The information will be provided over serial to the esp8266 at 19200 baud 8n1 in the form : 211 | vxxx,ixxx,pxxx,mxxxx,oxxx,rxxx* where : 212 | 213 | v=pack voltage (0-700Volts) 214 | i=current (0-1000Amps) 215 | p=power (0-300kw) 216 | m=motor rpm (0-10000rpm) 217 | o=motor temp (-20 to 120C) 218 | r=inverter temp (-20 to 120C) 219 | *=end of string 220 | xxx=three digit integer for each parameter eg p100 = 100kw. 221 | updates will be every 1100ms approx. 222 | 223 | v100,i200,p35,m3000,o20,r100* 224 | */ 225 | 226 | //Serial2.print("v100,i200,p35,m3000,o20,r100*"); //test string 227 | 228 | digitalWrite(13,!digitalRead(13));//blink led every time we fire this interrrupt. 229 | Serial.print(inv_volts_local); 230 | Serial.print(F(" Volts")); 231 | Serial.println(); 232 | Serial.println(HV_Flag); 233 | 234 | Serial2.print("v");//dc bus voltage 235 | Serial2.print(Sensor.Voltage);//voltage derived from ISA shunt 236 | Serial2.print(",i");//dc current 237 | Serial2.print(Sensor.Amperes);//current derived from ISA shunt 238 | Serial2.print(",p");//total motor power 239 | Serial2.print(Sensor.KW);//Power value derived from ISA Shunt 240 | Serial2.print(",m");//motor rpm 241 | Serial2.print(inverter_status.speed); 242 | Serial2.print(",o");//motor temp 243 | Serial2.print(inverter_status.motor_temperature); 244 | Serial2.print(",r");//inverter temp 245 | Serial2.print(inverter_status.inverter_temperature); 246 | Serial2.print("*");// end of data indicator 247 | } 248 | } 249 | 250 | 251 | 252 | 253 | 254 | void Msgs10ms() //10ms messages here 255 | { 256 | if(timer_Frames10.check()) 257 | { 258 | if(can_status) 259 | { 260 | 261 | 262 | static uint8_t counter_11a_d6 = 0; 263 | static uint8_t counter_1d4 = 0; 264 | static uint8_t counter_1db = 0; 265 | static uint8_t counter_329 = 0; 266 | static uint8_t counter_100ms = 0; 267 | 268 | // Send VCM gear selection signal (gets rid of P3197) 269 | 270 | 271 | outFrame.id = 0x11a; // Set our transmission address ID 272 | outFrame.length = 8; // Data payload 3 bytes 273 | outFrame.extended = 0; // Extended addresses - 0=11-bit 1=29bit 274 | outFrame.rtr=1; //No request 275 | 276 | 277 | 278 | 279 | // CAN_FRAME inFrame; 280 | // inFrame.id = 0x11a; 281 | // inFrame.length = 8; 282 | 283 | // Data taken from a gen1 inFrame where the car is starting to 284 | // move at about 10% throttle: 4E400055 0000017D 285 | 286 | // All possible gen1 values: 00 01 0D 11 1D 2D 2E 3D 3E 4D 4E 287 | // MSB nibble: Selected gear (gen1/LeafLogs) 288 | // 0: some kind of non-gear before driving 289 | // 1: some kind of non-gear after driving 290 | // 2: R 291 | // 3: N 292 | // 4: D 293 | // LSB nibble: ? (LeafLogs) 294 | // 0: sometimes at startup, not always; never when the 295 | // inverted is powered on (0.06%) 296 | // 1: this is the usual value (55% of the time in LeafLogs) 297 | // D: seems to occur for ~90ms when changing gears (0.2%) 298 | // E: this also is a usual value, but never occurs with the 299 | // non-gears 0 and 1 (44% of the time in LeafLogs) 300 | 301 | 302 | 303 | outFrame.data.bytes[0] = 0x4E; 304 | //outFrame.data.bytes[0] = 0x01; 305 | 306 | // 0x40 when car is ON, 0x80 when OFF, 0x50 when ECO 307 | outFrame.data.bytes[1] = 0x40; 308 | 309 | // Usually 0x00, sometimes 0x80 (LeafLogs), 0x04 seen by canmsgs 310 | outFrame.data.bytes[2] = 0x00; 311 | 312 | // Weird value at D3:4 that goes along with the counter 313 | // NOTE: Not actually needed, you can just send constant AA C0 314 | const static uint8_t weird_d34_values[4][2] = { 315 | {0xaa, 0xc0}, 316 | {0x55, 0x00}, 317 | {0x55, 0x40}, 318 | {0xaa, 0x80}, 319 | }; 320 | outFrame.data.bytes[3] = weird_d34_values[counter_11a_d6][0]; 321 | outFrame.data.bytes[4] = weird_d34_values[counter_11a_d6][1]; 322 | 323 | // Always 0x00 (LeafLogs, canmsgs) 324 | outFrame.data.bytes[5] = 0x00; 325 | 326 | // A 2-bit counter 327 | outFrame.data.bytes[6] = counter_11a_d6; 328 | 329 | counter_11a_d6++; 330 | if(counter_11a_d6 >= 4) 331 | counter_11a_d6 = 0; 332 | 333 | // Extra CRC 334 | nissan_crc(outFrame.data.bytes, 0x85); 335 | 336 | /*Serial.print(F("Sending ")); 337 | print_fancy_inFrame(inFrame); 338 | Serial.println();*/ 339 | 340 | Can0.sendFrame(outFrame); 341 | 342 | 343 | 344 | 345 | // Send target motor torque signal 346 | 347 | 348 | outFrame.id = 0x1d4; // Set our transmission address ID 349 | outFrame.length = 8; // Data payload 3 bytes 350 | outFrame.extended = 0; // Extended addresses - 0=11-bit 1=29bit 351 | outFrame.rtr=1; //No request 352 | 353 | // Data taken from a gen1 inFrame where the car is starting to 354 | // move at about 10% throttle: F70700E0C74430D4 355 | 356 | // Usually F7, but can have values between 9A...F7 (gen1) 357 | outFrame.data.bytes[0] = 0xF7; 358 | // 2016: 6E 359 | // outFrame.data.bytes[0] = 0x6E; 360 | 361 | // Usually 07, but can have values between 07...70 (gen1) 362 | outFrame.data.bytes[1] = 0x07; 363 | // 2016: 6E 364 | //outFrame.data.bytes[1] = 0x6E; 365 | 366 | // Requested torque (signed 12-bit value + always 0x0 in low nibble) 367 | static int16_t last_logged_final_torque_request = 0; 368 | if(final_torque_request != last_logged_final_torque_request){ 369 | last_logged_final_torque_request = final_torque_request; 370 | //log_print_timestamp(); 371 | //Serial.print(F("Sending torque request ")); 372 | //Serial.print(final_torque_request); 373 | //Serial.print(F(" (speed: ")); 374 | //Serial.print(inverter_status.speed / INVERTER_BITS_PER_RPM); 375 | //Serial.print(F(" rpm)")); 376 | //Serial.print(inverter_status.voltage / INVERTER_BITS_PER_VOLT); 377 | //Serial.print(F(" Volts)")); 378 | //Serial.println(); 379 | } 380 | if(final_torque_request >= -2048 && final_torque_request <= 2047){ 381 | outFrame.data.bytes[2] = ((final_torque_request < 0) ? 0x80 : 0) | 382 | ((final_torque_request >> 4) & 0x7f); 383 | outFrame.data.bytes[3] = (final_torque_request << 4) & 0xf0; 384 | } else { 385 | outFrame.data.bytes[2] = 0x00; 386 | outFrame.data.bytes[3] = 0x00; 387 | } 388 | 389 | // MSB nibble: Runs through the sequence 0, 4, 8, C 390 | // LSB nibble: Precharge report (precedes actual precharge 391 | // control) 392 | // 0: Discharging (5%) 393 | // 2: Precharge not started (1.4%) 394 | // 3: Precharging (0.4%) 395 | // 5: Starting discharge (3x10ms) (2.0%) 396 | // 7: Precharged (93%) 397 | outFrame.data.bytes[4] = 0x07 | (counter_1d4 << 6); 398 | //outFrame.data.bytes[4] = 0x02 | (counter_1d4 << 6); 399 | 400 | counter_1d4++; 401 | if(counter_1d4 >= 4) 402 | counter_1d4 = 0; 403 | 404 | // MSB nibble: 405 | // 0: 35-40ms at startup when gear is 0, then at shutdown 40ms 406 | // after the car has been shut off (6% total) 407 | // 4: Otherwise (94%) 408 | // LSB nibble: 409 | // 0: ~100ms when changing gear, along with 11A D0 b3:0 value 410 | // D (0.3%) 411 | // 2: Reverse gear related (13%) 412 | // 4: Forward gear related (21%) 413 | // 6: Occurs always when gear 11A D0 is 01 or 11 (66%) 414 | //outFrame.data.bytes[5] = 0x44; 415 | //outFrame.data.bytes[5] = 0x46; 416 | 417 | // 2016 drive cycle: 06, 46, precharge, 44, drive, 46, discharge, 06 418 | // 0x46 requires ~25 torque to start 419 | //outFrame.data.bytes[5] = 0x46; 420 | // 0x44 requires ~8 torque to start 421 | outFrame.data.bytes[5] = 0x44; 422 | 423 | // MSB nibble: 424 | // In a drive cycle, this slowly changes between values (gen1): 425 | // leaf_on_off.txt: 426 | // 5 7 3 2 0 1 3 7 427 | // leaf_on_rev_off.txt: 428 | // 5 7 3 2 0 6 429 | // leaf_on_Dx3.txt: 430 | // 5 7 3 2 0 2 3 2 0 2 3 2 0 2 3 7 431 | // leaf_on_stat_DRDRDR.txt: 432 | // 0 1 3 7 433 | // leaf_on_Driveincircle_off.txt: 434 | // 5 3 2 0 8 B 3 2 0 8 A B 3 2 0 8 A B A 8 0 2 3 7 435 | // leaf_on_wotind_off.txt: 436 | // 3 2 0 8 A B 3 7 437 | // leaf_on_wotinr_off.txt: 438 | // 5 7 3 2 0 8 A B 3 7 439 | // leaf_ac_charge.txt: 440 | // 4 6 E 6 441 | // Possibly some kind of control flags, try to figure out 442 | // using: 443 | // grep 000001D4 leaf_on_wotind_off.txt | cut -d' ' -f10 | uniq | ~/projects/leaf_tools/util/hex_to_ascii_binary.py 444 | // 2016: 445 | // Has different values! 446 | // LSB nibble: 447 | // 0: Always (gen1) 448 | // 1: (2016) 449 | 450 | // 2016 drive cycle: 451 | // E0: to 0.15s 452 | // E1: 2 messages 453 | // 61: to 2.06s (inverter is powered up and precharge 454 | // starts and completes during this) 455 | // 21: to 13.9s 456 | // 01: to 17.9s 457 | // 81: to 19.5s 458 | // A1: to 26.8s 459 | // 21: to 31.0s 460 | // 01: to 33.9s 461 | // 81: to 48.8s 462 | // A1: to 53.0s 463 | // 21: to 55.5s 464 | // 61: 2 messages 465 | // 60: to 55.9s 466 | // E0: to end of capture (discharge starts during this) 467 | 468 | // This value has been chosen at the end of the hardest 469 | // acceleration in the wide-open-throttle pull, with full-ish 470 | // torque still being requested, in 471 | // LeafLogs/leaf_on_wotind_off.txt 472 | //outFrame.data.bytes[6] = 0x00; 473 | 474 | // This value has been chosen for being seen most of the time 475 | // when, and before, applying throttle in the wide-open-throttle 476 | // pull, in 477 | // LeafLogs/leaf_on_wotind_off.txt 478 | outFrame.data.bytes[6] = 0x30; //brake applied heavilly. 479 | 480 | // Value chosen from a 2016 log 481 | //outFrame.data.bytes[6] = 0x61; 482 | 483 | // Value chosen from a 2016 log 484 | // 2016-24kWh-ev-on-drive-park-off.pcap #12101 / 15.63s 485 | // outFrame.data.bytes[6] = 0x01; 486 | //byte 6 brake signal 487 | 488 | // Extra CRC 489 | nissan_crc(outFrame.data.bytes, 0x85); 490 | 491 | /*Serial.print(F("Sending ")); 492 | print_fancy_inFrame(inFrame); 493 | Serial.println();*/ 494 | 495 | Can0.sendFrame(outFrame); 496 | 497 | //We need to send 0x1db here with voltage measured by inverter 498 | 499 | outFrame.id = 0x1db; // Set our transmission address ID 500 | outFrame.length = 8; // Data payload 3 bytes 501 | outFrame.extended = 0; // Extended addresses - 0=11-bit 1=29bit 502 | outFrame.rtr=1; //No request 503 | outFrame.data.bytes[0]=0x00; 504 | outFrame.data.bytes[1]=0x00; 505 | outFrame.data.bytes[2]=0x00; 506 | outFrame.data.bytes[3]=0x00; 507 | outFrame.data.bytes[4]=0x00; 508 | outFrame.data.bytes[5]=0x00; 509 | outFrame.data.bytes[6]=counter_1db; 510 | outFrame.data.bytes[7]=0x00; 511 | 512 | 513 | counter_1db++; 514 | if(counter_1db >= 4) 515 | counter_1db = 0; 516 | 517 | 518 | 519 | Can0.sendFrame(outFrame); 520 | 521 | ///////////////Originally sent as 100ms messages./////////////////////////////////////////// 522 | 523 | 524 | 525 | outFrame.id = 0x50b; // Set our transmission address ID 526 | outFrame.length = 7; // Data payload 8 bytes 527 | outFrame.extended = 0; // Extended addresses - 0=11-bit 1=29bit 528 | outFrame.rtr=1; //No request 529 | // Statistics from 2016 capture: 530 | // 10 00000000000000 531 | // 21 000002c0000000 532 | // 122 000000c0000000 533 | // 513 000006c0000000 534 | 535 | // Let's just send the most common one all the time 536 | // FIXME: This is a very sloppy implementation 537 | // hex_to_data(outFrame.data.bytes, "00,00,06,c0,00,00,00"); 538 | outFrame.data.bytes[0]=0x00; 539 | outFrame.data.bytes[1]=0x00; 540 | outFrame.data.bytes[2]=0x06; 541 | outFrame.data.bytes[3]=0xc0; 542 | outFrame.data.bytes[4]=0x00; 543 | outFrame.data.bytes[5]=0x00; 544 | outFrame.data.bytes[6]=0x00; 545 | 546 | /*CONSOLE.print(F("Sending ")); 547 | print_fancy_inFrame(inFrame); 548 | CONSOLE.println();*/ 549 | Can0.sendFrame(outFrame); 550 | 551 | ///////////////////////////////////////////////////////////////////////////////////////////////////// 552 | 553 | 554 | //these messages go out on vehicle can and are specific to driving the E46 instrument cluster etc. 555 | 556 | //////////////////////DME Messages ////////////////////////////////////////////////////////// 557 | 558 | outFrame.id = 0x316; // Set our transmission address ID 559 | outFrame.length = 8; // Data payload 8 bytes 560 | outFrame.extended = 0; // Extended addresses - 0=11-bit 1=29bit 561 | outFrame.rtr=1; //No request 562 | outFrame.data.bytes[0]=0x05; 563 | outFrame.data.bytes[1]=0x00; 564 | outFrame.data.bytes[2]=lowByte(outRPM); //RPM LSB 565 | outFrame.data.bytes[3]=highByte(outRPM); //RPM MSB [RPM=(hex2dec("byte3"&"byte2"))/6.4] 0x12c0 should be 750rpm on tach 566 | // outFrame.data.bytes[2]=0xc0; //RPM LSB 567 | // outFrame.data.bytes[3]=0x12; //RPM MSB [RPM=(hex2dec("byte3"&"byte2"))/6.4] 0x12c0 should be 750rpm on tach 568 | // outFrame.data.bytes[2]=0xff; //RPM LSB 569 | // outFrame.data.bytes[3]=0x4f; //RPM MSB [RPM=(hex2dec("byte3"&"byte2"))/6.4] 0x4fff gives 3200rpm on tach 570 | outFrame.data.bytes[4]=0x00; 571 | outFrame.data.bytes[5]=0x00; 572 | outFrame.data.bytes[6]=0x00; 573 | outFrame.data.bytes[7]=0x00; 574 | Can1.sendFrame(outFrame); 575 | 576 | 577 | ///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// 578 | 579 | 580 | //********************temp sense ******************************* 581 | // tempValue=analogRead(tempIN); //read Analog pin voltage 582 | // The sensor and gauge are not linear. So if the sensed 583 | // Voltage is less than the mid point the Map function 584 | // is used to map the input values to output values For the gauge 585 | // output values (in decimal): 586 | // 86 = First visible movment of needle starts 587 | // 93 = Begining of Blue section 588 | // 128 = End of Blue Section 589 | // 169 = Begin Straight up 590 | // 193 = Midpoint of needle straight up values 591 | // 219 = Needle begins to move from center 592 | // 230 = Beginning of Red section 593 | // 254 = needle pegged to the right 594 | // MAP program statement: map(value, fromLow, fromHigh, toLow, toHigh) 595 | 596 | // if(tempValue < 964){ //if pin voltage < mid point value 597 | tempValue= inverter_status.inverter_temperature; //read temp from leaf inverter can. 598 | tempValue= map(tempValue,15,80,88,254); //Map to e46 temp gauge 599 | // } 600 | // else { 601 | // tempValue= map(tempValue,964,1014,219,254); //Map upper half of range 602 | // } 603 | 604 | //Can bus data packet values to be sent 605 | outFrame.id = 0x329; // Set our transmission address ID 606 | outFrame.length = 8; // Data payload 8 bytes 607 | outFrame.extended = 0; // Extended addresses - 0=11-bit 1=29bit 608 | outFrame.rtr=1; //No request 609 | outFrame.data.bytes[0]=ABSMsg; //needs to cycle 11,86,d9 610 | outFrame.data.bytes[1]=tempValue; //temp bit tdata 611 | outFrame.data.bytes[2]=0xc5; 612 | outFrame.data.bytes[3]=0x00; 613 | outFrame.data.bytes[4]=0x00; 614 | outFrame.data.bytes[5]=0x00; //Throttle position currently just fixed value 615 | outFrame.data.bytes[6]=0x00; 616 | outFrame.data.bytes[7]=0x00; 617 | Can1.sendFrame(outFrame); 618 | 619 | 620 | counter_329++; 621 | if(counter_329 >= 22) counter_329 = 0; 622 | if(counter_329==0) ABSMsg=0x11; 623 | if(counter_329==8) ABSMsg=0x86; 624 | if(counter_329==15) ABSMsg=0xd9; 625 | 626 | 627 | 628 | 629 | 630 | //From ECU, MPG, MIL, overheat light, Cruise 631 | // ErrorState variable controls: 632 | //Check engine(binary 10), Cruise (1000), EML (10000) 633 | //Temp light Variable controls temp light. Hex 08 is on zero off 634 | 635 | 636 | //**************** set Error Lights & cruise light ****** 637 | // hex 08 = Overheat light on 638 | // // hex 08 = Overheat light on 639 | //Set check engine. Binary 0010 (hex 02) 640 | // No error light (zero) 641 | 642 | 643 | // int z = 0x60; // + y; higher value lower MPG 644 | 645 | 646 | //Can bus data packet values to be sent 647 | outFrame.id = 0x545; // Set our transmission address ID 648 | outFrame.length = 8; // Data payload 8 bytes 649 | outFrame.extended = 0; // Extended addresses - 0=11-bit 1=29bit 650 | outFrame.rtr=1; //No request 651 | outFrame.data.bytes[0]=0x00; //2=check ewwngine on , 0=check engine off 652 | outFrame.data.bytes[1]=0x00; //LSB fuel comp 653 | outFrame.data.bytes[2]=0x00; //MSB fuel comp 654 | outFrame.data.bytes[3]=0x00; // hex 08 = Overheat light on 655 | outFrame.data.bytes[4]=0x7E; 656 | outFrame.data.bytes[5]=0x10; 657 | outFrame.data.bytes[6]=0x00; 658 | outFrame.data.bytes[7]=0x18; 659 | Can1.sendFrame(outFrame); 660 | 661 | 662 | 663 | } 664 | } 665 | 666 | } 667 | 668 | 669 | 670 | 671 | void Msgs100ms() ////100ms messages here 672 | { 673 | if(timer_Frames100.check()) 674 | { 675 | if(can_status) 676 | { 677 | 678 | // digitalWrite(led, !digitalRead(led)); //toggle led everytime we fire the 100ms messages. 679 | 680 | outFrame.id = 0x50b; // Set our transmission address ID 681 | outFrame.length = 7; // Data payload 8 bytes 682 | outFrame.extended = 0; // Extended addresses - 0=11-bit 1=29bit 683 | outFrame.rtr=1; //No request 684 | // Statistics from 2016 capture: 685 | // 10 00000000000000 686 | // 21 000002c0000000 687 | // 122 000000c0000000 688 | // 513 000006c0000000 689 | 690 | // Let's just send the most common one all the time 691 | // FIXME: This is a very sloppy implementation 692 | // hex_to_data(outFrame.data.bytes, "00,00,06,c0,00,00,00"); 693 | outFrame.data.bytes[0]=0x00; 694 | outFrame.data.bytes[1]=0x00; 695 | outFrame.data.bytes[2]=0x06; 696 | outFrame.data.bytes[3]=0xc0; 697 | outFrame.data.bytes[4]=0x00; 698 | outFrame.data.bytes[5]=0x00; 699 | outFrame.data.bytes[6]=0x00; 700 | 701 | /*CONSOLE.print(F("Sending ")); 702 | print_fancy_inFrame(inFrame); 703 | CONSOLE.println();*/ 704 | Can0.sendFrame(outFrame); 705 | } 706 | } 707 | } 708 | 709 | 710 | 711 | void readPedals() 712 | { 713 | ThrotVal = analogRead(Throttle1); //read throttle channel 1 directly 714 | ThrotVal = constrain(ThrotVal, 145, 620); 715 | ThrotVal = map(ThrotVal, 145, 620, 0, MaxTrq); //will need to work here for cal. 716 | if(ThrotVal<0) ThrotVal=0; //no negative numbers for now. 717 | if(digitalRead(Brake)) ThrotVal=0; //if brake is pressed we zero the throttle value. 718 | //Serial.println(ThrotVal); //print for calibration. 719 | } 720 | 721 | 722 | 723 | void SendTorqueRequest() 724 | { 725 | 726 | final_torque_request = ThrotVal; //send mapped throttle signal to inverter. 727 | 728 | } 729 | 730 | 731 | 732 | void ProcessRPM() //here we convert motor rpm values received from the leaf inverter into BMW E46 RPM can message. 733 | { 734 | outRPM = (inverter_status.speed)*6.4; 735 | if(outRPM<4800) outRPM=4800; //set lowest rpm to 750 displayed on tach to keep car alive thinking engine is running. 736 | if(outRPM>44800) outRPM=44800; //DONT READ MORE THAN 7000RPM! 737 | //Serial.println(outRPM); 738 | } 739 | 740 | 741 | 742 | 743 | static int8_t fahrenheit_to_celsius(uint16_t fahrenheit) 744 | { 745 | int16_t result = ((int16_t)fahrenheit - 32) * 5 / 9; 746 | if(result < -128) 747 | return -128; 748 | if(result > 127) 749 | return 127; 750 | return result; 751 | } 752 | 753 | void CheckCAN() 754 | { 755 | 756 | /////////////////////////////////////////////////////////////////////////////////////////////////////////// 757 | //read incomming data from inverter////////////////// 758 | ////////////////////////////////////////////////////// 759 | if(Can0.available()) 760 | { 761 | Can0.read(inFrame); 762 | //Serial.println(inFrame.id, HEX); 763 | 764 | 765 | if(inFrame.id == 0x1da && inFrame.length == 8){ 766 | // last_received_from_inverter_timestamp = millis(); 767 | 768 | inverter_status.voltage = ((uint16_t)inFrame.data.bytes[0] << 2) | 769 | (inFrame.data.bytes[1] >> 6); 770 | 771 | int16_t parsed_speed = ((uint16_t)inFrame.data.bytes[4] << 8) | 772 | (uint16_t)inFrame.data.bytes[5]; 773 | inverter_status.speed = (parsed_speed == 0x7fff ? 0 : parsed_speed); 774 | 775 | inverter_status.error_state = (inFrame.data.bytes[6] & 0xb0) != 0x00; 776 | } 777 | 778 | if(inFrame.id == 0x55a && inFrame.length == 8){ 779 | // last_received_from_inverter_timestamp = millis(); 780 | 781 | inverter_status.inverter_temperature = fahrenheit_to_celsius(inFrame.data.bytes[2]); 782 | inverter_status.motor_temperature = fahrenheit_to_celsius(inFrame.data.bytes[1]); 783 | //Serial.println(inverter_status.inverter_temperature); 784 | } 785 | 786 | } 787 | 788 | //////////////////////////////////////////////////////////////////////////////////////////////// 789 | 790 | 791 | } 792 | 793 | static void nissan_crc(uint8_t *data, uint8_t polynomial) 794 | { 795 | // We want to process 8 bytes with the 8th byte being zero 796 | data[7] = 0; 797 | uint8_t crc = 0; 798 | for(int b=0; b<8; b++) 799 | { 800 | for(int i=7; i>=0; i--) 801 | { 802 | uint8_t bit = ((data[b] &(1 << i)) > 0) ? 1 : 0; 803 | if(crc >= 0x80) 804 | crc = (byte)(((crc << 1) + bit) ^ polynomial); 805 | else 806 | crc = (byte)((crc << 1) + bit); 807 | } 808 | } 809 | data[7] = crc; 810 | } 811 | -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | GNU GENERAL PUBLIC LICENSE 2 | Version 3, 29 June 2007 3 | 4 | Copyright (C) 2007 Free Software Foundation, Inc. 5 | Everyone is permitted to copy and distribute verbatim copies 6 | of this license document, but changing it is not allowed. 7 | 8 | Preamble 9 | 10 | The GNU General Public License is a free, copyleft license for 11 | software and other kinds of works. 12 | 13 | The licenses for most software and other practical works are designed 14 | to take away your freedom to share and change the works. By contrast, 15 | the GNU General Public License is intended to guarantee your freedom to 16 | share and change all versions of a program--to make sure it remains free 17 | software for all its users. We, the Free Software Foundation, use the 18 | GNU General Public License for most of our software; it applies also to 19 | any other work released this way by its authors. You can apply it to 20 | your programs, too. 21 | 22 | When we speak of free software, we are referring to freedom, not 23 | price. Our General Public Licenses are designed to make sure that you 24 | have the freedom to distribute copies of free software (and charge for 25 | them if you wish), that you receive source code or can get it if you 26 | want it, that you can change the software or use pieces of it in new 27 | free programs, and that you know you can do these things. 28 | 29 | To protect your rights, we need to prevent others from denying you 30 | these rights or asking you to surrender the rights. Therefore, you have 31 | certain responsibilities if you distribute copies of the software, or if 32 | you modify it: responsibilities to respect the freedom of others. 33 | 34 | For example, if you distribute copies of such a program, whether 35 | gratis or for a fee, you must pass on to the recipients the same 36 | freedoms that you received. You must make sure that they, too, receive 37 | or can get the source code. And you must show them these terms so they 38 | know their rights. 39 | 40 | Developers that use the GNU GPL protect your rights with two steps: 41 | (1) assert copyright on the software, and (2) offer you this License 42 | giving you legal permission to copy, distribute and/or modify it. 43 | 44 | For the developers' and authors' protection, the GPL clearly explains 45 | that there is no warranty for this free software. For both users' and 46 | authors' sake, the GPL requires that modified versions be marked as 47 | changed, so that their problems will not be attributed erroneously to 48 | authors of previous versions. 49 | 50 | Some devices are designed to deny users access to install or run 51 | modified versions of the software inside them, although the manufacturer 52 | can do so. This is fundamentally incompatible with the aim of 53 | protecting users' freedom to change the software. The systematic 54 | pattern of such abuse occurs in the area of products for individuals to 55 | use, which is precisely where it is most unacceptable. Therefore, we 56 | have designed this version of the GPL to prohibit the practice for those 57 | products. If such problems arise substantially in other domains, we 58 | stand ready to extend this provision to those domains in future versions 59 | of the GPL, as needed to protect the freedom of users. 60 | 61 | Finally, every program is threatened constantly by software patents. 62 | States should not allow patents to restrict development and use of 63 | software on general-purpose computers, but in those that do, we wish to 64 | avoid the special danger that patents applied to a free program could 65 | make it effectively proprietary. To prevent this, the GPL assures that 66 | patents cannot be used to render the program non-free. 67 | 68 | The precise terms and conditions for copying, distribution and 69 | modification follow. 70 | 71 | TERMS AND CONDITIONS 72 | 73 | 0. Definitions. 74 | 75 | "This License" refers to version 3 of the GNU General Public License. 76 | 77 | "Copyright" also means copyright-like laws that apply to other kinds of 78 | works, such as semiconductor masks. 79 | 80 | "The Program" refers to any copyrightable work licensed under this 81 | License. Each licensee is addressed as "you". "Licensees" and 82 | "recipients" may be individuals or organizations. 83 | 84 | To "modify" a work means to copy from or adapt all or part of the work 85 | in a fashion requiring copyright permission, other than the making of an 86 | exact copy. The resulting work is called a "modified version" of the 87 | earlier work or a work "based on" the earlier work. 88 | 89 | A "covered work" means either the unmodified Program or a work based 90 | on the Program. 91 | 92 | To "propagate" a work means to do anything with it that, without 93 | permission, would make you directly or secondarily liable for 94 | infringement under applicable copyright law, except executing it on a 95 | computer or modifying a private copy. Propagation includes copying, 96 | distribution (with or without modification), making available to the 97 | public, and in some countries other activities as well. 98 | 99 | To "convey" a work means any kind of propagation that enables other 100 | parties to make or receive copies. Mere interaction with a user through 101 | a computer network, with no transfer of a copy, is not conveying. 102 | 103 | An interactive user interface displays "Appropriate Legal Notices" 104 | to the extent that it includes a convenient and prominently visible 105 | feature that (1) displays an appropriate copyright notice, and (2) 106 | tells the user that there is no warranty for the work (except to the 107 | extent that warranties are provided), that licensees may convey the 108 | work under this License, and how to view a copy of this License. If 109 | the interface presents a list of user commands or options, such as a 110 | menu, a prominent item in the list meets this criterion. 111 | 112 | 1. Source Code. 113 | 114 | The "source code" for a work means the preferred form of the work 115 | for making modifications to it. "Object code" means any non-source 116 | form of a work. 117 | 118 | A "Standard Interface" means an interface that either is an official 119 | standard defined by a recognized standards body, or, in the case of 120 | interfaces specified for a particular programming language, one that 121 | is widely used among developers working in that language. 122 | 123 | The "System Libraries" of an executable work include anything, other 124 | than the work as a whole, that (a) is included in the normal form of 125 | packaging a Major Component, but which is not part of that Major 126 | Component, and (b) serves only to enable use of the work with that 127 | Major Component, or to implement a Standard Interface for which an 128 | implementation is available to the public in source code form. A 129 | "Major Component", in this context, means a major essential component 130 | (kernel, window system, and so on) of the specific operating system 131 | (if any) on which the executable work runs, or a compiler used to 132 | produce the work, or an object code interpreter used to run it. 133 | 134 | The "Corresponding Source" for a work in object code form means all 135 | the source code needed to generate, install, and (for an executable 136 | work) run the object code and to modify the work, including scripts to 137 | control those activities. However, it does not include the work's 138 | System Libraries, or general-purpose tools or generally available free 139 | programs which are used unmodified in performing those activities but 140 | which are not part of the work. For example, Corresponding Source 141 | includes interface definition files associated with source files for 142 | the work, and the source code for shared libraries and dynamically 143 | linked subprograms that the work is specifically designed to require, 144 | such as by intimate data communication or control flow between those 145 | subprograms and other parts of the work. 146 | 147 | The Corresponding Source need not include anything that users 148 | can regenerate automatically from other parts of the Corresponding 149 | Source. 150 | 151 | The Corresponding Source for a work in source code form is that 152 | same work. 153 | 154 | 2. Basic Permissions. 155 | 156 | All rights granted under this License are granted for the term of 157 | copyright on the Program, and are irrevocable provided the stated 158 | conditions are met. This License explicitly affirms your unlimited 159 | permission to run the unmodified Program. The output from running a 160 | covered work is covered by this License only if the output, given its 161 | content, constitutes a covered work. This License acknowledges your 162 | rights of fair use or other equivalent, as provided by copyright law. 163 | 164 | You may make, run and propagate covered works that you do not 165 | convey, without conditions so long as your license otherwise remains 166 | in force. You may convey covered works to others for the sole purpose 167 | of having them make modifications exclusively for you, or provide you 168 | with facilities for running those works, provided that you comply with 169 | the terms of this License in conveying all material for which you do 170 | not control copyright. Those thus making or running the covered works 171 | for you must do so exclusively on your behalf, under your direction 172 | and control, on terms that prohibit them from making any copies of 173 | your copyrighted material outside their relationship with you. 174 | 175 | Conveying under any other circumstances is permitted solely under 176 | the conditions stated below. Sublicensing is not allowed; section 10 177 | makes it unnecessary. 178 | 179 | 3. Protecting Users' Legal Rights From Anti-Circumvention Law. 180 | 181 | No covered work shall be deemed part of an effective technological 182 | measure under any applicable law fulfilling obligations under article 183 | 11 of the WIPO copyright treaty adopted on 20 December 1996, or 184 | similar laws prohibiting or restricting circumvention of such 185 | measures. 186 | 187 | When you convey a covered work, you waive any legal power to forbid 188 | circumvention of technological measures to the extent such circumvention 189 | is effected by exercising rights under this License with respect to 190 | the covered work, and you disclaim any intention to limit operation or 191 | modification of the work as a means of enforcing, against the work's 192 | users, your or third parties' legal rights to forbid circumvention of 193 | technological measures. 194 | 195 | 4. Conveying Verbatim Copies. 196 | 197 | You may convey verbatim copies of the Program's source code as you 198 | receive it, in any medium, provided that you conspicuously and 199 | appropriately publish on each copy an appropriate copyright notice; 200 | keep intact all notices stating that this License and any 201 | non-permissive terms added in accord with section 7 apply to the code; 202 | keep intact all notices of the absence of any warranty; and give all 203 | recipients a copy of this License along with the Program. 204 | 205 | You may charge any price or no price for each copy that you convey, 206 | and you may offer support or warranty protection for a fee. 207 | 208 | 5. Conveying Modified Source Versions. 209 | 210 | You may convey a work based on the Program, or the modifications to 211 | produce it from the Program, in the form of source code under the 212 | terms of section 4, provided that you also meet all of these conditions: 213 | 214 | a) The work must carry prominent notices stating that you modified 215 | it, and giving a relevant date. 216 | 217 | b) The work must carry prominent notices stating that it is 218 | released under this License and any conditions added under section 219 | 7. This requirement modifies the requirement in section 4 to 220 | "keep intact all notices". 221 | 222 | c) You must license the entire work, as a whole, under this 223 | License to anyone who comes into possession of a copy. This 224 | License will therefore apply, along with any applicable section 7 225 | additional terms, to the whole of the work, and all its parts, 226 | regardless of how they are packaged. This License gives no 227 | permission to license the work in any other way, but it does not 228 | invalidate such permission if you have separately received it. 229 | 230 | d) If the work has interactive user interfaces, each must display 231 | Appropriate Legal Notices; however, if the Program has interactive 232 | interfaces that do not display Appropriate Legal Notices, your 233 | work need not make them do so. 234 | 235 | A compilation of a covered work with other separate and independent 236 | works, which are not by their nature extensions of the covered work, 237 | and which are not combined with it such as to form a larger program, 238 | in or on a volume of a storage or distribution medium, is called an 239 | "aggregate" if the compilation and its resulting copyright are not 240 | used to limit the access or legal rights of the compilation's users 241 | beyond what the individual works permit. Inclusion of a covered work 242 | in an aggregate does not cause this License to apply to the other 243 | parts of the aggregate. 244 | 245 | 6. Conveying Non-Source Forms. 246 | 247 | You may convey a covered work in object code form under the terms 248 | of sections 4 and 5, provided that you also convey the 249 | machine-readable Corresponding Source under the terms of this License, 250 | in one of these ways: 251 | 252 | a) Convey the object code in, or embodied in, a physical product 253 | (including a physical distribution medium), accompanied by the 254 | Corresponding Source fixed on a durable physical medium 255 | customarily used for software interchange. 256 | 257 | b) Convey the object code in, or embodied in, a physical product 258 | (including a physical distribution medium), accompanied by a 259 | written offer, valid for at least three years and valid for as 260 | long as you offer spare parts or customer support for that product 261 | model, to give anyone who possesses the object code either (1) a 262 | copy of the Corresponding Source for all the software in the 263 | product that is covered by this License, on a durable physical 264 | medium customarily used for software interchange, for a price no 265 | more than your reasonable cost of physically performing this 266 | conveying of source, or (2) access to copy the 267 | Corresponding Source from a network server at no charge. 268 | 269 | c) Convey individual copies of the object code with a copy of the 270 | written offer to provide the Corresponding Source. This 271 | alternative is allowed only occasionally and noncommercially, and 272 | only if you received the object code with such an offer, in accord 273 | with subsection 6b. 274 | 275 | d) Convey the object code by offering access from a designated 276 | place (gratis or for a charge), and offer equivalent access to the 277 | Corresponding Source in the same way through the same place at no 278 | further charge. You need not require recipients to copy the 279 | Corresponding Source along with the object code. If the place to 280 | copy the object code is a network server, the Corresponding Source 281 | may be on a different server (operated by you or a third party) 282 | that supports equivalent copying facilities, provided you maintain 283 | clear directions next to the object code saying where to find the 284 | Corresponding Source. Regardless of what server hosts the 285 | Corresponding Source, you remain obligated to ensure that it is 286 | available for as long as needed to satisfy these requirements. 287 | 288 | e) Convey the object code using peer-to-peer transmission, provided 289 | you inform other peers where the object code and Corresponding 290 | Source of the work are being offered to the general public at no 291 | charge under subsection 6d. 292 | 293 | A separable portion of the object code, whose source code is excluded 294 | from the Corresponding Source as a System Library, need not be 295 | included in conveying the object code work. 296 | 297 | A "User Product" is either (1) a "consumer product", which means any 298 | tangible personal property which is normally used for personal, family, 299 | or household purposes, or (2) anything designed or sold for incorporation 300 | into a dwelling. In determining whether a product is a consumer product, 301 | doubtful cases shall be resolved in favor of coverage. For a particular 302 | product received by a particular user, "normally used" refers to a 303 | typical or common use of that class of product, regardless of the status 304 | of the particular user or of the way in which the particular user 305 | actually uses, or expects or is expected to use, the product. A product 306 | is a consumer product regardless of whether the product has substantial 307 | commercial, industrial or non-consumer uses, unless such uses represent 308 | the only significant mode of use of the product. 309 | 310 | "Installation Information" for a User Product means any methods, 311 | procedures, authorization keys, or other information required to install 312 | and execute modified versions of a covered work in that User Product from 313 | a modified version of its Corresponding Source. The information must 314 | suffice to ensure that the continued functioning of the modified object 315 | code is in no case prevented or interfered with solely because 316 | modification has been made. 317 | 318 | If you convey an object code work under this section in, or with, or 319 | specifically for use in, a User Product, and the conveying occurs as 320 | part of a transaction in which the right of possession and use of the 321 | User Product is transferred to the recipient in perpetuity or for a 322 | fixed term (regardless of how the transaction is characterized), the 323 | Corresponding Source conveyed under this section must be accompanied 324 | by the Installation Information. But this requirement does not apply 325 | if neither you nor any third party retains the ability to install 326 | modified object code on the User Product (for example, the work has 327 | been installed in ROM). 328 | 329 | The requirement to provide Installation Information does not include a 330 | requirement to continue to provide support service, warranty, or updates 331 | for a work that has been modified or installed by the recipient, or for 332 | the User Product in which it has been modified or installed. Access to a 333 | network may be denied when the modification itself materially and 334 | adversely affects the operation of the network or violates the rules and 335 | protocols for communication across the network. 336 | 337 | Corresponding Source conveyed, and Installation Information provided, 338 | in accord with this section must be in a format that is publicly 339 | documented (and with an implementation available to the public in 340 | source code form), and must require no special password or key for 341 | unpacking, reading or copying. 342 | 343 | 7. Additional Terms. 344 | 345 | "Additional permissions" are terms that supplement the terms of this 346 | License by making exceptions from one or more of its conditions. 347 | Additional permissions that are applicable to the entire Program shall 348 | be treated as though they were included in this License, to the extent 349 | that they are valid under applicable law. If additional permissions 350 | apply only to part of the Program, that part may be used separately 351 | under those permissions, but the entire Program remains governed by 352 | this License without regard to the additional permissions. 353 | 354 | When you convey a copy of a covered work, you may at your option 355 | remove any additional permissions from that copy, or from any part of 356 | it. (Additional permissions may be written to require their own 357 | removal in certain cases when you modify the work.) You may place 358 | additional permissions on material, added by you to a covered work, 359 | for which you have or can give appropriate copyright permission. 360 | 361 | Notwithstanding any other provision of this License, for material you 362 | add to a covered work, you may (if authorized by the copyright holders of 363 | that material) supplement the terms of this License with terms: 364 | 365 | a) Disclaiming warranty or limiting liability differently from the 366 | terms of sections 15 and 16 of this License; or 367 | 368 | b) Requiring preservation of specified reasonable legal notices or 369 | author attributions in that material or in the Appropriate Legal 370 | Notices displayed by works containing it; or 371 | 372 | c) Prohibiting misrepresentation of the origin of that material, or 373 | requiring that modified versions of such material be marked in 374 | reasonable ways as different from the original version; or 375 | 376 | d) Limiting the use for publicity purposes of names of licensors or 377 | authors of the material; or 378 | 379 | e) Declining to grant rights under trademark law for use of some 380 | trade names, trademarks, or service marks; or 381 | 382 | f) Requiring indemnification of licensors and authors of that 383 | material by anyone who conveys the material (or modified versions of 384 | it) with contractual assumptions of liability to the recipient, for 385 | any liability that these contractual assumptions directly impose on 386 | those licensors and authors. 387 | 388 | All other non-permissive additional terms are considered "further 389 | restrictions" within the meaning of section 10. If the Program as you 390 | received it, or any part of it, contains a notice stating that it is 391 | governed by this License along with a term that is a further 392 | restriction, you may remove that term. If a license document contains 393 | a further restriction but permits relicensing or conveying under this 394 | License, you may add to a covered work material governed by the terms 395 | of that license document, provided that the further restriction does 396 | not survive such relicensing or conveying. 397 | 398 | If you add terms to a covered work in accord with this section, you 399 | must place, in the relevant source files, a statement of the 400 | additional terms that apply to those files, or a notice indicating 401 | where to find the applicable terms. 402 | 403 | Additional terms, permissive or non-permissive, may be stated in the 404 | form of a separately written license, or stated as exceptions; 405 | the above requirements apply either way. 406 | 407 | 8. Termination. 408 | 409 | You may not propagate or modify a covered work except as expressly 410 | provided under this License. Any attempt otherwise to propagate or 411 | modify it is void, and will automatically terminate your rights under 412 | this License (including any patent licenses granted under the third 413 | paragraph of section 11). 414 | 415 | However, if you cease all violation of this License, then your 416 | license from a particular copyright holder is reinstated (a) 417 | provisionally, unless and until the copyright holder explicitly and 418 | finally terminates your license, and (b) permanently, if the copyright 419 | holder fails to notify you of the violation by some reasonable means 420 | prior to 60 days after the cessation. 421 | 422 | Moreover, your license from a particular copyright holder is 423 | reinstated permanently if the copyright holder notifies you of the 424 | violation by some reasonable means, this is the first time you have 425 | received notice of violation of this License (for any work) from that 426 | copyright holder, and you cure the violation prior to 30 days after 427 | your receipt of the notice. 428 | 429 | Termination of your rights under this section does not terminate the 430 | licenses of parties who have received copies or rights from you under 431 | this License. If your rights have been terminated and not permanently 432 | reinstated, you do not qualify to receive new licenses for the same 433 | material under section 10. 434 | 435 | 9. Acceptance Not Required for Having Copies. 436 | 437 | You are not required to accept this License in order to receive or 438 | run a copy of the Program. Ancillary propagation of a covered work 439 | occurring solely as a consequence of using peer-to-peer transmission 440 | to receive a copy likewise does not require acceptance. However, 441 | nothing other than this License grants you permission to propagate or 442 | modify any covered work. These actions infringe copyright if you do 443 | not accept this License. Therefore, by modifying or propagating a 444 | covered work, you indicate your acceptance of this License to do so. 445 | 446 | 10. Automatic Licensing of Downstream Recipients. 447 | 448 | Each time you convey a covered work, the recipient automatically 449 | receives a license from the original licensors, to run, modify and 450 | propagate that work, subject to this License. You are not responsible 451 | for enforcing compliance by third parties with this License. 452 | 453 | An "entity transaction" is a transaction transferring control of an 454 | organization, or substantially all assets of one, or subdividing an 455 | organization, or merging organizations. If propagation of a covered 456 | work results from an entity transaction, each party to that 457 | transaction who receives a copy of the work also receives whatever 458 | licenses to the work the party's predecessor in interest had or could 459 | give under the previous paragraph, plus a right to possession of the 460 | Corresponding Source of the work from the predecessor in interest, if 461 | the predecessor has it or can get it with reasonable efforts. 462 | 463 | You may not impose any further restrictions on the exercise of the 464 | rights granted or affirmed under this License. For example, you may 465 | not impose a license fee, royalty, or other charge for exercise of 466 | rights granted under this License, and you may not initiate litigation 467 | (including a cross-claim or counterclaim in a lawsuit) alleging that 468 | any patent claim is infringed by making, using, selling, offering for 469 | sale, or importing the Program or any portion of it. 470 | 471 | 11. Patents. 472 | 473 | A "contributor" is a copyright holder who authorizes use under this 474 | License of the Program or a work on which the Program is based. The 475 | work thus licensed is called the contributor's "contributor version". 476 | 477 | A contributor's "essential patent claims" are all patent claims 478 | owned or controlled by the contributor, whether already acquired or 479 | hereafter acquired, that would be infringed by some manner, permitted 480 | by this License, of making, using, or selling its contributor version, 481 | but do not include claims that would be infringed only as a 482 | consequence of further modification of the contributor version. For 483 | purposes of this definition, "control" includes the right to grant 484 | patent sublicenses in a manner consistent with the requirements of 485 | this License. 486 | 487 | Each contributor grants you a non-exclusive, worldwide, royalty-free 488 | patent license under the contributor's essential patent claims, to 489 | make, use, sell, offer for sale, import and otherwise run, modify and 490 | propagate the contents of its contributor version. 491 | 492 | In the following three paragraphs, a "patent license" is any express 493 | agreement or commitment, however denominated, not to enforce a patent 494 | (such as an express permission to practice a patent or covenant not to 495 | sue for patent infringement). To "grant" such a patent license to a 496 | party means to make such an agreement or commitment not to enforce a 497 | patent against the party. 498 | 499 | If you convey a covered work, knowingly relying on a patent license, 500 | and the Corresponding Source of the work is not available for anyone 501 | to copy, free of charge and under the terms of this License, through a 502 | publicly available network server or other readily accessible means, 503 | then you must either (1) cause the Corresponding Source to be so 504 | available, or (2) arrange to deprive yourself of the benefit of the 505 | patent license for this particular work, or (3) arrange, in a manner 506 | consistent with the requirements of this License, to extend the patent 507 | license to downstream recipients. "Knowingly relying" means you have 508 | actual knowledge that, but for the patent license, your conveying the 509 | covered work in a country, or your recipient's use of the covered work 510 | in a country, would infringe one or more identifiable patents in that 511 | country that you have reason to believe are valid. 512 | 513 | If, pursuant to or in connection with a single transaction or 514 | arrangement, you convey, or propagate by procuring conveyance of, a 515 | covered work, and grant a patent license to some of the parties 516 | receiving the covered work authorizing them to use, propagate, modify 517 | or convey a specific copy of the covered work, then the patent license 518 | you grant is automatically extended to all recipients of the covered 519 | work and works based on it. 520 | 521 | A patent license is "discriminatory" if it does not include within 522 | the scope of its coverage, prohibits the exercise of, or is 523 | conditioned on the non-exercise of one or more of the rights that are 524 | specifically granted under this License. You may not convey a covered 525 | work if you are a party to an arrangement with a third party that is 526 | in the business of distributing software, under which you make payment 527 | to the third party based on the extent of your activity of conveying 528 | the work, and under which the third party grants, to any of the 529 | parties who would receive the covered work from you, a discriminatory 530 | patent license (a) in connection with copies of the covered work 531 | conveyed by you (or copies made from those copies), or (b) primarily 532 | for and in connection with specific products or compilations that 533 | contain the covered work, unless you entered into that arrangement, 534 | or that patent license was granted, prior to 28 March 2007. 535 | 536 | Nothing in this License shall be construed as excluding or limiting 537 | any implied license or other defenses to infringement that may 538 | otherwise be available to you under applicable patent law. 539 | 540 | 12. No Surrender of Others' Freedom. 541 | 542 | If conditions are imposed on you (whether by court order, agreement or 543 | otherwise) that contradict the conditions of this License, they do not 544 | excuse you from the conditions of this License. If you cannot convey a 545 | covered work so as to satisfy simultaneously your obligations under this 546 | License and any other pertinent obligations, then as a consequence you may 547 | not convey it at all. For example, if you agree to terms that obligate you 548 | to collect a royalty for further conveying from those to whom you convey 549 | the Program, the only way you could satisfy both those terms and this 550 | License would be to refrain entirely from conveying the Program. 551 | 552 | 13. Use with the GNU Affero General Public License. 553 | 554 | Notwithstanding any other provision of this License, you have 555 | permission to link or combine any covered work with a work licensed 556 | under version 3 of the GNU Affero General Public License into a single 557 | combined work, and to convey the resulting work. The terms of this 558 | License will continue to apply to the part which is the covered work, 559 | but the special requirements of the GNU Affero General Public License, 560 | section 13, concerning interaction through a network will apply to the 561 | combination as such. 562 | 563 | 14. Revised Versions of this License. 564 | 565 | The Free Software Foundation may publish revised and/or new versions of 566 | the GNU General Public License from time to time. Such new versions will 567 | be similar in spirit to the present version, but may differ in detail to 568 | address new problems or concerns. 569 | 570 | Each version is given a distinguishing version number. If the 571 | Program specifies that a certain numbered version of the GNU General 572 | Public License "or any later version" applies to it, you have the 573 | option of following the terms and conditions either of that numbered 574 | version or of any later version published by the Free Software 575 | Foundation. If the Program does not specify a version number of the 576 | GNU General Public License, you may choose any version ever published 577 | by the Free Software Foundation. 578 | 579 | If the Program specifies that a proxy can decide which future 580 | versions of the GNU General Public License can be used, that proxy's 581 | public statement of acceptance of a version permanently authorizes you 582 | to choose that version for the Program. 583 | 584 | Later license versions may give you additional or different 585 | permissions. However, no additional obligations are imposed on any 586 | author or copyright holder as a result of your choosing to follow a 587 | later version. 588 | 589 | 15. Disclaimer of Warranty. 590 | 591 | THERE IS NO WARRANTY FOR THE PROGRAM, TO THE EXTENT PERMITTED BY 592 | APPLICABLE LAW. EXCEPT WHEN OTHERWISE STATED IN WRITING THE COPYRIGHT 593 | HOLDERS AND/OR OTHER PARTIES PROVIDE THE PROGRAM "AS IS" WITHOUT WARRANTY 594 | OF ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING, BUT NOT LIMITED TO, 595 | THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR 596 | PURPOSE. THE ENTIRE RISK AS TO THE QUALITY AND PERFORMANCE OF THE PROGRAM 597 | IS WITH YOU. SHOULD THE PROGRAM PROVE DEFECTIVE, YOU ASSUME THE COST OF 598 | ALL NECESSARY SERVICING, REPAIR OR CORRECTION. 599 | 600 | 16. Limitation of Liability. 601 | 602 | IN NO EVENT UNLESS REQUIRED BY APPLICABLE LAW OR AGREED TO IN WRITING 603 | WILL ANY COPYRIGHT HOLDER, OR ANY OTHER PARTY WHO MODIFIES AND/OR CONVEYS 604 | THE PROGRAM AS PERMITTED ABOVE, BE LIABLE TO YOU FOR DAMAGES, INCLUDING ANY 605 | GENERAL, SPECIAL, INCIDENTAL OR CONSEQUENTIAL DAMAGES ARISING OUT OF THE 606 | USE OR INABILITY TO USE THE PROGRAM (INCLUDING BUT NOT LIMITED TO LOSS OF 607 | DATA OR DATA BEING RENDERED INACCURATE OR LOSSES SUSTAINED BY YOU OR THIRD 608 | PARTIES OR A FAILURE OF THE PROGRAM TO OPERATE WITH ANY OTHER PROGRAMS), 609 | EVEN IF SUCH HOLDER OR OTHER PARTY HAS BEEN ADVISED OF THE POSSIBILITY OF 610 | SUCH DAMAGES. 611 | 612 | 17. Interpretation of Sections 15 and 16. 613 | 614 | If the disclaimer of warranty and limitation of liability provided 615 | above cannot be given local legal effect according to their terms, 616 | reviewing courts shall apply local law that most closely approximates 617 | an absolute waiver of all civil liability in connection with the 618 | Program, unless a warranty or assumption of liability accompanies a 619 | copy of the Program in return for a fee. 620 | 621 | END OF TERMS AND CONDITIONS 622 | 623 | How to Apply These Terms to Your New Programs 624 | 625 | If you develop a new program, and you want it to be of the greatest 626 | possible use to the public, the best way to achieve this is to make it 627 | free software which everyone can redistribute and change under these terms. 628 | 629 | To do so, attach the following notices to the program. It is safest 630 | to attach them to the start of each source file to most effectively 631 | state the exclusion of warranty; and each file should have at least 632 | the "copyright" line and a pointer to where the full notice is found. 633 | 634 | 635 | Copyright (C) 636 | 637 | This program is free software: you can redistribute it and/or modify 638 | it under the terms of the GNU General Public License as published by 639 | the Free Software Foundation, either version 3 of the License, or 640 | (at your option) any later version. 641 | 642 | This program is distributed in the hope that it will be useful, 643 | but WITHOUT ANY WARRANTY; without even the implied warranty of 644 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 645 | GNU General Public License for more details. 646 | 647 | You should have received a copy of the GNU General Public License 648 | along with this program. If not, see . 649 | 650 | Also add information on how to contact you by electronic and paper mail. 651 | 652 | If the program does terminal interaction, make it output a short 653 | notice like this when it starts in an interactive mode: 654 | 655 | Copyright (C) 656 | This program comes with ABSOLUTELY NO WARRANTY; for details type `show w'. 657 | This is free software, and you are welcome to redistribute it 658 | under certain conditions; type `show c' for details. 659 | 660 | The hypothetical commands `show w' and `show c' should show the appropriate 661 | parts of the General Public License. Of course, your program's commands 662 | might be different; for a GUI interface, you would use an "about box". 663 | 664 | You should also get your employer (if you work as a programmer) or school, 665 | if any, to sign a "copyright disclaimer" for the program, if necessary. 666 | For more information on this, and how to apply and follow the GNU GPL, see 667 | . 668 | 669 | The GNU General Public License does not permit incorporating your program 670 | into proprietary programs. If your program is a subroutine library, you 671 | may consider it more useful to permit linking proprietary applications with 672 | the library. If this is what you want to do, use the GNU Lesser General 673 | Public License instead of this License. But first, please read 674 | . 675 | -------------------------------------------------------------------------------- /WiFi/Data/highcharts-more.js: -------------------------------------------------------------------------------- 1 | /* 2 | Highcharts JS v8.0.0 (2019-12-10) 3 | 4 | (c) 2009-2018 Torstein Honsi 5 | 6 | License: www.highcharts.com/license 7 | */ 8 | (function(t){"object"===typeof module&&module.exports?(t["default"]=t,module.exports=t):"function"===typeof define&&define.amd?define("highcharts/highcharts-more",["highcharts"],function(A){t(A);t.Highcharts=A;return t}):t("undefined"!==typeof Highcharts?Highcharts:void 0)})(function(t){function A(b,a,r,g){b.hasOwnProperty(a)||(b[a]=g.apply(null,r))}t=t?t._modules:{};A(t,"parts-more/Pane.js",[t["parts/Globals.js"],t["parts/Utilities.js"]],function(b,a){function r(a,e){this.init(a,e)}var g=a.extend, 9 | m=a.splat,k=b.CenteredSeriesMixin,w=b.merge;b.Chart.prototype.collectionsWithUpdate.push("pane");g(r.prototype,{coll:"pane",init:function(a,e){this.chart=e;this.background=[];e.pane.push(this);this.setOptions(a)},setOptions:function(a){this.options=w(this.defaultOptions,this.chart.angular?{background:{}}:void 0,a)},render:function(){var a=this.options,e=this.options.background,l=this.chart.renderer;this.group||(this.group=l.g("pane-group").attr({zIndex:a.zIndex||0}).add());this.updateCenter();if(e)for(e= 10 | m(e),a=Math.max(e.length,this.background.length||0),l=0;lc?0:c,this.center[2]/2)-this.offset)},postTranslate:function(c,f){var q=this.chart,p=this.center;c=this.startAngleRad+c;return{x:q.plotLeft+p[0]+Math.cos(c)*f,y:q.plotTop+p[1]+Math.sin(c)*f}},getPlotBandPath:function(c,f,q){var p=this.center, 18 | d=this.startAngleRad,h=p[2]/2,v=[k(q.outerRadius,"100%"),q.innerRadius,k(q.thickness,10)],a=Math.min(this.offset,0),n=/%$/;var e=this.isCircular;if("polygon"===this.options.gridLineInterpolation)v=this.getPlotLinePath({value:c}).concat(this.getPlotLinePath({value:f,reverse:!0}));else{c=Math.max(c,this.min);f=Math.min(f,this.max);e||(v[0]=this.translate(c),v[1]=this.translate(f));v=v.map(function(f){n.test(f)&&(f=w(f,10)*h/100);return f});if("circle"!==q.shape&&e)c=d+this.translate(c),f=d+this.translate(f); 19 | else{c=-Math.PI/2;f=1.5*Math.PI;var g=!0}v[0]-=a;v[2]-=a;v=this.chart.renderer.symbols.arc(this.left+p[0],this.top+p[1],v[0],v[0],{start:Math.min(c,f),end:Math.max(c,f),innerR:k(v[1],v[0]-v[2]),open:g});e&&(e=(f+c)/2,a=this.left+p[0]+p[2]/2*Math.cos(e),v.xBounds=e>-Math.PI/2&&e-Math.PI&&0>e||e>Math.PI?-10:10)}return v},getCrosshairPosition:function(c,f,q){var p=c.value;if(this.isCircular){if(g(p))c.point&& 20 | (d=c.point.shapeArgs||{},d.start&&(p=this.translate(c.point.rectPlotY,!0)));else{var d=c.chartX||0;var a=c.chartY||0;p=this.translate(Math.atan2(a-q,d-f)-this.startAngleRad,!0)}c=this.getPosition(p);d=c.x;a=c.y}else g(p)||(d=c.chartX,a=c.chartY),g(d)&&g(a)&&(p=this.translate(Math.min(Math.sqrt(Math.pow(d-f,2)+Math.pow(a-q,2)),this.len),!0));return[p,d||0,a||0]},getPlotLinePath:function(c){var f=this,q=f.center,p=f.chart,d=p.inverted,a=c.value,e=c.reverse,h=f.getPosition(a),n=f.pane.options.background? 21 | f.pane.options.background[0]||f.pane.options.background:{},g=n.innerRadius||"0%",l=n.outerRadius||"100%";n=q[0]+p.plotLeft;q=q[1]+p.plotTop;var b=h.x;h=h.y;var u,m;c.isCrosshair&&(h=this.getCrosshairPosition(c,n,q),a=h[0],b=h[1],h=h[2]);if(f.isCircular){e="string"===typeof g?z(g,1):g/Math.sqrt(Math.pow(b-n,2)+Math.pow(h-q,2));c="string"===typeof l?z(l,1):l/Math.sqrt(Math.pow(b-n,2)+Math.pow(h-q,2));var r=["M",n+e*(b-n),q-e*(q-h),"L",b-(1-c)*(b-n),h+(1-c)*(q-h)]}else a=f.translate(a),!c.isCrosshair&& 22 | (0>a||a>f.height)&&d&&(a=0),"circle"===f.options.gridLineInterpolation?r=f.getLinePath(0,a):(p[d?"yAxis":"xAxis"].forEach(function(c){c.pane===f.pane&&(u=c)}),r=[],n=u.tickPositions,u.autoConnect&&(n=n.concat([n[0]])),e&&(n=[].concat(n).reverse()),n.forEach(function(f,c){m=u.getPosition(f,a);r.push(c?"L":"M",m.x,m.y)}));return r},getTitlePosition:function(){var c=this.center,f=this.chart,q=this.options.title;return{x:f.plotLeft+c[0]+(q.x||0),y:f.plotTop+c[1]-{high:.5,middle:.25,low:0}[q.align]*c[2]+ 23 | (q.y||0)}},createLabelCollector:function(){var c=this;return function(){if(c.isRadial&&c.tickPositions&&!0!==c.options.labels.allowOverlap)return c.tickPositions.map(function(f){return c.ticks[f]&&c.ticks[f].label}).filter(function(f){return!!f})}}};e(l,"init",function(c){var f=this.chart,q=f.inverted,d=f.angular,a=f.polar,h=this.isXAxis,e=this.coll,g=d&&h,l,b=f.options;c=c.userOptions.pane||0;c=this.pane=f.pane&&f.pane[c];if("colorAxis"===e)this.isRadial=!1;else{if(d){if(m(this,g?n:p),l=!h)this.defaultPolarOptions= 24 | this.defaultRadialGaugeOptions}else a&&(m(this,p),this.defaultPolarOptions=(l=this.horiz)?this.defaultCircularOptions:u("xAxis"===e?this.defaultOptions:this.defaultYAxisOptions,this.defaultRadialOptions),q&&"yAxis"===e&&(this.defaultPolarOptions.stackLabels=this.defaultYAxisOptions.stackLabels));d||a?(this.isRadial=!0,b.chart.zoomType=null,this.labelCollector||(this.labelCollector=this.createLabelCollector()),this.labelCollector&&f.labelCollectors.push(this.labelCollector)):this.isRadial=!1;c&&l&& 25 | (c.axis=this);this.isCircular=l}});e(l,"afterInit",function(){var c=this.chart,f=this.options,q=this.pane,p=q&&q.options;c.angular&&this.isXAxis||!q||!c.angular&&!c.polar||(this.angleRad=(f.angle||0)*Math.PI/180,this.startAngleRad=(p.startAngle-90)*Math.PI/180,this.endAngleRad=(k(p.endAngle,p.startAngle+360)-90)*Math.PI/180,this.offset=f.offset||0)});e(l,"autoLabelAlign",function(c){this.isRadial&&(c.align=void 0,c.preventDefault())});e(l,"destroy",function(){if(this.chart&&this.chart.labelCollectors){var c= 26 | this.chart.labelCollectors.indexOf(this.labelCollector);0<=c&&this.chart.labelCollectors.splice(c,1)}});e(d,"afterGetPosition",function(c){this.axis.getPosition&&m(c.pos,this.axis.getPosition(this.pos))});e(d,"afterGetLabelPosition",function(c){var f=this.axis,q=this.label,p=q.getBBox(),d=f.options.labels,a=d.y,h=20,n=d.align,e=(f.translate(this.pos)+f.startAngleRad+Math.PI/2)/Math.PI*180%360,l=Math.round(e),g="end",b=0>l?l+360:l,u=b,m=0,r=0,B=null===d.y?.3*-p.height:0;if(f.isRadial){var x=f.getPosition(this.pos, 27 | f.center[2]/2+z(k(d.distance,-25),f.center[2]/2,-f.center[2]/2));"auto"===d.rotation?q.attr({rotation:e}):null===a&&(a=f.chart.renderer.fontMetrics(q.styles&&q.styles.fontSize).b-p.height/2);null===n&&(f.isCircular?(p.width>f.len*f.tickInterval/(f.max-f.min)&&(h=0),n=e>h&&e<180-h?"left":e>180+h&&e<360-h?"right":"center"):n="center",q.attr({align:n}));if("auto"===n&&2===f.tickPositions.length&&f.isCircular){90b?b=180-b:270=b&&(b=540-b);180=u&&(u=360-u);if(f.pane.options.startAngle=== 28 | l||f.pane.options.startAngle===l+360||f.pane.options.startAngle===l-360)g="start";n=-90<=l&&90>=l||-360<=l&&-270>=l||270<=l&&360>=l?"start"===g?"right":"left":"start"===g?"left":"right";70u&&(n="center");15>b||180<=b&&195>b?m=.3*p.height:15<=b&&35>=b?m="start"===g?0:.75*p.height:195<=b&&215>=b?m="start"===g?.75*p.height:0:35=b?m="start"===g?.25*-p.height:p.height:215=b&&(m="start"===g?p.height:.25*-p.height);15>u?r="start"===g?.15*-p.height:.15*p.height:165=u&&(r="start"=== 29 | g?.15*p.height:.15*-p.height);q.attr({align:n});q.translate(r,m+B)}c.pos.x=x.x+d.x;c.pos.y=x.y+a}});a(x,"getMarkPath",function(c,f,q,p,d,a,h){var n=this.axis;n.isRadial?(c=n.getPosition(this.pos,n.center[2]/2+p),f=["M",f,q,"L",c.x,c.y]):f=c.call(this,f,q,p,d,a,h);return f})});A(t,"parts-more/AreaRangeSeries.js",[t["parts/Globals.js"],t["parts/Utilities.js"]],function(b,a){var r=a.defined,g=a.extend,m=a.isArray,k=a.isNumber,w=a.pick;a=b.seriesType;var z=b.seriesTypes,e=b.Series.prototype,l=b.Point.prototype; 30 | a("arearange","area",{lineWidth:1,threshold:null,tooltip:{pointFormat:'\u25cf {series.name}: {point.low} - {point.high}
'},trackByArea:!0,dataLabels:{align:null,verticalAlign:null,xLow:0,xHigh:0,yLow:0,yHigh:0}},{pointArrayMap:["low","high"],pointValKey:"low",deferTranslatePolar:!0,toYData:function(a){return[a.low,a.high]},highToXY:function(a){var h=this.chart,d=this.xAxis.postTranslate(a.rectPlotX,this.yAxis.len-a.plotHigh);a.plotHighX= 31 | d.x-h.plotLeft;a.plotHigh=d.y-h.plotTop;a.plotLowX=a.plotX},translate:function(){var a=this,h=a.yAxis,d=!!a.modifyValue;z.area.prototype.translate.apply(a);a.points.forEach(function(e){var b=e.high,n=e.plotY;e.isNull?e.plotY=null:(e.plotLow=n,e.plotHigh=h.translate(d?a.modifyValue(b,e):b,0,1,0,1),d&&(e.yBottom=e.plotHigh))});this.chart.polar&&this.points.forEach(function(d){a.highToXY(d);d.tooltipPos=[(d.plotHighX+d.plotLowX)/2,(d.plotHigh+d.plotLow)/2]})},getGraphPath:function(a){var e=[],d=[],b, 32 | l=z.area.prototype.getGraphPath;var n=this.options;var p=this.chart.polar&&!1!==n.connectEnds,c=n.connectNulls,f=n.step;a=a||this.points;for(b=a.length;b--;){var q=a[b];q.isNull||p||c||a[b+1]&&!a[b+1].isNull||d.push({plotX:q.plotX,plotY:q.plotY,doCurve:!1});var F={polarPlotY:q.polarPlotY,rectPlotX:q.rectPlotX,yBottom:q.yBottom,plotX:w(q.plotHighX,q.plotX),plotY:q.plotHigh,isNull:q.isNull};d.push(F);e.push(F);q.isNull||p||c||a[b-1]&&!a[b-1].isNull||d.push({plotX:q.plotX,plotY:q.plotY,doCurve:!1})}a= 33 | l.call(this,a);f&&(!0===f&&(f="left"),n.step={left:"right",center:"center",right:"left"}[f]);e=l.call(this,e);d=l.call(this,d);n.step=f;n=[].concat(a,e);this.chart.polar||"M"!==d[0]||(d[0]="L");this.graphPath=n;this.areaPath=a.concat(d);n.isArea=!0;n.xMap=a.xMap;this.areaPath.xMap=a.xMap;return n},drawDataLabels:function(){var a=this.points,h=a.length,d,b=[],l=this.options.dataLabels,n,p=this.chart.inverted;if(m(l))if(1n.plotLow;n.y=n.high;n._plotY=n.plotY;n.plotY=n.plotHigh;b[d]=n.dataLabel;n.dataLabel=n.dataLabelUpper;n.below=q;p?c.align||(c.align=q?"right":"left"):c.verticalAlign||(c.verticalAlign=q?"top":"bottom")}this.options.dataLabels=c;e.drawDataLabels&&e.drawDataLabels.apply(this,arguments);for(d=h;d--;)if(n=a[d])n.dataLabelUpper=n.dataLabel,n.dataLabel= 35 | b[d],delete n.dataLabels,n.y=n.low,n.plotY=n._plotY}if(f.enabled||this._hasPointLabels){for(d=h;d--;)if(n=a[d])q=f.inside?n.plotHighn.plotLow,n.below=!q,p?f.align||(f.align=q?"left":"right"):f.verticalAlign||(f.verticalAlign=q?"bottom":"top");this.options.dataLabels=f;e.drawDataLabels&&e.drawDataLabels.apply(this,arguments)}if(c.enabled)for(d=h;d--;)if(n=a[d])n.dataLabels=[n.dataLabelUpper,n.dataLabel].filter(function(f){return!!f});this.options.dataLabels=l},alignDataLabel:function(){z.column.prototype.alignDataLabel.apply(this, 36 | arguments)},drawPoints:function(){var a=this.points.length,h;e.drawPoints.apply(this,arguments);for(h=0;hC&&(C*=-1,e-=C);k?(d=c.barX+h,c.shapeType="path",c.shapeArgs={d:a.polarArc(e+C,e,d,d+c.pointWidth)}):(f.height=C,f.y=e,c.tooltipPos=m.inverted? 42 | [l.len+l.pos-m.plotLeft-e-C/2,b.len+b.pos-m.plotTop-f.x-f.width/2,C]:[b.left-m.plotLeft+f.x+f.width/2,l.pos-m.plotTop+e+C/2,C])})},directTouch:!0,trackerGroups:["group","dataLabelsGroup"],drawGraph:k,getSymbol:k,crispCol:function(){return z.crispCol.apply(this,arguments)},drawPoints:function(){return z.drawPoints.apply(this,arguments)},drawTracker:function(){return z.drawTracker.apply(this,arguments)},getColumnMetrics:function(){return z.getColumnMetrics.apply(this,arguments)},pointAttribs:function(){return z.pointAttribs.apply(this, 43 | arguments)},animate:function(){return z.animate.apply(this,arguments)},polarArc:function(){return z.polarArc.apply(this,arguments)},translate3dPoints:function(){return z.translate3dPoints.apply(this,arguments)},translate3dShapes:function(){return z.translate3dShapes.apply(this,arguments)}},{setState:z.pointClass.prototype.setState});""});A(t,"parts-more/ColumnPyramidSeries.js",[t["parts/Globals.js"],t["parts/Utilities.js"]],function(b,a){var r=a.clamp,g=a.pick;a=b.seriesType;var m=b.seriesTypes.column.prototype; 44 | a("columnpyramid","column",{},{translate:function(){var a=this,b=a.chart,z=a.options,e=a.dense=2>a.closestPointRange*a.xAxis.transA;e=a.borderWidth=g(z.borderWidth,e?0:1);var l=a.yAxis,u=z.threshold,h=a.translatedThreshold=l.getThreshold(u),d=g(z.minPointLength,5),B=a.getColumnMetrics(),x=B.width,n=a.barW=Math.max(x,1+2*e),p=a.pointXOffset=B.offset;b.inverted&&(h-=.5);z.pointPadding&&(n=Math.ceil(n));m.translate.apply(a);a.points.forEach(function(c){var f=g(c.yBottom,h),q=999+Math.abs(f),e=r(c.plotY, 45 | -q,l.len+q);q=c.plotX+p;var C=n/2,E=Math.min(e,f);f=Math.max(e,f)-E;c.barX=q;c.pointWidth=x;c.tooltipPos=b.inverted?[l.len+l.pos-b.plotLeft-e,a.xAxis.len-q-C,f]:[q+C,e+l.pos-b.plotTop,f];e=u+(c.total||c.y);"percent"===z.stacking&&(e=u+(0>c.y)?-100:100);e=l.toPixels(e,!0);var v=b.plotHeight-e-(b.plotHeight-h);var m=C*(E-e)/v;var k=C*(E+f-e)/v;v=q-m+C;m=q+m+C;var w=q+k+C;k=q-k+C;var B=E-d;var y=E+f;0>c.y&&(B=E,y=E+f+d);b.inverted&&(w=b.plotWidth-E,v=e-(b.plotWidth-h),m=C*(e-w)/v,k=C*(e-(w-f))/v,v=q+ 46 | C+m,m=v-2*m,w=q-k+C,k=q+k+C,B=E,y=E+f-d,0>c.y&&(y=E+f+d));c.shapeType="path";c.shapeArgs={x:v,y:B,width:m-v,height:f,d:["M",v,B,"L",m,B,w,y,k,y,"Z"]}})}});""});A(t,"parts-more/GaugeSeries.js",[t["parts/Globals.js"],t["parts/Utilities.js"]],function(b,a){var r=a.clamp,g=a.isNumber,m=a.pick,k=a.pInt,w=b.merge,z=b.Series;a=b.seriesType;var e=b.TrackerMixin;a("gauge","line",{dataLabels:{borderColor:"#cccccc",borderRadius:3,borderWidth:1,crop:!1,defer:!1,enabled:!0,verticalAlign:"top",y:15,zIndex:2},dial:{}, 47 | pivot:{},tooltip:{headerFormat:""},showInLegend:!1},{angular:!0,directTouch:!0,drawGraph:b.noop,fixedBox:!0,forceDL:!0,noSharedTooltip:!0,trackerGroups:["group","dataLabelsGroup"],translate:function(){var a=this.yAxis,e=this.options,h=a.center;this.generatePoints();this.points.forEach(function(d){var b=w(e.dial,d.dial),l=k(m(b.radius,"80%"))*h[2]/200,n=k(m(b.baseLength,"70%"))*l/100,p=k(m(b.rearLength,"10%"))*l/100,c=b.baseWidth||3,f=b.topWidth||1,q=e.overshoot,F=a.startAngleRad+a.translate(d.y,null, 48 | null,null,!0);if(g(q)||!1===e.wrap)q=g(q)?q/180*Math.PI:0,F=r(F,a.startAngleRad-q,a.endAngleRad+q);F=180*F/Math.PI;d.shapeType="path";d.shapeArgs={d:b.path||["M",-p,-c/2,"L",n,-c/2,l,-f/2,l,f/2,n,c/2,-p,c/2,"z"],translateX:h[0],translateY:h[1],rotation:F};d.plotX=h[0];d.plotY=h[1]})},drawPoints:function(){var a=this,e=a.chart,h=a.yAxis.center,d=a.pivot,b=a.options,g=b.pivot,n=e.renderer;a.points.forEach(function(p){var c=p.graphic,f=p.shapeArgs,q=f.d,d=w(b.dial,p.dial);c?(c.animate(f),f.d=q):p.graphic= 49 | n[p.shapeType](f).attr({rotation:f.rotation,zIndex:1}).addClass("highcharts-dial").add(a.group);if(!e.styledMode)p.graphic[c?"animate":"attr"]({stroke:d.borderColor||"none","stroke-width":d.borderWidth||0,fill:d.backgroundColor||"#000000"})});d?d.animate({translateX:h[0],translateY:h[1]}):(a.pivot=n.circle(0,0,m(g.radius,5)).attr({zIndex:2}).addClass("highcharts-pivot").translate(h[0],h[1]).add(a.group),e.styledMode||a.pivot.attr({"stroke-width":g.borderWidth||0,stroke:g.borderColor||"#cccccc",fill:g.backgroundColor|| 50 | "#000000"}))},animate:function(a){var e=this;a||(e.points.forEach(function(a){var d=a.graphic;d&&(d.attr({rotation:180*e.yAxis.startAngleRad/Math.PI}),d.animate({rotation:a.shapeArgs.rotation},e.options.animation))}),e.animate=null)},render:function(){this.group=this.plotGroup("group","series",this.visible?"visible":"hidden",this.options.zIndex,this.chart.seriesGroup);z.prototype.render.call(this);this.group.clip(this.chart.clipRect)},setData:function(a,e){z.prototype.setData.call(this,a,!1);this.processData(); 51 | this.generatePoints();m(e,!0)&&this.chart.redraw()},hasData:function(){return!!this.points.length},drawTracker:e&&e.drawTrackerPoint},{setState:function(a){this.state=a}});""});A(t,"parts-more/BoxPlotSeries.js",[t["parts/Globals.js"],t["parts/Utilities.js"]],function(b,a){var r=a.pick;a=b.noop;var g=b.seriesType,m=b.seriesTypes;g("boxplot","column",{threshold:null,tooltip:{pointFormat:'\u25cf {series.name}
Maximum: {point.high}
Upper quartile: {point.q3}
Median: {point.median}
Lower quartile: {point.q1}
Minimum: {point.low}
'}, 52 | whiskerLength:"50%",fillColor:"#ffffff",lineWidth:1,medianWidth:2,whiskerWidth:2},{pointArrayMap:["low","q1","median","q3","high"],toYData:function(a){return[a.low,a.q1,a.median,a.q3,a.high]},pointValKey:"high",pointAttribs:function(){return{}},drawDataLabels:a,translate:function(){var a=this.yAxis,b=this.pointArrayMap;m.column.prototype.translate.apply(this);this.points.forEach(function(g){b.forEach(function(e){null!==g[e]&&(g[e+"Plot"]=a.translate(g[e],0,1,0,1))})})},drawPoints:function(){var a= 53 | this,b=a.options,g=a.chart,e=g.renderer,l,m,h,d,B,x,n=0,p,c,f,q,F=!1!==a.doQuartiles,C,E=a.options.whiskerLength;a.points.forEach(function(v){var G=v.graphic,k=G?"animate":"attr",w=v.shapeArgs,u={},y={},D={},J={},t=v.color||a.color;"undefined"!==typeof v.plotY&&(p=w.width,c=Math.floor(w.x),f=c+p,q=Math.round(p/2),l=Math.floor(F?v.q1Plot:v.lowPlot),m=Math.floor(F?v.q3Plot:v.lowPlot),h=Math.floor(v.highPlot),d=Math.floor(v.lowPlot),G||(v.graphic=G=e.g("point").add(a.group),v.stem=e.path().addClass("highcharts-boxplot-stem").add(G), 54 | E&&(v.whiskers=e.path().addClass("highcharts-boxplot-whisker").add(G)),F&&(v.box=e.path(void 0).addClass("highcharts-boxplot-box").add(G)),v.medianShape=e.path(void 0).addClass("highcharts-boxplot-median").add(G)),g.styledMode||(y.stroke=v.stemColor||b.stemColor||t,y["stroke-width"]=r(v.stemWidth,b.stemWidth,b.lineWidth),y.dashstyle=v.stemDashStyle||b.stemDashStyle,v.stem.attr(y),E&&(D.stroke=v.whiskerColor||b.whiskerColor||t,D["stroke-width"]=r(v.whiskerWidth,b.whiskerWidth,b.lineWidth),v.whiskers.attr(D)), 55 | F&&(u.fill=v.fillColor||b.fillColor||t,u.stroke=b.lineColor||t,u["stroke-width"]=b.lineWidth||0,v.box.attr(u)),J.stroke=v.medianColor||b.medianColor||t,J["stroke-width"]=r(v.medianWidth,b.medianWidth,b.lineWidth),v.medianShape.attr(J)),x=v.stem.strokeWidth()%2/2,n=c+q+x,v.stem[k]({d:["M",n,m,"L",n,h,"M",n,l,"L",n,d]}),F&&(x=v.box.strokeWidth()%2/2,l=Math.floor(l)+x,m=Math.floor(m)+x,c+=x,f+=x,v.box[k]({d:["M",c,m,"L",c,l,"L",f,l,"L",f,m,"L",c,m,"z"]})),E&&(x=v.whiskers.strokeWidth()%2/2,h+=x,d+=x, 56 | C=/%$/.test(E)?q*parseFloat(E)/100:E/2,v.whiskers[k]({d:["M",n-C,h,"L",n+C,h,"M",n-C,d,"L",n+C,d]})),B=Math.round(v.medianPlot),x=v.medianShape.strokeWidth()%2/2,B+=x,v.medianShape[k]({d:["M",c,B,"L",f,B]}))})},setStackedPoints:a});""});A(t,"parts-more/ErrorBarSeries.js",[t["parts/Globals.js"]],function(b){var a=b.noop,r=b.seriesType,g=b.seriesTypes;r("errorbar","boxplot",{color:"#000000",grouping:!1,linkedTo:":previous",tooltip:{pointFormat:'\u25cf {series.name}: {point.low} - {point.high}
'}, 57 | whiskerWidth:null},{type:"errorbar",pointArrayMap:["low","high"],toYData:function(a){return[a.low,a.high]},pointValKey:"high",doQuartiles:!1,drawDataLabels:g.arearange?function(){var a=this.pointValKey;g.arearange.prototype.drawDataLabels.call(this);this.data.forEach(function(b){b.y=b[a]})}:a,getColumnMetrics:function(){return this.linkedParent&&this.linkedParent.columnMetrics||g.column.prototype.getColumnMetrics.call(this)}});""});A(t,"parts-more/WaterfallSeries.js",[t["parts/Globals.js"],t["parts/Utilities.js"]], 58 | function(b,a){var r=a.arrayMax,g=a.arrayMin,m=a.correctFloat,k=a.isNumber,w=a.objectEach,t=a.pick;a=b.addEvent;var e=b.Axis,l=b.Chart,u=b.Point,h=b.Series,d=b.StackItem,B=b.seriesType,x=b.seriesTypes;a(e,"afterInit",function(){this.isXAxis||(this.waterfallStacks={changed:!1})});a(e,"afterBuildStacks",function(){this.waterfallStacks.changed=!1;delete this.waterfallStacks.alreadyChanged});a(l,"beforeRedraw",function(){for(var a=this.axes,p=this.series,c=p.length;c--;)p[c].options.stacking&&(a.forEach(function(f){f.isXAxis|| 59 | (f.waterfallStacks.changed=!0)}),c=0)});a(e,"afterRender",function(){var a=this.options.stackLabels;a&&a.enabled&&this.waterfallStacks&&this.renderWaterfallStackTotals()});e.prototype.renderWaterfallStackTotals=function(){var a=this.waterfallStacks,p=this.stackTotalGroup,c=new d(this,this.options.stackLabels,!1,0,void 0);this.dummyStackItem=c;w(a,function(f){w(f,function(f){c.total=f.stackTotal;f.label&&(c.label=f.label);d.prototype.render.call(c,p);f.label=c.label;delete c.label})});c.total=null}; 60 | B("waterfall","column",{dataLabels:{inside:!0},lineWidth:1,lineColor:"#333333",dashStyle:"Dot",borderColor:"#333333",states:{hover:{lineWidthPlus:0}}},{pointValKey:"y",showLine:!0,generatePoints:function(){var a;x.column.prototype.generatePoints.apply(this);var p=0;for(a=this.points.length;py.height&&(y.y+=y.height,y.height*=-1);m.plotY=y.y=Math.round(y.y)-this.borderWidth%2/2;y.height=Math.max(Math.round(y.height),.001);m.yBottom=y.y+y.height;y.height<=f&&!m.isNull?(y.height=f,y.y-=q,m.plotY=y.y,m.minPointLengthOffset=0>m.y?-q:q):(m.isNull&&(y.width=0),m.minPointLengthOffset=0);y=m.plotY+(m.negative?y.height:0);this.chart.inverted?m.tooltipPos[0]=p.len-y:m.tooltipPos[1]=y}},processData:function(a){var p=this.options,c=this.yData,f=p.data,q=c.length,e=p.threshold||0,d,b,n,g,l;for(l= 65 | b=d=n=g=0;lm.y&&!d||0l.indexOf(d)&&(k=!0);c[d]||(c[d]={});l=c[d];for(var u=0;u=c&&this.renderRange(f)},this);this.legendSymbol.add(this.legendItem);this.legendItem.add(this.legendGroup);this.hideOverlappingLabels()},renderRange:function(a){var c=this.options,f=c.labels,e=this.chart.renderer,d=this.symbols,p=d.labels,b=a.center,h=Math.abs(a.radius),l=c.connectorDistance,n=f.align,g= 79 | f.style.fontSize;l=this.legend.options.rtl||"left"===n?-l:l;f=c.connectorWidth;var m=this.ranges[0].radius,r=b-h-c.borderWidth/2+f/2;g=g/2-(this.fontMetrics.h-g)/2;var k=e.styledMode;"center"===n&&(l=0,c.connectorDistance=0,a.labelStyle.align="center");n=r+c.labels.y;var u=m+l+c.labels.x;d.bubbleItems.push(e.circle(m,b+((r%1?1:.5)-(f%2?0:.5)),h).attr(k?{}:a.bubbleStyle).addClass((k?"highcharts-color-"+this.options.seriesIndex+" ":"")+"highcharts-bubble-legend-symbol "+(c.className||"")).add(this.legendSymbol)); 80 | d.connectors.push(e.path(e.crispLine(["M",m,r,"L",m+l,r],c.connectorWidth)).attr(k?{}:a.connectorStyle).addClass((k?"highcharts-color-"+this.options.seriesIndex+" ":"")+"highcharts-bubble-legend-connectors "+(c.connectorClassName||"")).add(this.legendSymbol));a=e.text(this.formatLabel(a),u,n+g).attr(k?{}:a.labelStyle).addClass("highcharts-bubble-legend-labels "+(c.labels.className||"")).add(this.legendSymbol);p.push(a);a.placed=!0;a.alignAttr={x:u,y:n+g}},getMaxLabelSize:function(){var a,c;this.symbols.labels.forEach(function(f){c= 81 | f.getBBox(!0);a=a?c.width>a.width?c:a:c});return a||{}},formatLabel:function(a){var c=this.options,f=c.labels.formatter;c=c.labels.format;var e=this.chart.numberFormatter;return c?b.format(c,a):f?f.call(a):e(a.value,1)},hideOverlappingLabels:function(){var a=this.chart,c=this.symbols;!this.options.labels.allowOverlap&&c&&(a.hideOverlappingLabels(c.labels),c.labels.forEach(function(f,a){f.newOpacity?f.newOpacity!==f.oldOpacity&&c.connectors[a].show():c.connectors[a].hide()}))},getRanges:function(){var a= 82 | this.legend.bubbleLegend,c=a.options.ranges,f,e=Number.MAX_VALUE,b=-Number.MAX_VALUE;a.chart.series.forEach(function(a){a.isBubble&&!a.ignoreSeries&&(f=a.zData.filter(m),f.length&&(e=w(a.options.zMin,Math.min(e,Math.max(g(f),!1===a.options.displayNegative?a.options.zThreshold:-Number.MAX_VALUE))),b=w(a.options.zMax,Math.max(b,r(f)))))});var h=e===b?[{value:b}]:[{value:e},{value:(e+b)/2},{value:b,autoRanges:!0}];c.length&&c[0].radius&&h.reverse();h.forEach(function(a,f){c&&c[f]&&(h[f]=d(!1,c[f],a))}); 83 | return h},predictBubbleSizes:function(){var a=this.chart,c=this.fontMetrics,f=a.legend.options,e="horizontal"===f.layout,d=e?a.legend.lastLineHeight:0,b=a.plotSizeX,h=a.plotSizeY,l=a.series[this.options.seriesIndex];a=Math.ceil(l.minPxSize);var n=Math.ceil(l.maxPxSize);l=l.options.maxSize;var g=Math.min(h,b);if(f.floating||!/%$/.test(l))c=n;else if(l=parseFloat(l),c=(g+d-c.h/2)*l/100/(l/100+1),e&&h-c>=b||!e&&b-c>=h)c=n;return[a,Math.ceil(c)]},updateRanges:function(a,c){var f=this.legend.options.bubbleLegend; 84 | f.minSize=a;f.maxSize=c;f.ranges=this.getRanges()},correctSizes:function(){var a=this.legend,c=this.chart.series[this.options.seriesIndex];1b.height&&(b.height=a[d].itemHeight);b.step=e}return c};e.prototype.retranslateItems=function(a){var c,f,e,d=this.options.rtl,b=0;this.allItems.forEach(function(q,h){c=q.legendGroup.translateX;f=q._legendItemPos[1];if((e=q.movementX)||d&&q.ranges)e=d?c-q.options.maxSize/2:c+e,q.legendGroup.attr({translateX:e});h>a[b].step&&b++;q.legendGroup.attr({translateY:Math.round(f+a[b].height/2)});q._legendItemPos[1]= 87 | f+a[b].height/2})};u(t,"legendItemClick",function(){var a=this.chart,c=this.visible,f=this.chart.legend;f&&f.bubbleLegend&&(this.visible=!c,this.ignoreSeries=c,a=0<=a.getVisibleBubbleSeriesIndex(),f.bubbleLegend.visible!==a&&(f.update({bubbleLegend:{enabled:a}}),f.bubbleLegend.visible=a),this.visible=c)});a(l.prototype,"drawChartBox",function(a,c,f){var e=this.legend,d=0<=this.getVisibleBubbleSeriesIndex();if(e&&e.options.enabled&&e.bubbleLegend&&e.options.bubbleLegend.autoRanges&&d){var b=e.bubbleLegend.options; 88 | d=e.bubbleLegend.predictBubbleSizes();e.bubbleLegend.updateRanges(d[0],d[1]);b.placed||(e.group.placed=!1,e.allItems.forEach(function(a){a.legendGroup.translateY=null}));e.render();this.getMargins();this.axes.forEach(function(a){a.visible&&a.render();b.placed||(a.setScale(),a.updateNames(),k(a.ticks,function(a){a.isNew=!0;a.isNewLabel=!0}))});b.placed=!0;this.getMargins();a.call(this,c,f);e.bubbleLegend.correctSizes();e.retranslateItems(e.getLinesHeights())}else a.call(this,c,f),e&&e.options.enabled&& 89 | e.bubbleLegend&&(e.render(),e.retranslateItems(e.getLinesHeights()))})});A(t,"parts-more/BubbleSeries.js",[t["parts/Globals.js"],t["parts/Utilities.js"]],function(b,a){var r=a.arrayMax,g=a.arrayMin,m=a.clamp,k=a.extend,w=a.isNumber,t=a.pick,e=a.pInt;a=b.Axis;var l=b.color,u=b.noop,h=b.Point,d=b.Series,B=b.seriesType,x=b.seriesTypes;B("bubble","scatter",{dataLabels:{formatter:function(){return this.point.z},inside:!0,verticalAlign:"middle"},animationLimit:250,marker:{lineColor:null,lineWidth:1,fillOpacity:.5, 90 | radius:null,states:{hover:{radiusPlus:0}},symbol:"circle"},minSize:8,maxSize:"20%",softThreshold:!1,states:{hover:{halo:{size:5}}},tooltip:{pointFormat:"({point.x}, {point.y}), Size: {point.z}"},turboThreshold:0,zThreshold:0,zoneAxis:"z"},{pointArrayMap:["y","z"],parallelArrays:["x","y","z"],trackerGroups:["group","dataLabelsGroup"],specialGroup:"group",bubblePadding:!0,zoneAxis:"z",directTouch:!0,isBubble:!0,pointAttribs:function(a,e){var c=this.options.marker.fillOpacity;a=d.prototype.pointAttribs.call(this, 91 | a,e);1!==c&&(a.fill=l(a.fill).setOpacity(c).get("rgba"));return a},getRadii:function(a,e,c){var f=this.zData,d=this.yData,b=c.minPxSize,h=c.maxPxSize,l=[];var g=0;for(c=f.length;g=this.minPxSize/2?(f.marker=k(f.marker,{radius:d,width:2*d,height:2*d}),f.dlBox={x:f.plotX-d,y:f.plotY-d,width:2*d,height:2*d}):f.shapeArgs=f.plotY=f.dlBox=void 0}},alignDataLabel:x.column.prototype.alignDataLabel,buildKDTree:u,applyZones:u},{haloPath:function(a){return h.prototype.haloPath.call(this,0===a?0:(this.marker?this.marker.radius||0:0)+a)},ttBelow:!1});a.prototype.beforePadding=function(){var a=this,d=this.len,c=this.chart,f=0,b=d,h= 94 | this.isXAxis,l=h?"xData":"yData",k=this.min,v={},u=Math.min(c.plotWidth,c.plotHeight),x=Number.MAX_VALUE,B=-Number.MAX_VALUE,z=this.max-k,y=d/z,D=[];this.series.forEach(function(f){var d=f.options;!f.bubblePadding||!f.visible&&c.options.chart.ignoreHiddenSeries||(a.allowZoomOutside=!0,D.push(f),h&&(["minSize","maxSize"].forEach(function(a){var f=d[a],c=/%$/.test(f);f=e(f);v[a]=c?u*f/100:f}),f.minPxSize=v.minSize,f.maxPxSize=Math.max(v.maxSize,v.minSize),f=f.zData.filter(w),f.length&&(x=t(d.zMin,m(g(f), 95 | !1===d.displayNegative?d.zThreshold:-Number.MAX_VALUE,x)),B=t(d.zMax,Math.max(B,r(f))))))});D.forEach(function(e){var c=e[l],d=c.length;h&&e.getRadii(x,B,e);if(0a?1:0)},barycenter:function(){var a=this.options.gravitationalConstant,b=this.barycenter.xFactor,g=this.barycenter.yFactor;b=(b-(this.box.left+this.box.width)/2)*a;g=(g-(this.box.top+this.box.height)/2)*a;this.nodes.forEach(function(a){a.fixedPosition||(a.plotX-=b/a.mass/a.degree, 97 | a.plotY-=g/a.mass/a.degree)})},repulsive:function(a,b,g){b=b*this.diffTemperature/a.mass/a.degree;a.fixedPosition||(a.plotX+=g.x*b,a.plotY+=g.y*b)},attractive:function(a,b,g){var m=a.getMass(),k=-g.x*b*this.diffTemperature;b=-g.y*b*this.diffTemperature;a.fromNode.fixedPosition||(a.fromNode.plotX-=k*m.fromNode/a.fromNode.degree,a.fromNode.plotY-=b*m.fromNode/a.fromNode.degree);a.toNode.fixedPosition||(a.toNode.plotX+=k*m.toNode/a.toNode.degree,a.toNode.plotY+=b*m.toNode/a.toNode.degree)},integrate:function(a, 98 | b){var g=-a.options.friction,m=a.options.maxSpeed,k=(b.plotX+b.dispX-b.prevX)*g;g*=b.plotY+b.dispY-b.prevY;var r=Math.abs,t=r(k)/(k||1);r=r(g)/(g||1);k=t*Math.min(m,Math.abs(k));g=r*Math.min(m,Math.abs(g));b.prevX=b.plotX+b.dispX;b.prevY=b.plotY+b.dispY;b.plotX+=k;b.plotY+=g;b.temperature=a.vectorLength({x:k,y:g})},getK:function(a){return Math.pow(a.box.width*a.box.height/a.nodes.length,.5)}},euler:{attractiveForceFunction:function(a,b){return a*a/b},repulsiveForceFunction:function(a,b){return b* 99 | b/a},barycenter:function(){var a=this.options.gravitationalConstant,b=this.barycenter.xFactor,g=this.barycenter.yFactor;this.nodes.forEach(function(m){if(!m.fixedPosition){var k=m.getDegree();k*=1+k/2;m.dispX+=(b-m.plotX)*a*k/m.degree;m.dispY+=(g-m.plotY)*a*k/m.degree}})},repulsive:function(a,b,g,m){a.dispX+=g.x/m*b/a.degree;a.dispY+=g.y/m*b/a.degree},attractive:function(a,b,g,m){var k=a.getMass(),r=g.x/m*b;b*=g.y/m;a.fromNode.fixedPosition||(a.fromNode.dispX-=r*k.fromNode/a.fromNode.degree,a.fromNode.dispY-= 100 | b*k.fromNode/a.fromNode.degree);a.toNode.fixedPosition||(a.toNode.dispX+=r*k.toNode/a.toNode.degree,a.toNode.dispY+=b*k.toNode/a.toNode.degree)},integrate:function(a,b){b.dispX+=b.dispX*a.options.friction;b.dispY+=b.dispY*a.options.friction;var g=b.temperature=a.vectorLength({x:b.dispX,y:b.dispY});0!==g&&(b.plotX+=b.dispX/g*Math.min(Math.abs(b.dispX),a.temperature),b.plotY+=b.dispY/g*Math.min(Math.abs(b.dispY),a.temperature))},getK:function(a){return Math.pow(a.box.width*a.box.height/a.nodes.length, 101 | .3)}}}});A(t,"modules/networkgraph/QuadTree.js",[t["parts/Globals.js"],t["parts/Utilities.js"]],function(b,a){a=a.extend;var r=b.QuadTreeNode=function(a){this.box=a;this.boxSize=Math.min(a.width,a.height);this.nodes=[];this.body=this.isInternal=!1;this.isEmpty=!0};a(r.prototype,{insert:function(a,b){this.isInternal?this.nodes[this.getBoxPosition(a)].insert(a,b-1):(this.isEmpty=!1,this.body?b?(this.isInternal=!0,this.divideBox(),!0!==this.body&&(this.nodes[this.getBoxPosition(this.body)].insert(this.body, 102 | b-1),this.body=!0),this.nodes[this.getBoxPosition(a)].insert(a,b-1)):(b=new r({top:a.plotX,left:a.plotY,width:.1,height:.1}),b.body=a,b.isInternal=!1,this.nodes.push(b)):(this.isInternal=!1,this.body=a))},updateMassAndCenter:function(){var a=0,b=0,k=0;this.isInternal?(this.nodes.forEach(function(g){g.isEmpty||(a+=g.mass,b+=g.plotX*g.mass,k+=g.plotY*g.mass)}),b/=a,k/=a):this.body&&(a=this.body.mass,b=this.body.plotX,k=this.body.plotY);this.mass=a;this.plotX=b;this.plotY=k},divideBox:function(){var a= 103 | this.box.width/2,b=this.box.height/2;this.nodes[0]=new r({left:this.box.left,top:this.box.top,width:a,height:b});this.nodes[1]=new r({left:this.box.left+a,top:this.box.top,width:a,height:b});this.nodes[2]=new r({left:this.box.left+a,top:this.box.top+b,width:a,height:b});this.nodes[3]=new r({left:this.box.left,top:this.box.top+b,width:a,height:b})},getBoxPosition:function(a){var b=a.plotYMath.abs(this.systemTemperature- 116 | this.prevSystemTemperature)||0>=this.temperature},getSystemTemperature:function(){return this.nodes.reduce(function(a,b){return a+b.temperature},0)},vectorLength:function(a){return Math.sqrt(a.x*a.x+a.y*a.y)},getDistR:function(a,b){a=this.getDistXY(a,b);return this.vectorLength(a)},getDistXY:function(a,b){var e=a.plotX-b.plotX;a=a.plotY-b.plotY;return{x:e,y:a,absX:Math.abs(e),absY:Math.abs(a)}}});a(t,"predraw",function(){this.graphLayoutsLookup&&this.graphLayoutsLookup.forEach(function(a){a.stop()})}); 117 | a(t,"render",function(){function a(a){a.maxIterations--&&isFinite(a.temperature)&&!a.isStable()&&!a.options.enableSimulation&&(a.beforeStep&&a.beforeStep(),a.step(),g=!1,b=!0)}var b=!1;if(this.graphLayoutsLookup){w(!1,this);for(this.graphLayoutsLookup.forEach(function(a){a.start()});!g;){var g=!0;this.graphLayoutsLookup.forEach(a)}b&&this.series.forEach(function(a){a&&a.layout&&a.render()})}})});A(t,"modules/networkgraph/draggable-nodes.js",[t["parts/Globals.js"]],function(b){var a=b.Chart,r=b.addEvent; 118 | b.dragNodesMixin={onMouseDown:function(a,b){b=this.chart.pointer.normalize(b);a.fixedPosition={chartX:b.chartX,chartY:b.chartY,plotX:a.plotX,plotY:a.plotY};a.inDragMode=!0},onMouseMove:function(a,b){if(a.fixedPosition&&a.inDragMode){var g=this.chart,m=g.pointer.normalize(b);b=a.fixedPosition.chartX-m.chartX;m=a.fixedPosition.chartY-m.chartY;if(5c&&(f.degree+=.01,f.neighbours++,b=a.repulsiveForce(-c/Math.sqrt(f.neighbours),a.k,f,q)),a.force("repulsive",f,b*q.mass,d,q,c))})})},applyLimitBox:function(a){if(this.options.splitSeries&& 125 | !a.isParentNode&&this.options.parentNodeLimit){var f=this.getDistXY(a,a.series.parentNode);var b=a.series.parentNodeRadius-a.marker.radius-this.vectorLength(f);0>b&&b>-2*a.marker.radius&&(a.plotX-=.01*f.x,a.plotY-=.01*f.y)}n.prototype.applyLimitBox.apply(this,arguments)},isStable:function(){return.00001>Math.abs(this.systemTemperature-this.prevSystemTemperature)||0>=this.temperature||0this.systemTemperature/this.nodes.length&&this.enableSimulation}});a("packedbubble", 126 | "bubble",{minSize:"10%",maxSize:"50%",sizeBy:"area",zoneAxis:"y",tooltip:{pointFormat:"Value: {point.value}"},draggable:!0,useSimulation:!0,dataLabels:{formatter:function(){return this.point.value},parentNodeFormatter:function(){return this.name},parentNodeTextPath:{enabled:!0},padding:0},layoutAlgorithm:{initialPositions:"circle",initialPositionRadius:20,bubblePadding:5,parentNodeLimit:!1,seriesInteraction:!0,dragBetweenSeries:!1,parentNodeOptions:{maxIterations:400,gravitationalConstant:.03,maxSpeed:50, 127 | initialPositionRadius:100,seriesInteraction:!0,marker:{fillColor:null,fillOpacity:1,lineWidth:1,lineColor:null,symbol:"circle"}},enableSimulation:!0,type:"packedbubble",integration:"packedbubble",maxIterations:1E3,splitSeries:!1,maxSpeed:5,gravitationalConstant:.01,friction:-.981}},{hasDraggableNodes:!0,forces:["barycenter","repulsive"],pointArrayMap:["value"],pointValKey:"value",isCartesian:!1,requireSorting:!1,directTouch:!0,axisTypes:[],noSharedTooltip:!0,searchPoint:b.noop,accumulateAllPoints:function(a){var f= 128 | a.chart,b=[],c,d;for(c=0;cMath.sqrt(f*f+c*c)-Math.abs(a[2]+b[2])},positionBubble:function(a,b,c){var f=Math.sqrt,d=Math.asin,e=Math.acos,h=Math.pow,g=Math.abs;f=f(h(a[0]-b[0],2)+h(a[1]-b[1],2));e=e((h(f, 139 | 2)+h(c[2]+b[2],2)-h(c[2]+a[2],2))/(2*(c[2]+b[2])*f));d=d(g(a[0]-b[0])/f);a=(0>a[1]-b[1]?0:Math.PI)+e+d*(0>(a[0]-b[0])*(a[1]-b[1])?1:-1);return[b[0]+(b[2]+c[2])*Math.sin(a),b[1]-(b[2]+c[2])*Math.cos(a),c[2],c[3],c[4]]},placeBubbles:function(a){var b=this.checkOverlap,c=this.positionBubble,d=[],f=1,e=0,h=0;var g=[];var n;a=a.sort(function(a,b){return b[2]-a[2]});if(a.length){d.push([[0,0,a[0][2],a[0][3],a[0][4]]]);if(1d&&(d=a),af&&(c.series.addPoint(b.merge(a.options,{plotX:a.plotX,plotY:a.plotY}), 144 | !1),e.removeElementFromCollection(a,e.nodes),a.remove()))});c.onMouseUp.apply(this,arguments)}},destroy:function(){this.chart.graphLayoutsLookup&&this.chart.graphLayoutsLookup.forEach(function(a){a.removeElementFromCollection(this,a.series)},this);this.parentNode&&(this.parentNodeLayout.removeElementFromCollection(this.parentNode,this.parentNodeLayout.nodes),this.parentNode.dataLabel&&(this.parentNode.dataLabel=this.parentNode.dataLabel.destroy()));b.Series.prototype.destroy.apply(this,arguments)}, 145 | alignDataLabel:b.Series.prototype.alignDataLabel},{destroy:function(){this.series.layout&&this.series.layout.removeElementFromCollection(this,this.series.layout.nodes);return u.prototype.destroy.apply(this,arguments)}});h(B,"beforeRedraw",function(){this.allDataPoints&&delete this.allDataPoints});""});A(t,"parts-more/Polar.js",[t["parts/Globals.js"],t["parts/Utilities.js"]],function(b,a){var r=a.defined,g=a.pick,m=a.splat,k=a.wrap,t=b.Series,z=b.seriesTypes,e=t.prototype,l=b.Pointer.prototype;e.searchPointByAngle= 146 | function(a){var b=this.chart,e=this.xAxis.pane.center;return this.searchKDTree({clientX:180+-180/Math.PI*Math.atan2(a.chartX-e[0]-b.plotLeft,a.chartY-e[1]-b.plotTop)})};e.getConnectors=function(a,b,e,g){var d=g?1:0;var h=0<=b&&b<=a.length-1?b:0>b?a.length-1+b:0;b=0>h-1?a.length-(1+d):h-1;d=h+1>a.length-1?d:h+1;var c=a[b];d=a[d];var f=c.plotX;c=c.plotY;var l=d.plotX;var k=d.plotY;d=a[h].plotX;h=a[h].plotY;f=(1.5*d+f)/2.5;c=(1.5*h+c)/2.5;l=(1.5*d+l)/2.5;var m=(1.5*h+k)/2.5;k=Math.sqrt(Math.pow(f-d, 147 | 2)+Math.pow(c-h,2));var x=Math.sqrt(Math.pow(l-d,2)+Math.pow(m-h,2));f=Math.atan2(c-h,f-d);m=Math.PI/2+(f+Math.atan2(m-h,l-d))/2;Math.abs(f-m)>Math.PI/2&&(m-=Math.PI);f=d+Math.cos(m)*k;c=h+Math.sin(m)*k;l=d+Math.cos(Math.PI+m)*x;m=h+Math.sin(Math.PI+m)*x;d={rightContX:l,rightContY:m,leftContX:f,leftContY:c,plotX:d,plotY:h};e&&(d.prevPointCont=this.getConnectors(a,b,!1,g));return d};e.toXY=function(a){var b=this.chart,e=this.xAxis;var h=this.yAxis;var g=a.plotX,l=a.plotY,c=a.series,f=b.inverted,k= 148 | a.y;f&&c&&!c.isRadialBar&&(a.plotY=l="number"===typeof k?h.translate(k)||0:0);a.rectPlotX=g;a.rectPlotY=l;h=f?e.postTranslate(l,g):e.postTranslate(g,h.len-l);a.plotX=a.polarPlotX=h.x-b.plotLeft;a.plotY=a.polarPlotY=h.y-b.plotTop;this.kdByAngle?(b=(g/Math.PI*180+e.pane.options.startAngle)%360,0>b&&(b+=360),a.clientX=b):a.clientX=a.plotX};z.spline&&(k(z.spline.prototype,"getPointSpline",function(a,b,e,g){this.chart.polar?g?(a=this.getConnectors(b,g,!0,this.connectEnds),a=["C",a.prevPointCont.rightContX, 149 | a.prevPointCont.rightContY,a.leftContX,a.leftContY,a.plotX,a.plotY]):a=["M",e.plotX,e.plotY]:a=a.call(this,b,e,g);return a}),z.areasplinerange&&(z.areasplinerange.prototype.getPointSpline=z.spline.prototype.getPointSpline));b.addEvent(t,"afterTranslate",function(){var a=this.chart;if(a.polar&&this.xAxis){(this.kdByAngle=a.tooltip&&a.tooltip.shared)?this.searchPoint=this.searchPointByAngle:this.options.findNearestPointBy="xy";if(!this.preventPostTranslate)for(var d=this.points,e=d.length;e--;)this.toXY(d[e]), 150 | !a.hasParallelCoordinates&&!this.yAxis.reversed&&d[e].yz?z=0:z>t&&(z=t),this.translatedThreshold=z+m)}for(;u--;){d=e[u]; 154 | var A=d.barX;var I=d.x;var H=d.y;if(g.inverted){d.shapeType="arc";d.plotY=k.translate(H);if(h){if(H=k.stacks[(0>H?"-":"")+this.stackKey],this.visible&&H&&H[I]&&!d.isNull){var y=H[I].points[this.getStackIndicator(void 0,I,this.index).key];var D=k.translate(y[0]);y=k.translate(y[1]);r(D)&&(D=a.clamp(D,0,t))}}else D=z,y=d.plotY;D>y&&(y=[D,D=y][0]);if(!c)if(Dv)y=v;else{if(yv)D=y=0}else if(y>w)y=w;else if(Dw||yk.max&&(D=y=c?t:0);D+=m;y+=m;I=Math.max(A, 155 | 0);A=Math.max(A+d.pointWidth,0);d.shapeArgs={x:f[0],y:f[1],r:A,innerR:I,start:D,end:y};d.opacity=D===y?0:void 0;d.plotY=(r(this.translatedThreshold)&&(Df[1]}}}),t.findAlignments=function(a,b){null=== 156 | b.align&&(b.align=20a?"left":200a?"right":"center");null===b.verticalAlign&&(b.verticalAlign=45>a||315a?"top":"middle");return b},k(t,"alignDataLabel",function(a,b,l,k,m,p){var c=this.chart,d=g(k.inside,!!this.options.stacking);c.polar?(a=b.rectPlotX/Math.PI*180,c.inverted?(this.forceDL=c.isInsidePlot(b.plotX,Math.round(b.plotY),!1),d&&b.shapeArgs?(m=b.shapeArgs,m=this.xAxis.postTranslate((m.start+m.end)/2-this.xAxis.startAngleRad,b.barX+b.pointWidth/2),m={x:m.x- 157 | c.plotLeft,y:m.y-c.plotTop}):b.tooltipPos&&(m={x:b.tooltipPos[0],y:b.tooltipPos[1]}),k.align=g(k.align,"center"),k.verticalAlign=g(k.verticalAlign,"middle")):k=this.findAlignments(a,k),e.alignDataLabel.call(this,b,l,k,m,p),this.isRadialBar&&b.shapeArgs&&b.shapeArgs.start===b.shapeArgs.end&&l.hide(!0)):a.call(this,b,l,k,m,p)}));k(l,"getCoordinates",function(a,b){var d=this.chart,e={xAxis:[],yAxis:[]};d.polar?d.axes.forEach(function(a){var h=a.isXAxis,c=a.center;if("colorAxis"!==a.coll){var f=b.chartX- 158 | c[0]-d.plotLeft;c=b.chartY-c[1]-d.plotTop;e[h?"xAxis":"yAxis"].push({axis:a,value:a.translate(h?Math.PI-Math.atan2(f,c):Math.sqrt(Math.pow(f,2)+Math.pow(c,2)),!0)})}}):e=a.call(this,b);return e});b.SVGRenderer.prototype.clipCircle=function(a,d,e){var h=b.uniqueKey(),g=this.createElement("clipPath").attr({id:h}).add(this.defs);a=this.circle(a,d,e).add(g);a.id=h;a.clipPath=g;return a};b.addEvent(b.Chart,"getAxes",function(){this.pane||(this.pane=[]);m(this.options.pane).forEach(function(a){new b.Pane(a, 159 | this)},this)});b.addEvent(b.Chart,"afterDrawChartBox",function(){this.pane.forEach(function(a){a.render()})});b.addEvent(b.Series,"afterInit",function(){var a=this.chart;a.inverted&&a.polar&&(this.isRadialSeries=!0,this instanceof z.column&&(this.isRadialBar=!0))});k(b.Chart.prototype,"get",function(a,d){return b.find(this.pane,function(a){return a.options.id===d})||a.call(this,d)})});A(t,"masters/highcharts-more.src.js",[],function(){})}); 160 | //# sourceMappingURL=highcharts-more.js.map --------------------------------------------------------------------------------