json, CAN

A place to discuss software and code that isn't automotive related. Free and open source preferred but not compulsory.
andg
SOT-223 - Salvaje
Posts: 144
Joined: Thu Apr 18, 2013 3:21 am
Location: Portland OREGON
Contact:

Re: json, CAN

Post by andg »

at this point external event handlers can be attached that log json data of any request.

Code: Select all

:before_transition :park => do 
  moving? transition[neutral]
end
Optimizing state machine to do simplest, most critical validation just before the transition.

Code: Select all

:event park_brake
  transition[park]
end

Code: Select all

def moving?
  db.sensors.find({"speed" : {$exists:true}}, {speed:1}).sort({_id:-1}).limit(1)
end
find documents with a speed key and return the most recent one.

Code: Select all

{ "_id" : ObjectId("517f3fbb6e46043d8781257f"), "speed" : 2 }
Last edited by andg on Tue Apr 30, 2013 8:35 pm, edited 7 times in total.

Code: Select all

{url: andrewgauger.com, skype: andrgaug, email: andg@andrewgauger.com, car: 25, fb: facebook.com/DonatoArrighi, github: andg.github.io, assets:https://s3.amazonaws.com/3400}
andg
SOT-223 - Salvaje
Posts: 144
Joined: Thu Apr 18, 2013 3:21 am
Location: Portland OREGON
Contact:

Re: json, CAN

Post by andg »

Code: Select all

def avg_speed
  if ( m = db.sensor.count(speed: {$exists:true}) ) < 1 raise "we don't know if we're moving!"
  db.sensors.aggregate( [
   { $group: { _id: null,
               count: { $sum: 1 } } }] ) / m
end
aggregation provides powerful framework to do anything outside of the simple sum succintly

But what we are looking to do is at the database be able to implement high level OOP into the database layer which is where we need functions added to our playground. a mapreduce might look like this:

Code: Select all

res = db.<mycollection>.mapReduce(map, red);
which can create a temporary collect to abstract data in different ways
Last edited by andg on Tue Apr 30, 2013 8:37 pm, edited 6 times in total.

Code: Select all

{url: andrewgauger.com, skype: andrgaug, email: andg@andrewgauger.com, car: 25, fb: facebook.com/DonatoArrighi, github: andg.github.io, assets:https://s3.amazonaws.com/3400}
andg
SOT-223 - Salvaje
Posts: 144
Joined: Thu Apr 18, 2013 3:21 am
Location: Portland OREGON
Contact:

Re: json, CAN

Post by andg »

Code: Select all

map = function() {
   var res = 0;
   for (i = 0; i < this.marks.length; i++) {
      res = res + this.marks[i];
   }
   var median = res/this.marks.length;
   emit(this._id,{marks:this.marks,median:median});
}


reduce = function (k, values) {
    values.forEach(function(value) {
      result = value;
    });
    return result;
}

Code: Select all

group({ initial: {count: 0, running_average: 0},
     reduce: function(doc, out) 
     {out.count++; out.running_average+=doc.v;
     },finalize: function(out)
     {  out.average = out.running_average / out.count;}});
Used formatting more like node js here. If you want to learn the power of mongoDB you need to learn the Javascript engine that runs it.
Last edited by andg on Tue Apr 30, 2013 7:04 pm, edited 5 times in total.

Code: Select all

{url: andrewgauger.com, skype: andrgaug, email: andg@andrewgauger.com, car: 25, fb: facebook.com/DonatoArrighi, github: andg.github.io, assets:https://s3.amazonaws.com/3400}
andg
SOT-223 - Salvaje
Posts: 144
Joined: Thu Apr 18, 2013 3:21 am
Location: Portland OREGON
Contact:

Re: json, CAN

Post by andg »

production runs through manufacturing.
In 24 hrs product had velocity of 26 units/sec and we need a way to expose business intelligence through an api so that adjunct systems can communicate.

Code: Select all

{)id: BSON,
product: "Cascade",
invent_trans_id: 3445},

{)id: BSON,
product: "Cascade",
invent_trans_id: 3446},

{)id: BSON,
product: "Cascade",
invent_trans_id: 3447}
Last edited by andg on Sat Apr 27, 2013 5:16 pm, edited 1 time in total.

Code: Select all

