API Examples¶
This comprehensive guide is designed to help you understand and utilize the various functionalities provided by this library in your projects.
ISU API¶
This API is utilized by the isutool to perform firmware binary inspection for Frontier Smart. Please refer to the isutool documentation for detailed instructions on how to leverage this API’s capabilities and effectively interact with Frontier Smart firmware binaries.
Parsing ISU Files¶
1from fsapi.isu import ISU
2
3# It is only possible to read file inputstreams
4isu = ISU.parse_file("firmware.isu.bin")
5# Or just use the '<<' operator
6isu = ISU << "firmware.isu.bin"
Getting Data of an Archive File¶
In order to retrieve the (un)compressed file bytes of an archive file, you need to perform various steps.
1from fsapi.isu import ISU, IndexEntryType
2
3isu = ISU << "firmware.isu.bin"
4archive = isu.archive
5# We first need an entry that contains file data. You can either
6# iterater over all elements or you know, what entry you would
7# like to export
8entry = ... or archive.index.entries[0]
9# The entry must be of type 'File'
10assert entry.type == IndexEntryType.File
11# The ISU instance will extract the bytes for us
12data = isu.get_archive_file(entry.content, archive)
Creating Data Sections¶
1from fsapi.isu import ISU
2
3isu = ISU << "firmware.isu.bin"
4# Assume we have found a data section at a specific offset
5offset = ...
6section = isu.get_data_section(offset)
Generating an update URL¶
With a simple function, you can generate the URL where a firmware binary is located. Here’s an example of how you can achieve this:
1from fsapi.isu import ISU, url_get_update
2
3# We can use the version and customisation from a firmware binary
4isu = ISU << "firmware.isu.bin"
5name = f"{isu.customisation}_V{isu.version}"
6# The url should store the firmware binary
7url = url_get_update(name)
FS API¶
The FSAPI (Frontier Smart API) is utilized for communication and control of Frontier Smart’s internet radio devices. The following examples demonstrate how you can interact with these devices:
1from fsapi.net import nodes, FSDevice, wrap
2
3# First, create the radio object
4device = FSDevice("127.0.0.1")
5
6# Create a new session id (only one at a time)
7device.new_session()
8
9# In order to simplify the usage of the FSDevice class
10api = wrap(device)
11friendly_name = api.friendly_name
12# or manually
13response = device.get(nodes / "netRemote.sys.info.friendlyName")
14if response.success:
15 #_ Again, type(content) = nodes.BaseSysInfoFriendlyName
16 friendly_name = response.node.value
17
18 # Apply a new name via wrapper
19 api.friendly_name = "FooBar"
20 # or manually
21 device.put(nodes / "netRemote.sys.info.friendlyName", value="FooBar")
22
23# get all elements of a list
24valid_modes = api.ls_valid_modes()
25# get a certain amount of elements beginning at index 3
26valid_mpdes = api.ls_valid_modes(_pos=3, max_items=10)
Fetching all notifies¶
A simple FSDevice
object provides the possibility to fetch all notify values. Be
aware that too many notifies would result in a timout caused by the device.
1from fsapi.net import nodes, FSDevice, wrap
2
3# First, create the radio object
4device = FSDevice("127.0.0.1")
5
6# Create a new session id (only one at a time)
7device.new_session()
8notifies: list[Node] = device.get_notifies()