pythontimestampsensorspoint-cloudslidar

Issue with obtaining accurate timestamp for scan data in current date and time in LMS511 and LMS111 sensors


I need to obtain a timestamp for every scan data with the current date and time. However, I am facing some issues with getting the correct time and date values.

I have made changes to the current time in sopas engineering tool, the obtained data still shows the wrong time and date.

I suspect that there might be an error in how I am converting the timestamp. Could someone please guide me on the correct way to obtain and convert the timestamp for accurate time and date representation?

This is the data that i get from the lms111 sensor

sRA LMDscandata 1 1 1195F7E 0 0 5DD8 5DDB BB7E993F BB7EF691 0 0 FF 7 0 1388 168 0 1 DIST1 3F800000 00000000 AAE60 1388 51 515 502 4FC 501 50F 4F0 4F7 501 4E1 4EA 4EC 4F3 4D2 4D7 4E4 4D2 4CD 4CF 4E1 4C5 4D4 4D7 4D5 4D9 4D0 4CD 4D3 4D3 4C8 4C5 4C8 4D5 4D3 4C6 4C6 4C0 4C8 4C1 4CD 4CE 4C9 4CA 4D4 4C8 4C8 4D4 4CE 4C4 4D1 4CA 4C4 4C3 4CF 4DC 4D8 4C3 4D2 4C5 4C8 4D3 4CD 4CB 4CE 4DB 4E8 4E8 4DB 4EB 4EE 4EC 4F4 4E3 4EF 4F1 4F6 510 4FD 4FE 503 508 508 0 0 1 3 SL2 0 1 7B2 1 1 0 34 19 6AB08 0

The bold numbers that i convert into timestamp


def hex_to_date(hex_value):
    try:
        hex_value = hex_value.replace("0x", "")
        decimal_value = int(hex_value, 16)
        timestamp = datetime.datetime.fromtimestamp(decimal_value)
        return timestamp.strftime("%Y-%m-%d %H:%M:%S")
    except ValueError:
        return "Invalid hexadecimal value"

   hex_value = "BB7EF691"
   date = hex_to_date(hex_value)
   print(date)```

This is the answer that i got 2069-09-06 02:27:29.
But expected answer is the current date and time.


Any help or suggestions would be greatly appreciated. Thank you!



Solution

  • As Anentropic already pointed out, these are not the timestamps you're looking for. Let me instead explain how to get the proper one.

    Recall from my previous answer on parsing the measurement telegrams that after the fixed header, there is a number of of optional sections. We dealt with one of them that contains measured distances. The real timestamp has a separate section (the second last):

    # of encoder blocks         0
    [<encoder info>]
    # of 16-bit channel blocks  1
    [<channel blocks>]
    # of 8-bit channel blocks   0
    [<channel blocks>]
    Position                    0
    [<position info>]
    Device name                 0
    [<name text>]
    Comment                     0
    [<comment text>]
    Time                        0     <----- Here
    [<timestamp>]
    Events                      0 
    [<event info>]
    

    The layout of this part of the telegram is documented in Telegram Listing reference, on page 109:

    Note that this section is optional, and you have to configure the sensor to include it in the measurement telegrams. In your case, it is not enabled (hence the 0 in the first field, and the rest omitted).


    The configuration of the contents of the measurement telegrams is accomplished via the LMDscandatacfg telegram (Telegram Listing, section 4.3.1, pages 80-82). The specific field you're looking for is the second last one:

    When this field is set to 1, the measurement telegrams will contain the timestamp section.

    You should be able to set this up in SOPAS as well, and save it to non-volatile memory, but for practical purposes, I found it useful to send this telegram every time I connect to the sensor (thus making sure it's always configured the way I want, without needing to rely on other software).


    Finally, you need to be able to set the sensor's clock in order for the timestamps to have a useful value. This can be accomplished using the LSPsetdatetime telegram (Telegram Listing, section 4.4.1, pages 122-123). The documentation contains the following important notice:

    Attention: There is no real time clock inside the device. When the scanner is switched off and after a reboot, the time has to be set again.

    This means that this is yet another configuration telegram to send every time you establish a new connection with the sensor.