Commit ac54686b authored by 马伊齐's avatar 马伊齐

本地发送接收Demo

parent e404ac1a
......@@ -19,13 +19,14 @@ int main(int argc, char *argv[])
while (fgets(buffer, sizeof(buffer), stdin) != NULL)
{
if (msg_local_send(MSG_CAN_HEARTBEAT, 0, (void *)buffer, strlen(buffer)) == -1)
buffer[strlen(buffer) - 1] = '\0';
if (msg_local_send(MSG_CAN_OD, 0, (void *)buffer, (strlen(buffer) + 1)) == -1)
{
destroy_msg_queue();
exit(EXIT_FAILURE);
}
// 清空buffer
memset(buffer, 0, sizeof(buffer));
memset(buffer, 0, BUFFER_SIZE);
}
// 清理消息队列
......
......@@ -17,6 +17,8 @@ int main(int argc, char *argv[])
exit(EXIT_FAILURE);
}
printf("Server is running...\n");
while (1)
{
if (msg_local_recv(&msg) > 0)
......@@ -24,9 +26,9 @@ int main(int argc, char *argv[])
printf("Received code: %d\n", msg.code);
printf("Received type: %d\n", msg.type);
printf("Received len: %d\n", msg.len);
printf("Received pad: %s\n", (char *)(msg.pad));
printf("Received pad: %s\n\n", (char *)(msg.pad));
// 清空pad
memset(msg.pad, 0, msg.len);
memset(msg.pad, 0, BUFFER_SIZE);
}
else
{
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment