/*
 *========================================================================
 *
 *    : AZN_PLAZA_LANE APP
 *      : lo_ctrl.h
 *      : JBY (baarong@neighbor21.co.kr)
 *      : 2018.07.13
 *      : 
 *        :  low-level comm. control block /  Data Buffer lccb.status  define pktflag
 *
 *========================================================================
*/


#ifndef    _LO_CTRL
#define    _LO_CTRL

#include "def_set.h"

#define   LOBUFF_SIZE    4096         /* raw buffer size                      */

struct    lo_comm_ctrl {              /* low-level comm. control block        */
    char   device_nm[24];             /* device name(inet port)               */
    int    port_fd;                   /* Open file(COMM PORT) descriptor      */
    int    stat_flag;                 /* status flag                          */

    struct    {                       /* --   --                      */
        int    sno;                   /*                              */
        int    len;                   /* DATA LENGTH                          */
        uchar  buf[LOBUFF_SIZE];      /*  DATA BUFFER                     */
        int    cnt;                   /* RETRY COUNT                          */
        int    err;                   /*  ERROR BYTE                      */
    } snd;
    struct    {                       /* --   --                      */
        int    psn;                   /* PSN (Protocol Status Number)         */
        int    sno;                   /*                              */
        int    len;                   /* DATA LENGTH                          */
        uchar  buf[LOBUFF_SIZE];      /*  DATA BUFFER                     */
        int    cnt;                   /* RETRY COUNT                          */
        int    err;                   /* ERROR CODE                           */
    } rcv;
    struct    {
        int    flg;                   /* packet flag                          */
        int    len;                   /* length                               */
        int    seq;                   /* packet sequencial number             */
        uchar  buf[LOBUFF_SIZE];      /* packet buffer                        */
    } pkt;
};

/* lccb.status */
#define    L_OPEN        0x0001       /* open compeleted              */
#define    L_STOP        0x0002       /* stop request                 */
#define    L_ERR         0x0004       /*                      */

/* lccb.pkt.flg */
#define    LP_FREE        0x0000      /* free(empty)                  */
#define    LP_SEND        0x0001      /* send                         */

#define    ETX            0x03

#define    F_DATA         0x40        /*         : DATA               */


#define    RETRY_COUNT        3       /* RETRY COUNT                  */

/* lccb.rcv.err */
#define   RE_FIN         9990         /* FIN ес         */
#define   RE_TMOUT       9991         /* receive timeout(NO RESPONSE) */
#define   RE_FRAME       9992         /* frame format error           */
#define   RE_LENG        9994         /* Frame length error           */

extern    struct    lo_comm_ctrl    lo_comm_ctrl;       /* LOW-Communication-Control-Block*/
#endif
