29 #if defined(_USE_WIN_API) 31 #elif defined(_USE_LINUX_API) 32 #include <arpa/inet.h> 91 if (len_data > 0 && data == NULL)
97 packet->
len = len_data;
106 memcpy(packet->
data, data, len_data);
123 if (packet != NULL) {
155 if (packet_send == NULL)
159 if (device->
arg == NULL)
176 hr = device->
dn_send(device->
sock, (
const char *) packet_send->
buf, len_send,
194 int client,
unsigned int retry_nak)
197 unsigned int retry_cnt;
199 uint32_t len_recv, len_recved, len_tmp;
210 if (packet_recv == NULL)
214 if (device->
arg == NULL)
220 for (retry_cnt = 0; retry_cnt <= retry_nak; retry_cnt++) {
223 pos = (
char *) memchr(buf_tmp,
RTK_ENQ, len_recved);
225 if (pos != buf_tmp) {
226 len_recved -= ((long) pos - (
long) buf_tmp);
227 memcpy(buf_tmp, pos, len_recved);
236 hr = device->
dn_recv(device->
sock, &buf_tmp[len_recved],
240 if (client || flag_init) {
253 len_recved += len_tmp;
260 memcpy(buf_tmp, &buf_tmp[1], len_recved);
264 memcpy(packet_recv->
buf, buf_tmp,
265 (len_recv < len_recved) ? len_recv : len_recved);
267 while (len_recv > len_recved) {
269 (
char *) &packet_recv->
buf[len_recved], len_recv - len_recved,
270 &len_tmp, device->
timeout, parg);
281 len_recved += len_tmp;
289 if (crc != crc_recv) {
293 if (retry_cnt == retry_nak)
300 command = packet_recv->
command;
A type definition for the ROBOTalk packet.
#define RTK_CHECK_SEND
A definition for the check_conn_param function.
HRESULT rtk_param2packet(uint16_t command, const uint8_t *data, uint8_t len_data, uint8_t from_id, uint8_t to_id, union RTK_PACKET *packet)
Creates a ROBOTalk packet.
HRESULT(* dn_recv)(int sock, char *buf, uint32_t len_buf, uint32_t *len_recved, uint32_t timeout, void *arg)
#define UDP_MAX_PACKET
The maximum buffer size of a UDP packet.
#define RTK_SIZE_DATA
The data buffer size of a ROBOTalk packet.
A type definition for parameters of udp_send and udp_recv.
#define RTK_SIZE_CRC
The CRC buffer size of a ROBOTalk packet.
#define FAILED(hr)
A macro that returns TRUE/FALSE. If hr is less than zero, then returns TRUE.
#define RTK_CMD_NAK
A definition for the ROBOTalk command which means negative acknowledge.
#define RTK_CHECK_RECV
A definition for the check_conn_param function.
uint16_t rtk_calc_crc(const union RTK_PACKET *packet)
Calculates CRC of the ROBOTalk packet.
#define E_INVALIDARG
Failed because some arguments are invalid.
#define RTK_SIZE_PACKET
The maximum buffer size of a ROBOTalk packet.
_DN_EXP_UDP HRESULT udp_check_sockaddr(const struct sockaddr_in *sock_to, const struct sockaddr_in *sock_from)
Checks the socket address. If sock_to and sock_from are equivalent, then returns S_OK.
#define RTK_SIZE_COMMAND
The command buffer size of a ROBOTalk packet.
#define E_TOO_MUCH_DATA
Failed because the packet is too much.
#define E_INVALIDPACKET
Failed because the packet is invalid.
#define E_OUTOFMEMORY
Failed because there is no enough memory space.
#define RTK_ENQ
A definition for the ROBOTalk enquiry.
static HRESULT rtk_send_nak(const struct CONN_PARAM_COMMON *device, uint8_t from_id, uint8_t to_id)
Sends a NAK packet.
HRESULT rtk_send(const struct CONN_PARAM_COMMON *device, union RTK_PACKET *packet_send)
Sends ROBOTalk packet.
#define SUCCEEDED(hr)
A macro that returns TRUE/FALSE. If hr is zero or more, then returns TRUE.
_DN_EXP_DEVICE void memcpy_be(void *dst, const void *src, uint32_t len)
Orders to big endian.
A type definition for common communication parameters.
uint8_t buf[RTK_SIZE_PACKET]
#define RTK_SIZE_HEADER
The header buffer size of a ROBOTalk packet.
HRESULT rtk_recv(const struct CONN_PARAM_COMMON *device, union RTK_PACKET *packet_recv, int client, unsigned int retry_nak)
Receives ROBOTalk packet.
_DN_EXP_DEVICE HRESULT check_conn_param(const struct CONN_PARAM_COMMON *device, int flag)
Checks the communication parameters.
HRESULT(* dn_send)(int sock, const char *buf, uint32_t len_buf, void *arg)
uint8_t data[RTK_SIZE_DATA]