Skip to content
GitLab
Menu
Projects
Groups
Snippets
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
Menu
Open sidebar
Vladislav Rykov
gateway_protocol
Commits
3d9709f8
Commit
3d9709f8
authored
Mar 25, 2020
by
vladislav
Browse files
Initial commit
parents
Changes
2
Hide whitespace changes
Inline
Side-by-side
gateway_protocol/gateway_protocol.c
0 → 100644
View file @
3d9709f8
#include <gateway_protocol.h>
void
gateway_protocol_packet_encode
(
const
uint8_t
dev_id
,
const
gateway_protocol_packet_type_t
packet_type
,
const
uint8_t
payload_length
,
const
uint8_t
*
payload
,
uint8_t
*
packet_length
,
uint8_t
*
packet
)
{
*
packet_length
=
0
;
packet
[
*
packet_length
]
=
dev_id
;
packet_length
++
;
packet
[
*
packet_length
]
=
packet_type
;
(
*
packet_length
)
++
;
memcpy
(
&
packet
[
*
packet_length
],
payload
,
payload_length
);
*
packet_length
+=
payload_length
;
}
uint8_t
gateway_protocol_packet_decode
(
uint8_t
*
dev_id
,
gateway_protocol_packet_type_t
*
packet_type
,
uint8_t
*
payload_length
,
uint8_t
*
payload
,
const
uint8_t
packet_length
,
const
uint8_t
*
packet
)
{
uint8_t
p_len
=
0
;
*
dev_id
=
packet
[
p_len
];
p_len
++
;
*
packet_type
=
(
gateway_protocol_packet_type_t
)
packet
[
p_len
];
p_len
++
;
*
payload_length
=
packet_length
-
p_len
;
memcpy
(
payload
,
&
packet
[
p_len
],
*
payload_length
);
p_len
+=
*
payload_length
;
return
(
p_len
==
packet_length
);
}
\ No newline at end of file
gateway_protocol/gateway_protocol.h
0 → 100644
View file @
3d9709f8
#ifndef __GATEWAY_PROTOCOL_H__
#define __GATEWAY_PROTOCOL_H__
#include <stdint.h>
#include <string.h>
#define GATEWAY_PROTOCOL_PACKET_SIZE_MAX 128
typedef
enum
{
GATEWAY_PROTOCOL_PACKET_TYPE_DATA_SEND
=
0x00
,
GATEWAY_PROTOCOL_PACKET_TYPE_PEND_REQ
=
0x04
,
GATEWAY_PROTOCOL_PACKET_TYPE_PEND_SEND
=
0x05
,
GATEWAY_PROTOCOL_PACKET_TYPE_STAT
=
0x10
,
GATEWAY_PROTOCOL_PACKET_TYPE_TIME_REQ
=
0x20
,
GATEWAY_PROTOCOL_PACKET_TYPE_TIME_SEND
=
0x21
}
gateway_protocol_packet_type_t
;
typedef
enum
{
GATEWAY_PROTOCOL_STAT_ACK
=
0
,
GATEWAY_PROTOCOL_STAT_ACK_PEND
,
GATEWAY_PROTOCOL_STAT_NACK
=
0xFF
}
gateway_protocol_stat_t
;
void
gateway_protocol_packet_encode
(
const
uint8_t
dev_id
,
const
gateway_protocol_packet_type_t
packet_type
,
const
uint8_t
payload_length
,
const
uint8_t
*
payload
,
uint8_t
*
packet_length
,
uint8_t
*
packet
);
uint8_t
gateway_protocol_packet_decode
(
uint8_t
*
dev_id
,
gateway_protocol_packet_type_t
*
packet_type
,
uint8_t
*
payload_length
,
uint8_t
*
payload
,
const
uint8_t
packet_length
,
const
uint8_t
*
packet
);
#endif // __GATEWAY_PROTOCOL_H__
\ No newline at end of file
Write
Preview
Supports
Markdown
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment