Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 11 additions & 0 deletions examples/tests/ipc/package_name_client-libtock/Makefile
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
# Makefile for user application

# Specify this directory relative to the current application.
TOCK_USERLAND_BASE_DIR = ../../../..

# Which files to compile.
C_SRCS := $(wildcard *.c)

# Include userland master makefile. Contains rules and flags for actually
# building the application.
include $(TOCK_USERLAND_BASE_DIR)/AppMakefile.mk
27 changes: 27 additions & 0 deletions examples/tests/ipc/package_name_client-libtock/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
# Package Name Client - libtock

Discovers an IPC service via TBF Header Package Name using the asynchronous
libtock IPC Registry Package Name driver.

This is intended to be loaded alongside [package_name_server-libtock](../package_name_server-libtock). When
loaded with the Package Name Server the expected behavior is:

```
SERVER: Starting server.
CLIENT: Starting client.
SERVER: IPC Registry Package Name capsule exists.
CLIENT: IPC Registry Package Name capsule exists.
CLIENT: Discovering: "tbf_package_name_service"
CLIENT: Discovery started.
CLIENT: Discovery complete. Service not found.
SERVER: Registering with my package name (see Makefile).
SERVER: Registration started.
SERVER: Registration complete. Succeeded!
CLIENT: Discovering: "tbf_package_name_service"
CLIENT: Discovery started.
CLIENT: Discovery complete. Succeeded! Found IPC ID: 0000000000000001
```

Note that above IPC IDs may not match depending on the order the apps are
loaded and the configuration of your board.

64 changes: 64 additions & 0 deletions examples/tests/ipc/package_name_client-libtock/main.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,64 @@
#include <stdio.h>
#include <stdlib.h>
#include <string.h>

#include <libtock-sync/services/alarm.h>
#include <libtock/ipc/ipc_registry_package_name.h>

// Service name (specified in Makefile of service)
char service_name[] = "tbf_package_name_service";

static void ipc_discovery_complete(returncode_t ret, uint64_t ipc_id) {
if (ret == RETURNCODE_SUCCESS) {
uint32_t lower = (uint32_t)ipc_id;
uint32_t upper = (uint32_t)(ipc_id >> 32);
printf("CLIENT: Discovery complete. Succeeded! Found IPC ID: %08X%08X\n", (unsigned int)upper, (unsigned int)lower);
} else if (ret == RETURNCODE_ENODEVICE) {
printf("CLIENT: Discovery complete. Service not found.\n");
} else {
printf("CLIENT: Discovery complete. Failed with returncode: %d\n", ret);
}
}

int main(void) {
returncode_t ret = RETURNCODE_SUCCESS;
printf("CLIENT: Starting client.\n");

// Check that we can find the driver at all
if (!libtock_ipc_registry_package_name_exists()) {
printf("CLIENT: IPC Registry Package Name capsule does not exist on this board.\n");
return 1;
} else {
printf("CLIENT: IPC Registry Package Name capsule exists.\n");
}

// Delay a bit
libtocksync_alarm_delay_ms(1000);

// Attempt to discover (this should fail as the server hasn't registered yet)
printf("CLIENT: Discovering: \"%s\"\n", service_name);
ret = libtock_ipc_registry_package_name_discover_service(ipc_discovery_complete, (uint8_t*)service_name,
strlen(service_name));
if (ret != RETURNCODE_SUCCESS) {
printf("CLIENT: Discovery failed. Returncode: %d\n", ret);
} else {
printf("CLIENT: Discovery started.\n");
}

// Delay for a bit
libtocksync_alarm_delay_ms(5000);

// Re-attempt to discover (this should now succeed)
printf("CLIENT: Discovering: \"%s\"\n", service_name);
ret = libtock_ipc_registry_package_name_discover_service(ipc_discovery_complete, (uint8_t*)service_name,
strlen(service_name));
if (ret != RETURNCODE_SUCCESS) {
printf("CLIENT: Discovery failed. Returncode: %d\n", ret);
} else {
printf("CLIENT: Discovery started.\n");
}

while (1) {
yield();
}
}
14 changes: 14 additions & 0 deletions examples/tests/ipc/package_name_server-libtock/Makefile
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
# Makefile for user application

# Specify this directory relative to the current application.
TOCK_USERLAND_BASE_DIR = ../../../..

# Which files to compile.
C_SRCS := $(wildcard *.c)

# Package name field for TBF headers
PACKAGE_NAME = tbf_package_name_service

# Include userland master makefile. Contains rules and flags for actually
# building the application.
include $(TOCK_USERLAND_BASE_DIR)/AppMakefile.mk
30 changes: 30 additions & 0 deletions examples/tests/ipc/package_name_server-libtock/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
# Package Name Server - libtock

Registers as an IPC service via TBF Header Package Name using the asynchronous
libtock IPC Registry Package Name driver.

The Package Name for this server is specified in the [Makefile](./Makefile) as
`PACKAGE_NAME = tbf_package_name_service`.

This is intended to be loaded alongside [package_name_client-libtock](../package_name_client-libtock). When
loaded with the Package Name Client the expected behavior is:

```
SERVER: Starting server.
CLIENT: Starting client.
SERVER: IPC Registry Package Name capsule exists.
CLIENT: IPC Registry Package Name capsule exists.
CLIENT: Discovering: "tbf_package_name_service"
CLIENT: Discovery started.
CLIENT: Discovery complete. Service not found.
SERVER: Registering with my package name (see Makefile).
SERVER: Registration started.
SERVER: Registration complete. Succeeded!
CLIENT: Discovering: "tbf_package_name_service"
CLIENT: Discovery started.
CLIENT: Discovery complete. Succeeded! Found IPC ID: 0000000000000001
```

