FGInterface Class: Difference between revisions

From FlightGear wiki
Jump to navigation Jump to search
Line 67: Line 67:


=== Auxiliary Configuration File ===
=== Auxiliary Configuration File ===
The auxiliary configuration files contain all the elements of the cockpit. In the example, two auxiliary configuration files are defined in the general configuration of the interface. They will be analyzed and loaded during the creation of the RADIOPANEL interface.
The auxiliary configuration files contain all the elements of the cockpit. In the example, three auxiliary configuration files are defined in the general configuration of the interface. They will be analyzed and loaded during the creation of the RADIOPANEL interface.


==== Displays Configuration File ====
==== Displays Configuration File ====

Revision as of 14:54, 26 November 2019

Configuration Files

Main Configuration File

Here is the Main Configuration File (/opt/fgint/Config/radiopanel.cfg) that will be use for all examples:

[INT]
intname=RADIOPANEL
deviceconf=/opt/fgint/Config/RadioPanel/devices.cfg

[MODULES]
module01=FGIntHT16K33,HT16K33
module02=FGIntMCP23017,MCP23017
module03=FGIntSegDisplay,SegDisplay
module04=FGIntSwitch,Switch

[AUXCONF]
displays=/opt/fgint/Config/RadioPanel/displays.cfg
switches=/opt/fgint/Config/RadioPanel/switches.cfg
swlights=/opt/fgint/Config/RadioPanel/swlights.cfg

There are 3 sections in the configuration : INT, MODULES and AUXCONF

  • INT : General Inteface configuration section.
  • MODULES : Modules configuration section. Modules that will be loaded into the interface object at creation. Should contain all devices configuration needed
  • AUXCONF : Auxiliary configuration section. Auxiliary configuration files that will be loaded into the interface object at creation. Should contain all cockpit element configuration connected to the inferface.

INT

The INT section contains the name of the interface (intname) and the full path of the devices configuration file (deviceconf).

MODULES

The MODULES section contains the list of modules to be loaded.
The configuration format is:

Modulexx = LibFileName, Module Class name

Library file are in the FGInt directory (/opt/fgint/FGInt).

AUXCONF

The section AUXCONF refers to the set of configuration files to be loaded describing the elements of the cockpit to be created in the interface.
The configuration format is:

configname = /full/path/config/<Project>/file

Auxiliary configuration files are int the Project Config directory (/opt/fgint/Config/RadioPanel).

Devices Configuration File

Devices configuration file : /opt/fgint/Config/RadioPanel/devices.cfg.
For the radio panel we need 2 devices (One for input MCP23017 and one for displays and lights HT16K33)

[CONF]
confname=DEVICES

[LEDPACK1]
devicetype=HT16K33
devicename=LEDPACK1
deviceaddr=0x70
devicedummy=0

[IOPACK1]
devicetype=MCP23017
devicename=IOPACK1
deviceaddr=0x20
devicedummy=0

Auxiliary Configuration File

The auxiliary configuration files contain all the elements of the cockpit. In the example, three auxiliary configuration files are defined in the general configuration of the interface. They will be analyzed and loaded during the creation of the RADIOPANEL interface.

Displays Configuration File

Displays configuration file : /opt/fgint/Config/RadioPanel/displays.cfg
This file describes the configuration of the 7-segment displays of the radio panel.
There are two separate parts in this file.

  1. a general configuration part, in the CONF and PROPERTIES sections.
  2. the other sections each describe a display.
[CONF]
confname=DISPLAYS
library=FGIntSegDisplay
module=SegDisplay
properylist=device,dispname,nbdigit,port,com1,decdigit
createmethod=createDisplays

[PROPERTIES]
prop01=device
prop02=name
prop03=nbdigit
prop04=port
prop05=com1
prop06=decdigit

[ACTVFREQ]
name=ACTVFREQ
device=LEDPACK1
nbdigit=6
com1=1
port=A
decdigit=3

[STBYFREQ]
name=STBYFREQ
device=LEDPACK1
nbdigit=6
com1=1
port=B
decdigit=3

Switches Configuration File

