Cross reference for libutil.c of cxref.

# File libutil.c

## Included Files

- `#include <stdio.h>`

- `#include <netinet/in.h>`

- `#include <unistd.h>`

- `#include <sys/types.h>`

- `#include <sys/uio.h>`

- `#include <sys/socket.h>`

- `#include <netdb.h>`

- `#include <stdbool.h>`

- `#include <assert.h>`

- `#include <sys/stat.h>`

- `#include <string.h>`

- `#include <err.h>`

- `#include <sys/param.h>`

- `#include "scifTrafMain.h"`
  - `#include "libaccelSensor.h"`
    - `#include <sys/types.h>`
  - `#include "libled.h"`
    - `#include <stdbool.h>`
    - `#include <sys/types.h>`
    - `#include "rs485devs.h"`

- `#include "rs485devs.h"`

- `#include "libutil.h"`
  - `#include <sys/time.h>`
  - `#include <sys/uio.h>`
  - `#include <stdbool.h>`
  - `#include "scifTrafMain.h"`

- `#include "/home/tos/cvs/common/include/errcheck.h"`

- `#include "/home/tos/cvs/common/include/trace.h"`

## Global Function get485devShort()

get short data from RS485 device

`u_short get485devShort ( u_char src[sizeof(short)] )`
return decode value

Prototyped in: | libutil.h

## Global Function open_cli_sock()

open client socket.

`int open_cli_sock ( const char* srvName, const char* srvPort )`

`const char* srvName`
  IP address or server name. IPv6 is effective.
`const char* srvPort`
  server port number or service name(if effective).
  default server port is '6809'.

return socket descriptor.

Prototyped in: | libutil.h
Calls: | __assert13(), close(), connect(), err(), errx(), freeaddrinfo(), gai_strerror(), getaddrinfo(), memset(), perror(), socket()

## Global Function readPacket()

read packet from 'd' to buffer 'iovec' likely readv(2). The different is that data size is decided after read header , and set iovec[PcData].iov_len to 'header.datLen'.

`ssize_t readPacket ( int d, struct iovec iovec[NUM_e_packetCat], _Bool ntohF, _Bool readBlkF )`

`int d`
  descriptor
`struct iovec iovec[NUM_e_packetCat]`
  read buffer vector.
  'iovec[PcData].iov_len' will be set after read(2) header.
`_Bool ntohF`
  ntoh(byteorder) flag to recv(2) data. effective only in header part.
`_Bool readBlkF`
  blocking read flag
  true: block to complete read, false: non-block read

return to read(2) status.
iovec[PcData].iov_len is max size of iovec[PcData].iov_base, that will over write to request data size in readPacket().

Prototyped in: | libutil.h
Calls: | __assert13(), __byte_swap_long_variable(), __byte_swap_word_variable(), fprintf(), fstat(), read(), recv(), usleep()

## Global Function rs485_make_long_packet()

`int rs485_make_long_packet ( u_char* pcmdbuf, u_char flag, u_char address, u_char length, u_char count, const u_char* pdata )`

Prototyped in: | libutil.h
Calls: | memcpy()

## Global Function rs485_make_packet()

`size_t rs485_make_packet ( u_char* pcmdbuf, u_char id, u_char flag, u_char address, u_char length, u_char count, const u_char* pdata )`

`u_char* pcmdbuf`
  data buf of send data
`u_char id`
  dev ID
`u_char flag`
  flag in header
`u_char address`
  device map address
`u_char length`
  pdata length
`u_char count`
  count in header
`const u_char* pdata`
  body of send data

Prototyped in: | libutil.h
Calls: | memcpy()

## Global Function set485devShort()

set short data to send RS485 device

`u_short set485devShort ( u_char dst[sizeof(short)], u_short src )`
return src value

Prototyped in: | libutil.h

## Global Function usec2tv()

convert usec to 'struct timeval'

`struct timeval* usec2tv ( time_t usec, struct timeval* tv )`

`time_t usec`
  value in usec.
`struct timeval* tv`
  pointer to set return value

@ret return {@link tv}

Prototyped in: | libutil.h

## Global Function writePacket()

edit and send packet to 'd'

`ssize_t writePacket ( int d, __uint32_t seq, __uint16_t pri, __uint16_t cat, __uint16_t flg, __uint16_t datLen, void* dat, _Bool htonF )`

`int d`
  write descriptor
`__uint32_t seq`
  sequence no
`__uint16_t pri`
  priority
`__uint16_t cat`
  category
`__uint16_t flg`
  flags
`__uint16_t datLen`
  data length
`void* dat`
  data
`_Bool htonF`
  hton(byteorder) flag to edit packet. effective only in header part.

return write size(byte).

Prototyped in: | libutil.h
Calls: | __byte_swap_long_variable(), __byte_swap_word_variable(), writev()