Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Extended Gator Protocol (M558FS) #5069

Open
wants to merge 28 commits into
base: master
Choose a base branch
from

Conversation

abish7643
Copy link

@abish7643 abish7643 commented Apr 14, 2023

Functionalities Added

  1. RFID Packet Decoding (Tested)
  2. Alarm Packet Decoding (Power Off, SOS Tested)
  3. Engine Start Encoding (Tested)
  4. Engine Stop Decoding (Tested)

Attaching Logs for anyone to do Test Cases

24248000253c0d0733230414195650008307570765682900000000c0470100000c0f0000473000ff710d
2424210005718000d50d
24248000253c0d0733230414195720008307570765682900000000c0470100000c0f0000473600ff060d
2424210005068000a20d
24248000253c0d0733230414195750008307570765682900000000c0470100000c0f0000473a00ff7a0d
24242100057a8000de0d
24248000253c0d0733230414195820008307570765683000000000c0470100000c0f0000473d00ff1b0d
24242100051b8000bf0d
24248000253c0d0733230414195850008307570765682900000000c0470100000c0f0000474000ff0f0d
24242100050f8000ab0d
24248000253c0d0733230414195920008307580765682900000000c0470100000c0f0000474200ff730d
2424210005738000d70d
24248000253c0d0733230414195950008307580765683100000000c0470100000c0f0000474800ff110d
24248000253c0d0733230414200020008307590765683200000000c0470100000c0f0000474b00ff000d
2424210005008000a40d
24248000253c0d0733230414200050008307590765683200000000c0470100000c0f0000474d00ff760d
24248000253c0d0733230414200120008307590765683200000000c0470100000c0f0000475100ff1b0d
24242100051b8000bf0d
24248000253c0d0733230414200135008307590765683200000000c0470000000c0d0000475300ff0f0d
24242100050f8000ab0d
24248200273c0d0733230414200145008307590765683200000000c04700000000000000475300ff0008760d
2424210005768200d00d
24248000253c0d0733230414200149008307590765683200000000c04701000000000000475300ff730d
2424210005738000d70d
24247200203c0d07330242313631394143430d2a4123041420015600830758076568329f0d
24242100059f7200c90d
24247200203c0d07330231394143324630430d2a412304142002010083075807656831c90d
2424210005c972009f0d
24248000253c0d0733230414200219008307580765683200000000c0470100000c0d0000475500ff260d
2424210005268000820d
24248200273c0d0733230414200220008307580765683200000000c0470100000c0d0000475500ff00011e0d
24242100051e8200b80d
24248000253c0d0733230414200249008307580765683200000000c0470100000c0f0000475700ff760d
2424210005768000d20d

Copy link
Member

@tananaev tananaev left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Let's start with some big themes first:

  1. Please add unit tests for both decoding and encoding
  2. Fix formatting. For example, variable use our variable name convention. No underscores. Lower camel case names for functions and variables. No shortened words.
  3. Run gradle check to make sure all checks pass.

@abish7643
Copy link
Author

abish7643 commented Apr 14, 2023

Let's start with some big themes first:

1. Please add unit tests for both decoding and encoding

2. Fix formatting. For example, variable use our variable name convention. No underscores. Lower camel case names for functions and variables. No shortened words.

3. Run gradle check to make sure all checks pass.

I'll do all of this in the upcoming days.

@abish7643
Copy link
Author

abish7643 commented Apr 15, 2023

Added new commit.

Gradle Build ran successfully without any StyleCode errors.

image

@abish7643
Formatting Fixed, Naming Patterns Fixed, Gradle Build Successful

@abish7643 abish7643 changed the title Extended Gator Protocol Extended Gator Protocol (M558FS) Apr 15, 2023
@tananaev
Copy link
Member

OK, can you please add unit tests and provide the protocol documentation.

@abish7643
Copy link
Author

abish7643 commented Apr 17, 2023

OK, can you please add unit tests and provide the protocol documentation.

Attaching Protocol Document. The protocol is exactly same as the one found on Protocol page.
M508A_M508G_M528S_M508S_M558_M558T_M588F_M588FS_tracker_data_protocol.pdf

I'm running the development server locally and using localtonet to forward UDP packets to Gator's predefined port. All functionalities were tested and was working as intended.

@abish7643
Copy link
Author

abish7643 commented Apr 17, 2023

@tananaev

Added Single Location Reporting Encoder Function
Added Encoder and Decoder Tests

debug.xml Outdated Show resolved Hide resolved
return buf;
}

