Skip to content

Commit

Permalink
Merge pull request #914 from frogonwheels/incoming_poll_state
Browse files Browse the repository at this point in the history
Use state record as parameters for Incoming poll
  • Loading branch information
dexterbg committed Jan 7, 2024
2 parents aa7762f + 8926e88 commit 0e15bdc
Show file tree
Hide file tree
Showing 68 changed files with 707 additions and 717 deletions.
30 changes: 16 additions & 14 deletions vehicle/OVMS.V3/components/vehicle/vehicle.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -276,24 +276,26 @@ OvmsVehicle::OvmsVehicle()
m_ready = false;

m_poll_state = 0;
m_poll_bus = NULL;
m_poll_bus_default = NULL;
m_poll_txcallback = std::bind(&OvmsVehicle::PollerTxCallback, this, _1, _2);
m_poll_plist = NULL;
m_poll_plcur = NULL;
m_poll_entry = {};
m_poll_vwtp = {};
m_poll_ticker = 0;

m_poll.bus = NULL;
m_poll.entry = {};
m_poll.ticker = 0;
m_poll_single_rxbuf = NULL;
m_poll_single_rxerr = 0;
m_poll_moduleid_sent = 0;
m_poll_moduleid_low = 0;
m_poll_moduleid_high = 0;
m_poll_type = 0;
m_poll_pid = 0;
m_poll_ml_remain = 0;
m_poll_ml_offset = 0;
m_poll_ml_frame = 0;
m_poll.moduleid_sent = 0;
m_poll.moduleid_low = 0;
m_poll.moduleid_high = 0;
m_poll.type = 0;
m_poll.pid = 0;
m_poll.mlremain = 0;
m_poll.mloffset = 0;
m_poll.mlframe = 0;

m_poll_wait = 0;
m_poll_sequence_max = 1;
m_poll_sequence_cnt = 0;
Expand Down Expand Up @@ -476,14 +478,14 @@ void OvmsVehicle::RxTask()
{
PollerVWTPReceive(&frame, frame.MsgID);
}
else if (m_poll_wait && frame.origin == m_poll_bus && m_poll_plist)
else if (m_poll_wait && frame.origin == m_poll.bus && m_poll_plist)
{
uint32_t msgid;
if (m_poll_protocol == ISOTP_EXTADR)
if (m_poll.protocol == ISOTP_EXTADR)
msgid = frame.MsgID << 8 | frame.data.u8[0];
else
msgid = frame.MsgID;
if (msgid >= m_poll_moduleid_low && msgid <= m_poll_moduleid_high)
if (msgid >= m_poll.moduleid_low && msgid <= m_poll.moduleid_high)
{
PollerISOTPReceive(&frame, msgid);
}
Expand Down
111 changes: 64 additions & 47 deletions vehicle/OVMS.V3/components/vehicle/vehicle.h
Original file line number Diff line number Diff line change
Expand Up @@ -284,6 +284,53 @@ inline bool operator<(OvmsStatus lhs, OvmsStatus rhs) {
return static_cast<short>(lhs) < static_cast<short>(rhs);
}

namespace OvmsPoller
{
typedef struct
{
uint32_t txmoduleid; // transmission CAN ID (address), 0x7df = OBD2 broadcast
uint32_t rxmoduleid; // expected response CAN ID or 0 for broadcasts
uint16_t type; // UDS poll type / OBD2 "mode", see VEHICLE_POLL_TYPE_…
union
{
uint16_t pid; // PID (shortcut for requests w/o payload)
struct
{
uint16_t pid; // PID for requests with additional payload
uint8_t datalen; // payload length (bytes)
uint8_t data[6]; // inline payload data (single frame request)
} args;
struct
{
uint16_t pid; // PID for requests with additional payload
uint8_t tag; // needs to be POLL_TXDATA
uint16_t datalen; // payload length (bytes, max 4095)
const uint8_t* data; // pointer to payload data (single/multi frame request)
} xargs;
};
uint16_t polltime[VEHICLE_POLL_NSTATES]; // poll intervals in seconds for used poll states
uint8_t pollbus; // 0 = default CAN bus from PollSetPidList(), 1…4 = specific
uint8_t protocol; // ISOTP_STD / ISOTP_EXTADR / ISOTP_EXTFRAME / VWTP_20
} poll_pid_t;

typedef struct
{
canbus* bus; ///< Bus to poll on.
uint32_t protocol; ///< ISOTP_STD / ISOTP_EXTADR / ISOTP_EXTFRAME / VWTP_20.
uint16_t type; ///< Expected type
uint16_t pid; ///< Expected PID
uint32_t moduleid_sent; ///< ModuleID last sent
uint32_t moduleid_low; ///< Expected response moduleid low mark
uint32_t moduleid_high; ///< Expected response moduleid high mark
uint32_t moduleid_rec; ///< Actual received moduleid.
uint16_t mlframe; ///< Frame number for multi frame response
uint16_t mloffset; ///< Current Byte offset of multi frame response
uint16_t mlremain; ///< Bytes remaining for multi frame response
OvmsPoller::poll_pid_t entry; ///< Currently processed entry of poll list (copy)
uint32_t ticker; ///< Polling tick count
} poll_job_t;
}

class OvmsVehicle : public InternalRamAllocated
{
friend class OvmsVehicleFactory;
Expand Down Expand Up @@ -321,8 +368,6 @@ class OvmsVehicle : public InternalRamAllocated

protected:
virtual void PollerStateTicker();
virtual void IncomingPollReply(canbus* bus, uint16_t type, uint16_t pid, uint8_t* data, uint8_t length, uint16_t mlremain);
virtual void IncomingPollError(canbus* bus, uint16_t type, uint16_t pid, uint16_t code);

protected:
int m_minsoc; // The minimum SOC level before alert
Expand Down Expand Up @@ -539,56 +584,20 @@ class OvmsVehicle : public InternalRamAllocated
virtual bool SetFeature(int key, const char* value);
virtual const std::string GetFeature(int key);

public:
typedef struct
{
uint32_t txmoduleid; // transmission CAN ID (address), 0x7df = OBD2 broadcast
uint32_t rxmoduleid; // expected response CAN ID or 0 for broadcasts
uint16_t type; // UDS poll type / OBD2 "mode", see VEHICLE_POLL_TYPE_…
union
{
uint16_t pid; // PID (shortcut for requests w/o payload)
struct
{
uint16_t pid; // PID for requests with additional payload
uint8_t datalen; // payload length (bytes)
uint8_t data[6]; // inline payload data (single frame request)
} args;
struct
{
uint16_t pid; // PID for requests with additional payload
uint8_t tag; // needs to be POLL_TXDATA
uint16_t datalen; // payload length (bytes, max 4095)
const uint8_t* data; // pointer to payload data (single/multi frame request)
} xargs;
};
uint16_t polltime[VEHICLE_POLL_NSTATES]; // poll intervals in seconds for used poll states
uint8_t pollbus; // 0 = default CAN bus from PollSetPidList(), 1…4 = specific
uint8_t protocol; // ISOTP_STD / ISOTP_EXTADR / ISOTP_EXTFRAME / VWTP_20
} poll_pid_t;

protected:
OvmsRecMutex m_poll_mutex; // Concurrency protection for recursive calls
uint8_t m_poll_state; // Current poll state
canbus* m_poll_bus; // Bus to poll on
canbus* m_poll_bus_default; // Bus default to poll on
const poll_pid_t* m_poll_plist; // Head of poll list
const poll_pid_t* m_poll_plcur; // Poll list loop cursor
poll_pid_t m_poll_entry; // Currently processed entry of poll list (copy)
uint32_t m_poll_ticker; // Polling ticker
uint8_t m_poll_protocol; // ISOTP_STD / ISOTP_EXTADR / ISOTP_EXTFRAME / VWTP_20
uint32_t m_poll_moduleid_sent; // ModuleID last sent
uint32_t m_poll_moduleid_low; // Expected response moduleid low mark
uint32_t m_poll_moduleid_high; // Expected response moduleid high mark
uint16_t m_poll_type; // Expected type
uint16_t m_poll_pid; // Expected PID
const OvmsPoller::poll_pid_t* m_poll_plist; // Head of poll list
const OvmsPoller::poll_pid_t* m_poll_plcur; // Poll list loop cursor
private:
// Poll state for received data.
OvmsPoller::poll_job_t m_poll;

const uint8_t* m_poll_tx_data; // Payload data for multi frame request
uint16_t m_poll_tx_remain; // Payload bytes remaining for multi frame request
uint16_t m_poll_tx_offset; // Payload offset of multi frame request
uint16_t m_poll_tx_frame; // Frame number for multi frame request
uint16_t m_poll_ml_remain; // Bytes remaining for multi frame response
uint16_t m_poll_ml_offset; // Offset of multi frame response
uint16_t m_poll_ml_frame; // Frame number for multi frame response
uint8_t m_poll_wait; // Wait counter for a reply from a sent poll or bytes remaining.
// Gets set = 2 when a poll is sent OR when bytes are remaining after receiving.
// Gets set = 0 when a poll is received.
Expand All @@ -599,6 +608,12 @@ class OvmsVehicle : public InternalRamAllocated
// Only when the reply doesn't get in until the next ticker occurs
// PollserSend() decrements to 0 and abandons the outstanding reply (=timeout)

protected:
// Polling Response
virtual void IncomingPollReply(const OvmsPoller::poll_job_t &job, uint8_t* data, uint8_t length);
virtual void IncomingPollError(const OvmsPoller::poll_job_t &job, uint16_t code);
virtual void IncomingPollTxCallback(const OvmsPoller::poll_job_t &job, bool success);

private:
uint8_t m_poll_sequence_max; // Polls allowed to be sent in sequence per time tick (second), default 1, 0 = no limit
uint8_t m_poll_sequence_cnt; // Polls already sent in the current time tick (second)
Expand All @@ -615,7 +630,11 @@ class OvmsVehicle : public InternalRamAllocated
vwtp_channel_t m_poll_vwtp; // VWTP channel state

protected:
void PollSetPidList(canbus* bus, const poll_pid_t* plist);
void PollSetPidList(canbus* bus, const OvmsPoller::poll_pid_t* plist);
void PollSetPidList( const OvmsPoller::poll_pid_t* plist)
{
PollSetPidList(m_poll.bus, plist);
}
void PollSetState(uint8_t state);
void PollSetThrottling(uint8_t sequence_max);
void PollSetResponseSeparationTime(uint8_t septime);
Expand Down Expand Up @@ -645,8 +664,6 @@ class OvmsVehicle : public InternalRamAllocated

private:
void PollerTxCallback(const CAN_frame_t* frame, bool success);
protected:
virtual void IncomingPollTxCallback(canbus* bus, uint32_t txid, uint16_t type, uint16_t pid, bool success);


// BMS helpers
Expand Down

0 comments on commit 0e15bdc

Please sign in to comment.