Switches configuration file : /opt/fgint/Config/RadioPanel/switches.cfg This file describes the configuration of switch of the radio panel.
There are two separate parts in this file.

  1. a general configuration part, in the CONF and PROPERTIES sections.
  2. the other sections each describe a switch.
[CONF]
confname=SWITCHES
library=FGIntSwitch
module=Switch
properylist=device,name,port,pin,values,valuestype,invert,node

[PROPERTIES]
prop01=device
prop02=name
prop03=port
prop04=pin
prop05=values
prop06=valuestype
prop07=invert
prop08=node

[POWERSW]
name=powersw
device=IOPACK1
port=B
pin=2
values=0,1
valuestype=int
node=None
invert=0

FGInterface Class

So, before you can act on the various elements of the interface, you have to create it. An interface is created by instantiating the Class FGInterface. Creating an FGInterface object requires two parameters:

FGInterface(config_filename, debug_level)

  • config_file: The main configuration file (String, a file name in the "Config" directory)
  • debug_level: Debug Level Value (Integer)

Example: Creating an interface named RADIOPANEL with a config file named radiopanel.cfg.

Interface Création :

Python 3.4.2 (default, Oct 19 2014, 13:31:11)
[GCC 4.9.1] on linux
Type "help", "copyright", "credits" or "license" for more information.
>>> from FGInterface import FGInterface as FGINT
>>> FGINT1 = FGINT('radiopanel.cfg', 0)
>>>

FGInterface Methods

getName()

Returns the name of the interface, corresponding to the name defined in the configuration.

Python 3.4.2 (default, Oct 19 2014, 13:31:11)
[GCC 4.9.1] on linux
Type "help", "copyright", "credits" or "license" for more information.
>>> from FGInterface import FGInterface as FGINT
>>> FGINT1 = FGINT('radiopanel.cfg', 0)
>>> print(FGINT1.getName())
RADIOPANEL
>>>

getConfigFile()

Returns the configuration file and its absolute path.

Python 3.4.2 (default, Oct 19 2014, 13:31:11)
[GCC 4.9.1] on linux
Type "help", "copyright", "credits" or "license" for more information.
>>> from FGInterface import FGInterface as FGINT
>>> FGINT1 = FGINT('radiopanel.cfg', 0)
>>> print(FGINT1.getConfigFile())
/opt/fgint/Config/radiopanel.cfg
>>>

readConfig()

Reads the interface configuration file and stores it in the interface. This method is called automatically when the interface is created. Since the configuration files are not normally modified during execution, there is normally no reason to invoke it.

Python 3.4.2 (default, Oct 19 2014, 13:31:11)
[GCC 4.9.1] on linux
Type "help", "copyright", "credits" or "license" for more information.
>>> from FGInterface import FGInterface as FGINT
>>> FGINT1 = FGINT('radiopanel.cfg', 0)
>>> print(FGINT1.readConfig())
{'INT': {'deviceconf': '/opt/fgint/Config/devices.cfg', 'intname': 'RADIOPANEL'}, 'MODULES': {'module03': 'FGIntSegDisplay,SegDisplay', 'module04': 'FGIntSwitch,Switch', 'module01': 'FGIntHT16K33,HT16K33', 'module02': 'FGIntMCP23017,MCP23017'}, 'AUXCONF': {'displays': '/opt/fgint/Config/displays.cfg', 'switches': '/opt/fgint/Config/switches.cfg'}}
>>>

getConfig()

Returns the configuration stored in the interface.

Python 3.4.2 (default, Oct 19 2014, 13:31:11)
[GCC 4.9.1] on linux
Type "help", "copyright", "credits" or "license" for more information.
>>> from FGInterface import FGInterface as FGINT
>>> FGINT1 = FGINT('radiopanel.cfg', 0)
>>> print(FGINT1.getConfig())
{'INT': {'deviceconf': '/opt/fgint/Config/devices.cfg', 'intname': 'RADIOPANEL'}, 'MODULES': {'module03': 'FGIntSegDisplay,SegDisplay', 'module04': 'FGIntSwitch,Switch', 'module01': 'FGIntHT16K33,HT16K33', 'module02': 'FGIntMCP23017,MCP23017'}, 'AUXCONF': {'displays': '/opt/fgint/Config/displays.cfg', 'switches': '/opt/fgint/Config/switches.cfg'}}
>>>

