<!DOCTYPE html>
<html>
  <head>
    <title>Vehicle Information Access API</title>
    <meta http-equiv="Content-Type" content="text/html;charset=utf-8"/>
    <script src='https://www.w3.org/Tools/respec/respec-w3c-common'
            class='remove'></script>
    <script class="remove">
      var respecConfig = {
          specStatus:           "BG-DRAFT",
          shortName:            "vehicle-information-api",
          publishDate:          "",
		  previousPublishDate:  "2014-11-24",
          previousMaturity:     "BG-FINAL",
          edDraftURI:           "",
          // lcEnd:                "",
          crEnd:                "",
          editors:  [
              { name: "Kevron Rees", company: "Intel",
                      companyURL: "http://www.intel.com" },
              { name: "Justin (Jong Seon) Park", company: "LG Electronics",
                      companyURL: "http://www.lg.com"}
         ],
          inlineCSS:    true,
          noIDLIn:      true,
          wg:           "Automotive and Web Platform Business Group",
          wgURI:        "http://www.w3.org/community/autowebplatform/",
          wgPublicList: "public-autowebplatform",
          wgPatentURI:  "",

          localBiblio:  {
              "VIN": {
                  title:    "Vehicle Identification Number"
              ,   href:     "http://en.wikipedia.org/wiki/Vehicle_Identification_Number#World_Manufacturer_Identifier"
              ,   publisher:  "Wikipedia"
              }
          }
      };
    </script>
  </head>

  <body>


<!------------------------------ Abstract ------------------------------------>
<section id="abstract">
  <p>
  The W3C Vehicle Information API defines an Open Web Platform standard for HTML5/JavaScript application developers enabling Web connectivity through in-vehicle infotainment systems and vehicle data access protocols. This API can also be leveraged by HTML5/JavaScript applications running on mobile devices that access the data resources of a connected passenger vehicle.</p>
  <p>
  This vehicle data API specification does not dictate or describe the access protocol or transport method used for the data connection. Data may come from numerous sources including OBD-II, CAN, LIN, etc. Bluetooth, WiFi, or cloud connections are all possible.</p>
  <p>
  The key purpose of this specification is to promote an API enabling application development in a consistent manner across all automotive manufacturers. It is recognized, however, that the mechanisms required for access or control of vehicle Properties may differ between automobile manufacturers, makes and models. Furthermore, different automobile manufacturers may expose different Properties that can be read or set by an application.</p>
  <p>
  As a result of these constraints, this specification shall allow for automobile manufacturer-specific extensions or restrictions. Extensions are only permitted for interfaces that are not already described by this API, and must be implemented to conform within the format and guidelines existing in this specification. If a Property is restricted, the automobile manufacturer would omit the optional feature in their implementation (see the <a>Availability</a> Section).
  </p>
  <p>
  The target platform supported by the specification is exclusively passenger vehicles. Use of this specification for non-passenger applications (transportation, heavy machinery, marine, airline infotainment, military, etc.) is not prohibited, but is not covered in the design or content of the API and therefore may be insufficient.
  </p>
  <p>
  Initially, a typical use case of Vehicle Information might be the implementation of a 'Virtual Mechanic' application that provides vehicle status information such as tire pressure, engine oil level, washer fluid level, battery status, etc. Future use case innovations in transportation, safety, navigation, smart energy grid and consumer infotainment and customization are all possible through this specification.
  </p>
  <p>
  Web developers building interoperable applications based upon this W3C Vehicle API standard, will help empower a common web platform across consumer devices and passenger vehicles consistent with the Web of Things.
  </p>

</section>

<!----------------------- Status of this document ---------------------------->
<section id="sotd">
</section>

<!----------------------------- Introduction --------------------------------->
<section class="informative">
  <h2>Introduction</h2>
  <p>
    The Vehicle Information API provides operations to get access to the vehicle data
    (henceforth "properties") available from vehicle systems and also to change (write) a number of
    properties.  Vehicle data types are available in the <a href="data_spec.html">Vehicle Data specification</a>.
  <p>
    An example of use is provided below:

  <pre class="example highlight">
        var vehicle = navigator.vehicle;

        vehicle.vehicleSpeed.get().then(function(vehicleSpeed) {
          console.log("vehicle speed: " + vehicleSpeed.speed);
        },
        function(error) {
          console.log("There was an error");
        });

        var vehicleSpeedSub = vehicle.vehicleSpeed.subscribe(function(vehicleSpeed) {
          console.log("vehicle speed changed to: " + vehicleSpeed.speed);
          vehicle.vehicleSpeed.unsubscribe(vehicleSpeedSub);
        });

        var zone = new Zone;

        var zones = vehicle.climateControl.zones;

        for(var i in zones)
        {
           if(i.equals(zone.driver))
           {
              var value = {};
              value["acStatus"] = true;
              vehicle.climateControl.set(value, zone.driver).then(function(){
                console.log("successfully set acStatus");
             },
             function(error) {
               console.log("there was an error");
             });
           }
        }
  </pre>
