/
rover_honocloud.cpp
169 lines (149 loc) · 3.71 KB
/
rover_honocloud.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
/*
* Copyright (c) 2017 FH Dortmund and others
* All rights reserved. This program and the accompanying materials
* are made available under the terms of the Eclipse Public License v1.0
* which accompanies this distribution, and is available at
* http://www.eclipse.org/legal/epl-v10.html
*
* Description:
* Rover Hono Cloud API - Interfaces for Rover Hono cloud application development
*
* Contributors:
* M.Ozcelikors <mozcelikors@gmail.com>, created API 17.11.2017
*
*/
#include <roverapi/rover_honocloud.hpp>
#include <libraries/hono_interaction/hono_interaction.h>
#include <libraries/status_library/status_library.h>
#include <stdio.h>
#include <string.h>
rover::RoverHonoCloud::RoverHonoCloud()
:REGISTRATION_PORT(1),
TENANT_NAME((char*)"N"),
PORT(1),
HOST_NAME((char*)"N")
{
#if SIMULATOR
// Just to keep the symbol
handleCode(200);
#endif
}
rover::RoverHonoCloud::RoverHonoCloud(char * host_name, const int port, const int registration_port, char * tenant_name)
{
this->HOST_NAME = host_name;
this->PORT = port;
this->REGISTRATION_PORT = registration_port;
this->TENANT_NAME = tenant_name;
}
int rover::RoverHonoCloud::attributeErrorCheck (void) const
{
if (this->PORT == 1 || this->TENANT_NAME[0] == 'N' || this->HOST_NAME[0] == 'N')
{
fprintf (stderr, "Hono is not initialized. Please use: setHono function\n");
return 0;
}
else
{
return 1;
}
}
int rover::RoverHonoCloud::registerDevice (char * device_id)
{
#if SIMULATOR
return 0;
#endif
if (this->REGISTRATION_PORT != 1)
{
int status = 0;
status = registerDeviceToHonoInstance (this->HOST_NAME, this->REGISTRATION_PORT, this->TENANT_NAME, device_id);
return status;
}
else
{
fprintf (stderr, "Registration port is not initialized. Please use: setRegistrationPort function\n");
return 0;
}
}
int rover::RoverHonoCloud::sendTelemetry (char * device_id, char * user, char * password, char * field, double value)
{
#if SIMULATOR
return 0;
#endif
if (this->attributeErrorCheck() == 1)
{
int status = 0;
status = sendTelemetryDataToHonoInstance (this->HOST_NAME, this->PORT, this->TENANT_NAME, device_id, user, password, field, value);
return status;
}
else
{
return 0;
}
}
int rover::RoverHonoCloud::sendEvent (char * device_id, char * user, char * password, char * field, double value)
{
#if SIMULATOR
return 0;
#endif
if (this->attributeErrorCheck() == 1)
{
int status = 0;
status = sendEventDataToHonoInstance (this->HOST_NAME, this->PORT, this->TENANT_NAME, device_id, user, password, field, value);
return status;
}
else
{
return 0;
}
}
void rover::RoverHonoCloud::setHono (char * host_name, const int port, char * tenant)
{
this->HOST_NAME = host_name;
this->PORT = port;
this->TENANT_NAME = tenant;
}
void rover::RoverHonoCloud::setHostName (char * host_name)
{
this->HOST_NAME = host_name;
}
void rover::RoverHonoCloud::setPort (const int port)
{
this->PORT = port;
}
void rover::RoverHonoCloud::setRegistrationPort (const int port) const
{
this->REGISTRATION_PORT = port;
}
int rover::RoverHonoCloud::getRegistrationPort (void) const
{
return this->REGISTRATION_PORT;
}
void rover::RoverHonoCloud::setTenantName (char * tenant) const
{
this->TENANT_NAME = tenant;
}
char * rover::RoverHonoCloud::getHostName (void) const
{
return this->HOST_NAME;
}
int rover::RoverHonoCloud::getPort (void) const
{
return this->PORT;
}
char * rover::RoverHonoCloud::getTenantName (void) const
{
return this->TENANT_NAME;
}
int rover::RoverHonoCloud::getHonoStatus (char * device_id, char * user, char * password)
{
if (this->attributeErrorCheck() == 1)
{
int status = 0;
status = retrieveHONOStatus (this->HOST_NAME, this->PORT, this->TENANT_NAME, device_id, user, password);
return status;
}
else
{
return 0;
}
}