Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

adding get_query_function #667

Open
wants to merge 6 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions docs/index.md
Original file line number Diff line number Diff line change
Expand Up @@ -205,6 +205,10 @@ Information about header:

- [modbus_get_header_length](modbus_get_header_length.md)

Information about query:

- [modbus_get_query_function](modbus_get_query_function.md)

## Data handling

Macros for data manipulation:
Expand Down
20 changes: 20 additions & 0 deletions docs/modbus_get_query_function.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
# modbus_get_query_function

## Name

modbus_get_query_function- retrieve the function code of a query

## Synopsis

```c
int modbus_get_query_function(modbus_t *ctx, const uint8_t * query);
```

## Description

The *modbus_get_query_function()* function shall retrieve the function code
of a query. It can be useful for modbus server development.

## Return value

The function code of the query.
10 changes: 10 additions & 0 deletions src/modbus.c
Original file line number Diff line number Diff line change
Expand Up @@ -1857,6 +1857,16 @@ int modbus_get_header_length(modbus_t *ctx)
return ctx->backend->header_length;
}

int modbus_get_query_function(modbus_t *ctx, const uint8_t * query)
{
if (ctx == NULL) {
errno = EINVAL;
return -1;
}

return query[ctx->backend->header_length];
}

int modbus_enable_quirks(modbus_t *ctx, unsigned int quirks_mask)
{
if (ctx == NULL) {
Expand Down
1 change: 1 addition & 0 deletions src/modbus.h
Original file line number Diff line number Diff line change
Expand Up @@ -206,6 +206,7 @@ MODBUS_API int
modbus_set_indication_timeout(modbus_t *ctx, uint32_t to_sec, uint32_t to_usec);

MODBUS_API int modbus_get_header_length(modbus_t *ctx);
int modbus_get_query_function(modbus_t *ctx, const uint8_t * req);

MODBUS_API int modbus_connect(modbus_t *ctx);
MODBUS_API void modbus_close(modbus_t *ctx);
Expand Down