getConfigSection(section)

Returns the definitions of a section of the configuration. With the example file, if you want to retrieve the configuration of the interface [ section INT ]:

Python 3.4.2 (default, Oct 19 2014, 13:31:11)
[GCC 4.9.1] on linux
Type "help", "copyright", "credits" or "license" for more information.
>>> from FGInterface import FGInterface as FGINT
>>> FGINT1 = FGINT('radiopanel.cfg', 0)
>>> print(FGINT1.getConfigSection('INT'))
{'deviceconf': '/opt/fgint/Config/devices.cfg', 'intname': 'RADIOPANEL'}
>>>

getConfigOption(section, option)

Returns the value of an option contained in a section. With the sample file, to retrieve the name of the interface in the INT section.

Python 3.4.2 (default, Oct 19 2014, 13:31:11)
[GCC 4.9.1] on linux
Type "help", "copyright", "credits" or "license" for more information.
>>> from FGInterface import FGInterface as FGINT
>>> FGINT1 = FGINT('radiopanel.cfg', 0)
>>> print(FGINT1.getConfigOption('INT', 'intname'))
RADIOPANEL
>>>

getDebugLevel()

Returns the debug level.

Python 3.4.2 (default, Oct 19 2014, 13:31:11)
[GCC 4.9.1] on linux
Type "help", "copyright", "credits" or "license" for more information.
>>> from FGInterface import FGInterface as FGINT
>>> FGINT1 = FGINT('radiopanel.cfg', 0)
>>> print(FGINT1.getDebugLevel())
0
>>>

setDebugLevel(debuglevel)

Set the debug level to debuglevel. Debug Mode :

  • Level 0 : Debug mode off
  • Level 1 : Debug mode on FGInt
  • Level 2 : Debug mode on FG Int Device
  • Level 3 : Debug mode on FG Int Object
  • Level 4 : Debug mode on Bus I2C
  • Level 5 : Debug mode on Object I2C
Python 3.4.2 (default, Oct 19 2014, 13:31:11)
[GCC 4.9.1] on linux
Type "help", "copyright", "credits" or "license" for more information.
>>> from FGInterface import FGInterface as FGINT
>>> FGINT1 = FGINT('radiopanel.cfg', 0)
>>> print(FGINT1.getDebugLevel())
0
>>> FGINT1.setDebugLevel(1)
>>> print(FGINT1.getDebugLevel())
1
>>> FGINT1.setDebugLevel(0)
##################################################
# Set Debug to 0
##################################################

>>> print(FGINT1.getDebugLevel())
0
>>>

listModules()

Returns the list of defined modules in the interface configuration.

Python 3.4.2 (default, Oct 19 2014, 13:31:11)
[GCC 4.9.1] on linux
Type "help", "copyright", "credits" or "license" for more information.
>>> from FGInterface import FGInterface as FGINT
>>> FGINT1 = FGINT('radiopanel.cfg', 0)
>>> FGINT1.listModules()
{'module03': 'FGIntSegDisplay,SegDisplay', 'module04': 'FGIntSwitch,Switch', 'module01': 'FGIntHT16K33,HT16K33', 'module02': 'FGIntMCP23017,MCP23017'}
>>>

listLoadedModules()

Returns the loaded modules in the interface.

Python 3.4.2 (default, Oct 19 2014, 13:31:11)
[GCC 4.9.1] on linux
Type "help", "copyright", "credits" or "license" for more information.
>>> from FGInterface import FGInterface as FGINT
>>> FGINT1 = FGINT('radiopanel.cfg', 0)
>>> FGINT1.listLoadedModules()
{'Switch': <module 'FGIntSwitch' from '/opt/fgint/FGInt/FGIntSwitch.py'>, 'HT16K33': <module 'FGIntHT16K33' from '/opt/fgint/FGInt/FGIntHT16K33.py'>, 'SegDisplay': <module 'FGIntSegDisplay' from '/opt/fgint/FGInt/FGIntSegDisplay.py'>, 'MCP23017': <module 'FGIntMCP23017' from '/opt/fgint/FGInt/FGIntMCP23017.py'>}
>>>

loadModules()

Reads the configuration of the interface modules, the load in the interface, creates the different modules at the interface and stores them in the interface.

Python 3.4.2 (default, Oct 19 2014, 13:31:11)
[GCC 4.9.1] on linux
Type "help", "copyright", "credits" or "license" for more information.
>>> from FGInterface import FGInterface as FGINT
>>> FGINT1 = FGINT('radiopanel.cfg', 0)

getModule(modulename)

Returns a modulename Module object.

Python 3.4.2 (default, Oct 19 2014, 13:31:11)
[GCC 4.9.1] on linux
Type "help", "copyright", "credits" or "license" for more information.
>>> from FGInterface import FGInterface as FGINT
>>> FGINT1 = FGINT('radiopanel.cfg', 0)
>>> MCP23017 = FGINT1.getModule('MCP23017')
>>> print(MCP23017)
<class 'FGIntMCP23017.MCP23017'>
>>>

getDeviceConf(devicename)

Returns the configuration of a devicename device.

Python 3.4.2 (default, Oct 19 2014, 13:31:11)
[GCC 4.9.1] on linux
Type "help", "copyright", "credits" or "license" for more information.
>>> from FGInterface import FGInterface as FGINT
>>> FGINT1 = FGINT('radiopanel.cfg', 0)
>>> FGINT1.getDeviceConf('IOPACK1')
{'devicedummy': '0', 'devicetype': 'MCP23017', 'deviceaddr': '0x20', 'devicename': 'IOPACK1'}
>>>

getDevice(devicename)

Returns the device devicename object.

Python 3.4.2 (default, Oct 19 2014, 13:31:11)
[GCC 4.9.1] on linux
Type "help", "copyright", "credits" or "license" for more information.
>>> from FGInterface import FGInterface as FGINT
>>> FGINT1 = FGINT('radiopanel.cfg', 0)
>>> IOPACK1 = FGINT1.getDevice('IOPACK1')
>>> print(IOPACK1)
<FGIntMCP23017.MCP23017 object at 0x769302d0>
>>>

getDevices()

Returns all devices and their configuration.

Python 3.4.2 (default, Oct 19 2014, 13:31:11)
[GCC 4.9.1] on linux
Type "help", "copyright", "credits" or "license" for more information.
>>> from FGInterface import FGInterface as FGINT
>>> FGINT1 = FGINT('radiopanel.cfg', 0)
>>> print(FGINT1.getDevices())
{'IOPACK1': {'CONF': {'devicedummy': '0', 'devicetype': 'MCP23017', 'deviceaddr': '0x20', 'devicename': 'IOPACK1'}, 'OBJECT': <FGIntMCP23017.MCP23017 object at 0x769302d0>}, 'LEDPACK1': {'CONF': {'devicedummy': '0', 'devicetype': 'HT16K33', 'deviceaddr': '0x70', 'devicename': 'LEDPACK1'}, 'OBJECT': <FGIntHT16K33.HT16K33 object at 0x76930530>}}
>>>

createDevice(devicename)

Created the device devicename, devicename must exist in the configuration files. Creating the IOPACK1 device declared in the device configuration file:

Python 3.4.2 (default, Oct 19 2014, 13:31:11)
[GCC 4.9.1] on linux
Type "help", "copyright", "credits" or "license" for more information.
>>> from FGInterface import FGInterface as FGINT
>>> FGINT1 = FGINT('radiopanel.cfg', 0)
>>> DEVICE = FGINT1.createDevice('IOPACK1')
>>> print(DEVICE)
<FGIntMCP23017.MCP23017 object at 0x769371b0>
>>>

createDevices()

Created all devices declared in the device configuration file. Returns all device objects and their configuration.

