Simulated the CD changer of a Saab to implement a bluetooth connection to the car stereo. Control of playback device (phone) with steering wheel buttons. Needs a RN52 bluetooth transciever and a CAN transiever. So far only audio playback and control via steering wheel buttons implemented. Hands free calling planned.

Dependencies:   mbed

Revision:
3:b76c74783d0d
Parent:
2:10c60edc8573
Child:
6:c454f88524d6
--- a/CDC.cpp	Mon Jan 04 23:36:50 2016 +0000
+++ b/CDC.cpp	Tue Jan 05 21:32:11 2016 +0000
@@ -42,7 +42,24 @@
 bool cdc_active = false; // True while our module, the simulated CDC, is active.
 bool mute = false;
 int toggle_shuffle = 1;
-int ninefive_cmd[] = {0x32,0x00,0x00,0x16,0x01,0x02,0x00,0x00,-1};
+int ninefive_poweron_cmd[4][9] = {
+    {0x32,0x00,0x00,0x03,0x01,0x02,0x00,0x00,-1},
+    {0x42,0x00,0x00,0x22,0x00,0x00,0x00,0x00,-1},
+    {0x52,0x00,0x00,0x22,0x00,0x00,0x00,0x00,-1},
+    {0x62,0x00,0x00,0x22,0x00,0x00,0x00,0x00,-1}
+};
+int ninefive_active_cmd[4][9] = {
+    {0x32,0x00,0x00,0x16,0x01,0x02,0x00,0x00,-1},
+    {0x42,0x00,0x00,0x36,0x00,0x00,0x00,0x00,-1},
+    {0x52,0x00,0x00,0x36,0x00,0x00,0x00,0x00,-1},
+    {0x62,0x00,0x00,0x36,0x00,0x00,0x00,0x00,-1},
+};
+int ninefive_powerdown_cmd[4][9] = {
+    {0x32,0x00,0x00,0x19,0x01,0x00,0x00,0x00,-1},
+    {0x42,0x00,0x00,0x38,0x01,0x00,0x00,0x00,-1},
+    {0x52,0x00,0x00,0x38,0x01,0x00,0x00,0x00,-1},
+    {0x62,0x00,0x00,0x38,0x01,0x00,0x00,0x00,-1}
+};
 int beep_cmd[] = {0x80,0x04,0x00,0x00,0x00,0x00,0x00,0x00,-1};
 int cdc_status_cmd[] = {0xE0,0x00,0x01,0x41,0x01,0x00,0x00,0xD0,-1};
 int display_request_cmd[] = {CDC_APL_ADR,0x02,0x05,CDC_SID_FUNCTION_ID,0x00,0x00,0x00,0x00,-1};
@@ -119,7 +136,23 @@
                 led1 = !led1;
                 break;
             case NODE_STATUS_RX:
-                send_can_frame(NODE_STATUS_TX, ninefive_cmd);
+                switch (CAN_RxMsg.data[3] & 0x0F){
+                    case (0x3):
+                        for (int i = 0; i < 4; i++) {
+                            send_can_frame(NODE_STATUS_TX, ninefive_poweron_cmd[i]);
+                        }
+                        break;
+                    case (0x2):
+                        for (int i = 0; i < 4; i++) {
+                            send_can_frame(NODE_STATUS_TX, ninefive_active_cmd[i]);
+                        }
+                        break;
+                    case (0x8):
+                        for (int i = 0; i < 4; i++) {
+                            send_can_frame(NODE_STATUS_TX, ninefive_powerdown_cmd[i]);
+                        }
+                        break;
+                }
                 break;
             case IHU_BUTTONS:
                 return get_ihu_cmd();