Note that above IPC IDs may not match depending on the order the apps are
loaded and the configuration of your board.

41 changes: 41 additions & 0 deletions examples/tests/ipc/package_name_server-libtock/main.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
#include <stdio.h>
#include <stdlib.h>

#include <libtock-sync/services/alarm.h>
#include <libtock/ipc/ipc_registry_package_name.h>

static void ipc_registration_complete(returncode_t ret) {
if (ret == RETURNCODE_SUCCESS) {
printf("SERVER: Registration complete. Succeeded!\n");
} else {
printf("SERVER: Registration complete. Failed with returncode: %d\n", ret);
}
}

int main(void) {
printf("SERVER: Starting server.\n");

// Check that we can find the driver at all
if (!libtock_ipc_registry_package_name_exists()) {
printf("SERVER: IPC Registry Package Name capsule does not exist on this board.\n");
return 1;
} else {
printf("SERVER: IPC Registry Package Name capsule exists.\n");
}

// Delay a bit
libtocksync_alarm_delay_ms(5000);

// Attempt to register
printf("SERVER: Registering with my package name (see Makefile).\n");
returncode_t ret = libtock_ipc_registry_package_name_register_service(ipc_registration_complete);
if (ret != RETURNCODE_SUCCESS) {
printf("SERVER: Registration failed. Returncode: %d\n", ret);
} else {
printf("SERVER: Registration started.\n");
}

while (1) {
yield();
}
}
11 changes: 11 additions & 0 deletions examples/tests/ipc/relay_request_client-libtock/Makefile
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
# Makefile for user application

# Specify this directory relative to the current application.
TOCK_USERLAND_BASE_DIR = ../../../..

# Which files to compile.
C_SRCS := $(wildcard *.c)

# Include userland master makefile. Contains rules and flags for actually
# building the application.
include $(TOCK_USERLAND_BASE_DIR)/AppMakefile.mk
85 changes: 85 additions & 0 deletions examples/tests/ipc/relay_request_client-libtock/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,85 @@
# Relay Request Client - libtock

Discovers an IPC service via a provided string name using the asynchronous
libtock IPC Registry String Name driver and then periodically sends requests to
it using the asynchronous libtock IPC Relay Request driver.

This is intended to be loaded alongside [relay_request_server-libtock](../relay_request_server-libtock). When
loaded with the Relay Request Server the expected behavior is:

```
SERVER: Starting server.
CLIENT: Starting client.
SERVER: IPC Registry String Name capsule exists.
CLIENT: IPC Registry String Name capsule exists.
SERVER: IPC Relay Request capsule exists.
CLIENT: IPC Relay Request capsule exists.
SERVER: Enabled request waiting callbacks.
CLIENT: Discovering: "Request_Service"
SERVER: Registering with string name: "Request_Service"
CLIENT: Discovery started.
SERVER: Registration started.
CLIENT: Discovery complete. Service not found.
SERVER: Registration complete. Succeeded!
tock$ CLIENT: Discovering: "Request_Service"
CLIENT: Discovery started.
CLIENT: Discovery complete. Succeeded! Found IPC ID: 0000000000000001
CLIENT: Sending request with data { AA BB CC DD EE FF }
CLIENT: Request initiated.
SERVER: New request waiting from IPC ID: 0000000000000000
SERVER: Got a request from IPC ID: 0000000000000000
SERVER: Request data {AA BB CC DD EE FF }
CLIENT: Waiting for response (1 of 10)
CLIENT: Waiting for response (2 of 10)
CLIENT: Waiting for response (3 of 10)
SERVER: Sent response.
CLIENT: Received response. Data { 12 34 56 78 }
CLIENT: Sending request with data { AA BB CC DD EE FF }
...
```

Note that above IPC IDs may not match depending on the order the apps are
loaded and the configuration of your board.

## Fault Handling

This app is designed to handle faults gracefully. Communication is
intentionally slowed down to provide time to manually trigger faults between
certain actions to see the response. Using the Process Console is the easiest
way to intentionally cause a fault to test this. If your board is configured
with the process Fault Policy `RestartFaultPolicy`, then after one process
restarts discovery will be re-initiated and communication will resume.

For example, you can fault the server with the command `fault
relay_request_server-libtock`.

```
SERVER: Got a request from IPC ID: 0000000000000000
SERVER: Request data {AA BB CC DD EE FF }
CLIENT: Waiting for response (1 of 10)
CLIENT: Waiting for response (2 of 10)
CLIENT: Waiting for response (3 of 10)
SERVER: Sent response.
CLIENT: Received response. Data { 12 34 56 78 }
$ fault relay_request_server-libtock

Process relay_request_server-libtock now faulted
SERVER: Starting server.
SERVER: IPC Registry String Name capsule exists.
SERVER: IPC Relay Request capsule exists.
SERVER: Enabled request waiting callbacks.
SERVER: Registering with string name: "Request_Service"
SERVER: Registration started.
SERVER: Registration complete. Succeeded!
CLIENT: Sending request with data { AA BB CC DD EE FF }
CLIENT: Server disappeared? Discover it again.
CLIENT: Discovering: "Request_Service"
CLIENT: Discovery started.
CLIENT: Discovery complete. Succeeded! Found IPC ID: 0000000000000002
CLIENT: Sending request with data { AA BB CC DD EE FF }
CLIENT: Request initiated.
SERVER: New request waiting from IPC ID: 0000000000000000
SERVER: Got a request from IPC ID: 0000000000000000
SERVER: Request data {AA BB CC DD EE FF }
```

Loading
Loading