Show lessgps.c syntax highlighted
/*
*
* Copyright (c) 2003 The Regents of the University of California. All
* rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
*
* - Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
*
* - Neither the name of the University nor the names of its
* contributors may be used to endorse or promote products derived
* from this software without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS''
* AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
* THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A
* PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR
* CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
* EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
* PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
* PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY
* OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*
*/
/*
* lessgps - visualizes lessgps status
*
* $Id: lessgps.c,v 1.3 2004/07/23 00:14:35 jelson Exp $
*/
char emview_lessgps_c_id[] = "$Id: lessgps.c,v 1.3 2004/07/23 00:14:35 jelson Exp $";
#include <mod/mod_radio.h>
#include <mod/mod_timesync.h>
#include <emview/emview.h>
#include <libmisc/misc.h>
#include <link/link.h>
#include <timesync/sync.h>
#include <timesync/lessgps.h>
static struct {
emview_module_t *mod;
emview_device_t *dev;
GQuark statbox_q;
} state = {
/* initialize to all null/0 */
};
int ts_lessgps_status_handler(emview_device_t *dev, emproxy_reply_hdr_t *reply,
emview_dev_node_t *node)
{
/* emview framework appears to check for correct length */
lessgps_status_t *ls = (lessgps_status_t *) reply->data;
/* if lessgps is unlocked, box has no color */
if (!ls->locked) {
emview_update_source_int(TS_LESSGPS_LOCKED, emview_dn_get_node_id(node), 0);
emview_update_source(TS_LESSGPS_ERROR, emview_dn_get_node_id(node), "");
return 0;
}
#if 0
/* otherwise box is color of the master - we try to make a unique
identifier from the combo of node ID and component ID */
emview_update_source_int(TS_LESSGPS_LOCKED, emview_dn_get_node_id(node),
emview_assign_color(TS_LESSGPS_LOCKED,
(ls->master.node << 8) | ls->master.comp)
);
#endif
emview_update_source_int(TS_LESSGPS_LOCKED, emview_dn_get_node_id(node), EMVIEW_COLOR_GREEN);
emview_update_source_int(TS_LESSGPS_ERROR, emview_dn_get_node_id(node), ls->error);
return 0;
}
static
int ts_lessgps_new_instance(emview_module_t *mod,
emview_module_inst_t *instance,
char *device, node_id_t node)
{
char buf[255];
emview_device_opts_t opts = {
name: LESSGPS_OUTPUT_STATUS_DEV,
private_data: instance,
proxy_string: buf,
nominal_data_length: sizeof(lessgps_status_t),
data_handler: ts_lessgps_status_handler,
parent: mod
};
/* register the device -- to read data from timesync /dev file */
sprintf(buf, "dev=%s:reread=5000", LESSGPS_OUTPUT_STATUS_DEV);
state.dev = emview_register_device(&opts);
emview_register_source(state.dev, TS_LESSGPS_LOCKED, NULL);
emview_register_source(state.dev, TS_LESSGPS_ERROR, NULL);
return 0;
}
static
int ts_lessgps_assign(emview_module_t *mod, emview_module_inst_t *inst,
node_id_t node, parser_state_t *ps)
{
state.statbox_q = g_quark_from_string(TS_LESSGPS_BOX);
emview_component_register(state.statbox_q, node, EMVIEW_COMP_TYPE_BOX);
emview_assign_source(node,
TS_LESSGPS_BOX,
EMVIEW_BOX_COLOR,
TS_LESSGPS_LOCKED,
TS_LESSGPS_OPT,
EMVIEW_ENABLE_ALL);
emview_assign_source(node,
TS_LESSGPS_BOX,
EMVIEW_BOX_INSIDE,
TS_LESSGPS_ERROR,
TS_LESSGPS_OPT,
EMVIEW_ENABLE_ALL);
return 0;
}
static
int ts_lessgps_opts(emview_module_t *mod, emview_module_inst_t *inst,
node_id_t node, parser_state_t *ps)
{
emview_document_option_class
(mod, TS_LESSGPS_OPT, "dont-know-what-this-is-for",
"LessGPS Lock Status", NULL);
emview_option_class_set_enable
(node, TS_LESSGPS_OPT, 1);
return 0;
}
int ts_lessgps_main(int *argc, char **argv)
{
static emview_module_opts_t mod_opts = {
name: TS_LESSGPS_MODULE,
description: "LessGPS Lock Status",
config_new_instance: ts_lessgps_new_instance,
config_assign: ts_lessgps_assign,
config_opts: ts_lessgps_opts
};
state.mod = emview_register(&mod_opts);
return 0;
}
See more files for this project here