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