Library to control Dodge LX (83.3k) CAN devices

Dependents:   DodgeRadioEmulatorv30

Committer:
rtgree01
Date:
Mon Aug 20 02:35:43 2012 +0000
Revision:
0:ab4c4438577e
Child:
1:6dcab41a32df
[mbed] converted /DodgeRadioEmulatorv30/DodgeRadioLib

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