rusEFI
The most advanced open source ECU
Loading...
Searching...
No Matches
Public Member Functions | Data Fields
ObdCanSensor< Size, Offset > Class Template Reference

#include <can_sensor.h>

Inheritance diagram for ObdCanSensor< Size, Offset >:
Inheritance graph
[legend]
Collaboration diagram for ObdCanSensor< Size, Offset >:
Collaboration graph
[legend]

Public Member Functions

 ObdCanSensor (int p_PID, float p_Scale, SensorType type)
 
void decodeFrame (const CANRxFrame &frame, efitick_t nowNt) override
 
CanListenerrequest () override
 
- Public Member Functions inherited from CanSensorBase
 CanSensorBase (uint32_t eid, SensorType type, efidur_t timeout)
 
void showInfo (const char *sensorName) const override
 
- Public Member Functions inherited from StoredValueSensor
SensorResult get () const final override
 
 StoredValueSensor (SensorType type, efidur_t timeoutNt)
 
void invalidate ()
 
void invalidate (UnexpectedCode why)
 
void setValidValue (float value, efitick_t timestamp)
 
void showInfo (const char *sensorName) const override
 
virtual void setTimeout (int timeoutMs)
 
- Public Member Functions inherited from Sensor
bool Register ()
 
const chargetSensorName () const
 
virtual bool hasSensor () const
 
virtual float getRaw () const
 
virtual bool isRedundant () const
 
void unregister ()
 
SensorType type () const
 
- Public Member Functions inherited from CanListener
 CanListener (uint32_t id)
 
CanListenerprocessFrame (const size_t busIndex, const CANRxFrame &frame, efitick_t nowNt)
 
uint32_t getId ()
 
void setNext (CanListener *next)
 
bool hasNext () const
 
virtual bool acceptFrame (const size_t busIndex, const CANRxFrame &frame) const
 

Data Fields

int PID
 
float Scale
 

Additional Inherited Members

- Static Public Member Functions inherited from Sensor
static void showAllSensorInfo ()
 
static void showInfo (SensorType type)
 
static void resetRegistry ()
 
static const SensorgetSensorOfType (SensorType type)
 
static SensorResult get (SensorType type)
 
static float getOrZero (SensorType type)
 
static float getRaw (SensorType type)
 
static bool isRedundant (SensorType type)
 
static bool hasSensor (SensorType type)
 
static void setMockValue (SensorType type, float value, bool mockRedundant=false)
 
static void setInvalidMockValue (SensorType type)
 
static void resetMockValue (SensorType type)
 
static void resetAllMocks ()
 
static void inhibitTimeouts (bool inhibit)
 
static const chargetSensorName (SensorType type)
 
- Protected Member Functions inherited from Sensor
 Sensor (SensorType type)
 
- Static Protected Attributes inherited from Sensor
static bool s_inhibitSensorTimeouts = false
 

Detailed Description

template<int Size, int Offset>
class ObdCanSensor< Size, Offset >

Definition at line 59 of file can_sensor.h.

Constructor & Destructor Documentation

◆ ObdCanSensor()

template<int Size, int Offset>
ObdCanSensor< Size, Offset >::ObdCanSensor ( int  p_PID,
float  p_Scale,
SensorType  type 
)
inline

Definition at line 61 of file can_sensor.h.

61 :
62 CanSensorBase(OBD_TEST_RESPONSE, type, /* timeout, never expire */ 0) {
63 this->PID = p_PID;
64 this->Scale = p_Scale;
65 }
SensorType type() const
Definition sensor.h:162

Member Function Documentation

◆ decodeFrame()

template<int Size, int Offset>
void ObdCanSensor< Size, Offset >::decodeFrame ( const CANRxFrame frame,
efitick_t  nowNt 
)
inlineoverridevirtual

Implements CanListener.

Definition at line 67 of file can_sensor.h.

67 {
68 if (frame.data8[2] != PID) {
69 return;
70 }
71
72 int iValue;
73 if (Size == 2) {
74 iValue = frame.data8[3] * 256 + frame.data8[4];
75 } else {
76 iValue = frame.data8[3];
77 }
78
79 float fValue = (1.0 * iValue / Scale) - Offset;
80 setValidValue(fValue, nowNt);
81 }
void setValidValue(float value, efitick_t timestamp)
uint8_t data8[8]
Frame data.
Definition can_mocks.h:55
Here is the call graph for this function:

◆ request()

template<int Size, int Offset>
CanListener * ObdCanSensor< Size, Offset >::request ( void  )
inlineoverridevirtual

Reimplemented from CanListener.

Definition at line 83 of file can_sensor.h.

83 {
84 {
85 CanTxMessage msg(CanCategory::OBD, OBD_TEST_REQUEST);
86 msg[0] = _OBD_2;
87 msg[1] = OBD_CURRENT_DATA;
88 msg[2] = PID;
89 }
90 // let's sleep on write update after each OBD request, this would give read thread a chance to read response
91 // todo: smarter logic of all this with with semaphore not just sleep
92 chThdSleepMilliseconds(300);
93 return CanListener::request();
94 }
virtual CanListener * request()
Here is the call graph for this function:

Field Documentation

◆ PID

template<int Size, int Offset>
int ObdCanSensor< Size, Offset >::PID

◆ Scale

template<int Size, int Offset>
float ObdCanSensor< Size, Offset >::Scale

The documentation for this class was generated from the following file: