### Build Unet.js Package Source: https://github.com/org-arl/unetsockets/blob/master/js/examples/esm/readme.md Install dependencies and build the unet.js package. This is a prerequisite for running the example. ```sh # inside js directory npm install npm run build ``` -------------------------------- ### Install unetpy from Source Source: https://github.com/org-arl/unetsockets/blob/master/python/docs/installation.md Clone the repository and install unetpy in editable mode for development. ```bash git clone https://github.com/org-arl/unetsockets.git cd unetsockets/python pip install -e . ``` -------------------------------- ### Install Unet.js Source: https://github.com/org-arl/unetsockets/blob/master/js/README.md Install the unetjs package using pnpm. ```sh $ pnpm install unetjs ... ``` -------------------------------- ### UnetSocket Constructor Example Source: https://github.com/org-arl/unetsockets/blob/master/python/docs/api/unetsocket.md Example of creating a UnetSocket instance and retrieving its local address. Remember to close the socket after use. ```python sock = UnetSocket("localhost", 1100) sock.getLocalAddress() sock.close() ``` -------------------------------- ### Verify unetpy Installation Source: https://github.com/org-arl/unetsockets/blob/master/python/docs/installation.md Run this Python code to confirm that the unetpy library has been installed correctly and can be imported. ```python import unetpy print("unetpy imported successfully") ``` -------------------------------- ### Install unetpy from PyPI Source: https://github.com/org-arl/unetsockets/blob/master/python/docs/installation.md Use this command to install the latest stable version of unetpy from the Python Package Index. ```bash pip install unetpy ``` -------------------------------- ### Install unetpy with Development Dependencies Source: https://github.com/org-arl/unetsockets/blob/master/python/docs/installation.md Install unetpy in editable mode along with development dependencies like pytest. ```bash pip install -e ".[dev]" ``` -------------------------------- ### Run Unet Simulator on Windows Source: https://github.com/org-arl/unetsockets/blob/master/c/README.md Starts the Unet simulator with a two-node network configuration on Windows. ```bash $ bin\unet.bat samples\2-node-network.groovy ``` -------------------------------- ### Run Unet Simulator on Linux/macOS Source: https://github.com/org-arl/unetsockets/blob/master/c/README.md Starts the Unet simulator with a two-node network configuration on Linux or macOS. ```bash $ bin/unet samples/2-node-network.groovy ``` -------------------------------- ### Connect to UnetStack Node Source: https://github.com/org-arl/unetsockets/blob/master/python/docs/installation.md Example of connecting to a running UnetStack node, typically a local simulator. Ensure UnetStack is running before executing. ```python from unetpy import UnetSocket # Connect to a local simulator sock = UnetSocket("localhost", 1100) print(f"Connected to node at address: {sock.getLocalAddress()}") sock.close() ``` -------------------------------- ### Example of coordinate conversion Source: https://github.com/org-arl/unetsockets/blob/master/python/docs/api/utilities.md Demonstrates converting between local and GPS coordinates using a specified origin. ```python >>> from unetpy import to_gps, to_local >>> origin = (1.34286, 103.84109) # lat, lon >>> lat, lon = to_gps(origin, x=100, y=100) >>> x, y = to_local(origin, lat, lon) ``` -------------------------------- ### Get Physical Layer Agent Source: https://github.com/org-arl/unetsockets/blob/master/python/docs/api/constants.md Retrieves the agent for the PHYSICAL service to interact with the physical layer. Accessing MTU is shown as an example. ```python phy = sock.agentForService(Services.PHYSICAL) print(phy.MTU) ``` -------------------------------- ### UnetSocket Communication Example Source: https://github.com/org-arl/unetsockets/blob/master/python/README.md Demonstrates basic UnetSocket usage: binding, connecting, sending data, setting a timeout, receiving a notification, and accessing the underlying Gateway. ```python from unetpy import Protocol, Services, DatagramNtf, UnetSocket with UnetSocket("localhost", 1101) as sock: sock.bind(Protocol.USER) sock.connect(31, Protocol.USER) sock.send([0x01, 0x02, 0x03]) sock.setTimeout(2000) ntf = sock.receive() if isinstance(ntf, DatagramNtf): print(f"Got datagram from {ntf.from_}: {ntf.data}") # Drop down to fjåge when you need shell access or raw agents gw = sock.getGateway() shell = gw.agentForService(Services.SHELL) print(shell.language) ``` -------------------------------- ### getGateway Source: https://github.com/org-arl/unetsockets/blob/master/js/docs/readme.md Gets a Gateway to provide low-level access to UnetStack. ```APIDOC ## getGateway ### Description Gets a Gateway to provide low-level access to UnetStack. ### Returns **Gateway** underlying fjage Gateway supporting this socket ``` -------------------------------- ### Bind Protocol and Get Service Agent Source: https://github.com/org-arl/unetsockets/blob/master/python/docs/api/constants.md Demonstrates binding to a protocol and retrieving an agent for a specific service. Use Protocol.USER for user applications. ```python sock.bind(Protocol.USER) phy = sock.agentForService(Services.PHYSICAL) ``` -------------------------------- ### Node A Chat Client Setup and Message Handling Source: https://github.com/org-arl/unetsockets/blob/master/js/examples/esm/nodeA.html Initializes the UnetSocket, connects to Node B, and sets up event listeners for sending messages and interval-based message reception. This code is intended to run in a browser environment. ```javascript import { UnetSocket, Services, AgentID, Gateway, Protocol, UnetMessages } from './unet.js'; const NAME = 'A'; const PORT = 8081; const REMOTE = 'B' var form = document.getElementById('form'); var input = document.getElementById('input'); var messages = document.getElementById('messages'); const usock= await new UnetSocket('localhost', PORT); (async () => { let raddr = await usock.host(REMOTE); usock.connect(raddr, Protocol.USER); usock.bind(Protocol.USER); usock.setTimeout(1000); })(); form.addEventListener('submit', function(e) { e.preventDefault(); if (input.value) { usock.send(string2Bin(input.value)); input.value = ''; } }); setInterval(async () => { if (!usock.isConnected()) return; let msg = await usock.receive(); if (!msg || !msg.data) return; let str = bin2String(msg.data); if (str) display(str); },1000) function display(str){ var item = document.createElement('li'); item.textContent = str; messages.appendChild(item); window.scrollTo(0, document.body.scrollHeight); } function string2Bin(str) { var result = []; for (var i = 0; i < str.length; i++) { result.push(str.charCodeAt(i)); } return result; } function bin2String(array) { return String.fromCharCode.apply(String, array); } ``` -------------------------------- ### Get UnetStack Gateway in MATLAB Source: https://github.com/org-arl/unetsockets/blob/master/matlab/readme.md Retrieve the UnetStack gateway object to access its methods. ```matlab modem = sock.getGateway() ``` -------------------------------- ### Two-Way Communication Example Source: https://github.com/org-arl/unetsockets/blob/master/python/docs/quickstart.md Demonstrates two-way communication between two nodes using separate threads for sending and receiving. Includes binding, sending, and receiving datagrams. ```python from unetpy import UnetSocket, Protocol, DatagramNtf import threading def receiver(): with UnetSocket("localhost", 1102) as sock: sock.bind(Protocol.USER) sock.setTimeout(5000) ntf = sock.receive() if isinstance(ntf, DatagramNtf): print(f"Node B received: {ntf.data}") def sender(): with UnetSocket("localhost", 1101) as sock: sock.send([1, 2, 3], to=31, protocol=Protocol.USER) print("Node A sent data") # Start receiver in background recv_thread = threading.Thread(target=receiver) recv_thread.start() # Send data sender() # Wait for receiver recv_thread.join() ``` -------------------------------- ### getTimeout Source: https://github.com/org-arl/unetsockets/blob/master/js/docs/readme.md Gets the timeout for datagram reception in milliseconds. ```APIDOC ## getTimeout ### Description Gets the timeout for datagram reception. ### Returns **[number][84]** timeout in milliseconds ``` -------------------------------- ### Getting the Route Source: https://github.com/org-arl/unetsockets/blob/master/python/docs/api/unetsocket.md Retrieves the route for outgoing datagrams. Returns None if not set. ```python sock.getRoute() ``` -------------------------------- ### agentsForService Source: https://github.com/org-arl/unetsockets/blob/master/js/docs/readme.md Gets an array of AgentIDs providing a specified service for low-level access to UnetStack. ```APIDOC ## agentsForService ### Description Gets an array of AgentIDs providing a specified service for low-level access to UnetStack. ### Parameters #### Query Parameters - **svc** (string) - Required - the named service of interest ### Returns **Promise>** a promise which returns an array of [AgentIDs] that provides the service when resolved ``` -------------------------------- ### Instantiate UnetSocket Source: https://github.com/org-arl/unetsockets/blob/master/js/docs/readme.md Creates a new UnetSocket instance. This constructor returns a Promise, so use `await` or `.then()` to get the UnetSocket object. It connects over WebSockets in a browser or TCP in Node.js. ```javascript let socket = await new UnetSocket('localhost', 8081, '/ws/'); ``` -------------------------------- ### agentForService Source: https://github.com/org-arl/unetsockets/blob/master/js/docs/readme.md Gets an AgentID providing a specified service for low-level access to UnetStack. ```APIDOC ## agentForService ### Description Gets an AgentID providing a specified service for low-level access to UnetStack. ### Parameters #### Query Parameters - **svc** (string) - Required - the named service of interest ### Returns **Promise** a promise which returns an [AgentID] that provides the service when resolved ``` -------------------------------- ### agent Source: https://github.com/org-arl/unetsockets/blob/master/js/docs/readme.md Gets a named AgentID for low-level access to UnetStack. ```APIDOC ## agent ### Description Gets a named AgentID for low-level access to UnetStack. ### Parameters #### Query Parameters - **name** (string) - Required - name of agent ### Returns **AgentID** AgentID for the given name ``` -------------------------------- ### Receive Unsolicited Notifications Source: https://github.com/org-arl/unetsockets/blob/master/matlab/readme.md Subscribe to agent topics to receive unsolicited notifications. This example shows how to capture a baseband signal notification. ```matlab >> ntf = modem.receive() ntf = RxBasebandSignalNtf:INFORM rxTime:42836833 rssi:‐79.5 adc:1 fc:12000 fs:12000 (12000 samples) ``` ```matlab plot(ntf.getSignal()) ``` -------------------------------- ### Get Agent by Name Source: https://github.com/org-arl/unetsockets/blob/master/python/docs/api/unetsocket.md Retrieves an agent by its name. Useful for interacting with specific nodes or services within the UnetStack network. ```python node = sock.agent("node") print(f"Address: {node.address}, Name: {node.nodeName}") ``` -------------------------------- ### Getting the Local Node Address Source: https://github.com/org-arl/unetsockets/blob/master/python/docs/api/unetsocket.md Retrieves the local node address. Returns -1 on error. ```python sock.getLocalAddress() 232 ``` -------------------------------- ### Getting the MIME Type Source: https://github.com/org-arl/unetsockets/blob/master/python/docs/api/unetsocket.md Retrieves the MIME type for outgoing datagrams. Returns None if not set. ```python sock.getMimeType() ``` -------------------------------- ### getTTL Source: https://github.com/org-arl/unetsockets/blob/master/js/docs/readme.md Gets the default time-to-live for datagrams sent using this socket. Returns the time-to-live in seconds, or NaN if not set. ```APIDOC ## getTTL ### Description Gets the default time-to-live for datagrams sent using this socket. ### Returns **[number][84]** time-to-live in seconds, or NaN if not set ``` -------------------------------- ### Build Samples on Linux/macOS Source: https://github.com/org-arl/unetsockets/blob/master/c/README.md Compiles the object files for the sample applications on Linux or macOS. ```bash make samples ``` -------------------------------- ### Unbind Socket to Listen to All Protocols Source: https://github.com/org-arl/unetsockets/blob/master/python/docs/api/unetsocket.md Removes the socket's binding, allowing it to listen on all unreserved protocols. This example shows binding and then unbinding. ```python >>> sock.bind(Protocol.USER) >>> sock.unbind() >>> sock.isBound() False ``` -------------------------------- ### Getting the Local Protocol Source: https://github.com/org-arl/unetsockets/blob/master/python/docs/api/unetsocket.md Retrieves the protocol number the socket is bound to. Returns -1 if the socket is not bound. ```python sock.getLocalProtocol() ``` -------------------------------- ### getServiceProvider Source: https://github.com/org-arl/unetsockets/blob/master/js/docs/readme.md Gets the currently configured service provider override. Returns the override agent ID or null if auto-selection is active. ```APIDOC ## getServiceProvider ### Description Gets the currently configured service provider override. ### Returns **([AgentID] | null)** the override agent id, or null if auto-selection is active ``` -------------------------------- ### Build Samples on Windows Source: https://github.com/org-arl/unetsockets/blob/master/c/README.md Compiles the executable files for the sample applications on Windows. ```powershell $ cl fjage.lib unet.lib samples\txdata.c /link /out:samples\txdata.exe $ cl fjage.lib unet.lib samples\rxdata.c /link /out:samples\rxdata.exe ``` -------------------------------- ### Protocol Constants Source: https://github.com/org-arl/unetsockets/blob/master/python/docs/api/index.md Access protocol number assignments for different communication types. Protocol.DATA is for user data, Protocol.USER starts user protocols, and Protocol.MAX is the upper limit. ```python from unetpy import Protocol Protocol.DATA # User application data (0) Protocol.USER # User protocols start here (32) Protocol.MAX # Maximum protocol number (63) ``` -------------------------------- ### Getting the UnetSocket Gateway Source: https://github.com/org-arl/unetsockets/blob/master/python/docs/api/unetsocket.md Retrieves the underlying fjåge Gateway for low-level access. Returns None if the socket is closed. ```python gw = sock.getGateway() shell = gw.agentForService(Services.SHELL) ``` -------------------------------- ### Getting the Reliability Setting Source: https://github.com/org-arl/unetsockets/blob/master/python/docs/api/unetsocket.md Retrieves the reliability setting for outgoing datagrams. Returns True if reliable, False if unreliable, or None if not set. ```python sock.getReliability() ``` -------------------------------- ### Get Shell Agent Source: https://github.com/org-arl/unetsockets/blob/master/python/docs/api/constants.md Retrieves the agent for the SHELL service, typically used for interacting with the gateway's command-line interface. ```python shell = gw.agentForService(Services.SHELL) ``` -------------------------------- ### getMessageClass() Source: https://github.com/org-arl/unetsockets/blob/master/python/docs/api/unetsocket.md Gets the message class for outgoing datagrams. ```APIDOC ## getMessageClass() ### Description Get the message class for outgoing datagrams. ### Method `getMessageClass()` ### Returns `Optional[str]` - Message class string, or None if not set. ``` -------------------------------- ### getLocalAddress() Source: https://github.com/org-arl/unetsockets/blob/master/python/docs/api/unetsocket.md Gets the local node address of the socket. ```APIDOC ## getLocalAddress() ### Description Get the local node address. ### Method `getLocalAddress()` ### Returns `int` - Local node address, or -1 on error. ### Example ```python >>> sock.getLocalAddress() 232 ``` ``` -------------------------------- ### Using Pre-defined Messages and Services Source: https://github.com/org-arl/unetsockets/blob/master/js/README.md Simplify message creation and service lookup compared to manual instantiation. ```js // Instead of writing this, import {MessageClass, Gateway} from 'unetjs' let gw = new Gateway({...}); const DatagramReq = MessageClass('org.arl.unet.DatagramReq'); let req = new DatagramReq(); ... req.recipient = await gw.agentForService('org.arl.unet.Services.DATAGRAM') let rsp = await gw.send(req); ... // you can write this import {UnetMessages, Gateway} from 'unetjs' let gw = new Gateway({...}); let req = new UnetMessages.DatagramReq(); ... req.recipient = await gw.agentForService(Services.DATAGRAM) let rsp = await gw.send(req); ``` -------------------------------- ### Basic UnetSocket Usage Source: https://github.com/org-arl/unetsockets/blob/master/python/docs/api/unetsocket.md Demonstrates basic usage of UnetSocket with a context manager, including binding to a protocol, sending data, setting a timeout, and receiving a notification. ```python from unetpy import UnetSocket, Protocol with UnetSocket("localhost", 1100) as sock: sock.bind(Protocol.USER) sock.send([1, 2, 3], to=31, protocol=Protocol.USER) sock.setTimeout(5000) ntf = sock.receive() if ntf: print(f"Received: {ntf.data}") ``` -------------------------------- ### getRobustness() Source: https://github.com/org-arl/unetsockets/blob/master/python/docs/api/unetsocket.md Gets the robustness level configured for outgoing datagrams. ```APIDOC ## getRobustness() ### Description Get the robustness level for outgoing datagrams. ### Method `getRobustness()` ### Returns `Robustness` - Robustness level. ``` -------------------------------- ### getPriority() Source: https://github.com/org-arl/unetsockets/blob/master/python/docs/api/unetsocket.md Gets the priority level assigned to outgoing datagrams. ```APIDOC ## getPriority() ### Description Get the priority level for outgoing datagrams. ### Method `getPriority()` ### Returns `Priority` - Priority level. ``` -------------------------------- ### Getting the Service Provider Source: https://github.com/org-arl/unetsockets/blob/master/python/docs/api/unetsocket.md Retrieves the explicitly selected datagram service provider. Returns None if not set, in which case UnetSocket selects one automatically. RemoteMessageReq traffic prefers Services.REMOTE. ```python sock.getServiceProvider() ``` -------------------------------- ### Access Underlying Gateway Agents Source: https://github.com/org-arl/unetsockets/blob/master/python/docs/quickstart.md Retrieves the underlying fjåge Gateway and accesses its agents for services like PHYSICAL or NODE_INFO to get agent details and node information. ```python from unetpy import UnetSocket, Services with UnetSocket("localhost", 1100) as sock: gw = sock.getGateway() # Get agents phy = gw.agentForService(Services.PHYSICAL) print(f"PHY agent: {phy.name}") print(f"MTU: {phy.MTU}") # Get node info node = sock.agent("node") print(f"Node name: {node.nodeName}") print(f"Node address: {node.address}") ``` -------------------------------- ### Getting the Robustness Level Source: https://github.com/org-arl/unetsockets/blob/master/python/docs/api/unetsocket.md Retrieves the robustness level for outgoing datagrams. ```python sock.getRobustness() ``` -------------------------------- ### Connect using Context Manager Source: https://github.com/org-arl/unetsockets/blob/master/python/docs/quickstart.md The recommended way to connect to a UnetStack node using a context manager for automatic cleanup. ```python from unetpy import UnetSocket with UnetSocket("localhost", 1100) as sock: print(f"Local address: {sock.getLocalAddress()}") # Socket is automatically closed here ``` -------------------------------- ### Getting the Priority Level Source: https://github.com/org-arl/unetsockets/blob/master/python/docs/api/unetsocket.md Retrieves the priority level for outgoing datagrams. ```python sock.getPriority() ``` -------------------------------- ### Create API Package for Distribution Source: https://github.com/org-arl/unetsockets/blob/master/c/README.md Generates a distribution package 'c-api.zip' for the Unet C APIs. ```bash make package ``` -------------------------------- ### Run Unet Simulator Source: https://github.com/org-arl/unetsockets/blob/master/js/examples/esm/readme.md Execute the Unet simulator script to set up a Unet with two nodes (A and B). This script is located in the examples/esm directory. ```sh # inside examples/esm directory ./run-example.sh ``` -------------------------------- ### getRemoteProtocol Source: https://github.com/org-arl/unetsockets/blob/master/js/docs/readme.md Gets the default transmission protocol number used to transmit a datagram. ```APIDOC ## getRemoteProtocol ### Description Gets the default transmission protocol number. ### Returns **[number][84]** default protocol number used to transmit a datagram ``` -------------------------------- ### Build Unet Library on Linux/macOS Source: https://github.com/org-arl/unetsockets/blob/master/c/README.md Builds the Unet C APIs library on Linux or macOS using the provided Makefile. Generates a static library file 'libunet.a'. ```bash make ``` -------------------------------- ### getSendMode() Source: https://github.com/org-arl/unetsockets/blob/master/python/docs/api/unetsocket.md Gets the send mode for datagram transmission, indicating blocking or non-blocking behavior. ```APIDOC ## getSendMode() ### Description Get the send mode for datagram transmission. ### Method `getSendMode()` ### Returns `int` - Send mode. -2 = semi-blocking, 0 = non-blocking, -1 = blocking. NON_BLOCKING sends the request without waiting for an AGREE. SEMI_BLOCKING waits for an AGREE, and if reliability is True also waits for a remote delivery/failure notification. BLOCKING waits for an AGREE followed by a completion notification. ``` -------------------------------- ### Import unetjs with CommonJS Source: https://github.com/org-arl/unetsockets/blob/master/js/README.md Use require to import necessary components for CommonJS environments. Initializes a Gateway connection. ```javascript const { Performative, AgentID, Message, Gateway, MessageClass } = require('unetjs'); const shell = new AgentID('shell'); const gw = new Gateway({ hostname: 'localhost', port : '5081', }); ``` -------------------------------- ### Getting the Remote Protocol Source: https://github.com/org-arl/unetsockets/blob/master/python/docs/api/unetsocket.md Retrieves the default protocol number used to transmit datagrams. ```python sock.getRemoteProtocol() ``` -------------------------------- ### Build Unet Library on Windows Source: https://github.com/org-arl/unetsockets/blob/master/c/README.md Builds the Unet C library on Windows using Microsoft Visual C++ compiler and linker. Generates a dynamic link library 'unet.lib'. ```powershell $ cl /LD fjage.lib *.c $ lib unet.obj unet_ext.obj pthreadwindows.obj /out:unet.lib ``` -------------------------------- ### Import UnetSocket Source: https://github.com/org-arl/unetsockets/blob/master/python/docs/api/unetsocket.md Import the UnetSocket class from the unetpy library. ```python from unetpy import UnetSocket ``` -------------------------------- ### Getting the Remote Recipient Source: https://github.com/org-arl/unetsockets/blob/master/python/docs/api/unetsocket.md Retrieves the remote recipient for outgoing datagrams. Returns None if not set. ```python sock.getRemoteRecipient() ``` -------------------------------- ### Getting the Remote Address Source: https://github.com/org-arl/unetsockets/blob/master/python/docs/api/unetsocket.md Retrieves the default destination node address. Returns -1 if not connected. ```python sock.getRemoteAddress() ``` -------------------------------- ### Import unetjs with ECMAScript Modules Source: https://github.com/org-arl/unetsockets/blob/master/js/README.md Use import statements to bring in unetjs components in ECMAScript module environments. Initializes a Gateway connection. ```javascript import { Performative, AgentID, Message, Gateway, MessageClass } from 'unetjs' const shell = new AgentID('shell'); const gw = new Gateway({ hostname: 'localhost', port : '5081', }); ``` -------------------------------- ### Import unetpy utilities Source: https://github.com/org-arl/unetsockets/blob/master/python/docs/api/utilities.md Import the necessary coordinate conversion functions from the unetpy library. ```python from unetpy import to_gps, to_local ``` -------------------------------- ### Getting the Message Class Source: https://github.com/org-arl/unetsockets/blob/master/python/docs/api/unetsocket.md Retrieves the message class for outgoing datagrams. Returns None if not set. ```python sock.getMessageClass() ``` -------------------------------- ### Compile and Run Unet C API Tests on Windows Source: https://github.com/org-arl/unetsockets/blob/master/c/README.md Compiles the test executable and runs the Unet C API tests on Windows. Requires specifying IP addresses and ports for transmitter and receiver modems. ```powershell $ cl fjage.lib unet.lib test\test_unet.c /link /out:test\test_unet.exe $ test/test_unet.exe ``` -------------------------------- ### Getting the Mailbox Source: https://github.com/org-arl/unetsockets/blob/master/python/docs/api/unetsocket.md Retrieves the mailbox name for outgoing remote messages. Returns None if not set. ```python sock.getMailbox() ``` -------------------------------- ### Run Unet C API Tests on Linux/macOS Source: https://github.com/org-arl/unetsockets/blob/master/c/README.md Compiles and runs the Unet C API tests on Linux or macOS. Requires specifying IP addresses and ports for transmitter and receiver modems. ```bash make test $ test/test_unet ``` -------------------------------- ### connect() Source: https://github.com/org-arl/unetsockets/blob/master/python/docs/api/unetsocket.md Sets the default destination address and protocol for sending datagrams. ```APIDOC ## connect() ### Description Set the default destination address and protocol for sending. The defaults can be overridden for specific send() calls. Protocol numbers between Protocol.DATA+1 to Protocol.USER-1 are reserved and cannot be used. ### Parameters - **to** (int) - Required - Default destination node address. - **protocol** (int) - Optional - Default protocol number (default: Protocol.DATA). ### Returns - **bool** - True on success, False if the address or protocol is invalid. ### Example ```python >>> sock.connect(31, Protocol.USER) True >>> sock.send([1, 2, 3]) # Sends to node 31 with USER protocol True ``` ``` -------------------------------- ### Add UnetStack JARs to MATLAB Static Classpath Source: https://github.com/org-arl/unetsockets/blob/master/matlab/readme.md Edit the javaclasspath.txt file to include all necessary UnetStack and dependency JAR files for MATLAB. ```bash /home/myname/matlab-api/jars/commons-lang*.jar /home/myname/matlab-api/jars/fjage-*.jar /home/myname/matlab-api/jars/gson‐*.jar /home/myname/matlab-api/jars/unet-framework-*.jar /home/myname/matlab-api/jars/unet-basic-*.jar /home/myname/matlab-api/jars/unet-yoda-*.jar /home/myname/matlab-api/jars/groovy-*.jar /home/myname/matlab-api/jars/websocket-servlet-*.jar ``` -------------------------------- ### Getting the Time-To-Live (TTL) Source: https://github.com/org-arl/unetsockets/blob/master/python/docs/api/unetsocket.md Retrieves the Time-To-Live (TTL) value for outgoing datagrams. Returns NaN if not set. ```python sock.getTtl() ``` -------------------------------- ### Import unetjs with UMD Source: https://github.com/org-arl/unetsockets/blob/master/js/README.md Include the unet.min.js script and use the global fjage object for UMD environments. Initializes a Gateway connection with a different port and pathname. ```javascript ``` -------------------------------- ### getSendMode Source: https://github.com/org-arl/unetsockets/blob/master/js/docs/readme.md Gets the current send mode. Returns the current send mode (NON_BLOCKING=0, SEMI_BLOCKING=1, BLOCKING=2). ```APIDOC ## getSendMode ### Description Gets the current send mode. ### Returns **number** current send mode (NON_BLOCKING=0, SEMI_BLOCKING=1, BLOCKING=2) ``` -------------------------------- ### Connect to a UnetStack Node Source: https://github.com/org-arl/unetsockets/blob/master/python/docs/quickstart.md Establishes a socket connection to a UnetStack node. Always close the socket when done. ```python from unetpy import UnetSocket # Create a socket connection to a UnetStack node sock = UnetSocket("localhost", 1100) # Get the local node address print(f"Local address: {sock.getLocalAddress()}") # Always close when done sock.close() ``` -------------------------------- ### Record Baseband Signal using UnetStack Source: https://github.com/org-arl/unetsockets/blob/master/matlab/readme.md Record a baseband signal by subscribing to the baseband service agent, creating a RecordBasebandSignalReq, and waiting for a RxBasebandSignalNtf. The recorded signal is then plotted. ```matlab % subscribe to the agent providing the baseband service agent = modem.agentForService(org.arl.unet.Services.BASEBAND); modem.subscribe(agent); % create the message with relevant attributes to be sent to the modem req = org.arl.unet.bb.RecordBasebandSignalReq(); req.setRecipient(agent); % send the message to the modem and wait for the response sp = modem.request(req, 5000); % check if the message was successfully sent if isjava(rsp) && rsp.getPerformative() == org.arl.fjage.Performative.AGREE % receive the notification message containing the signal cls = org.arl.unet.bb.RxBasebandSignalNtf().getClass(); ntf = modem.receive(cls, 5000); end % plot the recorded signal plot(ntf.getSignal()) ``` -------------------------------- ### bind() Source: https://github.com/org-arl/unetsockets/blob/master/python/docs/api/unetsocket.md Binds the UnetSocket to listen for a specific protocol. ```APIDOC ## bind() ### Description Bind the socket to listen for a specific protocol. Protocol numbers between Protocol.DATA+1 to Protocol.USER-1 are reserved and cannot be bound. Unbound sockets listen to all unreserved protocols. ### Parameters - **protocol** (int) - Required - Protocol number to listen for. Use Protocol.DATA (0) or ### Returns - **bool** - True on success, False if the protocol number is reserved. ### Example ```python >>> sock.bind(Protocol.USER) True >>> sock.isBound() True >>> sock.getLocalProtocol() 32 ``` ``` -------------------------------- ### Getting the TTL Source: https://github.com/org-arl/unetsockets/blob/master/python/docs/api/unetsocket.md Retrieves the Time-To-Live (TTL) value for outgoing datagrams. Returns NaN if not set. This is an alias for getTtl(). ```python sock.getTTL() ``` -------------------------------- ### UnetSocket Constructor Source: https://github.com/org-arl/unetsockets/blob/master/js/docs/readme.md Creates a new UnetSocket to connect to a running Unet instance. This constructor returns a Promise which resolves to the UnetSocket object. ```APIDOC ## UnetSocket Constructor Creates a new UnetSocket to connect to a running Unet instance. This constructor returns a Promise instead of the constructed UnetSocket object. Use `await` or `.then()` to get a reference to the UnetSocket object. Based on if this is run in a Browser or Node.js, it will internally connect over WebSockets or TCP respectively. ### Parameters * `hostname` **[string]?** hostname/ip address of the master container to connect to * `port` **[string]?** port number of the master container to connect to * `path` **[string]** path of the master container to connect to (for WebSockets) (optional, default `''`) ### Examples ```javascript let socket = await new UnetSocket('localhost', 8081, '/ws/'); ``` Returns **Promise** Promise which resolves to the UnetSocket object being constructed ``` -------------------------------- ### Connect and Send/Receive with UnetSocket Source: https://github.com/org-arl/unetsockets/blob/master/python/docs/readme.md Connect to a UnetStack node, bind to a user protocol, send data, and receive notifications with a timeout. Ensure UnetStack is running on localhost:1100. ```python from unetpy import UnetSocket, Protocol # Connect to a UnetStack node with UnetSocket("localhost", 1100) as sock: # Bind to user protocol sock.bind(Protocol.USER) # Send data to node 31 sock.send([1, 2, 3], to=31, protocol=Protocol.USER) # Receive with timeout sock.setTimeout(5000) ntf = sock.receive() if ntf: print(f"Received: {ntf.data}") ``` -------------------------------- ### getReliability Source: https://github.com/org-arl/unetsockets/blob/master/js/docs/readme.md Gets the default reliability setting for datagrams. Returns true if reliable, false if unreliable, or null if not set. ```APIDOC ## getReliability ### Description Gets the default reliability setting for datagrams sent using this socket. ### Returns **([boolean][83] | null)** true if reliable, false if unreliable, null if not set ``` -------------------------------- ### getPriority Source: https://github.com/org-arl/unetsockets/blob/master/js/docs/readme.md Gets the default priority for datagrams sent using this socket. Returns the priority value, or null if not set. ```APIDOC ## getPriority ### Description Gets the default priority for datagrams sent using this socket. ### Returns **any** priority value, or null if not set ``` -------------------------------- ### Configure Logging for Debugging Source: https://github.com/org-arl/unetsockets/blob/master/python/docs/quickstart.md Configures Python's logging system to display all logs on standard output. This is useful for troubleshooting. ```python import logging # Show all logs on stdout logging.basicConfig(level=logging.DEBUG) ``` -------------------------------- ### Run Unit Tests Source: https://github.com/org-arl/unetsockets/blob/master/python/README.md Execute the project's unit tests using pytest. ```bash pytest ``` -------------------------------- ### Create RecordBasebandSignalReq Message in MATLAB Source: https://github.com/org-arl/unetsockets/blob/master/matlab/readme.md Instantiate a RecordBasebandSignalReq message and set its recipient to a specific agent. ```matlab msg = org.arl.unet.bb.RecordBasebandSignalReq() msg.setRecipient(bb) ``` -------------------------------- ### getRemoteAddress Source: https://github.com/org-arl/unetsockets/blob/master/js/docs/readme.md Gets the default destination node address for a connected socket. Returns the address if connected, -1 otherwise. ```APIDOC ## getRemoteAddress ### Description Gets the default destination node address for a connected socket. ### Returns **[number][84]** default destination node address if connected, -1 otherwise ``` -------------------------------- ### getLocalProtocol Source: https://github.com/org-arl/unetsockets/blob/master/js/docs/readme.md Gets the protocol number that the socket is bound to. Returns the protocol number if the socket is bound, -1 otherwise. ```APIDOC ## getLocalProtocol ### Description Gets the protocol number that the socket is bound to. ### Returns **[number][84]** protocol number if socket is bound, -1 otherwise ``` -------------------------------- ### Create UnetSocket Connection in MATLAB Source: https://github.com/org-arl/unetsockets/blob/master/matlab/readme.md Establish a UnetSocket connection to a UnetStack modem using its IP address and port. ```matlab sock = org.arl.unet.api.UnetSocket('192.168.0.42', 1100) ``` -------------------------------- ### Connect and Send Datagram Source: https://github.com/org-arl/unetsockets/blob/master/python/docs/api/index.md Establishes a connection to UnetStack, binds to a user protocol, and sends a datagram. Use this for basic datagram communication. ```python from unetpy import UnetSocket with UnetSocket("localhost", 1100) as sock: sock.bind(Protocol.USER) sock.send([1, 2, 3], to=31, protocol=Protocol.USER) ``` -------------------------------- ### UnetSocket Constructor Source: https://github.com/org-arl/unetsockets/blob/master/python/docs/api/unetsocket.md Creates a new UnetSocket instance connected to the specified UnetStack node host and port. ```APIDOC ## UnetSocket Constructor ### Description Create a new UnetSocket connected to the specified host. ### Parameters - **hostname** (str) - Hostname or IP address of the UnetStack node. - **port** (int) - Optional - TCP port number (default: 1100). ### Example ```python >>> sock = UnetSocket("localhost", 1100) >>> sock.getLocalAddress() 232 >>> sock.close() ``` ``` -------------------------------- ### Find Agent for a Specific Service in MATLAB Source: https://github.com/org-arl/unetsockets/blob/master/matlab/readme.md Use the agentForService method to find an agent providing a specific service, such as BASEBAND. ```matlab bb = sock.agentForService(org.arl.unet.Services.BASEBAND) ``` -------------------------------- ### getMailbox Source: https://github.com/org-arl/unetsockets/blob/master/js/docs/readme.md Gets the default mailbox name for datagrams sent using this socket. Returns the mailbox name, or null if not set. ```APIDOC ## getMailbox ### Description Gets the default mailbox name for datagrams sent using this socket. ### Returns **([string][82] | null)** mailbox name, or null if not set ``` -------------------------------- ### Receive Frame using UnetStack Source: https://github.com/org-arl/unetsockets/blob/master/matlab/readme.md Receive a frame by subscribing to the physical service agent and waiting for an RxFrameNtf. This is intended to be run on the receiver modem. ```matlab % subscribe to the agent providing the physical service agent = modem.agentForService(org.arl.unet.Services.PHYSICAL); modem.subscribe(agent); % receive the notification message cls = org.arl.unet.phy.RxFrameNtf().getClass(); ntf = modem.receive(cls, 5000); ``` -------------------------------- ### getRoute Source: https://github.com/org-arl/unetsockets/blob/master/js/docs/readme.md Gets the default route identifier for datagrams sent using this socket. Returns the route identifier, or null if not set. ```APIDOC ## getRoute ### Description Gets the default route identifier for datagrams sent using this socket. ### Returns **any** route identifier, or null if not set ``` -------------------------------- ### Transmit Baseband Signal using UnetStack Source: https://github.com/org-arl/unetsockets/blob/master/matlab/readme.md Transmit a baseband signal by loading signal data, opening a Gateway, subscribing to the baseband service, creating a TxBasebandSignalReq, and sending it to the modem. It then waits for a TxFrameNtf. ```matlab % load the baseband signal % signal.txt contains interleaved real and imaginary values in a single column % with values normalized between +1 and ‐1 x = load('signal.txt'); % open the modem gateway modem = org.arl.fjage.remote.Gateway('192.168.0.42', 1100); % subscribe to the agent providing baseband service bb = modem.agentForService(org.arl.unet.Services.BASEBAND); % create the message with relevant attributes to be sent to the modem msg = org.arl.unet.bb.TxBasebandSignalReq(); msg.setSignal(x); msg.setRecipient(bb); % send the message to modem rsp = modem.request(msg, 1000); % check if the message was successfully sent if isjava(rsp) && rsp.getPerformative() == org.arl.fjage.Performative.AGREE cls = org.arl.unet.phy.TxFrameNtf().getClass(); % receive the notification message ntf = modem.receive(cls, 5000); end ``` -------------------------------- ### getLocalAddress Source: https://github.com/org-arl/unetsockets/blob/master/js/docs/readme.md Gets the local node address of the Unet node connected to. Returns the local node address or -1 on error. ```APIDOC ## getLocalAddress ### Description Gets the local node address of the Unet node connected to. ### Returns **[Promise][81]\** local node address, or -1 on error ``` -------------------------------- ### Send Message and Receive Response in MATLAB Source: https://github.com/org-arl/unetsockets/blob/master/matlab/readme.md Send a message to UnetStack using the request method and wait for a response within a specified timeout. ```matlab modem.request(msg, 1000) ``` -------------------------------- ### Set Robustness Level for Outgoing Datagrams Source: https://github.com/org-arl/unetsockets/blob/master/python/docs/api/unetsocket.md Adjusts the robustness level for outgoing datagrams. This example demonstrates setting a robust level. ```python setRobustness(robustness: 'Union[Robustness, str]') -> 'None' ``` ```python >>> sock.setRobustness(Robustness.ROBUST) ``` -------------------------------- ### Transmit Passband Signal using UnetStack Source: https://github.com/org-arl/unetsockets/blob/master/matlab/readme.md Transmit a passband signal by loading signal data, opening a Gateway, subscribing to the baseband service, creating a TxBasebandSignalReq with carrier frequency set to 0, and sending it to the modem. It then waits for a TxFrameNtf. ```matlab % load the passband signal % signal.txt must contain the real values in single column sampled at 192KHz % with values normalized between +1 and ‐1 x = load('signal.txt'); % open the modem gateway modem = org.arl.fjage.remote.Gateway('192.168.0.42', 1100); % subscribe to the agent providing baseband service bb = modem.agentForService(org.arl.unet.Services.BASEBAND); % create the message with relevant attributes to be sent to the modem msg = org.arl.unet.bb.TxBasebandSignalReq(); msg.setSignal(x); msg.setRecipient(bb); % to transmit the passband signal the carrier frequency attribute is set to 0 msg.setCarrierFrequency(0) % send the message to modem rsp = modem.request(msg, 1000); % check if the message was successfully sent if isjava(rsp) && rsp.getPerformative() == org.arl.fjage.Performative.AGREE cls = org.arl.unet.phy.TxFrameNtf().getClass(); % receive the notification message ntf = modem.receive(cls, 5000); end ``` -------------------------------- ### Clean Build Files on Linux/macOS Source: https://github.com/org-arl/unetsockets/blob/master/c/README.md Removes all generated build files and dependencies on Linux or macOS. ```bash make clean ``` -------------------------------- ### Getting the Timeout for Datagram Reception Source: https://github.com/org-arl/unetsockets/blob/master/python/docs/api/unetsocket.md Retrieves the timeout in milliseconds for datagram reception. 0 indicates non-blocking, and -1 indicates blocking. ```python sock.getTimeout() ``` -------------------------------- ### Import UnetPy Constants Source: https://github.com/org-arl/unetsockets/blob/master/python/docs/api/constants.md Import necessary constants and enumerations from the UnetPy library for use in your application. ```python from unetpy import Protocol, Services, Topics, ReservationStatus, Address ``` -------------------------------- ### Node B Chat Client with unet.js Source: https://github.com/org-arl/unetsockets/blob/master/js/examples/esm/nodeB.html This script sets up Node B to connect to Node A, send chat messages, and display received messages. It uses unet.js for network communication. ```javascript import { UnetSocket, Services, AgentID, Gateway, Protocol, UnetMessages } from './unet.js'; const NAME = 'B'; const PORT = 8082; const REMOTE = 'A'; var form = document.getElementById('form'); var input = document.getElementById('input'); var messages = document.getElementById('messages'); const usock= await new UnetSocket('localhost', PORT); (async () => { let raddr = await usock.host(REMOTE); usock.connect(raddr, Protocol.USER); usock.bind(Protocol.USER); usock.setTimeout(1000); })(); form.addEventListener('submit', function(e) { e.preventDefault(); if (input.value) { usock.send(string2Bin(input.value)); input.value = ''; } }); setInterval(async () => { if (!usock.isConnected()) return; let msg = await usock.receive(); if (!msg || !msg.data) return; let str = bin2String(msg.data); if (str) display(str); },1000) function display(str){ var item = document.createElement('li'); item.textContent = str; messages.appendChild(item); window.scrollTo(0, document.body.scrollHeight); } function string2Bin(str) { var result = []; for (var i = 0; i < str.length; i++) { result.push(str.charCodeAt(i)); } return result; } function bin2String(array) { return String.fromCharCode.apply(String, array); } ``` -------------------------------- ### getRemoteRecipient Source: https://github.com/org-arl/unetsockets/blob/master/js/docs/readme.md Gets the default remote recipient for datagrams sent using this socket. Returns the remote recipient identifier, or null if not set. ```APIDOC ## getRemoteRecipient ### Description Gets the default remote recipient for datagrams sent using this socket. ### Returns **any** remote recipient identifier, or null if not set ``` -------------------------------- ### getMimeType Source: https://github.com/org-arl/unetsockets/blob/master/js/docs/readme.md Gets the default MIME type for datagrams sent using this socket. Returns the MIME type string, or null if not set. ```APIDOC ## getMimeType ### Description Gets the default MIME type for datagrams sent using this socket. ### Returns **([string][82] | null)** MIME type string, or null if not set ``` -------------------------------- ### Import unetpy High-Level API Source: https://github.com/org-arl/unetsockets/blob/master/python/README.md Import the main components of the unetpy high-level API, similar to unet.js. ```python from unetpy import ( Gateway, AgentID, Performative, Message, MessageClass, UnetSocket, Protocol, Services, to_gps, to_local, ) ``` -------------------------------- ### host Source: https://github.com/org-arl/unetsockets/blob/master/js/docs/readme.md Resolve node name to node address. ```APIDOC ## host ### Description Resolve node name to node address. ### Parameters #### Query Parameters - **nodeName** (string) - Required - name of the node to resolve ### Returns **Promise** address of the node, or null if unable to resolve ``` -------------------------------- ### getMessageClass Source: https://github.com/org-arl/unetsockets/blob/master/js/docs/readme.md Gets the default application message class for datagrams sent using this socket. Returns the message class name, or null if not set. ```APIDOC ## getMessageClass ### Description Gets the default application message class for datagrams sent using this socket. ### Returns **([string][82] | null)** message class name, or null if not set ``` -------------------------------- ### Message Classes Source: https://github.com/org-arl/unetsockets/blob/master/python/docs/api/index.md All UnetStack message classes can be imported directly. ```APIDOC ## Message Classes ### Description All UnetStack message classes can be imported directly. ### Common Messages - `DatagramReq` - Request to send a datagram - `DatagramNtf` - Notification of received datagram - `RxFrameNtf` - Physical layer frame received - `TxFrameReq` - Request to transmit a frame ### Usage ```python from unetpy import DatagramReq, DatagramNtf req = DatagramReq() req.to = 31 req.data = [1, 2, 3] ``` ``` -------------------------------- ### close() Source: https://github.com/org-arl/unetsockets/blob/master/python/docs/api/unetsocket.md Closes the UnetSocket and releases all associated resources. ```APIDOC ## close() ### Description Close the socket and release all resources. After calling close(), the socket cannot be used for communication. All subsequent operations will fail or return None/-1. ### Example ```python >>> sock = UnetSocket("localhost", 1100) >>> sock.isClosed() False >>> sock.close() >>> sock.isClosed() True ``` ``` -------------------------------- ### Coordinate Conversion Helpers Source: https://github.com/org-arl/unetsockets/blob/master/python/README.md Utilize to_gps and to_local functions for converting between local coordinates and GPS latitude/longitude. These replicate the math from unet.js. ```python from unetpy import to_gps, to_local origin = (1.25, 103.88) # latitude, longitude lat, lon = to_gps(origin, x=120.0, y=-45.0) print(lat, lon) print(to_local(origin, lat, lon)) ``` -------------------------------- ### Clean Build Files on Windows Source: https://github.com/org-arl/unetsockets/blob/master/c/README.md Removes all generated build files, libraries, and executables on Windows. ```powershell del *.obj *.dll unet.lib test\*.obj test\*.exe samples\*.obj samples\*.exe 2>nul ``` -------------------------------- ### Receive Datagrams with UnetSocket Source: https://github.com/org-arl/unetsockets/blob/master/python/docs/api/unetsocket.md Use receive() to get datagrams. This method blocks until a datagram is available or the socket timeout is reached. It can be used with or without binding the socket to a protocol. ```python >>> sock.bind(Protocol.USER) >>> sock.setTimeout(5000) >>> ntf = sock.receive() >>> if ntf: ... print(f"From: {ntf.from_}, Data: {ntf.data}") ``` -------------------------------- ### Enable Library-Specific Logging Source: https://github.com/org-arl/unetsockets/blob/master/python/docs/quickstart.md Enables logging specifically for the 'fjagepy' library to the standard output. Use this to filter logs and reduce noise. ```python # Or, enable only logs from this library logging.getLogger("fjagepy").setLevel(logging.DEBUG) ``` -------------------------------- ### Transmit Frame using UnetStack Source: https://github.com/org-arl/unetsockets/blob/master/matlab/readme.md Transmit a frame by subscribing to the physical service agent, creating a TxFrameReq message, and sending it to the modem. It then waits for a TxFrameNtf. ```matlab % subscribe to the agent providing the physical service agent = modem.agentForService(org.arl.unet.Services.PHYSICAL); modem.subscribe(agent); % create the message with relevant attributes to be sent to the modem req = org.arl.unet.phy.TxFrameReq(); req.setRecipient(agent); % send the message to the modem and wait for the response sp = modem.request(req, 5000); % check if the message was successfully sent if isjava(rsp) && rsp.getPerformative() == org.arl.fjage.Performative.AGREE cls = org.arl.unet.phy.TxFrameNtf().getClass(); % receive the notification message ntf = modem.receive(cls, 5000); end ``` -------------------------------- ### agentsForService() Source: https://github.com/org-arl/unetsockets/blob/master/python/docs/api/unetsocket.md Retrieves all agents providing a specific service. ```APIDOC ## agentsForService() ### Description Get all agents providing the specified service. ### Parameters - **svc** - Required - Service identifier (from Services class). ### Returns - **Optional[Iterable[AgentID]]** - List of AgentID instances, or None if socket is closed. ### Example ```python >>> phy_agents = sock.agentsForService(Services.PHYSICAL) ``` ``` -------------------------------- ### agentForService() Source: https://github.com/org-arl/unetsockets/blob/master/python/docs/api/unetsocket.md Retrieves an agent that provides a specific service. ```APIDOC ## agentForService() ### Description Get an agent providing the specified service. ### Parameters - **svc** - Required - Service identifier (from Services class). ### Returns - **AgentID** - AgentID if found, None otherwise. ### Example ```python >>> phy = sock.agentForService(Services.PHYSICAL) >>> print(phy.MTU) ``` ``` -------------------------------- ### Address Constants Source: https://github.com/org-arl/unetsockets/blob/master/python/docs/api/index.md Address constants. ```APIDOC ## Address ### Description Address constants. ### Constants - **Address.BROADCAST** (int): Broadcast address (0) ### Usage ```python from unetpy import Address Address.BROADCAST ``` ``` -------------------------------- ### Getting the Send Mode Source: https://github.com/org-arl/unetsockets/blob/master/python/docs/api/unetsocket.md Retrieves the send mode for datagram transmission. -2 = semi-blocking, 0 = non-blocking, -1 = blocking. Different modes affect waiting behavior for acknowledgments and notifications. ```python sock.getSendMode() ``` -------------------------------- ### Subscribe to Parameter Change Topic Source: https://github.com/org-arl/unetsockets/blob/master/python/docs/api/constants.md Subscribes to the PARAMCHANGE topic to receive notifications when system parameters are modified. ```python gw.subscribe(gw.topic(Topics.PARAMCHANGE)) ``` -------------------------------- ### Close UnetSocket Source: https://github.com/org-arl/unetsockets/blob/master/python/docs/api/unetsocket.md Demonstrates closing the UnetSocket to release resources. After closing, the socket is no longer usable. ```python sock = UnetSocket("localhost", 1100) print(sock.isClosed()) sock.close() print(sock.isClosed()) ``` -------------------------------- ### Import UnetStack Message Classes Source: https://github.com/org-arl/unetsockets/blob/master/python/docs/api/messages.md Import necessary message classes like DatagramReq, DatagramNtf, and RxFrameNtf from the unetpy library. These classes are used for UnetStack communication. ```python from unetpy import DatagramReq, DatagramNtf, RxFrameNtf ```