Python 3.4.2 (default, Oct 19 2014, 13:31:11)
[GCC 4.9.1] on linux
Type "help", "copyright", "credits" or "license" for more information.
>>> from FGInterface import FGInterface as FGINT
>>> FGINT1 = FGINT('radiopanel.cfg', 0)
>>> ALLDEVICES = FGINT1.createDevices()
>>> print(ALLDEVICES)
{'IOPACK1': {'CONF': {'devicedummy': '0', 'devicetype': 'MCP23017', 'deviceaddr': '0x20', 'devicename': 'IOPACK1'}, 'OBJECT': <FGIntMCP23017.MCP23017 object at 0x76937790>}, 'LEDPACK1': {'CONF': {'devicedummy': '0', 'devicetype': 'HT16K33', 'deviceaddr': '0x70', 'devicename': 'LEDPACK1'}, 'OBJECT': <FGIntHT16K33.HT16K33 object at 0x76930530>}}
>>>

loadAuxConfigs()

Reads and stores auxiliary configurations.

Python 3.4.2 (default, Oct 19 2014, 13:31:11)
[GCC 4.9.1] on linux
Type "help", "copyright", "credits" or "license" for more information.
>>> from FGInterface import FGInterface as FGINT
>>> FGINT1 = FGINT('radiopanel.cfg', 0)

getAuxConfigs()

Returns auxiliary configurations.

Python 3.4.2 (default, Oct 19 2014, 13:31:11)
[GCC 4.9.1] on linux
Type "help", "copyright", "credits" or "license" for more information.
>>> from FGInterface import FGInterface as FGINT
>>> FGINT1 = FGINT('radiopanel.cfg', 0)
>>> print(FGINT1.getAuxConfigs())
{'displays': {'ACTVFREQ': {'device': 'LEDPACK1', 'com1': '1', 'decdigit': '3', 'port': 'A', 'name': 'ACTVFREQ', 'nbdigit': '6'}, 'PROPERTIES': {'prop03': 'nbdigit', 'prop04': 'port', 'prop02': 'name', 'prop01': 'device', 'prop06': 'decdigit', 'prop05': 'com1'}, 'CONF': {'library': 'FGIntSegDisplay', 'module': 'SegDisplay', 'createmethod': 'createDisplays', 'confname': 'DISPLAYS', 'properylist': 'device,dispname,nbdigit,port,com1,decdigit'}, 'STBYFREQ': {'device': 'LEDPACK1', 'com1': '1', 'decdigit': '3', 'port': 'B', 'name': 'STBYFREQ', 'nbdigit': '6'}}, 'switches': {'NAVSW': {'device': 'IOPACK1', 'valuestype': 'int', 'pin': '6', 'port': 'B', 'invert': '0', 'values': '0,1', 'node': 'None', 'name': 'navsw'}, 'PROPERTIES': {'prop08': 'node', 'prop03': 'port', 'prop04': 'pin', 'prop02': 'name', 'prop01': 'device', 'prop06': 'valuestype', 'prop05': 'values', 'prop07': 'invert'}, 'CONF': {'library': 'FGIntSwitch', 'module': 'Switch', 'confname': 'SWITCHES', 'properylist': 'device,name,port,pin,values,valuestype,invert,node'}, 'POWERSW': {'device': 'IOPACK1', 'valuestype': 'int', 'pin': '2', 'port': 'B', 'invert': '0', 'values': '0,1', 'node': 'None', 'name': 'powersw'}}}
>>>

createElementCat(elementcat)

Creates, stores in the interface and returns the objects of the category.
Creating "displays" catégprie :

Python 3.4.2 (default, Oct 19 2014, 13:31:11)
[GCC 4.9.1] on linux
Type "help", "copyright", "credits" or "license" for more information.
>>> from FGInterface import FGInterface as FGINT
>>> FGINT1 = FGINT('radiopanel.cfg', 0)
>>> FGINT1.createElementCat('displays')
{'ACTVFREQ': <FGIntSegDisplay.SegDisplay object at 0x768ff170>, 'STBYFREQ': <FGIntSegDisplay.SegDisplay object at 0x768ff910>}
>>>

createElement(elementcat, element)

Creates, stores in the interface and returns the element element of the category elementcat .
To create the "ACTVFREQ" display from displays category :

