The online racing simulator
Searching in All forums
(5 results)
Hidra Julika
S3 licensed
Yes, I deleted all the buffer.flip lines.
I tried yours, it works too.

Quote : The way I see it the current core ignores the possibility of an OutGauge packet with no ID which is only 92 bytes long.

Yes, you are right I think.

It misses the OR relation, that OutSim's IF ELSE has.

else if (buffer.position() == OUT_SIM_SIZE || buffer.position() == OUT_SIM_SIZE - 4)

Hidra Julika
S3 licensed
Maybe you misunderstand me.
The solution that i was posted works for me.
I think yours works too.
Maybe instead buffer.position(0) is better buffer.clear.

But the problem is buffer.flip I think. I dont really see the point of buffer.flip in the original code. As far I know it sets the new limit to the current position, and then sets position to zero.

The problem is with the original, that buffer.flips sets buffer limit to 68 (since OutSim package comes first) thats why the new buffer size becomes 68 bytes.

So, there will be never again 96 bytes buffer, because it is capped to 68 bytes to the rest of eternity. The next flips just "changes" form 68 to 68 again.

So the next OutGauge package fills the newly set 68 bytes buffer (the remaining bytes are ignored) and continues its life as an OutSim package (with completly meaningless data of course).

In other words we cant differ packages by size, if the buffer is set to the size of the smaller package. And that is what OutSim's buffer.flip does.

Am I thinking right?
Last edited by Hidra Julika, .
Hidra Julika
S3 licensed
0.5RC5
Looking at the code, I don't think it could work otherwise, than buggy. But I'm not a veteran programmer, so I might miss something.
The code in question is as follows:


public void run() {
running = true;

ByteBuffer buffer = ByteBuffer.allocateDirect(BUFFER_SIZE);
buffer.order(ByteOrder.LITTLE_ENDIAN);

while (running) {
try {

datagramChannel.receive(buffer);

if (buffer.position() == OUT_GAUGE_SIZE) {
buffer.flip();

OutGaugeResponse reponse = new OutGaugeResponse();
reponse.construct(buffer);
client.notifyListeners(reponse);
buffer.flip();


} else if (buffer.position() == OUT_SIM_SIZE || buffer.position() == OUT_SIM_SIZE - 4) {
buffer.flip();

OutSimResponse response = new OutSimResponse();
response.construct(buffer);
client.notifyListeners(response);
buffer.flip();
}
Thread.sleep(10);
} catch (Exception e) {
log.error("Something went wrong!", e);
}
}
}


Hidra Julika
S3 licensed
Well maybe my above post was not clear enough. Lets say, it's becouse I'm not a native speaker, and I was tried.

Nevertheless, I found the solution. I think it's a bug in OutChannel.java.

So the problem is, if both OutSim and OutGauge packages are sent by LFS, jinsim will interpret both as OutSim packages. From the user perspective it makes virtually no OutGauge packages received, and every second OutSim packages contains incorrect values. (This second packages are the OutGauge packages, only jinsim process them as they were OutSim packages.)

My solution was to change the run method of OutChannel.java.
I deleted every buffer.slip(); lines, and inserted buffer.position(0); at the end of the two if section.

I think the problem with the original, that the buffer.flip of the if else section sets the buffer limit to 68 (the last package's size). So after this every buffer.position(); reading will give 68 and will never go into the first if.

I run LFS on a PC, and jinsim on a laptop, that runs Ubuntu and connected via wireless to the PC. Just for the record, but I don't think this is an issue.
Hidra Julika
S3 licensed
I receive OutSim and OutGauge packets , based on the Speedometer example.

I can receive OutGauge packets _or_ OutSim packets very well, everything works. But not at the same time.

If I set...
client.enableOutGauge(1);
client.enableOutOutsim(1);

Monitoring the response I see no OutGauge packets only OutSim recieved. (response.toString)

(If I turn off OutSim, OutGauge packtes come.)

Any ideas what do I do wrong? I tried everything and googled for a day, but nothing moved me further.

Thanks in advance, and respect for the effort, jinsim seems to be a bliss form my motionsim project.
FGED GREDG RDFGDR GSFDG