Important changes to repositories hosted on mbed.com
Mbed hosted mercurial repositories are deprecated and are due to be permanently deleted in July 2026.
To keep a copy of this software download the repository Zip archive or clone locally using Mercurial.
It is also possible to export all your personal repositories from the account settings page.
mbed-mqtt-master/paho_mqtt_embedded_c/MQTTPacket/samples/baremetalserial/transport.h@0:ba7e439238ab, 2022-06-20 (annotated)
- Committer:
- pavleradojkovic
- Date:
- Mon Jun 20 16:24:43 2022 +0000
- Revision:
- 0:ba7e439238ab
Inital commit
Who changed what in which revision?
| User | Revision | Line number | New contents of line |
|---|---|---|---|
| pavleradojkovic | 0:ba7e439238ab | 1 | /******************************************************************************* |
| pavleradojkovic | 0:ba7e439238ab | 2 | * Copyright (c) 2014 IBM Corp. |
| pavleradojkovic | 0:ba7e439238ab | 3 | * |
| pavleradojkovic | 0:ba7e439238ab | 4 | * All rights reserved. This program and the accompanying materials |
| pavleradojkovic | 0:ba7e439238ab | 5 | * are made available under the terms of the Eclipse Public License v1.0 |
| pavleradojkovic | 0:ba7e439238ab | 6 | * and Eclipse Distribution License v1.0 which accompany this distribution. |
| pavleradojkovic | 0:ba7e439238ab | 7 | * |
| pavleradojkovic | 0:ba7e439238ab | 8 | * The Eclipse Public License is available at |
| pavleradojkovic | 0:ba7e439238ab | 9 | * http://www.eclipse.org/legal/epl-v10.html |
| pavleradojkovic | 0:ba7e439238ab | 10 | * and the Eclipse Distribution License is available at |
| pavleradojkovic | 0:ba7e439238ab | 11 | * http://www.eclipse.org/org/documents/edl-v10.php. |
| pavleradojkovic | 0:ba7e439238ab | 12 | * |
| pavleradojkovic | 0:ba7e439238ab | 13 | * Contributors: |
| pavleradojkovic | 0:ba7e439238ab | 14 | * Ian Craggs - initial API and implementation and/or initial documentation |
| pavleradojkovic | 0:ba7e439238ab | 15 | * Sergio R. Caprile - media specifics, nice api doc :^) |
| pavleradojkovic | 0:ba7e439238ab | 16 | *******************************************************************************/ |
| pavleradojkovic | 0:ba7e439238ab | 17 | |
| pavleradojkovic | 0:ba7e439238ab | 18 | typedef struct { |
| pavleradojkovic | 0:ba7e439238ab | 19 | int (*send)(unsigned char *address, unsigned int bytes); ///< pointer to function to send 'bytes' bytes, returns the actual number of bytes sent |
| pavleradojkovic | 0:ba7e439238ab | 20 | int (*recv)(unsigned char *address, unsigned int maxbytes); ///< pointer to function to receive upto 'maxbytes' bytes, returns the actual number of bytes copied |
| pavleradojkovic | 0:ba7e439238ab | 21 | } transport_iofunctions_t; |
| pavleradojkovic | 0:ba7e439238ab | 22 | |
| pavleradojkovic | 0:ba7e439238ab | 23 | #define TRANSPORT_DONE 1 |
| pavleradojkovic | 0:ba7e439238ab | 24 | #define TRANSPORT_AGAIN 0 |
| pavleradojkovic | 0:ba7e439238ab | 25 | #define TRANSPORT_ERROR -1 |
| pavleradojkovic | 0:ba7e439238ab | 26 | /** |
| pavleradojkovic | 0:ba7e439238ab | 27 | @note Blocks until requested buflen is sent |
| pavleradojkovic | 0:ba7e439238ab | 28 | */ |
| pavleradojkovic | 0:ba7e439238ab | 29 | int transport_sendPacketBuffer(int sock, unsigned char* buf, int buflen); |
| pavleradojkovic | 0:ba7e439238ab | 30 | /** |
| pavleradojkovic | 0:ba7e439238ab | 31 | @note Blocks until requested count is received, as MQTTPacket_read() expects |
| pavleradojkovic | 0:ba7e439238ab | 32 | @warning This function is not supported (not implemented) |
| pavleradojkovic | 0:ba7e439238ab | 33 | @warning unless you provide a timeout, this function can block forever. Socket based systems do have |
| pavleradojkovic | 0:ba7e439238ab | 34 | a built in timeout, if your system can provide this, do modify this function, otherwise use getdatanb() instead |
| pavleradojkovic | 0:ba7e439238ab | 35 | @returns number of bytes read |
| pavleradojkovic | 0:ba7e439238ab | 36 | */ |
| pavleradojkovic | 0:ba7e439238ab | 37 | int transport_getdata(unsigned char* buf, int count); |
| pavleradojkovic | 0:ba7e439238ab | 38 | |
| pavleradojkovic | 0:ba7e439238ab | 39 | /** |
| pavleradojkovic | 0:ba7e439238ab | 40 | This is a bare metal implementation, so we must have non-blocking functions, |
| pavleradojkovic | 0:ba7e439238ab | 41 | the process of pumping to serial lines can result a bit slow and we don't want to busy wait. |
| pavleradojkovic | 0:ba7e439238ab | 42 | This function starts the process, you will call sendPacketBuffernb() until it reports success (or error) |
| pavleradojkovic | 0:ba7e439238ab | 43 | */ |
| pavleradojkovic | 0:ba7e439238ab | 44 | void transport_sendPacketBuffernb_start(int sock, unsigned char* buf, int buflen); |
| pavleradojkovic | 0:ba7e439238ab | 45 | /** |
| pavleradojkovic | 0:ba7e439238ab | 46 | This is a bare metal implementation, so we must have non-blocking functions, |
| pavleradojkovic | 0:ba7e439238ab | 47 | the process of pumping to serial lines can result a bit slow and we don't want to busy wait |
| pavleradojkovic | 0:ba7e439238ab | 48 | @returns TRANSPORT_DONE if finished, TRANSPORT_AGAIN for call again, or TRANSPORT_ERROR on error |
| pavleradojkovic | 0:ba7e439238ab | 49 | @note you will call again until it finishes (this is stream) |
| pavleradojkovic | 0:ba7e439238ab | 50 | */ |
| pavleradojkovic | 0:ba7e439238ab | 51 | int transport_sendPacketBuffernb(int sock); |
| pavleradojkovic | 0:ba7e439238ab | 52 | |
| pavleradojkovic | 0:ba7e439238ab | 53 | /** |
| pavleradojkovic | 0:ba7e439238ab | 54 | This is a bare metal implementation, so we must have non-blocking functions, |
| pavleradojkovic | 0:ba7e439238ab | 55 | the process of sucking from serial lines can result a bit slow and we don't want to busy wait |
| pavleradojkovic | 0:ba7e439238ab | 56 | @return the actual number of bytes read, 0 for none, or TRANSPORT_ERROR on error |
| pavleradojkovic | 0:ba7e439238ab | 57 | @note you will call again until total number of expected bytes is read (this is stream) |
| pavleradojkovic | 0:ba7e439238ab | 58 | */ |
| pavleradojkovic | 0:ba7e439238ab | 59 | int transport_getdatanb(void *sck, unsigned char* buf, int count); |
| pavleradojkovic | 0:ba7e439238ab | 60 | |
| pavleradojkovic | 0:ba7e439238ab | 61 | /** |
| pavleradojkovic | 0:ba7e439238ab | 62 | We assume whatever connection needs to be done, it is externally established by the specifics of the hardware |
| pavleradojkovic | 0:ba7e439238ab | 63 | E.g.: |
| pavleradojkovic | 0:ba7e439238ab | 64 | A cell modem: you will call AT+whatever and put the modem in transparent mode, OR, you will embed |
| pavleradojkovic | 0:ba7e439238ab | 65 | the AT+xSENDx / AT+xRECVx commands into the former sendPacketBuffer() and getdatanb() functions |
| pavleradojkovic | 0:ba7e439238ab | 66 | @param thisio pointer to a structure containing all necessary stuff to handle direct serial I/O |
| pavleradojkovic | 0:ba7e439238ab | 67 | @returns whatever indicator the system assigns to this link, if any. (a.k.a. : 'sock'), or TRANSPORT_ERROR for error |
| pavleradojkovic | 0:ba7e439238ab | 68 | */ |
| pavleradojkovic | 0:ba7e439238ab | 69 | int transport_open(transport_iofunctions_t *thisio); |
| pavleradojkovic | 0:ba7e439238ab | 70 | int transport_close(int sock); |