HesaiTechnology / HesaiLidar_General_SDK

Development Kit for PandarXT PandarQT Pandar64 Pandar40P Pandar40M Pandar20A Pandar20B
BSD 2-Clause "Simplified" License
74 stars 36 forks source link

Standby Mode #25

Closed dagata-mining closed 2 years ago

dagata-mining commented 2 years ago

Hi,

I'm trying to put my PANDARXT in standby mode via the API but does not seem to have any command. Any idea on how to do it?

yangfanFred commented 2 years ago

Hi,

I'm trying to put my PANDARXT in standby mode via the API but does not seem to have any command. Any idea on how to do it?

Hi @dagata-mining , does it mean you don't have the HTTP and TCP API manual? Please contact your sales man to get those manuals.

dagata-mining commented 2 years ago

Hi, Just got the TCP API pdf, however it does not seem to have a TCP call to set the operation mode to Standby but just to get the status

dagata-mining commented 2 years ago

Finally, the TCP protocol was not the right version. Got the right one and now is working. So any one struggling with this problem you need to implement a new tcp call in tcp_command_client.c Here's my snipped of code (you'll also need to update the header and implement the)

PTC_ErrCode TcpCommandSetStandby(const void* handle, int on)
{
    if (!handle)
    {
        printf("Bad Parameter!!!\n");
        return PTC_ERROR_BAD_PARAMETER;
    }
    TcpCommandClient *client = (TcpCommandClient *) handle;

    char *buffer;
    if (on == 1)
    {
        buffer[0] = 0;
    }
    else
    {
        buffer[0] = 1;
    }

    TC_Command cmd;
    memset(&cmd, 0, sizeof(TC_Command));
    cmd.header.cmd = 0x1c;
    cmd.header.len = 1;
    cmd.data = strdup(buffer);

    PTC_ErrCode errorCode = tcpCommandClient_SendCmd(client, &cmd);
    if (errorCode != PTC_ERROR_NO_ERROR) {
        free(cmd.data);
        return errorCode;
    }
    free(cmd.data);

    if (cmd.ret_data) {
        // useless data;
        free(cmd.ret_data);
    }

    return cmd.header.ret_code;
}

and also create a new function in the sdk pandarGeneral_sdk.cc

void PandarGeneralSDK::StandBy(bool standBy)
{
    if (!tcp_command_client_)
    {
        return;
    }
    std::cout << "StandBy Mode Called" << std::endl;
    int32_t ret = 0;
    if (standBy)
    {
        ret = TcpCommandSetStandby(tcp_command_client_,0 );
    }
    else
    {
        ret = TcpCommandSetStandby(tcp_command_client_, 1);
    }
    if (ret == 0)
    {
        std::cout << "StandBy Mode Activated" << std::endl;
    }

}
yangfanFred commented 2 years ago

@dagata-mining Great job, thanks for sharing