{url: andrewgauger.com, skype: andrgaug, email: andg@andrewgauger.com, car: 25, fb: facebook.com/DonatoArrighi, github: andg.github.io, assets:https://s3.amazonaws.com/3400}
andg
SOT-223 - Salvaje
Posts: 144
Joined: Thu Apr 18, 2013 3:21 am
Location: Portland OREGON
Contact:

Re: json, CAN

Post by andg »

JSON is adjunct XML in terms of data exposure. mongo data can be exposed in an xml format from incredibly low level processes. all the way up through c and ruby comes along

Code: Select all

<nodes>
<node><id>BSON</id>
<product>Cascade</product>,
<invent_trans_id> 3445<</invent_trans_id>
</node>
<node><id>BSON</id>
<product>Cascade</product>,
<invent_trans_id> 3446<</invent_trans_id>
</node>
<node><id>BSON</id>
<product>Cascade</product>,
<invent_trans_id> 3447<</invent_trans_id>
</node>
</nodes>
Last edited by andg on Tue Apr 30, 2013 5:32 am, edited 3 times in total.

Code: Select all

{url: andrewgauger.com, skype: andrgaug, email: andg@andrewgauger.com, car: 25, fb: facebook.com/DonatoArrighi, github: andg.github.io, assets:https://s3.amazonaws.com/3400}
andg
SOT-223 - Salvaje
Posts: 144
Joined: Thu Apr 18, 2013 3:21 am
Location: Portland OREGON
Contact:

Re: json, CAN

Post by andg »

CAN is a network aware protocol using as few as 4 wires although all implementations use 9 which when you are dealing with shielded signals is a major pain in the arse.

this leads to a various sample size for an event handler which shares the data model. As more signals are sent through the network each cpu has to keep up with the message size so each sensor gets tuned from a networking perspective

Networks can be taped. They can be injected. If an external controller detects on the network something is missing it can inject a calculated signal, detect if it sent a signal in error and stop doing that for a while and externally log the sensor before it tells you you should look into something on the car.

4 wires are TX and RX signals

CAN interface is impractical in its implementation

if you output tap the RX and validate against your local code to know when to fire. remote attached networked sensors that only alert the event handlers which run on two bluetooth attached iPads that elect which one is in charge. The two iPads are running native app or broken if necissary. They display EMS Studio as the dash and ensure all of the necessary signals are present even if the remote sensor isn't present.

engine at predefined rpm shifts from 24x signal to 3x signal for performance reasons and that signal takes too long to process normally. This remote sensor can be queried by sending a request signal across the network to provide signal for a duration.

local validation code on the output device uses CAN decipering signals across those 4 wires.

GM DIS is first example on car already using the technology by pre processing the7x signal and converign it to 3x off board

what better place to put input signals like slap shifters that say lets upshift and we want it to happen asap.

event logger is waiting for any signal of the slap shift telling the `car` to do something unique like any good event handler deals with

Transmission control happens externally with a harness to the transmission which signals the network of a query interface to find the neutral safety switch status

lets say we want our event handler to detect throttle platee at 0 since this is a major event for the system

we need to bypass air since thats how I sit in trtaffic mostly on the brake. Idle air control through the existing valve is valuable. MAP, TPS, and TACH can be interpreted that we're idling but there is no reason to send these signals everywhere at every chance so we tune the network, and data logging usage by allowing for small documents to transmit.

need to add event handler for throttle plate position by time interval and time interval acceration

This type of logic lives at a higher level than the firmware. The entire design is to be able to tune event handlers for known conditions. I currently have an evap leak that I ought to fix, but a check engine light is a bit extreme for this.

normal cpu not utilized determining based off existing tables or at the oscellation. Event handlers become the slimed down versions of code.
gemsets or versions of the modules become available to each external controller.
Last edited by andg on Tue Apr 30, 2013 9:01 pm, edited 10 times in total.

Code: Select all

{url: andrewgauger.com, skype: andrgaug, email: andg@andrewgauger.com, car: 25, fb: facebook.com/DonatoArrighi, github: andg.github.io, assets:https://s3.amazonaws.com/3400}
andg
SOT-223 - Salvaje
Posts: 144
Joined: Thu Apr 18, 2013 3:21 am
Location: Portland OREGON
Contact:

Re: json, CAN

Post by andg »

Code: Select all

CREATE TRIGGER ON INVENTORY FOR INSERT AS UPDATE INVENTORY SET VELOCITY=calculation
Not implemented in mongodb. Implement at a higher level or consider tailable cursors on the oplog
oplog used in replication
Last edited by andg on Tue Apr 30, 2013 8:52 pm, edited 3 times in total.

Code: Select all

{url: andrewgauger.com, skype: andrgaug, email: andg@andrewgauger.com, car: 25, fb: facebook.com/DonatoArrighi, github: andg.github.io, assets:https://s3.amazonaws.com/3400}
andg
SOT-223 - Salvaje
Posts: 144
Joined: Thu Apr 18, 2013 3:21 am
Location: Portland OREGON
Contact:

Re: json, CAN

Post by andg »

Code: Select all

show dbs
sensors	0.203125GB
local  0.314223GB
In this example there is a replicated collection that multiple members add their sensor data to a document

Code: Select all

rs.status()
db.runCommand( { replSetGetStatus: 1 } )
get status of replication
Oplog equivalent to transaction log. Used for replication. Capped collection on primary member
Last edited by andg on Fri May 03, 2013 1:59 am, edited 5 times in total.

Code: Select all

{url: andrewgauger.com, skype: andrgaug, email: andg@andrewgauger.com, car: 25, fb: facebook.com/DonatoArrighi, github: andg.github.io, assets:https://s3.amazonaws.com/3400}
andg
SOT-223 - Salvaje
Posts: 144
Joined: Thu Apr 18, 2013 3:21 am
Location: Portland OREGON
Contact:

Re: json, CAN

Post by andg »

so lets let the sequential fuel injection go for a moment by profiding a tach signal over the same networked interfeace. they determine when the right time the ought to fire and be able to switch back and forth between different bodes my overwriting oop driven classes.

Code: Select all

{url: andrewgauger.com, skype: andrgaug, email: andg@andrewgauger.com, car: 25, fb: facebook.com/DonatoArrighi, github: andg.github.io, assets:https://s3.amazonaws.com/3400}
User avatar
Fred
Moderator
Posts: 15431
Joined: Tue Jan 15, 2008 2:31 pm
Location: Home sweet home!
Contact:

Re: json, CAN

Post by Fred »

You were just trying to up your package type to BGA-208, weren't you!!?? I did you a favour and customised it for you :-)

http://stuff.fredcooke.com/AndyGHalfPos ... rnight.png
DIYEFI.org - where Open Source means Open Source, and Free means Freedom
FreeEMS.org - the open source engine management system
FreeEMS dev diary and its comments thread and my turbo truck!
n00bs, do NOT PM or email tech questions! Use the forum!
The ever growing list of FreeEMS success stories!
Post Reply