</section>

<!---------------------------- Conformance ----------------------------------->
<section id="conformance">
  <p>This specification defines conformance criteria that apply to a single
  product: the <dfn>user agent</dfn> that implements the interfaces that it
  contains.

  <p>Implementations that use ECMAScript to implement the APIs defined in this
  specification MUST implement them in a manner consistent with the ECMAScript
  Bindings defined in the Web IDL specification [[!WEBIDL]], as this
  specification uses that specification and terminology.
</section>

<!----------------------------- Terminology ---------------------------------->
<section id="terminology">
  <h2>Terminology</h2> <p>The <code><a
  href="http://www.w3.org/TR/2013/WD-dom-20131107/#promises">
  Promise</a></code> provide a convenient way to get access to the result of an operation.</p>
</section>

<!------------------------ Security and privacy ------------------------------>
<section id="security">
      <h2>Security and privacy considerations</h2>

<p>It is expected that security of vehicle APIs described in this document is based on permissions dictated by:
  <li>The JavaScript runtime under which the APIs are used – in some cases</li>
  <li>The underlying operating system – always</li>
  <br/>
  No separate permission or access control model will be defined for vehicle APIs. Depending on a specific platform,
  the JavaScript runtime SDK used may have to provide tools to generate permissions for application descriptors as
  required by the OS. Android is an example under which such a descriptor (Android app manifest) has to be generated
  if the runtime maps its apps to OS-level apps.
</p>

</section>

<!---------------------- Extended interface Navigator ------------------------>
<section>
  <h3><a>Navigator</a> Interface</h3>
    <dl title="partial interface Navigator" class="idl">
      <dt>readonly attribute Vehicle vehicle</dt>
      <dd>The object that exposes the interface to vehicle information services.</dd>
  </dl>
</section>

<!------------------------ Interface Vehicle ------------------------------->
<section>
  <h3><a>Vehicle</a> Interface</h3> <p>The <a>Vehicle</a> interface
  represents the initial entry point for getting access to the vehicle information
  services, i.e. Engine Speed and Tire Pressure. </p>
  <dl title="[NoInterfaceObject] interface Vehicle" class="idl">
  </dl>
</section>

<!------------------------ Interface Zone ------------------------>
<section>
  <h3><a>Zone</a> Interface</h3> <p>The <a>Zone</a>
  interface contains the constants that represent physical zones and logical zones</p>

  <dl title="enum ZonePosition" class="idl">
    <dt>Front = "Front"</dt>
    <dt>Middle = "Middle"</dt>
    <dd>the middle position of a row.
    <dt>Right = "Right"</dt>
    <dt>Left = "Left"</dt>
    <dt>Rear = "Rear"</dt>
    <dt>Center = "Center"</dt>
    <dd>the center row</dd>
  </dl>

  <dl title="[NoInterfaceObject] interface Zone"
  class="idl">

    <dt>attribute DOMString[] value</dt><dd>MUST return array of physical zones</dd>
    <dt>readonly attribute Zone driver</dt><dd>MUST return physical zone for logical driver</dd>

    <dt>boolean equals(Zone zone)</dt><dd>MUST return true if zone.value matches the contents of this.value.
    Ordering of elements within Zone.value does not matter.</dd>

    <dt>boolean contains(Zone zone)</dt><dd>MUST return true if zone.value can be found within this.value</dd>

  </dl>
</section>

<!------------------------ Callback VehicleInterfaceCallback------------------------------>
<section>
  <h3><a>VehicleInterfaceCallback</a> Callback</h3>
  <p>The <a>VehicleInterfaceCallback</a> </p>
  <dl title="callback VehicleInterfaceCallback = void(object value);" class="idl"></dl>
</section>

<!------------------------ Callback AvailableCallback------------------------------>
<section>
  <h3><a>AvailableCallback</a> Callback</h3>
  <p>The <a>AvailableCallback</a> </p>
  <dl title="callback AvailableCallback = void (Availability available)" class="idl"></dl>
</section>

<!------------------------ Interface VehicleInterfaceError ------------------------>

