mesh.h
Go to the documentation of this file.
1 /*
2  * SocialLedge.com - Copyright (C) 2013
3  *
4  * This file is part of free software framework for embedded processors.
5  * You can use it and/or distribute it as long as this copyright header
6  * remains unmodified. The code is free for personal use and requires
7  * permission to use in a commercial product.
8  *
9  * THIS SOFTWARE IS PROVIDED "AS IS". NO WARRANTIES, WHETHER EXPRESS, IMPLIED
10  * OR STATUTORY, INCLUDING, BUT NOT LIMITED TO, IMPLIED WARRANTIES OF
11  * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE APPLY TO THIS SOFTWARE.
12  * I SHALL NOT, IN ANY CIRCUMSTANCES, BE LIABLE FOR SPECIAL, INCIDENTAL, OR
13  * CONSEQUENTIAL DAMAGES, FOR ANY REASON WHATSOEVER.
14  *
15  * You can reach the author of this software at :
16  * p r e e t . w i k i @ g m a i l . c o m
17  */
18 
109 #ifndef MESH_NET_H__
110 #define MESH_NET_H__
111 #ifdef __cplusplus
112 extern "C"
113 {
114 #endif
115 #include "mesh_typedefs.h"
116 
117 
118 
129 bool mesh_init(const uint8_t local_node_id, const bool is_mesh_node, const char *node_name,
130  const mesh_driver_t driver, const bool discovery);
131 
136 bool mesh_set_node_address(const uint8_t local_node_id);
137 uint8_t mesh_get_node_address(void);
138 
150 void mesh_set_retry_count(const uint8_t count);
151 
157 void mesh_service(void);
158 
179 bool mesh_send(const uint8_t dst, const mesh_protocol_t type,
180  const void* pData, const uint8_t len,
181  const uint8_t hop_count_max);
182 
214 bool mesh_form_pkt(mesh_packet_t *pkt, const uint8_t dst,
215  const mesh_protocol_t type, const uint8_t hop_count_max,
216  uint8_t num_ptrs, ...);
217 
222 bool mesh_send_formed_pkt(mesh_packet_t *pkt);
223 
241 bool mesh_deform_pkt(mesh_packet_t *pkt, uint8_t num_ptrs, ...);
242 
243 
250 static inline bool mesh_is_ack_required(const mesh_packet_t* pPacket)
251 {
252  return (mesh_pkt_ack_app == pPacket->info.pkt_type);
253 }
254 
261 static inline bool mesh_is_ack_ok(const mesh_packet_t* pRxPkt, const uint8_t sentDstAddr)
262 {
263  return (mesh_pkt_ack_rsp == pRxPkt->info.pkt_type && pRxPkt->nwk.src == sentDstAddr);
264 }
265 
272 static inline bool mesh_send_ack(char* pData, uint8_t len, const mesh_packet_t* p_orig_pkt)
273 {
274  /* Response needs to be NACK otherwise loop of ACKs will occur */
275  return mesh_send(p_orig_pkt->nwk.src, mesh_pkt_ack_rsp, pData, len, p_orig_pkt->info.hop_count_max);
276 }
277 
284 const mesh_rte_table_t* mesh_get_routing_entry(const uint8_t route_num);
285 
289 uint8_t mesh_get_num_routing_entries(void);
290 
294 bool mesh_is_route_known(const uint8_t addr);
295 
303 uint8_t mesh_get_pnd_pkt_count(void);
304 
312 uint32_t mesh_get_expected_ack_time(uint8_t node_addr);
313 
318 uint32_t mesh_get_max_timeout_before_packet_fails(uint8_t node_addr);
319 
332 void mesh_reset_error_mask(void);
333 
335 #if MESH_USE_STATISTICS
336 
339 mesh_stats_t mesh_get_stats(void);
340 #endif
341 
342 
343 
344 #ifdef __cplusplus
345 }
346 #endif
347 #endif /* MESH_NET_H__ */
uint8_t mesh_get_pnd_pkt_count(void)
Definition: mesh.c:1125
Response packet of an ACK.
Definition: mesh_typedefs.h:90
Routing table type.
Definition: mesh_typedefs.h:60
uint8_t mesh_get_num_routing_entries(void)
Definition: mesh.c:1099
unsigned int unsigned int len
Definition: startup.cpp:197
uint32_t mesh_get_expected_ack_time(uint8_t node_addr)
Definition: mesh.c:1144
void mesh_service(void)
Definition: mesh.c:817
uint8_t mesh_get_node_address(void)
Definition: mesh.c:805
mesh_error_mask_t mesh_get_error_mask(void)
Definition: mesh.c:1167
Mesh type defines.
void mesh_set_retry_count(const uint8_t count)
Definition: mesh.c:810
bool mesh_send(const uint8_t dst, const mesh_protocol_t type, const void *pData, const uint8_t len, const uint8_t hop_count_max)
Definition: mesh.c:928
Application is required to ACK ASAP.
Definition: mesh_typedefs.h:89
mesh_error_mask_t
Mesh error types.
Definition: mesh_typedefs.h:94
void mesh_reset_error_mask(void)
Resets the error mask to zero.
Definition: mesh.c:1172
bool mesh_form_pkt(mesh_packet_t *pkt, const uint8_t dst, const mesh_protocol_t type, const uint8_t hop_count_max, uint8_t num_ptrs,...)
Definition: mesh.c:952
bool mesh_set_node_address(const uint8_t local_node_id)
Definition: mesh.c:795
uint32_t mesh_get_max_timeout_before_packet_fails(uint8_t node_addr)
Definition: mesh.c:1152
bool mesh_send_formed_pkt(mesh_packet_t *pkt)
Definition: mesh.c:1053
bool mesh_init(const uint8_t local_node_id, const bool is_mesh_node, const char *node_name, const mesh_driver_t driver, const bool discovery)
Definition: mesh.c:745
mesh_protocol_t
Mesh packet type.
Definition: mesh_typedefs.h:86
const mesh_rte_table_t * mesh_get_routing_entry(const uint8_t route_num)
Definition: mesh.c:1080
mesh_stats_t mesh_get_stats(void)
Definition: mesh.c:1161
bool mesh_deform_pkt(mesh_packet_t *pkt, uint8_t num_ptrs,...)
Definition: mesh.c:1027
Definition: mesh_typedefs.h:50
bool mesh_is_route_known(const uint8_t addr)
Definition: mesh.c:1112