• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*******************************************************************************
2  * Copyright (c) 2014, 2015 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  *    Allan Stockdill-Mander - initial API and implementation and/or initial documentation
15  *******************************************************************************/
16 
17 #if !defined(MQTTLiteOS_H)
18 #define MQTTLiteOS_H
19 
20 
21 #include <sys/types.h>
22 
23 #if !defined(SOCKET_ERROR)
24     /** error in socket operation */
25 #define SOCKET_ERROR (-1)
26 #endif
27 
28 
29 #define INVALID_SOCKET SOCKET_ERROR
30 #include <sys/socket.h>
31 #include <sys/param.h>
32 #include <sys/time.h>
33 #include <netinet/in.h>
34 #include <netinet/tcp.h>
35 #include <arpa/inet.h>
36 #include <netdb.h>
37 #include <stdio.h>
38 #include <unistd.h>
39 #include <errno.h>
40 #include <fcntl.h>
41 #include <string.h>
42 #include <stdlib.h>
43 
44 #include <sys/ioctl.h>
45 #include <net/if.h>
46 
47 #include "ohos_init.h"
48 #include "cmsis_os2.h"
49 
50 #include "lwip/ip_addr.h"
51 #include "lwip/netifapi.h"
52 
53 #include "lwip/sockets.h"
54 
55 #define MQTT_TASK
56 
57 typedef struct Thread {
58     osThreadId_t task;
59 } Thread;
60 
61 int ThreadStart(Thread* thread, void (*fn)(void*), void* arg);
62 
63 typedef struct Timer {
64     struct timeval end_time;
65 } Timer;
66 
67 typedef struct Mutex {
68     osSemaphoreId_t sem;
69 } Mutex;
70 
71 void MqttMutexInit(Mutex* mutex);
72 int MqttMutexLock(Mutex* mutex);
73 int MqttMutexUnlock(Mutex* mutex);
74 
75 void TimerInit(Timer* timer);
76 char TimerIsExpired(Timer* timer);
77 void TimerCountdownMS(Timer* timer, unsigned int);
78 void TimerCountdown(Timer* timer, unsigned int);
79 int TimerLeftMS(Timer* timer);
80 
81 typedef struct Network {
82     int my_socket;
83     int (*mqttread) (struct Network*, unsigned char*, int, int);
84     int (*mqttwrite) (struct Network*, unsigned char*, int, int);
85 } Network;
86 
87 int linux_read(Network* n, unsigned char*, int, int);
88 int linux_write(Network* n, unsigned char*, int, int);
89 
90 void NetworkInit(Network* n);
91 int NetworkConnect(Network* n, char*, int);
92 void NetworkDisconnect(Network* n);
93 
94 #endif
95