libpandac  0.0.0
A library designed for a comm.ai Panda.
obd-pid.h
1 /*
2  Author: Matt Bunting
3  Copyright (c) 2020 Arizona Board of Regents
4  All rights reserved.
5 
6  Permission is hereby granted, without written agreement and without
7  license or royalty fees, to use, copy, modify, and distribute this
8  software and its documentation for any purpose, provided that the
9  above copyright notice and the following two paragraphs appear in
10  all copies of this software.
11 
12  IN NO EVENT SHALL THE ARIZONA BOARD OF REGENTS BE LIABLE TO ANY PARTY
13  FOR DIRECT, INDIRECT, SPECIAL, INCIDENTAL, OR CONSEQUENTIAL DAMAGES
14  ARISING OUT OF THE USE OF THIS SOFTWARE AND ITS DOCUMENTATION, EVEN
15  IF THE UNIVERSITY OF CALIFORNIA HAS BEEN ADVISED OF THE POSSIBILITY OF
16  SUCH DAMAGE.
17 
18  THE ARIZONA BOARD OF REGENTS SPECIFICALLY DISCLAIMS ANY WARRANTIES,
19  INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY
20  AND FITNESS FOR A PARTICULAR PURPOSE. THE SOFTWARE PROVIDED HEREUNDER
21  IS ON AN "AS IS" BASIS, AND THE UNIVERSITY OF CALIFORNIA HAS NO OBLIGATION
22  TO PROVIDE MAINTENANCE, SUPPORT, UPDATES, ENHANCEMENTS, OR MODIFICATIONS.
23 
24  */
25 
26 #ifndef OBD_PID_H
27 #define OBD_PID_H
28 
29 #include <queue>
30 
31 #include "can.h"
32 
33 
34 #define CAN_FRAME_TYPE_MASK (0xF0)
35 
36 namespace Panda {
37 
38 
39 // TODO: Codify some PID codes from here as enums/defines
40 // https://en.wikipedia.org/wiki/OBD-II_PIDs#Service_09
41 
42 
43 //enum CanFrameTypes {
44 // CAN_FRAME_SINGLE = 0x00,
45 // CAN_FRAME_FIRST = 0x01,
46 // CAN_FRAME_CONSECUTIVE = 0x02,
47 // CAN_FRAME_FLOW_CONTROL = 0x03
48 //};
49 
50 
51 //class Handler;
52 class ObdPidRequest : public CanListener, public Mogi::Thread {
53 
54 public:
55  unsigned char* data;
56  int dataLength; // this should always be 17
57 
58  ObdPidRequest(Can& handler);
59  ~ObdPidRequest();
60 
61  void request( unsigned char mode, unsigned char pid );
62 
63  bool complete();
64 
65 private:
66  unsigned char* tempData;
67  int tempLength;
68 
69  int assignedId;
70 
71  bool busy;
72 
73  unsigned char mode;
74  unsigned char pid;
75  Can *canHandler;
76 
77  std::queue<CanFrame> frameQueue;
78 
79  void sendFlowControl();
80 
81  // Override from Mogi::Thread
82  void doAction();
83 
84  // Override from CanListener:
85  void newDataNotification( CanFrame* canFrame );
86 
87 };
88 
89 
90 }
91 
92 
93 #endif
Handles USB communication and parsing with a comma.ai Panda.
Definition: can.h:38
Definition: obd-pid.h:52
An abstract class for new data notifications for new CAN data.
Definition: can.h:63
Abstract class, handles a single thread. Features mutual exclusion and pause/resume.
Definition: thread.h:27
Definition: candata.h:38
A class that handles the CAN data.
Definition: can.h:103