Results 1 to 8 of 8

Thread: New Toy: obdsim

  1. #1
    SuperMod - OBDII GPS Logger forum
    Auto Apps:loading...

    Join Date
    Mar 2009
    Location
    Los Angeles
    Posts
    929

    New Toy: obdsim

    So, I tried a bunch of simulators out there, and found none of them were meeting my wishlist. Specifically, high on my wishlist is "must work from obdgpslogger logs and pretend that it's a real ELM device while doing it". That, and "command-line".

    So, I decided to write a sim. The code borrows heavily from malcolm2073's ObdSim in this thread, a very friendly base to work from for which I am eternally grateful.

    Here are some major features:

    It works by consuming logfiles from obdgpslogger. If you don't have any, here's one.

    It also has a pluggable [although only compile-time, and currently only done by editing build files] mechanism for pulling from other data streams. The first, proof-of-concept one I wrote was a random generator - it pulls numbers from random() every time. The default is now to use logs, but the random one is still there.

    It honors ATE{1,0}, ATS{0,1}, ATZ, with more on the way. It's also case-insensitive.

    It reads the database created by obdgpslogger, and when asked what it supports [via 0100/0120/0140/0160], it responds accurately with a list of what it found based on columns in the database. Short version, it really pretends to be the car the log was originally created in.

    It interpolates values from the database, so if your original database was created with a samplerate of once-per-second, but you are connecting to it and sampling 20 times a second, you'll get a graph that looks exactly the same and has pretty good guesses at values. The opposite works too, obviously.

    It's free (as in beer), and Free (as in speech). Thanks to Malcolm2073 again for doing the hard bits.

    It's in the same repo as obdgpslogger (1). It's obviously first-and-foremost a tool for messing with obdgpslogger, but it doesn't depend on the logger itself [although it does depend on some other libraries in the same source tree]. This means that it works with OBDII software other than obdgpslogger. It does, though, provide a cheesy command-line option to let it take a stab at automatically launching obdgpslogger and connecting the logger to it.

    It's in the same repo as obdgpslogger (2). I intend to keep it feature-compatible with obdgpslogger; as I add features to obdgpslogger, I will be adding features to the sim for testing it. As mentioned, the current set of AT commands is pretty limited, but it neatly matches the commands that obdgpslogger uses.

    I think that's a good enough start.

    Gary (-;
    OBDGPSLogger, for logging OBDII and/or GPS data
    OBDSim, an OBDII/ELM327 software simulator
    mp3car forums: obdgpslogger, obdsim

  2. #2
    Constant Bitrate
    Join Date
    Aug 2007
    Location
    Northern VA
    Posts
    135
    Excellent. I'll try check it out later this week!

  3. #3
    SuperMod - OBDII GPS Logger forum
    Auto Apps:loading...

    Join Date
    Mar 2009
    Location
    Los Angeles
    Posts
    929
    All,

    As promised, I worked on the generator API a bit last night. Now obdsim is capable of having multiple generators linked in at the same time. Instructions on writing plugins are provided in src/sim/generators/README.generator [repeated below]. The short version is "copy generators/random/ to generators/{whatever}/, and edit to taste".

    Code:
    How to write a generator for obdsim
    
    
    Note: By convention, I will refer to the name of your generator-to-be
    as {generator}, or {GENERATOR} if you should uppercase it.
    
    1) Start by looking at datasource.h
      It contains a struct, "obdsim_generator", containing functions you
        must implement.
    
    2) The easiest generator to understand is in /generators/random/
      Copy /generators/random/ to generators/{generator}/
    
    2a) Look at the C files
      It #includes "datasource.h", then creates the functions required
        by datasource.h.
      By convention, all the functions are named {generator}_simgen_{function}.
      At the end of the file, we create the obdsim_generator struct.
    
    2b) Look at the CMakeInclude.cmake files
      Edit this and replace all instances of RANDOM with {GENERATOR},
        and random with {generator}
      If you need extra libraries for your generator, add them similarly at
        the end of GENERATOR_LIBS
    
    3) Open sim/obdsim.c
      Your plugin should be added in two places, both near the top of the file:
        first, an extern to declare it without #including anything.
        second, added to the list of available_generators.
      Note that each instance is wrapped with #ifdef OBDSIMGEN_{GENERATOR}
    
    
    Project-wide conventions: If your generator will add external dependencies,
       it should default to Off.
    
    
    Gary "Chunky Ks" Briggs
    <[email protected]>
    Step 3 is obviously the slightly cheesy C workaround. If anyone has a better way of doing it, I'm open to suggestion. The rest of it is pretty easy, a big case of monkey-see-monkey-do. I'm likely to make the CMakeInclude files easier to edit by some simple substitutions, but that won't change anything important.


    The output of --help now appears thus:
    Code:
    Usage: ../bin/obdsim [params]
       [-s|--seed=<generator-specific-string>]
       [-g|--generator=<name of generator>]
       [-o|--launch-logger]
       [-v|--version] [-h|--help]
    The generators built into this sim:
     "Random"
     "Logger" (default)
    It's also not too late to get in requests for changes to the API. The current version is here: http://svn.icculus.org/obdgpslogger/....h?view=markup. As I see it, there's two things that might be worth changing:
    1) The build system, specifically a better way of working around step 3 in the instructions. In C++, I would use a linked list and some macros so that generators get added during static initialisation. I don't know of a pattern like that that works in C, though.
    2) The API itself. It's not too late to get in requests for API changes. I'm currently considering two more functions:
    a) one to get a human-friendly description of the seed for end-user help [eg, the one for logger would be "Filename of obdgpslogger logfile"].
    b) An idle-type callback. Currently the sim blocks on reading lines from the pty. This was easier to code [a lot!] than a nonblocking version. The problem is that when you want to write a GUI data generator.

    There are two ways to write a GUI data generator for this;
    1) Spawn a thread in the generator_create function and run the UI from that [generally running UIs out of your non-main thread is a Bad Idea(TM), although it will work fine for some of them, or in most cases...].
    2) Add an idle callback in obdsim. Use nonblocking reads from the pty, and whenever obdsim has nothing better to do, it calls that idle callback. This is great for GUIs, since you can just shove a call to wxYield(), FL::check(), QApplication:rocessEvents(), etc.

    Feedback is welcome. In fact, more than welcome, I really need help and advice of developers here :-)

    It also occurs to me that an idle callback would be more useful in the case of, say, a dbus plugin which can continue consuming signals while it has nothing better to do.

    Gary (-;
    OBDGPSLogger, for logging OBDII and/or GPS data
    OBDSim, an OBDII/ELM327 software simulator
    mp3car forums: obdgpslogger, obdsim

  4. #4
    Constant Bitrate
    Join Date
    Aug 2007
    Location
    Northern VA
    Posts
    135
    Works just like it says on the tin!

    #2++

  5. #5
    SuperMod - OBDII GPS Logger forum
    Auto Apps:loading...

    Join Date
    Mar 2009
    Location
    Los Angeles
    Posts
    929
    So it's super cheesy and ugly right now, but...



    It's a gui plugin for obdsim. The sim is on the right [you can see obdsim announcing the pty it created in the terminal], and on the left is obdgpslogger [where you can see I gave it the pty created by the sim]

    Woooo

    Gary (-;
    OBDGPSLogger, for logging OBDII and/or GPS data
    OBDSim, an OBDII/ELM327 software simulator
    mp3car forums: obdgpslogger, obdsim

  6. #6
    SuperMod - OBDII GPS Logger forum
    Auto Apps:loading...

    Join Date
    Mar 2009
    Location
    Los Angeles
    Posts
    929
    Up to five plugins now:
    Code:
    kibbles-2:build chunky$ ../bin/obdsim --help
    Usage: ../bin/obdsim [params]
       [-s|--seed=<generator-specific-string>]
       [-g|--generator=<name of generator>]
       [-o|--launch-logger]
       [-v|--version] [-h|--help]
    The generators built into this sim:
     "Random" (default)
     "Logger"
     "DBus"
     "dlopen"
     "gui_fltk"
    kibbles-2:build chunky$
    Gary (-;
    OBDGPSLogger, for logging OBDII and/or GPS data
    OBDSim, an OBDII/ELM327 software simulator
    mp3car forums: obdgpslogger, obdsim

  7. #7
    Constant Bitrate
    Join Date
    Aug 2007
    Location
    Northern VA
    Posts
    135
    Nice work. I've gotten busy but will test it out later this week.

    charles

  8. #8
    SuperMod - OBDII GPS Logger forum
    Auto Apps:loading...

    Join Date
    Mar 2009
    Location
    Los Angeles
    Posts
    929
    Coo, have fun :-)

    Gary (-;
    OBDGPSLogger, for logging OBDII and/or GPS data
    OBDSim, an OBDII/ELM327 software simulator
    mp3car forums: obdgpslogger, obdsim

Similar Threads

  1. IGNav (New toy for the new year)
    By Champak in forum General MP3Car Discussion
    Replies: 11
    Last Post: 03-10-2008, 05:38 PM
  2. new toy - wifi card w/ external antenna
    By warnockm in forum Wireless Communications
    Replies: 3
    Last Post: 08-13-2006, 12:30 AM
  3. my new toy
    By scott_fx in forum Off Topic
    Replies: 2
    Last Post: 07-14-2006, 09:01 PM
  4. Another toy by MindTool: MindCalm
    By mindtool in forum MediaCar
    Replies: 34
    Last Post: 12-10-2003, 01:12 PM
  5. Built a box today for my new toy!
    By outragis in forum General MP3Car Discussion
    Replies: 2
    Last Post: 09-15-2003, 07:25 AM

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •