Rest API

OLAF includes an internal REST API using Flask. The REST API is used to give insight into what the OLAF app is doing during testing and system integration without using the CAN bus.

The REST API provides the /od/<index> and /od/<index>/<subindex> endpoints that will call the internal SDO uploads / downloads, then all other endpoints should be used to render Flask templates that can use those two endpoints.

OLAF also include a base template for all other Flask templates to use. The base templates includes readValue() and writeValue() functions for reading and writing values to the OD using the index and subindex endpoints, the scetToDate() function for convert SCET values to the native JavaScript Date object, as well as a very basic standarized layout.

Note

OLAF will automatically add the core blueprint which includes the /od/<index> and /od/<index>/<subindex> endpoints as well as the all the core templates endpoints.

Example template that displays a value from the OD

<!-- templates/example.html --->

{% extends 'base.html' %}

{% block content %}
<a>Data: <span id='data'></span></a>
<script>
  /** Update the data value */
  async function updateData() {
   const obj = await readValue('0x6000', '0x01');
   document.getElementById('data').textContent = obj.value;
  }

  // update data initially and every 30s after that
  updateData();
  const interval = setInterval(function() {
    updateData();
  }, 30000);
</script>
{% endblock %}
# main.py

from olaf import rest_api, olaf_run
from olaf import olaf_setup, olaf_run, app, rest_api, render_olaf_template

@rest_api.app.route('/example')
def example_template():
    return render_olaf_template('example.html', name='Example')

def main():
    path = os.path.dirname(os.path.abspath(__file__))
    args = olaf_setup(f'{path}/app.dcf')  # path to eds or dcf file

    rest_api.add_template(f'{path}/templates/example.html')  # path to Flask template

    olaf_run()


if __name__ == '__main__':
    main()
class olaf.RestAPI[source]

An optional Flask app for reading and writing values into the OD.

Use the global olaf.rest_api object.

setup(address: str, port: int)[source]

Setup the REST API thread

start()[source]

Start the REST API thread

stop()[source]

Stop the REST API thread

add_template(template_path: str)[source]

Add a Flask template to common templates dir. All templates must be in the same directory.

Parameters:

template_path (str) – Path to the template file to add.

olaf.render_olaf_template(template: str, name: str)[source]

Render a standard OLAF template.

Parameters:
  • template (str) – Template file name.

  • name (str) – Nice name for the template.