car chassis

Dependencies:   Servo mbed-rtos mbed

Files at this revision

API Documentation at this revision

Comitter:
mariob
Date:
Sun Oct 11 21:17:42 2015 +0000
Parent:
2:7dfc8dd6aab3
Child:
4:7fa7f78cbb92
Commit message:
renaming

Changed in this revision

body.cpp Show annotated file Show diff for this revision Revisions of this file
can.cpp Show annotated file Show diff for this revision Revisions of this file
car_config.hpp Show annotated file Show diff for this revision Revisions of this file
diag.cpp Show annotated file Show diff for this revision Revisions of this file
diag.hpp Show annotated file Show diff for this revision Revisions of this file
driver.cpp Show diff for this revision Revisions of this file
driver.hpp Show diff for this revision Revisions of this file
main.cpp Show annotated file Show diff for this revision Revisions of this file
net.hpp Show annotated file Show diff for this revision Revisions of this file
--- a/body.cpp	Thu Oct 08 13:36:17 2015 +0000
+++ b/body.cpp	Sun Oct 11 21:17:42 2015 +0000
@@ -56,9 +56,9 @@
     else {
       //if a message has been received, set lights
       if (can_cmd_body.flag == CAN_FLAG_RECEIVED) {
-        int r = can_cmd_body.payload.msg.light_r;
-        int l = can_cmd_body.payload.msg.light_l;
-        int c = can_cmd_body.payload.msg.light_c;
+        //int r = can_cmd_body.payload.msg.light_r;
+        //int l = can_cmd_body.payload.msg.light_l;
+        //int c = can_cmd_body.payload.msg.light_c;
         can_cmd_body.flag = CAN_FLAG_EMPTY;
       }
     }
--- a/can.cpp	Thu Oct 08 13:36:17 2015 +0000
+++ b/can.cpp	Sun Oct 11 21:17:42 2015 +0000
@@ -11,8 +11,8 @@
 can_sts_body_t can_sts_body;
 can_cmd_engine_t can_cmd_engine;
 can_cmd_time_t can_cmd_time;
-can_cmd_driver_t can_cmd_driver;
-can_sts_driver_t can_sts_driver;
+can_cmd_diag_t can_cmd_diag;
+can_sts_diag_t can_sts_diag;
 can_cmd_camera_t can_cmd_camera;
 
 /*** LOCAL DATA ***/
@@ -107,26 +107,26 @@
         can_cmd_time.flag = CAN_FLAG_RECEIVED;
         break;
 #endif
-#ifdef NET_RX_CMD_DRIVER
-      case CAN_CMD_DRIVER_ID:
-        can_cmd_driver.payload.buf[0] = message.data[0];
-        can_cmd_driver.payload.buf[1] = message.data[1];
-        can_cmd_driver.payload.buf[2] = message.data[2];
-        can_cmd_driver.payload.buf[3] = message.data[3];
-        can_cmd_driver.payload.buf[4] = message.data[4];
-        can_cmd_driver.payload.buf[5] = message.data[5];
-        can_cmd_driver.payload.buf[6] = message.data[6];
-        can_cmd_driver.payload.buf[7] = message.data[7];
-        can_cmd_driver.flag = CAN_FLAG_RECEIVED;
+#ifdef NET_RX_CMD_DIAG
+      case CAN_CMD_DIAG_ID:
+        can_cmd_diag.payload.buf[0] = message.data[0];
+        can_cmd_diag.payload.buf[1] = message.data[1];
+        can_cmd_diag.payload.buf[2] = message.data[2];
+        can_cmd_diag.payload.buf[3] = message.data[3];
+        can_cmd_diag.payload.buf[4] = message.data[4];
+        can_cmd_diag.payload.buf[5] = message.data[5];
+        can_cmd_diag.payload.buf[6] = message.data[6];
+        can_cmd_diag.payload.buf[7] = message.data[7];
+        can_cmd_diag.flag = CAN_FLAG_RECEIVED;
         break;
 #endif
