0

So I have a poller that polls a device for a response that looks like this:

{"mode":"41","pid":"0C","name":"rpm","value":1817.75}

I have multiple pollers with similar responses. Say, another poller with the following response:

{"mode":"41","pid":"05","name":"temp","value":81}

Each poll takes place in a 500ms interval. I need to log all this data in a certain form.

What happens now?

I have a log that looks like this:

{"data": {"mode":"41","pid":"0C","name":"rpm","value":1817.75}, "time": "someTime" },
{"data": {"mode":"41","pid":"05","name":"temp","value":81}, "time": "someOtherTime" }

What I'm trying to achieve?

A log that looks like this:

{ 
  "data": {
            "rpm": {"mode":"41","pid":"0C","name":"rpm","value":1817.75},
            "temp":{"mode":"41","pid":"05","name":"temp","value":81},
            "time": newTime
          },
 "data": {
            "rpm": {"mode":"41","pid":"0C","name":"rpm","value":1817.75},
            "temp":{"mode":"41","pid":"05","name":"temp","value":81},
            "time": newTime
          },
 "data": {
            "rpm": {"mode":"41","pid":"0C","name":"rpm","value":1817.75},
            "temp":{"mode":"41","pid":"05","name":"temp","value":81},
            "time": newTime
          },
}

I need to construct the object to look like the way I've mentioned. I'm sure there's a simple way to do it. Also, if there's a better way to do it, what would it be?

Arvind
  • 179
  • 2
  • 4
  • 11
  • The way you suggested: "data": { "rpm": {"mode":"41","pid":"0C","name":"rpm","value":1817.75}, "temp":{"mode":"41","pid":"05","name":"temp","value":81}, "time": newTime } is cannot be achieved for 100% correctness. This is because you can't query more data at the same time. So there is always a small time difference. – Eric Smekens Feb 06 '14 at 11:12
  • @EricSmekens Yes I understand that there will be a delay as the data cannot be queried for at the same time. However, since the polling is possible at an interval of 200ms, I was wondering if I could poll for all the data at the minimum cost of time and construct an object together like I've mentioned. I simply couldn't work it out, what I'm trying to do. So, that's where I could use some help. – Arvind Feb 06 '14 at 13:01
  • 1
    http://stackoverflow.com/questions/21334147/send-multiple-obd-commands-together-and-get-response-simultaneously See that link for a way to get queries faster. – Eric Smekens Feb 07 '14 at 07:13

0 Answers0