• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Tim Cooke
  • paul wheaton
  • Liutauras Vilda
  • Ron McLeod
Sheriffs:
  • Jeanne Boyarsky
  • Devaka Cooray
  • Paul Clapham
Saloon Keepers:
  • Scott Selikoff
  • Tim Holloway
  • Piet Souris
  • Mikalai Zaikin
  • Frits Walraven
Bartenders:
  • Stephan van Hulst
  • Carey Brown

Get JSON from EXE over stdout

 
Greenhorn
Posts: 2
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi all,

I'm new win Java and I have small problem to get bytes via stdout, and from them create JSON.

Sensor simulator file is .EXE ( https://drive.google.com/open?id=1WZj6vmAfzFysCRUYgymqqueh-wt-1cue )

Problem is next:
The simulator can be spawned with a --name argument. If no name is given, a random name will be generated.
I can have a few .EXE files and over stdout and mapping bytes I need to write JSON in log file.

JSON should have this format:


Sensor data format
The sensor data is a binary format. Each reading will be packaged with the length of the packet, a
timestamp, a name of the sensor, and the available sensor readings. Strings are in UTF-8. Numerical
values are in network byte order.

OffsetField nameTypeSizeDescription
0plengthunsigned integer4 bytesThe length of package, including this field
4timestampunsigned integer8 bytesUnix timestamp, in milliseconds
12nlenunsigned integer1 byteThe length of the name
13namestringnlen bytesThe length of the name
13 + nlentemperatureunsigned integer3 bytesIn hundredths of K
16 + nlen (13 +nlen)humidityunsigned integer2 bytesRelative humidity in ‰


Note: Both temperature and humidity are optional. This means that the offset for humidity can
also be 13 + nlen.


I did something like this, but I don't think that I'm on the good way:



I need this ASAP, so please help me to solve, also to understand

Thank you!
 
Sheriff
Posts: 28344
97
Eclipse IDE Firefox Browser MySQL Database
  • Likes 2
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
No, if you don't have to use Runtime.exec() then I strongly recommend not to use it.

Why can't you just run your sensor-simulator at the command line and pipe the output into this Java program you want to write? Something like:

cd \resources
sensor_simulator_01.exe | java ConvertSensorDataToJson

 
Alex Serbia
Greenhorn
Posts: 2
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Paul Clapham wrote:No, if you don't have to use Runtime.exec() then I strongly recommend not to use it.

Why can't you just run your sensor-simulator at the command line and pipe the output into this Java program you want to write? Something like:

cd \resources
sensor_simulator_01.exe | java ConvertSensorDataToJson



Thank you on your answer, but I'm not familiar with this command type... :(

Questions:
1) ConvertSensorDataToJson - this is Main class?
2) "sensor_simulator_01.exe | java ConvertSensorDataToJson" or "java ConvertSensorDataToJson | sensor_simulator_01"?

Can someone provide me a some code? To learn on first place...than to solve my task for school.
 
Paul Clapham
Sheriff
Posts: 28344
97
Eclipse IDE Firefox Browser MySQL Database
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Alex Serbia wrote:1) ConvertSensorDataToJson - this is Main class?


Yes, it's the class you're going to write to convert the sensor data to Json.

2) "sensor_simulator_01.exe | java ConvertSensorDataToJson" or "java ConvertSensorDataToJson | sensor_simulator_01"?


Yes, the pipes work from left to right. Example tutorial: Command Redirection, Pipes.

Can someone provide me a some code? To learn on first place...than to solve my task for school.


I don't know what you have in mind  Nobody here is going to write your code for you. But if you like, you could start working on it and ask questions when you get stuck.
 
Politics n. Poly "many" + ticks "blood sucking insects". Tiny ad:
Gift giving made easy with the permaculture playing cards
https://coderanch.com/t/777758/Gift-giving-easy-permaculture-playing
reply
    Bookmark Topic Watch Topic
  • New Topic