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
Compare Revisions
e1e8ab40b6c7fdfa5d1628fbcc067c907f676ee3...7a7face29165cc7668386edf869011c2a3d6eb4c
Commits (2)
bug fixes
· 132ea374
vladislav
authored
Mar 31, 2020
132ea374
appkey added
· 7a7face2
vladislav
authored
Apr 16, 2020
7a7face2
Hide whitespace changes
Inline
Side-by-side
gateway_protocol/gateway_protocol.c
View file @
7a7face2
#include <gateway_protocol/gateway_protocol.h>
#define GATEWAY_PROTOCOL_APP_KEY_SIZE 8
static
uint8_t
app_key
[
GATEWAY_PROTOCOL_APP_KEY_SIZE
];
static
uint8_t
dev_id
=
0xFF
;
void
gateway_protocol_init
(
const
uint8_t
*
appkey
,
const
uint8_t
devid
)
{
memcpy
(
app_key
,
appkey
,
GATEWAY_PROTOCOL_APP_KEY_SIZE
);
dev_id
=
devid
;
}
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
,
...
...
@@ -11,18 +19,23 @@ void gateway_protocol_packet_encode (
{
*
packet_length
=
0
;
memcpy
(
&
packet
[
*
packet_length
],
app_key
,
GATEWAY_PROTOCOL_APP_KEY_SIZE
);
(
*
packet_length
)
+=
GATEWAY_PROTOCOL_APP_KEY_SIZE
;
packet
[
*
packet_length
]
=
dev_id
;
packet_length
++
;
(
*
packet_length
)
++
;
packet
[
*
packet_length
]
=
packet_type
;
(
*
packet_length
)
++
;
packet
[
*
packet_length
]
=
payload_length
;
(
*
packet_length
)
++
;
memcpy
(
&
packet
[
*
packet_length
],
payload
,
payload_length
);
*
packet_length
+=
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
,
...
...
@@ -30,17 +43,25 @@ uint8_t gateway_protocol_packet_decode (
const
uint8_t
*
packet
)
{
uint8_t
p_len
=
0
;
uint8_t
appkey
[
GATEWAY_PROTOCOL_APP_KEY_SIZE
];
uint8_t
dev
;
*
dev_id
=
packet
[
p_len
];
memcpy
(
appkey
,
&
packet
[
p_len
],
GATEWAY_PROTOCOL_APP_KEY_SIZE
);
p_len
+=
GATEWAY_PROTOCOL_APP_KEY_SIZE
;
dev
=
packet
[
p_len
];
p_len
++
;
*
packet_type
=
(
gateway_protocol_packet_type_t
)
packet
[
p_len
];
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
);
return
(
memcmp
(
appkey
,
app_key
,
GATEWAY_PROTOCOL_APP_KEY_SIZE
)
&&
dev
==
dev_id
&&
p_len
==
packet_length
);
}
\ No newline at end of file
gateway_protocol/gateway_protocol.h
View file @
7a7face2
...
...
@@ -26,8 +26,9 @@ typedef enum {
GATEWAY_PROTOCOL_STAT_NACK
=
0xFF
}
gateway_protocol_stat_t
;
void
gateway_protocol_init
(
const
uint8_t
*
appkey
,
const
uint8_t
devid
);
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
,
...
...
@@ -35,7 +36,6 @@ void gateway_protocol_packet_encode (
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
,
...
...