-#ifdef NET_RX_STS_DRIVER
-      case CAN_STS_DRIVER_ID:
-        can_sts_driver.payload.buf[0] = message.data[0];
-        can_sts_driver.payload.buf[1] = message.data[1];
-        can_sts_driver.payload.buf[2] = message.data[2];
-        can_sts_driver.payload.buf[3] = message.data[3];
-        can_sts_driver.flag = CAN_FLAG_RECEIVED;
+#ifdef NET_RX_STS_DIAG
+      case CAN_STS_DIAG_ID:
+        can_sts_diag.payload.buf[0] = message.data[0];
+        can_sts_diag.payload.buf[1] = message.data[1];
+        can_sts_diag.payload.buf[2] = message.data[2];
+        can_sts_diag.payload.buf[3] = message.data[3];
+        can_sts_diag.flag = CAN_FLAG_RECEIVED;
         break;
 #endif
 #ifdef NET_RX_CMD_CAMERA
@@ -195,24 +195,24 @@
 #endif
 
   /** event messages */
-#ifdef NET_TX_CMD_DRIVER
-  if (can_cmd_driver.flag == CAN_FLAG_SEND) {
+#ifdef NET_TX_CMD_DIAG
+  if (can_cmd_diag.flag == CAN_FLAG_SEND) {
     wait(2); //wait 2 milliseconds between 2 consecutive transmissions
-    if (!can.write(CANMessage(CAN_CMD_DRIVER_ID,
-                             (char*)(&(can_cmd_driver.payload.buf)),
-                             CAN_CMD_PAYLOAD_DRIVER)))
-      printf("SEND CMD_DRIVER NOT OK\r\n");
-    can_cmd_driver.flag = CAN_FLAG_EMPTY;
+    if (!can.write(CANMessage(CAN_CMD_DIAG_ID,
+                             (char*)(&(can_cmd_diag.payload.buf)),
+                             CAN_CMD_PAYLOAD_DIAG)))
+      printf("SEND CMD_DIAG NOT OK\r\n");
+    can_cmd_diag.flag = CAN_FLAG_EMPTY;
   }
 #endif
-#ifdef NET_TX_STS_DRIVER
-  if (can_sts_driver.flag == CAN_FLAG_SEND) {
+#ifdef NET_TX_STS_DIAG
+  if (can_sts_diag.flag == CAN_FLAG_SEND) {
     wait(2); //wait 2 milliseconds between 2 consecutive transmissions
-    if (!can.write(CANMessage(CAN_STS_DRIVER_ID,
-                             (char*)(&(can_sts_driver.payload.buf)),
-                             CAN_STS_PAYLOAD_DRIVER)))
-      printf("SEND STS_DRIVER NOT OK\r\n");
-    can_sts_driver.flag = CAN_FLAG_EMPTY;
+    if (!can.write(CANMessage(CAN_STS_DIAG_ID,
+                             (char*)(&(can_sts_diag.payload.buf)),
+                             CAN_STS_PAYLOAD_DIAG)))
+      printf("SEND STS_DIAG NOT OK\r\n");
+    can_sts_diag.flag = CAN_FLAG_EMPTY;
   }
 #endif
 #ifdef NET_TX_CMD_TIME
--- a/car_config.hpp	Thu Oct 08 13:36:17 2015 +0000
+++ b/car_config.hpp	Sun Oct 11 21:17:42 2015 +0000
@@ -10,7 +10,7 @@
 #define CLOCK_THREAD_PERIOD     1000  //milliseconds
 #define ENGINE_THREAD_PERIOD    250   //milliseconds
 #define BODY_THREAD_PERIOD      500   //milliseconds
-#define DRIVER_THREAD_PERIOD    500   //milliseconds
+#define DIAG_THREAD_PERIOD      500   //milliseconds
 #define CAN_THREAD_PERIOD       100   //milliseconds
 
 /*********************
@@ -21,15 +21,15 @@
 #define NET_TX_STS_BODY
 //#define NET_TX_CMD_ENGINE
 //#define NET_TX_CMD_TIME
-//#define NET_TX_CMD_DRIVER
-#define NET_TX_STS_DRIVER
+//#define NET_TX_CMD_DIAG
+#define NET_TX_STS_DIAG
 //#define NET_TX_CMD_CAMERA
 #define NET_RX_CMD_BODY
 //#define NET_RX_STS_BODY
 #define NET_RX_CMD_ENGINE
 #define NET_RX_CMD_TIME
-#define NET_RX_CMD_DRIVER
-//#define NET_RX_STS_DRIVER
+#define NET_RX_CMD_DIAG
+//#define NET_RX_STS_DIAG
 //#define NET_RX_CMD_CAMERA
 
 /*********************
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/diag.cpp	Sun Oct 11 21:17:42 2015 +0000
@@ -0,0 +1,28 @@
+#include "car_config.hpp"
+#include "can.hpp"
+#include "net.hpp"
+#include "mbed.h"
+#include "rtos.h"
+
+void init_diag () {
+}
+
+void thread_diag (void const *args) {
+  while(1) {
+    if (can_cmd_diag.flag == CAN_FLAG_RECEIVED) {
+      uint16 cmd = can_cmd_diag.payload.msg.cmd;
+      uint32 data = can_cmd_diag.payload.msg.data;
+      switch(cmd) {
+        case CMD_ECHO:
+          can_sts_diag.payload.msg.data = data;
+          can_sts_diag.flag = CAN_FLAG_SEND;
+          break;
+        default:
+          //ignore it
+          break;
+      }
+      can_cmd_diag.flag = CAN_FLAG_EMPTY;
+    }
+    Thread::wait(DIAG_THREAD_PERIOD);
+  }
+}
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/diag.hpp	Sun Oct 11 21:17:42 2015 +0000
@@ -0,0 +1,10 @@
+#ifndef __DIAG_HPP__
+#define __DIAG_HPP__
+
+//initialize the diagnosis module
+void init_diag();
+
+//execute pending diagnosis operations
+void thread_diag (void const *args);
+
+#endif //__DIAG_HPP__
--- a/driver.cpp	Thu Oct 08 13:36:17 2015 +0000
+++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
@@ -1,28 +0,0 @@
-#include "car_config.hpp"
-#include "can.hpp"
-#include "net.hpp"
-#include "mbed.h"
-#include "rtos.h"
-
-void init_driver () {
-}
-
-void thread_driver (void const *args) {
-  while(1) {
-    if (can_cmd_driver.flag == CAN_FLAG_RECEIVED) {
-      uint16 cmd = can_cmd_driver.payload.msg.cmd;
-      uint32 data = can_cmd_driver.payload.msg.data;
-      switch(cmd) {
-        case CMD_ECHO:
-          can_sts_driver.payload.msg.data = data;
-          can_sts_driver.flag = CAN_FLAG_SEND;
-          break;
-        default:
-          //ignore it
-          break;
-      }
-      can_cmd_driver.flag = CAN_FLAG_EMPTY;
-    }
-    Thread::wait(DRIVER_THREAD_PERIOD);
-  }
-}
--- a/driver.hpp	Thu Oct 08 13:36:17 2015 +0000
+++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
@@ -1,10 +0,0 @@
-#ifndef __DRIVER_HPP__
-#define __DRIVER_HPP__
-
-//initialize the diagnosis module
-void init_driver();
-
-//execute pending diagnosis operations
-void thread_driver (void const *args);
-
-#endif //__DRIVER_HPP__
--- a/main.cpp	Thu Oct 08 13:36:17 2015 +0000
+++ b/main.cpp	Sun Oct 11 21:17:42 2015 +0000
@@ -1,3 +1,5 @@
+//this project implements the body/engine devices
+
 #include "mbed.h"
 #include "car_config.hpp"
 #include "rtos.h"
@@ -6,11 +8,11 @@
 #include "led.hpp"
 #include "body.hpp"
 #include "engine.hpp"
-#include "driver.hpp"
+#include "diag.hpp"
 #include "clock.hpp"
 
 //initialize the system:
-//- single components: body, clock, driver (diagnosis), engine
+//- single components: body, clock, diagnosis, engine
 //- hardware: leds, can
 //- threads
 int init();
@@ -27,7 +29,7 @@
 Thread *th_body;
 Thread *th_can;
 Thread *th_engine;
-Thread *th_driver;
+Thread *th_diag;
 Thread *th_clock;
 
 void init_threads ()
@@ -35,7 +37,7 @@
   th_body = new Thread(thread_body);
   th_engine = new Thread(thread_engine);
   th_can = new Thread(thread_can);
-  th_driver = new Thread(thread_driver);
+  th_diag = new Thread(thread_diag);
   th_clock = new Thread(thread_clock);
 }
 
@@ -43,7 +45,7 @@
 {
   init_body();
   init_clock();
-  init_driver();
+  init_diag();
   init_engine();
 
   //printf("INIT LED\r\n");
--- a/net.hpp	Thu Oct 08 13:36:17 2015 +0000
+++ b/net.hpp	Sun Oct 11 21:17:42 2015 +0000
@@ -17,8 +17,8 @@
 #define CAN_STS_BODY_ID         0xAB
 #define CAN_CMD_ENGINE_ID       0x0A
 #define CAN_CMD_TIME_ID         0xBB
-#define CAN_CMD_DRIVER_ID       0x11
-#define CAN_STS_DRIVER_ID       0x10
+#define CAN_CMD_DIAG_ID         0x11
+#define CAN_STS_DIAG_ID         0x10
 #define CAN_CMD_CAMERA_ID       0x22
 
 /**************************************************
@@ -56,8 +56,8 @@
 #define CAN_STS_PAYLOAD_BODY    8
 #define CAN_CMD_PAYLOAD_ENGINE  4
 #define CAN_CMD_PAYLOAD_TIME    4
-#define CAN_CMD_PAYLOAD_DRIVER  8
-#define CAN_STS_PAYLOAD_DRIVER  4
+#define CAN_CMD_PAYLOAD_DIAG    8
+#define CAN_STS_PAYLOAD_DIAG    4
 #define CAN_CMD_PAYLOAD_CAMERA  2
 
 /**************************************************
@@ -122,29 +122,29 @@
     uint8 flag;
 } can_cmd_time_t;
 
-typedef union can_cmd_driver_payload_s {
-    uint8 buf[CAN_CMD_PAYLOAD_DRIVER];
+typedef union can_cmd_diag_payload_s {
+    uint8 buf[CAN_CMD_PAYLOAD_DIAG];
     struct {
         uint32 cmd:16;
         uint32 opt:16;
         uint32 data;
     } msg;
-} can_cmd_driver_payload_t;
-typedef struct can_cmd_driver_s {
-    can_cmd_driver_payload_t payload;
+} can_cmd_diag_payload_t;
+typedef struct can_cmd_diag_s {
+    can_cmd_diag_payload_t payload;
     uint8 flag;
-} can_cmd_driver_t;
+} can_cmd_diag_t;
 
-typedef union can_sts_driver_payload_s {
-    uint8 buf[CAN_STS_PAYLOAD_DRIVER];
+typedef union can_sts_diag_payload_s {
+    uint8 buf[CAN_STS_PAYLOAD_DIAG];
     struct {
         uint32 data;
     } msg;
-} can_sts_driver_payload_t;
-typedef struct can_sts_driver_time_s {
-    can_sts_driver_payload_t payload;
+} can_sts_diag_payload_t;
+typedef struct can_sts_diag_time_s {
+    can_sts_diag_payload_t payload;
     uint8 flag;
-} can_sts_driver_t;
+} can_sts_diag_t;
 
 typedef union can_cmd_camera_payload_s {
     uint8 buf[CAN_CMD_PAYLOAD_CAMERA];
@@ -167,8 +167,8 @@
 extern can_sts_body_t can_sts_body;
 extern can_cmd_engine_t can_cmd_engine;
 extern can_cmd_time_t can_cmd_time;
-extern can_cmd_driver_t can_cmd_driver;
-extern can_sts_driver_t can_sts_driver;
+extern can_cmd_diag_t can_cmd_diag;
+extern can_sts_diag_t can_sts_diag;
 extern can_cmd_camera_t can_cmd_camera;
 
 #endif //__NET_H__