Class CanBus
- java.lang.Object
-
- All Implemented Interfaces:
java.lang.Cloneable
,Actor
,CommunicationAspect
,Executable
,FiringsRecordable
,Initializable
,TypedActor
,Changeable
,Debuggable
,DebugListener
,Decorator
,Derivable
,Instantiable
,ModelErrorHandler
,MoMLExportable
,Moveable
,Nameable
@Deprecated public class CanBus extends AtomicCommunicationAspect
Deprecated.This does not appear to work!This actor is anCommunicationAspect
that simulates a CAN bus network When itssendToken(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.- Since:
- Ptolemy II 10.0
- Version:
- $Id$
- Author:
- D. Marciano, G. Lasnier, P. Derler
- Pt.AcceptedRating:
- Yellow (glasnier)
- Pt.ProposedRating:
- Yellow (glasnier)
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description static class
CanBus.CanBusAttributes
Deprecated.The attributes configured per port which is mediated by a CanBus.-
Nested classes/interfaces inherited from class ptolemy.kernel.Entity
Entity.ContainedObjectsIterator
-
-
Field Summary
Fields Modifier and Type Field Description protected java.util.HashMap<Port,java.lang.Integer>
_ioPortToCanPriority
Deprecated.Tokens sent to ports mediated by this communication aspect are rerouted to the switch ports with the IDs specified in this map.Parameter
bitRate
Deprecated.The bit rate of the bus.Parameter
canFormatOfFrame
Deprecated.The format of frame.Parameter
canFramePolicy
Deprecated.The selected policy for the frame queue behavior.-
Fields inherited from class ptolemy.actor.lib.aspect.AtomicCommunicationAspect
_parameters, _tokenCount
-
Fields inherited from class ptolemy.actor.TypedAtomicActor
_typesValid
-
Fields inherited from class ptolemy.actor.AtomicActor
_actorFiringListeners, _initializables, _notifyingActorFiring, _stopRequested
-
Fields inherited from class ptolemy.kernel.util.NamedObj
_changeListeners, _changeLock, _changeRequests, _debugging, _debugListeners, _deferChangeRequests, _elementName, _isPersistent, _verbose, _workspace, ATTRIBUTES, CLASSNAME, COMPLETE, CONTENTS, DEEP, FULLNAME, LINKS
-
Fields inherited from interface ptolemy.actor.CommunicationAspect
decoratorHighlightColorName
-
Fields inherited from interface ptolemy.actor.Executable
COMPLETED, NOT_READY, STOP_ITERATING
-
-
Constructor Summary
Constructors Constructor Description CanBus(CompositeEntity container, java.lang.String name)
Deprecated.Construct a CanBus with a name and a container.
-
Method Summary
All Methods Instance Methods Concrete Methods Deprecated Methods Modifier and Type Method Description protected int
_getCanBusPriority(Receiver receiver)
Deprecated.Return the priority of the CanBus port where this receiver is connected to.protected void
_scheduleRefire()
Deprecated.Schedule a refiring of the actor.void
attributeChanged(Attribute attribute)
Deprecated.If the attribute is bitRate, then ensure that the value is non-negative.java.lang.Object
clone(Workspace workspace)
Deprecated.Clone this actor into the specified workspace.DecoratorAttributes
createDecoratorAttributes(NamedObj target)
Deprecated.Return the decorated attributes for the target NamedObj.IntermediateReceiver
createIntermediateReceiver(Receiver receiver)
Deprecated.Create an intermediate receiver that wraps a given receiver.void
fire()
Deprecated.Fire the actor.Receiver
getReceiver(Receiver receiver, IOPort port)
Deprecated.Create a receiver to mediate a communication via the specified receiver.void
initialize()
Deprecated.Initialize the actor.int
nextCanPriority()
Deprecated.Method that computes the identifier ('CanPriority') of the message that has the highest priority.Token
nextToken()
Deprecated.Return the next token to be sent according to the CAN protocol.int
nextTokenSize()
Deprecated.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 thenextTokenSize()
method.double
nextTokenTransmissionTime()
Deprecated.Compute the transmission time of the next token through the network In the current version of thisCommunicationAspect
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()
Deprecated.Method that print in a human readable way the content of_tokenTree
.void
reset()
Deprecated.Reset the communication aspect.void
sendToken(Receiver source, Receiver receiver, Token token)
Deprecated.Initiate a send of the specified token to the specified receiver.void
setCanBusPriority(Port port, int canPriority)
Deprecated.Set the canbus priority attached to this actor port.void
setContainer(CompositeEntity container)
Deprecated.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.-
Methods inherited from class ptolemy.actor.lib.aspect.AtomicCommunicationAspect
_sendToReceiver, decoratedObjects, isGlobalDecorator, registerListener, sendCommunicationEvent
-
Methods inherited from class ptolemy.actor.TypedAtomicActor
_containedTypeConstraints, _customTypeConstraints, _defaultTypeConstraints, _fireAt, _fireAt, attributeTypeChanged, clone, isBackwardTypeInferenceEnabled, newPort, typeConstraintList, typeConstraints
-
Methods inherited from class ptolemy.actor.AtomicActor
_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
-
Methods inherited from class ptolemy.kernel.ComponentEntity
_adjustDeferrals, _checkContainer, _getContainedObject, _propagateExistence, getContainer, instantiate, isAtomic, isOpaque, moveDown, moveToFirst, moveToIndex, moveToLast, moveUp, propagateExistence, setName
-
Methods inherited from class ptolemy.kernel.Entity
_addPort, _description, _exportMoMLContents, _removePort, _validateSettables, connectedPortList, connectedPorts, containedObjectsIterator, getAttribute, getPort, getPorts, linkedRelationList, linkedRelations, portList, removeAllPorts, setClassDefinition, uniqueName
-
Methods inherited from class ptolemy.kernel.InstantiableNamedObj
_setParent, exportMoML, getChildren, getElementName, getParent, getPrototypeList, isClassDefinition, isWithinClassDefinition
-
Methods inherited from class ptolemy.kernel.util.NamedObj
_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
-
Methods inherited from class java.lang.Object
equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
-
Methods inherited from interface ptolemy.actor.Actor
createReceivers, getCausalityInterface, getDirector, getExecutiveDirector, getManager, inputPortList, newReceiver, outputPortList
-
Methods inherited from interface ptolemy.kernel.util.Derivable
getDerivedLevel, getDerivedList, propagateValue
-
Methods inherited from interface ptolemy.actor.Executable
isFireFunctional, isStrict, iterate, postfire, prefire, stop, stopFire, terminate
-
Methods inherited from interface ptolemy.actor.Initializable
addInitializable, preinitialize, removeInitializable, wrapup
-
Methods inherited from interface ptolemy.kernel.util.Nameable
description, getContainer, getDisplayName, getFullName, getName, getName, setName
-
-
-
-
Field Detail
-
bitRate
public Parameter bitRate
Deprecated.The bit rate of the bus. This is a double with default value to 125 (Kbit/second). It is required to be positive.
-
canFormatOfFrame
public Parameter canFormatOfFrame
Deprecated.The format of frame. This is a string with default value to "Standard frame". It is required to be either "Standard frame" or "Extended frame".
-
canFramePolicy
public Parameter canFramePolicy
Deprecated.The selected policy for the frame queue behavior. This is a string with the default value "Send All Frames".
-
_ioPortToCanPriority
protected java.util.HashMap<Port,java.lang.Integer> _ioPortToCanPriority
Deprecated.Tokens sent to ports mediated by this communication aspect are rerouted to the switch ports with the IDs specified in this map.
-
-
Constructor Detail
-
CanBus
public CanBus(CompositeEntity container, java.lang.String name) throws IllegalActionException, NameDuplicationException
Deprecated.Construct a CanBus with a name and a container. The container argument must not be null, or a NullPointerException will be thrown. This actor will use the workspace of the container for synchronization and version counts. If the name argument is null, then the name is set to the empty string. Increment the version of the workspace.- Parameters:
container
- The container.name
- The name of this actor.- Throws:
IllegalActionException
- If the container is incompatible with this actor.NameDuplicationException
- If the name coincides with an actor already in the container.
-
-
Method Detail
-
attributeChanged
public void attributeChanged(Attribute attribute) throws IllegalActionException
Deprecated.If the attribute is bitRate, then ensure that the value is non-negative.- Overrides:
attributeChanged
in classNamedObj
- Parameters:
attribute
- The attribute that changed.- Throws:
IllegalActionException
- If the service time is negative.
-
clone
public java.lang.Object clone(Workspace workspace) throws java.lang.CloneNotSupportedException
Deprecated.Clone this actor into the specified workspace. The new actor is not added to the directory of that workspace (you must do this yourself if you want it there). The result is a new actor with the same ports as the original, but no connections and no container. A container must be set before much can be done with this actor.- Overrides:
clone
in classAtomicCommunicationAspect
- Parameters:
workspace
- The workspace for the cloned object.- Returns:
- A new CanBus.
- Throws:
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.- See Also:
NamedObj.exportMoML(Writer, int, String)
,NamedObj.setDeferringChangeRequests(boolean)
-
createDecoratorAttributes
public DecoratorAttributes createDecoratorAttributes(NamedObj target)
Deprecated.Return the decorated attributes for the target NamedObj. If the specified target is not an Actor, return null.- Specified by:
createDecoratorAttributes
in interfaceDecorator
- Overrides:
createDecoratorAttributes
in classAtomicCommunicationAspect
- Parameters:
target
- The NamedObj that will be decorated.- Returns:
- The decorated attributes for the target NamedObj, or null if the specified target is not an Actor.
-
fire
public void fire() throws IllegalActionException
Deprecated.Fire the actor. Typically, the fire() method performs the computation associated with an actor. Here, it delivers (if required) the intended token to the intended receiver(s).- Specified by:
fire
in interfaceExecutable
- Overrides:
fire
in classAtomicActor<TypedIOPort>
- Throws:
IllegalActionException
- If firing is not permitted.
-
createIntermediateReceiver
public IntermediateReceiver createIntermediateReceiver(Receiver receiver)
Deprecated.Create an intermediate receiver that wraps a given receiver.- Specified by:
createIntermediateReceiver
in interfaceCommunicationAspect
- Overrides:
createIntermediateReceiver
in classAtomicCommunicationAspect
- Parameters:
receiver
- The receiver that is being wrapped.- Returns:
- A new intermediate receiver.
-
getReceiver
public Receiver getReceiver(Receiver receiver, IOPort port) throws IllegalActionException
Deprecated.Create a receiver to mediate a communication via the specified receiver. This receiver is linked to a specific port of the communication aspect.- Parameters:
receiver
- Receiver whose communication is to be mediated.port
- Port of the communication aspect.- Returns:
- A new receiver.
- Throws:
IllegalActionException
- If the receiver cannot be created.
-
initialize
public void initialize() throws IllegalActionException
Deprecated.Initialize the actor.- Specified by:
initialize
in interfaceInitializable
- Overrides:
initialize
in classAtomicCommunicationAspect
- Throws:
IllegalActionException
- If the superclass throws it.
-
nextCanPriority
public int nextCanPriority()
Deprecated.Method that computes the identifier ('CanPriority') of the message that has the highest priority.- Returns:
- The identifier ('CanPriority') of the message that has the highest priority.
-
nextToken
public Token nextToken()
Deprecated.Return the next token to be sent according to the CAN protocol.- Returns:
- The next token to be sent according to the CAN protocol.
-
nextTokenSize
public int nextTokenSize()
Deprecated.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 thenextTokenSize()
method.- Returns:
- The size of the next token to be sent.
-
nextTokenTransmissionTime
public double nextTokenTransmissionTime()
Deprecated.Compute the transmission time of the next token through the network In the current version of thisCommunicationAspect
the size of a token (message) is fixed In order to have a variable token size please uncomment the dedicated line in this method.- Returns:
- Transmission time for the next token to be sent through the network.
-
printTokenTree
public void printTokenTree()
Deprecated.Method that print in a human readable way the content of_tokenTree
.
-
setContainer
public void setContainer(CompositeEntity container) throws IllegalActionException, NameDuplicationException
Deprecated.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.- Overrides:
setContainer
in classAtomicCommunicationAspect
- Parameters:
container
- The container to attach this attribute to..- Throws:
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.- See Also:
ComponentEntity.getContainer()
-
setCanBusPriority
public void setCanBusPriority(Port port, int canPriority)
Deprecated.Set the canbus priority attached to this actor port.- Parameters:
port
- The actor port.canPriority
- The priority attached to the port.
-
reset
public void reset()
Deprecated.Reset the communication aspect.
-
sendToken
public void sendToken(Receiver source, Receiver receiver, Token token) throws IllegalActionException
Deprecated.Initiate a send of the specified token to the specified receiver. This method will schedule a refiring of this actor according to the requirements of the CAN protocol.- Parameters:
source
- Sender of the token.receiver
- The receiver to send to.token
- The token to send.- Throws:
IllegalActionException
- If the refiring request fails.
-
_getCanBusPriority
protected int _getCanBusPriority(Receiver receiver)
Deprecated.Return the priority of the CanBus port where this receiver is connected to. The port ID's are set via parameters.- Parameters:
receiver
- The actor receiver.- Returns:
- The port ID.
-
_scheduleRefire
protected void _scheduleRefire() throws IllegalActionException
Deprecated.Schedule a refiring of the actor.- Throws:
IllegalActionException
- Thrown if the actor cannot be rescheduled.
-
-