Procedure Call
Abstraction
Within this Cruise Control implementation,
a transformation from stream input to data that can be used in the Procedure
Call architectural style is necessary. A component called "Bridge"
acts as the main program, scanning the input streams, and updating the
global data in the shared data component called Data. Bridge also
acts as the driver for the Cruise Control system. It periodically makes
a Procedure Call to CalculateThrottleSetting to calculate new throttle
settings. Bridge is a component of type General in UniCon because it mixes
architectural styles. It exports both StreamIn and StreamOut players (i.e.,
it behaves like a Filter) as well as RoutineCall, RoutineDef, and GlobalDataUse
players (i.e., it behaves like a Module or Computation component). Bridge
periodically outputs the new throttle setting from the Cruise Control filter.
This design differs from the GM Procedure Call system as described in [CKS95] in that it uses a shared data component to implement the Get_Current_Speed and Get_Brake_State components. GlobalDataDef players exposed by the Data component are used by the CalculateThrottleSetting and CalculateDesiredSpeed components. The system retains the main program/subroutine structure but adds the interaction with globally defined data.
CalculateThrottleSetting and CalculateDesiredSpeed are components of type Computation because they do not maintain state. They provide a result based on function inputs and global data. Both CalculateThrottleSetting and CalculateDesiredSpeed read and update data via a DataAccess connector in the Data component of type SharedData.
Implementation
Component Bridge is the main driver for this
Cruise Control implementation. Bridge’s main loop reads data from the input
streams and then makes a local procedure call to the function CalculateThrottleSetting.
The value returned by CalculateThrottleSetting is compared with the previously
written value and if different is written to the output stream. This comparison
reduces output volume by writing only when values change. This eliminated
data production/consumption timing concerns between the Cruise Control
component and the User Interface component. CalculateThrottleSetting uses
Global Data CurrentSpeed and the return value from the function CalculateDesiredSpeed
to calculate a throttle setting. If the return value from CalculateDesiredSpeed
is greater than zero and is also greater than the CurrentSpeed, the following
formula is used to calculate a new throttle setting:
ThrottleSetting =
(int) (((double)(DesiredSpeed - PulsesPerSecondData) / (double)DesiredSpeed)
* 10.0);