Repository navigation
Expand file tree
/
Copy pathcommand.c
More file actions
60 lines (48 loc) · 1.42 KB
/
Copy pathcommand.c
File metadata and controls
60 lines (48 loc) · 1.42 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
/*
* Copyright 2022 Morse Micro
*/
#include <errno.h>
#include <stdlib.h>
#include <string.h>
#include <stdio.h>
#include <stdint.h>
#include "portable_endian.h"
#include "utilities.h"
#include "command.h"
#define MORSECTRL_CMD_REQ_FLAG (BIT(0))
int morsectrl_send_command(struct morsectrl_transport *transport,
int message_id,
struct morsectrl_transport_buff *cmd,
struct morsectrl_transport_buff *resp)
{
int ret = 0;
struct command *command;
struct response *response;
if (!cmd || !resp)
{
ret = -ENOMEM;
goto exit;
}
command = (struct command *)cmd->data;
memset(&command->hdr, 0, sizeof(command->hdr));
command->hdr.message_id = htole16(message_id);
command->hdr.len = htole16(cmd->data_len - sizeof(struct command));
command->hdr.flags = MORSECTRL_CMD_REQ_FLAG;
response = (struct response *)resp->data;
ret = morsectrl_transport_send(transport, cmd, resp);
if (ret < 0)
{
if (transport && transport->debug)
mctrl_err("message failed %d\n", ret);
goto exit;
}
ret = le32toh(response->status);
if (ret)
{
if (transport && transport->debug && (ret != 110))
mctrl_err("Command failed\n");
goto exit;
}
exit:
return ret;
} // NOLINT - checkstyle.py seems to think this brace is in the wrong place.