Arduino C++ Library for VLCB
Loading...
Searching...
No Matches
CanService.h
Go to the documentation of this file.
1// Copyright (C) Sven Rosvall (sven@rosvall.ie)
2// This file is part of VLCB-Arduino project on https://github.com/SvenRosvall/VLCB-Arduino
3// Licensed under the Creative Commons Attribution-NonCommercial-ShareAlike 4.0 International License.
4// The full licence can be found at: http://creativecommons.org/licenses/by-nc-sa/4.0
5
6#pragma once
7
8#include "Service.h"
9#include "CanTransport.h"
10#include <vlcbdefs.hpp>
11
12namespace VLCB
13{
14
15struct VlcbMessage;
16
28class CanService : public Service
29{
30
31public:
34 CanService(CanTransport * tpt) : canTransport(tpt) {}
35
37 virtual VlcbServiceTypes getServiceID() const override { return SERVICE_ID_CAN; }
38 virtual byte getServiceVersionID() const override { return 2; }
39 virtual Data getServiceData();
40
41 virtual void process() override;
42 virtual void processAction(const Action &action) override;
43
44protected:
45 CanTransport * canTransport;
47
48private:
49 void handleCanServiceMessage(const VlcbMessage *msg);
50 void handleEnumeration(unsigned int nn);
51 void handleSetCANID(const VlcbMessage *msg, unsigned int nn);
52
53 bool sendMessage(const VlcbMessage *msg);
54 bool sendRtrFrame();
55 bool sendEmptyFrame(bool rtr = false);
56 bool sendCanFrame(CANFrame *msg) { return canTransport->sendCanFrame(msg); }
57 void startCANenumeration(bool fromENUM = false);
58
59 void checkIncomingCanFrame();
60 void checkCANenumTimout();
61 byte findFreeCanId();
62
63 bool enumeration_required = false;
64 bool bCANenum = false;
65 bool startedFromEnumMessage = false;
66 unsigned long CANenumTime;
67 byte enum_responses[16]; // 128 bits for storing CAN ID enumeration results
68};
69
70}
CanService(CanTransport *tpt)
Definition CanService.h:34
Interface base class for CAN transport implementations.
Definition CanTransport.h:35
Interface base class for all VLCB services.
Definition Service.h:25
Definition VLCB.h:50
void process()
VlcbServiceTypes
Definition vlcbdefs.hpp:487
@ SERVICE_ID_CAN
Definition vlcbdefs.hpp:494