29 #if defined(_USE_WIN_API) 32 #if defined(_USE_LINUX_API) 33 #include <arpa/inet.h> 42 #define _TIME_DIFFERENCE (25569.0) 48 #define _SEC_ONEDAY (24 * 60 * 60) 83 cnt = ubnd - lbnd + 1;
85 switch (vt ^ VT_ARRAY) {
108 for (i = 0; i < cnt; i++) {
110 if (((
BSTR*) pdata + i) != NULL) {
119 for (i = 0; i < cnt; i++) {
121 if (((
VARIANT*) pdata + i) != NULL) {
178 #if defined(_USE_WIN_API) 198 #if defined(_USE_WIN_API) 230 if (src->
parray != NULL) {
232 switch (vt ^ VT_ARRAY) {
234 if (*offset + argc > len_dst)
236 memcpy(&dst[*offset], parray, argc);
259 for (i = 0; i < argc; i++) {
260 if (*offset + size > len_dst)
269 for (i = 0; i < argc; i++) {
271 if (*offset + size > len_dst)
275 memcpy_le(&dst[*offset], &len_bstr, size);
279 for (j = 0; j < len_bstr / size; j++) {
280 if (*offset + size > len_dst)
302 for (i = 0; i < argc; i++) {
303 if (*offset + size > len_dst)
305 memcpy_le(&dst[*offset], (
char *) parray + i * size, size);
364 if (*offset + size > len_dst)
373 if (*offset + size > len_dst)
376 memcpy_le(&dst[*offset], &len_bstr, size);
380 for (i = 0; i < len_bstr / size; i++) {
381 if (*offset + size > len_dst)
394 if (*offset + size > len_dst)
419 uint32_t i, cnt, size, len_vnt, offset_tmp;
423 for (i = 0; i < argc; i++) {
425 offset_tmp = *offset;
432 if (*offset + size > len_dst)
438 if (vnt->
parray != NULL) {
441 cnt = ubnd - lbnd + 1;
450 if (*offset + size > len_dst)
461 memcpy_le(&dst[offset_tmp], &len_vnt, BCAP_SIZE_DATA_LEN);
481 if (src == NULL || dst == NULL)
487 memset(dst, 0, len_dst);
533 void *pdata, *parray;
543 switch (vt ^ VT_ARRAY) {
545 if (*offset + argc > len_src)
547 memcpy(parray, &src[*offset], argc);
570 for (i = 0; i < argc; i++) {
571 if (*offset + size > len_src)
580 for (i = 0; i < argc; i++) {
582 if (*offset + size > len_src)
584 memcpy_le(&len_bstr, &src[*offset], size);
589 if (*((
BSTR*) parray + i) == NULL)
593 for (j = 0; j < len_bstr; j++) {
594 if (*offset + size > len_src)
616 for (i = 0; i < argc; i++) {
617 if (*offset + size > len_src)
619 memcpy_le((
char *) parray + i * size, &src[*offset], size);
677 if (*offset + size > len_src)
686 if (*offset + size > len_src)
688 memcpy_le(&len_bstr, &src[*offset], size);
697 for (i = 0; i < len_bstr; i++) {
698 if (*offset + size > len_src)
711 if (*offset + size > len_src)
739 for (i = 0; i < argc; i++) {
748 if (*offset + size > len_src)
754 if (*offset + size > len_src)
782 if (src == NULL || dst == NULL)
792 if (len_tmp != len_src)
812 memcpy_le(&tmp_argc, &src[offset], size);
816 if (dst->
args != NULL)
818 dst->
argc = tmp_argc;
820 if ((dst->
argc > 0) && (dst->
args == NULL))
822 if (tmp_argc > dst->
argc)
824 dst->
argc = tmp_argc;
828 if (dst->
args == NULL) {
830 if (dst->
args == NULL)
852 if (packet != NULL) {
854 for (i = 0; i < packet->
argc; i++) {
877 for (pos = 0; pos < len_buf; pos++) {
878 crc ^= (buf[pos] << 8);
879 for (cnt = 0; cnt < 8; cnt++) {
881 crc = (crc << 1) ^ 0x1021;
904 char *buf_send = NULL;
913 if (packet_send == NULL)
916 switch (device->
type) {
923 if (device->
arg == NULL)
942 if (len_send > len_max) {
947 buf_send = (
char *) malloc(len_send);
948 if (buf_send == NULL) {
963 hr = device->
dn_send(device->
sock, buf_send, len_send, parg);
968 if (buf_send != NULL) {
987 int opt_tcp, flag_init = 0, flag_crc = 1;
989 uint32_t len_recv, len_recved, len_tmp, len_min, len_max;
1000 if (packet_recv == NULL)
1003 switch (device->
type) {
1011 if (device->
arg == NULL)
1029 pos = (
char *) memchr(buf_tmp,
BCAP_HEADER, len_recved);
1031 if (pos != buf_tmp) {
1033 len_tmp = ((long) pos - (
long) buf_tmp);
1034 device->
dn_recv(device->
sock, buf_tmp, len_tmp, &len_recv,
1037 len_recved -= ((long) pos - (
long) buf_tmp);
1038 memcpy(buf_tmp, pos, len_recved);
1042 device->
dn_recv(device->
sock, buf_tmp, len_recved, &len_recv,
1056 hr = device->
dn_recv(device->
sock, &buf_tmp[len_recved],
1060 if (client || flag_init) {
1063 &opt_udp.
addr) : hr;
1073 len_recved += len_tmp;
1077 if ((len_recv < len_min) || (len_max < len_recv)) {
1083 memcpy(buf_tmp, &buf_tmp[BCAP_POS_LEN], len_recved);
1087 buf_recv = (
char *) malloc(len_recv);
1088 if (buf_recv == NULL) {
1095 device->
dn_recv(device->
sock, buf_recv, len_recv, &len_recved,
1098 memcpy(buf_recv, buf_tmp,
1099 (len_recv < len_recved) ? len_recv : len_recved);
1102 while (len_recv > len_recved) {
1103 hr = device->
dn_recv(device->
sock, &buf_recv[len_recved],
1104 len_recv - len_recved, &len_tmp, device->
timeout, parg);
1109 &opt_udp.
addr) : hr;
1115 len_recved += len_tmp;
1127 flag_crc = (crc == crc_recv);
1136 if (buf_recv != NULL) {
#define BCAP_HEADER
A definition for the b-CAP header.
static HRESULT bcap_bytary2vnt(const char *src, uint32_t len_src, VARIANT *dst, uint32_t argc, uint32_t *offset)
Converts the byte array to a VARIANT value.
struct CONN_PARAM_COMMON device
uint32_t bcap_calc_size_packet(const struct BCAP_PACKET *packet)
Calculates the converted buffer size of the b-CAP packet.
#define BCAP_SIZE_HEADER
A definition for the size of b-CAP header.
HRESULT bcap_send(struct CONN_PARAM_COMMON *device, struct BCAP_PACKET *packet_send)
Sends b-CAP packet.
_DN_EXP_COMMON HRESULT SafeArrayUnaccessData(SAFEARRAY *psa)
Unaccesses the SAFEARRAY.
_DN_EXP_COMMON BSTR SysAllocStringLen(const wchar_t *pch, uint16_t cch)
Allocates and returns BSTR.
HRESULT(* dn_recv)(int sock, char *buf, uint32_t len_buf, uint32_t *len_recved, uint32_t timeout, void *arg)
_DN_EXP_COMMON HRESULT SafeArrayGetLBound(SAFEARRAY *psa, uint16_t nDim, int32_t *plLbound)
Gets the lower bound of SAFEARRAY.
#define BCAP_SIZE_RESERVE
A definition for the size of b-CAP version or retry count.
#define UDP_MAX_PACKET
The maximum buffer size of a UDP packet.
#define BCAP_POS_HEADER
A definition for the buffer position of b-CAP header.
A type definition for parameters of udp_send and udp_recv.
static HRESULT bcap_bytary2vntary(const char *src, uint32_t len_src, VARIANT *dst, uint32_t argc, uint32_t *offset, int flag)
Converts the byte array to a VARIANT array.
static void bcap_bytary2vntdate(const char *src, DATE *dst)
Converts the byte array to a DATE value.
#define BCAP_SIZE_BSTR_BUFFER
A definition for the size of a BSTR character.
#define BCAP_SIZE_VARIANT_NUM
A definition for the size of VARIANT number of elements.
#define BCAP_SIZE_ARGC
A definition for the size of b-CAP number of args.
#define BCAP_SIZE_VARIANT_TYPE
A definition for the size of VARIANT data type.
#define FAILED(hr)
A macro that returns TRUE/FALSE. If hr is less than zero, then returns TRUE.
#define E_INVALIDARG
Failed because some arguments are invalid.
_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 BCAP_SIZE_ID
A definition for the size of b-CAP function ID or return code.
_DN_EXP_COMMON HRESULT SafeArrayGetUBound(SAFEARRAY *psa, uint16_t nDim, int32_t *plUbound)
Gets the upper bound of SAFEARRAY.
#define E_TOO_MUCH_DATA
Failed because the packet is too much.
HRESULT bcap_recv(struct CONN_PARAM_COMMON *device, struct BCAP_PACKET *packet_recv, int client)
Receives b-CAP packet.
#define BCAP_SIZE_MIN
A definition for the minimum buffer size of a b-CAP packet.
static HRESULT bcap_vntary2bytary(const VARIANT *src, uint32_t argc, char *dst, uint32_t len_dst, uint32_t *offset, int flag)
#define E_INVALIDPACKET
Failed because the packet is invalid.
static HRESULT bcap_vnt2bytary(const VARIANT *src, uint32_t argc, char *dst, uint32_t len_dst, uint32_t *offset)
#define _SEC_ONEDAY
A definition for the second of one day.
#define E_OUTOFMEMORY
Failed because there is no enough memory space.
_DN_EXP_COMMON uint16_t SysStringLen(BSTR bstr)
Gets and returns the number of characters of BSTR.
#define BCAP_SIZE_BSTR_LEN
A definition for the size of BSTR string length.
HRESULT bcap_bytary2packet(const char *src, uint32_t len_src, struct BCAP_PACKET *dst)
Converts the byte array to a b-CAP packet.
uint16_t bcap_calc_crc(uint8_t *buf, uint32_t len_buf)
Calculates CRC of the b-CAP packet.
#define SUCCEEDED(hr)
A macro that returns TRUE/FALSE. If hr is zero or more, then returns TRUE.
_DN_EXP_COMMON void VariantInit(VARIANT *pvarg)
Initializes the VARIANT.
A type definition for common communication parameters.
#define BCAP_SIZE_DATA_LEN
A definition for the size of b-CAP argument data length.
#define _TIME_DIFFERENCE
A definition for the time difference between time_t(0) and DATE(0).
_DN_EXP_DEVICE void memcpy_le(void *dst, const void *src, uint32_t len)
Orders to little endian.
A type definition for the multi type variable.
static void bcap_vntdate2bytary(const DATE *src, char *dst)
Converts the DATE value to a byte array.
static uint32_t bcap_calc_size_variant(const VARIANT *vnt)
Calculates the buffer length of the VARIANT.
#define BCAP_TERMINATOR
A definition for the b-CAP terminator.
#define BCAP_SIZE_LEN
A definition for the size of b-CAP message length.
A type definition for the b-CAP packet.
#define BCAP_POS_LEN
A definition for the buffer position of b-CAP message length.
HRESULT bcap_packet2bytary(const struct BCAP_PACKET *src, char *dst, uint32_t len_dst)
Converts the b-CAP packet to a byte array.
#define BCAP_SIZE_CRC
A definition for the size of b-CAP CRC.
#define BCAP_SIZE_CALC_CRC(total_size)
A macro for calculating a b-CAP CRC.
#define BCAP_POS_CRC(total_size)
A macro for calculating the buffer position of b-CAP CRC.
_DN_EXP_DEVICE HRESULT check_conn_param(const struct CONN_PARAM_COMMON *device, int flag)
Checks the communication parameters.
#define BCAP_CHECK_SEND
A definition for the check_conn_param function.
#define BCAP_SIZE_SERIAL
A definition for the size of b-CAP serial number.
HRESULT(* dn_send)(int sock, const char *buf, uint32_t len_buf, void *arg)
#define BCAP_CHECK_RECV
A definition for the check_conn_param function.
_DN_EXP_COMMON SAFEARRAY * SafeArrayCreateVector(uint16_t vt, int32_t lLbound, uint32_t cElements)
Allocates and returns SAFEARRAY.
_DN_EXP_COMMON HRESULT SafeArrayAccessData(SAFEARRAY *psa, void **ppvData)
Accesses the SAFEARRAY and gets the pointer of array data.