Final Report

Dependencies:   mbed

Fork of ecu_reader by Sukkin Pang

Committer:
LAvtec818
Date:
Mon Oct 27 02:46:55 2014 +0000
Revision:
6:dae9630af6e3
Parent:
3:05bb8f0bd7a4
report

Who changed what in which revision?

UserRevisionLine numberNew contents of line
pangsk 0:908be729d27c 1
pangsk 0:908be729d27c 2 #include "mbed.h"
pangsk 0:908be729d27c 3 #include "ecu_reader.h"
pangsk 0:908be729d27c 4 #include "globals.h"
pangsk 0:908be729d27c 5 #include "TextLCD.h"
LAvtec818 6:dae9630af6e3 6 #include <stdio.h>
LAvtec818 6:dae9630af6e3 7 #include <string>
LAvtec818 6:dae9630af6e3 8 //#include "SDFileSystem.h"
pangsk 0:908be729d27c 9
LAvtec818 6:dae9630af6e3 10 TextLCD lcd(p26, p25, p24, p23, p22, p20, p19, TextLCD::LCD20x4);//(p18, p19, p20, p17, p16, p15, p14); // rs, rw, e, d0, d1, d2, d3
LAvtec818 6:dae9630af6e3 11 //SDFileSystem sd(p5, p6, p7, p13, "sd");
LAvtec818 6:dae9630af6e3 12
pangsk 3:05bb8f0bd7a4 13 Serial pc(USBTX, USBRX);
LAvtec818 6:dae9630af6e3 14 DigitalIn enable(p8);
LAvtec818 6:dae9630af6e3 15
LAvtec818 6:dae9630af6e3 16 Serial xbee1(p9, p10); //Creates a variable for serial comunication through pin 9 and 10
LAvtec818 6:dae9630af6e3 17 DigitalOut rst1(p11); //Digital reset for the XBee, 200ns for reset
pangsk 3:05bb8f0bd7a4 18
pangsk 0:908be729d27c 19
pangsk 0:908be729d27c 20 ecu_reader obdii(CANSPEED_500); //Create object and set CAN speed
LAvtec818 6:dae9630af6e3 21 //void sd_demo(void);
LAvtec818 6:dae9630af6e3 22
LAvtec818 6:dae9630af6e3 23 void Rx_interrupt() {
LAvtec818 6:dae9630af6e3 24 float rx_data[8];
LAvtec818 6:dae9630af6e3 25 int first_byte[8];
LAvtec818 6:dae9630af6e3 26 int second_byte[8];
LAvtec818 6:dae9630af6e3 27 char buffer[30];
LAvtec818 6:dae9630af6e3 28 if (can2.read(can_MsgRx)){
LAvtec818 6:dae9630af6e3 29 //xbee1.printf("\n\rPackets Received:\n\r");
LAvtec818 6:dae9630af6e3 30
LAvtec818 6:dae9630af6e3 31 if((can_MsgRx.id == Filter1) || (can_MsgRx.id == Filter1) || (can_MsgRx.id == Filter2) || (can_MsgRx.id == Filter3) || (can_MsgRx.id == Filter4) || (can_MsgRx.id == Filter5) || (can_MsgRx.id == Filter6)
LAvtec818 6:dae9630af6e3 32 || (can_MsgRx.id == Filter7) || (can_MsgRx.id == Filter8) || (can_MsgRx.id == Filter9) || (can_MsgRx.id == Filtera) || (can_MsgRx.id == Filterb) || (can_MsgRx.id == Filterc)){
LAvtec818 6:dae9630af6e3 33 //xbee1.printf("\n\rIgnored\n\r");
LAvtec818 6:dae9630af6e3 34 }
LAvtec818 6:dae9630af6e3 35
LAvtec818 6:dae9630af6e3 36 else{
LAvtec818 6:dae9630af6e3 37 for (int z = 0; z < 8; z++){
LAvtec818 6:dae9630af6e3 38 rx_data[z] = (can_MsgRx.data[z]);
LAvtec818 6:dae9630af6e3 39 if (rx_data[z] > 15){
LAvtec818 6:dae9630af6e3 40 first_byte[z] = rx_data[z]/16;
LAvtec818 6:dae9630af6e3 41 second_byte[z] = (int)(rx_data[z])%16;}
LAvtec818 6:dae9630af6e3 42 else {
LAvtec818 6:dae9630af6e3 43 first_byte[z] = 0;
LAvtec818 6:dae9630af6e3 44 second_byte[z] = rx_data[z];
LAvtec818 6:dae9630af6e3 45 }}
LAvtec818 6:dae9630af6e3 46
LAvtec818 6:dae9630af6e3 47 sprintf(buffer,"\n\r%d, %d, %d, %d, %d, %d, %d, %d", (int) rx_data[0],(int) rx_data[1],(int) rx_data[2],(int) rx_data[3],(int) rx_data[4],(int) rx_data[5],(int) rx_data[6],(int) rx_data[7] );
LAvtec818 6:dae9630af6e3 48 xbee1.printf(buffer, "\n\r");
LAvtec818 6:dae9630af6e3 49 sprintf(buffer,"%d%d %d%d %d%d %d%d %d%d %d%d %d%d %d%d", (int) first_byte[0],(int) second_byte[0],(int) first_byte[1],(int) second_byte[1],(int) first_byte[2],(int) second_byte[2],(int) first_byte[3],(int) second_byte[3],
LAvtec818 6:dae9630af6e3 50 (int) first_byte[4],(int) second_byte[4],(int) first_byte[5],(int) second_byte[5],(int) first_byte[6],(int) second_byte[6],(int) first_byte[7],(int) second_byte[7]);
LAvtec818 6:dae9630af6e3 51 xbee1.printf(buffer);
LAvtec818 6:dae9630af6e3 52 xbee1.printf("\n\r");
LAvtec818 6:dae9630af6e3 53 }
LAvtec818 6:dae9630af6e3 54 }
LAvtec818 6:dae9630af6e3 55 }
pangsk 0:908be729d27c 56
pangsk 0:908be729d27c 57 int main() {
LAvtec818 6:dae9630af6e3 58
LAvtec818 6:dae9630af6e3 59 int Mod1 = 0;
LAvtec818 6:dae9630af6e3 60 int Mod2 = 0;
LAvtec818 6:dae9630af6e3 61
LAvtec818 6:dae9630af6e3 62 rst1 = 0; //Set reset pin to 0
LAvtec818 6:dae9630af6e3 63 wait_ms(1);//Wait at least one millisecond
LAvtec818 6:dae9630af6e3 64 rst1 = 1;//Set reset pin to 1
LAvtec818 6:dae9630af6e3 65 wait_ms(1);
pangsk 3:05bb8f0bd7a4 66
LAvtec818 6:dae9630af6e3 67 //pc.baud(115200);
LAvtec818 6:dae9630af6e3 68 // xbee1.baud(9600);
LAvtec818 6:dae9630af6e3 69 xbee1.baud(115200); //set serial baurd rate, need to configure the xbees to 115200 manually
LAvtec818 6:dae9630af6e3 70 char buffer[30];
pangsk 3:05bb8f0bd7a4 71
LAvtec818 6:dae9630af6e3 72 // xbee1.printf("ECU Reader \n");
LAvtec818 6:dae9630af6e3 73 // lcd.locate(0,0); // Set LCD cursor position
LAvtec818 6:dae9630af6e3 74 // lcd.printf("ECU Malicious Attack");
pangsk 0:908be729d27c 75
LAvtec818 6:dae9630af6e3 76 // lcd.locate(0,1);
LAvtec818 6:dae9630af6e3 77 // lcd.printf(" UCLA EE202A");
LAvtec818 6:dae9630af6e3 78
LAvtec818 6:dae9630af6e3 79 can2.attach(&Rx_interrupt);//, CAN::RxIrq ); //need to figure this out ///////
pangsk 0:908be729d27c 80
LAvtec818 6:dae9630af6e3 81 xbee1.printf("\n\rECU Malicious Attack\n\rUCLA EE202A\n\r");
LAvtec818 6:dae9630af6e3 82 //wait(3);
LAvtec818 6:dae9630af6e3 83 //lcd.cls();
LAvtec818 6:dae9630af6e3 84 // lcd.locate(0,2);
LAvtec818 6:dae9630af6e3 85 //lcd.printf("Use joystick");
pangsk 0:908be729d27c 86
LAvtec818 6:dae9630af6e3 87 // lcd.locate(0,3);
LAvtec818 6:dae9630af6e3 88 // lcd.printf(" Push BTN1 to Start");
LAvtec818 6:dae9630af6e3 89 int can_bus_speed = 500000;
LAvtec818 6:dae9630af6e3 90
LAvtec818 6:dae9630af6e3 91 xbee1.printf("\n\r\n\rSelect CAN BUS Frequency\n\r0: 125Kbps\n\r1: 250Kbps\n\r2: 500Kbps\n\r3: 1Mbps\n\r ");
LAvtec818 6:dae9630af6e3 92
LAvtec818 6:dae9630af6e3 93 while(1){
LAvtec818 6:dae9630af6e3 94 if (xbee1.readable()){
LAvtec818 6:dae9630af6e3 95
LAvtec818 6:dae9630af6e3 96 char c_freq = xbee1.getc();
LAvtec818 6:dae9630af6e3 97
LAvtec818 6:dae9630af6e3 98 if (c_freq == '0'){
LAvtec818 6:dae9630af6e3 99 can_bus_speed = 125000;
LAvtec818 6:dae9630af6e3 100 break;}
LAvtec818 6:dae9630af6e3 101 if (c_freq == '1'){
LAvtec818 6:dae9630af6e3 102 can_bus_speed = 25000;
LAvtec818 6:dae9630af6e3 103 break;}
LAvtec818 6:dae9630af6e3 104 if (c_freq == '2'){
LAvtec818 6:dae9630af6e3 105 can_bus_speed = 500000;
LAvtec818 6:dae9630af6e3 106 break;}
LAvtec818 6:dae9630af6e3 107 if (c_freq == '3'){
LAvtec818 6:dae9630af6e3 108 can_bus_speed = 1000000;
LAvtec818 6:dae9630af6e3 109 break;}
LAvtec818 6:dae9630af6e3 110
LAvtec818 6:dae9630af6e3 111 }
LAvtec818 6:dae9630af6e3 112 }
LAvtec818 6:dae9630af6e3 113
LAvtec818 6:dae9630af6e3 114 can2.frequency(can_bus_speed);
LAvtec818 6:dae9630af6e3 115
LAvtec818 6:dae9630af6e3 116 xbee1.printf("\n\rPush BTN1 to Start\n\r");
pangsk 0:908be729d27c 117
pangsk 0:908be729d27c 118 while(1) // Wait until option is selected by the joystick
pangsk 0:908be729d27c 119 {
LAvtec818 6:dae9630af6e3 120
LAvtec818 6:dae9630af6e3 121 if(enable == 0) break;
pangsk 0:908be729d27c 122
pangsk 0:908be729d27c 123 }
LAvtec818 6:dae9630af6e3 124 wait(1);
LAvtec818 6:dae9630af6e3 125 // lcd.cls();
LAvtec818 6:dae9630af6e3 126
LAvtec818 6:dae9630af6e3 127 xbee1.printf("\n\r\n\rSelect Mode of Operation:\n\r\n\r0: PID Reading (RPM, Air Intake Temp., Fuel Pressure, and Etc...)\n\r1: Transmit and Receive CAN Packets\n\r");
LAvtec818 6:dae9630af6e3 128
LAvtec818 6:dae9630af6e3 129 while (1)
LAvtec818 6:dae9630af6e3 130 {
LAvtec818 6:dae9630af6e3 131 if (xbee1.readable()) {
LAvtec818 6:dae9630af6e3 132 char c1 = xbee1.getc();
LAvtec818 6:dae9630af6e3 133 if (c1 == '0'){
LAvtec818 6:dae9630af6e3 134 Mod1 = 1;
LAvtec818 6:dae9630af6e3 135 xbee1.printf("\n\rPID Mode Selected!\n\r");
LAvtec818 6:dae9630af6e3 136 break; }
LAvtec818 6:dae9630af6e3 137 if (c1 == '1'){
LAvtec818 6:dae9630af6e3 138 Mod2 = 1;
LAvtec818 6:dae9630af6e3 139 xbee1.printf("\n\rCAN Packet Communication Mode Selected!\n\r");
LAvtec818 6:dae9630af6e3 140 break;}
LAvtec818 6:dae9630af6e3 141 }
LAvtec818 6:dae9630af6e3 142 }
pangsk 0:908be729d27c 143
pangsk 0:908be729d27c 144 while(1) { // Main CAN loop
LAvtec818 6:dae9630af6e3 145
LAvtec818 6:dae9630af6e3 146 if (Mod1 == 1){
LAvtec818 6:dae9630af6e3 147
pangsk 0:908be729d27c 148 led2 = 1;
pangsk 0:908be729d27c 149 wait(0.1);
pangsk 0:908be729d27c 150 led2 = 0;
pangsk 0:908be729d27c 151 wait(0.1);
pangsk 0:908be729d27c 152
pangsk 0:908be729d27c 153 if(obdii.request(ENGINE_RPM,buffer) == 1) // Get engine rpm and display on LCD
pangsk 0:908be729d27c 154 {
pangsk 0:908be729d27c 155 lcd.locate(0,0);
pangsk 0:908be729d27c 156 lcd.printf(buffer);
LAvtec818 6:dae9630af6e3 157 xbee1.printf(buffer);
LAvtec818 6:dae9630af6e3 158 xbee1.printf("\n\r");
pangsk 0:908be729d27c 159 }
pangsk 0:908be729d27c 160
pangsk 0:908be729d27c 161 if(obdii.request(ENGINE_COOLANT_TEMP,buffer) == 1)
pangsk 0:908be729d27c 162 {
pangsk 0:908be729d27c 163 lcd.locate(9,0);
pangsk 0:908be729d27c 164 lcd.printf(buffer);
LAvtec818 6:dae9630af6e3 165 xbee1.printf(buffer);
LAvtec818 6:dae9630af6e3 166 xbee1.printf("\n\r");
pangsk 0:908be729d27c 167 }
pangsk 0:908be729d27c 168
pangsk 0:908be729d27c 169 if(obdii.request(VEHICLE_SPEED,buffer) == 1)
pangsk 0:908be729d27c 170 {
pangsk 0:908be729d27c 171 lcd.locate(0,1);
pangsk 0:908be729d27c 172 lcd.printf(buffer);
LAvtec818 6:dae9630af6e3 173 xbee1.printf(buffer);
LAvtec818 6:dae9630af6e3 174 xbee1.printf("\n\r");
pangsk 0:908be729d27c 175 }
pangsk 0:908be729d27c 176
pangsk 0:908be729d27c 177 if(obdii.request(THROTTLE,buffer) ==1 )
pangsk 0:908be729d27c 178 {
pangsk 0:908be729d27c 179 lcd.locate(9,1);
LAvtec818 6:dae9630af6e3 180 lcd.printf(buffer);
LAvtec818 6:dae9630af6e3 181 xbee1.printf(buffer);
LAvtec818 6:dae9630af6e3 182 xbee1.printf("\n\r");
pangsk 0:908be729d27c 183 }
pangsk 0:908be729d27c 184
LAvtec818 6:dae9630af6e3 185 if(obdii.request(AIR_INTAKE_TEMP,buffer) ==1 )
LAvtec818 6:dae9630af6e3 186 {
LAvtec818 6:dae9630af6e3 187 lcd.locate(0,2);
LAvtec818 6:dae9630af6e3 188 lcd.printf(buffer);
LAvtec818 6:dae9630af6e3 189 xbee1.printf(buffer);
LAvtec818 6:dae9630af6e3 190 xbee1.printf("\n\r");
LAvtec818 6:dae9630af6e3 191 }
LAvtec818 6:dae9630af6e3 192
LAvtec818 6:dae9630af6e3 193 if(obdii.request(FUEL_PRESSURE,buffer) ==1 )
LAvtec818 6:dae9630af6e3 194 {
LAvtec818 6:dae9630af6e3 195 lcd.locate(9,2);
LAvtec818 6:dae9630af6e3 196 lcd.printf(buffer);
LAvtec818 6:dae9630af6e3 197 xbee1.printf(buffer);
LAvtec818 6:dae9630af6e3 198 xbee1.printf("\n\r");
LAvtec818 6:dae9630af6e3 199 }
LAvtec818 6:dae9630af6e3 200 }
LAvtec818 6:dae9630af6e3 201
LAvtec818 6:dae9630af6e3 202 else if (Mod2 == 1){
LAvtec818 6:dae9630af6e3 203 led4 = 1;
LAvtec818 6:dae9630af6e3 204 wait(0.1);
LAvtec818 6:dae9630af6e3 205 led4 = 0;
LAvtec818 6:dae9630af6e3 206 wait(0.1);
LAvtec818 6:dae9630af6e3 207 float rx_data[8];
LAvtec818 6:dae9630af6e3 208 int first_byte[8];
LAvtec818 6:dae9630af6e3 209 int second_byte[8];
LAvtec818 6:dae9630af6e3 210
LAvtec818 6:dae9630af6e3 211 int packet1 = 0;
LAvtec818 6:dae9630af6e3 212 int packet2 = 0;
LAvtec818 6:dae9630af6e3 213 int packet3 = 0;
LAvtec818 6:dae9630af6e3 214 int packet4 = 0;
LAvtec818 6:dae9630af6e3 215 int receive0 = 0;
LAvtec818 6:dae9630af6e3 216
LAvtec818 6:dae9630af6e3 217 char can_bus_msg[8];
LAvtec818 6:dae9630af6e3 218
LAvtec818 6:dae9630af6e3 219 xbee1.printf("\n\r\n\rSelect Type of Packet to Transmit:\n\r\n\ra: Flow Control\n\rb: Tester Present\n\rc: Enhanced Diagnostics\n\rd: Security Access: Request Seed\n\re: Sniff Packets");
LAvtec818 6:dae9630af6e3 220
LAvtec818 6:dae9630af6e3 221
LAvtec818 6:dae9630af6e3 222 while (1)
pangsk 0:908be729d27c 223 {
LAvtec818 6:dae9630af6e3 224 if (xbee1.readable()) {
LAvtec818 6:dae9630af6e3 225 char c = xbee1.getc();
LAvtec818 6:dae9630af6e3 226 if (c == 'a'){
LAvtec818 6:dae9630af6e3 227 packet1 = 1;
LAvtec818 6:dae9630af6e3 228 xbee1.printf("\n\rFlow Control Packet Selected!\n\r");
LAvtec818 6:dae9630af6e3 229 break; }
LAvtec818 6:dae9630af6e3 230 if (c == 'b'){
LAvtec818 6:dae9630af6e3 231 packet2 = 1;
LAvtec818 6:dae9630af6e3 232 xbee1.printf("\n\rTester Present Packet Selected!\n\r");
LAvtec818 6:dae9630af6e3 233 break;}
LAvtec818 6:dae9630af6e3 234 if (c == 'e'){
LAvtec818 6:dae9630af6e3 235 receive0 = 1;
LAvtec818 6:dae9630af6e3 236 xbee1.printf("\n\rRead Filtered Packets!\n\r");
LAvtec818 6:dae9630af6e3 237 break;}
LAvtec818 6:dae9630af6e3 238 if (c == 'c'){
LAvtec818 6:dae9630af6e3 239 packet3 = 1;
LAvtec818 6:dae9630af6e3 240 xbee1.printf("\n\rEnhanced Diagnostics Packet Selected!\n\r");
LAvtec818 6:dae9630af6e3 241 break;}
LAvtec818 6:dae9630af6e3 242
LAvtec818 6:dae9630af6e3 243 if (c == 'd'){
LAvtec818 6:dae9630af6e3 244 packet4 = 1;
LAvtec818 6:dae9630af6e3 245 xbee1.printf("\n\rRequest Seed Packet Selected!\n\r");
LAvtec818 6:dae9630af6e3 246 break;}
pangsk 0:908be729d27c 247 }
pangsk 0:908be729d27c 248 }
LAvtec818 6:dae9630af6e3 249
LAvtec818 6:dae9630af6e3 250 if (packet1) { //flow control packet
LAvtec818 6:dae9630af6e3 251
LAvtec818 6:dae9630af6e3 252 can_bus_msg[0] = 0x30; //0x30 Clear To Send, 0x31 Wait
LAvtec818 6:dae9630af6e3 253 can_bus_msg[1] = 0; //Block Size, 0 -> Don't wait, send as many frames as are in the message
LAvtec818 6:dae9630af6e3 254 can_bus_msg[2] = 0; //Separation Time -> 0 -> Send As Fast As Possible, 101-255 are viable numbers
LAvtec818 6:dae9630af6e3 255 can_bus_msg[3] = 0; //Don't Care
LAvtec818 6:dae9630af6e3 256 can_bus_msg[4] = 0; //Don't Care
LAvtec818 6:dae9630af6e3 257 can_bus_msg[5] = 0; //Don't Care
LAvtec818 6:dae9630af6e3 258 can_bus_msg[6] = 0; //Don't Care
LAvtec818 6:dae9630af6e3 259 can_bus_msg[7] = 0; //Don't Care
LAvtec818 6:dae9630af6e3 260
LAvtec818 6:dae9630af6e3 261 can2.write(CANMessage(Ext_Diag, can_bus_msg, 8)); //7E0 Extension Diag. TX
LAvtec818 6:dae9630af6e3 262 packet1 = 0;
LAvtec818 6:dae9630af6e3 263
LAvtec818 6:dae9630af6e3 264 }
LAvtec818 6:dae9630af6e3 265
LAvtec818 6:dae9630af6e3 266 else if (packet2) {
LAvtec818 6:dae9630af6e3 267
LAvtec818 6:dae9630af6e3 268 can_bus_msg[0] = 0x02;
LAvtec818 6:dae9630af6e3 269 can_bus_msg[1] = 0x3E;
LAvtec818 6:dae9630af6e3 270 can_bus_msg[2] = 0x02;
LAvtec818 6:dae9630af6e3 271 can_bus_msg[3] = 0;
LAvtec818 6:dae9630af6e3 272 can_bus_msg[4] = 0;
LAvtec818 6:dae9630af6e3 273 can_bus_msg[5] = 0;
LAvtec818 6:dae9630af6e3 274 can_bus_msg[6] = 0;
LAvtec818 6:dae9630af6e3 275 can_bus_msg[7] = 0;
LAvtec818 6:dae9630af6e3 276
LAvtec818 6:dae9630af6e3 277 can2.write(CANMessage(Ext_Diag, can_bus_msg, 8)); //7E0 Extension Diag. TX
LAvtec818 6:dae9630af6e3 278 packet2 = 0;
LAvtec818 6:dae9630af6e3 279 }
pangsk 2:e7b3b8da71ff 280
LAvtec818 6:dae9630af6e3 281 else if (packet3) {
LAvtec818 6:dae9630af6e3 282
LAvtec818 6:dae9630af6e3 283 can_bus_msg[0] = 0x02;
LAvtec818 6:dae9630af6e3 284 can_bus_msg[1] = 0x10;
LAvtec818 6:dae9630af6e3 285 can_bus_msg[2] = 0x82;
LAvtec818 6:dae9630af6e3 286 can_bus_msg[3] = 0;
LAvtec818 6:dae9630af6e3 287 can_bus_msg[4] = 0;
LAvtec818 6:dae9630af6e3 288 can_bus_msg[5] = 0;
LAvtec818 6:dae9630af6e3 289 can_bus_msg[6] = 0;
LAvtec818 6:dae9630af6e3 290 can_bus_msg[7] = 0;
LAvtec818 6:dae9630af6e3 291
LAvtec818 6:dae9630af6e3 292 can2.write(CANMessage(Ext_Diag, can_bus_msg, 8)); //7E0 Extension Diag. TX
LAvtec818 6:dae9630af6e3 293 packet3 = 0;
LAvtec818 6:dae9630af6e3 294 }
LAvtec818 6:dae9630af6e3 295 else if (packet4) {
LAvtec818 6:dae9630af6e3 296
LAvtec818 6:dae9630af6e3 297 can_bus_msg[0] = 0x02;
LAvtec818 6:dae9630af6e3 298 can_bus_msg[1] = 0x27;
LAvtec818 6:dae9630af6e3 299 can_bus_msg[2] = 0x01;
LAvtec818 6:dae9630af6e3 300 can_bus_msg[3] = 0;
LAvtec818 6:dae9630af6e3 301 can_bus_msg[4] = 0;
LAvtec818 6:dae9630af6e3 302 can_bus_msg[5] = 0;
LAvtec818 6:dae9630af6e3 303 can_bus_msg[6] = 0;
LAvtec818 6:dae9630af6e3 304 can_bus_msg[7] = 0;
LAvtec818 6:dae9630af6e3 305
LAvtec818 6:dae9630af6e3 306 can2.write(CANMessage(Ext_Diag, can_bus_msg, 8)); //7E0 Extension Diag. TX
LAvtec818 6:dae9630af6e3 307 packet3 = 0;
LAvtec818 6:dae9630af6e3 308 }
LAvtec818 6:dae9630af6e3 309
LAvtec818 6:dae9630af6e3 310 else if (receive0) {
pangsk 2:e7b3b8da71ff 311
LAvtec818 6:dae9630af6e3 312 if (can2.read(can_MsgRx)){
LAvtec818 6:dae9630af6e3 313
LAvtec818 6:dae9630af6e3 314 if((can_MsgRx.id == Filter1) || (can_MsgRx.id == Filter1) || (can_MsgRx.id == Filter2) || (can_MsgRx.id == Filter3) || (can_MsgRx.id == Filter4) || (can_MsgRx.id == Filter5) || (can_MsgRx.id == Filter6)
LAvtec818 6:dae9630af6e3 315 || (can_MsgRx.id == Filter7) || (can_MsgRx.id == Filter8) || (can_MsgRx.id == Filter9) || (can_MsgRx.id == Filtera) || (can_MsgRx.id == Filterb) || (can_MsgRx.id == Filterc)){
LAvtec818 6:dae9630af6e3 316 xbee1.printf("\n\rIgnored\n\r");
LAvtec818 6:dae9630af6e3 317 }
LAvtec818 6:dae9630af6e3 318
LAvtec818 6:dae9630af6e3 319 else{
LAvtec818 6:dae9630af6e3 320 for (int z = 0; z < 8; z++){
LAvtec818 6:dae9630af6e3 321 rx_data[z] = (can_MsgRx.data[z]);
LAvtec818 6:dae9630af6e3 322 if (rx_data[z] > 15){
LAvtec818 6:dae9630af6e3 323 first_byte[z] = rx_data[z]/16;
LAvtec818 6:dae9630af6e3 324 second_byte[z] = (int)(rx_data[z])%16;}
LAvtec818 6:dae9630af6e3 325 else {
LAvtec818 6:dae9630af6e3 326 first_byte[z] = 0;
LAvtec818 6:dae9630af6e3 327 second_byte[z] = rx_data[z];
LAvtec818 6:dae9630af6e3 328 }}
LAvtec818 6:dae9630af6e3 329
LAvtec818 6:dae9630af6e3 330 sprintf(buffer,"%d, %d, %d, %d, %d, %d, %d, %d", (int) rx_data[0],(int) rx_data[1],(int) rx_data[2],(int) rx_data[3],(int) rx_data[4],(int) rx_data[5],(int) rx_data[6],(int) rx_data[7] );
LAvtec818 6:dae9630af6e3 331 xbee1.printf(buffer);
LAvtec818 6:dae9630af6e3 332 xbee1.printf("\n\r");
LAvtec818 6:dae9630af6e3 333 sprintf(buffer,"%d%d %d%d %d%d %d%d %d%d %d%d %d%d %d%d", (int) first_byte[0],(int) second_byte[0],(int) first_byte[1],(int) second_byte[1],(int) first_byte[2],(int) second_byte[2],(int) first_byte[3],(int) second_byte[3],
LAvtec818 6:dae9630af6e3 334 (int) first_byte[4],(int) second_byte[4],(int) first_byte[5],(int) second_byte[5],(int) first_byte[6],(int) second_byte[6],(int) first_byte[7],(int) second_byte[7]);
LAvtec818 6:dae9630af6e3 335 xbee1.printf(buffer);
LAvtec818 6:dae9630af6e3 336 xbee1.printf("\n\r");
LAvtec818 6:dae9630af6e3 337 }
LAvtec818 6:dae9630af6e3 338 }
LAvtec818 6:dae9630af6e3 339
LAvtec818 6:dae9630af6e3 340 }
LAvtec818 6:dae9630af6e3 341 } // end else
LAvtec818 6:dae9630af6e3 342 } //end while
LAvtec818 6:dae9630af6e3 343 }//end main
LAvtec818 6:dae9630af6e3 344
LAvtec818 6:dae9630af6e3 345