<section>
   <h3><a>VehicleInterfaceError</a> Interface</h3>
   <p>VehicleInterfaceError is used to identify the type of error encountered during an operation</p>

   <dl title="enum VehicleError" class="idl">
     <dt>permission_denied</dt>
     <dd>Indicates that the user does not have permission to perform the operation. More details can be obtained through the <a href="#data-availability">Data Availability</a> API.</dd>
     <dt>invalid_operation</dt>
     <dd>Indicates that the operation is not valid.  This can be because it isn't supported or has invalid arguments</dd>
     <dt>timeout</dt>
     <dd>Operation timed out.  Timeout length depends upon the implementation</dd>
     <dt>invalid_zone</dt>
     <dd>Indicates the zone argument is not valid</dd>
     <dt>unknown</dt>
     <dd>Indicates an error that is not known</dd>
   </dl>

   <dl title="[NoInterfaceObject] interface VehicleInterfaceError"
  class="idl">
     <dt>readonly attribute VehicleError error</dt>
     <dd>MUST return VehicleError</dd>
     <dt>readonly attribute DOMString message</dt>
     <dd>MUST return user-readable error message</dd>
  </dl>
</section>

<!------------------------ Interface VehicleInterface ------------------------>
<section>
  <h3><a>VehicleInterface</a> Interface</h3> <p>The <a>VehicleInterface</a>
  interface represents the base interface to get all vehicle properties.</p>

  <dl title="[NoInterfaceObject] interface VehicleInterface"
  class="idl">
    <dt>Promise get(optional Zone zone)</dt>
    <dd>MUST return the <a href="http://www.w3.org/TR/2013/WD-dom-20131107/#promises">Promise</a>.  The "resolve" callback in the promise is used to pass the vehicle data type that corresponds to the specific VehicleInterface instance.
    For example, "vehicle.vehicleSpeed" corresponds to the "VehicleSpeed" data type.  <a>VehicleInterfaceError</a> is passed to the 'reject' callback in the promise.</dd>
    <dt>readonly attribute Zone[] zones</dt>
    <dd>MUST return all zones supported for this type.</dd>
  </dl>

  <pre class="example highlight">
  vehicle.vehicleSpeed.get().then(resolve);

  function resolve(data)
  {
    //data is of type VehicleSpeed
    console.log("Speed: " + data.speed);
    console.log("Time Stamp: " + data.timestamp);
  }
  </pre>
</section>

<!------------------------ Interface VehicleConfigurationInterface ------------------------>
<section>
  <h3><a>VehicleConfigurationInterface</a> Interface</h3> <p>The <a>VehicleConfigurationInterface</a>
  interface is to be used to provide access to static vehicle information that never changes: external dimensions, identification, transmission type etc... </p>

  <dl title="[NoInterfaceObject] interface VehicleConfigurationInterface : VehicleInterface"
  class="idl">
  </dl>
</section>
<!------------------------ Interface VehicleSignalInterface ------------------------>
<section>
  <h3><a>VehicleSignalInterface</a> Interface</h3> <p>The <a>VehicleSignalInterface</a>
  interface represents vehicle signals that, as a rule, and unlike vehicle configurations, can change values, either programmatically
  (necessitating support for set method) or due to external events and occurrences, as reflected by subscription management.</p>

  <dl title="[NoInterfaceObject] interface VehicleSignalInterface : VehicleInterface"
  class="idl">
    <dt>Promise set(object value, optional Zone zone)</dt>
    <dd>MUST return <a href="http://www.w3.org/TR/2013/WD-dom-20131107/#promises">Promise</a>.  The "resolve" callback indicates the set was successful.  No data is passed to resolve.  If there was an error,
    "reject" will be called with a <a>VehicleInterfaceError</a> object</dd>
    <dt>unsigned short subscribe(VehicleInterfaceCallback callback, optional Zone zone)</dt>
    <dd>MUST return handle to subscription or 0 if error</dd>
    <dt>void unsubscribe(unsigned short handle)</dt>
    <dd>MUST return void.  unsubscribes to value changes on this interface.</dd>
  </dl>

  <pre class="example highlight">
  var zone = Zone
  vehicle.door.set({"lock" : true}, zone.driver).then(resolve, reject);

  function resolve()
  {
    /// success
  }

  function reject(errorData)
  {
    console.log("Error occurred during set: " + errorData.message + " code: " + errorData.error);
  }
  </pre>

