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 <stdint.h>
29 #include <stdbool.h>
30 
34 typedef struct
35 {
37  csp_conn_t * conn_handle;
38 } pubsub_conn;
39 
47 csp_socket_t * kprv_server_setup(uint8_t port, uint8_t num_connections);
48 
55 bool kprv_server_accept(csp_socket_t * socket, pubsub_conn * conn);
56 
64 bool kprv_subscriber_connect(pubsub_conn * conn, uint8_t address, uint8_t port);
65 
74 bool kprv_publisher_read(const pubsub_conn * conn, void * buffer, int buffer_size, uint8_t port);
75 
84 bool kprv_subscriber_read(const pubsub_conn * conn, void * buffer, int buffer_size, uint8_t port);
85 
93 bool kprv_send_csp(const pubsub_conn * conn, const void * data, uint16_t length);
94 
95 #endif
96 
97 /* @} */
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_conn_t * conn_handle
Definition: pubsub.h:37
PubSub connection structure.
Definition: pubsub.h:34
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...
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.