00001 // Copyright (C) 2006 Pablo Mejia 00002 00003 00004 #ifndef AEVIT_DRIVE_FRAME_H 00005 #define AEVIT_DRIVE_FRAME_H 00006 00007 00008 #include "aevit_frame.H" 00009 #include <iostream> 00010 00011 namespace aevit 00012 { 00013 00014 class drive_frame_t : public frame_t 00015 { 00016 protected: 00017 static unsigned const DEVICE_MASK = 0x0F; 00018 static unsigned const ACTIVE_MASK = 0x10; 00019 static unsigned const ERROR_MASK = 0x60; 00020 static unsigned const ALIVE_MASK = 0x80; 00021 00022 static unsigned const ENCODER_LO_OFFSET = 1; 00023 static unsigned const ENCODER_HI_OFFSET = 2; 00024 00025 static unsigned const INPUT_LO_OFFSET = 1; 00026 static unsigned const INPUT_HI_OFFSET = 2; 00027 static unsigned const INPUT_MASK = 0x07FF; 00028 00029 static unsigned const DEACTIVATE_REQUESTED_MASK = 0x08; 00030 static unsigned const PARK_BRAKE_REQUESTED_MASK = 0x10; 00031 static unsigned const ACTIVATE_REQUESTED_MASK = 0x20; 00032 static unsigned const EVAL_CONNECTED_MASK = 0x40; 00033 static unsigned const EVAL_ACTIVE_MASK = 0x80; 00034 00035 static unsigned const GENERIC_LO_OFFSET = 5; 00036 static unsigned const GENERIC_HI_OFFSET = 6; 00037 static unsigned const COMMAND_OFFSET = 7; 00038 00039 public: 00040 drive_frame_t (frame_t const &frame_) : frame_t (frame_) {} 00041 00042 unsigned device () const { return m_data[0] & DEVICE_MASK; } 00043 00044 bool is_steering (unsigned id) const 00045 { 00046 unsigned val = id % 10; 00047 if (val <= 3) 00048 return true; 00049 else 00050 return false; 00051 } 00052 00053 bool is_throttle (unsigned id) const 00054 { 00055 unsigned val = id % 10; 00056 if (val >= 4 && val <= 7) 00057 return true; 00058 else 00059 return false; 00060 } 00061 00062 bool active () const { return (m_data[0] & ACTIVE_MASK) != 0; } 00063 bool error () const { return (m_data[0] & ERROR_MASK) != 0; } 00064 bool alive () const { return (m_data[0] & ALIVE_MASK) != 0; } 00065 00066 unsigned encoder () const 00067 { 00068 return (m_data[ENCODER_HI_OFFSET] << 8) | 00069 m_data[ENCODER_LO_OFFSET]; 00070 } 00071 unsigned input () const 00072 { 00073 return ((m_data[INPUT_HI_OFFSET] << 8) | 00074 m_data[INPUT_LO_OFFSET]) & INPUT_MASK; 00075 } 00076 00077 bool deactivate_requested () const 00078 { return (m_data[4] & DEACTIVATE_REQUESTED_MASK) != 0; } 00079 bool park_brake_requested () const 00080 { return (m_data[4] & PARK_BRAKE_REQUESTED_MASK) != 0; } 00081 bool activate_requested () const 00082 { return (m_data[4] & ACTIVATE_REQUESTED_MASK) != 0; } 00083 bool eval_connected () const 00084 { return (m_data[4] & EVAL_CONNECTED_MASK) != 0; } 00085 bool eval_active () const 00086 { return (m_data[4] & EVAL_ACTIVE_MASK) != 0; } 00087 00088 unsigned generic () const 00089 { 00090 return (m_data[GENERIC_HI_OFFSET] << 8) | 00091 m_data[GENERIC_LO_OFFSET]; 00092 } 00093 00094 unsigned command () const { return m_data[COMMAND_OFFSET]; } 00095 }; 00096 00097 00098 }; 00099 00100 00101 #endif