Dual CANbus monitor and instrumentation cluster
Eagle Schematic and Board design
/media/uploads/TickTock/canaryr5.zip
Parts List
Assembly
1) LCD Displays
I found ribbon cable is a nice way to organize the wires to the displays. You'll need 12 conductors and I connected them in the following order:
1 | LED+ |
2 | LED- |
3 | RSTB |
4 | MOSI |
5 | SCLK |
6 | CSB |
7 | X+ |
8 | X- |
9 | Y+ |
10 | Y- |
11 | VDD |
12 | GND |
First I connected all the GND connections (IM0, IM1, IM3, & 2 GND). Do not connect the bottom GND until you have the ribbon cable connected. After making all the ribbon cable connections (connecting the GND of the ribbon cable to the bottom GND pad), solder the GND bar from the previous step to the back of the bottom GND connection. Finally, make a connection from the back side 3.3V pin to IM2. Take a break and repeat for the second display. Once the two displays are complete combine all wires except CS0, CS1, X+, X-, Y+, and Y-. Connect X- of the left display to X+ of the right. Similarly connect Y- of the left display to Y+ of the right. Insulate any exposed wires.
2) PCB
Refer to the schematics to place all the components on the board. If you plan to install into the CANary 3D enclosure, DO NOT install the battery holder or the socket for the mbed and, instead, connect two wires to the VB and GND pads nearby. You will have to install the battery holder against the back wall to avoid interfering with the right-hand display and the mbed will have to be directly soldered. I have not found a socket with a low enough profile to fit in the space provided (depth of enclosure is limited by the space behind the center console). Also, I recommend keeping as much lead as possible on the Zener diode (bending it as shown to clear the back wall). Although it is operating well within parameters, the Zener gets quite hot during extended operation and the leads help dissipate the heat and keep it away from the PCB and other components.
Once the PCB is populated, solder the LCDs to the PCB. CS0 connects to the right display and CS1 connects to the left.
3) Testing
1) | First step is to buzz out all connections from the LCDs to the pins in the main board |
2) | Next check the touch screen connections. On the main board, place an Ohm meter across X+ and X-. You should read 700 Ohms. Repeat for Y+ and Y-. Then test the resistance from X+ to Y+. With nothing touching the screens, it should read >100K Ohms and <1K when touching either screen. |
3) | When all connections are checked, solder in the mbed. Download and install the touch2 program http://mbed.org/users/TickTock/code/touch2/ to test the basic operation of the mbed and touch screens. |
tips: | |
Touch screen is sensitive - excess flux on X+,X-,Y+,Y- connection on mbed can result in flakey operation | |
If touch is not working, double-check the LCD0_CS and LCD1_CS are not swapped. LCD0_CS must connect to the CS of the LCD that has X- & Y- connected to the mbed. LCD1_CS must connect to the CS of the LCD that has X+ & Y+ connected to the mbed. | |
4) | Once touch2 works, it is time to connect to the OBD connector. I highly recommend double checking all connections from the OBD to the PCB with the cable in place before connecting to the Leaf. Buzz out all the pins in the OBS to make sure none are shorting to each other, Check that the 12V goes to the Zener (and nothing else) and the switched 12V to the resistor divider (and nothing else). Test the ground connection properly connects to ground and nothing else. |
5) | Once you are confident there are no shorts or wrong connections from the OBD connector, take a deep breath and plug it into your leaf. Touch2 program should come up and function. Unplug and install the latest CANary firmware. Test all features before installing into the enclosure (gids, cellpair, menu system, logging) since installing and removing from the enclosure is a PITA. |
4) Enclosure
The 3D printer leaves a lot of powder behind - I used a strong spray of water to get it out of all the cracks. The enclosure comes with a rather rough finish. I recommend convincing yourself you like it, then simply lightly sand then paint before assembly. Sanding is very difficult - the nylon is very nicely fused and doesn't want to sand. I tried sandblasting and that didn't work either. I had some limited success with filler and then sanding, but only on the outside - it is too difficult to sand the face.
5) Final Assembly
utility.cpp@96:a6c6a6fd1d28, 2013-05-03 (annotated)
- Committer:
- TickTock
- Date:
- Fri May 03 14:31:07 2013 +0000
- Revision:
- 96:a6c6a6fd1d28
- Parent:
- 95:248b3c25a7df
Fixed mistake (battTemp is char not short)
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
TickTock | 13:62e0f7f39ff5 | 1 | // utility.cpp |
TickTock | 13:62e0f7f39ff5 | 2 | #include "utility.h" |
TickTock | 13:62e0f7f39ff5 | 3 | |
TickTock | 13:62e0f7f39ff5 | 4 | void mbed_reset(); |
TickTock | 22:a43df3905863 | 5 | |
TickTock | 13:62e0f7f39ff5 | 6 | void RTC_IRQHandler() { |
TickTock | 13:62e0f7f39ff5 | 7 | timer.reset(); // zero ms at the-seconds-tic |
TickTock | 20:3bf176d14b14 | 8 | canIdle=(++secsNoMsg>canTimeout)?true:false; |
TickTock | 20:3bf176d14b14 | 9 | userIdle=(++secsNoTouch>userTimeout)?true:false; |
TickTock | 13:62e0f7f39ff5 | 10 | LPC_RTC->ILR |= (1<<0); // clear interrupt to prepare for next |
TickTock | 34:4751a8259b18 | 11 | tick=true; |
garygid | 69:6bfdfc002036 | 12 | // will use this to generate a logTP() just before the next Message received. |
garygid | 69:6bfdfc002036 | 13 | if( (time(NULL) % 60) == 0) ZeroSecTick = true; // gg - at 0-second of each minute |
TickTock | 13:62e0f7f39ff5 | 14 | } |
TickTock | 13:62e0f7f39ff5 | 15 | |
TickTock | 37:fea2c1d52c5f | 16 | void RTC_Init (void) { |
TickTock | 13:62e0f7f39ff5 | 17 | LPC_RTC->ILR=0x00; // set up the RTC interrupts |
TickTock | 13:62e0f7f39ff5 | 18 | LPC_RTC->CIIR=0x01; // interrupts each second |
TickTock | 13:62e0f7f39ff5 | 19 | LPC_RTC->CCR = 0x01; // Clock enable |
TickTock | 92:935adef49ea4 | 20 | //NVIC_SetPriority( RTC_IRQn, 10 ); |
TickTock | 13:62e0f7f39ff5 | 21 | NVIC_EnableIRQ( RTC_IRQn ); |
TickTock | 13:62e0f7f39ff5 | 22 | } |
TickTock | 13:62e0f7f39ff5 | 23 | |
TickTock | 93:c2402e8cd0e2 | 24 | void printMsg (char *msg) { |
TickTock | 13:62e0f7f39ff5 | 25 | strcpy(displayLog[displayLoc],msg); |
TickTock | 13:62e0f7f39ff5 | 26 | displayLoc=displayLoc>17?0:displayLoc+1; |
TickTock | 13:62e0f7f39ff5 | 27 | } |
TickTock | 13:62e0f7f39ff5 | 28 | |
TickTock | 13:62e0f7f39ff5 | 29 | void touch_ISR(){ |
TickTock | 37:fea2c1d52c5f | 30 | //LPC_GPIOINT->IO2IntClr = (LPC_GPIOINT->IO2IntStatR | LPC_GPIOINT->IO2IntStatF); // seems to work without so maybe not necessary (performed inInterruptIn handler?) |
TickTock | 35:5acbd8a64a89 | 31 | touched=true; // just set flag - touch screen algorythm is long and we don't want to block other interrupts |
TickTock | 13:62e0f7f39ff5 | 32 | } |
TickTock | 13:62e0f7f39ff5 | 33 | |
TickTock | 13:62e0f7f39ff5 | 34 | unsigned short getTimeStamp() { |
TickTock | 13:62e0f7f39ff5 | 35 | unsigned short msec = timer.read_ms() ; // read ms from the timer |
TickTock | 13:62e0f7f39ff5 | 36 | unsigned long secs = time(NULL); // seconds past 12:00:00 AM 1 Jan 1900 |
TickTock | 13:62e0f7f39ff5 | 37 | unsigned short isecs = secs%60 ; // modulo 60 for 0-59 seconds from RTC |
TickTock | 13:62e0f7f39ff5 | 38 | return ((isecs<<10)+msec) ; // return the two byte time stamp |
TickTock | 13:62e0f7f39ff5 | 39 | } |
TickTock | 13:62e0f7f39ff5 | 40 | |
TickTock | 13:62e0f7f39ff5 | 41 | void logCan (char mType, CANMessage canRXmsg) { |
TickTock | 85:5c27e88b3fbe | 42 | |
TickTock | 85:5c27e88b3fbe | 43 | // re-arranged to put static first |
TickTock | 85:5c27e88b3fbe | 44 | static unsigned char ii = 0; |
TickTock | 85:5c27e88b3fbe | 45 | static unsigned char lasti = 0; // indexindex |
TickTock | 85:5c27e88b3fbe | 46 | static unsigned char bdi=0; |
TickTock | 85:5c27e88b3fbe | 47 | static signed short imotorRPM = 0; |
TickTock | 85:5c27e88b3fbe | 48 | static unsigned short nLost = 0; // gg - overrun |
TickTock | 85:5c27e88b3fbe | 49 | |
TickTock | 83:52b1f330a62d | 50 | char sTemp[40]; |
TickTock | 92:935adef49ea4 | 51 | unsigned char changed; |
TickTock | 92:935adef49ea4 | 52 | unsigned short i; // was unsigned char |
TickTock | 92:935adef49ea4 | 53 | signed short packV; |
TickTock | 92:935adef49ea4 | 54 | signed short packA; |
TickTock | 40:0e6e71a7323f | 55 | signed long imWs_x4; |
garygid | 87:46ac3f2519d6 | 56 | unsigned short ts; |
TickTock | 85:5c27e88b3fbe | 57 | |
TickTock | 36:dbd39c315258 | 58 | secsNoMsg=0; // reset deadman switch |
garygid | 87:46ac3f2519d6 | 59 | if(debugMode||(skin==ggSkin)){ |
garygid | 87:46ac3f2519d6 | 60 | // code to insert actual number of dropped frames for overrun debug - skiped in normal mode to keep logcan short |
TickTock | 85:5c27e88b3fbe | 61 | if(logOpen){ |
TickTock | 85:5c27e88b3fbe | 62 | if(canRXmsg.id>0) { |
TickTock | 85:5c27e88b3fbe | 63 | // check to see if buffer is already full (read - write) = 1 |
TickTock | 85:5c27e88b3fbe | 64 | // actually the last buffer location cannot be used because then |
TickTock | 85:5c27e88b3fbe | 65 | // the buffer would look empty after writePointer++ |
TickTock | 85:5c27e88b3fbe | 66 | |
TickTock | 85:5c27e88b3fbe | 67 | //if (((writePointer+maxBufLen-readPointer)%maxBufLen)>(maxBufLen/16)) // modulo is slow? |
TickTock | 85:5c27e88b3fbe | 68 | |
garygid | 87:46ac3f2519d6 | 69 | // pointers are 0 through maxBufLen-1 |
TickTock | 85:5c27e88b3fbe | 70 | if( (readPointer - writePointer) == 1 || (writePointer - readPointer) == (maxBufLen - 1)) { |
TickTock | 85:5c27e88b3fbe | 71 | // the buffer is "full", so Lose this message |
TickTock | 85:5c27e88b3fbe | 72 | |
TickTock | 85:5c27e88b3fbe | 73 | // point to the last-stored message |
TickTock | 85:5c27e88b3fbe | 74 | int tempWritePointer = writePointer - 1 ; |
garygid | 87:46ac3f2519d6 | 75 | if( tempWritePointer < 0 ) tempWritePointer = maxBufLen - 1; |
TickTock | 85:5c27e88b3fbe | 76 | char strLost[9] ; |
TickTock | 85:5c27e88b3fbe | 77 | |
TickTock | 85:5c27e88b3fbe | 78 | if( nLost == 0 ) { |
TickTock | 85:5c27e88b3fbe | 79 | // this is the first message lost |
TickTock | 85:5c27e88b3fbe | 80 | // and we must overwrite the last message with an FFE comment message |
TickTock | 85:5c27e88b3fbe | 81 | // So, there will be two messages lost as the comment message is laid in. |
TickTock | 85:5c27e88b3fbe | 82 | nLost = 2; |
TickTock | 85:5c27e88b3fbe | 83 | sprintf(strLost,"%s","Lost0002"); // indicate two messages lost |
TickTock | 85:5c27e88b3fbe | 84 | |
TickTock | 85:5c27e88b3fbe | 85 | // overlay the last message with a "Lost0002" comment |
TickTock | 85:5c27e88b3fbe | 86 | writeBuffer[tempWritePointer][0]=0; |
garygid | 87:46ac3f2519d6 | 87 | // leave the ts of the overlaid message |
garygid | 87:46ac3f2519d6 | 88 | //writeBuffer[tempWritePointer][1]=(ts&0xff00)>>8; // Time Stamp (2 bytes_ |
garygid | 87:46ac3f2519d6 | 89 | //writeBuffer[tempWritePointer][2]=(ts&0x00ff); |
garygid | 87:46ac3f2519d6 | 90 | // force the MsgID to an Event Message |
TickTock | 85:5c27e88b3fbe | 91 | writeBuffer[tempWritePointer][3]=0xfe; // MsgID, low byte |
TickTock | 85:5c27e88b3fbe | 92 | writeBuffer[tempWritePointer][4]=0xff; // Len nibble, and MsgID high nibble |
garygid | 87:46ac3f2519d6 | 93 | // lay in the "Lost0002" text |
TickTock | 92:935adef49ea4 | 94 | for(i=5;i<13;i++){ |
TickTock | 85:5c27e88b3fbe | 95 | writeBuffer[tempWritePointer][i]= strLost[i-5]; |
TickTock | 85:5c27e88b3fbe | 96 | } |
TickTock | 85:5c27e88b3fbe | 97 | } else { |
garygid | 87:46ac3f2519d6 | 98 | // at least one message was previously lost |
TickTock | 85:5c27e88b3fbe | 99 | // increment the loat counter |
TickTock | 85:5c27e88b3fbe | 100 | nLost += 1; |
TickTock | 85:5c27e88b3fbe | 101 | |
TickTock | 85:5c27e88b3fbe | 102 | // lay the new count into the comment |
TickTock | 85:5c27e88b3fbe | 103 | sprintf(strLost,"%04d",nLost); |
TickTock | 92:935adef49ea4 | 104 | for(i=9;i<13;i++){ |
TickTock | 85:5c27e88b3fbe | 105 | writeBuffer[tempWritePointer][i]= strLost[i-9]; |
TickTock | 85:5c27e88b3fbe | 106 | } |
TickTock | 85:5c27e88b3fbe | 107 | } |
TickTock | 85:5c27e88b3fbe | 108 | } else { |
garygid | 87:46ac3f2519d6 | 109 | // there is room to insert the message |
TickTock | 85:5c27e88b3fbe | 110 | // get it inserted quickly |
garygid | 87:46ac3f2519d6 | 111 | ts=getTimeStamp(); |
TickTock | 85:5c27e88b3fbe | 112 | writeBuffer[writePointer][0]=mType; |
TickTock | 85:5c27e88b3fbe | 113 | writeBuffer[writePointer][1]=(ts&0xff00)>>8; // Time Stamp (2 bytes_ |
TickTock | 85:5c27e88b3fbe | 114 | writeBuffer[writePointer][2]=(ts&0x00ff); |
TickTock | 85:5c27e88b3fbe | 115 | writeBuffer[writePointer][3]=canRXmsg.id&0xff; // MsgID, low byte |
garygid | 87:46ac3f2519d6 | 116 | char sLen = canRXmsg.len ; |
garygid | 87:46ac3f2519d6 | 117 | writeBuffer[writePointer][4]=(canRXmsg.id>>8)+(sLen<<4); // Len nibble, and MsgID high nibble |
TickTock | 92:935adef49ea4 | 118 | for(i=0;i<8;i++){ // Is there a better way to do this? (writeBuffer[writePointer][i]=canRXmsg.data?) |
garygid | 87:46ac3f2519d6 | 119 | if(i<sLen) |
garygid | 87:46ac3f2519d6 | 120 | writeBuffer[writePointer][i+5]=canRXmsg.data[i]; |
garygid | 87:46ac3f2519d6 | 121 | else // i>=sLen |
garygid | 87:46ac3f2519d6 | 122 | // force unused data bytes to FF for CAN-Do compatibility |
garygid | 87:46ac3f2519d6 | 123 | writeBuffer[writePointer][i+5]=0xFF; |
TickTock | 85:5c27e88b3fbe | 124 | } |
garygid | 87:46ac3f2519d6 | 125 | |
TickTock | 85:5c27e88b3fbe | 126 | //-------------- |
garygid | 87:46ac3f2519d6 | 127 | // Note, this is not protected from the interrupt. |
garygid | 87:46ac3f2519d6 | 128 | // Due to the nLost code above, this no longer |
TickTock | 85:5c27e88b3fbe | 129 | // overflows to writePointer = readPointer |
TickTock | 85:5c27e88b3fbe | 130 | // which would make the buffer look empty |
TickTock | 85:5c27e88b3fbe | 131 | if (++writePointer >= maxBufLen) { |
TickTock | 85:5c27e88b3fbe | 132 | writePointer = 0; |
TickTock | 85:5c27e88b3fbe | 133 | led3 = !led3; |
TickTock | 85:5c27e88b3fbe | 134 | } |
TickTock | 85:5c27e88b3fbe | 135 | //-------------- |
TickTock | 85:5c27e88b3fbe | 136 | // log a local message if we had lost messages. gg - logcan |
TickTock | 85:5c27e88b3fbe | 137 | if( nLost > 0 ) { |
TickTock | 85:5c27e88b3fbe | 138 | // We previously lost messages that did not get into the buffer |
garygid | 87:46ac3f2519d6 | 139 | sprintf(sTemp,"-- Lost %d Messages.\n", nLost); |
TickTock | 93:c2402e8cd0e2 | 140 | printMsg(sTemp); // write buffer overrun |
garygid | 87:46ac3f2519d6 | 141 | //spkr.beep(500,0.25); |
TickTock | 85:5c27e88b3fbe | 142 | |
TickTock | 85:5c27e88b3fbe | 143 | nLost = 0 ; |
TickTock | 85:5c27e88b3fbe | 144 | } |
TickTock | 85:5c27e88b3fbe | 145 | //-------------- |
TickTock | 85:5c27e88b3fbe | 146 | } |
TickTock | 83:52b1f330a62d | 147 | } |
TickTock | 85:5c27e88b3fbe | 148 | } |
TickTock | 92:935adef49ea4 | 149 | }else{ // not debugMode - keep code short |
TickTock | 85:5c27e88b3fbe | 150 | if(logOpen){ |
TickTock | 93:c2402e8cd0e2 | 151 | NVIC_DisableIRQ(CAN_IRQn); // Block interrupts until write pointer assigned |
TickTock | 93:c2402e8cd0e2 | 152 | int localWritePointer = writePointer++; // create local copy to make logCan reentrant |
TickTock | 93:c2402e8cd0e2 | 153 | // note that the static variables do not prevent safe reentry |
TickTock | 93:c2402e8cd0e2 | 154 | // since they are only used for msgId<0x800 which will never interrupt |
TickTock | 93:c2402e8cd0e2 | 155 | // another msgId<0x800 (both CANbusses are same priority) |
TickTock | 93:c2402e8cd0e2 | 156 | if (writePointer >= maxBufLen) { |
TickTock | 93:c2402e8cd0e2 | 157 | writePointer = 0; |
TickTock | 93:c2402e8cd0e2 | 158 | led3 = !led3; |
TickTock | 93:c2402e8cd0e2 | 159 | } |
TickTock | 93:c2402e8cd0e2 | 160 | NVIC_EnableIRQ(CAN_IRQn); // Unblock interrupts once local pointer set and global pointer incremented |
TickTock | 93:c2402e8cd0e2 | 161 | ts=getTimeStamp(); |
TickTock | 93:c2402e8cd0e2 | 162 | writeBuffer[localWritePointer][0]=mType; |
TickTock | 93:c2402e8cd0e2 | 163 | writeBuffer[localWritePointer][1]=(ts&0xff00)>>8; |
TickTock | 93:c2402e8cd0e2 | 164 | writeBuffer[localWritePointer][2]=(ts&0x00ff); |
TickTock | 93:c2402e8cd0e2 | 165 | writeBuffer[localWritePointer][3]=canRXmsg.id&0xff; |
TickTock | 93:c2402e8cd0e2 | 166 | writeBuffer[localWritePointer][4]=(canRXmsg.id>>8)+(canRXmsg.len<<4); |
TickTock | 93:c2402e8cd0e2 | 167 | for(i=5;i<13;i++){ // Is there a better way to do this? (writeBuffer[localWritePointer][5]=canRXmsg.data?) |
TickTock | 93:c2402e8cd0e2 | 168 | writeBuffer[localWritePointer][i]=canRXmsg.data[i-5]; |
TickTock | 93:c2402e8cd0e2 | 169 | } |
TickTock | 93:c2402e8cd0e2 | 170 | if (writePointer==readPointer) { |
TickTock | 93:c2402e8cd0e2 | 171 | // Just caught up to read pointer |
TickTock | 93:c2402e8cd0e2 | 172 | sprintf(sTemp,"Write buffer overrun.\n"); |
TickTock | 93:c2402e8cd0e2 | 173 | printMsg(sTemp); // write buffer overrun |
TickTock | 93:c2402e8cd0e2 | 174 | spkr.beep(500,0.25); |
TickTock | 13:62e0f7f39ff5 | 175 | } |
TickTock | 13:62e0f7f39ff5 | 176 | } |
TickTock | 37:fea2c1d52c5f | 177 | } |
TickTock | 40:0e6e71a7323f | 178 | |
TickTock | 83:52b1f330a62d | 179 | if(canRXmsg.id<0x800){ // Block FFE and FFF messages |
TickTock | 83:52b1f330a62d | 180 | if(indexLastMsg[canRXmsg.id]==0) { //Check if no entry |
TickTock | 92:935adef49ea4 | 181 | //ii=ii<99?ii+1:0; // Should never wrap - less than 100 different messages ever used |
garygid | 87:46ac3f2519d6 | 182 | if(ii<99) { |
TickTock | 92:935adef49ea4 | 183 | //indexLastMsg[canRXmsg.id]=ii; //Create entry if first message |
garygid | 87:46ac3f2519d6 | 184 | indexLastMsg[canRXmsg.id]=++ii; //Create entry for first MsgID occurance |
garygid | 87:46ac3f2519d6 | 185 | // ii max is 99 here |
garygid | 87:46ac3f2519d6 | 186 | } else { |
garygid | 87:46ac3f2519d6 | 187 | // the ii array is full, more than 100 MsgIDs found |
garygid | 87:46ac3f2519d6 | 188 | if(ii==99) { |
TickTock | 92:935adef49ea4 | 189 | ii++; // step to 100 to log only one error |
garygid | 87:46ac3f2519d6 | 190 | sprintf(sTemp,"MsgID buffer overrun.\n"); |
TickTock | 93:c2402e8cd0e2 | 191 | printMsg(sTemp); // write buffer overrun |
garygid | 87:46ac3f2519d6 | 192 | } |
garygid | 87:46ac3f2519d6 | 193 | } |
TickTock | 83:52b1f330a62d | 194 | } |
garygid | 87:46ac3f2519d6 | 195 | |
garygid | 87:46ac3f2519d6 | 196 | //---------------- |
TickTock | 85:5c27e88b3fbe | 197 | if(dMode[0]==changedScreen||dMode[1]==changedScreen){// Skip if not using (for execution speed) |
TickTock | 83:52b1f330a62d | 198 | changed=msgChanged[indexLastMsg[canRXmsg.id]]; |
TickTock | 85:5c27e88b3fbe | 199 | // This is cleared in the main loop when reset button is touched |
TickTock | 92:935adef49ea4 | 200 | for(i=0;i<8;i++){ |
TickTock | 83:52b1f330a62d | 201 | if(lastMsg[indexLastMsg[canRXmsg.id]].data[i]!=canRXmsg.data[i]){ |
TickTock | 83:52b1f330a62d | 202 | changed |= 1<<i; |
garygid | 79:24f1793171e7 | 203 | } |
TickTock | 13:62e0f7f39ff5 | 204 | } |
TickTock | 83:52b1f330a62d | 205 | msgChanged[indexLastMsg[canRXmsg.id]]=changed; |
TickTock | 13:62e0f7f39ff5 | 206 | } |
garygid | 79:24f1793171e7 | 207 | |
TickTock | 83:52b1f330a62d | 208 | lastMsg[indexLastMsg[canRXmsg.id]]=canRXmsg; //Store in table |
garygid | 87:46ac3f2519d6 | 209 | |
garygid | 87:46ac3f2519d6 | 210 | //------------------- |
TickTock | 83:52b1f330a62d | 211 | //Miscellaneous on-recieve operations below |
TickTock | 93:c2402e8cd0e2 | 212 | if((mType==1)&&(canRXmsg.id==0x7bb)){ // is battery data? Need to store all responses |
TickTock | 83:52b1f330a62d | 213 | if(canRXmsg.data[0]<0x20){ |
garygid | 87:46ac3f2519d6 | 214 | if(canRXmsg.data[3]==2){//Group 2 = cellpair data |
garygid | 87:46ac3f2519d6 | 215 | bdi=BatDataBaseG2; // index offset for CP data (uses 00 - 1C) |
garygid | 87:46ac3f2519d6 | 216 | sprintf(sTemp," Getting cell pair data\n"); |
TickTock | 93:c2402e8cd0e2 | 217 | printMsg(sTemp); |
garygid | 87:46ac3f2519d6 | 218 | |
garygid | 87:46ac3f2519d6 | 219 | }else if(canRXmsg.data[3]==4){//Group 4 = temperature data |
garygid | 87:46ac3f2519d6 | 220 | bdi=BatDataBaseG4; // index offset for Temperature data (uses 20 - 22) |
garygid | 87:46ac3f2519d6 | 221 | sprintf(sTemp," Getting temperature data\n"); |
TickTock | 93:c2402e8cd0e2 | 222 | printMsg(sTemp); |
garygid | 87:46ac3f2519d6 | 223 | |
garygid | 87:46ac3f2519d6 | 224 | }else if(canRXmsg.data[3]==1){//Group 1 data |
garygid | 87:46ac3f2519d6 | 225 | bdi=BatDataBaseG1; // index offset for Group 1 data (uses 20 - 22) |
TickTock | 93:c2402e8cd0e2 | 226 | sprintf(sTemp," Getting Group 1 data\n"); |
TickTock | 93:c2402e8cd0e2 | 227 | printMsg(sTemp); |
garygid | 87:46ac3f2519d6 | 228 | |
garygid | 87:46ac3f2519d6 | 229 | }else if(canRXmsg.data[3]==3){//Group 3 data |
garygid | 87:46ac3f2519d6 | 230 | bdi=BatDataBaseG3; // index offset for Group 3 data (uses 20 - 22) |
garygid | 87:46ac3f2519d6 | 231 | sprintf(sTemp," Getting Group 3 data\n"); |
TickTock | 93:c2402e8cd0e2 | 232 | printMsg(sTemp); |
garygid | 87:46ac3f2519d6 | 233 | |
garygid | 87:46ac3f2519d6 | 234 | }else if(canRXmsg.data[3]==5){//Group 5 data |
garygid | 87:46ac3f2519d6 | 235 | bdi=BatDataBaseG5; // index offset for Group 5 data (uses 20 - 22) |
garygid | 87:46ac3f2519d6 | 236 | sprintf(sTemp," Getting Group 5 data\n"); |
TickTock | 93:c2402e8cd0e2 | 237 | printMsg(sTemp); |
garygid | 87:46ac3f2519d6 | 238 | |
TickTock | 83:52b1f330a62d | 239 | }else bdi=0xff; // ignore other messages (for now) |
TickTock | 83:52b1f330a62d | 240 | lasti=0; |
TickTock | 83:52b1f330a62d | 241 | } |
garygid | 87:46ac3f2519d6 | 242 | |
TickTock | 83:52b1f330a62d | 243 | if(bdi<0xff){ |
TickTock | 83:52b1f330a62d | 244 | i=canRXmsg.data[0]&0x0f; //lower nibble of D0 is index |
TickTock | 83:52b1f330a62d | 245 | if(lasti>i){ //detect rollover and offset index appropriately |
garygid | 87:46ac3f2519d6 | 246 | bdi=BatDataBaseG2 + 0x10; // only for CP data |
TickTock | 83:52b1f330a62d | 247 | } |
TickTock | 83:52b1f330a62d | 248 | lasti=i; //remember the msb to detect rollover next time around |
TickTock | 83:52b1f330a62d | 249 | i+=bdi; |
garygid | 87:46ac3f2519d6 | 250 | //------- |
garygid | 87:46ac3f2519d6 | 251 | if(i==BatDataBaseG4+2){ // Last of Temperature data |
TickTock | 83:52b1f330a62d | 252 | logCP=yesBattLog; // Only log if logging enabled |
TickTock | 83:52b1f330a62d | 253 | showCP=true; // Always show |
TickTock | 95:248b3c25a7df | 254 | battTemp_x4=battData[224+5]+battData[224+8]+battData[224+11]+battData[224+14]; |
TickTock | 83:52b1f330a62d | 255 | } |
garygid | 87:46ac3f2519d6 | 256 | //------- |
TickTock | 83:52b1f330a62d | 257 | i*=7; |
garygid | 87:46ac3f2519d6 | 258 | //if(i<0xfa){ // Is there a better way to do this? |
garygid | 87:46ac3f2519d6 | 259 | if(i+6 < BatDataBufMax) { |
TickTock | 83:52b1f330a62d | 260 | battData[i+0]=canRXmsg.data[1]; |
TickTock | 83:52b1f330a62d | 261 | battData[i+1]=canRXmsg.data[2]; |
TickTock | 83:52b1f330a62d | 262 | battData[i+2]=canRXmsg.data[3]; |
TickTock | 83:52b1f330a62d | 263 | battData[i+3]=canRXmsg.data[4]; |
TickTock | 83:52b1f330a62d | 264 | battData[i+4]=canRXmsg.data[5]; |
TickTock | 83:52b1f330a62d | 265 | battData[i+5]=canRXmsg.data[6]; |
TickTock | 83:52b1f330a62d | 266 | battData[i+6]=canRXmsg.data[7]; |
TickTock | 83:52b1f330a62d | 267 | } |
TickTock | 83:52b1f330a62d | 268 | } |
TickTock | 83:52b1f330a62d | 269 | }else if((mType==1)&&(canRXmsg.id==0x1db)){ //Battery Volts and Amps |
TickTock | 83:52b1f330a62d | 270 | packV=((canRXmsg.data[2]<<2)|(canRXmsg.data[3]>>6)); // 1 LSB = 0.5V |
TickTock | 83:52b1f330a62d | 271 | packA=((canRXmsg.data[0]<<3)|(canRXmsg.data[1]>>5)); // 1 LSB = 0.5A |
TickTock | 83:52b1f330a62d | 272 | if(packA>0x03ff){ |
TickTock | 83:52b1f330a62d | 273 | packA|=0xf800;//extend sign; |
TickTock | 83:52b1f330a62d | 274 | } |
TickTock | 83:52b1f330a62d | 275 | packA -= 1; //Slight correction to value required (unique to my Leaf?) |
TickTock | 83:52b1f330a62d | 276 | imWs_x4 = packV; // Volts*milliSeconds*2 |
TickTock | 83:52b1f330a62d | 277 | imWs_x4 *= -packA; // milliWattseconds*4 |
TickTock | 83:52b1f330a62d | 278 | if (!((imotorRPM<2)&&(imWs_x4<0))){ //Ignore if charging from wall |
TickTock | 83:52b1f330a62d | 279 | mWs_x4 += imWs_x4; // total mWs_x4 |
TickTock | 92:935adef49ea4 | 280 | numWsamples++; |
TickTock | 83:52b1f330a62d | 281 | } |
TickTock | 83:52b1f330a62d | 282 | }else if((mType==1)&&(canRXmsg.id==0x1da)){ //Motor Speed |
TickTock | 83:52b1f330a62d | 283 | imotorRPM=((canRXmsg.data[4]<<8)|(canRXmsg.data[5])); |
TickTock | 83:52b1f330a62d | 284 | if(imotorRPM<0){ // take absolute value |
TickTock | 83:52b1f330a62d | 285 | imotorRPM=-imotorRPM; |
TickTock | 83:52b1f330a62d | 286 | } |
TickTock | 83:52b1f330a62d | 287 | motorRPM+=imotorRPM; |
TickTock | 92:935adef49ea4 | 288 | numSsamples++; |
TickTock | 37:fea2c1d52c5f | 289 | } |
TickTock | 37:fea2c1d52c5f | 290 | } |
TickTock | 13:62e0f7f39ff5 | 291 | } |
TickTock | 13:62e0f7f39ff5 | 292 | |
garygid | 87:46ac3f2519d6 | 293 | //----------------------------- |
TickTock | 13:62e0f7f39ff5 | 294 | void logTS () { |
TickTock | 13:62e0f7f39ff5 | 295 | CANMessage tsMsg; |
TickTock | 13:62e0f7f39ff5 | 296 | unsigned long secs = time(NULL); // seconds past 12:00:00 AM 1 Jan 1900 |
garygid | 69:6bfdfc002036 | 297 | // NOTE: In Mbed, I believe that this is seconds past start of 1970, not 1900 |
garygid | 69:6bfdfc002036 | 298 | // but this is good, since seconds past 1970 is what CAN-Do expects. GG - Date Time |
TickTock | 13:62e0f7f39ff5 | 299 | tsMsg.id=0xfff; |
TickTock | 13:62e0f7f39ff5 | 300 | tsMsg.len=0xf; |
garygid | 69:6bfdfc002036 | 301 | tsMsg.data[0]=secs&0xff; |
TickTock | 13:62e0f7f39ff5 | 302 | tsMsg.data[1]=(secs>>8)&0xff; |
TickTock | 13:62e0f7f39ff5 | 303 | tsMsg.data[2]=(secs>>16)&0xff; |
garygid | 69:6bfdfc002036 | 304 | tsMsg.data[3]=(secs>>24)&0xff; |
garygid | 69:6bfdfc002036 | 305 | tsMsg.data[4]=0; // 0xff; gg - Date Time |
garygid | 69:6bfdfc002036 | 306 | tsMsg.data[5]=0; // 0xff; for CAN-Do |
garygid | 69:6bfdfc002036 | 307 | tsMsg.data[6]=0; // 0xff; |
TickTock | 13:62e0f7f39ff5 | 308 | tsMsg.data[7]=0xff; |
garygid | 69:6bfdfc002036 | 309 | logCan(0,tsMsg); // Date-Time |
garygid | 69:6bfdfc002036 | 310 | } |
garygid | 69:6bfdfc002036 | 311 | |
TickTock | 93:c2402e8cd0e2 | 312 | void logEvent (char * errMsg) { |
garygid | 69:6bfdfc002036 | 313 | // log CAN-Do 8-character Pseudo Message |
garygid | 69:6bfdfc002036 | 314 | CANMessage tsMsg; |
garygid | 69:6bfdfc002036 | 315 | tsMsg.id=0xffe; // pseudo Message to CAN-Do log |
garygid | 69:6bfdfc002036 | 316 | tsMsg.len=0xf; |
TickTock | 92:935adef49ea4 | 317 | int iMsgLen = strlen(errMsg); |
garygid | 69:6bfdfc002036 | 318 | // 8 character message compatible with CAN-Do |
TickTock | 92:935adef49ea4 | 319 | for(int i=0; i<8; i++){ |
garygid | 69:6bfdfc002036 | 320 | tsMsg.data[i]=' '; |
TickTock | 92:935adef49ea4 | 321 | if( i < iMsgLen ) tsMsg.data[i]=errMsg[i]; |
garygid | 69:6bfdfc002036 | 322 | } |
garygid | 69:6bfdfc002036 | 323 | logCan(0,tsMsg); // FFE Comment Message |
TickTock | 13:62e0f7f39ff5 | 324 | } |
TickTock | 13:62e0f7f39ff5 | 325 | |
TickTock | 78:a383971fe02f | 326 | void sendReq() { |
TickTock | 78:a383971fe02f | 327 | static char data[8] = {0x02, 0x21, 0x01, 0xff, 0xff, 0xff, 0xff, 0xff}; |
TickTock | 78:a383971fe02f | 328 | if(reqMsgCnt<99){ |
TickTock | 92:935adef49ea4 | 329 | switch (reqMsgCnt){ |
TickTock | 92:935adef49ea4 | 330 | case 0: |
TickTock | 78:a383971fe02f | 331 | can1.monitor(false); // set to active mode |
TickTock | 78:a383971fe02f | 332 | can1SleepMode = 0; // enable TX |
TickTock | 83:52b1f330a62d | 333 | data[0]=0x02; //change to request group 1 |
TickTock | 78:a383971fe02f | 334 | data[1]=0x21; |
TickTock | 78:a383971fe02f | 335 | data[2]=0x01; |
TickTock | 78:a383971fe02f | 336 | break; |
TickTock | 92:935adef49ea4 | 337 | case 6: // group 1 has 6 frames |
TickTock | 78:a383971fe02f | 338 | can1.monitor(false); // set to active mode |
TickTock | 78:a383971fe02f | 339 | can1SleepMode = 0; // enable TX |
TickTock | 83:52b1f330a62d | 340 | data[0]=0x02; //change to request group 2 (cp data) |
TickTock | 78:a383971fe02f | 341 | data[1]=0x21; |
TickTock | 78:a383971fe02f | 342 | data[2]=0x02; |
TickTock | 78:a383971fe02f | 343 | break; |
TickTock | 92:935adef49ea4 | 344 | case 35: // group 2 has 29 frames |
TickTock | 83:52b1f330a62d | 345 | data[0]=0x02; //change to request group 3 |
TickTock | 78:a383971fe02f | 346 | data[1]=0x21; |
TickTock | 78:a383971fe02f | 347 | data[2]=0x03; |
TickTock | 78:a383971fe02f | 348 | break; |
TickTock | 92:935adef49ea4 | 349 | case 40: // group 3 has 5 frames |
TickTock | 83:52b1f330a62d | 350 | data[0]=0x02; //change to request group 4 (temperature) |
TickTock | 78:a383971fe02f | 351 | data[1]=0x21; |
TickTock | 78:a383971fe02f | 352 | data[2]=0x04; |
TickTock | 78:a383971fe02f | 353 | break; |
TickTock | 92:935adef49ea4 | 354 | case 43: // group 4 has 3 frames |
TickTock | 83:52b1f330a62d | 355 | data[0]=0x02; //change to request group 5 |
TickTock | 78:a383971fe02f | 356 | data[1]=0x21; |
TickTock | 78:a383971fe02f | 357 | data[2]=0x05; |
TickTock | 78:a383971fe02f | 358 | break; |
TickTock | 92:935adef49ea4 | 359 | case 54: // group 5 has 11 frames |
TickTock | 78:a383971fe02f | 360 | reqMsgCnt = 99; |
TickTock | 78:a383971fe02f | 361 | can1SleepMode = 1; // disable TX |
TickTock | 78:a383971fe02f | 362 | can1.monitor(true); // set to snoop mode |
TickTock | 83:52b1f330a62d | 363 | msgReq.detach(); // stop ticker |
TickTock | 78:a383971fe02f | 364 | default: |
TickTock | 78:a383971fe02f | 365 | data[0]=0x30; //change to request next line message |
TickTock | 78:a383971fe02f | 366 | data[1]=0x01; |
TickTock | 78:a383971fe02f | 367 | data[2]=0x00; |
TickTock | 78:a383971fe02f | 368 | } |
TickTock | 78:a383971fe02f | 369 | can1.write(CANMessage(0x79b, data, 8)); |
TickTock | 92:935adef49ea4 | 370 | reqMsgCnt++; |
TickTock | 78:a383971fe02f | 371 | } |
TickTock | 78:a383971fe02f | 372 | } |
TickTock | 78:a383971fe02f | 373 | |
TickTock | 78:a383971fe02f | 374 | void autoPollISR(){ |
TickTock | 94:c3a14b3975d6 | 375 | char sTemp[40]; // just for debug |
TickTock | 94:c3a14b3975d6 | 376 | sprintf(sTemp,"Requesting cp data\n"); // just for debug |
TickTock | 94:c3a14b3975d6 | 377 | printMsg(sTemp); // just for debug |
TickTock | 78:a383971fe02f | 378 | reqMsgCnt = 0; //reset message counter |
TickTock | 94:c3a14b3975d6 | 379 | msgReq.attach(&sendReq,0.015); |
TickTock | 78:a383971fe02f | 380 | } |
garygid | 87:46ac3f2519d6 | 381 | |
TickTock | 36:dbd39c315258 | 382 | void playbackISR() { //Used for autoplayback |
TickTock | 36:dbd39c315258 | 383 | step=true; |
TickTock | 36:dbd39c315258 | 384 | } |
TickTock | 36:dbd39c315258 | 385 | |
TickTock | 36:dbd39c315258 | 386 | void doNothing(){ //CAN deattach work-around |
TickTock | 36:dbd39c315258 | 387 | } |
TickTock | 36:dbd39c315258 | 388 | |
TickTock | 13:62e0f7f39ff5 | 389 | void recieve1() { |
TickTock | 13:62e0f7f39ff5 | 390 | CANMessage msg1; |
TickTock | 13:62e0f7f39ff5 | 391 | can1.read(msg1); |
garygid | 69:6bfdfc002036 | 392 | |
garygid | 69:6bfdfc002036 | 393 | if( ZeroSecTick ) { ZeroSecTick = false; logTS(); } // gg - 0-second EV bus |
garygid | 69:6bfdfc002036 | 394 | |
garygid | 69:6bfdfc002036 | 395 | logCan(1, msg1); // EVcan Message Received |
TickTock | 13:62e0f7f39ff5 | 396 | led1 = !led1; |
TickTock | 13:62e0f7f39ff5 | 397 | } |
TickTock | 13:62e0f7f39ff5 | 398 | |
TickTock | 13:62e0f7f39ff5 | 399 | void recieve2() { |
TickTock | 13:62e0f7f39ff5 | 400 | CANMessage msg2; |
TickTock | 13:62e0f7f39ff5 | 401 | can2.read(msg2); |
garygid | 69:6bfdfc002036 | 402 | |
garygid | 69:6bfdfc002036 | 403 | if( ZeroSecTick ) { ZeroSecTick = false; logTS(); } // gg - 0-second EV bus |
garygid | 69:6bfdfc002036 | 404 | |
garygid | 69:6bfdfc002036 | 405 | logCan(2, msg2); // CARcan Message Received |
TickTock | 13:62e0f7f39ff5 | 406 | led2 = !led2; |
TickTock | 13:62e0f7f39ff5 | 407 | } |
TickTock | 13:62e0f7f39ff5 | 408 | |
TickTock | 22:a43df3905863 | 409 | unsigned char buttonX(unsigned short X, unsigned char columns) { |
TickTock | 22:a43df3905863 | 410 | unsigned char val = X*columns/320; |
TickTock | 22:a43df3905863 | 411 | return val; |
TickTock | 22:a43df3905863 | 412 | } |
TickTock | 22:a43df3905863 | 413 | |
TickTock | 22:a43df3905863 | 414 | unsigned char buttonY(unsigned short Y, unsigned char rows) { |
TickTock | 22:a43df3905863 | 415 | unsigned short val = Y*rows/240; |
TickTock | 22:a43df3905863 | 416 | return val; |
TickTock | 22:a43df3905863 | 417 | } |
TickTock | 23:cd03f9c3395e | 418 | |
TickTock | 23:cd03f9c3395e | 419 | void saveConfig(){ |
TickTock | 23:cd03f9c3395e | 420 | FILE *cfile; |
TickTock | 23:cd03f9c3395e | 421 | cfile = fopen("/local/config.txt", "w"); |
garygid | 87:46ac3f2519d6 | 422 | //fprintf(cfile,"format 3\r\n"); |
garygid | 87:46ac3f2519d6 | 423 | fprintf(cfile,"format 4\r\n"); |
TickTock | 23:cd03f9c3395e | 424 | fprintf(cfile,"x0_off %d\r\n",tt.x0_off); |
TickTock | 23:cd03f9c3395e | 425 | fprintf(cfile,"y0_off %d\r\n",tt.y0_off); |
TickTock | 23:cd03f9c3395e | 426 | fprintf(cfile,"x0_pp %d\r\n",tt.x0_pp); |
TickTock | 23:cd03f9c3395e | 427 | fprintf(cfile,"y0_pp %d\r\n",tt.y0_pp); |
TickTock | 23:cd03f9c3395e | 428 | fprintf(cfile,"x1_off %d\r\n",tt.x1_off); |
TickTock | 23:cd03f9c3395e | 429 | fprintf(cfile,"y1_off %d\r\n",tt.y1_off); |
TickTock | 23:cd03f9c3395e | 430 | fprintf(cfile,"x1_pp %d\r\n",tt.x1_pp); |
TickTock | 23:cd03f9c3395e | 431 | fprintf(cfile,"y1_pp %d\r\n",tt.y1_pp); |
TickTock | 23:cd03f9c3395e | 432 | fprintf(cfile,"x_mid %d\r\n",tt.x_mid); |
TickTock | 26:462ccb580472 | 433 | if (dMode[0]==config1Screen) |
TickTock | 41:8d4609ea7259 | 434 | fprintf(cfile,"dMode0 %d\r\n",mainScreen); |
TickTock | 26:462ccb580472 | 435 | else |
TickTock | 26:462ccb580472 | 436 | fprintf(cfile,"dMode0 %d\r\n",dMode[0]); |
TickTock | 26:462ccb580472 | 437 | if (dMode[1]==config1Screen) |
TickTock | 41:8d4609ea7259 | 438 | fprintf(cfile,"dMode1 %d\r\n",mainScreen); |
TickTock | 26:462ccb580472 | 439 | else |
TickTock | 26:462ccb580472 | 440 | fprintf(cfile,"dMode1 %d\r\n",dMode[1]); |
TickTock | 35:5acbd8a64a89 | 441 | fprintf(cfile,"ledHi %4.3f\r\n",ledHi); |
TickTock | 35:5acbd8a64a89 | 442 | fprintf(cfile,"ledLo %4.3f\r\n",ledLo); |
TickTock | 35:5acbd8a64a89 | 443 | fprintf(cfile,"pollInt %d\r\n",pollInt); |
TickTock | 35:5acbd8a64a89 | 444 | fprintf(cfile,"scale12V %4.2f\r\n",scale12V); |
TickTock | 48:d1ce92104a1f | 445 | fprintf(cfile,"skin %d\r\n",skin); |
TickTock | 50:83d5864c64a0 | 446 | fprintf(cfile,"dtePeriod %d\r\n",dtePeriod); |
garygid | 87:46ac3f2519d6 | 447 | fprintf(cfile,"DebugMode %d\r\n",(debugMode?1:0)); |
TickTock | 23:cd03f9c3395e | 448 | fclose(cfile); |
TickTock | 23:cd03f9c3395e | 449 | } |
TickTock | 23:cd03f9c3395e | 450 | |
TickTock | 23:cd03f9c3395e | 451 | void readConfig(){ |
TickTock | 23:cd03f9c3395e | 452 | FILE *cfile; |
TickTock | 23:cd03f9c3395e | 453 | int ff; |
TickTock | 23:cd03f9c3395e | 454 | char sTemp[40]; |
TickTock | 23:cd03f9c3395e | 455 | cfile = fopen("/local/config.txt", "r"); |
TickTock | 23:cd03f9c3395e | 456 | if (cfile==NULL){ // if doesn't exist --> create |
TickTock | 23:cd03f9c3395e | 457 | sprintf(sTemp,"No config file found.\n"); |
TickTock | 93:c2402e8cd0e2 | 458 | printMsg(sTemp); // no config file |
TickTock | 23:cd03f9c3395e | 459 | sprintf(sTemp,"Calibrating touch screen.\n"); |
TickTock | 93:c2402e8cd0e2 | 460 | printMsg(sTemp); // calibrating |
TickTock | 23:cd03f9c3395e | 461 | //tt.setcal(5570, 34030, 80, 108, 33700, 5780, 82, 108, 32500);// bypass calibration using my values |
TickTock | 23:cd03f9c3395e | 462 | tt.calibrate(); // run touchscreen calibration routine |
garygid | 58:4d06288d75a2 | 463 | // NOTE: calibrates screen 1 first, then screen 0. |
TickTock | 23:cd03f9c3395e | 464 | saveConfig(); |
TickTock | 23:cd03f9c3395e | 465 | } else { |
TickTock | 48:d1ce92104a1f | 466 | ledHi = 0.823; |
TickTock | 48:d1ce92104a1f | 467 | ledLo = 0.1; |
TickTock | 48:d1ce92104a1f | 468 | pollInt = 300; |
TickTock | 48:d1ce92104a1f | 469 | scale12V = 16.2; |
TickTock | 48:d1ce92104a1f | 470 | skin = ttSkin; |
TickTock | 48:d1ce92104a1f | 471 | fscanf(cfile, "format %d\r\n", &ff ) ; |
TickTock | 23:cd03f9c3395e | 472 | fscanf(cfile, "x0_off %d\r\n", &tt.x0_off ) ; |
TickTock | 23:cd03f9c3395e | 473 | fscanf(cfile, "y0_off %d\r\n", &tt.y0_off ) ; |
TickTock | 23:cd03f9c3395e | 474 | fscanf(cfile, "x0_pp %d\r\n", &tt.x0_pp ) ; |
TickTock | 23:cd03f9c3395e | 475 | fscanf(cfile, "y0_pp %d\r\n", &tt.y0_pp ) ; |
TickTock | 23:cd03f9c3395e | 476 | fscanf(cfile, "x1_off %d\r\n", &tt.x1_off ) ; |
TickTock | 23:cd03f9c3395e | 477 | fscanf(cfile, "y1_off %d\r\n", &tt.y1_off ) ; |
TickTock | 23:cd03f9c3395e | 478 | fscanf(cfile, "x1_pp %d\r\n", &tt.x1_pp ) ; |
TickTock | 23:cd03f9c3395e | 479 | fscanf(cfile, "y1_pp %d\r\n", &tt.y1_pp ) ; |
TickTock | 23:cd03f9c3395e | 480 | fscanf(cfile, "x_mid %d\r\n", &tt.x_mid ) ; |
TickTock | 26:462ccb580472 | 481 | fscanf(cfile, "dMode0 %d\r\n", &dMode[0] ) ; |
TickTock | 26:462ccb580472 | 482 | fscanf(cfile, "dMode1 %d\r\n", &dMode[1] ) ; |
TickTock | 35:5acbd8a64a89 | 483 | if(ff>1){ |
TickTock | 48:d1ce92104a1f | 484 | fscanf(cfile, "ledHi %f\r\n", &ledHi ) ; |
TickTock | 48:d1ce92104a1f | 485 | fscanf(cfile, "ledLo %f\r\n", &ledLo ) ; |
TickTock | 35:5acbd8a64a89 | 486 | fscanf(cfile, "pollInt %d\r\n", &pollInt ) ; |
TickTock | 48:d1ce92104a1f | 487 | fscanf(cfile, "scale12V %f\r\n", &scale12V ) ; |
TickTock | 48:d1ce92104a1f | 488 | } |
TickTock | 48:d1ce92104a1f | 489 | if(ff>2){ |
TickTock | 48:d1ce92104a1f | 490 | fscanf(cfile, "skin %d\r\n", &skin ) ; |
TickTock | 50:83d5864c64a0 | 491 | fscanf(cfile, "dtePeriod %d\r\n", &dtePeriod ) ; |
TickTock | 35:5acbd8a64a89 | 492 | } |
garygid | 87:46ac3f2519d6 | 493 | if(ff>3){ |
garygid | 87:46ac3f2519d6 | 494 | int iDebug ; |
garygid | 87:46ac3f2519d6 | 495 | fscanf(cfile, "DebugMode %d\r\n", &iDebug ) ; |
garygid | 87:46ac3f2519d6 | 496 | debugMode = (iDebug==1)?true:false ; |
garygid | 87:46ac3f2519d6 | 497 | } |
TickTock | 23:cd03f9c3395e | 498 | fclose(cfile); |
garygid | 87:46ac3f2519d6 | 499 | |
garygid | 87:46ac3f2519d6 | 500 | //if(ff<3){//If not latest format, save as latest format |
garygid | 87:46ac3f2519d6 | 501 | if(ff<4){//If not latest format, save as latest format |
TickTock | 35:5acbd8a64a89 | 502 | saveConfig(); |
TickTock | 48:d1ce92104a1f | 503 | sprintf(sTemp,"Config file format updated.\n"); |
TickTock | 93:c2402e8cd0e2 | 504 | printMsg(sTemp); // config forat updates |
TickTock | 48:d1ce92104a1f | 505 | } |
TickTock | 43:e7f6f80590e3 | 506 | sprintf(sTemp,"Config file loaded.\n"); |
TickTock | 93:c2402e8cd0e2 | 507 | printMsg(sTemp); // config file loaded |
TickTock | 23:cd03f9c3395e | 508 | } |
TickTock | 23:cd03f9c3395e | 509 | } |
TickTock | 25:ddf0ec209f03 | 510 | |
TickTock | 25:ddf0ec209f03 | 511 | void upDate(unsigned char field, bool upDownBar){ |
TickTock | 25:ddf0ec209f03 | 512 | struct tm t; // pointer to a static tm structure |
TickTock | 25:ddf0ec209f03 | 513 | time_t seconds ; |
TickTock | 25:ddf0ec209f03 | 514 | seconds = time(NULL); |
TickTock | 25:ddf0ec209f03 | 515 | t = *localtime(&seconds) ; |
TickTock | 25:ddf0ec209f03 | 516 | switch(field){ |
TickTock | 25:ddf0ec209f03 | 517 | case 0: // year |
TickTock | 25:ddf0ec209f03 | 518 | if (upDownBar) { |
TickTock | 25:ddf0ec209f03 | 519 | t.tm_year = t.tm_year+1; |
TickTock | 25:ddf0ec209f03 | 520 | } else { |
TickTock | 25:ddf0ec209f03 | 521 | t.tm_year = t.tm_year-1; |
TickTock | 25:ddf0ec209f03 | 522 | } |
TickTock | 25:ddf0ec209f03 | 523 | break; |
TickTock | 25:ddf0ec209f03 | 524 | case 1: // month |
TickTock | 25:ddf0ec209f03 | 525 | if (upDownBar) { |
TickTock | 25:ddf0ec209f03 | 526 | t.tm_mon = (t.tm_mon<12)?t.tm_mon+1:1; |
TickTock | 25:ddf0ec209f03 | 527 | } else { |
TickTock | 25:ddf0ec209f03 | 528 | t.tm_mon = (t.tm_mon>2)?t.tm_mon-1:12; |
TickTock | 25:ddf0ec209f03 | 529 | } |
TickTock | 25:ddf0ec209f03 | 530 | break; |
TickTock | 25:ddf0ec209f03 | 531 | case 2: // day |
TickTock | 25:ddf0ec209f03 | 532 | if (upDownBar) { |
TickTock | 25:ddf0ec209f03 | 533 | t.tm_mday = (t.tm_mday<31)?t.tm_mday+1:1; |
TickTock | 25:ddf0ec209f03 | 534 | } else { |
TickTock | 25:ddf0ec209f03 | 535 | t.tm_mday = (t.tm_mday>2)?t.tm_mday-1:31; |
TickTock | 25:ddf0ec209f03 | 536 | } |
TickTock | 25:ddf0ec209f03 | 537 | break; |
TickTock | 25:ddf0ec209f03 | 538 | case 3: // hour |
TickTock | 25:ddf0ec209f03 | 539 | if (upDownBar) { |
TickTock | 25:ddf0ec209f03 | 540 | t.tm_hour = (t.tm_hour<23)?t.tm_hour+1:0; |
TickTock | 25:ddf0ec209f03 | 541 | } else { |
TickTock | 25:ddf0ec209f03 | 542 | t.tm_hour = (t.tm_hour>1)?t.tm_hour-1:23; |
TickTock | 25:ddf0ec209f03 | 543 | } |
TickTock | 25:ddf0ec209f03 | 544 | break; |
TickTock | 25:ddf0ec209f03 | 545 | case 4: // minute |
TickTock | 25:ddf0ec209f03 | 546 | if (upDownBar) { |
TickTock | 25:ddf0ec209f03 | 547 | t.tm_min = (t.tm_min<59)?t.tm_min+1:0; |
TickTock | 25:ddf0ec209f03 | 548 | } else { |
TickTock | 25:ddf0ec209f03 | 549 | t.tm_min = (t.tm_min>1)?t.tm_min-1:59; |
TickTock | 25:ddf0ec209f03 | 550 | } |
TickTock | 25:ddf0ec209f03 | 551 | break; |
TickTock | 25:ddf0ec209f03 | 552 | case 5: // second |
TickTock | 25:ddf0ec209f03 | 553 | if (upDownBar) { |
TickTock | 25:ddf0ec209f03 | 554 | t.tm_sec = (t.tm_sec<59)?t.tm_sec+1:0; |
TickTock | 25:ddf0ec209f03 | 555 | } else { |
TickTock | 25:ddf0ec209f03 | 556 | t.tm_sec = (t.tm_sec>1)?t.tm_sec-1:59; |
TickTock | 25:ddf0ec209f03 | 557 | } |
TickTock | 25:ddf0ec209f03 | 558 | break; |
TickTock | 25:ddf0ec209f03 | 559 | default: |
TickTock | 25:ddf0ec209f03 | 560 | break; |
TickTock | 25:ddf0ec209f03 | 561 | } |
TickTock | 25:ddf0ec209f03 | 562 | set_time(mktime(&t)); |
TickTock | 25:ddf0ec209f03 | 563 | } |
TickTock | 25:ddf0ec209f03 | 564 | |
TickTock | 39:eef8beac7411 | 565 | void logPackVoltages() { // Turbo3 - routine to dump CP values to text file |
TickTock | 39:eef8beac7411 | 566 | char sTemp[40]; |
TickTock | 39:eef8beac7411 | 567 | struct tm t; // pointer to a static tm structure |
TickTock | 39:eef8beac7411 | 568 | short unsigned max, min, jv, i, bd; |
TickTock | 39:eef8beac7411 | 569 | unsigned avg; |
TickTock | 39:eef8beac7411 | 570 | unsigned short gids, SOC, packV; |
TickTock | 39:eef8beac7411 | 571 | signed short packA; |
TickTock | 39:eef8beac7411 | 572 | time_t seconds ; |
TickTock | 39:eef8beac7411 | 573 | |
TickTock | 39:eef8beac7411 | 574 | CANMessage msg; |
TickTock | 39:eef8beac7411 | 575 | |
TickTock | 39:eef8beac7411 | 576 | seconds = time(NULL); // Turbo3 |
TickTock | 39:eef8beac7411 | 577 | t = *localtime(&seconds) ; // Turbo3 |
TickTock | 39:eef8beac7411 | 578 | |
TickTock | 39:eef8beac7411 | 579 | msg = lastMsg[indexLastMsg[0x5bc]]; //Get gids |
TickTock | 39:eef8beac7411 | 580 | gids = (msg.data[0]<<2)+(msg.data[1]>>6); |
TickTock | 39:eef8beac7411 | 581 | msg = lastMsg[indexLastMsg[0x55b]]; //Get SOC |
TickTock | 39:eef8beac7411 | 582 | SOC = (msg.data[0]<<2)+(msg.data[1]>>6); |
TickTock | 39:eef8beac7411 | 583 | msg = lastMsg[indexLastMsg[0x1db]]; //Get pack volts |
TickTock | 39:eef8beac7411 | 584 | packV = (msg.data[2]<<2)+(msg.data[3]>>6); |
TickTock | 39:eef8beac7411 | 585 | packA = (msg.data[0]<<3)+(msg.data[1]>>5); |
TickTock | 39:eef8beac7411 | 586 | if (packA & 0x400) packA |= 0xf800; |
TickTock | 39:eef8beac7411 | 587 | |
TickTock | 39:eef8beac7411 | 588 | max=0; |
TickTock | 39:eef8beac7411 | 589 | min=9999; |
TickTock | 39:eef8beac7411 | 590 | avg=0; |
TickTock | 92:935adef49ea4 | 591 | for(i=0; i<96; i++) { |
TickTock | 39:eef8beac7411 | 592 | bd=(battData[i*2+3]<<8)+battData[i*2+4]; |
TickTock | 39:eef8beac7411 | 593 | avg+=bd; |
TickTock | 39:eef8beac7411 | 594 | if(bd>max) max=bd; |
TickTock | 39:eef8beac7411 | 595 | if(bd<min) min=bd; |
TickTock | 39:eef8beac7411 | 596 | } |
TickTock | 39:eef8beac7411 | 597 | avg /= 96; |
TickTock | 39:eef8beac7411 | 598 | if(min<3713) { |
TickTock | 39:eef8beac7411 | 599 | jv=avg-(max-avg)*1.5; |
TickTock | 39:eef8beac7411 | 600 | } else { // Only compute judgement value if min cellpair meets <= 3712mV requirement |
TickTock | 39:eef8beac7411 | 601 | jv=0; |
TickTock | 39:eef8beac7411 | 602 | } |
TickTock | 39:eef8beac7411 | 603 | |
TickTock | 39:eef8beac7411 | 604 | FILE *bfile; |
TickTock | 39:eef8beac7411 | 605 | //bfile = fopen("/local/batvolt.txt", "a"); |
TickTock | 39:eef8beac7411 | 606 | bfile = fopen("/usb/batvolt.txt", "a"); |
TickTock | 39:eef8beac7411 | 607 | if(bfile!=NULL) { |
TickTock | 39:eef8beac7411 | 608 | strftime(sTemp, 40, "%a %m/%d/%Y %X", &t); |
TickTock | 39:eef8beac7411 | 609 | fprintf(bfile,"%s,%d,%5.1f%%,%5.1f,%5.1f,%d,%d,%d,%d,%d",sTemp,gids,(float)SOC/10,(float)packV/2,(float)packA/2,max,min,avg,max-min,jv); |
garygid | 87:46ac3f2519d6 | 610 | // BatDataBaseG4 * 7 = 224 |
TickTock | 39:eef8beac7411 | 611 | fprintf(bfile,"%d,%d,%d,%d,",(battData[224+ 3]<<8)+battData[224+ 4],battData[224+ 5],(battData[224+ 6]<<8)+battData[224+ 7],battData[224+ 8]); |
TickTock | 39:eef8beac7411 | 612 | fprintf(bfile,"%d,%d,%d,%d", (battData[224+ 9]<<8)+battData[224+10],battData[224+11],(battData[224+12]<<8)+battData[224+13],battData[224+14]); |
TickTock | 92:935adef49ea4 | 613 | for(i=0; i<96; i++) { |
TickTock | 39:eef8beac7411 | 614 | bd=(battData[i*2+3]<<8)+battData[i*2+4]; |
TickTock | 39:eef8beac7411 | 615 | fprintf(bfile,",%d",bd); |
TickTock | 39:eef8beac7411 | 616 | } |
TickTock | 39:eef8beac7411 | 617 | fprintf(bfile,"\r\n"); |
TickTock | 39:eef8beac7411 | 618 | fclose(bfile); |
TickTock | 39:eef8beac7411 | 619 | } |
TickTock | 39:eef8beac7411 | 620 | logCP=false; |
TickTock | 40:0e6e71a7323f | 621 | showCP=true; |
TickTock | 39:eef8beac7411 | 622 | } |
TickTock | 25:ddf0ec209f03 | 623 |