public class CanBus extends AtomicCommunicationAspect
CommunicationAspect
that simulates a CAN bus network
When its sendToken(Receiver, Receiver, Token)
method is called,
the delivery of the specified token to the specified receiver is delayed according to the CAN protocol.
The CAN bus is a serial communication protocol that supports real-time systems with high reliability.
Its main features are: priority-based bus access and non destructive content-based arbitration.
If two or more nodes attempt to transmit a message on the idle bus, the access conflicts are resolved
by performing a bitwise arbitration (non destructive) according to a priority (called here CanPriority).
Our CommunicationAspect
simulates such content-based arbitration.
A node attempting to transmit a message when the bus is busy must try again when the bus will be free (in fact, there is a
queue with messages that did not win the bus during arbitration or arrived when the bus is busy).
In order to perform such an arbitration, it is needed to set a parameter called CanPriority to each receiving switch port. CanPriority is a positive integer. The higher is CanPriority the lower is the priority. (note that in the reality the arbitration is done bit to bit. The higher is the identifier the higher is the priority) It is just needed to set this parameter, using the Parameter dialogs offered by the Decorator mechanism, to the port(s) we want to connect to the bus. The CanPriority parameter is already added and is visible on Parameter dialogs when the CanBus QM is deployed in a model (enhancing visibility).
Messages sent on the Bus are stored and delivered on due time. Since the CAN protocol cover the second layer of the OSI model, messages sent on the bus are encapsulated in frames according to the CAN protocol. We consider that messages sent by actors correspond to exactly one frame. Also, two formats of frames are provided by the CAN standard: the base frame and the extended frame. We can choose the standard according to which the simulation will be performed.
Of course, the bit rate of the bus is also a parameter that can be modified. Typical bit rates for the CAN bus range from 125 Kbits/second to 1 Mbits/second.
Future work: implementing an application layer of the OSI model based on CAN, taking errors into account by delaying the deliveries of messages, finest management of time by dividing the time continuum in periods of 1/bitRate, bit stuffing...
For more information please refer to: CAN bus simulator using a communication aspect.Yellow (glasnier) |
Yellow (glasnier) |
Modifier and Type | Class and Description |
---|---|
static class |
CanBus.CanBusAttributes
The attributes configured per port which is mediated by a
CanBus.
|
Entity.ContainedObjectsIterator
Modifier and Type | Field and Description |
---|---|
protected java.util.HashMap<Port,java.lang.Integer> |
_ioPortToCanPriority
Tokens sent to ports mediated by this communication aspect
are rerouted to the switch ports with the IDs specified in this
map.
|
Parameter |
bitRate
The bit rate of the bus.
|
Parameter |
canFormatOfFrame
The format of frame.
|
Parameter |
canFramePolicy
The selected policy for the frame queue behavior.
|
_parameters, _tokenCount
_typesValid
_actorFiringListeners, _initializables, _notifyingActorFiring, _stopRequested
_changeListeners, _changeLock, _changeRequests, _debugging, _debugListeners, _deferChangeRequests, _elementName, _isPersistent, _verbose, _workspace, ATTRIBUTES, CLASSNAME, COMPLETE, CONTENTS, DEEP, FULLNAME, LINKS
decoratorHighlightColorName
COMPLETED, NOT_READY, STOP_ITERATING
Constructor and Description |
---|
CanBus(CompositeEntity container,
java.lang.String name)
Construct a CanBus with a name and a container.
|
Modifier and Type | Method and Description |
---|---|
protected int |
_getCanBusPriority(Receiver receiver)
Return the priority of the CanBus port where this receiver is
connected to.
|
protected void |
_scheduleRefire()
Schedule a refiring of the actor.
|
void |
attributeChanged(Attribute attribute)
If the attribute is bitRate, then ensure that the value
is non-negative.
|
java.lang.Object |
clone(Workspace workspace)
Clone this actor into the specified workspace.
|
DecoratorAttributes |
createDecoratorAttributes(NamedObj target)
Return the decorated attributes for the target NamedObj.
|
IntermediateReceiver |
createIntermediateReceiver(Receiver receiver)
Create an intermediate receiver that wraps a given receiver.
|
void |
fire()
Fire the actor.
|
Receiver |
getReceiver(Receiver receiver,
IOPort port)
Create a receiver to mediate a communication via the specified receiver.
|
void |
initialize()
Initialize the actor.
|
int |
nextCanPriority()
Method that computes the identifier ('CanPriority') of the message that has
the highest priority.
|
Token |
nextToken()
Return the next token to be sent according to the CAN protocol.
|
int |
nextTokenSize()
Method that compute the size of the next token that need to be sent according to the CAN protocol
This method uses the serialization API to compute the size of the token that need to be sent
Actually, this method is never called in the current version of the code
If you want to use a variable size for objects sent through the network, you need to uncomment the line
dedicated to this functionality in the
nextTokenSize() method. |
double |
nextTokenTransmissionTime()
Compute the transmission time of the next token through the network
In the current version of this
CommunicationAspect the size of a token (message) is fixed
In order to have a variable token size please uncomment the dedicated line in this method. |
void |
printTokenTree()
Method that print in a human readable way the content of
_tokenTree . |
void |
reset()
Reset the communication aspect.
|
void |
sendToken(Receiver source,
Receiver receiver,
Token token)
Initiate a send of the specified token to the specified
receiver.
|
void |
setCanBusPriority(Port port,
int canPriority)
Set the canbus priority attached to this actor port.
|
void |
setContainer(CompositeEntity container)
Override the base class to first set the container, then establish
a connection with any decorated objects it finds in scope in the new
container.
|
_sendToReceiver, decoratedObjects, isGlobalDecorator, registerListener, sendCommunicationEvent
_containedTypeConstraints, _customTypeConstraints, _defaultTypeConstraints, _fireAt, _fireAt, attributeTypeChanged, clone, isBackwardTypeInferenceEnabled, newPort, typeConstraintList, typeConstraints
_actorFiring, _actorFiring, _declareDelayDependency, addActorFiringListener, addInitializable, connectionsChanged, createReceivers, declareDelayDependency, getCausalityInterface, getDirector, getExecutiveDirector, getManager, inputPortList, isFireFunctional, isStrict, iterate, newReceiver, outputPortList, postfire, prefire, preinitialize, pruneDependencies, recordFiring, removeActorFiringListener, removeDependency, removeInitializable, stop, stopFire, terminate, wrapup
_adjustDeferrals, _checkContainer, _getContainedObject, _propagateExistence, getContainer, instantiate, isAtomic, isOpaque, moveDown, moveToFirst, moveToIndex, moveToLast, moveUp, propagateExistence, setName
_addPort, _description, _exportMoMLContents, _removePort, _validateSettables, connectedPortList, connectedPorts, containedObjectsIterator, getAttribute, getPort, getPorts, linkedRelationList, linkedRelations, portList, removeAllPorts, setClassDefinition, uniqueName
_setParent, exportMoML, getChildren, getElementName, getParent, getPrototypeList, isClassDefinition, isWithinClassDefinition
_addAttribute, _adjustOverride, _attachText, _cloneFixAttributeFields, _containedDecorators, _copyChangeRequestList, _debug, _debug, _debug, _debug, _debug, _executeChangeRequests, _getIndentPrefix, _isMoMLSuppressed, _markContentsDerived, _notifyHierarchyListenersAfterChange, _notifyHierarchyListenersBeforeChange, _propagateValue, _removeAttribute, _splitName, _stripNumericSuffix, addChangeListener, addDebugListener, addHierarchyListener, attributeDeleted, attributeList, attributeList, decorators, deepContains, depthInHierarchy, description, description, event, executeChangeRequests, exportMoML, exportMoML, exportMoML, exportMoML, exportMoMLPlain, getAttribute, getAttributes, getChangeListeners, getClassName, getDecoratorAttribute, getDecoratorAttributes, getDerivedLevel, getDerivedList, getDisplayName, getFullName, getModelErrorHandler, getName, getName, getSource, handleModelError, isDeferringChangeRequests, isOverridden, isPersistent, lazyContainedObjectsIterator, message, notifyOfNameChange, propagateValue, propagateValues, removeAttribute, removeChangeListener, removeDebugListener, removeHierarchyListener, requestChange, setClassName, setDeferringChangeRequests, setDerivedLevel, setDisplayName, setModelErrorHandler, setPersistent, setSource, sortContainedObjects, toplevel, toString, validateSettables, workspace
equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
description, getContainer, getDisplayName, getFullName, getName, getName, setName
createReceivers, getCausalityInterface, getDirector, getExecutiveDirector, getManager, inputPortList, newReceiver, outputPortList
isFireFunctional, isStrict, iterate, postfire, prefire, stop, stopFire, terminate
addInitializable, preinitialize, removeInitializable, wrapup
getDerivedLevel, getDerivedList, propagateValue
public Parameter bitRate
public Parameter canFormatOfFrame
public Parameter canFramePolicy
protected java.util.HashMap<Port,java.lang.Integer> _ioPortToCanPriority
public CanBus(CompositeEntity container, java.lang.String name) throws IllegalActionException, NameDuplicationException
container
- The container.name
- The name of this actor.IllegalActionException
- If the container is incompatible
with this actor.NameDuplicationException
- If the name coincides with
an actor already in the container.public void attributeChanged(Attribute attribute) throws IllegalActionException
attributeChanged
in class NamedObj
attribute
- The attribute that changed.IllegalActionException
- If the service time is negative.public java.lang.Object clone(Workspace workspace) throws java.lang.CloneNotSupportedException
clone
in class AtomicCommunicationAspect
workspace
- The workspace for the cloned object.java.lang.CloneNotSupportedException
- If cloned ports cannot have
as their container the cloned entity (this should not occur), or
if one of the attributes cannot be cloned.NamedObj.exportMoML(Writer, int, String)
,
NamedObj.setDeferringChangeRequests(boolean)
public DecoratorAttributes createDecoratorAttributes(NamedObj target)
createDecoratorAttributes
in interface Decorator
createDecoratorAttributes
in class AtomicCommunicationAspect
target
- The NamedObj that will be decorated.public void fire() throws IllegalActionException
fire
in interface Executable
fire
in class AtomicActor<TypedIOPort>
IllegalActionException
- If firing is not permitted.public IntermediateReceiver createIntermediateReceiver(Receiver receiver)
createIntermediateReceiver
in interface CommunicationAspect
createIntermediateReceiver
in class AtomicCommunicationAspect
receiver
- The receiver that is being wrapped.public Receiver getReceiver(Receiver receiver, IOPort port) throws IllegalActionException
receiver
- Receiver whose communication is to be mediated.port
- Port of the communication aspect.IllegalActionException
- If the receiver cannot be created.public void initialize() throws IllegalActionException
initialize
in interface Initializable
initialize
in class AtomicCommunicationAspect
IllegalActionException
- If the superclass throws it.public int nextCanPriority()
public Token nextToken()
public int nextTokenSize()
nextTokenSize()
method.public double nextTokenTransmissionTime()
CommunicationAspect
the size of a token (message) is fixed
In order to have a variable token size please uncomment the dedicated line in this method.public void printTokenTree()
_tokenTree
.public void setContainer(CompositeEntity container) throws IllegalActionException, NameDuplicationException
setContainer
in class AtomicCommunicationAspect
container
- The container to attach this attribute to..IllegalActionException
- If this attribute is not of the
expected class for the container, or it has no name,
or the attribute and container are not in the same workspace, or
the proposed container would result in recursive containment.NameDuplicationException
- If the container already has
an attribute with the name of this attribute.ComponentEntity.getContainer()
public void setCanBusPriority(Port port, int canPriority)
port
- The actor port.canPriority
- The priority attached to the port.public void reset()
public void sendToken(Receiver source, Receiver receiver, Token token) throws IllegalActionException
source
- Sender of the token.receiver
- The receiver to send to.token
- The token to send.IllegalActionException
- If the refiring request fails.protected int _getCanBusPriority(Receiver receiver)
receiver
- The actor receiver.protected void _scheduleRefire() throws IllegalActionException
IllegalActionException
- Thrown if the actor cannot be rescheduled.