Virtual Hardware  Version 1.3.0 - beta
Simulation Models with Virtual Interfaces for Test Automation

Using Virtual Socket Interface (VSocket)

Using Virtual Socket Interface (VSocket)

VSocket API provides a general purpose implementation for socket peripheral. This chapter shows how VSocket can be applied in specific use case.

./interface/vsocket/iot_socket.c: implements the IoT Socket variant for Arm Virtual Hardware based on the ARM_VSocket_Type structure and its mapping defined in arm_vsocket.h.

Setup

Instructions below cover specifically setup for using IoT Socket API in a project using Arm Fixed Virtual Platform (FVP) as a target.

Usage example

After VSocket is added to the project the interface can be fully used as described in IoT Socket documentation. For example:

#include "iot_socket.h" // ::IoT Utility:Socket (API)
static const char message[] = { "The quick brown fox jumps over the lazy dog." };
void Echo_Client_Thread (void *arg) {
uint8_t ip[4] = { 192U, 168U, 0U, 100U };
int32_t sock, res;
char dbuf[120];
while (1) {
sock = iotSocketCreate (IOT_SOCKET_AF_INET, IOT_SOCKET_SOCK_STREAM, IOT_SOCKET_IPPROTO_TCP);
res = iotSocketConnect (sock, (uint8_t *)ip, sizeof(ip), 7U);
if (res == 0) {
while (1) {
iotSocketSend (sock, message, sizeof(message));
res = iotSocketRecv (sock, dbuf, sizeof(dbuf));
if (res < 0) {
break; // Receive error
}
if (res > 0) {
if (memcmp (dbuf, message, res) != 0) {
break; // Message error, echoed message is not the same
}
}
osDelay (1000U);
}
}
iotSocketClose (sock);
}
}