-
Notifications
You must be signed in to change notification settings - Fork 3
/
ubx_agpsIf.cpp
executable file
·162 lines (140 loc) · 4.14 KB
/
ubx_agpsIf.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
/*******************************************************************************
*
* Copyright (C) u-blox AG
* u-blox AG, Thalwil, Switzerland
*
* All rights reserved.
*
* Permission to use, copy, modify, and distribute this software for any
* purpose without fee is hereby granted, provided that this entire notice
* is included in all copies of any software which is or includes a copy
* or modification of this software and in all copies of the supporting
* documentation for such software.
*
* THIS SOFTWARE IS BEING PROVIDED "AS IS", WITHOUT ANY EXPRESS OR IMPLIED
* WARRANTY. IN PARTICULAR, NEITHER THE AUTHOR NOR U-BLOX MAKES ANY
* REPRESENTATION OR WARRANTY OF ANY KIND CONCERNING THE MERCHANTABILITY
* OF THIS SOFTWARE OR ITS FITNESS FOR ANY PARTICULAR PURPOSE.
*
*******************************************************************************
*
* Project: PE_ANS
*
******************************************************************************/
/*!
\file
\brief Debug interface implementation
*/
/*******************************************************************************
* $Id: ubx_agpsIf.cpp 63615 2012-11-27 10:12:42Z andrea.foni $
******************************************************************************/
#include "string.h"
#include "ubx_agpsIf.h"
///////////////////////////////////////////////////////////////////////////////
// Definitions & Types
///////////////////////////////////////////////////////////////////////////////
// Local data
static CAgpsIf s_myIf; //!< Private instance of the CAgpsIf class - 'singleton'
const AGpsInterface CAgpsIf::s_interface = { //!< Agps interface jump table
size: sizeof(AGpsInterface),
init: CAgpsIf::init,
data_conn_open: CAgpsIf::dataConnOpen,
data_conn_closed: CAgpsIf::dataConnClosed,
data_conn_failed: CAgpsIf::dataConnFailed,
set_server: CAgpsIf::setServer,
};
///////////////////////////////////////////////////////////////////////////////
CAgpsIf::CAgpsIf()
{
m_ready = false;
m_agpsServersCnt = 0;
#ifdef SUPL_ENABLED
m_certificateFileName = NULL;
#endif
memset(&m_callbacks, 0, sizeof(m_callbacks));
memset(m_agpsServers, 0, sizeof(m_agpsServers));
}
CAgpsIf::~CAgpsIf()
{
#ifdef SUPL_ENABLED
if (m_certificateFileName)
{
free(m_certificateFileName);
m_certificateFileName = NULL;
}
#endif
}
CAgpsIf* CAgpsIf::getInstance()
{
return &s_myIf;
}
void CAgpsIf::init(AGpsCallbacks* callbacks)
{
if (s_myIf.m_ready)
LOGE("CAgpsIf::%s : already initialized", __FUNCTION__);
LOGV("CAgpsIf::%s :", __FUNCTION__);
s_myIf.m_callbacks = *callbacks;
s_myIf.m_ready = true;
//lint -e{818} remove "could be declared as pointing to const"
}
int CAgpsIf::dataConnOpen(const char* apn)
{
LOGD("CAgpsIf::%s : apn='%s'", __FUNCTION__, apn);
return 0;
}
int CAgpsIf::dataConnClosed(void)
{
LOGD("CAgpsIf::%s :", __FUNCTION__);
return 0;
}
int CAgpsIf::dataConnFailed()
{
LOGD("CAgpsIf::%s :", __FUNCTION__);
return 0;
}
int CAgpsIf::setServer(AGpsType type, const char* hostname, int port)
{
LOGD("CAgpsIf::%s : type=%i(%s) host=%s port=%i", __FUNCTION__, type, _LOOKUPSTR(type, AGpsType), hostname, port);
int cnt = s_myIf.m_agpsServersCnt;
if (cnt < NUM_AGPS_SERVERS)
{
s_myIf.m_agpsServers[cnt].type = type;
s_myIf.m_agpsServers[cnt].port = port;
strncpy(s_myIf.m_agpsServers[cnt].hostname, hostname, MAX_HOSTNAME);
s_myIf.m_agpsServersCnt = cnt +1;
}
else
{
LOGE("CAgpsIf::%s : no space", __FUNCTION__);
}
return 0;
}
int CAgpsIf::numServer(AGpsType type) const
{
int i;
int cnt = 0;
for (i = 0; i < m_agpsServersCnt; i ++)
{
if (m_agpsServers[i].type == type)
cnt ++;
}
LOGD("CAgpsIf::%s : num=%d", __FUNCTION__, cnt);
return cnt;
}
#ifdef SUPL_ENABLED
void CAgpsIf::getSuplServerInfo(char** ppSuplServerAddress, int *pSuplPort)
{
*ppSuplServerAddress = NULL;
*pSuplPort = -1;
int i;
for (i = 0; i < m_agpsServersCnt; i ++)
{
if (m_agpsServers[i].type == AGPS_TYPE_SUPL)
{
*ppSuplServerAddress = m_agpsServers[i].hostname;
*pSuplPort = m_agpsServers[i].port;
}
}
LOGV("CAgpsIf::%s : Address:Port %s:%d", __FUNCTION__, *ppSuplServerAddress, *pSuplPort);
}
#endif