-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathremoteMonitorMenu.c
More file actions
205 lines (177 loc) · 7.96 KB
/
remoteMonitorMenu.c
File metadata and controls
205 lines (177 loc) · 7.96 KB
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
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <errno.h>
#include <stdlib.h>
#include <net/if.h>
#include "debugMenu.h"
#include "clientApp.h"
#include "remoteMonitor.h"
#include "eqptResponse.h"
#include "socket.h"
static int remoteState(int);
static int numRemoteClients(int);
static int remoteKill(int);
static int remoteStopHb(int);
static int remoteStatus(int);
debugMenuStruct remoteMonDebugMenu[] =
{
{"remote", "Remote Monitor debug Menus", NULL, NULL, NULL},
{NULL, NULL, "state", "Display remote monitor state", remoteState},
{NULL, NULL, "status","Displays remote monitor variables", remoteStatus},
{NULL, NULL, "show", "Display the number of registered remote clients", numRemoteClients},
{NULL, NULL, "kill", "Kills remote monitor and closes socket to webservice ", remoteKill},
{NULL, NULL, "stop", "Stops transmission of heart beats to the webservice", remoteStopHb}
};
void registerRemoteMonDebugMenu()
{
registerDebugCommand(&remoteMonDebugMenu[0], sizeof(remoteMonDebugMenu)/sizeof(debugMenuStruct));
}
//*************************************************************************************
//*************************************************************************************
// FUNCTION: remoteState
//
// DESCRIPTION: Function used to display the state of Remote Monitor
//
// Parameters:
//
//************************************************************************************
static int remoteState(int theSocketFd)
{
YESNO state;
memset(debugOutputString, 0, DEBUG_OUTPUT_LEN);
sprintf(debugOutputString, "\r\n\r\nRemote Monitor is %s\r\n", ((state = getRemoteMonitorState() == YES)) ? "ACTIVE": "INACTIVE");
sendSocket(theSocketFd, (unsigned char *)debugOutputString, strlen(debugOutputString), 0);
if(state == YES)
{
memset(debugOutputString, 0, DEBUG_OUTPUT_LEN);
}
return RECONN_SUCCESS;
}
//*************************************************************************************
//*************************************************************************************
// FUNCTION: numRemoteClients
//
// DESCRIPTION: Function to display the number of remote clients connected.
//
// Parameters:
//
//************************************************************************************
static int numRemoteClients(int theSocketFd)
{
memset((char *)&debugOutputString, 0, DEBUG_OUTPUT_LEN);
sprintf((char *)&debugOutputString, "\r\n\r\nThe number of registered remote clients = %d\r\n", reconnClientsRegistered(REMOTE));
sendSocket(theSocketFd, (unsigned char *)&debugOutputString, strlen(debugOutputString), 0);
if(reconnClientsRegistered(REMOTE) == 0)
{
sprintf((char *)&debugOutputString, "Web service must have data transmission turned off.\r\n");
sendSocket(theSocketFd, (unsigned char *)&debugOutputString, strlen(debugOutputString), 0);
}
return RECONN_SUCCESS;
}
//*************************************************************************************
//*************************************************************************************
// FUNCTION: remoteKill
//
// DESCRIPTION: Function used to close the socket to the remote server
//
// Parameters:
//
//************************************************************************************
static int remoteKill(int theSocketFd)
{
YESNO wasRmDebugOn = YES;
UNUSED_PARAM(theSocketFd);
/*
* Temporarily turn on remote monitor's debug -- if it is not already on.
*/
if(!RECONN_DEBUG_ON(RM_DEBUG))
{
wasRmDebugOn = NO;
gReconnDebugLevel |= RM_DEBUG;
}
remoteMonitorActivate(NO, NULL);
if(wasRmDebugOn == NO)
{
gReconnDebugLevel &= ~RM_DEBUG;
}
return RECONN_SUCCESS;
}
//*************************************************************************************
//*************************************************************************************
// FUNCTION: remoteStopHb
//
// DESCRIPTION: Function used to stop heart beat message being sent to the web service
// this will cause the web service to close the socket.
//
// Parameters:
//
//************************************************************************************
static int remoteStopHb(int theSocketFd)
{
YESNO wasRmDebugOn = YES;
UNUSED_PARAM(theSocketFd);
/*
* Temporarily turn on remote monitor's debug -- if it is not already on.
*/
if(!RECONN_DEBUG_ON(RM_DEBUG))
{
wasRmDebugOn = NO;
gReconnDebugLevel |= RM_DEBUG;
}
stopRemoteMonitorHb = TRUE;
if(wasRmDebugOn == NO)
{
gReconnDebugLevel &= ~RM_DEBUG;
}
return RECONN_SUCCESS;
}
//*************************************************************************************
//*************************************************************************************
// FUNCTION: remoteStatus
//
// DESCRIPTION: Function used to display information about Remote monitor key variables
//
// Parameters:
//
//************************************************************************************
static int remoteStatus(int theSocketFd)
{
REMOTE_MONITOR_DEBUG_DATA theDebugData;
memset(&theDebugData, 0, sizeof(REMOTE_MONITOR_DEBUG_DATA));
remoteMonitorGetDebugValues(&theDebugData);
memset(debugOutputString, 0, DEBUG_OUTPUT_LEN);
sprintf(debugOutputString, "\r\n%-21s %s","Variable", "Value");
sendSocket(theSocketFd, (unsigned char *)debugOutputString, strlen(debugOutputString), 0);
memset(debugOutputString, 0, DEBUG_OUTPUT_LEN);
sprintf(debugOutputString, "\r\n============================");
sendSocket(theSocketFd, (unsigned char *)debugOutputString, strlen(debugOutputString), 0);
memset(debugOutputString, 0, DEBUG_OUTPUT_LEN);
sprintf(debugOutputString, "\r\n%-21s %d","clientIndex", (theDebugData.theContextPtr) ? theDebugData.theContextPtr->index : -1);
sendSocket(theSocketFd, (unsigned char *)debugOutputString, strlen(debugOutputString), 0);
memset(debugOutputString, 0, DEBUG_OUTPUT_LEN);
sprintf(debugOutputString, "\r\n%-21s %d","webServerSocket", theDebugData.webServerSocket);
sendSocket(theSocketFd, (unsigned char *)debugOutputString, strlen(debugOutputString), 0);
memset(debugOutputString, 0, DEBUG_OUTPUT_LEN);
sprintf(debugOutputString, "\r\n%-21s %s","IpAddress", (theDebugData.theContextPtr) ? inet_ntoa(theDebugData.theContextPtr->sourceIp.sin_addr) : "0.0.0.0");
sendSocket(theSocketFd, (unsigned char *)debugOutputString, strlen(debugOutputString), 0);
memset(debugOutputString, 0, DEBUG_OUTPUT_LEN);
sprintf(debugOutputString, "\r\n%-21s %u","port", (theDebugData.theContextPtr) ? ntohs(theDebugData.theContextPtr->sourceIp.sin_port): 0);
sendSocket(theSocketFd, (unsigned char *)debugOutputString, strlen(debugOutputString), 0);
memset(debugOutputString, 0, DEBUG_OUTPUT_LEN);
sprintf(debugOutputString, "\r\n%-21s %s","remoteMonitorDone", (theDebugData.remoteMonitorDone == FALSE) ? "FALSE" : "TRUE");
sendSocket(theSocketFd, (unsigned char *)debugOutputString, strlen(debugOutputString), 0);
memset(debugOutputString, 0, DEBUG_OUTPUT_LEN);
sprintf(debugOutputString, "\r\n%-21s %s","stopRemoteMonitorHb", (stopRemoteMonitorHb == FALSE) ? "FALSE" : "TRUE");
sendSocket(theSocketFd, (unsigned char *)debugOutputString, strlen(debugOutputString), 0);
memset(debugOutputString, 0, DEBUG_OUTPUT_LEN);
sprintf(debugOutputString, "\r\n%-21s %s","remoteMonitorActive", (theDebugData.remoteMonitorActive == YES) ? "YES" : "NO");
sendSocket(theSocketFd, (unsigned char *)debugOutputString, strlen(debugOutputString), 0);
memset(debugOutputString, 0, DEBUG_OUTPUT_LEN);
sprintf(debugOutputString, "\r\n%-21s %s","theState", theDebugData.theState == RM_INIT ? "INIT" :
theDebugData.theState == RM_GET_HANDSHAKE ? "HANDSHAKE" :
theDebugData.theState == RM_RCV_DATA ? "RCV_DATA" :
"UNKNOWN");
sendSocket(theSocketFd, (unsigned char *)debugOutputString, strlen(debugOutputString), 0);
return RECONN_SUCCESS;
}