navit  0.5.3-trunk
j1850.c File Reference
#include <math.h>
#include <stdio.h>
#include <glib.h>
#include <time.h>
#include <stdlib.h>
#include <string.h>
#include <fcntl.h>
#include <unistd.h>
#include <termios.h>
#include <errno.h>
#include <sys/ioctl.h>
#include "config.h"
#include <navit/item.h>
#include <navit/xmlconfig.h>
#include <navit/main.h>
#include <navit/debug.h>
#include <navit/map.h>
#include <navit/navit.h>
#include <navit/callback.h>
#include <navit/file.h>
#include <navit/plugin.h>
#include <navit/event.h>
#include <navit/command.h>
#include <navit/config_.h>
#include "graphics.h"
#include "color.h"
#include "osd.h"

Data Structures

struct  j1850
 

Functions

void rand_str (char *dest, size_t length)
 Generates a fake sentence. Used for debugging. More...
 
void write_to_serial_port (unsigned char *cmd, int device)
 Writes 'cmd' to the serial port'. More...
 
static void j1850_idle (struct j1850 *j1850)
 Function called when navit is idle. Does the continous reading. More...
 
static void osd_j1850_draw (struct j1850 *this, struct navit *nav, struct vehicle *v)
 Draws the j1850 OSD. More...
 
static void osd_j1850_init (struct j1850 *this, struct navit *nav)
 Initialize the j1850 OSD. More...
 
void send_and_read (unsigned char *cmd, int USB)
 Sends 'cmd' and reads the reply from the device. More...
 
void j1850_init_serial_port (struct j1850 *j1850)
 Opens the serial port and saves state to the j1850 object. More...
 
static struct osd_priv * osd_j1850_new (struct navit *nav, struct osd_methods *meth, struct attr **attrs)
 Creates the j1850 OSD and set some default properties. More...
 
void plugin_init (void)
 The plugin entry point. More...
 

Function Documentation

◆ j1850_idle()

static void j1850_idle ( struct j1850 j1850)
static

Function called when navit is idle. Does the continous reading.

Parameters
[in]j1850- the j1850 struct containing the state of the plugin
Returns
nothing

This is the main function of this plugin. It is called when navit is idle, and performs the initialization of the obd device if needed, then reads one char each time it is called, and puts this char in a buffer. When it reads an EOL character, the buffer is parsed, and the appropriate action is taken. The buffer is then cleared and we start over.

References j1850::callback, command_evaluate(), data, dbg, j1850::device, j1850::engine_rpm, event_add_idle(), event_remove_timeout(), j1850::filename, j1850::idle, j1850::index, j1850::init_string_index, lvl_debug, lvl_error, lvl_info, j1850::map, j1850::message, j1850::nav, j1850::odo, rand_str(), j1850::tank_level, j1850::trans_rpm, value, and write_to_serial_port().

Referenced by j1850_init_serial_port().

◆ j1850_init_serial_port()

void j1850_init_serial_port ( struct j1850 j1850)

Opens the serial port and saves state to the j1850 object.

Parameters
[in]j1850- the j1850 struct containing the state of the plugin
Returns
nothing

Opens the serial port and saves state to the j1850 object

References j1850::callback, callback_cast, callback_new_1, dbg, j1850::device, event_add_timeout(), j1850::idle, j1850_idle(), and lvl_error.

Referenced by osd_j1850_init().

◆ osd_j1850_draw()

static void osd_j1850_draw ( struct j1850 this,
struct navit nav,
struct vehicle v 
)
static

Draws the j1850 OSD.

Parameters
[in]j1850- the j1850 struct containing the state of the plugin nav - the navit object v - the vehicle object
Returns
nothing

Draws the j1850 OSD. Currently it only displays the last parsed message

References bbox(), draw_mode_end, graphics::font, osd_item::gr, graphics_draw_mode(), graphics_draw_text(), graphics_get_text_bbox(), osd_item::h, p, and osd_item::w.

Referenced by osd_j1850_init(), and osd_j1850_new().

◆ osd_j1850_init()

static void osd_j1850_init ( struct j1850 this,
struct navit nav 
)
static

Initialize the j1850 OSD.

Parameters
[in]j1850- the j1850 struct containing the state of the plugin nav - the navit object
Returns
nothing

Initialize the j1850 OSD

References c, callback_cast, callback_new_1, event_add_timeout(), osd_item::gr, osd_item::graphic_fg, graphics_gc_new(), graphics_gc_set_foreground(), graphics_gc_set_linewidth(), j1850_init_serial_port(), osd_j1850_draw(), osd_set_std_graphic(), and width.

Referenced by osd_j1850_new().

◆ osd_j1850_new()

static struct osd_priv* osd_j1850_new ( struct navit nav,
struct osd_methods meth,
struct attr **  attrs 
)
static

Creates the j1850 OSD and set some default properties.

Parameters
[in]nav- the navit object meth - the osd_methods attrs - pointer to the attributes
Returns
nothing

Creates the j1850 OSD and set some default properties

References attr_search(), attr::attrs, callback_cast, callback_new_attr_1, dbg, osd_item_methods::draw, filename, osd_item::font_size, osd_item::h, j1850::init_string_index, lvl_error, osd_item::meth, j1850::nav, osd_item::navit, navit_add_callback(), attr::num, osd_draw_cast, osd_j1850_draw(), osd_j1850_init(), osd_set_std_attr(), osd_item::p, attr::u, osd_item::w, width, point::x, and point::y.

Referenced by plugin_init().

◆ plugin_init()

void plugin_init ( void  )

The plugin entry point.

Returns
nothing

The plugin entry point

References attr_iter::iter, and osd_j1850_new().

◆ rand_str()

void rand_str ( char *  dest,
size_t  length 
)

Generates a fake sentence. Used for debugging.

Parameters
[in]dest- the char * to which we will write the sentence lenght - the length of the sentence to generate
Returns
nothing

Generates a fake string to simulate data from the serial port

References startup::dest, and length.

Referenced by j1850_idle().

◆ send_and_read()

void send_and_read ( unsigned char *  cmd,
int  USB 
)

Sends 'cmd' and reads the reply from the device.

Parameters
[in]cmd- the char * that we will write to the serial port device - the serial port device
Returns
nothing

Sends 'cmd' and reads the reply from the device

References dbg, lvl_debug, and lvl_error.

◆ write_to_serial_port()

void write_to_serial_port ( unsigned char *  cmd,
int  device 
)

Writes 'cmd' to the serial port'.

Parameters
[in]cmd- the char * that we will write to the serial port device - the serial port device
Returns
nothing

Write the cmd to the serial port

References dbg, and lvl_info.

Referenced by j1850_idle().