Skip to content

Commit

Permalink
Merge pull request #7 from nasa-itc/nos3#163-Spacecraft-Docker
Browse files Browse the repository at this point in the history
[nasa/nos3#163] Spacecraft Docker
  • Loading branch information
jlucas9 authored Sep 19, 2023
2 parents eb38ad4 + dab85eb commit 405f028
Show file tree
Hide file tree
Showing 3 changed files with 173 additions and 125 deletions.
1 change: 1 addition & 0 deletions fsw/public_inc/libsocket.h
Original file line number Diff line number Diff line change
Expand Up @@ -62,5 +62,6 @@ int32_t socket_connect(socket_info_t* socket_info, char* remote_ip_address, int
int32_t socket_send(socket_info_t* socket_info, uint8_t* buffer, size_t buflen, size_t* bytes_sent, char* remote_ip_address, int remote_port_num);
int32_t socket_recv(socket_info_t* socket_info, uint8_t* buffer, size_t buflen, size_t* bytes_recvd);
int32_t socket_close(socket_info_t* socket_info);
int32_t HostToIp(const char * hostname, char* ip);

#endif
57 changes: 52 additions & 5 deletions sim/src/libsocket.c
Original file line number Diff line number Diff line change
@@ -1,9 +1,12 @@
#include "libsocket.h"

#include <sys/socket.h>
#include <arpa/inet.h>
#include <fcntl.h>
#include <errno.h>
#include <fcntl.h>
#include <netdb.h>
#include <netinet/in.h>
#include <sys/socket.h>
#include <sys/types.h>

// Creates an endpoint for communication
// Binds stream, server sockets to localhost and port number
Expand Down Expand Up @@ -84,8 +87,20 @@ int32_t socket_create(socket_info_t* socket_info)
{
// Prepare the sockaddr_in structure
sockaddr.sin_family = address_family;
sockaddr.sin_addr.s_addr = inet_addr(socket_info->ip_address);
sockaddr.sin_port = htons(socket_info->port_num);
if(inet_addr(socket_info->ip_address) != INADDR_NONE)
{
sockaddr.sin_addr.s_addr = inet_addr(socket_info->ip_address);
}
else
{
char ip[16];
int check = HostToIp(socket_info->ip_address, ip);
if(check == 0)
{
sockaddr.sin_addr.s_addr = inet_addr(ip);
}
}
sockaddr.sin_port = htons(socket_info->port_num);

// Bind the socket
ret = bind(socket_info->sockfd,(struct sockaddr *)&sockaddr , sizeof(sockaddr));
Expand Down Expand Up @@ -321,7 +336,19 @@ int32_t socket_send(socket_info_t* socket_info, uint8_t* buffer, size_t buflen,
{
// Prepare the remote_sockaddr structure
remote_sockaddr.sin_family = socket_info->address_family;
remote_sockaddr.sin_addr.s_addr = inet_addr(remote_ip_address);
if(inet_addr(remote_ip_address) != INADDR_NONE)
{
remote_sockaddr.sin_addr.s_addr = inet_addr(remote_ip_address);
}
else
{
char ip[16];
int check = HostToIp(remote_ip_address, ip);
if(check == 0)
{
remote_sockaddr.sin_addr.s_addr = inet_addr(ip);
}
}
remote_sockaddr.sin_port = htons(remote_port_num);

ret = sendto(socket_info->sockfd, (void*)buffer, buflen, 0, (struct sockaddr *)&remote_sockaddr , sizeof(remote_sockaddr));
Expand Down Expand Up @@ -452,3 +479,23 @@ int32_t socket_close(socket_info_t* socket_info)

return status;
}

int HostToIp(const char * hostname, char* ip)
{
struct hostent *he;
struct in_addr **addr_list;

if ( (he = gethostbyname( hostname ) ) == NULL )
{
return 1;
}

addr_list = (struct in_addr **) he->h_addr_list;

for(int i=0; addr_list[i] != NULL; i++)
{
strcpy(ip, inet_ntoa(*addr_list[i]) );
return 0;
}
return 1;
}
240 changes: 120 additions & 120 deletions sim/src/nos_link.c
Original file line number Diff line number Diff line change
Expand Up @@ -21,138 +21,138 @@ [email protected]

/* nos usart connection table */
nos_connection_t nos_usart_connection[NUM_USARTS] = {
{"tcp://127.0.0.1:12000", "usart_0"},
{"tcp://127.0.0.1:12000", "usart_1"},
{"tcp://127.0.0.1:12000", "usart_2"},
{"tcp://127.0.0.1:12000", "usart_3"},
{"tcp://127.0.0.1:12000", "usart_4"},
{"tcp://127.0.0.1:12000", "usart_5"},
{"tcp://127.0.0.1:12000", "usart_6"},
{"tcp://127.0.0.1:12000", "usart_7"},
{"tcp://127.0.0.1:12000", "usart_8"},
{"tcp://127.0.0.1:12000", "usart_9"},
{"tcp://127.0.0.1:12000", "usart_10"},
{"tcp://127.0.0.1:12000", "usart_11"},
{"tcp://127.0.0.1:12000", "usart_12"},
{"tcp://127.0.0.1:12000", "usart_13"},
{"tcp://127.0.0.1:12000", "usart_14"},
{"tcp://127.0.0.1:12000", "usart_15"},
{"tcp://127.0.0.1:12000", "usart_16"},
{"tcp://127.0.0.1:12000", "usart_17"},
{"tcp://127.0.0.1:12000", "usart_18"},
{"tcp://127.0.0.1:12000", "usart_19"},
{"tcp://127.0.0.1:12000", "usart_20"},
{"tcp://127.0.0.1:12000", "usart_21"},
{"tcp://127.0.0.1:12000", "usart_22"},
{"tcp://127.0.0.1:12000", "usart_23"},
{"tcp://127.0.0.1:12000", "usart_24"},
{"tcp://127.0.0.1:12000", "usart_25"},
{"tcp://127.0.0.1:12000", "usart_26"},
{"tcp://127.0.0.1:12000", "usart_27"},
{"tcp://127.0.0.1:12000", "usart_28"},
{"tcp://127.0.0.1:12000", "usart_29"}
{"tcp://nos_engine_server:12000", "usart_0"},
{"tcp://nos_engine_server:12000", "usart_1"},
{"tcp://nos_engine_server:12000", "usart_2"},
{"tcp://nos_engine_server:12000", "usart_3"},
{"tcp://nos_engine_server:12000", "usart_4"},
{"tcp://nos_engine_server:12000", "usart_5"},
{"tcp://nos_engine_server:12000", "usart_6"},
{"tcp://nos_engine_server:12000", "usart_7"},
{"tcp://nos_engine_server:12000", "usart_8"},
{"tcp://nos_engine_server:12000", "usart_9"},
{"tcp://nos_engine_server:12000", "usart_10"},
{"tcp://nos_engine_server:12000", "usart_11"},
{"tcp://nos_engine_server:12000", "usart_12"},
{"tcp://nos_engine_server:12000", "usart_13"},
{"tcp://nos_engine_server:12000", "usart_14"},
{"tcp://nos_engine_server:12000", "usart_15"},
{"tcp://nos_engine_server:12000", "usart_16"},
{"tcp://nos_engine_server:12000", "usart_17"},
{"tcp://nos_engine_server:12000", "usart_18"},
{"tcp://nos_engine_server:12000", "usart_19"},
{"tcp://nos_engine_server:12000", "usart_20"},
{"tcp://nos_engine_server:12000", "usart_21"},
{"tcp://nos_engine_server:12000", "usart_22"},
{"tcp://nos_engine_server:12000", "usart_23"},
{"tcp://nos_engine_server:12000", "usart_24"},
{"tcp://nos_engine_server:12000", "usart_25"},
{"tcp://nos_engine_server:12000", "usart_26"},
{"tcp://nos_engine_server:12000", "usart_27"},
{"tcp://nos_engine_server:12000", "usart_28"},
{"tcp://nos_engine_server:12000", "usart_29"}
};

/* nos i2c connection table */
nos_connection_t nos_i2c_connection[NUM_I2C_DEVICES] = {
{"tcp://127.0.0.1:12000", "i2c_0"},
{"tcp://127.0.0.1:12000", "i2c_1"},
{"tcp://127.0.0.1:12000", "i2c_2"},
{"tcp://127.0.0.1:12000", "i2c_3"},
{"tcp://127.0.0.1:12000", "i2c_4"},
{"tcp://127.0.0.1:12000", "i2c_5"},
{"tcp://127.0.0.1:12000", "i2c_6"},
{"tcp://127.0.0.1:12000", "i2c_7"},
{"tcp://127.0.0.1:12000", "i2c_8"},
{"tcp://127.0.0.1:12000", "i2c_9"},
{"tcp://127.0.0.1:12000", "i2c_10"},
{"tcp://127.0.0.1:12000", "i2c_11"},
{"tcp://127.0.0.1:12000", "i2c_12"},
{"tcp://127.0.0.1:12000", "i2c_13"},
{"tcp://127.0.0.1:12000", "i2c_14"},
{"tcp://127.0.0.1:12000", "i2c_15"},
{"tcp://127.0.0.1:12000", "i2c_16"},
{"tcp://127.0.0.1:12000", "i2c_17"},
{"tcp://127.0.0.1:12000", "i2c_18"},
{"tcp://127.0.0.1:12000", "i2c_19"},
{"tcp://127.0.0.1:12000", "i2c_20"},
{"tcp://127.0.0.1:12000", "i2c_21"},
{"tcp://127.0.0.1:12000", "i2c_22"},
{"tcp://127.0.0.1:12000", "i2c_23"},
{"tcp://127.0.0.1:12000", "i2c_24"},
{"tcp://127.0.0.1:12000", "i2c_25"},
{"tcp://127.0.0.1:12000", "i2c_26"},
{"tcp://127.0.0.1:12000", "i2c_27"},
{"tcp://127.0.0.1:12000", "i2c_28"},
{"tcp://127.0.0.1:12000", "i2c_29"}
{"tcp://nos_engine_server:12000", "i2c_0"},
{"tcp://nos_engine_server:12000", "i2c_1"},
{"tcp://nos_engine_server:12000", "i2c_2"},
{"tcp://nos_engine_server:12000", "i2c_3"},
{"tcp://nos_engine_server:12000", "i2c_4"},
{"tcp://nos_engine_server:12000", "i2c_5"},
{"tcp://nos_engine_server:12000", "i2c_6"},
{"tcp://nos_engine_server:12000", "i2c_7"},
{"tcp://nos_engine_server:12000", "i2c_8"},
{"tcp://nos_engine_server:12000", "i2c_9"},
{"tcp://nos_engine_server:12000", "i2c_10"},
{"tcp://nos_engine_server:12000", "i2c_11"},
{"tcp://nos_engine_server:12000", "i2c_12"},
{"tcp://nos_engine_server:12000", "i2c_13"},
{"tcp://nos_engine_server:12000", "i2c_14"},
{"tcp://nos_engine_server:12000", "i2c_15"},
{"tcp://nos_engine_server:12000", "i2c_16"},
{"tcp://nos_engine_server:12000", "i2c_17"},
{"tcp://nos_engine_server:12000", "i2c_18"},
{"tcp://nos_engine_server:12000", "i2c_19"},
{"tcp://nos_engine_server:12000", "i2c_20"},
{"tcp://nos_engine_server:12000", "i2c_21"},
{"tcp://nos_engine_server:12000", "i2c_22"},
{"tcp://nos_engine_server:12000", "i2c_23"},
{"tcp://nos_engine_server:12000", "i2c_24"},
{"tcp://nos_engine_server:12000", "i2c_25"},
{"tcp://nos_engine_server:12000", "i2c_26"},
{"tcp://nos_engine_server:12000", "i2c_27"},
{"tcp://nos_engine_server:12000", "i2c_28"},
{"tcp://nos_engine_server:12000", "i2c_29"}
};

/* nos can connection table */
nos_connection_t nos_can_connection[NUM_CAN_DEVICES] = {
{"tcp://127.0.0.1:12000", "can_0"},
{"tcp://127.0.0.1:12000", "can_1"},
{"tcp://127.0.0.1:12000", "can_2"},
{"tcp://127.0.0.1:12000", "can_3"},
{"tcp://127.0.0.1:12000", "can_4"},
{"tcp://127.0.0.1:12000", "can_5"},
{"tcp://127.0.0.1:12000", "can_6"},
{"tcp://127.0.0.1:12000", "can_7"},
{"tcp://127.0.0.1:12000", "can_8"},
{"tcp://127.0.0.1:12000", "can_9"},
{"tcp://127.0.0.1:12000", "can_10"},
{"tcp://127.0.0.1:12000", "can_11"},
{"tcp://127.0.0.1:12000", "can_12"},
{"tcp://127.0.0.1:12000", "can_13"},
{"tcp://127.0.0.1:12000", "can_14"},
{"tcp://127.0.0.1:12000", "can_15"},
{"tcp://127.0.0.1:12000", "can_16"},
{"tcp://127.0.0.1:12000", "can_17"},
{"tcp://127.0.0.1:12000", "can_18"},
{"tcp://127.0.0.1:12000", "can_19"},
{"tcp://127.0.0.1:12000", "can_20"},
{"tcp://127.0.0.1:12000", "can_21"},
{"tcp://127.0.0.1:12000", "can_22"},
{"tcp://127.0.0.1:12000", "can_23"},
{"tcp://127.0.0.1:12000", "can_24"},
{"tcp://127.0.0.1:12000", "can_25"},
{"tcp://127.0.0.1:12000", "can_26"},
{"tcp://127.0.0.1:12000", "can_27"},
{"tcp://127.0.0.1:12000", "can_28"},
{"tcp://127.0.0.1:12000", "can_29"}
{"tcp://nos_engine_server:12000", "can_0"},
{"tcp://nos_engine_server:12000", "can_1"},
{"tcp://nos_engine_server:12000", "can_2"},
{"tcp://nos_engine_server:12000", "can_3"},
{"tcp://nos_engine_server:12000", "can_4"},
{"tcp://nos_engine_server:12000", "can_5"},
{"tcp://nos_engine_server:12000", "can_6"},
{"tcp://nos_engine_server:12000", "can_7"},
{"tcp://nos_engine_server:12000", "can_8"},
{"tcp://nos_engine_server:12000", "can_9"},
{"tcp://nos_engine_server:12000", "can_10"},
{"tcp://nos_engine_server:12000", "can_11"},
{"tcp://nos_engine_server:12000", "can_12"},
{"tcp://nos_engine_server:12000", "can_13"},
{"tcp://nos_engine_server:12000", "can_14"},
{"tcp://nos_engine_server:12000", "can_15"},
{"tcp://nos_engine_server:12000", "can_16"},
{"tcp://nos_engine_server:12000", "can_17"},
{"tcp://nos_engine_server:12000", "can_18"},
{"tcp://nos_engine_server:12000", "can_19"},
{"tcp://nos_engine_server:12000", "can_20"},
{"tcp://nos_engine_server:12000", "can_21"},
{"tcp://nos_engine_server:12000", "can_22"},
{"tcp://nos_engine_server:12000", "can_23"},
{"tcp://nos_engine_server:12000", "can_24"},
{"tcp://nos_engine_server:12000", "can_25"},
{"tcp://nos_engine_server:12000", "can_26"},
{"tcp://nos_engine_server:12000", "can_27"},
{"tcp://nos_engine_server:12000", "can_28"},
{"tcp://nos_engine_server:12000", "can_29"}
};

/* nos spi connection table */
nos_connection_t nos_spi_connection[NUM_SPI_DEVICES] = {
{"tcp://127.0.0.1:12000", "spi_0"},
{"tcp://127.0.0.1:12000", "spi_1"},
{"tcp://127.0.0.1:12000", "spi_2"},
{"tcp://127.0.0.1:12000", "spi_3"},
{"tcp://127.0.0.1:12000", "spi_4"},
{"tcp://127.0.0.1:12000", "spi_5"},
{"tcp://127.0.0.1:12000", "spi_6"},
{"tcp://127.0.0.1:12000", "spi_7"},
{"tcp://127.0.0.1:12000", "spi_8"},
{"tcp://127.0.0.1:12000", "spi_9"},
{"tcp://127.0.0.1:12000", "spi_10"},
{"tcp://127.0.0.1:12000", "spi_11"},
{"tcp://127.0.0.1:12000", "spi_12"},
{"tcp://127.0.0.1:12000", "spi_13"},
{"tcp://127.0.0.1:12000", "spi_14"},
{"tcp://127.0.0.1:12000", "spi_15"},
{"tcp://127.0.0.1:12000", "spi_16"},
{"tcp://127.0.0.1:12000", "spi_17"},
{"tcp://127.0.0.1:12000", "spi_18"},
{"tcp://127.0.0.1:12000", "spi_19"},
{"tcp://127.0.0.1:12000", "spi_20"},
{"tcp://127.0.0.1:12000", "spi_21"},
{"tcp://127.0.0.1:12000", "spi_22"},
{"tcp://127.0.0.1:12000", "spi_23"},
{"tcp://127.0.0.1:12000", "spi_24"},
{"tcp://127.0.0.1:12000", "spi_25"},
{"tcp://127.0.0.1:12000", "spi_26"},
{"tcp://127.0.0.1:12000", "spi_27"},
{"tcp://127.0.0.1:12000", "spi_28"},
{"tcp://127.0.0.1:12000", "spi_29"}
{"tcp://nos_engine_server:12000", "spi_0"},
{"tcp://nos_engine_server:12000", "spi_1"},
{"tcp://nos_engine_server:12000", "spi_2"},
{"tcp://nos_engine_server:12000", "spi_3"},
{"tcp://nos_engine_server:12000", "spi_4"},
{"tcp://nos_engine_server:12000", "spi_5"},
{"tcp://nos_engine_server:12000", "spi_6"},
{"tcp://nos_engine_server:12000", "spi_7"},
{"tcp://nos_engine_server:12000", "spi_8"},
{"tcp://nos_engine_server:12000", "spi_9"},
{"tcp://nos_engine_server:12000", "spi_10"},
{"tcp://nos_engine_server:12000", "spi_11"},
{"tcp://nos_engine_server:12000", "spi_12"},
{"tcp://nos_engine_server:12000", "spi_13"},
{"tcp://nos_engine_server:12000", "spi_14"},
{"tcp://nos_engine_server:12000", "spi_15"},
{"tcp://nos_engine_server:12000", "spi_16"},
{"tcp://nos_engine_server:12000", "spi_17"},
{"tcp://nos_engine_server:12000", "spi_18"},
{"tcp://nos_engine_server:12000", "spi_19"},
{"tcp://nos_engine_server:12000", "spi_20"},
{"tcp://nos_engine_server:12000", "spi_21"},
{"tcp://nos_engine_server:12000", "spi_22"},
{"tcp://nos_engine_server:12000", "spi_23"},
{"tcp://nos_engine_server:12000", "spi_24"},
{"tcp://nos_engine_server:12000", "spi_25"},
{"tcp://nos_engine_server:12000", "spi_26"},
{"tcp://nos_engine_server:12000", "spi_27"},
{"tcp://nos_engine_server:12000", "spi_28"},
{"tcp://nos_engine_server:12000", "spi_29"}
};

/* common transport hub */
Expand Down

0 comments on commit 405f028

Please sign in to comment.