</section>
<!------------------------ Availability ------------------------>
<section>
  <h2>Data Availability</h2>
  <p>The availability API allows for developers to determine what attributes are available or not and if not, why.  It also allows for notifications when the availability
   changes.</p>

  <dl title="enum Availability"
  class="idl">
    <dt>available</dt>
    <dd>data is available</dd>
    <dt>not_supported</dt>
    <dd>not supported by this vehicle</dd>
    <dt>not_supported_yet</dt>
    <dd>not supported at this time, but may become supported later.</dd>
    <dt>not_supported_security_policy</dt>
    <dd>not supported because of security policy</dd>
    <dt>not_supported_business_policy</dt>
    <dd>not supported because of business policy</dd>
    <dt>not_supported_other</dt>
    <dd>not supported for other reasons</dd>
  </dl>

   <dl title="partial interface VehicleInterface" class="idl">
     <dt>Availability availableForRetrieval(DOMString attributeName)</dt>
     <dd>MUST return whether a not this attribute is available for get() or not</dd>
     <dt>readonly attribute boolean supported</dt>
     <dd>MUST return true if this attribute is supported and available</dd>
     <dt>short availabilityChangedListener( AvailableCallback callback )</dt>
     <dd>MUST return handle for listener.</dd>
     <dt>void removeAvailabilityChangedListener( short handle )</dt>
   </dl>

   <pre class="example highlight">
   if( ( var a = vehicle.vehicleSpeed.availableForRetrieval("speed") ) === "available" )
   {
     // we can use it.
   }
   else
   {
     // tell us why:
     console.log(a);
   }
   </pre>

   <dl title="partial interface VehicleSignalInterface" class="idl">
     <dt>Availability availableForSubscription(DOMString attributeName)</dt>
     <dd>MUST return whether a not this attribute is available for subscribe() or not</dd>
     <dt>Availability availableForSetting(DOMString attributeName)</dt>
     <dd>MUST return whether a not this attribute is available for set() or not</dd>
   </dl>

   <pre class="example highlight">
   var canHasVehicleSpeed = vehicle.vehicleSpeed.availableForSubscription("speed") === "available";

   vehicle.vehicleSpeed.availabilityChangedListener( function (available) {
     canHasVehicleSpeed = available === "available";
     checkVehicleSpeed();
   });

   function checkVehicleSpeed()
   {
     if(canHasVehicleSpeed)
     {
       vehicle.vehicleSpeed.get().then(callback);
     }
   }
  </pre>

</section>
<!------------------------ History ------------------------>
<section>
<h2>History</h2>
   <p> The History API provides a way for applications to access logged data from the vehicle.  What data is available and how much is up to the implementation.  This section is OPTIONAL.</p>
   <dl title="interface HistoryItem" class="idl">
     <dt>readonly attribute any value</dt>
     <dd>MUST return value.  This is ANY Vehicle Data Type.</dd>
     <dt>readonly attribute DOMTimeStamp timestamp</dt>
     <dd>MUST return time in which 'value' was read by the system.</dd>
   </dl>
   <dl title="partial interface VehicleInterface" class="idl">
     <dt>readonly attribute History? history</dt>
     <dd>MUST return History interface if the platform supports the History API</dd>
   </dl>
   <dl title="interface History" class="idl">
     <dt>Promise get(Date begin, Date end, optional Zone zone)</dt>
     <dd>MUST return Promise.  The "resolve" callback in the promise is used to pass an array of <a>HistoryItem</a>s.</dd>
     <dt>readonly attribute boolean isLogged</dt>
     <dd>MUST return true if this attribute is logged</dd>
     <dt>readonly attribute Date? from</dt>
     <dd>MUST return Date in which logging started from.  Returns null if <a>isLogged</a> is false.</dd>
     <dt>readonly attribute Date? to</dt>
     <dd>MUST return Date in which logging of this attribute ends. Returns null if <a>isLogged</a> is false.</dd>
   </dl>

   <pre class="example highlight">
   /// check if there is data being logged for vehicleSpeed:
   if(vehicle.vehicleSpeed.history.isLogged)
   {
     /// get all vehicleSpeed since it was first logged:
	   vehicle.vehicleSpeed.history.get(vehicle.vehicleSpeed.history.from, vehicle.vehicleSpeed.history.to).then( function ( data ) {
       console.log(data.length);
     });
   }
   </pre>

</section>

<section class="use-cases">
  <h2>Use-Cases</h2>

    <section>
        <h3>Normative</h3>
        The primary purpose of this specification is to provide web developers the ability to access and set vehicle
        information through a simple common set of operations including get, set, subscribe, and unsubscribe.  Thus
        normative use cases pertain to this access and do not cover higher application of business level use cases.
        <section>
            <h4>Get </h4>
            Get a single value once from the vehicle.
        </section>
        <section>
            <h4>Set </h4>
            Set a single value once in the vehicle.
        </section>
        <section>
            <h4>Subscribe </h4>
            Subscribe to single value until unsubscribed.
        </section>
        <section>
            <h4>Set </h4>
            Unsubscribe to single value.
        </section>
    </section>
</section>
  </body>
</html>