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:
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:
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}
virtual byte getServiceVersionID() const override
Return the version of the service specification implemented by this service.
Definition CanService.h:38
virtual void process() override
This method that be called regularly from the VLCB core to let the service perform regular tasks.
Definition CanService.cpp:22
CanService(CanTransport *tpt)
Definition CanService.h:34
virtual void processAction(const Action &action) override
Called when there is an action available.
Definition CanService.cpp:36
CanTransport * canTransport
Definition CanService.h:45
virtual VlcbServiceTypes getServiceID() const override
Return a unique ID for this service.
Definition CanService.h:37
virtual Data getServiceData()
Return Data bytes specific for the implementing service. The meaning of each data byte is defined in ...
Definition CanService.cpp:16
Interface base class for CAN transport implementations.
Definition CanTransport.h:35
Interface base class for all VLCB services.
Definition Service.h:25
Definition AbstractEventTeachingService.cpp:13
An action to be performed.
Definition Controller.h:51
Represents a CAN frame sent on the CAN bus.
Definition CanTransport.h:21
CAN/Controller message type.
Definition Controller.h:30
VlcbServiceTypes
Definition vlcbdefs.hpp:487
@ SERVICE_ID_CAN
Definition vlcbdefs.hpp:494