int
main
(
int
argc,
const
char
* argv
[])
{
string
errmsg;
// Setup the API to use local USB devices
if(
yRegisterHub
(
"usb"
, errmsg
)
!= YAPI_SUCCESS
)
{
cerr
<<
"RegisterHub error: "
<< errmsg <<
endl
;
return
1
;
}
if(
argc <
2
)
usage
(
argv
[
0
])
;
YModule *module = yFindModule
(
argv
[
1
])
;
// use serial or logical name
if
(
module->
isOnline
())
{
if
(
argc >
2
)
{
if
(
string
(
argv
[
2
])
==
"ON"
)
module->
set_beacon
(
Y_BEACON_ON
)
;
else
module->
set_beacon
(
Y_BEACON_OFF
)
;
}
cout
<<
"serial: "
<< module->
get_serialNumber
()
<<
endl
;
cout
<<
"logical name: "
<< module->
get_logicalName
()
<<
endl
;
cout
<<
"luminosity: "
<< module->
get_luminosity
()
<<
endl
;
cout
<<
"beacon: "
;
if
(
module->
get_beacon
()
== Y_BEACON_ON
)
cout
<<
"ON"
<<
endl
;
else
cout
<<
"OFF"
<<
endl
;
cout
<<
"upTime: "
<< module->
get_upTime
()
/
1000
<<
" sec"
<<
endl
;
cout
<<
"USB current: "
<< module->
get_usbCurrent
()
<<
" mA"
<<
endl
;
cout
<<
"Logs:"
<<
endl
<< module->
get_lastLogs
()
<<
endl
;
}
else
{
cout
<< argv
[
1
]
<<
" not connected (check identification and USB cable)"
<<
endl
;
}
yFreeAPI
()
;
return
0
;
}
Each property
xxx
of the module can be read thanks to a method of type
get_xxxx()
, and
properties which are not read-only can be modified with the help of the
set_xxx()
method. For
more details regarding the used functions, refer to the API chapters.
Changing the module settings
When you want to modify the settings of a module, you only need to call the corresponding
set_xxx()
function. However, this modification is performed only in the random access memory
(RAM) of the module: if the module is restarted, the modifications are lost. To memorize them
persistently, it is necessary to ask the module to save its current configuration in its permanent
memory. To do so, use the
saveToFlash()
method. Inversely, it is possible to force the module to
forget its current settings by using the
revertFromFlash()
method. The short example below
allows you to modify the logical name of a module.
#include <iostream>
#include <stdlib.h>
#include "yocto_api.h"
using
namespace
std;
static
void
usage
(const
char
*exe
)
{
cerr
<<
"usage: "
<< exe <<
" <serial> <newLogicalName>"
<<
endl
;
exit
(
1
)
;
}
int
main
(
int
argc,
const
char
* argv
[])
{
string
errmsg;
9. Using Yocto-GPS with C++
62
www.yoctopuce.com
Summary of Contents for Yocto-GPS
Page 1: ...Yocto GPS User s guide...
Page 2: ......
Page 6: ...22 Characteristics 557 Blueprint 559 Index 561...
Page 10: ...4 www yoctopuce com...
Page 14: ...8 www yoctopuce com...
Page 18: ...12 www yoctopuce com...
Page 22: ...16 www yoctopuce com...
Page 38: ...32 www yoctopuce com...
Page 42: ...36 www yoctopuce com...
Page 54: ...48 www yoctopuce com...
Page 72: ...66 www yoctopuce com...
Page 92: ...86 www yoctopuce com...
Page 122: ...116 www yoctopuce com...
Page 132: ...126 www yoctopuce com...
Page 564: ...22 Characteristics 558 www yoctopuce com...
Page 565: ......
Page 566: ......