Library to control Dodge LX (83.3k) CAN devices

Dependents:   DodgeRadioEmulatorv30

Committer:
rtgree01
Date:
Fri Jan 25 04:04:27 2013 +0000
Revision:
2:ade5ba8a9d37
Parent:
1:6dcab41a32df
Library to control Dodge LX (83.3k) CAN devices

Who changed what in which revision?

UserRevisionLine numberNew contents of line
rtgree01 0:ab4c4438577e 1 #include "mbed.h"
rtgree01 0:ab4c4438577e 2 #include "radioEmulator.h"
rtgree01 0:ab4c4438577e 3
rtgree01 0:ab4c4438577e 4 DigitalOut led1(LED1);
rtgree01 0:ab4c4438577e 5 DigitalOut led2(LED2);
rtgree01 0:ab4c4438577e 6 DigitalOut led3(LED3);
rtgree01 0:ab4c4438577e 7 DigitalOut led4(LED4);
rtgree01 0:ab4c4438577e 8
rtgree01 2:ade5ba8a9d37 9 DigitalOut reverse(p15);
rtgree01 2:ade5ba8a9d37 10
rtgree01 0:ab4c4438577e 11
rtgree01 0:ab4c4438577e 12 #undef CHECK_HW_SHUTDOWN
rtgree01 0:ab4c4438577e 13
rtgree01 0:ab4c4438577e 14 //LocalFileSystem local("local");
rtgree01 0:ab4c4438577e 15 //#include "SDFileSystem.h"
rtgree01 0:ab4c4438577e 16
rtgree01 0:ab4c4438577e 17 //SDFileSystem sd(p5, p6, p7, p8, "sd"); // the pinout on the mbed Cool Components workshop board
rtgree01 0:ab4c4438577e 18
rtgree01 0:ab4c4438577e 19 char RadioEmulator::unlock[6] = {0x03,0x02,0x00,0x40,0x87,0xa5};
rtgree01 0:ab4c4438577e 20 char RadioEmulator::lock[6] = {0x01, 0x02, 0x00, 0x40, 0x87, 0xa5};
rtgree01 0:ab4c4438577e 21 char RadioEmulator::trunk[6] = {0x05, 0x02, 0x00, 0x40, 0x87, 0xa5};
rtgree01 0:ab4c4438577e 22
rtgree01 0:ab4c4438577e 23 RadioEmulator::RadioEmulator(CAN *can, DigitalOut *rs, InterruptIn *irq, bool wdTO)
rtgree01 0:ab4c4438577e 24 {
rtgree01 0:ab4c4438577e 25 printf("RadioEmulator Initializing\r\n");
rtgree01 0:ab4c4438577e 26
rtgree01 0:ab4c4438577e 27 HostSock = new UDPSock(new Host(IpAddr(), 50000, NULL), 64, this);
rtgree01 0:ab4c4438577e 28
rtgree01 0:ab4c4438577e 29 CANDevice = can;
rtgree01 0:ab4c4438577e 30 can_RS = rs;
rtgree01 0:ab4c4438577e 31 canIRQ = irq;
rtgree01 0:ab4c4438577e 32
rtgree01 2:ade5ba8a9d37 33 reverse = 0;
rtgree01 2:ade5ba8a9d37 34
rtgree01 0:ab4c4438577e 35 prevSWC = 0;
rtgree01 0:ab4c4438577e 36
rtgree01 0:ab4c4438577e 37 memset(&status, 0, sizeof(status));
rtgree01 0:ab4c4438577e 38 memset(&siriusdata, 0, 512);
rtgree01 0:ab4c4438577e 39 status.marker1 = 0x42;
rtgree01 0:ab4c4438577e 40 status.marker2 = 0x42;
rtgree01 0:ab4c4438577e 41 status.marker3 = 0x42;
rtgree01 0:ab4c4438577e 42 status.marker4 = 0x42;
rtgree01 0:ab4c4438577e 43
rtgree01 0:ab4c4438577e 44 status._radioMode = SAT;
rtgree01 0:ab4c4438577e 45
rtgree01 0:ab4c4438577e 46 // readInitFile();
rtgree01 0:ab4c4438577e 47 status._volume = 10;
rtgree01 0:ab4c4438577e 48 status._bass = 15;
rtgree01 0:ab4c4438577e 49 status._mid = 13;
rtgree01 0:ab4c4438577e 50 status._treble = 14;
rtgree01 0:ab4c4438577e 51 status._balance = 10;
rtgree01 0:ab4c4438577e 52 status._fade = 10;
rtgree01 0:ab4c4438577e 53
rtgree01 0:ab4c4438577e 54 for (int i = 0; i < 8; i++)
rtgree01 0:ab4c4438577e 55 {
rtgree01 0:ab4c4438577e 56 if (wdTO)
rtgree01 0:ab4c4438577e 57 {
rtgree01 0:ab4c4438577e 58 sprintf(&siriusdata[i * 64], "WATCH DOG TIMED OUT");
rtgree01 0:ab4c4438577e 59 }
rtgree01 0:ab4c4438577e 60 else
rtgree01 0:ab4c4438577e 61 {
rtgree01 0:ab4c4438577e 62 sprintf(&siriusdata[i * 64], "Fun line text # %d", i);
rtgree01 0:ab4c4438577e 63 }
rtgree01 0:ab4c4438577e 64 }
rtgree01 0:ab4c4438577e 65
rtgree01 0:ab4c4438577e 66 PowerUp();
rtgree01 0:ab4c4438577e 67
rtgree01 0:ab4c4438577e 68 printf("RadioEmulator initialized\n\r");
rtgree01 0:ab4c4438577e 69 }
rtgree01 0:ab4c4438577e 70
rtgree01 0:ab4c4438577e 71 /*
rtgree01 0:ab4c4438577e 72 void RadioEmulator::readInitFile()
rtgree01 0:ab4c4438577e 73 {
rtgree01 0:ab4c4438577e 74 FILE *fp = fopen("/sd/stereo.txt", "r"); // Open "out.txt" on the local file system for writing
rtgree01 0:ab4c4438577e 75 char temp[100];
rtgree01 0:ab4c4438577e 76
rtgree01 0:ab4c4438577e 77 while ( fscanf(fp, "%s", temp) > 0)
rtgree01 0:ab4c4438577e 78 {
rtgree01 0:ab4c4438577e 79 if (strcmp(temp, "volume") == 0)
rtgree01 0:ab4c4438577e 80 {
rtgree01 0:ab4c4438577e 81 fscanf(fp, "%d", &status._volume);
rtgree01 0:ab4c4438577e 82 }
rtgree01 0:ab4c4438577e 83 if (strcmp(temp, "bass") == 0)
rtgree01 0:ab4c4438577e 84 {
rtgree01 0:ab4c4438577e 85 fscanf(fp, "%d", &status._bass);
rtgree01 0:ab4c4438577e 86 }
rtgree01 0:ab4c4438577e 87 if (strcmp(temp, "mid") == 0)
rtgree01 0:ab4c4438577e 88 {
rtgree01 0:ab4c4438577e 89 fscanf(fp, "%d", &status._mid);
rtgree01 0:ab4c4438577e 90 }
rtgree01 0:ab4c4438577e 91 if (strcmp(temp, "treble") == 0)
rtgree01 0:ab4c4438577e 92 {
rtgree01 0:ab4c4438577e 93 fscanf(fp, "%d", &status._treble);
rtgree01 0:ab4c4438577e 94 }
rtgree01 0:ab4c4438577e 95 if (strcmp(temp, "balance") == 0)
rtgree01 0:ab4c4438577e 96 {
rtgree01 0:ab4c4438577e 97 fscanf(fp, "%d", &status._balance);
rtgree01 0:ab4c4438577e 98 }
rtgree01 0:ab4c4438577e 99 if (strcmp(temp, "fade") == 0)
rtgree01 0:ab4c4438577e 100 {
rtgree01 0:ab4c4438577e 101 fscanf(fp, "%d", &status._fade);
rtgree01 0:ab4c4438577e 102 }
rtgree01 0:ab4c4438577e 103 if (strcmp(temp, "MAC") == 0)
rtgree01 0:ab4c4438577e 104 {
rtgree01 0:ab4c4438577e 105 char temp2[64];
rtgree01 0:ab4c4438577e 106 fscanf(fp, "%s", temp2);
rtgree01 0:ab4c4438577e 107 char *pEnd;
rtgree01 0:ab4c4438577e 108 hostMACAddress[0] = strtoul(temp2, &pEnd, 16);
rtgree01 0:ab4c4438577e 109 hostMACAddress[1] = strtoul(pEnd, &pEnd, 16);
rtgree01 0:ab4c4438577e 110 hostMACAddress[2] = strtoul(pEnd, &pEnd, 16);
rtgree01 0:ab4c4438577e 111 hostMACAddress[3] = strtoul(pEnd, &pEnd, 16);
rtgree01 0:ab4c4438577e 112 hostMACAddress[4] = strtoul(pEnd, &pEnd, 16);
rtgree01 0:ab4c4438577e 113 hostMACAddress[5] = strtoul(pEnd, &pEnd, 16);
rtgree01 0:ab4c4438577e 114 }
rtgree01 0:ab4c4438577e 115 }
rtgree01 0:ab4c4438577e 116
rtgree01 0:ab4c4438577e 117 fclose(fp);
rtgree01 0:ab4c4438577e 118 }
rtgree01 0:ab4c4438577e 119
rtgree01 0:ab4c4438577e 120 void RadioEmulator::writeInitFile()
rtgree01 0:ab4c4438577e 121 {
rtgree01 0:ab4c4438577e 122 FILE *fp = fopen("/sd/stereo.txt", "w"); // Open "out.txt" on the local file system for writing
rtgree01 0:ab4c4438577e 123
rtgree01 0:ab4c4438577e 124 fprintf(fp,"volume %d\r\n", status._volume);
rtgree01 0:ab4c4438577e 125 fprintf(fp,"bass %d\r\n", status._bass);
rtgree01 0:ab4c4438577e 126 fprintf(fp,"mid %d\r\n", status._mid);
rtgree01 0:ab4c4438577e 127 fprintf(fp,"treble %d\r\n", status._treble);
rtgree01 0:ab4c4438577e 128 fprintf(fp,"balance %d\r\n", status._balance);
rtgree01 0:ab4c4438577e 129 fprintf(fp,"fade %d\r\n", status._fade);
rtgree01 0:ab4c4438577e 130 fclose(fp);
rtgree01 0:ab4c4438577e 131 }
rtgree01 0:ab4c4438577e 132 */
rtgree01 0:ab4c4438577e 133
rtgree01 0:ab4c4438577e 134 void RadioEmulator::PowerUp(void)
rtgree01 0:ab4c4438577e 135 {
rtgree01 0:ab4c4438577e 136 led1 = 1;
rtgree01 0:ab4c4438577e 137
rtgree01 0:ab4c4438577e 138 needToParseCANMessage = false;
rtgree01 0:ab4c4438577e 139 ReceivedCANMsg = false;
rtgree01 0:ab4c4438577e 140 LPC_CAN2->BTR = 0x52001C;
rtgree01 0:ab4c4438577e 141 *can_RS = 0; // Wake up the CAN Transceiver
rtgree01 0:ab4c4438577e 142
rtgree01 0:ab4c4438577e 143 sleeping = false;
rtgree01 0:ab4c4438577e 144
rtgree01 0:ab4c4438577e 145 writeCANFlag = false;
rtgree01 1:6dcab41a32df 146 CANBusTicker.attach(this, &RadioEmulator::WriteCANMessages, 1);
rtgree01 0:ab4c4438577e 147
rtgree01 0:ab4c4438577e 148 ChangeSiriusStation(status._siriusChan, true);
rtgree01 0:ab4c4438577e 149
rtgree01 0:ab4c4438577e 150 ReceivedHostMsg = false;
rtgree01 0:ab4c4438577e 151 statusFlag = false;
rtgree01 0:ab4c4438577e 152 statusTicker.attach(this, &RadioEmulator::SendStatusToHost, 0.1);
rtgree01 0:ab4c4438577e 153
rtgree01 0:ab4c4438577e 154 opMode = standalone;
rtgree01 0:ab4c4438577e 155 hostTimeoutFlag = false;
rtgree01 0:ab4c4438577e 156 HostTimeout.attach(this, &RadioEmulator::CheckHostTimeout, 1);
rtgree01 0:ab4c4438577e 157
rtgree01 0:ab4c4438577e 158 CANTimeoutFlag = false;
rtgree01 0:ab4c4438577e 159 canIRQ->rise(0);
rtgree01 0:ab4c4438577e 160 // only enable this if trying to power up/down the processor
rtgree01 0:ab4c4438577e 161 // CANTimeout.attach(this, &RadioEmulator::CheckCANTimeout, 1);
rtgree01 0:ab4c4438577e 162 }
rtgree01 0:ab4c4438577e 163
rtgree01 0:ab4c4438577e 164 void RadioEmulator::PowerDown(void)
rtgree01 0:ab4c4438577e 165 {
rtgree01 0:ab4c4438577e 166 led1 = 0;
rtgree01 0:ab4c4438577e 167 // Need to Power Down
rtgree01 0:ab4c4438577e 168
rtgree01 0:ab4c4438577e 169 CANBusTicker.detach();
rtgree01 0:ab4c4438577e 170 CANTimeout.detach();
rtgree01 0:ab4c4438577e 171 statusTicker.detach();
rtgree01 0:ab4c4438577e 172 HostTimeout.detach();
rtgree01 0:ab4c4438577e 173
rtgree01 0:ab4c4438577e 174 *can_RS = 1;
rtgree01 0:ab4c4438577e 175 powerUpIRQCounter = 0;
rtgree01 0:ab4c4438577e 176 sleeping = true;
rtgree01 0:ab4c4438577e 177 needToWakeUp = false;
rtgree01 0:ab4c4438577e 178
rtgree01 0:ab4c4438577e 179 canIRQ->rise(this, &RadioEmulator::CANActivity);
rtgree01 0:ab4c4438577e 180 }
rtgree01 0:ab4c4438577e 181
rtgree01 0:ab4c4438577e 182 void RadioEmulator::Operate(void)
rtgree01 0:ab4c4438577e 183 {
rtgree01 0:ab4c4438577e 184 if (sleeping)
rtgree01 0:ab4c4438577e 185 {
rtgree01 0:ab4c4438577e 186 if (needToWakeUp)
rtgree01 0:ab4c4438577e 187 {
rtgree01 0:ab4c4438577e 188 PowerUp();
rtgree01 0:ab4c4438577e 189 needToWakeUp = false;
rtgree01 0:ab4c4438577e 190 }
rtgree01 0:ab4c4438577e 191
rtgree01 0:ab4c4438577e 192 return;
rtgree01 0:ab4c4438577e 193 }
rtgree01 0:ab4c4438577e 194
rtgree01 0:ab4c4438577e 195 if (writeCANFlag)
rtgree01 0:ab4c4438577e 196 {
rtgree01 0:ab4c4438577e 197 writeCANFlag = false;
rtgree01 0:ab4c4438577e 198
rtgree01 0:ab4c4438577e 199 led2 = !led2;
rtgree01 0:ab4c4438577e 200 SendRadioModeMsg();
rtgree01 0:ab4c4438577e 201 SendEVICMsg();
rtgree01 0:ab4c4438577e 202 SendStereoSettingsMsg();
rtgree01 0:ab4c4438577e 203 SendHostMessages();
rtgree01 0:ab4c4438577e 204 }
rtgree01 0:ab4c4438577e 205
rtgree01 0:ab4c4438577e 206 if (statusFlag)
rtgree01 0:ab4c4438577e 207 {
rtgree01 0:ab4c4438577e 208 statusFlag = false;
rtgree01 0:ab4c4438577e 209
rtgree01 0:ab4c4438577e 210 if (opMode == standalone)
rtgree01 0:ab4c4438577e 211 {
rtgree01 0:ab4c4438577e 212 StandaloneSWI();
rtgree01 0:ab4c4438577e 213 }
rtgree01 0:ab4c4438577e 214
rtgree01 0:ab4c4438577e 215 prevSWC = status.SWCButtons;
rtgree01 0:ab4c4438577e 216
rtgree01 0:ab4c4438577e 217 status.count++;
rtgree01 1:6dcab41a32df 218 static Host statusHost(IpAddr(224,1,2,3), 51000, NULL); //Join multicast group on port 50000
rtgree01 0:ab4c4438577e 219 HostSock->SendTo(&statusHost, sizeof(status), (char *)&status);
rtgree01 0:ab4c4438577e 220
rtgree01 0:ab4c4438577e 221 if ((status.count % 10) == 0)
rtgree01 0:ab4c4438577e 222 {
rtgree01 1:6dcab41a32df 223 static Host siriusTextHost(IpAddr(224,1,2,3), 61000, NULL); //Join multicast group on port 50000
rtgree01 0:ab4c4438577e 224 HostSock->SendTo(&siriusTextHost, 512, siriusdata);
rtgree01 0:ab4c4438577e 225 }
rtgree01 0:ab4c4438577e 226 }
rtgree01 0:ab4c4438577e 227
rtgree01 0:ab4c4438577e 228 if (hostTimeoutFlag)
rtgree01 0:ab4c4438577e 229 {
rtgree01 0:ab4c4438577e 230 hostTimeoutFlag = false;
rtgree01 0:ab4c4438577e 231
rtgree01 0:ab4c4438577e 232 if (!ReceivedHostMsg)
rtgree01 0:ab4c4438577e 233 {
rtgree01 0:ab4c4438577e 234 led4 = 1;
rtgree01 0:ab4c4438577e 235 opMode = standalone;
rtgree01 0:ab4c4438577e 236 }
rtgree01 0:ab4c4438577e 237 else
rtgree01 0:ab4c4438577e 238 {
rtgree01 0:ab4c4438577e 239 led4 = 0;
rtgree01 0:ab4c4438577e 240 }
rtgree01 0:ab4c4438577e 241
rtgree01 0:ab4c4438577e 242 ReceivedHostMsg = false;
rtgree01 0:ab4c4438577e 243 }
rtgree01 0:ab4c4438577e 244
rtgree01 0:ab4c4438577e 245 // only enable this if trying to power up/down the processor
rtgree01 0:ab4c4438577e 246 if (CANTimeoutFlag)
rtgree01 0:ab4c4438577e 247 {
rtgree01 0:ab4c4438577e 248 CANTimeoutFlag = false;
rtgree01 0:ab4c4438577e 249
rtgree01 0:ab4c4438577e 250 if (!ReceivedCANMsg)
rtgree01 0:ab4c4438577e 251 {
rtgree01 0:ab4c4438577e 252 PowerDown();
rtgree01 0:ab4c4438577e 253 }
rtgree01 0:ab4c4438577e 254
rtgree01 0:ab4c4438577e 255 ReceivedCANMsg = false;
rtgree01 0:ab4c4438577e 256 }
rtgree01 0:ab4c4438577e 257
rtgree01 0:ab4c4438577e 258 readCANbus();
rtgree01 0:ab4c4438577e 259 }
rtgree01 0:ab4c4438577e 260
rtgree01 0:ab4c4438577e 261 void RadioEmulator::StandaloneSWI()
rtgree01 0:ab4c4438577e 262 {
rtgree01 0:ab4c4438577e 263 if (status.SWCButtons == 0)
rtgree01 0:ab4c4438577e 264 {
rtgree01 0:ab4c4438577e 265 if ((prevSWC & 0x00000004) != 0)
rtgree01 0:ab4c4438577e 266 {
rtgree01 0:ab4c4438577e 267 if (status._volume > 0)
rtgree01 0:ab4c4438577e 268 status._volume --;
rtgree01 0:ab4c4438577e 269 }
rtgree01 0:ab4c4438577e 270 else if ((prevSWC & 0x00000002) != 0)
rtgree01 0:ab4c4438577e 271 {
rtgree01 0:ab4c4438577e 272 if (status._volume < 40)
rtgree01 0:ab4c4438577e 273 status._volume ++;
rtgree01 0:ab4c4438577e 274 }
rtgree01 0:ab4c4438577e 275 else if ((prevSWC & 0x00000010) != 0)
rtgree01 0:ab4c4438577e 276 {
rtgree01 0:ab4c4438577e 277 if (status._siriusChan > 0)
rtgree01 0:ab4c4438577e 278 ChangeSiriusStation(status._siriusChan-1, false);
rtgree01 0:ab4c4438577e 279 }
rtgree01 0:ab4c4438577e 280 else if ((prevSWC & 0x00000008) != 0)
rtgree01 0:ab4c4438577e 281 {
rtgree01 0:ab4c4438577e 282 if ((status._siriusChan < 256) && (status._siriusChan > 0))
rtgree01 0:ab4c4438577e 283 ChangeSiriusStation(status._siriusChan+1, false);
rtgree01 0:ab4c4438577e 284 }
rtgree01 0:ab4c4438577e 285 else if ((prevSWC & 0x00000001) != 0)
rtgree01 0:ab4c4438577e 286 {
rtgree01 0:ab4c4438577e 287 }
rtgree01 0:ab4c4438577e 288 }
rtgree01 0:ab4c4438577e 289 }
rtgree01 0:ab4c4438577e 290
rtgree01 0:ab4c4438577e 291 void RadioEmulator::SendOnMsg()
rtgree01 0:ab4c4438577e 292 {
rtgree01 0:ab4c4438577e 293 CANMessage msg;
rtgree01 0:ab4c4438577e 294 msg.id = 0x416;
rtgree01 0:ab4c4438577e 295 msg.len = 8;
rtgree01 0:ab4c4438577e 296 char temp[8] = {0xfe, 0x1b, 0x3f, 0xff, 0xff, 0xff, 0xff, 0xff};
rtgree01 0:ab4c4438577e 297 memcpy(msg.data, temp, 8);
rtgree01 0:ab4c4438577e 298 CANDevice->write(msg);
rtgree01 0:ab4c4438577e 299 }
rtgree01 0:ab4c4438577e 300
rtgree01 0:ab4c4438577e 301 void RadioEmulator::SendRadioModeMsg()
rtgree01 0:ab4c4438577e 302 {
rtgree01 0:ab4c4438577e 303 CANMessage msg;
rtgree01 0:ab4c4438577e 304 msg.id = 0x09F;
rtgree01 0:ab4c4438577e 305 msg.len = 8;
rtgree01 0:ab4c4438577e 306
rtgree01 0:ab4c4438577e 307 msg.data[7] = 0x0f;
rtgree01 0:ab4c4438577e 308 msg.data[6] = 0xff;
rtgree01 0:ab4c4438577e 309 msg.data[5] = 0xff;
rtgree01 0:ab4c4438577e 310 msg.data[4] = 0xff;
rtgree01 0:ab4c4438577e 311 msg.data[3] = 0x07;
rtgree01 0:ab4c4438577e 312 msg.data[2] = 0x00;
rtgree01 0:ab4c4438577e 313 msg.data[1] = 0x00;
rtgree01 0:ab4c4438577e 314 msg.data[0] = 0x00;
rtgree01 0:ab4c4438577e 315
rtgree01 0:ab4c4438577e 316 if (status._radioMode == AM)
rtgree01 0:ab4c4438577e 317 {
rtgree01 0:ab4c4438577e 318 if ((status._amPreset >= 0) && (status._amPreset < 16))
rtgree01 0:ab4c4438577e 319 {
rtgree01 0:ab4c4438577e 320 msg.data[0] = (status._amPreset + 1) << 4;
rtgree01 0:ab4c4438577e 321 }
rtgree01 0:ab4c4438577e 322 msg.data[1] = (status._amFreq & 0xFF00) >> 8;
rtgree01 0:ab4c4438577e 323 msg.data[2] = (status._amFreq & 0x00FF);
rtgree01 0:ab4c4438577e 324 }
rtgree01 0:ab4c4438577e 325 else if (status._radioMode == FM)
rtgree01 0:ab4c4438577e 326 {
rtgree01 0:ab4c4438577e 327 if ((status._fmPreset >= 0) && (status._fmPreset < 16))
rtgree01 0:ab4c4438577e 328 {
rtgree01 0:ab4c4438577e 329 msg.data[0] = (status._fmPreset + 1) << 4;
rtgree01 0:ab4c4438577e 330 }
rtgree01 0:ab4c4438577e 331 msg.data[0] |= 0x01;
rtgree01 0:ab4c4438577e 332 msg.data[1] = (status._fmFreq & 0xFF00) >> 8;
rtgree01 0:ab4c4438577e 333 msg.data[2] = (status._fmFreq & 0x00FF);
rtgree01 0:ab4c4438577e 334 }
rtgree01 0:ab4c4438577e 335 else if (status._radioMode == CD)
rtgree01 0:ab4c4438577e 336 {
rtgree01 0:ab4c4438577e 337 msg.data[0] = status._cdNum << 4;
rtgree01 0:ab4c4438577e 338 msg.data[1] = 0x20;
rtgree01 0:ab4c4438577e 339 msg.data[0] |= 0x03;
rtgree01 0:ab4c4438577e 340 msg.data[2] = status._cdTrackNum;
rtgree01 0:ab4c4438577e 341 msg.data[4] = status._cdHours;
rtgree01 0:ab4c4438577e 342 msg.data[5] = status._cdMinutes;
rtgree01 0:ab4c4438577e 343 msg.data[6] = status._cdSeconds;
rtgree01 0:ab4c4438577e 344 }
rtgree01 0:ab4c4438577e 345 else if (status._radioMode == SAT)
rtgree01 0:ab4c4438577e 346 {
rtgree01 0:ab4c4438577e 347 if ((status._siriusPreset >= 0) && (status._siriusPreset < 16))
rtgree01 0:ab4c4438577e 348 {
rtgree01 0:ab4c4438577e 349 msg.data[0] = (status._siriusPreset + 1) << 4;
rtgree01 0:ab4c4438577e 350 }
rtgree01 0:ab4c4438577e 351 msg.data[0] |= 0x04;
rtgree01 0:ab4c4438577e 352 msg.data[1] = 0;
rtgree01 0:ab4c4438577e 353 msg.data[2] = status._siriusChan;
rtgree01 0:ab4c4438577e 354 }
rtgree01 0:ab4c4438577e 355 else if (status._radioMode == VES)
rtgree01 0:ab4c4438577e 356 {
rtgree01 0:ab4c4438577e 357 msg.data[0] = 0x16;
rtgree01 0:ab4c4438577e 358 msg.data[1] = 0x10;
rtgree01 0:ab4c4438577e 359 msg.data[2] = 0x01;
rtgree01 0:ab4c4438577e 360 }
rtgree01 0:ab4c4438577e 361
rtgree01 0:ab4c4438577e 362 msg.data[1] |= 0x10;
rtgree01 0:ab4c4438577e 363
rtgree01 0:ab4c4438577e 364 CANDevice->write(msg);
rtgree01 0:ab4c4438577e 365 }
rtgree01 0:ab4c4438577e 366
rtgree01 0:ab4c4438577e 367 void RadioEmulator::SendEVICMsg()
rtgree01 0:ab4c4438577e 368 {
rtgree01 0:ab4c4438577e 369 CANMessage msg;
rtgree01 0:ab4c4438577e 370 msg.id = 0x394;
rtgree01 0:ab4c4438577e 371 msg.len = 6;
rtgree01 0:ab4c4438577e 372
rtgree01 0:ab4c4438577e 373 memset(msg.data, 0, 8);
rtgree01 0:ab4c4438577e 374
rtgree01 0:ab4c4438577e 375 if (status._radioMode == AM)
rtgree01 0:ab4c4438577e 376 {
rtgree01 0:ab4c4438577e 377 if ((status._amPreset >= 0) && (status._amPreset < 16))
rtgree01 0:ab4c4438577e 378 {
rtgree01 0:ab4c4438577e 379 msg.data[0] = (status._amPreset + 1) << 4;
rtgree01 0:ab4c4438577e 380 }
rtgree01 0:ab4c4438577e 381 msg.data[1] = (status._amFreq & 0xFF00) >> 8;
rtgree01 0:ab4c4438577e 382 msg.data[2] = (status._amFreq & 0x00FF);
rtgree01 0:ab4c4438577e 383 }
rtgree01 0:ab4c4438577e 384 else
rtgree01 0:ab4c4438577e 385 {
rtgree01 0:ab4c4438577e 386 if ((status._fmPreset >= 0) && (status._fmPreset < 16))
rtgree01 0:ab4c4438577e 387 {
rtgree01 0:ab4c4438577e 388 msg.data[0] = (status._fmPreset + 1) << 4;
rtgree01 0:ab4c4438577e 389 }
rtgree01 0:ab4c4438577e 390 msg.data[0] |= 0x01;
rtgree01 0:ab4c4438577e 391 msg.data[1] = (status._fmFreq & 0xFF00) >> 8;
rtgree01 0:ab4c4438577e 392 msg.data[2] = (status._fmFreq & 0x00FF);
rtgree01 0:ab4c4438577e 393 }
rtgree01 0:ab4c4438577e 394
rtgree01 0:ab4c4438577e 395 CANDevice->write(msg);
rtgree01 0:ab4c4438577e 396 }
rtgree01 0:ab4c4438577e 397
rtgree01 0:ab4c4438577e 398 void RadioEmulator::SendStereoSettingsMsg()
rtgree01 0:ab4c4438577e 399 {
rtgree01 0:ab4c4438577e 400 CANMessage msg;
rtgree01 0:ab4c4438577e 401 msg.id = 0x3D0;
rtgree01 0:ab4c4438577e 402 msg.len = 7;
rtgree01 0:ab4c4438577e 403
rtgree01 0:ab4c4438577e 404 msg.data[0] = status._volume;
rtgree01 0:ab4c4438577e 405 msg.data[1] = status._balance;
rtgree01 0:ab4c4438577e 406 msg.data[2] = status._fade;
rtgree01 0:ab4c4438577e 407 msg.data[3] = status._bass;
rtgree01 0:ab4c4438577e 408 msg.data[4] = status._mid;
rtgree01 0:ab4c4438577e 409 msg.data[5] = status._treble;
rtgree01 0:ab4c4438577e 410
rtgree01 0:ab4c4438577e 411 CANDevice->write(msg);
rtgree01 0:ab4c4438577e 412 }
rtgree01 0:ab4c4438577e 413
rtgree01 0:ab4c4438577e 414 void RadioEmulator::SendHostMessages()
rtgree01 0:ab4c4438577e 415 {
rtgree01 0:ab4c4438577e 416 if (hostMessages.size() > 0)
rtgree01 0:ab4c4438577e 417 {
rtgree01 0:ab4c4438577e 418 CANDevice->write(hostMessages.front());
rtgree01 0:ab4c4438577e 419
rtgree01 0:ab4c4438577e 420 hostMessages.pop_front();
rtgree01 0:ab4c4438577e 421 }
rtgree01 0:ab4c4438577e 422 }
rtgree01 0:ab4c4438577e 423
rtgree01 0:ab4c4438577e 424 void RadioEmulator::ChangeSiriusStation(int station, bool turn_on)
rtgree01 0:ab4c4438577e 425 {
rtgree01 0:ab4c4438577e 426 if (station == 0)
rtgree01 0:ab4c4438577e 427 {
rtgree01 0:ab4c4438577e 428 return;
rtgree01 0:ab4c4438577e 429 }
rtgree01 0:ab4c4438577e 430
rtgree01 0:ab4c4438577e 431 CANMessage msg;
rtgree01 0:ab4c4438577e 432 msg.id = 0x3B0;
rtgree01 0:ab4c4438577e 433 msg.len = 6;
rtgree01 0:ab4c4438577e 434
rtgree01 0:ab4c4438577e 435 if (turn_on)
rtgree01 0:ab4c4438577e 436 {
rtgree01 0:ab4c4438577e 437 msg.data[0] = 21;
rtgree01 0:ab4c4438577e 438 }
rtgree01 0:ab4c4438577e 439 else
rtgree01 0:ab4c4438577e 440 {
rtgree01 0:ab4c4438577e 441 msg.data[0] = 23;
rtgree01 0:ab4c4438577e 442 }
rtgree01 0:ab4c4438577e 443 msg.data[1] = station;
rtgree01 0:ab4c4438577e 444
rtgree01 0:ab4c4438577e 445 CANDevice->write(msg);
rtgree01 0:ab4c4438577e 446
rtgree01 0:ab4c4438577e 447 memset(msg.data, 0, 8);
rtgree01 0:ab4c4438577e 448 msg.data[1] = station;
rtgree01 0:ab4c4438577e 449
rtgree01 0:ab4c4438577e 450 CANDevice->write(msg);
rtgree01 0:ab4c4438577e 451
rtgree01 0:ab4c4438577e 452 status._siriusChan = station;
rtgree01 0:ab4c4438577e 453
rtgree01 0:ab4c4438577e 454 memset(&siriusdata, 0, 512);
rtgree01 0:ab4c4438577e 455 }
rtgree01 0:ab4c4438577e 456
rtgree01 0:ab4c4438577e 457 void RadioEmulator::ParseCANMessage(CANMessage can_MsgRx)
rtgree01 0:ab4c4438577e 458 {
rtgree01 0:ab4c4438577e 459 // this message seems to be a message requesting all other devices
rtgree01 0:ab4c4438577e 460 // to start announcing their presence
rtgree01 0:ab4c4438577e 461 if ((can_MsgRx.id >= 0x400) && (can_MsgRx.data[0] == 0xfd))
rtgree01 0:ab4c4438577e 462 {
rtgree01 0:ab4c4438577e 463 }
rtgree01 0:ab4c4438577e 464
rtgree01 0:ab4c4438577e 465 if (can_MsgRx.id == 0x000)
rtgree01 0:ab4c4438577e 466 {
rtgree01 0:ab4c4438577e 467 /*
rtgree01 0:ab4c4438577e 468 if (can_MsgRx.data[0] > 1)
rtgree01 0:ab4c4438577e 469 {
rtgree01 0:ab4c4438577e 470 radioOn = true;
rtgree01 0:ab4c4438577e 471 }
rtgree01 0:ab4c4438577e 472 else
rtgree01 0:ab4c4438577e 473 {
rtgree01 0:ab4c4438577e 474 radioOn = false;
rtgree01 0:ab4c4438577e 475 }
rtgree01 0:ab4c4438577e 476 */
rtgree01 0:ab4c4438577e 477 status._keyPosition = can_MsgRx.data[0];
rtgree01 0:ab4c4438577e 478 }
rtgree01 0:ab4c4438577e 479 else if (can_MsgRx.id == 0x002)
rtgree01 0:ab4c4438577e 480 {
rtgree01 0:ab4c4438577e 481 status._rpm = (can_MsgRx.data[0] << 8) + can_MsgRx.data[1];
rtgree01 0:ab4c4438577e 482 status._speed = ((can_MsgRx.data[2] << 8) + can_MsgRx.data[3]) >> 7;
rtgree01 0:ab4c4438577e 483
rtgree01 0:ab4c4438577e 484 // what are the other 4 bytes?
rtgree01 0:ab4c4438577e 485 }
rtgree01 0:ab4c4438577e 486 else if (can_MsgRx.id == 0x003)
rtgree01 0:ab4c4438577e 487 {
rtgree01 0:ab4c4438577e 488 status._brake = can_MsgRx.data[3] & 0x01;
rtgree01 0:ab4c4438577e 489 status._gear = can_MsgRx.data[4];
rtgree01 2:ade5ba8a9d37 490 if (status._gear == 'R')
rtgree01 2:ade5ba8a9d37 491 {
rtgree01 2:ade5ba8a9d37 492 reverse = 1;
rtgree01 2:ade5ba8a9d37 493 }
rtgree01 2:ade5ba8a9d37 494 else
rtgree01 2:ade5ba8a9d37 495 {
rtgree01 2:ade5ba8a9d37 496 reverse = 0;
rtgree01 2:ade5ba8a9d37 497 }
rtgree01 0:ab4c4438577e 498 }
rtgree01 0:ab4c4438577e 499 else if (can_MsgRx.id == 0x012)
rtgree01 0:ab4c4438577e 500 {
rtgree01 0:ab4c4438577e 501 if (memcmp(can_MsgRx.data, unlock, 6) == 0)
rtgree01 0:ab4c4438577e 502 {
rtgree01 0:ab4c4438577e 503 }
rtgree01 0:ab4c4438577e 504 else if (memcmp(can_MsgRx.data, lock, 6) == 0)
rtgree01 0:ab4c4438577e 505 {
rtgree01 0:ab4c4438577e 506 }
rtgree01 0:ab4c4438577e 507 else if (memcmp(can_MsgRx.data, trunk, 6) == 0)
rtgree01 0:ab4c4438577e 508 {
rtgree01 0:ab4c4438577e 509 }
rtgree01 0:ab4c4438577e 510 }
rtgree01 0:ab4c4438577e 511 else if (can_MsgRx.id == 0x14)
rtgree01 0:ab4c4438577e 512 {
rtgree01 0:ab4c4438577e 513 status._odometer = (can_MsgRx.data[0] << 16) + (can_MsgRx.data[1] << 8) + can_MsgRx.data[2];
rtgree01 0:ab4c4438577e 514 // what are the other 4 bytes?
rtgree01 0:ab4c4438577e 515 }
rtgree01 0:ab4c4438577e 516 else if (can_MsgRx.id == 0x15)
rtgree01 0:ab4c4438577e 517 {
rtgree01 0:ab4c4438577e 518 status._batteryVoltage = (float)(can_MsgRx.data[1]) / 10;
rtgree01 0:ab4c4438577e 519 }
rtgree01 0:ab4c4438577e 520 else if (can_MsgRx.id == 0x01b)
rtgree01 0:ab4c4438577e 521 {
rtgree01 0:ab4c4438577e 522 // vin number
rtgree01 0:ab4c4438577e 523 int part = can_MsgRx.data[0];
rtgree01 0:ab4c4438577e 524 if ((part >= 0) && (part < 3))
rtgree01 0:ab4c4438577e 525 {
rtgree01 0:ab4c4438577e 526 for (int i = 1; i < 8; i++)
rtgree01 0:ab4c4438577e 527 {
rtgree01 0:ab4c4438577e 528 status._vin[(part*7) + i-1] = can_MsgRx.data[i];
rtgree01 0:ab4c4438577e 529 }
rtgree01 0:ab4c4438577e 530 }
rtgree01 0:ab4c4438577e 531 }
rtgree01 0:ab4c4438577e 532 else if (can_MsgRx.id == 0x0d0)
rtgree01 0:ab4c4438577e 533 {
rtgree01 0:ab4c4438577e 534 if (can_MsgRx.data[0] == 0x80)
rtgree01 0:ab4c4438577e 535 {
rtgree01 0:ab4c4438577e 536 status._parkingBrake = true;
rtgree01 0:ab4c4438577e 537 }
rtgree01 0:ab4c4438577e 538 else
rtgree01 0:ab4c4438577e 539 {
rtgree01 0:ab4c4438577e 540 status._parkingBrake = false;
rtgree01 0:ab4c4438577e 541 }
rtgree01 0:ab4c4438577e 542 }
rtgree01 0:ab4c4438577e 543 else if (can_MsgRx.id == 0x0EC)
rtgree01 0:ab4c4438577e 544 {
rtgree01 0:ab4c4438577e 545 if ((can_MsgRx.data[0] & 0x40) == 0x40)
rtgree01 0:ab4c4438577e 546 {
rtgree01 0:ab4c4438577e 547 status._fanRequested = true;
rtgree01 0:ab4c4438577e 548 }
rtgree01 0:ab4c4438577e 549 else
rtgree01 0:ab4c4438577e 550 {
rtgree01 0:ab4c4438577e 551 status._fanRequested = false;
rtgree01 0:ab4c4438577e 552 }
rtgree01 0:ab4c4438577e 553
rtgree01 0:ab4c4438577e 554 if ((can_MsgRx.data[0] & 0x01) == 0x01)
rtgree01 0:ab4c4438577e 555 {
rtgree01 0:ab4c4438577e 556 status._fanOn = true;
rtgree01 0:ab4c4438577e 557 }
rtgree01 0:ab4c4438577e 558 else
rtgree01 0:ab4c4438577e 559 {
rtgree01 0:ab4c4438577e 560 status._fanOn = false;
rtgree01 0:ab4c4438577e 561 }
rtgree01 0:ab4c4438577e 562 }
rtgree01 0:ab4c4438577e 563 else if (can_MsgRx.id == 0x159)
rtgree01 0:ab4c4438577e 564 {
rtgree01 0:ab4c4438577e 565 status._fuel = can_MsgRx.data[5];
rtgree01 0:ab4c4438577e 566 }
rtgree01 0:ab4c4438577e 567 else if (can_MsgRx.id == 0x1a2)
rtgree01 0:ab4c4438577e 568 {
rtgree01 0:ab4c4438577e 569 if ((can_MsgRx.data[0] & 0x80) == 0x80)
rtgree01 0:ab4c4438577e 570 {
rtgree01 0:ab4c4438577e 571 status._rearDefrost = true;
rtgree01 0:ab4c4438577e 572 }
rtgree01 0:ab4c4438577e 573 else
rtgree01 0:ab4c4438577e 574 {
rtgree01 0:ab4c4438577e 575 status._rearDefrost = false;
rtgree01 0:ab4c4438577e 576 }
rtgree01 0:ab4c4438577e 577
rtgree01 0:ab4c4438577e 578 if ((can_MsgRx.data[0] & 0x40) == 0x40)
rtgree01 0:ab4c4438577e 579 {
rtgree01 0:ab4c4438577e 580 status._fanRequested = true;
rtgree01 0:ab4c4438577e 581 }
rtgree01 0:ab4c4438577e 582 else
rtgree01 0:ab4c4438577e 583 {
rtgree01 0:ab4c4438577e 584 status._fanRequested = false;
rtgree01 0:ab4c4438577e 585 }
rtgree01 0:ab4c4438577e 586
rtgree01 0:ab4c4438577e 587 if ((can_MsgRx.data[0] & 0x01) == 0x01)
rtgree01 0:ab4c4438577e 588 {
rtgree01 0:ab4c4438577e 589 status._fanOn = true;
rtgree01 0:ab4c4438577e 590 }
rtgree01 0:ab4c4438577e 591 else
rtgree01 0:ab4c4438577e 592 {
rtgree01 0:ab4c4438577e 593 status._fanOn = false;
rtgree01 0:ab4c4438577e 594 }
rtgree01 0:ab4c4438577e 595 }
rtgree01 0:ab4c4438577e 596 else if (can_MsgRx.id == 0x1bd)
rtgree01 0:ab4c4438577e 597 {
rtgree01 0:ab4c4438577e 598 // SDAR status
rtgree01 0:ab4c4438577e 599
rtgree01 0:ab4c4438577e 600 if (status._siriusChan == 0)
rtgree01 0:ab4c4438577e 601 {
rtgree01 0:ab4c4438577e 602 status._siriusChan = can_MsgRx.data[1];
rtgree01 0:ab4c4438577e 603 }
rtgree01 0:ab4c4438577e 604
rtgree01 0:ab4c4438577e 605 if (can_MsgRx.data[0] == 0x85)
rtgree01 0:ab4c4438577e 606 {
rtgree01 0:ab4c4438577e 607 ChangeSiriusStation(status._siriusChan, true);
rtgree01 0:ab4c4438577e 608 }
rtgree01 0:ab4c4438577e 609
rtgree01 0:ab4c4438577e 610 if (status._siriusChan != can_MsgRx.data[1])
rtgree01 0:ab4c4438577e 611 {
rtgree01 0:ab4c4438577e 612 ChangeSiriusStation(status._siriusChan, true);
rtgree01 0:ab4c4438577e 613 }
rtgree01 0:ab4c4438577e 614 }
rtgree01 0:ab4c4438577e 615 else if (can_MsgRx.id == 0x1c8)
rtgree01 0:ab4c4438577e 616 {
rtgree01 0:ab4c4438577e 617 status._headlights = can_MsgRx.data[0];
rtgree01 0:ab4c4438577e 618 }
rtgree01 0:ab4c4438577e 619 else if (can_MsgRx.id == 0x210)
rtgree01 0:ab4c4438577e 620 {
rtgree01 0:ab4c4438577e 621 status._dimmerMode = can_MsgRx.data[0];
rtgree01 0:ab4c4438577e 622 if (can_MsgRx.data[0] == 0x03)
rtgree01 0:ab4c4438577e 623 {
rtgree01 0:ab4c4438577e 624 status._dimmer = -1;
rtgree01 0:ab4c4438577e 625 }
rtgree01 0:ab4c4438577e 626 else if (can_MsgRx.data[0] == 0x02)
rtgree01 0:ab4c4438577e 627 {
rtgree01 0:ab4c4438577e 628 status._dimmer = can_MsgRx.data[1];
rtgree01 0:ab4c4438577e 629 }
rtgree01 0:ab4c4438577e 630 }
rtgree01 0:ab4c4438577e 631 else if (can_MsgRx.id == 0x3a0)
rtgree01 0:ab4c4438577e 632 {
rtgree01 0:ab4c4438577e 633 // note = 0x01
rtgree01 0:ab4c4438577e 634 // volume up = 0x02
rtgree01 0:ab4c4438577e 635 // volume down = 0x04
rtgree01 0:ab4c4438577e 636 // up arrow = 0x08
rtgree01 0:ab4c4438577e 637 // down arrow = 0x10
rtgree01 0:ab4c4438577e 638 // right arrow = 0x20
rtgree01 0:ab4c4438577e 639
rtgree01 0:ab4c4438577e 640 status.SWCButtons = can_MsgRx.data[0];
rtgree01 0:ab4c4438577e 641 }
rtgree01 0:ab4c4438577e 642 else if (can_MsgRx.id == 0x3bd)
rtgree01 0:ab4c4438577e 643 {
rtgree01 0:ab4c4438577e 644 ReadSiriusText((char *)can_MsgRx.data);
rtgree01 0:ab4c4438577e 645 }
rtgree01 0:ab4c4438577e 646 }
rtgree01 0:ab4c4438577e 647
rtgree01 0:ab4c4438577e 648 void RadioEmulator::ReadSiriusText(char *data)
rtgree01 0:ab4c4438577e 649 {
rtgree01 0:ab4c4438577e 650 int num = (data[0] & 0xF0) >> 4;
rtgree01 0:ab4c4438577e 651 if ((num > 7) || (num < 0))
rtgree01 0:ab4c4438577e 652 {
rtgree01 0:ab4c4438577e 653 return;
rtgree01 0:ab4c4438577e 654 }
rtgree01 0:ab4c4438577e 655
rtgree01 0:ab4c4438577e 656 int part = (data[0] & 0x0E) >> 1;
rtgree01 0:ab4c4438577e 657 if ((part > 7) || (part < 0))
rtgree01 0:ab4c4438577e 658 {
rtgree01 0:ab4c4438577e 659 return;
rtgree01 0:ab4c4438577e 660 }
rtgree01 0:ab4c4438577e 661
rtgree01 0:ab4c4438577e 662 if ((data[0] & 0x01) != 0)
rtgree01 0:ab4c4438577e 663 {
rtgree01 0:ab4c4438577e 664 memset(&siriusdata[num * 64], 0, 64);
rtgree01 0:ab4c4438577e 665 }
rtgree01 0:ab4c4438577e 666
rtgree01 0:ab4c4438577e 667 memset(&siriusdata[(num * 64) + (part * 7)], 0, 7);
rtgree01 0:ab4c4438577e 668
rtgree01 0:ab4c4438577e 669 for (int i = 1; i < 8; i++)
rtgree01 0:ab4c4438577e 670 {
rtgree01 0:ab4c4438577e 671 siriusdata[(num * 64) + (part * 7) + (i-1)] = data[i];
rtgree01 0:ab4c4438577e 672 }
rtgree01 0:ab4c4438577e 673 /*
rtgree01 0:ab4c4438577e 674 int cls = (data[0] & 0x0F) >> 1;
rtgree01 0:ab4c4438577e 675 if (cls - 1 == 0)
rtgree01 0:ab4c4438577e 676 {
rtgree01 0:ab4c4438577e 677 for (int i = 0; i < 8; i++)
rtgree01 0:ab4c4438577e 678 {
rtgree01 0:ab4c4438577e 679 memset(st.TextLine[i], 0, 64);
rtgree01 0:ab4c4438577e 680 for (int j = 0; j < 8; j++)
rtgree01 0:ab4c4438577e 681 {
rtgree01 0:ab4c4438577e 682 strcat(st.TextLine[i], siriusText[i][j]);
rtgree01 0:ab4c4438577e 683 }
rtgree01 0:ab4c4438577e 684
rtgree01 0:ab4c4438577e 685 printf("%d: %s\r\n", i, st.TextLine[i]);
rtgree01 0:ab4c4438577e 686 }
rtgree01 0:ab4c4438577e 687 }
rtgree01 0:ab4c4438577e 688 */
rtgree01 0:ab4c4438577e 689 }
rtgree01 0:ab4c4438577e 690
rtgree01 0:ab4c4438577e 691 void RadioEmulator::readCANbus(void)
rtgree01 0:ab4c4438577e 692 {
rtgree01 0:ab4c4438577e 693 if (CANDevice->read(can_MsgRx))
rtgree01 0:ab4c4438577e 694 {
rtgree01 0:ab4c4438577e 695 led3 = !led3;
rtgree01 0:ab4c4438577e 696 needToParseCANMessage = true;
rtgree01 0:ab4c4438577e 697 ReceivedCANMsg = true;
rtgree01 0:ab4c4438577e 698
rtgree01 0:ab4c4438577e 699
rtgree01 0:ab4c4438577e 700 char buffer[11];
rtgree01 0:ab4c4438577e 701 buffer[0] = (can_MsgRx.id & 0xFF00) >> 8;
rtgree01 0:ab4c4438577e 702 buffer[1] = can_MsgRx.id & 0x00FF;
rtgree01 0:ab4c4438577e 703 buffer[2] = can_MsgRx.len;
rtgree01 0:ab4c4438577e 704 memcpy(&buffer[3], can_MsgRx.data, 8);
rtgree01 0:ab4c4438577e 705
rtgree01 1:6dcab41a32df 706 static Host monitorHost(IpAddr(224,1,2,3), 41000, NULL);
rtgree01 1:6dcab41a32df 707 HostSock->SendTo(&monitorHost, can_MsgRx.len + 3, buffer);
rtgree01 0:ab4c4438577e 708
rtgree01 0:ab4c4438577e 709 }
rtgree01 0:ab4c4438577e 710
rtgree01 0:ab4c4438577e 711 if (needToParseCANMessage)
rtgree01 0:ab4c4438577e 712 {
rtgree01 0:ab4c4438577e 713 needToParseCANMessage = false;
rtgree01 0:ab4c4438577e 714
rtgree01 0:ab4c4438577e 715 ParseCANMessage(can_MsgRx);
rtgree01 0:ab4c4438577e 716 }
rtgree01 0:ab4c4438577e 717 }
rtgree01 0:ab4c4438577e 718
rtgree01 0:ab4c4438577e 719 void RadioEmulator::ReceivedData(int socketStatus, int len, char *msg)
rtgree01 0:ab4c4438577e 720 {
rtgree01 0:ab4c4438577e 721 if ((msg[0] == 0x42) && (msg[1] == 0x42) && (msg[2] == 0x42) && (msg[3] == 0x42))
rtgree01 0:ab4c4438577e 722 {
rtgree01 0:ab4c4438577e 723 ReceivedHostMsg = true;
rtgree01 0:ab4c4438577e 724
rtgree01 0:ab4c4438577e 725 switch (msg[4])
rtgree01 0:ab4c4438577e 726 {
rtgree01 0:ab4c4438577e 727 case 0x00:
rtgree01 0:ab4c4438577e 728 opMode = slave;
rtgree01 0:ab4c4438577e 729 break;
rtgree01 0:ab4c4438577e 730
rtgree01 0:ab4c4438577e 731 case 0x01:
rtgree01 0:ab4c4438577e 732 if (len >= 11)
rtgree01 0:ab4c4438577e 733 {
rtgree01 0:ab4c4438577e 734 status._volume = msg[5];
rtgree01 0:ab4c4438577e 735 status._balance = msg[6];
rtgree01 0:ab4c4438577e 736 status._fade = msg[7];
rtgree01 0:ab4c4438577e 737 status._bass = msg[8];
rtgree01 0:ab4c4438577e 738 status._mid = msg[9];
rtgree01 0:ab4c4438577e 739 status._treble = msg[10];
rtgree01 0:ab4c4438577e 740 }
rtgree01 0:ab4c4438577e 741
rtgree01 0:ab4c4438577e 742 // writeInitFile();
rtgree01 0:ab4c4438577e 743 break;
rtgree01 0:ab4c4438577e 744
rtgree01 0:ab4c4438577e 745 case 0x02:
rtgree01 0:ab4c4438577e 746 if (len >= 6)
rtgree01 0:ab4c4438577e 747 {
rtgree01 0:ab4c4438577e 748 status._siriusChan = msg[5];
rtgree01 0:ab4c4438577e 749 ChangeSiriusStation(msg[5], false);
rtgree01 0:ab4c4438577e 750 }
rtgree01 0:ab4c4438577e 751 break;
rtgree01 0:ab4c4438577e 752
rtgree01 0:ab4c4438577e 753 case 0x03:
rtgree01 0:ab4c4438577e 754 if (len >= 11)
rtgree01 0:ab4c4438577e 755 {
rtgree01 0:ab4c4438577e 756 status._radioMode = (radioMode)msg[5];
rtgree01 0:ab4c4438577e 757
rtgree01 0:ab4c4438577e 758 switch (status._radioMode)
rtgree01 0:ab4c4438577e 759 {
rtgree01 0:ab4c4438577e 760 case AM:
rtgree01 0:ab4c4438577e 761 status._amPreset = msg[6];
rtgree01 0:ab4c4438577e 762 status._amFreq = msg[7] + (msg[8] << 8);
rtgree01 0:ab4c4438577e 763 break;
rtgree01 0:ab4c4438577e 764
rtgree01 0:ab4c4438577e 765 case FM:
rtgree01 0:ab4c4438577e 766 status._fmPreset = msg[6];
rtgree01 0:ab4c4438577e 767 status._fmFreq = msg[7] + (msg[8] << 8);
rtgree01 0:ab4c4438577e 768 break;
rtgree01 0:ab4c4438577e 769
rtgree01 0:ab4c4438577e 770 case SAT:
rtgree01 0:ab4c4438577e 771 status._siriusPreset = msg[6];
rtgree01 0:ab4c4438577e 772 status._siriusChan = msg[7];
rtgree01 0:ab4c4438577e 773 break;
rtgree01 0:ab4c4438577e 774
rtgree01 0:ab4c4438577e 775 case CD:
rtgree01 0:ab4c4438577e 776 status._cdNum = msg[6];
rtgree01 0:ab4c4438577e 777 status._cdTrackNum = msg[7];
rtgree01 0:ab4c4438577e 778 status._cdHours = msg[8];
rtgree01 0:ab4c4438577e 779 status._cdMinutes = msg[9];
rtgree01 0:ab4c4438577e 780 status._cdSeconds = msg[10];
rtgree01 0:ab4c4438577e 781 break;
rtgree01 0:ab4c4438577e 782
rtgree01 0:ab4c4438577e 783 case VES:
rtgree01 0:ab4c4438577e 784 break;
rtgree01 0:ab4c4438577e 785 }
rtgree01 0:ab4c4438577e 786 }
rtgree01 0:ab4c4438577e 787 break;
rtgree01 0:ab4c4438577e 788
rtgree01 0:ab4c4438577e 789 case 0x04:
rtgree01 0:ab4c4438577e 790 // CANMessage canMsg;
rtgree01 0:ab4c4438577e 791 // canMsg.id = msg[5] + (msg[6] << 8);
rtgree01 0:ab4c4438577e 792 // canMsg.len = msg[7];
rtgree01 0:ab4c4438577e 793 // memcpy(canMsg.data, msg + 8, canMsg.len);
rtgree01 0:ab4c4438577e 794
rtgree01 0:ab4c4438577e 795 // hostMessages.push_back(canMsg);
rtgree01 0:ab4c4438577e 796 break;
rtgree01 0:ab4c4438577e 797
rtgree01 0:ab4c4438577e 798 }
rtgree01 0:ab4c4438577e 799
rtgree01 0:ab4c4438577e 800 }
rtgree01 0:ab4c4438577e 801 }
rtgree01 0:ab4c4438577e 802
rtgree01 0:ab4c4438577e 803 void RadioEmulator::WriteCANMessages()
rtgree01 0:ab4c4438577e 804 {
rtgree01 0:ab4c4438577e 805 writeCANFlag = true;
rtgree01 0:ab4c4438577e 806 }
rtgree01 0:ab4c4438577e 807
rtgree01 0:ab4c4438577e 808 void RadioEmulator::SendStatusToHost(void)
rtgree01 0:ab4c4438577e 809 {
rtgree01 0:ab4c4438577e 810 statusFlag = true;
rtgree01 0:ab4c4438577e 811 }
rtgree01 0:ab4c4438577e 812
rtgree01 0:ab4c4438577e 813 void RadioEmulator::CheckHostTimeout(void)
rtgree01 0:ab4c4438577e 814 {
rtgree01 0:ab4c4438577e 815 hostTimeoutFlag = true;
rtgree01 0:ab4c4438577e 816 }
rtgree01 0:ab4c4438577e 817
rtgree01 0:ab4c4438577e 818 // only enable this if trying to power up/down the processor
rtgree01 0:ab4c4438577e 819 void RadioEmulator::CheckCANTimeout(void)
rtgree01 0:ab4c4438577e 820 {
rtgree01 0:ab4c4438577e 821 CANTimeoutFlag = true;
rtgree01 0:ab4c4438577e 822 }
rtgree01 0:ab4c4438577e 823
rtgree01 0:ab4c4438577e 824 void RadioEmulator::CANActivity(void)
rtgree01 0:ab4c4438577e 825 {
rtgree01 0:ab4c4438577e 826 if (powerUpIRQCounter == 5)
rtgree01 0:ab4c4438577e 827 {
rtgree01 0:ab4c4438577e 828 canIRQ->rise(0);
rtgree01 0:ab4c4438577e 829 needToWakeUp = true;
rtgree01 0:ab4c4438577e 830 }
rtgree01 0:ab4c4438577e 831 powerUpIRQCounter++;
rtgree01 0:ab4c4438577e 832 }