27 #if defined(_USE_WIN_API) 30 #pragma comment(lib, "wsock32.lib") 31 #elif defined(_USE_LINUX_API) 32 #include <arpa/inet.h> 34 #include <sys/ioctl.h> 57 #define _TP_CMD_SPECIAL (0x0FFF) 64 #define _TIMER_INTERVAL (10) 71 #define _TPERROR_TIMEOUT (10000) 78 #define _TPLESS_INTERVAL (10000) 85 #define _PING_INTERVAL_CONNECT (300) 92 #define _PING_INTERVAL_TPERROR (1000) 99 #define _TP_INIT_WAIT_CLIENT (100) 106 #define _TP_INIT_WAIT_SERVER (3000) 207 if (len_data ==
sizeof(
int)) {
259 if(func.Call_TPDefault != NULL) {
260 hr = func.Call_TPDefault(command, data, len_data);
294 device = &tp_param->
device;
297 tp_param->
to_id, &packet);
324 unsigned int retry_cnt;
330 device = &tp_param->
device;
332 for (retry_cnt = 0; retry_cnt <= retry_nak; retry_cnt++) {
359 if (retry_cnt == retry_nak) {
364 *len_data = packet.
len;
365 if (packet.
len > 0) {
366 memcpy(data, packet.
data, packet.
len);
398 unsigned int retry_cnt;
403 if (tp_param == NULL)
414 for (retry_cnt = 0; retry_cnt <= retry_timeout; retry_cnt++) {
421 hr =
tp_send(tp_param, command_send, data_send, len_send);
454 int resp = 1, tmp_state = tp_param->
flags.
state;
515 packet_send.
len =
sizeof(int);
555 *(
int *) packet_send.
data = tmp_state;
761 if (connect == NULL || pfd == NULL)
769 device = &tp_param->
device;
773 switch (device->
type) {
776 conn_param = ð_param;
785 device->
arg = (
void *) paddr;
795 conn_param = &com_param;
810 if (device->
arg != NULL) {
821 if (device->
arg != NULL) {
832 if (device->
arg != NULL) {
841 sock = &device->
sock;
842 hr = device->
dn_open(conn_param, sock);
846 if (device->
arg != NULL) {
897 if (tp_param == NULL)
900 device = &tp_param->
device;
901 sock = &device->
sock;
921 if (device->
arg != NULL) {
943 if (tp_param == NULL)
946 device = &tp_param->
device;
947 sock = &device->
sock;
972 if (tp_param == NULL)
978 device = &tp_param->
device;
990 if (tp_param == NULL)
1065 uint32_t ulPosCmd, ulNumCmd, ulNumPar, ulPosPar, ulPosSub, ulNumSub, ulLenStr,
1068 VARIANT *vntCmd, vntPar[2], vntSub[5];
1071 memset(vntPar, 0,
sizeof(vntPar));
1072 memset(vntSub, 0,
sizeof(vntSub));
1081 for (ulPosCmd = 0; ulPosCmd < ulNumCmd; ulPosCmd++) {
1082 if (!(vntCmd[ulPosCmd].vt &
VT_ARRAY)) {
1087 for (ulPosPar = 0; ulPosPar < 2; ulPosPar++) {
1091 for (ulPosSub = 0; ulPosSub < 5; ulPosSub++) {
1105 switch (vntPar[0].bVal) {
1109 if (248 < len_data + 3) {
1118 data[len_data] = vntPar[0].
bVal;
1119 data[len_data + 1] = 0x1;
1120 data[len_data + 2] = vntPar[1].
bVal;
1131 for (ulPosSub = 0; ulPosSub < 5; ulPosSub++) {
1139 ulLenCmd = ulLenStr * 2 + 5;
1141 if (248 < (len_data + ulLenCmd + 2)) {
1146 data[len_data] = vntPar[0].
bVal;
1147 data[len_data + 1] = (
uint8_t) ulLenCmd;
1148 data[len_data + 2] = vntSub[1].
bVal;
1149 data[len_data + 3] = vntSub[2].
bVal;
1150 data[len_data + 4] = vntSub[3].
bVal;
1151 data[len_data + 5] = (
uint8_t) ulLenStr;
1152 wcstombs((
char*) &data[len_data + 6], vntSub[0].bstrVal, ulLenStr);
1153 data[len_data + ulLenStr + 6] =
'\0';
1154 memset(&data[len_data + ulLenStr + 7], vntSub[4].bVal, ulLenStr);
1155 len_data += (
uint8_t) (ulLenCmd + 2);
1166 if (248 < len_data + 6) {
1171 data[len_data] = vntPar[0].
bVal;
1172 data[len_data + 1] = 0x04;
1173 memcpy(&data[len_data + 2], chSub, 4);
1191 for (ulPosPar = 0; ulPosPar < 2; ulPosPar++) {
1195 for (ulPosSub = 0; ulPosSub < 5; ulPosSub++) {
1208 VARIANT vntCmd, *vntPar, *vntSub1, *vntSub2;
1221 bData[1] = color_fg;
1229 bData[1] = color_bg;
1244 vntSub2[1].
bVal = pos_x;
1246 vntSub2[2].
bVal = pos_y;
1248 vntSub2[3].
bVal = size;
1250 vntSub2[4].
bVal = attr;
1269 VARIANT vntCmd, *vntPar, *vntSub1;
1282 bData[1] = color_fg;
1316 VARIANT vntCmd, *vntPar, *vntSub1;
1329 bData[1] = color_fg;
1337 bData[1] = color_bg;
HRESULT TPComm_DrawString(int fd, BSTR bstr, uint8_t pos_x, uint8_t pos_y, uint8_t size, uint8_t attr, uint8_t color_fg, uint8_t color_bg)
Draws a string to Mini TP.
#define TP_CONN_MAX
A definition for the maximum count of TP connections.
#define S_FALSE
Succeeded but some processes may remain.
HRESULT TPComm_Open(const char *connect, uint32_t timeout, int client, int *pfd)
Starts TP communication.
_DN_EXP_ROBOTALK 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.
static struct CALL_FUNC_TP m_call_func
#define _TPLESS_INTERVAL
A definition for the interval of the TP less event.
_DN_EXP_THREAD HRESULT wait_event(EVENT *pevt, uint32_t timeout)
Waits a event.
_DN_EXP_THREAD HRESULT unlock_mutex(MUTEX *pmutex)
Unlocks mutex handle.
#define RTK_RETRY_COUNT
A definition for the ROBOTalk command. The upper 3bits mean the retry count.
A type definition for the ROBOTalk packet.
HRESULT TPComm_Close(int *pfd)
Ends TP communication.
HRESULT(* dn_set_timeout)(int sock, uint32_t timeout)
#define TP_CMD_LCD
A definition for the ROBOTalk command which means requests change LCD.
_DN_EXP_COM HRESULT com_clear(int sock, uint32_t timeout)
Clears the received buffer.
#define TP_CMD_GET_KEYSTATE
A definition for the ROBOTalk command which means requests key state.
static struct CONN_PARAM_TP * check_address(int index)
Checks whether the index has been used or not.
#define COM_BITS_CTS
A definition for CTS flag.
HRESULT TPComm_BEEP(int fd, int16_t time)
TP beeps.
HRESULT(* dn_clear)(int sock, uint32_t timeout)
_DN_EXP_COMMON HRESULT SafeArrayUnaccessData(SAFEARRAY *psa)
Unaccesses the SAFEARRAY.
HRESULT(* dn_recv)(int sock, char *buf, uint32_t len_buf, uint32_t *len_recved, uint32_t timeout, void *arg)
HRESULT TPComm_DrawRectangle(int fd, uint8_t start_x, uint8_t start_y, uint8_t end_x, uint8_t end_y, uint8_t color_fg, uint8_t color_bg)
Draws a rectangle to Mini TP.
#define _TP_INIT_WAIT_SERVER
A definition for the wait time of the initialization when the server mode.
_DN_EXP_COMMON uint32_t ChangeVarType(VARIANT varSrc, uint16_t vt, void *pDest, uint32_t dwSize)
Changes the variant to destination value with the indicated type.
_DN_EXP_THREAD HRESULT lock_mutex(MUTEX *pmutex, uint32_t timeout)
Locks mutex handle.
#define TP_CMD_LED_ON
A definition for the ROBOTalk command which means requests LED on.
_DN_EXP_THREAD HRESULT create_event(EVENT *pevt, int reset_mode, int init_signal)
Creates a event object.
#define TP_CMD_LED_FLASH
A definition for the ROBOTalk command which means requests LED flash.
_DN_EXP_UDP HRESULT udp_send(int sock, const char *buf, uint32_t len_buf, void *arg)
Sends UDP packet.
HRESULT(* Call_TPState)(int state)
#define TP_CMD_LED_OFF
A definition for the ROBOTalk command which means requests LED off.
_DN_EXP_UDP HRESULT udp_clear(int sock, uint32_t timeout)
Clears the received buffer.
#define _TIMER_INTERVAL
A definition for the interval of the timer event.
_DN_EXP_COM HRESULT com_get_modem_state(int sock, uint32_t *state)
Gets the serial port pin status.
#define _TP_INIT_WAIT_CLIENT
A definition for the wait time of the initialization when the client mode.
Thread and mutex API file.
struct CONN_PARAM_COMMON device
#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.
_DN_EXP_COM HRESULT com_open(void *param, int *sock)
Opens serial port.
#define TP_CMD_TOUTCHINFO
A definition for the ROBOTalk command which means requests or raised touch event. ...
HRESULT TPComm_LED(int fd, int16_t number, int16_t state)
Changes TP LED.
static uint32_t htonl(uint32_t hostlong)
#define E_HANDLE
Failed because the handle is invalid.
#define calc_time_diff(start, end)
A macro that calculates the time difference between start and end.
_DN_EXP_UDP HRESULT udp_set_timeout(int sock, uint32_t timeout)
Sets timeout value to the UDP socket.
#define E_ACCESSDENIED
Failed because the resource is not ready.
#define TP_CMD_KEYINFO
A definition for the ROBOTalk command which means requests or raised key event.
#define E_INVALIDARG
Failed because some arguments are invalid.
HRESULT(* dn_close)(int *sock)
volatile uint8_t timer_flag
HRESULT TPComm_DrawLine(int fd, uint8_t start_x, uint8_t start_y, uint8_t end_x, uint8_t end_y, uint8_t color_fg)
Draws a line to Mini TP.
Callback functions of TP event.
_DN_EXP_COM HRESULT com_set_timeout(int sock, uint32_t timeout)
Sets timeout value to the serial socket.
_DN_EXP_DEVICE HRESULT parse_conn_param_serial(const char *opt, struct CONN_PARAM_COM *param)
Parses serial connection parameters.
static int find_open_address()
Returns the open address of m_conn_param.
static HRESULT tp_callfunc(uint16_t command, const uint8_t *data, uint8_t len_data)
Execute a callback function with the ROBOTalk command.
_DN_EXP_COM HRESULT com_recv(int sock, char *buf, uint32_t len_buf, uint32_t *len_recved, uint32_t timeout, void *arg)
Receives serial packet.
HRESULT TPComm_DrawMiniTP(int fd, VARIANT commands)
Sends Draw Mini TP commands.
_DN_EXP_UDP HRESULT udp_open(void *param, int *sock)
Opens UDP socket.
#define E_FAIL
Failed because unspecified error occurs.
#define TP_CMD_PING
A definition for the ROBOTalk command which means requests check wire.
#define TP_RETRY_NAK
A definition for the retry count of sending and receiving NAK packet.
_DN_EXP_THREAD HRESULT destroy_event(EVENT *pevt)
Destroys a event object.
union RTK_PACKET last_packet
static uint32_t inet_addr(const char *addr)
#define E_INVALIDPACKET
Failed because the packet is invalid.
_DN_EXP_COM HRESULT com_close(int *sock)
Closes the socket.
#define RTK_CMD_ACK
A definition for the ROBOTalk command which means acknowledge.
#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.
HRESULT TPComm_GetTimeout(int fd, uint32_t *timeout)
Gets timeout.
#define TP_ID_SERVER
A definition for the server ID.
#define _PING_INTERVAL_TPERROR
A definition for the sending interval of the ping packet when TP is error state.
HRESULT TPComm_SetCallFunc(const struct CALL_FUNC_TP *func)
Sets callback functions.
HRESULT TPComm_SetTimeout(int fd, uint32_t timeout)
Sets timeout.
#define NOPARITY
A definition for serial communication setting.
#define TP_CMD_BEEP
A definition for the ROBOTalk command which means requests BEEP.
#define TP_RETRY_TIMEOUT
A definition for the retry count of communication timeout.
_DN_EXP_UDP HRESULT udp_recv(int sock, char *buf, uint32_t len_buf, uint32_t *len_recved, uint32_t timeout, void *arg)
Receives UDP packet.
#define SUCCEEDED(hr)
A macro that returns TRUE/FALSE. If hr is zero or more, then returns TRUE.
#define TP_CMD_MTP_DRAW
A definition for the ROBOTalk command which means requests draw Mini TP.
_DN_EXP_THREAD HRESULT set_event(EVENT *pevt)
Sets a event.
#define RTK_RETRY_FLAG
A definition for the ROBOTalk command. This bit means the retry packet.
A type definition for Ethernet connection parameters.
#define ONESTOPBIT
A definition for serial communication setting.
#define _TP_CMD_SPECIAL
A definition for the ROBOTalk command which means special command.
#define INFINITE
A definition for infinite wait.
_DN_EXP_COMMON void VariantInit(VARIANT *pvarg)
Initializes the VARIANT.
_DN_EXP_DEVICE void memcpy_be(void *dst, const void *src, uint32_t len)
Orders to big endian.
_DN_EXP_COMMON HRESULT VariantChangeType(VARIANT *pvargDest, VARIANT *pvarSrc, uint16_t wFlags, uint16_t vt)
Changes the source variant to destination variant with the indicated type.
static HRESULT receive_execute(struct CONN_PARAM_TP *tp_param)
Receives the ROBOTalk packet and executes callback functions.
A type definition for common communication parameters.
static uint16_t htons(uint16_t hostshort)
_DN_EXP_THREAD uint32_t gettimeofday_msec()
Gets the current time value [ms].
HRESULT(* dn_open)(void *param, int *sock)
_DN_EXP_COM HRESULT com_send(int sock, const char *buf, uint32_t len_buf, void *arg)
Sends serial packet.
HRESULT TPComm_GetTPState(int fd, int *state)
Gets TP state.
#define dn_sleep(n)
A macro that sleeps.
#define E_NOTIMPL
Failed because the function is not implemented.
A type definition for the multi type variable.
_DN_EXP_COMMON BSTR SysAllocString(const wchar_t *sz)
Allocates and returns BSTR.
_DN_EXP_THREAD HRESULT release_mutex(MUTEX *pmutex)
Releases mutex handle.
#define TP_CMD_REQ_ID
A definition for the ROBOTalk command which means requests ID.
_DN_EXP_COMMON void VariantClear(VARIANT *pvarg)
Clears the VARIANT.
#define E_MAX_OBJECT
Failed because the packet is too much.
#define begin_thread(p_thread, function, arg)
A macro that begins thread.
_DN_EXP_DEVICE int parse_conn_type(const char *opt)
Parses and returns the connection type.
static HRESULT tp_recv(struct CONN_PARAM_TP *tp_param, unsigned int retry_nak, uint16_t *command, uint8_t *data, uint8_t *len_data)
SAFEARRAYBOUND rgsabound[1]
A type definition for serial connection parameters.
static THRET THTYPE recv_thread(void *arg)
The receiving thread.
#define _TPERROR_TIMEOUT
A definition for the timeout which is used to raise disconnect event.
static HRESULT timer_event(struct CONN_PARAM_TP *tp_param)
Executes timer event procedure.
static THRET THTYPE timer_thread(void *arg)
The timer thread.
#define exit_thread(thread)
A macro that ends thread.
#define _PING_INTERVAL_CONNECT
A definition for the sending interval of the ping packet when TP connected.
#define NativeCommand(cmd)
A macro that removes the retry flag and count from the ROBOTalk command.
HRESULT TPComm_LCD(int fd, int16_t contrast)
Changes TP LCD.
_DN_EXP_UDP HRESULT udp_close(int *sock)
Closes the socket.
#define E_TIMEOUT
Failed because the communication timed out.
_DN_EXP_ROBOTALK HRESULT rtk_send(const struct CONN_PARAM_COMMON *device, union RTK_PACKET *packet_send)
Sends ROBOTalk packet.
static int connect(SOCKET s, const struct sockaddr *name, int namelen)
HRESULT(* dn_send)(int sock, const char *buf, uint32_t len_buf, void *arg)
_DN_EXP_DEVICE HRESULT parse_conn_param_ether(const char *opt, struct CONN_PARAM_ETH *param)
Parses Ethernet connection parameters.
HRESULT(* Call_TPTouchInfo)(struct TP_TOUCH_INFO touch_info)
_DN_EXP_THREAD HRESULT initialize_mutex(MUTEX *pmutex)
Initializes mutex handle.
static HRESULT tp_send(struct CONN_PARAM_TP *tp_param, uint16_t command, uint8_t *data, uint8_t len_data)
static struct CONN_PARAM_TP m_conn_param[TP_CONN_MAX]
_DN_EXP_THREAD HRESULT reset_event(EVENT *pevt)
Resets a event.
#define RTK_CMD_REJ
A definition for the ROBOTalk command which means reject.
uint8_t data[RTK_SIZE_DATA]
TP communication API file.
_DN_EXP_COMMON SAFEARRAY * SafeArrayCreateVector(uint16_t vt, int32_t lLbound, uint32_t cElements)
Allocates and returns SAFEARRAY.
volatile uint8_t recv_flag
HRESULT(* Call_TPKeyInfo)(struct TP_KEY_INFO key_info)
_DN_EXP_ROBOTALK HRESULT rtk_recv(const struct CONN_PARAM_COMMON *device, union RTK_PACKET *packet_recv, int client, unsigned int retry_nak)
Receives ROBOTalk packet.
static HRESULT send_receive(int index, unsigned int retry_timeout, uint16_t command_send, uint8_t *data_send, uint8_t len_send, uint16_t *command_recv, uint8_t *data_recv, uint8_t *len_recv)
#define TP_ID_CLIENT
A definition for the client ID.
_DN_EXP_COMMON HRESULT SafeArrayAccessData(SAFEARRAY *psa, void **ppvData)
Accesses the SAFEARRAY and gets the pointer of array data.