Python 3.4.2 (default, Oct 19 2014, 13:31:11)
[GCC 4.9.1] on linux
Type "help", "copyright", "credits" or "license" for more information.
>>> from FGInterface import FGInterface as FGINT
>>> FGINT1 = FGINT('radiopanel.cfg', 0)
>>> FGINT1.createElement('displays', 'ACTVFREQ')
<FGIntSegDisplay.SegDisplay object at 0x768ff4d0>
>>>

createElements()

Creates, stores in the interface all the elements defined in the configuration.

Python 3.4.2 (default, Oct 19 2014, 13:31:11)
[GCC 4.9.1] on linux
Type "help", "copyright", "credits" or "license" for more information.
>>> from FGInterface import FGInterface as FGINT
>>> FGINT1 = FGINT('radiopanel.cfg', 0)
>>> FGINT1.createElements()
>>>

getElementCatConfig(elementcat)

Returns the configuration of all elements of an elementcat category.
Retrieving the configuration of the 'displays' elements :

Python 3.4.2 (default, Oct 19 2014, 13:31:11)
[GCC 4.9.1] on linux
Type "help", "copyright", "credits" or "license" for more information.
>>> from FGInterface import FGInterface as FGINT
>>> FGINT1 = FGINT('radiopanel.cfg', 0)
>>> FGINT1.getElementCatConfig('displays')
{'CONF': {'library': 'FGIntSegDisplay', 'confname': 'DISPLAYS', 'module': 'SegDisplay', 'createmethod': 'createDisplays', 'properylist': 'device,dispname,nbdigit,port,com1,decdigit'}, 'PROPERTIES': {'prop02': 'name', 'prop04': 'port', 'prop06': 'decdigit', 'prop05': 'com1', 'prop01': 'device', 'prop03': 'nbdigit'}, 'ACTVFREQ': {'decdigit': '3', 'com1': '1', 'nbdigit': '6', 'port': 'A', 'device': 'LEDPACK1', 'name': 'ACTVFREQ'}, 'STBYFREQ': {'decdigit': '3', 'com1': '1', 'nbdigit': '6', 'port': 'B', 'device': 'LEDPACK1', 'name': 'STBYFREQ'}}
>>>

getElementConfig(elementcat, elementname)

Returns the configuration of the element element of the elementcat category.
Retrieving the configuration of the ACTVFREQ element in the displays category :

Python 3.4.2 (default, Oct 19 2014, 13:31:11)
[GCC 4.9.1] on linux
Type "help", "copyright", "credits" or "license" for more information.
>>> from FGInterface import FGInterface as FGINT
>>> FGINT1 = FGINT('radiopanel.cfg', 0)
>>> FGINT1.getElementConfig('displays', 'ACTVFREQ')
{'decdigit': '3', 'com1': '1', 'nbdigit': '6', 'port': 'A', 'device': 'LEDPACK1', 'name': 'ACTVFREQ'}
>>>

getElement(elementname)

Returns the element elementname (the object).

Python 3.4.2 (default, Oct 19 2014, 13:31:11)
[GCC 4.9.1] on linux
Type "help", "copyright", "credits" or "license" for more information.
>>> from FGInterface import FGInterface as FGINT
>>> FGINT1 = FGINT('radiopanel.cfg', 0)
>>> FGINT1.getElement('ACTVFREQ')
<FGIntSegDisplay.SegDisplay object at 0x76886e70>
>>>

getElements()

Returns the set of generated elements stored in the interface.

Python 3.4.2 (default, Oct 19 2014, 13:31:11)
[GCC 4.9.1] on linux
Type "help", "copyright", "credits" or "license" for more information.
>>> from FGInterface import FGInterface as FGINT
>>> FGINT1 = FGINT('radiopanel.cfg', 0)
>>> FGINT1.getElements()
{'ACTVFREQ': <FGIntSegDisplay.SegDisplay object at 0x76886e70>, 'POWERSW': <FGIntSwitch.Switch object at 0x768867b0>, 'NAVSW': <FGIntSwitch.Switch object at 0x76886e50>, 'STBYFREQ': <FGIntSegDisplay.SegDisplay object at 0x768ff170>}
>>>