public int[] numToIp(String sim) {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This function doesn't look right. First of all, the naming of the function and variables is not per our standards. Also, it looks too complicated. It just doesn't make sense. What are you trying to do here?

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It's an algorithm mentioned in the Protocol Document. Refer the Appendix section if required.

I have made the variable nomenclature understandable. I copied it from the document, initially even I didn't understand this nomenclature within the document, that's the reason why it ended like this. Now it made sense, so I have modified it.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes. The protocol document also have a complicated decoder function. Somehow this is simplified quite extensively,.

I'll look into this.

Copy link
Author

@abish7643 abish7643 Apr 19, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@abish7643
Copy link
Author

I have made the required changes as you mentioned, I need to test the device tomorrow since I have changed some parts which you suggested.

If there are any modification required, do mention.

@abish7643
Copy link
Author

abish7643 commented Apr 17, 2023

@tananaev

I do need a suggestion. The final one, don't worry.

One of the returned data from the device doesn't contain position data, so the last position known data is used. (getLastLocation(position, null);)

Should I set the position valid or not, since technically it's the previous location.

image

@tananaev
Copy link
Member

If you use getLastLocation, you shouldn't set any GPS related fields, including validity.

@abish7643
Copy link
Author

Removed That Line. I'll test all the functionalities tomorrow and will update.

@abish7643
Copy link
Author

@tananaev

Works perfect. Tested everything.
You could check, only a line was removed (setValid).

Copy link
Member

@tananaev tananaev left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think we're almost there. I've added a few smaller comments, mostly around formatting.

}

public int[] idToPseudoIPAddress(String deviceID) {
if (deviceID.length() != 11) {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What is this for?

Copy link
Author

@abish7643 abish7643 Apr 19, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I was about to mention that the gradle build was failing if I don't include that length check.

Definitely the test case failed but I'm not sure why that's the case. May be you could help.

image
image

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

So which message is correct?

Copy link
Author

@abish7643 abish7643 Apr 19, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@tananaev

I have tracked it down, the issue lies in the substring creation block. The device ID should be at least 11 to continue with that logic.

    public int[] idToPseudoIPAddress(String deviceID) {
        if (deviceID.length() != 11) {
            return new int[4];
        }

        int[] ipAddress = new int[4];
        for (int i = 0; i < 4; i++) {
            ipAddress[i] = Integer.parseInt(deviceID.substring(3 + i * 2, 5 + i * 2));
        }

        ipAddress[0] = ipAddress[0] % 0x7f;
        ipAddress[1] = ipAddress[1] % 0x7f;
        ipAddress[2] = ipAddress[2] % 0x7f;
        ipAddress[3] = ipAddress[3] % 0x7f;

        return ipAddress;
    }

According to the protocol document, the device id can be varied in length. The previous developer did assume that the device ID length was 11, that's the reason why the decoder function was simple while my initial encoder function was quite long since I have taken care of the length. Since the decoder creates an ID with a fixed length, there's no point in improving the capability of just the encoder. But to get past Gradle build, I may have to add a conditional check on length there.

So what's your take on this, should I extend the decoder function just like how I initially made the encoder function. Or should I keep it simple like this.

I did configure the tracker with an ID of length 10 rather than 11, and the decoded ID was wrong.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If it's incorrect, then yes, ideally we should fix it.

Comment on lines +117 to +127
String rfidData;
int rfidDataEndIndex = buf.indexOf(buf.readerIndex(), buf.writerIndex(), (byte) 0x0D);
if (rfidDataEndIndex == -1) {
return null;
}

int length = rfidDataEndIndex - buf.readerIndex();
rfidData = buf.readCharSequence(length, Charset.defaultCharset()).toString();
buf.readUnsignedByte();

position.set(Position.KEY_DRIVER_UNIQUE_ID, rfidData);
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why do you need so many variables? Just inline when possible.

Suggested change
String rfidData;
int rfidDataEndIndex = buf.indexOf(buf.readerIndex(), buf.writerIndex(), (byte) 0x0D);
if (rfidDataEndIndex == -1) {
return null;
}
int length = rfidDataEndIndex - buf.readerIndex();
rfidData = buf.readCharSequence(length, Charset.defaultCharset()).toString();
buf.readUnsignedByte();
position.set(Position.KEY_DRIVER_UNIQUE_ID, rfidData);
int rfidEndIndex = buf.indexOf(buf.readerIndex(), buf.writerIndex(), (byte) '\r');
if (rfidEndIndex == -1) {
return null;
}
position.set(
Position.KEY_DRIVER_UNIQUE_ID,
buf.readCharSequence(rfidEndIndex - buf.readerIndex(), ASCII).toString());
buf.readUnsignedByte();

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants