pubsub.h
Go to the documentation of this file.
1 /*
2  * Copyright (C) 2017 Kubos Corporation
3  *
4  * Licensed under the Apache License, Version 2.0 (the "License");
5  * you may not use this file except in compliance with the License.
6  * You may obtain a copy of the License at
7  *
8  * http://www.apache.org/licenses/LICENSE-2.0
9  *
10  * Unless required by applicable law or agreed to in writing, software
11  * distributed under the License is distributed on an "AS IS" BASIS,
12  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13  * See the License for the specific language governing permissions and
14  * limitations under the License.
15  */
16 
24 #ifndef PUBSUB_H
25 #define PUBSUB_H
26 
27 #include <csp/csp.h>
28 #include <csp/interfaces/csp_if_socket.h>
29 #include <stdbool.h>
30 #include <stdint.h>
31 
35 typedef struct
36 {
38  csp_conn_t * conn_handle;
39  csp_iface_t csp_socket_if;
40  csp_socket_handle_t socket_driver;
41 } pubsub_conn;
42 
50 csp_socket_t * kprv_server_setup(uint8_t port, uint8_t num_connections);
51 
58 bool kprv_server_accept(csp_socket_t * socket, pubsub_conn * conn);
59 
66 bool kprv_server_socket_accept(csp_socket_t * socket, pubsub_conn * conn);
67 
73 
81 bool kprv_subscriber_connect(pubsub_conn * conn, uint8_t address, uint8_t port);
82 
90 bool kprv_subscriber_socket_connect(pubsub_conn * conn, uint8_t address, uint8_t port);
91 
100 bool kprv_publisher_read(const pubsub_conn * conn, void * buffer, int buffer_size, uint8_t port);
101 
110 bool kprv_subscriber_read(const pubsub_conn * conn, void * buffer, int buffer_size, uint8_t port);
111 
119 bool kprv_send_csp(const pubsub_conn * conn, const void * data, uint16_t length);
120 
121 #endif
122 
123 /* @} */
bool kprv_subscriber_connect(pubsub_conn *conn, uint8_t address, uint8_t port)
Used by a telemetry subscriber to connect to the publishing server.
csp_iface_t csp_socket_if
Definition: pubsub.h:39
bool kprv_subscriber_socket_connect(pubsub_conn *conn, uint8_t address, uint8_t port)
Used by a client to connect to a server using a tcp socket.
csp_conn_t * conn_handle
Definition: pubsub.h:38
PubSub connection structure.
Definition: pubsub.h:35
bool kprv_send_csp(const pubsub_conn *conn, const void *data, uint16_t length)
Wrapper function for sending data via a csp connection.
csp_socket_t * kprv_server_setup(uint8_t port, uint8_t num_connections)
Performs the neccesary setup for the telemetry server to begin receiving subscriber connections...
void kprv_subscriber_socket_close(pubsub_conn *conn)
Performs shutdown and cleanup of tcp socket based connections.
bool kprv_server_accept(csp_socket_t *socket, pubsub_conn *conn)
Attempts to accept a subscriber connection.
bool kprv_subscriber_read(const pubsub_conn *conn, void *buffer, int buffer_size, uint8_t port)
Attempts to receive data over the specified pubsub_conn.
bool kprv_publisher_read(const pubsub_conn *conn, void *buffer, int buffer_size, uint8_t port)
Attempts to receive data over the specified pubsub_conn.
csp_socket_handle_t socket_driver
Definition: pubsub.h:40
bool kprv_server_socket_accept(csp_socket_t *socket, pubsub_conn *conn)
Attempts to accept a subscriber connection over a tcp socket.