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 
28 #ifndef PUBSUB_H
29 #define PUBSUB_H
30 
31 #include <csp/csp.h>
32 #include <csp/interfaces/csp_if_socket.h>
33 #include <stdbool.h>
34 #include <stdint.h>
35 
39 typedef struct
40 {
42  csp_conn_t * conn_handle;
43  csp_iface_t csp_socket_if;
44  csp_socket_handle_t socket_driver;
45 } pubsub_conn;
46 
54 csp_socket_t * kprv_server_setup(uint8_t port, uint8_t num_connections);
55 
62 bool kprv_server_accept(csp_socket_t * socket, pubsub_conn * conn);
63 
70 bool kprv_server_socket_accept(csp_socket_t * socket, pubsub_conn * conn);
71 
77 
85 bool kprv_subscriber_connect(pubsub_conn * conn, uint8_t address, uint8_t port);
86 
94 bool kprv_subscriber_socket_connect(pubsub_conn * conn, uint8_t address, uint8_t port);
95 
104 bool kprv_publisher_read(const pubsub_conn * conn, void * buffer, int buffer_size, uint8_t port);
105 
114 bool kprv_subscriber_read(const pubsub_conn * conn, void * buffer, int buffer_size, uint8_t port);
115 
123 bool kprv_send_csp(const pubsub_conn * conn, const void * data, uint16_t length);
124 
125 #endif
126 
127 /* @} */
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:43
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:42
PubSub connection structure.
Definition: pubsub.h:39
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:44
bool kprv_server_socket_accept(csp_socket_t *socket, pubsub_conn *conn)
Attempts to accept a subscriber connection over a tcp socket.