Closed hernaangq closed 4 months ago
Hi, what version and option are you using ?
Hello, The client is using 1.4 and server 1.6. what options do you mean?
Sorry, I meant what flag are you using ? RDP, CRC32 for example.
/ WARNING! All changes made to this file will be lost! /
/ #undef CSP_POSIX / / #undef CSP_WINDOWS / / #undef CSP_MACOSX /
/ #undef CSP_LITTLE_ENDIAN /
I am using those in the client side.
Sorry again, I meant thoses flags : https://github.com/libcsp/libcsp/blob/447cc38f2106a15290358dc8c128ad553a415568/examples/csp_client.c#L252
In csp_connect()``
no problem, thanks for taking the time to answer my question.
In the client side:
csp_conn_t * conn = csp_connect(CSP_PRIO_NORM, node, 5, 0, 0);
In the server side:
csp_conn_t *conn;
csp_packet_t *packet;
csp_socket_t *sock = csp_socket(CSP_DEFAULT_CONNECTION_OPTIONS);
if (sock == NULL)
{
debug_printf_safe(ERROR, "CSP SOCKET CREATION ERROR");
}
int error1 = csp_bind(sock, 5);
if (error1 != CSP_ERR_NONE)
{
debug_printf_safe(ERROR, "CSP BIND ERROR");
}
int error2 = csp_listen(sock, CSP_NUM_BACKLOG_QUEUES);
if (error2 != CSP_ERR_NONE)
{
debug_printf_safe(ERROR, "CSP LISTEN ERROR");
}
while (1)
{
conn = csp_accept(sock, 10000);
if (conn == NULL)
{
continue;
}
while ((packet = csp_read(conn, 0)) != NULL)
{
if (packet == NULL)
break;
debug_printf_safe(INFO, "CSP PACKET RECEIVED");
csp_buffer_free(packet);
}
csp_close(conn);
}
this might help, Now I am sending "hello cube" and with a CAN byte reader I am getting the following results:
B9 E8 96 4C
must be the CRC32. See https://crccalc.com/?crc=hello%20cube&method=CRC-32C&datatype=ascii&outtype=0
thank you so much, that was my first thought. I guess csp_read is the function that get rid of this CRC right?
thank you so much, that was my first thought. I guess csp_read is the function that get rid of this CRC right?
In fact CRC is strip on the security check : https://github.com/libcsp/libcsp/blob/v1.4/src/csp_crc32.c#L124 https://github.com/libcsp/libcsp/blob/v1.4/src/csp_route.c#L89C7-L89C23 https://github.com/libcsp/libcsp/blob/v1.4/src/csp_route.c#L129C5-L129C19 It's done when a packet is received on the route.
while (1)
{
conn = csp_accept(sock, 10000);
if (conn == NULL)
{
continue;
}
while ((packet = csp_read(conn, 0)) != NULL)
{
if (packet == NULL)
break;
debug_printf_safe(INFO, "CSP PACKET RECEIVED");
csp_buffer_free(packet);
}
csp_close(conn);
}
So this code should strip de CRC automatically or should I add any code?
while (1) { conn = csp_accept(sock, 10000); if (conn == NULL) { continue; } while ((packet = csp_read(conn, 0)) != NULL) { if (packet == NULL) break; debug_printf_safe(INFO, "CSP PACKET RECEIVED"); csp_buffer_free(packet); } csp_close(conn); }
So this code should strip de CRC automatically or should I add any code?
I'm curious about your client code, if you don't mind ? I think you should use CRC32 option flag to be automatically strip.
/* Prepare data */
csp_packet_t * packet = csp_buffer_get(5);
if (packet == NULL)
return;
/* Open connection */
csp_conn_t * conn = csp_connect(CSP_PRIO_NORM, node, 5, 0, 0);
if (conn == NULL) {
csp_buffer_free(packet);
return;
}
//packet->data[0] = 0x77;
//packet->data[1] = 0x6F;
//packet->data[2] = 0x72;
//packet->data[3] = 0x6c;
//packet->data[4] = 0x64;
packet->data[0] = 0x68;
packet->data[1] = 0x65;
packet->data[2] = 0x6c;
packet->data[3] = 0x6c;
packet->data[4] = 0x6f;
packet->data[5] = 0x20;
packet->data[6] = 0x63;
packet->data[7] = 0x75;
packet->data[8] = 0x62;
packet->data[9] = 0x65;
packet->length = 10;
//printf(" %u.\r\n", packet->data);
printf("Sending: %s\n", (char *)packet->data);
/* Try to send frame */
if (!csp_send(conn, packet, 0))
csp_buffer_free(packet);
csp_close(conn);
Here you have it, how do I add that CRC32 option flag to be automatically strip?
/* Prepare data */ csp_packet_t * packet = csp_buffer_get(5); if (packet == NULL) return; /* Open connection */ csp_conn_t * conn = csp_connect(CSP_PRIO_NORM, node, 5, 0, 0); if (conn == NULL) { csp_buffer_free(packet); return; } //packet->data[0] = 0x77; //packet->data[1] = 0x6F; //packet->data[2] = 0x72; //packet->data[3] = 0x6c; //packet->data[4] = 0x64; packet->data[0] = 0x68; packet->data[1] = 0x65; packet->data[2] = 0x6c; packet->data[3] = 0x6c; packet->data[4] = 0x6f; packet->data[5] = 0x20; packet->data[6] = 0x63; packet->data[7] = 0x75; packet->data[8] = 0x62; packet->data[9] = 0x65; packet->length = 10; //printf(" %u.\r\n", packet->data); printf("Sending: %s\n", (char *)packet->data); /* Try to send frame */ if (!csp_send(conn, packet, 0)) csp_buffer_free(packet); csp_close(conn);
Here you have it, how do I add that CRC32 option flag to be automatically strip?
Use this flag : CSP_O_CRC32
https://github.com/libcsp/libcsp/blob/v1.4/include/csp/csp_types.h#L159
csp_conn_t * conn = csp_connect(CSP_PRIO_NORM, node, 5, 0, CSP_O_CRC32);
@moonlight83340 Thank you so much, that was it.
Good morning,
I am sending CSP messages from a node to another one via CAN and printing them. I can see there are some bits after the message, is this how it is suppose to work? The message I am sending is just the word "hello".