/*========================================================================
*
*   시스템명 : 요금징수 시스템
*   파 일 명 : senddata_handle.sc
*   작 성 자 : 오효섭 (catacath@neighbor21.co.kr)
*   작 성 일 : 2012.09.17
*   수 정 일 :
*   설    명 :
*
*========================================================================
*/

#include <stdio.h>
#include <stdlib.h>
#include <fcntl.h>
#include <sys/types.h>
#include <string.h>
#include <unistd.h>
#include <sys/utsname.h>
#include <math.h>

#include "path_def.h"
#include "hi_ctrl.h"
#include "snd_rcv_knd.h"
#include "hi_packet_format.h"
#include "ipc_def.h"
#include "wrkr_info.h"
#include "fare_tbl.h"
#include "taglnk_frame.h"
#include "fw_ver.h"
#include "fw_data.h"
#include "bl_mst.h"
#include "bl_chg.h"
#include "pl_mst.h"
#include "pl_chg.h"
#include "bef_mst.h"
#include "bef_chg.h"
#include "pl_info.h"
#include "holi_tbl.h"
#include "nonpay_info.h"
#include "red_carno_info.h"
#include "imm_card_info.h"
#include "imm_carno_info.h"
#include "iss_comp.h"
#include "func_list.h"
#include "file_lb.h"
#include "tagbl_struc.h"
#include "dir_path.h"
#include "wfr_mst.h"
#include "file_ctrl.h"
#include "def_set.h"
#include "lb_func_list.h"

#define  ascii2ksc(x, y)        chg_asc_ks_code(x, sizeof(x), y, sizeof(y))
#define _MSTCHG_ 1

int isfd, isfd1;
extern int errno;
int mod_bef_type;
#define _ORACLE_ 1
#define _VERIFY_
#define _DEF_REQ_		 
/*
*========================================================================
*
*   함 수 명 : snd_rq_seq_no
*   작 성 자 : JBY
*   작 성 일 : 2012.09.18
*   수 정 일 :
*   설    명 : 전송연번 데이터 송신
*
*========================================================================
*/

int snd_rq_seq_no(char *msg_buf)
{
    struct hi_seq_no_data   *h_seq_no;
    struct rq_seq_no_tbl    *rq_seq;
    struct write_info       wf;
    int    k_ibtm, c_time;
    time_t i_clck;
    struct tm    *jdtm;
    int    c_wrk_no, p_wrk_no;            /* 현근무번호, 전근무번호 */
    int    c_kday, p_kday, i_kday;        /* 현근무일자, 전근무일자 */
    char   tmp[10];

    h_seq_no = (struct hi_seq_no_data *)hi_comm_ctrl.snd.buf;

    memset(h_seq_no, 0, sizeof(struct hi_seq_no_data));
    rq_seq = (struct rq_seq_no_tbl *)msg_buf;

    sprintf((char *)h_seq_no->kind, "%02x", NS_SEQ_NO_DATA);         /* 종별        */
#if 0 //DB 조회 방식
    sprintf((char *)h_seq_no->rq_seq_no, "%.8s", rq_seq->rq_seq_no);  /* 전송연번    */

    sprintf((char *)h_seq_no->wrk_no       , "%.4s", rq_seq->wrk_no);         /* 근무번호    */
    sprintf((char *)h_seq_no->start_year   , "%.4s", rq_seq->wrk_date);    /* 근무일자    */
    sprintf((char *)h_seq_no->start_month  , "%.2s", rq_seq->wrk_date+4);  /* 근무일자    */
    sprintf((char *)h_seq_no->start_day    , "%.2s", rq_seq->wrk_date+6);  /* 근무일자    */
    sprintf((char *)h_seq_no->lane_no      , "%.2s", rq_seq->lane_no);
    sprintf((char *)h_seq_no->day_chng_hour, "%.2s", rq_seq->day_chng_hour);
    sprintf((char *)h_seq_no->day_chng_min , "%.2s", rq_seq->day_chng_min);
    sprintf((char *)h_seq_no->day_end_hour , "%.2s", rq_seq->day_end_hour);
    sprintf((char *)h_seq_no->day_end_min  , "%.2s", rq_seq->day_end_min);
#else
    sprintf((char *)h_seq_no->rq_seq_no, "%08x", hi_comm_ctrl.lane_stat_info.lst_rev_snd_no + 1);    /* 최종 수신전송연번 */
printf("1\n");
    if (hi_comm_ctrl.lane_stat_info.lst_rev_snd_no + 1 == 0)
        sprintf((char *)h_seq_no->rq_seq_no, "%08x", 1);
printf("2\n");    
    i_clck = hi_comm_ctrl.time;            /* 현재시각 CLOCK   */    
printf("3\n");
    jdtm = localtime(&i_clck);
printf("4\n");
    sprintf((char *)h_seq_no->start_year, "%04d", YEAR(jdtm->tm_year));
    sprintf((char *)h_seq_no->start_month, "%02d", MONTH(jdtm->tm_mon));
    sprintf((char *)h_seq_no->start_day, "%02d", DAY(jdtm->tm_mday));
printf("5[%.4s]\n", hi_comm_ctrl.lane_stat_info.wrk_no);
    /* 초기화 근무번호 */
    c_wrk_no = natoi(&hi_comm_ctrl.lane_stat_info.wrk_no[2], 2);    /* 현근무번호 */
    p_wrk_no = natoi(&hi_comm_ctrl.lane_stat_info.be_wrk_no[2], 2); /* 전근무번호 */
    c_kday = DAYIT(lb_data2atoi((char*)hi_comm_ctrl.lane_stat_info.wrk_year, 4),
                   lb_data2atoi((char*)hi_comm_ctrl.lane_stat_info.wrk_mon, 2),
                   lb_data2atoi((char*)hi_comm_ctrl.lane_stat_info.wrk_day, 2));
    p_kday = DAYIT(lb_data2atoi((char*)hi_comm_ctrl.lane_stat_info.be_wrk_year, 4),
                   lb_data2atoi((char*)hi_comm_ctrl.lane_stat_info.be_wrk_mon, 2),
                   lb_data2atoi((char*)hi_comm_ctrl.lane_stat_info.be_wrk_day, 2));
    i_kday = DAYIT(lb_data2atoi((char*)h_seq_no->start_year, 4),
                   lb_data2atoi((char*)h_seq_no->start_month, 2),
                   lb_data2atoi((char*)h_seq_no->start_day, 2));
printf("6[%d][%d][%d]\n", c_kday, p_kday, i_kday);
    if (c_kday == i_kday && c_wrk_no != 0)
        c_wrk_no++;            /* 현근무일=초기화일 */
    else if (p_kday == i_kday && p_wrk_no != 0)
        c_wrk_no = p_wrk_no + 1;        /* 전근무일=초기화일 */
    else
    {
        e_memcpy(wf.year, h_seq_no->start_year);
        e_memcpy(wf.mon, h_seq_no->start_month);
        e_memcpy(wf.day, h_seq_no->start_day);
        c_wrk_no = reding_termrecv_wrkno(&wf);
        c_wrk_no++;
    }
printf("7\n");
    if (c_wrk_no > MAX_WRKCNT)            /* 최대근무수 OVER */
        return (-1);
printf("8\n");
    memset(tmp, 0x00, sizeof(tmp));
    c_wrk_no += (hi_comm_ctrl.lane_no * 100);        /* 초기화 근무번호 */
    sprintf((char *)tmp, "%04d", c_wrk_no);
	//sprintf((char *)tmp, "0704");
printf("9\n");
    memcpy(h_seq_no->wrk_no, tmp, 4);
    sprintf((char *)h_seq_no->start_year, "%04d", YEAR(jdtm->tm_year));
    sprintf((char *)h_seq_no->start_month, "%02d", MONTH(jdtm->tm_mon));
    sprintf((char *)h_seq_no->start_day, "%02d", DAY(jdtm->tm_mday));
printf("10\n");
    sprintf((char *)h_seq_no->lane_no, "%02d", hi_comm_ctrl.lane_no);
#endif
printf("11\n");
    return (sizeof(struct hi_seq_no_data));
}

/*
 *========================================================================
 *
 *   Function : rq_accuml_data_resnd()
 *   Progrmer : JBY (baarong@neighbor21.co.kr)
 *   Date     : 2018.09.03
 *   Modified :
 *   Remark   : 축적 DATA 재전송 요구
 *              전송연번=0, 일자 !=0
 *              해당일 일변경 MARK DATA 부터 (해당일 일변경 MARK없을시
 *              가장 오래된 축적 DATA 부터 )
 *              2 : 전송연번 = 0 일자 = 0
 *              가장 오래된 축적 DATA 부터
 *              3 : 전송연번 != 0 일자 != 0
 *              해당일 일변경 MARK에서 부터 지정된 전송연번 부터
 *              (해당 전송연번이 없는 경우 가장 오래된 축적 DATA 부터)
 *              4 : 전송연번 != 0 일자 = 0
 *              지정된 전송연번부터 (통상 이상 복구 수순)
 *              (지정된 전송연번이 없으면 가장 오래된 전송연번 부터)
 *
 *========================================================================
*/

int rq_accuml_data_resnd()
{
    struct    hi_rq_accuml_data    *accuml;
    struct    hi_comm_continue_rq  *hccr;
    char tmp[10]; memset(tmp, 0x00, sizeof(tmp));

    accuml = (struct hi_rq_accuml_data *)hi_comm_ctrl.snd.buf;
    hccr = (struct hi_comm_continue_rq *)hi_comm_ctrl.rcv_ctrl.buf;
    memset(accuml, 0x00, sizeof(struct hi_rq_accuml_data));

    sprintf((char *)accuml->kind, "%02x", NS_RQ_ACCUML_DATA);

    if (hi_comm_ctrl.now_stat_info & H_ACC_RESND)
    {
        /* 축적 DATA 전송요구 : 관리자 */
        sprintf((char *)accuml->rq_seq_no, "%08x", hi_comm_ctrl.rtr.rq_resnd_strtno); /* 재송요구 연번 */
		//sprintf((char *)accuml->rq_seq_no, "%08x", 1); /* 재송요구 연번 */
        memcpy(&accuml->year, hi_comm_ctrl.rtr.wrk_year, 4);   /* 재송일자      */
        memcpy(&accuml->month, hi_comm_ctrl.rtr.wrk_mon, 2);   /* 재송일자      */
        memcpy(&accuml->day, hi_comm_ctrl.rtr.wrk_day, 2);     /* 재송일자      */
    }
    else
    {
        /* 교신재개요구 수신에 의한 축적 재송요구 */
        //sprintf((char *)accuml->rq_seq_no, "%08x", hi_comm_ctrl.lane_stat_info.lst_rev_snd_no); /* 최종전송연번 */
		sprintf((char *)accuml->rq_seq_no, "%08x", 1); /* 최종전송연번 */
        sprintf(tmp, "%.8s%c", accuml->rq_seq_no, '\0');
        if (strtoul(tmp, NULL, 16) != 0)
        {
            if (strtoul(tmp, NULL, 16) == 0)            /* WRAP-AROUND ?*/
                sprintf((char *)accuml->rq_seq_no, "00000001");            /* 1st 전송연번 */
        }
        
        if (hi_comm_ctrl.write_info.rcv_snd_no == 0)
        {
            sprintf((char *)accuml->year, "%04d", YEAR(hi_comm_ctrl.cday.tm_year));
            sprintf((char *)accuml->month, "%02d", MONTH(hi_comm_ctrl.cday.tm_mon));
            sprintf((char *)accuml->day, "%02d", DAY(hi_comm_ctrl.cday.tm_mday));
        }else
        {
            sprintf((char *)accuml->year, "%.4s", hi_comm_ctrl.rtr.wrk_year);
            sprintf((char *)accuml->month, "%.2s", hi_comm_ctrl.rtr.wrk_mon);
            sprintf((char *)accuml->day, "%.2s", hi_comm_ctrl.rtr.wrk_day);
        }
    }

    sprintf((char *)accuml->lane_no,  "%02d", hi_comm_ctrl.lane_no);
    //memcpy(&accuml->lane_typ, &hccr->lane_typ, 2);

    sprintf(tmp, "%.8s%c", accuml->rq_seq_no, '\0');
    hi_comm_ctrl.sndrq_sndno = strtoul(tmp, NULL, 16);    /* 재송요구연번 */
    return (sizeof(struct hi_rq_accuml_data));
}

/*
*========================================================================
*
*   함 수 명 : confrm_reply_snd_hnd()
*   작 성 자 : JBY
*   작 성 일 : 2012.09.17
*   수 정 일 :
*   설    명 : 확인 응답 송신 처리
*
*========================================================================
*/

int confrm_reply_snd_hnd()
{
    struct    hi_confrm_reply    *confrm_reply;

    confrm_reply = (struct hi_confrm_reply *)hi_comm_ctrl.snd.buf;
    memset(confrm_reply, 0, sizeof(struct hi_confrm_reply));

    sprintf((char *)confrm_reply->kind, "%02x", NS_CONFRM_REPLY);

    if (hi_comm_ctrl.now_stat_info & H_ERR_REST)
    {
        confrm_reply->reply_typ = 0x01;        /* 이상복구 수순 : 축적 응답 */
        sprintf((char *)confrm_reply->warr_seq_no, "%08x", hi_comm_ctrl.warr_snd_no);
    }
    else if (hi_comm_ctrl.rcv_ctrl.cmd == NS_LANE_STAT)
        confrm_reply->reply_typ = 0x04;     /* 차로 상태 응답     */
    else if (hi_comm_ctrl.rcv_ctrl.cmd == NS_TBL_ORDER)
        confrm_reply->reply_typ = 0x03;     /* 테이블요구응답 응답     */
    else
        return (0);

    return (sizeof(struct hi_confrm_reply));
}

/*
 *========================================================================
 *
 *   Function : snd_tm_dt()
 *   Progrmer : JBY (baarong@neighbor21.co.kr)
 *   Date     : 2018.08.28
 *   Modified :
 *   Remark   : 시각 DATA 송신 처리
*
*========================================================================
*/

int snd_tm_dt()
{
    struct    write_info    wf;
    struct    hi_tm_data     *tm_dt;

    tm_dt = (struct hi_tm_data *)hi_comm_ctrl.snd.buf;
    sprintf((char *)wf.plz_id, "%.2s", hi_comm_ctrl.bas_tbl.plz_id);
    lb_freadx(&wf, FNO_BASICTBL, &hi_comm_ctrl.bas_tbl, FEQUAL);

    memset(tm_dt, 0, sizeof(struct hi_tm_data));

    sprintf((char *)tm_dt->kind, "%02x", NS_TM_DATA);

    sprintf((char *)tm_dt->year , "%04d", YEAR(hi_comm_ctrl.cday.tm_year));
    sprintf((char *)tm_dt->month, "%02d", MONTH(hi_comm_ctrl.cday.tm_mon));
    sprintf((char *)tm_dt->day  , "%02d", DAY(hi_comm_ctrl.cday.tm_mday) );
    sprintf((char *)tm_dt->hour , "%02d", hi_comm_ctrl.cday.tm_hour      );
    sprintf((char *)tm_dt->min  , "%02d", hi_comm_ctrl.cday.tm_min       );
    sprintf((char *)tm_dt->sec  , "%02d", hi_comm_ctrl.cday.tm_sec       );

    return (sizeof(struct hi_tm_data));
}

/*
 *========================================================================
 *
 *   Function : snd_tbl_cmd()
 *   Progrmer : JBY (baarong@neighbor21.co.kr)
 *   Date     : 2018.09.03
 *   Modified :
 *   Remark   : 차로제어기에 TABLE 지령 송신
*
*========================================================================
*/

int snd_tbl_cmd(int rsp)
{
    struct    write_info    wf;
    struct    hi_tbl_cmd     *tbl_cmd;
    struct    basic_tbl       bas_tbl;
    struct    bl_mst_tbl  bl_mst_tbl;
    struct    bl_chg_tbl  bl_chg_tbl;
    struct    bef_mst_tbl  adv_pay_mst;
    struct    bef_chg_tbl  adv_pay_chg;

    struct    imm_carno_info  imm_carno_mst;
    struct    imm_carno_info  imm_carno_chg;
    struct    imm_card_info  imm_card_mst;
    struct    imm_card_info  imm_card_chg;
    struct    red_carno_info  red_carno_mst;
    struct    red_carno_info  red_carno_chg;
    char      plz_id[2];
    int       flag=0,    ii;
    int       ret_val,isrc,isfd;
    unint     cjbl, cjbef, cjim, cjtag, cjred;            /* B/L, P/L 최종 관리연번    */
    char tmp[10]; memset(tmp, 0x00, sizeof(tmp));

    tbl_cmd = (struct hi_tbl_cmd *)hi_comm_ctrl.snd.buf;
    mod_bef_type = 0;
    sprintf(wf.plz_id, "%.2s", hi_comm_ctrl.write_info.plz_id);
if(strncmp(hi_comm_ctrl.write_info.plz_id, PLZ_CODE2, 2) != 0)
{
	//lane_log("######## SND PLZ_ID[%.2s] [%.2s]\n", hi_comm_ctrl.write_info.plz_id, hi_comm_ctrl.lane_stat_info.plz_id);
	snprintf(hi_comm_ctrl.write_info.plz_id, 2+1, "%s", PLZ_CODE2);
}
    if (hi_comm_ctrl.now_stat_info & H_PLURAL)        /* 다중 수순 처리중 */
        return (0);

    memset(tbl_cmd, 0, sizeof(struct hi_tbl_cmd));
    memset(&bl_mst_tbl, 0x00, sizeof(struct bl_mst_tbl));
    memset(&bl_chg_tbl, 0x00, sizeof(struct bl_chg_tbl));
    memset(&adv_pay_mst, 0x00, sizeof(struct bef_mst_tbl));
    memset(&adv_pay_chg, 0x00, sizeof(struct bef_chg_tbl));
/* 2019.06.15 신규 추가 */
    memset(&imm_carno_mst, 0x00, sizeof(struct imm_carno_info));
    memset(&imm_carno_chg, 0x00, sizeof(struct imm_carno_info));
    memset(&imm_card_mst, 0x00, sizeof(struct imm_card_info));
    memset(&imm_card_chg, 0x00, sizeof(struct imm_card_info));
    memset(&red_carno_mst, 0x00, sizeof(struct red_carno_info));
    memset(&red_carno_chg, 0x00, sizeof(struct red_carno_info));
#if 0
    isfd = lb_fopen(&wf, FNO_BASICTBL, FINPUT+FC_MANULOCK);
    if(isfd < 0)
    {
        lane_log("BASICTBL FILE OPEN ERROR (%d)[%d]\n", errno, isfd);
    }

    for(ii=0; ii<2;ii++)
    {
        isrc = lb_readl(isfd, &bas_tbl, FNEXT, sizeof(struct basic_tbl));
        if (isrc <= 0)
        {
            lane_log("BASICTBL_TBL READ ERROR\n");
            break;
        }
        memcpy(plz_id, &bas_tbl.plz_id, 2);

        if((memcmp(plz_id, hi_comm_ctrl.write_info.plz_id, 2) == 0))
        {
            memcpy(&hi_comm_ctrl.bas_tbl, &bas_tbl, sizeof(struct basic_tbl));
            lane_log(" SEND_DATA plz_id = [%.02s] lane_no = [%d]\n", hi_comm_ctrl.bas_tbl.plz_id, hi_comm_ctrl.lane_no);
            lane_log("---------------------------------------------------------------------\n");
            break;
        }
    }
#else
	isfd = lb_freadx(&wf, FNO_BASICTBL, &bas_tbl, FFIRST);

    if(isfd < 0)
    {
        lane_log("BASICTBL FILE OPEN ERROR (%d)[%d]\n", errno, isfd);
    }

	memcpy(&hi_comm_ctrl.bas_tbl, &bas_tbl, sizeof(struct basic_tbl));

#endif
   lb_close(isfd);

    /* B/L 관리연번 */
    ret_val = lb_freadx(&wf, FNO_BLCNG, &bl_chg_tbl, FLAST);

    if(ret_val < 0)
    {
        lb_freadx(&wf, FNO_BLMST, &bl_mst_tbl, FLAST);
        sprintf(tmp, "%08x%c", bl_mst_tbl.mngt_no, '\0');
        cjbl = strtoul(tmp, NULL, 16);
    }
    else
    {
        sprintf(tmp, "%08x%c", bl_chg_tbl.mngt_no, '\0');
        cjbl = strtoul(tmp, NULL, 16);
    }

    /* 사전결제 관리연번 */
    ret_val = lb_freadx(&wf, FNO_BEFCNG, &adv_pay_chg, FLAST);
    if(ret_val < 0)
    {
        lb_freadx(&wf, FNO_BEFMST, &adv_pay_mst, FLAST);
        sprintf(tmp, "%08x%c", lb_data2atoi(adv_pay_mst.snd_no, 10), '\0');
        cjbef = strtoul(tmp, NULL, 16);
    }
    else
    {
        sprintf(tmp, "%08x%c", lb_data2atoi(adv_pay_chg.snd_no, 10), '\0');
        cjbef = strtoul(tmp, NULL, 16);
    }
/* 2019.06.15 신규 추가 */
    /* 차량번호 면제 관리연번 */
    ret_val = lb_freadx(&wf, FNO_IMM_CARNO_CHG, &imm_carno_chg, FLAST);
    if(ret_val < 0)
    {
        lb_freadx(&wf, FNO_IMM_CARNO, &imm_carno_mst, FLAST);
        sprintf(tmp, "%08x%c", lb_data2atoi(imm_carno_mst.snd_no, 10), '\0');
        cjim = strtoul(tmp, NULL, 16);
    }
    else
    {
        sprintf(tmp, "%08x%c", lb_data2atoi(imm_carno_chg.snd_no, 10), '\0');
        cjim = strtoul(tmp, NULL, 16);
    }

    /* 요일제/저공해 면제 관리연번 */
    ret_val = lb_freadx(&wf, FNO_IMM_CARDNO_CHG, &imm_card_chg, FLAST);
    if(ret_val < 0)
    {
        lb_freadx(&wf, FNO_IMM_CARDNO, &imm_card_mst, FLAST);
        sprintf(tmp, "%08x%c", lb_data2atoi(imm_card_mst.snd_no, 10), '\0');
        cjtag = strtoul(tmp, NULL, 16);
    }
    else
    {
        sprintf(tmp, "%08x%c", lb_data2atoi(imm_card_chg.snd_no, 10), '\0');
        cjtag = strtoul(tmp, NULL, 16);
    }

    /* 차량번호 감면 관리연번 */
    ret_val = lb_freadx(&wf, FNO_RED_CARNO_CHG, &red_carno_chg, FLAST);
    if(ret_val < 0)
    {
        lb_freadx(&wf, FNO_RED_CARNO, &red_carno_mst, FLAST);
        sprintf(tmp, "%08x%c", lb_data2atoi(red_carno_mst.snd_no, 10), '\0');
        cjred = strtoul(tmp, NULL, 16);
    }
    else
    {
        sprintf(tmp, "%08x%c", lb_data2atoi(red_carno_chg.snd_no, 10), '\0');
        cjred = strtoul(tmp, NULL, 16);
    }

//lane_log("테이블지령[%d][%x][%x][%x][%x][%x]\n", rsp, cjbl, cjbef, cjim, cjtag, cjred);
    switch (rsp)
    {
        case 1: /* 차로측 수신후 송신처리 : 차로상태            */
                /*                 근무종료시   */
            flag = 0;

            for (ii = 0; ii < 20; ii++)
            {
//                if (hi_comm_ctrl.plz_typ == 0 && hi_comm_ctrl.asc_des_div == L_ENT && ii >= 2)
//                continue;    /* 입구 : 정수, 근무자 */
                if (hi_comm_ctrl.lane_stat_info.tbl_stat[ii][1] == 0x01)/* 지령 미처리 */
                {
                    flag = 1;
                    break;
                }
            }

            if(hi_comm_ctrl.lane_stat_info.bl_lst_hnd_no != cjbl)
            {
                flag = 1;
            }

            if(hi_comm_ctrl.lane_stat_info.bef_lst_hnd_no != cjbef)
            {
                flag = 1;
            }

            if(hi_comm_ctrl.lane_stat_info.imm_lst_hnd_no != cjim)
            {
                flag = 1;
            }

            if(hi_comm_ctrl.lane_stat_info.rfid_lst_hnd_no != cjtag)
            {
                flag = 1;
            }

            if(hi_comm_ctrl.lane_stat_info.red_lst_hnd_no != cjred)
            {
                flag = 1;
            }

            if (flag == 1 ) break;

            if (flag == 0 )
            {
                //lb_close(isfd);
                return (0);
            }

            break;

        case 2: /* TABLE DUMP 요구 */
            sprintf((char *)tbl_cmd->dump_tbl_div, "%02d", hi_comm_ctrl.dmp_tbl_no); /* DUMP할 TABLE */
            break;

        case 3: /* TABLE 지령 명령 */
            flag = 0;

            for (ii = 0; ii < 20; ii++)
            {
                if (lb_data2atoi((char*)hi_comm_ctrl.bas_tbl.rvs_tbl_info[ii].rvs_no, 2) != hi_comm_ctrl.lane_stat_info.tbl_stat[ii][0])
                {
                    hi_comm_ctrl.lane_stat_info.tbl_stat[ii][1] = 0x01; /* 지령 미처리 */
                    flag = 1;
                }
                else
                    hi_comm_ctrl.lane_stat_info.tbl_stat[ii][1] = 0x00; /* 송신완료    */
            }

            //lb_close(isfd);
            if(flag == 0) return (0);
            break;
    }

    sprintf((char *)tbl_cmd->kind, "%02x", NS_TBL_CMD);

    for(ii = 0; ii < 20 ; ii++)
    {
        e_memcpy(tbl_cmd->rvs_no_tbl[ii].rvs_no, hi_comm_ctrl.bas_tbl.rvs_tbl_info[ii].rvs_no);
    }

    //tbl_cmd->fw_div = lanectrl_fw_ver.ctrl_div;

    //sprintf((char *)tbl_cmd->fw_ver, "%04x", hi_comm_ctrl.lane_stat_info.lane_fw_ver);/* 차로 버젼*/

    if (lb_data2atoi((char*)hi_comm_ctrl.bas_tbl.rvs_tbl_info[4].rvs_no, 2) != hi_comm_ctrl.lane_stat_info.tbl_stat[4][0])
		cjim = 0;

	if (lb_data2atoi((char*)hi_comm_ctrl.bas_tbl.rvs_tbl_info[5].rvs_no, 2) != hi_comm_ctrl.lane_stat_info.tbl_stat[5][0])
		cjtag = 0;

	if (lb_data2atoi((char*)hi_comm_ctrl.bas_tbl.rvs_tbl_info[6].rvs_no, 2) != hi_comm_ctrl.lane_stat_info.tbl_stat[6][0])
	{
		mod_bef_type = 1;
		cjbef = 0;
	}

	if (lb_data2atoi((char*)hi_comm_ctrl.bas_tbl.rvs_tbl_info[8].rvs_no, 2) != hi_comm_ctrl.lane_stat_info.tbl_stat[8][0])
		cjbl = 0;

	if (lb_data2atoi((char*)hi_comm_ctrl.bas_tbl.rvs_tbl_info[9].rvs_no, 2) != hi_comm_ctrl.lane_stat_info.tbl_stat[9][0])
		cjred = 0;

    sprintf((char *)tbl_cmd->bl_seq_no , "%08x", cjbl);         /* 최종연번  */
    sprintf((char *)tbl_cmd->bef_seq_no, "%08x", cjbef);        /* 최종연번  */

    sprintf((char *)tbl_cmd->imm_carno_seq_no , "%08x", cjim);  /* 최종연번  */
    sprintf((char *)tbl_cmd->rfid_seq_no , "%08x", cjtag);      /* 최종연번  */
    sprintf((char *)tbl_cmd->red_carno_seq_no , "%08x", cjred); /* 최종연번  */
lane_log("테이블지령 End[%d][%x][%x][%x][%x][%x]\n", rsp, cjbl, cjbef, cjim, cjtag, cjred);
    //lb_close(isfd);
    return (sizeof(struct hi_tbl_cmd));
}

/*
 *========================================================================
 *
 *   Function : snd_tbl_dt()
 *   Progrmer : JBY (baarong@neighbor21.co.kr)
 *   Date     : 2018.08.28
 *   Modified :
 *   Remark   : TABLE DATA 송신 처리
*
*========================================================================
*/

int snd_tbl_dt(char *p)
{
    struct    hi_tbl_order    *rq_tbl;
    struct    hi_tbl_data    *tbl_dt;
    int    retc;

    rq_tbl = (struct hi_tbl_order *)hi_comm_ctrl.rcv_ctrl.buf;
    tbl_dt = (struct hi_tbl_data *)hi_comm_ctrl.snd.buf;

    switch (lb_data2atoi((char *)rq_tbl->tbl_typ, 2))
    {
        case TB_BAS         : retc = snd_bas_tbl(); break;         /* 정수 */
        case TB_WRKR        : retc = snd_wrkr_crd_tbl(); break;    /* 근무자 */
        case TB_HOLI        : retc = snd_holi_tbl(); break;        /* 휴일 */
        case TB_ISS_COMP    : retc = snd_iss_comp_tbl(); break;    /* 발행사 */
        case TB_IMM_CARNO   : retc = snd_imm_carno_tbl(); break;   /* 차량번호 면제 */
        case TB_IMM_CRDNO   : retc = snd_imm_cardno_tbl(); break;  /* 카드번호 면제 */
        case TB_ADV_PAY     : retc = snd_adv_pay_tbl(); break;     /* 사전등록 */
        case TB_PL_CRD      : retc = snd_pl_tbl(); break;          /* P/L TABLE DATA */
        case TB_BL_CRD      : retc = snd_bl_tbl(); break;          /* B/L TABLE DATA */
        case TB_RED_CARNO   : retc = snd_red_carno_tbl(); break;   /* 차량번호 감면 */
#if 0
		case TB_IMBL_CRD    : retc = snd_imbl_tbl(); break;        /* B/L TABLE DATA(구) */
#endif
        default:    retc = -1;
    }

    if (retc >= 0)
        return (retc);

    lane_log( " [LC2SV] (senddata_handle.pc) TABLE (%02d) DATA SEND ERROR....\n", tbl_dt->tbl_typ);
    memset(tbl_dt, 0, sizeof(struct hi_tbl_data));

    sprintf((char *)tbl_dt->kind, "%02x", NS_TBL_DATA);
    sprintf((char *)tbl_dt->tbl_typ, "%02d", TB_FORC_OCC_ERR);                /* ERROR 유도 */
    sprintf((char *)tbl_dt->frame_no, "%08x", FRAME_LAST_I);

    return (sizeof(struct hi_tbl_data));
}

/*
 *========================================================================
 *
 *   Function : snd_bas_tbl()
 *   Progrmer : JBY (baarong@neighbor21.co.kr)
 *   Date     : 2018.09.10
 *   Modified :
 *   Remark   : 정수 TABLE DATA 송신
 *
 *========================================================================
*/

int snd_bas_tbl()
{
    struct    hi_bas_tbl    *bas_tbl_hd;
    struct    hi_tbl_order    *rq_tbl;
    int    ii,jj;
    char tmp[10]; memset(tmp, 0x00, sizeof(tmp));

    bas_tbl_hd = (struct hi_bas_tbl *)hi_comm_ctrl.snd.buf;
    rq_tbl = (struct hi_tbl_order *)hi_comm_ctrl.rcv_ctrl.buf;

    memset(bas_tbl_hd, 0x00, sizeof(struct hi_bas_tbl));

    //sprintf((char *)bas_tbl_hd->seq_no, "%.8s", rq_tbl->seq_no);
    sprintf((char *)bas_tbl_hd->kind, "%02x", NS_TBL_DATA);   /* 종별   */

    sprintf((char *)bas_tbl_hd->tbl_typ, "%02d", TB_BAS);       /* TABLE Type */

    sprintf(tmp, "%.8s%c", rq_tbl->frame_no, '\0');

    if (strtoul(tmp, NULL, 16) != FRAME_FIRST_I)      /* Frame NO */
    {
        sprintf((char *)bas_tbl_hd->frame_no, "%08x", FRAME_LAST_I);     /* Frame NO */
        return (sizeof(struct hi_bas_tbl));
    }else
        sprintf((char *)bas_tbl_hd->frame_no, "%08x", strtoul(tmp, NULL, 16)); /* Frame NO */

    sprintf((char *)bas_tbl_hd->rvs_no, "%.2s", hi_comm_ctrl.bas_tbl.rvs_tbl_info[0].rvs_no); /* 개정번호 */

    e_memcpy(bas_tbl_hd->plz_id,   hi_comm_ctrl.bas_tbl.plz_id);       /* Plaza Code                      */
    e_memcpy(bas_tbl_hd->plz_name, hi_comm_ctrl.bas_tbl.plz_nm);       /* Plaza Name                      */
    del_space((char *)bas_tbl_hd->plz_name);

    sprintf((char *)bas_tbl_hd->lane_no, "%.2s", hi_comm_ctrl.bas_tbl.lane_info[hi_comm_ctrl.lane_no-1].phgc_lane_no);
    sprintf((char *)bas_tbl_hd->io_div , "%.2s", hi_comm_ctrl.bas_tbl.lane_info[hi_comm_ctrl.lane_no-1].io_div);
//printf("1[%s]\n", INI_FILE);
/* 2019.05.24 요금정보 기초사항 통합 */
    sprintf((char *)bas_tbl_hd->fare_cnt, "%.2s", hi_comm_ctrl.bas_tbl.fare_cnt);
    for(ii = 0; ii < 48; ii++)
    {
        sprintf((char *)bas_tbl_hd->fare_info[ii].fare_div, "%.2s", hi_comm_ctrl.bas_tbl.fare_info[ii].fare_div);
        bas_tbl_hd->fare_info[ii].dc_typ = hi_comm_ctrl.bas_tbl.fare_info[ii].dc_typ;
        sprintf((char *)bas_tbl_hd->fare_info[ii].fare    , "%.6s", hi_comm_ctrl.bas_tbl.fare_info[ii].fare);
        sprintf((char *)bas_tbl_hd->fare_info[ii].start_dt, "%.8s", hi_comm_ctrl.bas_tbl.fare_info[ii].start_dt);
        sprintf((char *)bas_tbl_hd->fare_info[ii].end_dt  , "%.8s", hi_comm_ctrl.bas_tbl.fare_info[ii].end_dt);
        sprintf((char *)bas_tbl_hd->fare_info[ii].fare_dc , "%.6s", hi_comm_ctrl.bas_tbl.fare_info[ii].fare_dc);
        sprintf((char *)bas_tbl_hd->fare_info[ii].penalty , "%.6s", hi_comm_ctrl.bas_tbl.fare_info[ii].penalty);
    }
//printf("TEL[%s][%s]\n", lb_get_inifile(INI_FILE,"PLAZA","TEL1"), lb_get_inifile(INI_FILE,"PLAZA","TEL2"));
//printf("2\n");
    //sprintf((char *)bas_tbl_hd->plz_tel1      , "%s", lb_get_inifile(INI_FILE,"PLAZA","TEL1"));
    //sprintf((char *)bas_tbl_hd->plz_tel2      , "%s", lb_get_inifile(INI_FILE,"PLAZA","TEL2"));
    sprintf((char *)bas_tbl_hd->plz_tel1      , "02)2290-6462");
    sprintf((char *)bas_tbl_hd->plz_tel2      , "2290-6462");
    sprintf((char *)bas_tbl_hd->bas_aply_year , "%.4s", hi_comm_ctrl.bas_tbl.rvs_tbl_info[0].apl_year);
    sprintf((char *)bas_tbl_hd->bas_aply_month, "%.2s", hi_comm_ctrl.bas_tbl.rvs_tbl_info[0].apl_mon);
    sprintf((char *)bas_tbl_hd->bas_aply_day  , "%.2s", hi_comm_ctrl.bas_tbl.rvs_tbl_info[0].apl_day);
    sprintf((char *)bas_tbl_hd->bas_aply_hour , "%.2s", hi_comm_ctrl.bas_tbl.rvs_tbl_info[0].apl_hr);
    sprintf((char *)bas_tbl_hd->bas_aply_min  , "%.2s", hi_comm_ctrl.bas_tbl.rvs_tbl_info[0].apl_min);

    sprintf((char *)bas_tbl_hd->bas_modf_year , "%.4s", hi_comm_ctrl.bas_tbl.rvs_tbl_info[0].modf_year);
    sprintf((char *)bas_tbl_hd->bas_modf_month, "%.2s", hi_comm_ctrl.bas_tbl.rvs_tbl_info[0].modf_mon);
    sprintf((char *)bas_tbl_hd->bas_modf_day  , "%.2s", hi_comm_ctrl.bas_tbl.rvs_tbl_info[0].modf_day);
    sprintf((char *)bas_tbl_hd->bas_modf_hour , "%.2s", hi_comm_ctrl.bas_tbl.rvs_tbl_info[0].modf_hr);
    sprintf((char *)bas_tbl_hd->bas_modf_min  , "%.2s", hi_comm_ctrl.bas_tbl.rvs_tbl_info[0].modf_min);

    sprintf((char *)bas_tbl_hd->rcv_str_dt, "%.4s", hi_comm_ctrl.bas_tbl.rcv_str_dt);
    sprintf((char *)bas_tbl_hd->rcv_end_dt, "%.4s", hi_comm_ctrl.bas_tbl.rcv_end_dt);
//lane_log("기초[%d]\n", sizeof(struct hi_bas_tbl));
    return (sizeof(struct hi_bas_tbl));
}

/*
*========================================================================
*
*   함 수 명 : record_cnt
*   작 성 자 : JBY
*   작 성 일 : 2012.09.18
*   수 정 일 :
*   설    명 : 파일 레코드수 반환
*
*========================================================================
*/

int record_cnt(int isfd, int fno)
{
    int cnt, isrc;
    char lamp_div[2+1];
    struct wrkr_personal_info wpinfo;
    cnt = 0;

    memset(lamp_div, 0, sizeof(lamp_div));

    switch(fno)
    {
/*
    case FNO_WRKRINFO:
        while( (isrc = lb_readl(isfd, &wpinfo, FNEXT, sizeof(struct wrkr_personal_info)))>0)
        {
            if (!memcmp(wpinfo.plz_id, hi_comm_ctrl.bas_tbl.plz_id, 2)) cnt++;
        }
        lseek(isfd, 0, SEEK_SET);
        break;
*/
    }

    return cnt;
}

/*
*========================================================================
*
*   함 수 명 : snd_wrkr_crd_tbl
*   작 성 자 : JBY
*   작 성 일 : 2012.09.18
*   수 정 일 :
*   설    명 : 근무자카드 테이블 송신
*
*========================================================================
*/

int snd_wrkr_crd_tbl()
{
    struct write_info         wf;
    struct wrkr_personal_info wpinfo;
    struct hi_wrkr_tbl_h     *wctbl_h;
    struct hi_wrkr_tbl_f     *wctbl_f;
    struct hi_tbl_order      *rq_tbl;
    int    isrc, pos;
    int    ii,row=0, tmp_frame = 0, hexi;
    char tmp[10]; memset(tmp, 0x00, sizeof(tmp));

    wctbl_h = (struct hi_wrkr_tbl_h *)hi_comm_ctrl.snd.buf;
    wctbl_f = (struct hi_wrkr_tbl_f *)hi_comm_ctrl.snd.buf;
    rq_tbl = (struct hi_tbl_order *)hi_comm_ctrl.rcv_ctrl.buf;
    memcpy(wf.plz_id, hi_comm_ctrl.bas_tbl.plz_id, 2);
    
    isfd = lb_fopen(&wf, FNO_WRKRINFO, FINPUT+FC_MANULOCK);
    if (isfd < 0) return (-1);

    sprintf((char *)wctbl_h->kind, "%02x", NS_TBL_DATA);
    sprintf(tmp, "%.8s%c", rq_tbl->frame_no, '\0');
    hexi = hextodig(rq_tbl->frame_no);
    switch (strtoul(tmp, NULL, 16))
    {
        case 0: /* 근무자 TABLE HEADER */
            memset(wctbl_h, 0, sizeof(struct hi_wrkr_tbl_h));

            sprintf((char *)wctbl_h->kind, "%02x", NS_TBL_DATA);
            sprintf((char *)wctbl_h->tbl_typ, "%02d", TB_WRKR);
            memcpy(wctbl_h->frame_no, rq_tbl->frame_no, sizeof(wctbl_h->frame_no));
            hi_comm_ctrl.frame_no = 0;
            row = lb_record_cnt(isfd, FNO_WRKRINFO);
//lane_log("근무자 ROW 1[%d]\n", row);
            if(row < 0) row = 0;
//lane_log("근무자 ROW 2[%d]\n", row);
            tmp_frame = row / 83 + 1;
            sprintf((char *)wctbl_h->frame_cnt, "%08x", tmp_frame);
            sprintf((char *)wctbl_h->rvs_no, "%.2s", hi_comm_ctrl.bas_tbl.rvs_tbl_info[1].rvs_no);

            memcpy(wctbl_h->tbl_aply_year, hi_comm_ctrl.bas_tbl.rvs_tbl_info[1].apl_year, 4);
            memcpy(wctbl_h->tbl_aply_mon,  hi_comm_ctrl.bas_tbl.rvs_tbl_info[1].apl_mon, 2);
            memcpy(wctbl_h->tbl_aply_day,  hi_comm_ctrl.bas_tbl.rvs_tbl_info[1].apl_day, 2);
            memcpy(wctbl_h->tbl_aply_hour, hi_comm_ctrl.bas_tbl.rvs_tbl_info[1].apl_hr, 2);
            memcpy(wctbl_h->tbl_aply_min,  hi_comm_ctrl.bas_tbl.rvs_tbl_info[1].apl_min, 2);

            memcpy(wctbl_h->tbl_modf_year, hi_comm_ctrl.bas_tbl.rvs_tbl_info[1].modf_year, 4);
            memcpy(wctbl_h->tbl_modf_mon,  hi_comm_ctrl.bas_tbl.rvs_tbl_info[1].modf_mon, 2);
            memcpy(wctbl_h->tbl_modf_day,  hi_comm_ctrl.bas_tbl.rvs_tbl_info[1].modf_day, 2);
            memcpy(wctbl_h->tbl_modf_hour, hi_comm_ctrl.bas_tbl.rvs_tbl_info[1].modf_hr, 2);
            memcpy(wctbl_h->tbl_modf_min,  hi_comm_ctrl.bas_tbl.rvs_tbl_info[1].modf_min, 2);

            sprintf((char *)wctbl_h->wrkr_crd_cnt, "%04d", row);
            lb_close(isfd);
            return (sizeof(struct hi_wrkr_tbl_h));

        case FRAME_LAST_I:
            memset(wctbl_f, 0, sizeof(struct hi_wrkr_tbl_f));
            sprintf((char *)wctbl_f->kind, "%02x", NS_TBL_DATA);
            sprintf((char *)wctbl_f->tbl_typ, "%02d", TB_WRKR);
            sprintf((char *)wctbl_f->frame_no, "%08x", FRAME_LAST_I);
            hi_comm_ctrl.frame_no = FRAME_LAST_I;
            lb_close(isfd);
            return (sizeof(struct hi_wrkr_tbl_f));

        default:
            break;
    }

    pos = (hexi-1) * 83;
    lseek(isfd, pos * sizeof(struct wrkr_personal_info),SEEK_SET);
    memset(wctbl_f, 0, sizeof(struct hi_wrkr_tbl_f));

    sprintf((char *)wctbl_h->kind, "%02x", NS_TBL_DATA);

    sprintf((char *)wctbl_f->tbl_typ, "%02d", TB_WRKR);
    e_memcpy(wctbl_f->frame_no, rq_tbl->frame_no);
    
    hi_comm_ctrl.frame_no = strtoul(tmp, NULL, 16);

    for (ii = 0; ii < 83; ii++)
    {
        memset(&wpinfo, 0, sizeof(struct wrkr_personal_info));
        isrc = lb_readl(isfd, &wpinfo,FNEXT,sizeof(struct wrkr_personal_info));

        if (isrc <= 0)
        {
            break;
        }
//printf("근무자[%.6s][%.6s][%.10s][%.8s]\n", wpinfo.plz_id, wpinfo.wrkr_no, wpinfo.wrkr_nm, wpinfo.wrkr_sno); 
        memcpy(wctbl_f->wrkr_crd_no[ii].wrkr_no, wpinfo.wrkr_no, 4);
        memcpy(wctbl_f->wrkr_crd_no[ii].wrkr_nm, wpinfo.wrkr_nm, 10);
        del_space((char *)wctbl_f->wrkr_crd_no[ii].wrkr_nm);
    }

    lb_close(isfd);
    return (sizeof(struct hi_wrkr_tbl_f));

}

/*
*========================================================================
*
*   함 수 명 : snd_holi_tbl
*   작 성 자 : JBY
*   작 성 일 : 2019.05.11
*   수 정 일 :
*   설    명 : 휴일정보 TABLE을 송신
*
*========================================================================
*/

int snd_holi_tbl()
{
    struct    write_info    wf;
    struct    holi_info     holi_tbl;
    struct    hi_holi_tbl_h   *holi_tbl_h;
    struct    hi_holi_tbl_f   *holi_tbl_f;
    struct    hi_tbl_order    *rq_tbl;
    int    isrc, row=0, nframe_cnt=0;
    int    ii,   jj, pos, hexi, tmp_frame;
    char tmp[10]; memset(tmp, 0x00, sizeof(tmp));

    holi_tbl_h = (struct hi_holi_tbl_h *)hi_comm_ctrl.snd.buf;
    holi_tbl_f = (struct hi_holi_tbl_f *)hi_comm_ctrl.snd.buf;
    rq_tbl = (struct hi_tbl_order *)hi_comm_ctrl.rcv_ctrl.buf;

    isfd = lb_fopen(&wf, FNO_HOLITBL, FINPUT+FC_MANULOCK);
    if (isfd < 0)
    {
        lane_log( "휴일정보 Open Fail[%d]\n", isfd);
        lb_close(isfd);
        return(-1);
    }
    
    sprintf(tmp, "%.8s%c", rq_tbl->frame_no, '\0');
    hexi = hextodig(rq_tbl->frame_no);
    switch (strtoul(tmp, NULL, 16))
    {
        case 0: /* 휴일 TABLE HEADER */
            memset(holi_tbl_h, 0, sizeof(struct hi_holi_tbl_h));

            sprintf((char *)holi_tbl_h->kind, "%02x", NS_TBL_DATA);
            sprintf((char *)holi_tbl_h->tbl_typ, "%02d", TB_HOLI);
            memcpy(holi_tbl_h->frame_no, rq_tbl->frame_no, sizeof(holi_tbl_h->frame_no));
            hi_comm_ctrl.frame_no = 0;
            row = lb_record_cnt(isfd, FNO_HOLITBL);

            if(row < 0) row = 0;

            tmp_frame = row / 250 + 1;
            sprintf((char *)holi_tbl_h->frame_cnt, "%08x", tmp_frame);
            sprintf((char *)holi_tbl_h->rvs_no, "%.2s", hi_comm_ctrl.bas_tbl.rvs_tbl_info[2].rvs_no);

            memcpy(holi_tbl_h->new_holi_rvs_year , hi_comm_ctrl.bas_tbl.rvs_tbl_info[2].apl_year, 4);
            memcpy(holi_tbl_h->new_holi_rvs_month, hi_comm_ctrl.bas_tbl.rvs_tbl_info[2].apl_mon, 2);
            memcpy(holi_tbl_h->new_holi_rvs_day  , hi_comm_ctrl.bas_tbl.rvs_tbl_info[2].apl_day, 2);
            memcpy(holi_tbl_h->new_holi_rvs_hour , hi_comm_ctrl.bas_tbl.rvs_tbl_info[2].apl_hr, 2);
            memcpy(holi_tbl_h->new_holi_rvs_min  , hi_comm_ctrl.bas_tbl.rvs_tbl_info[2].apl_min, 2);

            memcpy(holi_tbl_h->holi_modf_year , hi_comm_ctrl.bas_tbl.rvs_tbl_info[2].modf_year, 4);
            memcpy(holi_tbl_h->holi_modf_month, hi_comm_ctrl.bas_tbl.rvs_tbl_info[2].modf_mon, 2);
            memcpy(holi_tbl_h->holi_modf_day  , hi_comm_ctrl.bas_tbl.rvs_tbl_info[2].modf_day, 2);
            memcpy(holi_tbl_h->holi_modf_hour , hi_comm_ctrl.bas_tbl.rvs_tbl_info[2].modf_hr, 2);
            memcpy(holi_tbl_h->holi_modf_min  , hi_comm_ctrl.bas_tbl.rvs_tbl_info[2].modf_min, 2);
            lb_close(isfd);
            return (sizeof(struct hi_holi_tbl_h));

        case FRAME_LAST_I:
            memset(holi_tbl_f, 0, sizeof(struct hi_holi_tbl_f));
            sprintf((char *)holi_tbl_f->kind, "%02x", NS_TBL_DATA);
            sprintf((char *)holi_tbl_f->tbl_typ, "%02d", TB_HOLI);
            sprintf((char *)holi_tbl_f->frame_no, "%08x", FRAME_LAST_I);
            hi_comm_ctrl.frame_no = FRAME_LAST_I;
            lb_close(isfd);
            return (sizeof(struct hi_holi_tbl_f));

        default:
            break;
    }

    pos = (hexi-1) * 83;
    lseek(isfd, pos * sizeof(struct holi_info),SEEK_SET);
    memset(holi_tbl_f, 0, sizeof(struct hi_holi_tbl_f));

    sprintf((char *)holi_tbl_f->kind, "%02x", NS_TBL_DATA);
    sprintf((char *)holi_tbl_f->tbl_typ, "%02d", TB_HOLI);
    e_memcpy(holi_tbl_f->frame_no, rq_tbl->frame_no);

    hi_comm_ctrl.frame_no = strtoul(tmp, NULL, 16);
    
    for(jj = 0; jj < 250; jj++)
    {
        isrc = lb_readl(isfd, &holi_tbl, FNEXT, sizeof(struct holi_info));

        if (isrc <= 0)
        {
            //lb_close(isfd);
            break;
        }

        e_memcpy(holi_tbl_f->holi[jj].year, holi_tbl.year);
        e_memcpy(holi_tbl_f->holi[jj].mon, holi_tbl.mon);
        e_memcpy(holi_tbl_f->holi[jj].day, holi_tbl.day);
    }

    lb_close(isfd);
    return (sizeof(struct hi_holi_tbl_f));
}

/*
*========================================================================
*
*   함 수 명 : snd_iss_comp_tbl
*   작 성 자 : JBY
*   작 성 일 : 2012.09.18
*   수 정 일 :
*   설    명 : 발행사정보 TABLE을 송신
*
*========================================================================
*/

int snd_iss_comp_tbl()
{
    struct    write_info    wf;
    struct    iss_comp_tbl  iss_comp_tbl;
    struct    hi_iss_comp_info_h   *iss_comp_h;
    struct    hi_iss_comp_info_f   *iss_comp_f;
    struct    hi_tbl_order    *rq_tbl;
    int    isrc;
    int    ii, pos, hexi;
    int    nframe_cnt;
    char tmp[10]; memset(tmp, 0x00, sizeof(tmp));
	char tmp2[10]; memset(tmp2, 0x00, sizeof(tmp));

    iss_comp_h = (struct hi_iss_comp_info_h *)hi_comm_ctrl.snd.buf;
    iss_comp_f = (struct hi_iss_comp_info_f *)hi_comm_ctrl.snd.buf;
    rq_tbl = (struct hi_tbl_order *)hi_comm_ctrl.rcv_ctrl.buf;

    memset(&iss_comp_tbl, 0x00, sizeof(iss_comp_tbl));

    isfd = lb_fopen(&wf, FNO_ISSCOMPTBL, FINPUT+FC_MANULOCK);
    if (isfd < 0)
    {
        lane_log( "Issue Company Open Fail[%d]\n", isfd);
        lb_close(isfd);
        return(-1);
    }

    sprintf(tmp, "%.8s%c", rq_tbl->frame_no, '\0');
    hexi = hextodig(rq_tbl->frame_no);

    if (strtoul(tmp, NULL, 16) == 0)
    {
        /* 발행사정보 TABLE HEADER */
        memset(iss_comp_h, 0, sizeof(struct hi_iss_comp_info_h));

        sprintf((char *)iss_comp_h->kind, "%02x", NS_TBL_DATA);
        sprintf((char *)iss_comp_h->tbl_typ, "%02d", TB_ISS_COMP);
        e_memcpy(iss_comp_h->frame_no, rq_tbl->frame_no);

        sprintf((char *)iss_comp_h->frame_cnt, "%08x", lb_record_cnt(isfd, FNO_ISSCOMPTBL) / 200);
        if ((lb_data2atoi(iss_comp_h->frame_cnt, 8) == 0) || (lb_record_cnt(isfd, FNO_ISSCOMPTBL) % 200) != 0)
        {
			sprintf(tmp2, "%.8s%c", iss_comp_h->frame_cnt, '\0');
            nframe_cnt = strtoul(tmp2, NULL, 16);;
            sprintf((char *)iss_comp_h->frame_cnt, "%08x", nframe_cnt + 1);
        }
        hi_comm_ctrl.frame_no = 0;

        e_memcpy(iss_comp_h->rvs_no, hi_comm_ctrl.bas_tbl.rvs_tbl_info[3].rvs_no);

        sprintf((char *)iss_comp_h->rgst_iss_cnt, "%08d", lb_record_cnt(isfd, FNO_ISSCOMPTBL));

        e_memcpy(iss_comp_h->iss_aply_year,  hi_comm_ctrl.bas_tbl.rvs_tbl_info[3].apl_year);
        e_memcpy(iss_comp_h->iss_aply_month, hi_comm_ctrl.bas_tbl.rvs_tbl_info[3].apl_mon);
        e_memcpy(iss_comp_h->iss_aply_day,   hi_comm_ctrl.bas_tbl.rvs_tbl_info[3].apl_day);
        e_memcpy(iss_comp_h->iss_aply_hour,  hi_comm_ctrl.bas_tbl.rvs_tbl_info[3].apl_hr);
        e_memcpy(iss_comp_h->iss_aply_min,   hi_comm_ctrl.bas_tbl.rvs_tbl_info[3].apl_min);

        e_memcpy(iss_comp_h->iss_modf_year,  hi_comm_ctrl.bas_tbl.rvs_tbl_info[3].modf_year);
        e_memcpy(iss_comp_h->iss_modf_month, hi_comm_ctrl.bas_tbl.rvs_tbl_info[3].modf_mon);
        e_memcpy(iss_comp_h->iss_modf_day,   hi_comm_ctrl.bas_tbl.rvs_tbl_info[3].modf_day);
        e_memcpy(iss_comp_h->iss_modf_hour,  hi_comm_ctrl.bas_tbl.rvs_tbl_info[3].modf_hr);
        e_memcpy(iss_comp_h->iss_modf_min,   hi_comm_ctrl.bas_tbl.rvs_tbl_info[3].modf_min);
        lb_close(isfd);
        return (sizeof(struct hi_iss_comp_info_h));
    } else if(strtoul(tmp, NULL, 16) == FRAME_LAST_I){
        memset(iss_comp_f, 0, sizeof(struct hi_iss_comp_info_f));

        sprintf((char *)iss_comp_f->kind, "%02x", NS_TBL_DATA);
        sprintf((char *)iss_comp_f->tbl_typ, "%02d", TB_ISS_COMP);
        sprintf((char *)iss_comp_f->frame_no, "%08x", FRAME_LAST_I);

        hi_comm_ctrl.frame_no = FRAME_LAST_I;
        lb_close(isfd);
        return (sizeof(struct hi_iss_comp_info_f));
    }

    pos = (hexi-1) * 200;
    lseek(isfd, pos * sizeof(struct iss_comp_tbl),SEEK_SET);

    memset(iss_comp_f, 0, sizeof(struct hi_iss_comp_info_f));
    sprintf((char *)iss_comp_f->kind, "%02x", NS_TBL_DATA);
    sprintf((char *)iss_comp_f->tbl_typ, "%02d", TB_ISS_COMP);
    e_memcpy(iss_comp_f->frame_no, rq_tbl->frame_no);

    hi_comm_ctrl.frame_no = strtoul(tmp, NULL, 16);

    for(ii=0; ii<200; ii++)
    {
        isrc = lb_readl(isfd, &iss_comp_tbl, FNEXT, sizeof(struct iss_comp_tbl));

        if (isrc <= 0)
        {
            //lb_close(isfd);
            break;
        }
        //sscanf((const char *)iss_comp_f->comp[ii].crd_co, "%2hhx", &iss_comp_tbl.crd_co);
		memcpy(&iss_comp_f->comp[ii].crd_co, iss_comp_tbl.crd_co, 2);
        memcpy(&iss_comp_f->comp[ii].bin_code, iss_comp_tbl.bin_code, 8);
    }

    lb_close(isfd);
    return (sizeof(struct hi_iss_comp_info_f));
}

/*
*========================================================================
*
*   함 수 명 : snd_imm_carno_tbl
*   작 성 자 : JBY
*   작 성 일 : 2019.05.11
*   수 정 일 :
*   설    명 : 차량번호 면제정보 TABLE을 송신
*
*========================================================================
*/

int snd_imm_carno_tbl()
{
    struct write_info    wf;
#ifndef _MSTCHG_
    struct imm_carno_info      imm_carno;
#else
    struct imm_carno_info      imm_carno_mst;
    struct imm_carno_info      imm_carno_chg;
#endif
    struct hi_imm_carno_tbl_h *imm_carno_h;
    struct hi_imm_carno_tbl_f *imm_carno_f;
    struct hi_tbl_order       *rq_tbl;
#ifdef _MSTCHG_
    struct bl_struct           bl_struct;
#endif
    int    isrc;
    int    ii, pos, hexi, row;
	int    tmp_ldyb[142];
    int    nframe_cnt, ret;

    char rtn[MAX_STRING_SIZE]; memset(rtn, 0x00, sizeof(rtn));
	char bak[MAX_STRING_SIZE]; memset(bak, 0x00, sizeof(bak));
    char rq_seq_no[10]; memset(rq_seq_no, 0x00, sizeof(rq_seq_no));
    char snd_no_m[10]; memset(snd_no_m, 0x00, sizeof(snd_no_m));
    char snd_no_c[10]; memset(snd_no_c, 0x00, sizeof(snd_no_c));
	char tmp_frame[10]; memset(tmp_frame, 0x00, sizeof(tmp_frame));

    memset(tmp_ldyb, '0', sizeof(tmp_ldyb));
    sprintf(wf.plz_id, "%.2s", PLZ_CODE2);
    lb_freadx(&wf, FNO_BASICTBL, &hi_comm_ctrl.bas_tbl, FFIRST);
    imm_carno_h = (struct hi_imm_carno_tbl_h *)hi_comm_ctrl.snd.buf;
    imm_carno_f = (struct hi_imm_carno_tbl_f *)hi_comm_ctrl.snd.buf;
    rq_tbl = (struct hi_tbl_order *)hi_comm_ctrl.rcv_ctrl.buf;

	sprintf(rq_seq_no, "%.8s%c", rq_tbl->req_seq_no, '\0');
    sprintf(tmp_frame, "%.8s%c", rq_tbl->frame_no, '\0');
    hexi = hextodig(rq_tbl->frame_no);
#ifndef _MSTCHG_
    memset(&imm_carno, 0x00, sizeof(struct imm_carno_info));

    isfd = lb_fopen(&wf, FNO_IMM_CARNO, FINPUT+FC_MANULOCK);
    if (isfd < 0)
    {
        lane_log( "차량번호 면제정보 Open Fail[%d]\n", isfd);
        lb_close(isfd);
        return(-1);
    }

    switch(strtoul(tmp_frame, NULL, 16) )
    {
		case 0:

        /* 차량번호 면제정보 TABLE HEADER */
        memset(imm_carno_h, 0, sizeof(struct hi_imm_carno_tbl_h));

        sprintf((char *)imm_carno_h->kind, "%02x", NS_TBL_DATA);
        sprintf((char *)imm_carno_h->tbl_typ, "%02d", TB_IMM_CARNO);
        e_memcpy(imm_carno_h->frame_no, rq_tbl->frame_no);

        sprintf((char *)imm_carno_h->frame_cnt, "%08x", lb_record_cnt(isfd, FNO_IMM_CARNO) / 167);
        if ((lb_data2atoi(imm_carno_h->frame_cnt, 8) == 0) || (lb_record_cnt(isfd, FNO_IMM_CARNO) % 167) != 0)
        {
            nframe_cnt = lb_data2atoi(imm_carno_h->frame_cnt, 8);
            sprintf((char *)imm_carno_h->frame_cnt, "%08x", nframe_cnt + 1);
        }
        hi_comm_ctrl.frame_no = 0;

        e_memcpy(imm_carno_h->rvs_no, hi_comm_ctrl.bas_tbl.rvs_tbl_info[4].rvs_no);

        sprintf((char *)imm_carno_h->rgst_imm_cnt, "%08d", lb_record_cnt(isfd, FNO_IMM_CARNO));

        e_memcpy(imm_carno_h->imm_aply_year,  hi_comm_ctrl.bas_tbl.rvs_tbl_info[4].apl_year);
        e_memcpy(imm_carno_h->imm_aply_month, hi_comm_ctrl.bas_tbl.rvs_tbl_info[4].apl_mon);
        e_memcpy(imm_carno_h->imm_aply_day,   hi_comm_ctrl.bas_tbl.rvs_tbl_info[4].apl_day);
        e_memcpy(imm_carno_h->imm_aply_hour,  hi_comm_ctrl.bas_tbl.rvs_tbl_info[4].apl_hr);
        e_memcpy(imm_carno_h->imm_aply_min,   hi_comm_ctrl.bas_tbl.rvs_tbl_info[4].apl_min);

        e_memcpy(imm_carno_h->imm_modf_year,  hi_comm_ctrl.bas_tbl.rvs_tbl_info[4].modf_year);
        e_memcpy(imm_carno_h->imm_modf_month, hi_comm_ctrl.bas_tbl.rvs_tbl_info[4].modf_mon);
        e_memcpy(imm_carno_h->imm_modf_day,   hi_comm_ctrl.bas_tbl.rvs_tbl_info[4].modf_day);
        e_memcpy(imm_carno_h->imm_modf_hour,  hi_comm_ctrl.bas_tbl.rvs_tbl_info[4].modf_hr);
        e_memcpy(imm_carno_h->imm_modf_min,   hi_comm_ctrl.bas_tbl.rvs_tbl_info[4].modf_min);
        lb_close(isfd);
		return (sizeof(struct hi_imm_carno_tbl_h));

        case FRAME_LAST_I:

        memset(imm_carno_f, 0, sizeof(struct hi_imm_carno_tbl_f));

        sprintf((char *)imm_carno_f->kind, "%02x", NS_TBL_DATA);
        sprintf((char *)imm_carno_f->tbl_typ, "%02d", TB_IMM_CARNO);
        sprintf((char *)imm_carno_f->frame_no, "%08x", FRAME_LAST_I);

        hi_comm_ctrl.frame_no = FRAME_LAST_I;
        lb_close(isfd);

        return (sizeof(struct hi_imm_carno_tbl_f));

        default:

        pos = (hexi-1) * 167;
        lseek(isfd, pos * sizeof(struct imm_carno_info),SEEK_SET);
        
        memset(imm_carno_f, 0, sizeof(struct hi_imm_carno_tbl_f));
        sprintf((char *)imm_carno_f->kind, "%02x", NS_TBL_DATA);
        sprintf((char *)imm_carno_f->tbl_typ, "%02d", TB_IMM_CARNO);
        e_memcpy(imm_carno_f->frame_no, rq_tbl->frame_no);
        
        hi_comm_ctrl.frame_no = strtoul(rq_seq_no, NULL, 16);
        
        for(ii=0; ii<167; ii++)
        {
            isrc = lb_readl(isfd, &imm_carno, FNEXT, sizeof(struct imm_carno_info));
        
            if (isrc <= 0)
            {
                //lb_close(isfd);
                break;
            }
        
            memcpy(&imm_carno_f->imm_info[ii].imm_div, imm_carno.div, 2);
            memcpy(&imm_carno_f->imm_info[ii].car_no, imm_carno.carno_code, 10);
        }
        
        lb_close(isfd);
	    
        return (sizeof(struct hi_imm_carno_tbl_f));
    }
	lb_close(isfd);
#else
	if(lb_data2atoi((char *)rq_tbl->data_div, 2) == 1)
	{
	    e_memcpy(bl_struct.plz_id, hi_comm_ctrl.bas_tbl.plz_id);
//lane_log("LANE[%d]\n", hi_comm_ctrl.lane_no);

		sprintf((char *)bl_struct.lane_no, "%02d", hi_comm_ctrl.lane_no);
		sprintf((char *)bl_struct.seq_no, "%08x", hi_comm_ctrl.snd.snd_no);
		sprintf((char *)bl_struct.file_id, "%02d", FNO_IMM_CARNO);
		e_memcpy(bl_struct.rvs_no, hi_comm_ctrl.bas_tbl.rvs_tbl_info[4].rvs_no);
        e_memcpy(bl_struct.rvs_year,  hi_comm_ctrl.bas_tbl.rvs_tbl_info[4].apl_year);
        e_memcpy(bl_struct.rvs_month, hi_comm_ctrl.bas_tbl.rvs_tbl_info[4].apl_mon);
        e_memcpy(bl_struct.rvs_day,   hi_comm_ctrl.bas_tbl.rvs_tbl_info[4].apl_day);
        e_memcpy(bl_struct.rvs_hour,  hi_comm_ctrl.bas_tbl.rvs_tbl_info[4].apl_hr);
        e_memcpy(bl_struct.rvs_min,   hi_comm_ctrl.bas_tbl.rvs_tbl_info[4].apl_min);

        e_memcpy(bl_struct.modf_year,  hi_comm_ctrl.bas_tbl.rvs_tbl_info[4].modf_year);
        e_memcpy(bl_struct.modf_month, hi_comm_ctrl.bas_tbl.rvs_tbl_info[4].modf_mon);
        e_memcpy(bl_struct.modf_day,   hi_comm_ctrl.bas_tbl.rvs_tbl_info[4].modf_day);
        e_memcpy(bl_struct.modf_hour,  hi_comm_ctrl.bas_tbl.rvs_tbl_info[4].modf_hr);
        e_memcpy(bl_struct.modf_min,   hi_comm_ctrl.bas_tbl.rvs_tbl_info[4].modf_min);

	    sprintf(bak, "%.2s%.2s%.8s%.2s%.2s%.4s%.2s%.2s%.2s%.2s%.4s%.2s%.2s%.2s%.2s%c", bl_struct.plz_id, bl_struct.lane_no, bl_struct.seq_no, bl_struct.file_id, bl_struct.rvs_no,
		             bl_struct.rvs_year, bl_struct.rvs_month, bl_struct.rvs_day, bl_struct.rvs_hour, bl_struct.rvs_min,
					 bl_struct.modf_year, bl_struct.modf_month, bl_struct.modf_day, bl_struct.modf_hour, bl_struct.modf_min, '\0');

		//lane_log("[senddata_handle] FNO_IMM_CARNO MST [%s]\n", bak);
		
		ret = MessageSender(hi_comm_ctrl.rcv_ctrl.cmd, (char *)&bak, "lane_run", rtn);
		
		return(0);
	}else if(lb_data2atoi((char *)rq_tbl->data_div, 2) == 2)
	{
		memset(imm_carno_h, 0, sizeof(struct hi_imm_carno_tbl_h));
        sprintf((char *)imm_carno_h->kind, "%02x", NS_TBL_DATA);
        sprintf((char *)imm_carno_h->tbl_typ, "%02d", TB_IMM_CARNO);
        sprintf((char *)imm_carno_h->frame_no, "00000000");
		sprintf((char *)imm_carno_h->frame_cnt, "00000000");

		isfd = lb_freadx(&wf, FNO_IMM_CARNO, &imm_carno_mst, FLAST);
		sprintf(snd_no_m, "%08x%c", lb_data2atoi(imm_carno_mst.snd_no, 10), '\0');
		//lb_close(isfd);
		isfd = lb_freadx(&wf, FNO_IMM_CARNO_CHG, &imm_carno_chg, FFIRST);
		sprintf(snd_no_c, "%08x%c", lb_data2atoi(imm_carno_chg.snd_no, 10), '\0');
//lane_log("IMM MST[%.8s] CHG[%.8s]\n", snd_no_m, snd_no_c);
        if(isfd < 0 || strtoul(rq_seq_no, NULL, 16) < strtoul(snd_no_c, NULL, 16) && strtoul(rq_seq_no, NULL, 16) < strtoul(snd_no_m, NULL, 16))
		{
			lane_log("Change IMM CarNo Error \n");
			//lb_close(isfd);
			
			isfd = lb_freadx(&wf, FNO_IMM_CARNO, &imm_carno_mst, FLAST);
			sprintf(snd_no_m, "%08x%c", lb_data2atoi(imm_carno_mst.snd_no, 10), '\0');

			if(isfd < 0 || strtoul(rq_seq_no, NULL, 16) <= strtoul(snd_no_m, NULL, 16))
			{
				lane_log("Master Request again\n");
				sprintf((char *)imm_carno_h->div, "01");
				//lb_close(isfd);
				return(sizeof(struct hi_imm_carno_tbl_h));
			}
			sprintf((char *)imm_carno_h->div, "01");
			//lb_close(isfd);
			return(sizeof(struct hi_imm_carno_tbl_h));
		}else
		{
			lb_close(isfd);
			isfd = lb_freadx(&wf, FNO_IMM_CARNO_CHG, &imm_carno_chg, FLAST);
			sprintf(snd_no_c, "%08x%c", lb_data2atoi(imm_carno_chg.snd_no, 10), '\0');

            if(strtoul(rq_seq_no, NULL, 16) > strtoul(snd_no_c, NULL, 16))
			{
				lane_log("Request Seq Error Master Request again\n");
				sprintf((char *)imm_carno_h->div, "01");
				//lb_close(isfd);
				return(sizeof(struct hi_imm_carno_tbl_h));
			}else if(strtoul(rq_seq_no, NULL, 16) == strtoul(snd_no_c, NULL, 16))
			{
				lane_log("ISS Change Not exist RQ_SEQ[%.8s] Change[%.8s]\n", rq_seq_no, snd_no_c);
				sprintf((char *)imm_carno_h->div, "02");
				//lb_close(isfd);
				return(sizeof(struct hi_imm_carno_tbl_h));
			}
		}

        //lb_close(isfd);
		isfd = lb_fopen(&wf, FNO_IMM_CARNO_CHG, FINPUT+FC_MANULOCK);
		lseek(isfd, 0, SEEK_SET);
		
		sprintf(tmp_frame, "%.8s%c", rq_tbl->frame_no, '\0');
//lane_log("IMM Change Start\n");
        switch(strtoul(tmp_frame, NULL, 16))
		{
			case 0: //Header
//lane_log("IMM Change 1\n");
            e_memcpy(imm_carno_h->rvs_no, hi_comm_ctrl.bas_tbl.rvs_tbl_info[4].rvs_no);
			//memset(imm_carno_f, 0, sizeof(struct hi_imm_carno_tbl_f));
			memset(&imm_carno_chg, 0, sizeof(struct imm_carno_info));
//lane_log("IMM Change 2\n");			
			row = lb_record_cnt(isfd, FNO_IMM_CARNO_CHG);
//lane_log("IMM Change 3\n");
			if(row < 0)
			{
				row = 0;
				lane_log("IMM Master row not exist\n"); 
			}
//lane_log("IMM Change 4\n");
			nframe_cnt = row / 142;
//lane_log("IMM Change 5\n");
            if ((nframe_cnt == 0 && row != 0) || (row % 142) != 0)
                nframe_cnt++;
//lane_log("IMM Change 6\n");
            hi_comm_ctrl.frame_no = 0;
//lane_log("IMM Change 7\n");
            lb_close(isfd);
//lane_log("IMM Change 8\n");
            sprintf((char *)imm_carno_h->kind, "%02x", NS_TBL_DATA);
            sprintf((char *)imm_carno_h->tbl_typ, "%02d", TB_IMM_CARNO);
            sprintf((char *)imm_carno_h->frame_no, "00000000");
            sprintf((char *)imm_carno_h->frame_cnt, "%08x", nframe_cnt);
            sprintf((char *)imm_carno_h->rvs_no, "%.2s", hi_comm_ctrl.bas_tbl.rvs_tbl_info[4].rvs_no);
            sprintf((char *)imm_carno_h->div, "00");
            e_memcpy(imm_carno_h->imm_aply_year,  hi_comm_ctrl.bas_tbl.rvs_tbl_info[4].apl_year);
            e_memcpy(imm_carno_h->imm_aply_month, hi_comm_ctrl.bas_tbl.rvs_tbl_info[4].apl_mon);
            e_memcpy(imm_carno_h->imm_aply_day,   hi_comm_ctrl.bas_tbl.rvs_tbl_info[4].apl_day);
            e_memcpy(imm_carno_h->imm_aply_hour,  hi_comm_ctrl.bas_tbl.rvs_tbl_info[4].apl_hr);
            e_memcpy(imm_carno_h->imm_aply_min,   hi_comm_ctrl.bas_tbl.rvs_tbl_info[4].apl_min);
            
            e_memcpy(imm_carno_h->imm_modf_year,  hi_comm_ctrl.bas_tbl.rvs_tbl_info[4].modf_year);
            e_memcpy(imm_carno_h->imm_modf_month, hi_comm_ctrl.bas_tbl.rvs_tbl_info[4].modf_mon);
            e_memcpy(imm_carno_h->imm_modf_day,   hi_comm_ctrl.bas_tbl.rvs_tbl_info[4].modf_day);
            e_memcpy(imm_carno_h->imm_modf_hour,  hi_comm_ctrl.bas_tbl.rvs_tbl_info[4].modf_hr);
            e_memcpy(imm_carno_h->imm_modf_min,   hi_comm_ctrl.bas_tbl.rvs_tbl_info[4].modf_min);

            return (sizeof(struct hi_imm_carno_tbl_h));

			case FRAME_LAST_I:
            sprintf((char *)imm_carno_h->kind, "%02x", NS_TBL_DATA);
            sprintf((char *)imm_carno_h->tbl_typ, "%02d", TB_IMM_CARNO);
			sprintf((char *)imm_carno_h->frame_no, "%08x", FRAME_LAST_I);
			lb_close(isfd);

			return (sizeof(struct hi_imm_carno_tbl_h));
			
			default:
			
			memset(imm_carno_f, 0, sizeof(struct hi_imm_carno_tbl_f));
            memset(&imm_carno_chg, 0, sizeof(struct imm_carno_info));
			
			lane_log("IMM Change Data[%.8s]\n", tmp_frame);
			
			pos = (hexi-1) * 142;
			lseek(isfd, pos * sizeof(struct imm_carno_info),SEEK_SET);
			
			row = 0;
			
			for(ii = 0; ii < 142; ii++)
			{
				isrc = lb_readl(isfd, &imm_carno_chg, FNEXT, sizeof(struct imm_carno_info));
				if(isrc <= 0) break;
				
				sprintf(snd_no_c, "%08x%c", lb_data2atoi(imm_carno_chg.snd_no, 10), '\0');
                tmp_ldyb[ii] = strtoul(snd_no_c, NULL, 16); 
                row++;
			}
			
			sprintf((char *)imm_carno_f->kind, "%02x", NS_TBL_DATA);
			sprintf((char *)imm_carno_f->tbl_typ, "%02d", TB_IMM_CARNO);
			hi_comm_ctrl.frame_no = strtoul(tmp_frame, NULL, 16);
			e_memcpy(imm_carno_f->frame_no, rq_tbl->frame_no);
			
			if(row == 0)
			{
				sprintf((char *)imm_carno_f->last_data_seq_no, "00000000");
				sprintf((char *)imm_carno_f->item_cnt, "00");
			}else{
				sprintf((char *)imm_carno_f->last_data_seq_no, "%08x", tmp_ldyb[row-1]);
				sprintf((char *)imm_carno_f->item_cnt, "%02x", row);
			}
			
			lseek(isfd, -row*sizeof(struct imm_carno_info), SEEK_CUR);

			for(ii = 0; ii < 142; ii++)
            {
                isrc = lb_readl(isfd, &imm_carno_chg, FNEXT, sizeof(struct imm_carno_info));
                if (isrc <= 0) break;
            
                sprintf((char *)imm_carno_f->imm_info[ii].rgst_div, "%.2s", imm_carno_chg.rgst_div);
				sprintf((char *)imm_carno_f->imm_info[ii].imm_div, "%.2s", imm_carno_chg.div);
                sprintf((char *)imm_carno_f->imm_info[ii].car_no, "%.24s", imm_carno_chg.carno_code);
            }

            if (isrc <= 0 && !ii)
            {
                hi_comm_ctrl.frame_no = FRAME_LAST_I;
                sprintf((char *)imm_carno_f->frame_no, "%08x", FRAME_LAST_I);
                lb_close(isfd);
                return (sizeof(struct hi_imm_carno_tbl_f));
            }

            lb_close(isfd);
            return (sizeof(struct hi_imm_carno_tbl_f));
		}
	}else{
        lane_log( "ISS CarNo TableData Request Error!\n");
        //lb_close(isfd);
        return (-1);
	}
#endif

}

/*
*========================================================================
*
*   함 수 명 : snd_imm_cardno_tbl
*   작 성 자 : JBY
*   작 성 일 : 2019.05.11
*   수 정 일 :
*   설    명 : 카드번호 면제정보 TABLE을 송신
*
*========================================================================
*/

int snd_imm_cardno_tbl()
{
    struct write_info    wf;
#ifndef _MSTCHG_
    struct imm_card_info      imm_card_info;
#else
    struct imm_card_info      imm_card_mst;
    struct imm_card_info      imm_card_chg;
#endif
    struct hi_imm_crdno_tbl_h *imm_crdno_h;
    struct hi_imm_crdno_tbl_f *imm_crdno_f;
    struct hi_tbl_order       *rq_tbl;
#ifdef _MSTCHG_
    struct bl_struct           bl_struct;
#endif
    int    isrc;
    int    ii, pos, hexi, row;
	int    tmp_ldyb[49];
    int    nframe_cnt, ret;

    char rtn[MAX_STRING_SIZE]; memset(rtn, 0x00, sizeof(rtn));
	char bak[MAX_STRING_SIZE]; memset(bak, 0x00, sizeof(bak));
    char rq_seq_no[10]; memset(rq_seq_no, 0x00, sizeof(rq_seq_no));
    char snd_no_m[10]; memset(snd_no_m, 0x00, sizeof(snd_no_m));
    char snd_no_c[10]; memset(snd_no_c, 0x00, sizeof(snd_no_c));
	char tmp_frame[10]; memset(tmp_frame, 0x00, sizeof(tmp_frame));
    sprintf(wf.plz_id, "%.2s", PLZ_CODE2);
    lb_freadx(&wf, FNO_BASICTBL, &hi_comm_ctrl.bas_tbl, FFIRST);
    memset(tmp_ldyb, '0', sizeof(tmp_ldyb));

    imm_crdno_h = (struct hi_imm_crdno_tbl_h *)hi_comm_ctrl.snd.buf;
    imm_crdno_f = (struct hi_imm_crdno_tbl_f *)hi_comm_ctrl.snd.buf;
    rq_tbl = (struct hi_tbl_order *)hi_comm_ctrl.rcv_ctrl.buf;

	sprintf(rq_seq_no, "%.8s%c", rq_tbl->req_seq_no, '\0');
    sprintf(tmp_frame, "%.8s%c", rq_tbl->frame_no, '\0');
    hexi = hextodig(rq_tbl->frame_no);

#ifndef _MSTCHG_
    memset(&imm_card_info, 0x00, sizeof(struct imm_card_info));

    isfd = lb_fopen(&wf, FNO_IMM_CARDNO, FINPUT+FC_MANULOCK);
    if (isfd < 0)
    {
        lane_log( "카드번호 면제정보 Open Fail[%d]\n", isfd);
        lb_close(isfd);
        return(-1);
    }

    sprintf(tmp_frame, "%.8s%c", rq_tbl->frame_no, '\0');
    hexi = hextodig(rq_tbl->frame_no);

    if (strtoul(tmp_frame, NULL, 16) == 0)
    {
        /* 카드번호 면제정보 TABLE HEADER */
        memset(imm_crdno_h, 0, sizeof(struct hi_imm_crdno_tbl_h));

        sprintf((char *)imm_crdno_h->kind, "%02x", NS_TBL_DATA);
        sprintf((char *)imm_crdno_h->tbl_typ, "%02d", TB_IMM_CRDNO);
        e_memcpy(imm_crdno_h->frame_no, rq_tbl->frame_no);
        e_memcpy(imm_crdno_h->rvs_no, hi_comm_ctrl.bas_tbl.rvs_tbl_info[5].rvs_no);
        sprintf((char *)imm_crdno_h->frame_cnt, "%08x", lb_record_cnt(isfd, FNO_IMM_CARDNO) / 49);
        if ((lb_data2atoi(imm_crdno_h->frame_cnt, 8) == 0) || (lb_record_cnt(isfd, FNO_IMM_CARDNO) % 49) != 0)
        {
            nframe_cnt = lb_data2atoi(imm_crdno_h->frame_cnt, 8);
            sprintf((char *)imm_crdno_h->frame_cnt, "%08x", nframe_cnt + 1);
        }
        hi_comm_ctrl.frame_no = 0;

        sprintf((char *)imm_crdno_h->rgst_imm_cnt, "%08d", lb_record_cnt(isfd, FNO_IMM_CARDNO));

        e_memcpy(imm_crdno_h->imm_aply_year,  hi_comm_ctrl.bas_tbl.rvs_tbl_info[5].apl_year);
        e_memcpy(imm_crdno_h->imm_aply_month, hi_comm_ctrl.bas_tbl.rvs_tbl_info[5].apl_mon);
        e_memcpy(imm_crdno_h->imm_aply_day,   hi_comm_ctrl.bas_tbl.rvs_tbl_info[5].apl_day);
        e_memcpy(imm_crdno_h->imm_aply_hour,  hi_comm_ctrl.bas_tbl.rvs_tbl_info[5].apl_hr);
        e_memcpy(imm_crdno_h->imm_aply_min,   hi_comm_ctrl.bas_tbl.rvs_tbl_info[5].apl_min);
        
        e_memcpy(imm_crdno_h->imm_modf_year,  hi_comm_ctrl.bas_tbl.rvs_tbl_info[5].modf_year);
        e_memcpy(imm_crdno_h->imm_modf_month, hi_comm_ctrl.bas_tbl.rvs_tbl_info[5].modf_mon);
        e_memcpy(imm_crdno_h->imm_modf_day,   hi_comm_ctrl.bas_tbl.rvs_tbl_info[5].modf_day);
        e_memcpy(imm_crdno_h->imm_modf_hour,  hi_comm_ctrl.bas_tbl.rvs_tbl_info[5].modf_hr);
        e_memcpy(imm_crdno_h->imm_modf_min,   hi_comm_ctrl.bas_tbl.rvs_tbl_info[5].modf_min);
        lb_close(isfd);
        return (sizeof(struct hi_imm_crdno_tbl_h));
    } else if(strtoul(tmp_frame, NULL, 16) == FRAME_LAST_I){
        memset(imm_crdno_f, 0, sizeof(struct hi_imm_crdno_tbl_f));

        sprintf((char *)imm_crdno_f->kind, "%02x", NS_TBL_DATA);
        sprintf((char *)imm_crdno_f->tbl_typ, "%02d", TB_IMM_CRDNO);
        sprintf((char *)imm_crdno_f->frame_no, "%08x", FRAME_LAST_I);

        hi_comm_ctrl.frame_no = FRAME_LAST_I;
        lb_close(isfd);
        return (sizeof(struct hi_imm_crdno_tbl_f));
    }

    pos = (hexi-1) * 49;
    lseek(isfd, pos * sizeof(struct imm_card_info),SEEK_SET);

    memset(imm_crdno_f, 0, sizeof(struct hi_imm_crdno_tbl_f));
    sprintf((char *)imm_crdno_f->kind, "%02x", NS_TBL_DATA);
    sprintf((char *)imm_crdno_f->tbl_typ, "%02d", TB_IMM_CRDNO);
    e_memcpy(imm_crdno_f->frame_no, rq_tbl->frame_no);

    hi_comm_ctrl.frame_no = strtoul(tmp_frame, NULL, 16);

    for(ii=0; ii<49; ii++)
    {
        isrc = lb_readl(isfd, &imm_card_info, FNEXT, sizeof(struct imm_card_info));

        if (isrc <= 0)
        {
            //lb_close(isfd);
            break;
        }

        imm_crdno_f->imm_info[ii].car_div = imm_card_info.div;
        e_memcpy(&imm_crdno_f->imm_info[ii].crd_no,  imm_card_info.tag_id);
        e_memcpy(&imm_crdno_f->imm_info[ii].car_no,  imm_card_info.carno_code);
        imm_crdno_f->imm_info[ii].unap_div = imm_card_info.non_cnt;
        imm_crdno_f->imm_info[ii].vio_div = imm_card_info.vio_cnt;
    }

    lb_close(isfd);
    return (sizeof(struct hi_imm_crdno_tbl_f));
#else
    if(lb_data2atoi((char *)rq_tbl->data_div, 2) == 1)
    {
        sprintf((char *)bl_struct.plz_id, "%.2s", hi_comm_ctrl.bas_tbl.plz_id);
        sprintf((char *)bl_struct.lane_no, "%02d", hi_comm_ctrl.lane_no);
        sprintf((char *)bl_struct.seq_no, "%08x", hi_comm_ctrl.snd.snd_no);
        sprintf((char *)bl_struct.file_id, "%02d", FNO_IMM_CARDNO);
        e_memcpy(bl_struct.rvs_no, hi_comm_ctrl.bas_tbl.rvs_tbl_info[5].rvs_no);
        e_memcpy(bl_struct.rvs_year,  hi_comm_ctrl.bas_tbl.rvs_tbl_info[5].apl_year);
        e_memcpy(bl_struct.rvs_month, hi_comm_ctrl.bas_tbl.rvs_tbl_info[5].apl_mon);
        e_memcpy(bl_struct.rvs_day,   hi_comm_ctrl.bas_tbl.rvs_tbl_info[5].apl_day);
        e_memcpy(bl_struct.rvs_hour,  hi_comm_ctrl.bas_tbl.rvs_tbl_info[5].apl_hr);
        e_memcpy(bl_struct.rvs_min,   hi_comm_ctrl.bas_tbl.rvs_tbl_info[5].apl_min);

        e_memcpy(bl_struct.modf_year,  hi_comm_ctrl.bas_tbl.rvs_tbl_info[5].modf_year);
        e_memcpy(bl_struct.modf_month, hi_comm_ctrl.bas_tbl.rvs_tbl_info[5].modf_mon);
        e_memcpy(bl_struct.modf_day,   hi_comm_ctrl.bas_tbl.rvs_tbl_info[5].modf_day);
        e_memcpy(bl_struct.modf_hour,  hi_comm_ctrl.bas_tbl.rvs_tbl_info[5].modf_hr);
        e_memcpy(bl_struct.modf_min,   hi_comm_ctrl.bas_tbl.rvs_tbl_info[5].modf_min);

	    sprintf(bak, "%.2s%.2s%.8s%.2s%.2s%.4s%.2s%.2s%.2s%.2s%.4s%.2s%.2s%.2s%.2s%c", bl_struct.plz_id, bl_struct.lane_no, bl_struct.seq_no, bl_struct.file_id, bl_struct.rvs_no,
		             bl_struct.rvs_year, bl_struct.rvs_month, bl_struct.rvs_day, bl_struct.rvs_hour, bl_struct.rvs_min,
					 bl_struct.modf_year, bl_struct.modf_month, bl_struct.modf_day, bl_struct.modf_hour, bl_struct.modf_min, '\0');
        
        lane_log("[senddata_handle] FNO_IMM_CARDNO MST [%s]\n", bak);

        ret = MessageSender(hi_comm_ctrl.rcv_ctrl.cmd, (char *)&bak, "lane_run", rtn);
        //lb_close(isfd);
        return(0);
    }else if(lb_data2atoi((char *)rq_tbl->data_div, 2) == 2)
    {
        sprintf((char *)imm_crdno_h->kind, "%02x", NS_TBL_DATA);
        sprintf((char *)imm_crdno_h->tbl_typ, "%02d", TB_IMM_CRDNO);
        sprintf((char *)imm_crdno_h->frame_no, "00000000");
        sprintf((char *)imm_crdno_h->frame_cnt, "00000000");

        isfd = lb_freadx(&wf, FNO_IMM_CARDNO, &imm_card_mst, FLAST);
        sprintf(snd_no_m, "%08x%c", lb_data2atoi(imm_card_mst.snd_no, 10), '\0');
        //lb_close(isfd);
        isfd = lb_freadx(&wf, FNO_IMM_CARDNO_CHG, &imm_card_chg, FFIRST);
        sprintf(snd_no_c, "%08x%c", lb_data2atoi(imm_card_chg.snd_no, 10), '\0');
//lane_log("IMM MST[%.8s] CHG[%.8s]\n", snd_no_m, snd_no_c);
        if(isfd < 0 || strtoul(rq_seq_no, NULL, 16) < strtoul(snd_no_c, NULL, 16) && strtoul(rq_seq_no, NULL, 16) < strtoul(snd_no_m, NULL, 16))
        {
            lane_log("Change IMM CardNo Error \n");
            //lb_close(isfd);
            
            isfd = lb_freadx(&wf, FNO_IMM_CARDNO, &imm_card_mst, FLAST);
            sprintf(snd_no_m, "%08x%c", lb_data2atoi(imm_card_mst.snd_no, 10), '\0');

            if(isfd < 0 || strtoul(rq_seq_no, NULL, 16) <= strtoul(snd_no_m, NULL, 16))
            {
                lane_log("Master Request again\n");
                sprintf((char *)imm_crdno_h->div, "01");
                //lb_close(isfd);
                return(sizeof(struct hi_imm_crdno_tbl_h));
            }
            sprintf((char *)imm_crdno_h->div, "01");
            //lb_close(isfd);
            return(sizeof(struct hi_imm_crdno_tbl_h));
        }else
        {
            //lb_close(isfd);
            isfd = lb_freadx(&wf, FNO_IMM_CARDNO_CHG, &imm_card_chg, FLAST);
            sprintf(snd_no_c, "%08x%c", lb_data2atoi(imm_card_chg.snd_no, 10), '\0');

            if(strtoul(rq_seq_no, NULL, 16) > strtoul(snd_no_c, NULL, 16))
            {
                lane_log("Request Seq Error Master Request again\n");
                sprintf((char *)imm_crdno_h->div, "01");
                //lb_close(isfd);
                return(sizeof(struct hi_imm_crdno_tbl_h));
            }else if(strtoul(rq_seq_no, NULL, 16) == strtoul(snd_no_c, NULL, 16))
            {
                lane_log("ISS Change Not exist RQ_SEQ[%.8s] Change[%.8s]\n", rq_seq_no, snd_no_c);
                sprintf((char *)imm_crdno_h->div, "02");
                //lb_close(isfd);
                return(sizeof(struct hi_imm_crdno_tbl_h));
            }
        }

        isfd = lb_fopen(&wf, FNO_IMM_CARDNO_CHG, FINPUT+FC_MANULOCK);
        lseek(isfd, 0, SEEK_SET);
        
        sprintf(tmp_frame, "%.8s%c", rq_tbl->frame_no, '\0');
//lane_log("IMM Change Start\n");
        switch(strtoul(tmp_frame, NULL, 16))
        {
            case 0: //Header

            e_memcpy(imm_crdno_h->rvs_no, hi_comm_ctrl.bas_tbl.rvs_tbl_info[5].rvs_no);
            //memset(imm_crdno_f, 0, sizeof(struct hi_imm_crdno_tbl_f));
            memset(&imm_card_chg, 0, sizeof(struct imm_card_info));
            
            row = lb_record_cnt(isfd, FNO_IMM_CARDNO_CHG);
            
            if(row < 0)
            {
                row = 0;
                lane_log("IMM Master row not exist\n"); 
            }
            
            nframe_cnt = row / 49;

            if ((nframe_cnt == 0 && row != 0) || (row % 49) != 0)
                nframe_cnt++;

            hi_comm_ctrl.frame_no = 0;

            lb_close(isfd);

            sprintf((char *)imm_crdno_h->frame_cnt, "%08x", nframe_cnt);
            sprintf((char *)imm_crdno_h->rvs_no, "%.2s", hi_comm_ctrl.bas_tbl.rvs_tbl_info[5].rvs_no);
            sprintf((char *)imm_crdno_h->div, "00");
            e_memcpy(imm_crdno_h->imm_aply_year,  hi_comm_ctrl.bas_tbl.rvs_tbl_info[5].apl_year);
            e_memcpy(imm_crdno_h->imm_aply_month, hi_comm_ctrl.bas_tbl.rvs_tbl_info[5].apl_mon);
            e_memcpy(imm_crdno_h->imm_aply_day,   hi_comm_ctrl.bas_tbl.rvs_tbl_info[5].apl_day);
            e_memcpy(imm_crdno_h->imm_aply_hour,  hi_comm_ctrl.bas_tbl.rvs_tbl_info[5].apl_hr);
            e_memcpy(imm_crdno_h->imm_aply_min,   hi_comm_ctrl.bas_tbl.rvs_tbl_info[5].apl_min);
            
            e_memcpy(imm_crdno_h->imm_modf_year,  hi_comm_ctrl.bas_tbl.rvs_tbl_info[5].modf_year);
            e_memcpy(imm_crdno_h->imm_modf_month, hi_comm_ctrl.bas_tbl.rvs_tbl_info[5].modf_mon);
            e_memcpy(imm_crdno_h->imm_modf_day,   hi_comm_ctrl.bas_tbl.rvs_tbl_info[5].modf_day);
            e_memcpy(imm_crdno_h->imm_modf_hour,  hi_comm_ctrl.bas_tbl.rvs_tbl_info[5].modf_hr);
            e_memcpy(imm_crdno_h->imm_modf_min,   hi_comm_ctrl.bas_tbl.rvs_tbl_info[5].modf_min);

            //lb_close(isfd);
            return (sizeof(struct hi_imm_crdno_tbl_h));

            case FRAME_LAST_I:
            
            sprintf((char *)imm_crdno_h->frame_no, "%08x", FRAME_LAST_I);
            lb_close(isfd);

            return (sizeof(struct hi_imm_crdno_tbl_h));
            
            default:
            
            memset(imm_crdno_f, 0, sizeof(struct hi_imm_crdno_tbl_f));
            memset(&imm_card_chg, 0, sizeof(struct imm_card_info));
            
            lane_log("IMM Change Data[%.8s]\n", tmp_frame);
            
            pos = (hexi-1) * 49;
            lseek(isfd, pos * sizeof(struct imm_card_info),SEEK_SET);
            
            row = 0;
            
            for(ii = 0; ii < 49; ii++)
            {
                isrc = lb_readl(isfd, &imm_card_chg, FNEXT, sizeof(struct imm_card_info));
                if(isrc <= 0) break;
                
                sprintf(snd_no_c, "%08x%c", lb_data2atoi(imm_card_chg.snd_no, 10), '\0');
                tmp_ldyb[ii] = strtoul(snd_no_c, NULL, 16); 
                row++;
            }
            
            sprintf((char *)imm_crdno_f->kind, "%02x", NS_TBL_DATA);
            sprintf((char *)imm_crdno_f->tbl_typ, "%02d", TB_IMM_CRDNO);
            hi_comm_ctrl.frame_no = strtoul(tmp_frame, NULL, 16);
            e_memcpy(imm_crdno_f->frame_no, rq_tbl->frame_no);
            
            if(row == 0)
            {
                sprintf((char *)imm_crdno_f->last_data_seq_no, "00000000");
                sprintf((char *)imm_crdno_f->item_cnt, "00");
            }else{
                sprintf((char *)imm_crdno_f->last_data_seq_no, "%08x", tmp_ldyb[row-1]);
                sprintf((char *)imm_crdno_f->item_cnt, "%02x", row);
            }
            
            lseek(isfd, -row*sizeof(struct imm_card_info), SEEK_CUR);
			
            for(ii = 0; ii < 49; ii++)
            {
                isrc = lb_readl(isfd, &imm_card_chg, FNEXT, sizeof(struct imm_card_info));
                if (isrc <= 0) break;
            
                sprintf((char *)imm_crdno_f->imm_info[ii].rgst_div, "%.2s", imm_card_chg.rgst_div);
                imm_crdno_f->imm_info[ii].car_div = imm_card_chg.div;
                sprintf((char *)imm_crdno_f->imm_info[ii].crd_no, "%.24s", imm_card_chg.tag_id);
				sprintf((char *)imm_crdno_f->imm_info[ii].car_no, "%.10s", imm_card_chg.carno_code);
				imm_crdno_f->imm_info[ii].unap_div = imm_card_chg.non_cnt;
				imm_crdno_f->imm_info[ii].vio_div = imm_card_chg.vio_cnt;
            }

            if (isrc <= 0 && !ii)
            {
                hi_comm_ctrl.frame_no = FRAME_LAST_I;
                sprintf((char *)imm_crdno_f->frame_no, "%08x", FRAME_LAST_I);
                lb_close(isfd);
                return (sizeof(struct hi_imm_crdno_tbl_f));
            }

            lb_close(isfd);
            return (sizeof(struct hi_imm_crdno_tbl_f));
        }
    }else{
        lane_log( "ISS CarNo TableData Request Error!\n");
        //lb_close(isfd);
        return (-1);
    }
#endif
}

/*
*========================================================================
*
*   함 수 명 : snd_adv_pay_tbl
*   작 성 자 : JBY
*   작 성 일 : 2019.05.11
*   수 정 일 :
*   설    명 : 사전등록 TABLE 송신
*              Master -> Background / Change -> lane_svr process
*
*========================================================================
*/

int snd_adv_pay_tbl()
{
    static    int     all_row;
    struct    write_info     wf;
    struct    bef_mst_tbl     adv_pay_mst;
    struct    bef_chg_tbl     adv_pay_chg;
    struct    hi_adv_payment_tbl_h  *adv_pay_h;
    struct    hi_adv_payment_tbl_f  *adv_pay_f;
    struct    bl_struct        adv_struct;
    struct    hi_tbl_order       *rq_tbl;
    int    pos, isrc, ii, ret, row=0, hexi =0;
    unsigned int tmp_tybl=0;
    int    tmp_ldyb[166];
    int    nframe_cnt;
    int    typ = 0;
    char rq_seq_no[10]; memset(rq_seq_no, 0x00, sizeof(rq_seq_no));
    char snd_no_m[10]; memset(snd_no_m, 0x00, sizeof(snd_no_m));
    char snd_no_c[10]; memset(snd_no_c, 0x00, sizeof(snd_no_c));
    char rtn[MAX_STRING_SIZE]; memset(rtn, 0x00, sizeof(rtn));
	char bak[MAX_STRING_SIZE]; memset(bak, 0x00, sizeof(bak));
    char tmp_frame[10]; memset(tmp_frame, 0x00, sizeof(tmp_frame));
#ifdef _DEF_REQ_ 
    //2020.02.14 요구전송연번 적용
	int  chg_seek = 0;
	int  chk_chghead = 0;
#endif
    sprintf(wf.plz_id, "%.2s", PLZ_CODE2);
    lb_freadx(&wf, FNO_BASICTBL, &hi_comm_ctrl.bas_tbl, FFIRST);

    adv_pay_h = (struct hi_adv_payment_tbl_h *)hi_comm_ctrl.snd.buf;
    adv_pay_f = (struct hi_adv_payment_tbl_f *)hi_comm_ctrl.snd.buf;
    rq_tbl = (struct hi_tbl_order *)hi_comm_ctrl.rcv_ctrl.buf;
    sprintf((char *)adv_pay_h->kind, "%02x", NS_TBL_DATA);
    sprintf((char *)adv_pay_h->tbl_typ, "%02d", TB_ADV_PAY);
    sprintf((char *)adv_pay_h->frame_no, "00000000");
    sprintf((char *)adv_pay_h->frame_cnt, "00000000");
    memset(tmp_ldyb, '0', sizeof(tmp_ldyb));

    all_row = 0;

    sprintf(rq_seq_no, "%.8s%c", rq_tbl->req_seq_no, '\0');
    hexi = hextodig(rq_tbl->frame_no);
//    typ = hi_comm_ctrl.bas_tbl.lane_info[hi_comm_ctrl.lane_no-1].lane_type[1]-'0';
//lane_log("BL 요구 구분[%02d]\n", typ);
    if(lb_data2atoi((char *)rq_tbl->data_div, 2) == 1)    /* 사전등록 Master */
    {
        memset(&adv_struct, 0, sizeof(struct bl_struct));
//lane_log("BL 마스터 송신 넘어감[%d]\n", lb_data2atoi((char *)rq_tbl->data_div, 2));
//lane_log("차로유형 확인[%.2s][%d]\n", hi_comm_ctrl.bas_tbl.lane_info[hi_comm_ctrl.lane_no-1].lane_type, typ);
        e_memcpy(adv_struct.plz_id, hi_comm_ctrl.bas_tbl.plz_id);
        sprintf((char *)adv_struct.lane_no, "%02d", hi_comm_ctrl.lane_no);
        sprintf((char *)adv_struct.seq_no, "%08x", hi_comm_ctrl.snd.snd_no);
        sprintf((char *)adv_struct.file_id, "%02d", FNO_BEFMST);
        e_memcpy(adv_struct.rvs_no , hi_comm_ctrl.bas_tbl.rvs_tbl_info[6].rvs_no);
        memcpy(adv_struct.rvs_year , hi_comm_ctrl.bas_tbl.rvs_tbl_info[6].apl_year, 4);
        memcpy(adv_struct.rvs_month, hi_comm_ctrl.bas_tbl.rvs_tbl_info[6].apl_mon, 2);
        memcpy(adv_struct.rvs_day  , hi_comm_ctrl.bas_tbl.rvs_tbl_info[6].apl_day, 2);
        memcpy(adv_struct.rvs_hour , hi_comm_ctrl.bas_tbl.rvs_tbl_info[6].apl_hr, 2);
        memcpy(adv_struct.rvs_min  , hi_comm_ctrl.bas_tbl.rvs_tbl_info[6].apl_min, 2);

        lane_log("[senddata_handle] FNO_BEFMST \n");
	    sprintf(bak, "%.2s%.2s%.8s%.2s%.2s%.4s%.2s%.2s%.2s%.2s%.4s%.2s%.2s%.2s%.2s%c", adv_struct.plz_id, adv_struct.lane_no, adv_struct.seq_no, adv_struct.file_id, adv_struct.rvs_no, 
		             adv_struct.rvs_year, adv_struct.rvs_month, adv_struct.rvs_day, adv_struct.rvs_hour, adv_struct.rvs_min,
					 adv_struct.modf_year, adv_struct.modf_month, adv_struct.modf_day, adv_struct.modf_hour, adv_struct.modf_min, '\0');
        ret = MessageSender(hi_comm_ctrl.rcv_ctrl.cmd, (char *)&bak, "lane_run", rtn);

        return (0);
    }
    else if(lb_data2atoi((char *)rq_tbl->data_div, 2) == 2)    /* 사전등록 Change */
    {
        isfd = lb_freadx(&wf, FNO_BEFMST, &adv_pay_mst, FLAST);
        sprintf(snd_no_m, "%08x%c", lb_data2atoi(adv_pay_mst.snd_no, 10), '\0');
		//lb_close(isfd);
        isfd = lb_freadx(&wf, FNO_BEFCNG, &adv_pay_chg, FFIRST);

        sprintf(snd_no_c, "%08x%c", lb_data2atoi(adv_pay_chg.snd_no, 10), '\0');
#ifdef _DEF_REQ_
        //2020.02.14 요구전송연번 적용
        chk_chghead = strtoul(snd_no_c, NULL, 16);
#endif
//lane_log("사전등록 변경분 1[%x] 2[%x] 3[%x]\n", strtoul(rq_seq_no, NULL, 16), strtoul(snd_no_c, NULL, 16), strtoul(snd_no_m, NULL, 16));
//lane_log("사전등록 변경분 String 1[%.8s] 2[%.8s] 3[%.8s]\n", rq_seq_no, snd_no_c, snd_no_m);
//2020.05.25 사전등록 마스터 강제 송신 추가 로직 반영
#if 0
        if (isfd < 0 || strtoul(rq_seq_no, NULL, 16) < strtoul(snd_no_c, NULL, 16) && strtoul(rq_seq_no, NULL, 16) < strtoul(snd_no_m, NULL, 16))
#else
        if (isfd < 0 || strtoul(rq_seq_no, NULL, 16) < strtoul(snd_no_c, NULL, 16) && strtoul(rq_seq_no, NULL, 16) < strtoul(snd_no_m, NULL, 16) || mod_bef_type == 1)
#endif
        {
            lane_log("사전등록 변경분 Error \n");
            //lb_close(isfd);

            isfd = lb_freadx(&wf, FNO_BEFMST, &adv_pay_mst, FLAST);
            sprintf(snd_no_m, "%08x%c", lb_data2atoi(adv_pay_mst.snd_no, 10), '\0');
            if(isfd < 0 || strtoul(rq_seq_no, NULL, 16) <= strtoul(snd_no_m, NULL, 16))
            {
                lane_log("Master Request again\n");
                sprintf((char *)adv_pay_h->div, "01");
                //lb_close(isfd);
                return (sizeof(struct hi_adv_payment_tbl_h));
            }
            sprintf((char *)adv_pay_h->div, "01");
            //lb_close(isfd);
            return (sizeof(struct hi_adv_payment_tbl_h));
        }else
        {
            isfd = lb_freadx(&wf, FNO_BEFCNG, &adv_pay_chg, FLAST);
            sprintf(snd_no_c, "%08x%c", lb_data2atoi(adv_pay_chg.snd_no, 10), '\0');
//lane_log("사전등록 변경분 else 1[%x] 2[%x]\n", strtoul(rq_seq_no, NULL, 16), strtoul(snd_no_c, NULL, 16));
            if(strtoul(rq_seq_no, NULL, 16) > strtoul(snd_no_c, NULL, 16))
            {
                lane_log("Request Seq Error Master Request again\n");
                sprintf((char *)adv_pay_h->div, "01");
                //lb_close(isfd);
                return (sizeof(struct hi_adv_payment_tbl_h));
            }else if(strtoul(rq_seq_no, NULL, 16) == strtoul(snd_no_c, NULL, 16))
            {
                lane_log( "CRD B/L Change not exist data ldyb [%08x] Request B/L[%.8s]\n",
                           lb_data2atoi(adv_pay_chg.snd_no, 10), rq_tbl->req_seq_no);
                sprintf((char *)adv_pay_h->div, "02");
                //lb_close(isfd);
                return (sizeof(struct hi_adv_payment_tbl_h));
            }
        }

        isfd = lb_fopen(&wf, FNO_BEFCNG, FINPUT+FC_MANULOCK);
        lseek(isfd, 0, SEEK_SET);
#ifdef _DEF_REQ_
		chg_seek = strtoul(rq_seq_no, NULL, 16) - (chk_chghead);
		if(chg_seek < 0) chg_seek = 0;
//lane_log("사전등록 변경분 SEEK 이동 0 [%d][%d]1추가[%d]\n", strtoul(rq_seq_no, NULL, 16), chk_chghead, chg_seek);
        lseek(isfd, chg_seek, SEEK_SET);
#endif
        sprintf(tmp_frame, "%.8s%c", rq_tbl->frame_no, '\0');
//lane_log("사전등록 변경분 Start [%x]\n", strtoul(tmp_frame, NULL, 16));
        switch (strtoul(tmp_frame, NULL, 16))
        {
            /* frame_no = 0 -> TABLE DATA HEADER */
            case 0:
                memset(adv_pay_h, 0, sizeof(struct hi_adv_payment_tbl_h));
                //memset(adv_pay_f, 0, sizeof(struct hi_adv_payment_tbl_f));
                memset(&adv_pay_chg, 0, sizeof(struct bef_chg_tbl));
                sprintf((char *)adv_pay_h->kind, "%02x", NS_TBL_DATA);
                sprintf((char *)adv_pay_h->tbl_typ, "%02d", TB_ADV_PAY);
                sprintf((char *)adv_pay_h->frame_no, "00000000");
                sprintf((char *)adv_pay_h->frame_cnt, "00000000");
                sprintf((char *)adv_pay_h->rvs_no, "%.2s", hi_comm_ctrl.bas_tbl.rvs_tbl_info[6].rvs_no);

                row = lb_record_cnt(isfd,FNO_BEFCNG);

                if (row < 0)
                {
                    row = 0;
                    lane_log( "CRD B/L MASTER row not exist\n");
                }

                nframe_cnt = row / 142;

                if ((nframe_cnt == 0 && row != 0) || (row % 142) != 0)
                    nframe_cnt++;

                hi_comm_ctrl.frame_no = 0;
                
                lb_close(isfd);
                
                sprintf((char *)adv_pay_h->frame_cnt, "%08x", nframe_cnt);
                sprintf((char *)adv_pay_h->rvs_no, "%.2s", hi_comm_ctrl.bas_tbl.rvs_tbl_info[6].rvs_no);
                sprintf((char *)adv_pay_h->div, "00");
                return (sizeof(struct hi_adv_payment_tbl_h));

            case FRAME_LAST_I:
                memset(adv_pay_h, 0, sizeof(struct hi_adv_payment_tbl_h));
                sprintf((char *)adv_pay_h->kind, "%02x", NS_TBL_DATA);
                sprintf((char *)adv_pay_h->tbl_typ, "%02d", TB_ADV_PAY);
                sprintf((char *)adv_pay_h->frame_no, "%08x", FRAME_LAST_I);
                sprintf((char *)adv_pay_h->frame_cnt, "00000000");
                lb_close(isfd);
                return (sizeof(struct hi_adv_payment_tbl_h));

            default :
                memset(adv_pay_f, 0, sizeof(struct hi_adv_payment_tbl_f));
                memset(&adv_pay_chg, 0, sizeof(struct bef_chg_tbl));

                lane_log( "CRD B/L Change Data Request\n");
#ifdef _DEF_REQ_
                pos = ((hexi-1)* 142)+chg_seek;
//lane_log("사전등록 변경분 SEEK 이동 %d [%d]\n", hexi, pos);
#endif
                pos = (hexi-1) * 142;
                lseek(isfd, pos * sizeof(struct bef_chg_tbl),SEEK_SET);
//lane_log("##### POS[%d] Size[%d] #####\n", pos, sizeof(struct bef_chg_tbl));
                row = 0;

                for(ii = 0; ii < 142; ii++)
                {
                    isrc = lb_readl(isfd, &adv_pay_chg, FNEXT, sizeof(struct bef_chg_tbl));
                    if (isrc <= 0) break;

                    sprintf(snd_no_c, "%08x%c", lb_data2atoi(adv_pay_chg.snd_no, 10), '\0');

                    tmp_ldyb[ii] = strtoul(snd_no_c, NULL, 16); 
                    row++;
					//lseek(isfd, sizeof(struct bef_chg_tbl), SEEK_SET);
//lane_log("##### read Data[%.10s][%.2s][%.2s][%.10s] #####\n", adv_pay_chg.snd_no, adv_pay_chg.div, adv_pay_chg.kind, adv_pay_chg.car_no);
                }

                sprintf((char *)adv_pay_f->kind, "%02x", NS_TBL_DATA);
                sprintf((char *)adv_pay_f->tbl_typ, "%02d", TB_ADV_PAY);
                sprintf(tmp_frame, "%.8s%c", rq_tbl->frame_no, '\0');
                hi_comm_ctrl.frame_no = strtoul(tmp_frame, NULL, 16);
                e_memcpy(adv_pay_f->frame_no, rq_tbl->frame_no);
//lane_log("사전등록 Item[%d]\n", row);
                if(row == 0)
                {
                    sprintf((char *)adv_pay_f->last_data_seq_no, "00000000");
                    sprintf((char *)adv_pay_f->item_cnt, "00");
                }
                else
                {
                    sprintf((char *)adv_pay_f->last_data_seq_no, "%08x", tmp_ldyb[row-1]);
                    sprintf((char *)adv_pay_f->item_cnt, "%02x", row);
                }

                lseek(isfd, -row * sizeof(struct bef_chg_tbl), SEEK_CUR);
//lane_log("#####22 POS[%d] Size[%d] #####\n", pos, sizeof(struct bef_chg_tbl));
                for(ii = 0; ii < 142; ii++)
                {
                    isrc = lb_readl(isfd, &adv_pay_chg, FNEXT, sizeof(struct bef_chg_tbl));
                    if (isrc <= 0) break;
                
                    sprintf((char *)adv_pay_f->adv_info[ii].rgst_div, "%.2s", adv_pay_chg.div);
					sprintf((char *)adv_pay_f->adv_info[ii].div, "%.2s", adv_pay_chg.kind);
                    sprintf((char *)adv_pay_f->adv_info[ii].car_no, "%.10s", adv_pay_chg.car_no);
//lane_log("변경분 Frame 송신[%d] 8-0[%.10s][%.2s]\n", ii, adv_pay_f->adv_info[ii].rgst_div, adv_pay_chg.div);
//lane_log("변경분 Frame 송신[%d] 8-1[%.2s][%.2s]\n", ii, adv_pay_f->adv_info[ii].rgst_div, adv_pay_chg.div);
//lane_log("변경분 Frame 송신[%d] 8-2[%.2s][%.2s]\n", ii, adv_pay_f->adv_info[ii].div, adv_pay_chg.kind);
//lane_log("변경분 Frame 송신[%d] 8-3[%.10s][%.10s]\n", ii, adv_pay_f->adv_info[ii].car_no, adv_pay_chg.car_no);
                }

                if (isrc <= 0 && !ii)
                {
                    hi_comm_ctrl.frame_no = FRAME_LAST_I;
                    sprintf((char *)adv_pay_f->frame_no, "%08x", FRAME_LAST_I);
                    lb_close(isfd);
                    return (sizeof(struct hi_adv_payment_tbl_f));
                }

                lb_close(isfd);
                return (sizeof(struct hi_adv_payment_tbl_f));
        }
    }
    else{
        lane_log( "사전등록 TableData Request Error!\n");
        //lb_close(isfd);
        return (-1);
    }
}

/*
*========================================================================
*
*   함 수 명 : snd_pl_tbl
*   작 성 자 : 강준석
*   작 성 일 : 2018.08.08
*   수 정 일 :
*   설    명 : TAG P/L  TABLE 송신
*              Master -> Background / Change -> lane_svr process
*
*========================================================================
*/

int snd_pl_tbl()
{
    static int           all_row;
    struct write_info    wf;
    struct pl_mst_tbl    pl_tcrd_mst;
    struct pl_info       pl_tcrd_info_f;
    struct hi_pl_tbl_h  *pl_tcrd_h;
    struct hi_pl_tbl_f  *pl_tcrd_f;
    struct bl_struct     pl_struct;
    struct hi_tbl_order *rq_tbl;
    int  pos, isrc, ii, ret, row=0;
    unsigned int req_seq_no_tybl=0;
    int  nframe_cnt;
    char path[128]; memset(path, 0x00, sizeof(path));
    int  block_st_no[17];
    int  block_cnt[17];
	char rtn[MAX_STRING_SIZE]; memset(rtn, 0x00, sizeof(rtn));
	char bak[MAX_STRING_SIZE]; memset(bak, 0x00, sizeof(bak));

    sprintf(wf.plz_id, "%.2s", PLZ_CODE2);
    lb_freadx(&wf, FNO_BASICTBL, &hi_comm_ctrl.bas_tbl, FFIRST);

    pl_tcrd_h = (struct hi_pl_tbl_h *)hi_comm_ctrl.snd.buf;
    pl_tcrd_f = (struct hi_pl_tbl_f *)hi_comm_ctrl.snd.buf;
    rq_tbl = (struct hi_tbl_order *)hi_comm_ctrl.rcv_ctrl.buf;

    memset(&pl_struct, 0, sizeof(struct bl_struct));

    e_memcpy(pl_struct.plz_id, hi_comm_ctrl.bas_tbl.plz_id);
    sprintf((char *)pl_struct.lane_no, "%02d", hi_comm_ctrl.lane_no);
    sprintf((char *)pl_struct.seq_no, "%08x", hi_comm_ctrl.snd.snd_no);
    sprintf((char *)pl_struct.file_id, "%02d", FNO_PLMST);

    e_memcpy(pl_struct.rvs_no , hi_comm_ctrl.bas_tbl.rvs_tbl_info[7].rvs_no);

    memcpy(pl_struct.rvs_year , hi_comm_ctrl.bas_tbl.rvs_tbl_info[7].apl_year, 4);
    memcpy(pl_struct.rvs_month, hi_comm_ctrl.bas_tbl.rvs_tbl_info[7].apl_mon, 2);
    memcpy(pl_struct.rvs_day  , hi_comm_ctrl.bas_tbl.rvs_tbl_info[7].apl_day, 2);
    memcpy(pl_struct.rvs_hour , hi_comm_ctrl.bas_tbl.rvs_tbl_info[7].apl_hr, 2);
    memcpy(pl_struct.rvs_min  , hi_comm_ctrl.bas_tbl.rvs_tbl_info[7].apl_min, 2);

    memcpy(pl_struct.modf_year , hi_comm_ctrl.bas_tbl.rvs_tbl_info[7].modf_year, 4);
    memcpy(pl_struct.modf_month, hi_comm_ctrl.bas_tbl.rvs_tbl_info[7].modf_mon, 2);
    memcpy(pl_struct.modf_day  , hi_comm_ctrl.bas_tbl.rvs_tbl_info[7].modf_day, 2);
    memcpy(pl_struct.modf_hour , hi_comm_ctrl.bas_tbl.rvs_tbl_info[7].modf_hr, 2);
    memcpy(pl_struct.modf_min  , hi_comm_ctrl.bas_tbl.rvs_tbl_info[7].modf_min, 2);

    lane_log("[senddata_handle] FNO_PLMST \n");
    
    sprintf(path, "%s/%s/PLTCRDINFO", DIR_TCS, DIR_BASEINFO);
    isfd = open(path, FINPUT+FC_MANULOCK);

    for(ii=0; ii<17; ii++)
    {
        block_st_no[ii] = 0;
        block_cnt[ii] = 0;
    }

    for(ii=0; ii<17; ii++)
    {
        memset(&pl_tcrd_info_f, 0, sizeof(struct pl_info));
        isrc = read(isfd, &pl_tcrd_info_f, sizeof(struct pl_info));
        if(isrc < 0) break;
        block_st_no[ii] = lb_data2atoi(pl_tcrd_info_f.block_st_no, 10);
        block_cnt[ii] = ceil(ceil(lb_data2atoi(pl_tcrd_info_f.block_cnt, 10)/8.0)/1005.0);
    }

    for(ii=0; ii<17; ii++)
    {
        sprintf(pl_struct.pl_block[ii].block_st_no, "%010d", block_st_no[ii]);
        sprintf(pl_struct.pl_block[ii].block_cnt, "%010d", block_cnt[ii]);
    }

#if 0
    tagblrq_send(&pl_struct);
#else
	sprintf(bak, "%.2s%.2s%.8s%.2s%.2s%.4s%.2s%.2s%.2s%.2s%.4s%.2s%.2s%.2s%.2s%c", pl_struct.plz_id, pl_struct.lane_no, pl_struct.seq_no, pl_struct.file_id, pl_struct.rvs_no,
	             pl_struct.rvs_year, pl_struct.rvs_month, pl_struct.rvs_day, pl_struct.rvs_hour, pl_struct.rvs_min,
				 pl_struct.modf_year, pl_struct.modf_month, pl_struct.modf_day, pl_struct.modf_hour, pl_struct.modf_min, '\0');
    ret = MessageSender(hi_comm_ctrl.rcv_ctrl.cmd, (char *)&bak, "lane_run", rtn);
#endif

    close(isfd);

    return(0);
}

/*
*========================================================================
*
*   함 수 명 : snd_bl_tbl
*   작 성 자 : 강준석
*   작 성 일 : 2018.08.08
*   수 정 일 :
*   설    명 : B/L  TABLE 송신
*              Master -> Background / Change -> lane_svr process
*
*========================================================================
*/

int snd_bl_tbl()
{
    static int           all_row;
    struct write_info    wf;
    struct bl_mst_tbl    bl_mst;
    struct bl_chg_tbl    bl_chg;
    struct hi_bl_tbl_h  *bl_tag_h;
    struct hi_bl_tbl_f  *bl_tag_f;
    struct bl_struct   tagbl_struct;
    struct hi_tbl_order *rq_tbl;
    int    pos, isrc, ii, ret, row=0, hexi =0;
    unsigned int tmp_tybl=0;
    int    tmp_ldyb[111];
    int    nframe_cnt;
    int    typ = 0;
    char   rq_seq_no[10]; memset(rq_seq_no, 0x00, sizeof(rq_seq_no));
    char   snd_no_m[10]; memset(snd_no_m, 0x00, sizeof(snd_no_m));
    char   snd_no_c[10]; memset(snd_no_c, 0x00, sizeof(snd_no_c));
    char   rtn[MAX_STRING_SIZE]; memset(rtn, 0x00, sizeof(rtn));
	char   bak[MAX_STRING_SIZE]; memset(bak, 0x00, sizeof(bak));
    char   tmp_frame[10]; memset(tmp_frame, 0x00, sizeof(tmp_frame));

    sprintf(wf.plz_id, "%.2s", PLZ_CODE2);
    lb_freadx(&wf, FNO_BASICTBL, &hi_comm_ctrl.bas_tbl, FFIRST);

    bl_tag_h = (struct hi_bl_tbl_h *)hi_comm_ctrl.snd.buf;
    bl_tag_f = (struct hi_bl_tbl_f *)hi_comm_ctrl.snd.buf;
    rq_tbl   = (struct hi_tbl_order *)hi_comm_ctrl.rcv_ctrl.buf;
    sprintf((char *)bl_tag_h->kind     , "%02x", NS_TBL_DATA);
    sprintf((char *)bl_tag_h->tbl_typ  , "%02d", TB_BL_CRD);
    sprintf((char *)bl_tag_h->frame_no , "00000000");
    sprintf((char *)bl_tag_h->frame_cnt, "00000000");
    memset(tmp_ldyb, '0', sizeof(tmp_ldyb));

    all_row = 0;

    sprintf(rq_seq_no, "%.8s%c", rq_tbl->req_seq_no, '\0');
    hexi = hextodig(rq_tbl->frame_no);
    //typ = hi_comm_ctrl.bas_tbl.lane_info[hi_comm_ctrl.lane_no-1].lane_type[1]-'0';
//lane_log("BL 요구 구분[%02d]\n", typ);

    if(lb_data2atoi((char *)rq_tbl->data_div, 2) == 1)    /* CRD B/L Master */
    {
        memset(&tagbl_struct, 0, sizeof(struct bl_struct));
//lane_log("BL 마스터 송신 넘어감[%d]\n", lb_data2atoi((char *)rq_tbl->data_div, 2));
//lane_log("차로유형 확인[%.2s][%d]\n", hi_comm_ctrl.bas_tbl.lane_info[hi_comm_ctrl.lane_no-1].lane_type, typ);
        e_memcpy(tagbl_struct.plz_id, hi_comm_ctrl.bas_tbl.plz_id);
        sprintf((char *)tagbl_struct.lane_no, "%02d", hi_comm_ctrl.lane_no);
        sprintf((char *)tagbl_struct.seq_no, "%08x", hi_comm_ctrl.snd.snd_no);
        sprintf((char *)tagbl_struct.file_id, "%02d", FNO_BLMST);
        e_memcpy(tagbl_struct.rvs_no , hi_comm_ctrl.bas_tbl.rvs_tbl_info[8].rvs_no);
        memcpy(tagbl_struct.rvs_year , hi_comm_ctrl.bas_tbl.rvs_tbl_info[8].apl_year, 4);
        memcpy(tagbl_struct.rvs_month, hi_comm_ctrl.bas_tbl.rvs_tbl_info[8].apl_mon, 2);
        memcpy(tagbl_struct.rvs_day  , hi_comm_ctrl.bas_tbl.rvs_tbl_info[8].apl_day, 2);
        memcpy(tagbl_struct.rvs_hour , hi_comm_ctrl.bas_tbl.rvs_tbl_info[8].apl_hr, 2);
        memcpy(tagbl_struct.rvs_min  , hi_comm_ctrl.bas_tbl.rvs_tbl_info[8].apl_min, 2);

        lane_log("[senddata_handle] FNO_BLMST \n");
	sprintf(bak, "%.2s%.2s%.8s%.2s%.2s%.4s%.2s%.2s%.2s%.2s%.4s%.2s%.2s%.2s%.2s%c", tagbl_struct.plz_id, tagbl_struct.lane_no, tagbl_struct.seq_no, tagbl_struct.file_id, tagbl_struct.rvs_no,
	             tagbl_struct.rvs_year, tagbl_struct.rvs_month, tagbl_struct.rvs_day, tagbl_struct.rvs_hour, tagbl_struct.rvs_min,
				 tagbl_struct.modf_year, tagbl_struct.modf_month, tagbl_struct.modf_day, tagbl_struct.modf_hour, tagbl_struct.modf_min, '\0');
        ret = MessageSender(hi_comm_ctrl.rcv_ctrl.cmd, (char *)&bak, "lane_run", rtn);

        return (0);
    }
    else if(lb_data2atoi((char *)rq_tbl->data_div, 2) == 2)    /* CRD B/L Change */
    {
        isfd1 = lb_freadx(&wf, FNO_BLMST, &bl_mst, FLAST);
        sprintf(snd_no_m, "%08x%c", bl_mst.mngt_no, '\0');
        isfd = lb_freadx(&wf, FNO_BLCNG, &bl_chg, FFIRST);

        sprintf(snd_no_c, "%08x%c", bl_chg.mngt_no, '\0');
//lane_log("BL 변경분 1[%x] 2[%x] 3[%x]\n", strtoul(rq_seq_no, NULL, 16), strtoul(snd_no_c, NULL, 16), strtoul(snd_no_m, NULL, 16));
//lane_log("BL 변경분 String 1[%.8s] 2[%.8s] 3[%.8s]\n", rq_seq_no, snd_no_c, snd_no_m);
        if (isfd < 0 || strtoul(rq_seq_no, NULL, 16) < strtoul(snd_no_c, NULL, 16) && strtoul(rq_seq_no, NULL, 16) < strtoul(snd_no_m, NULL, 16))
        {
            lane_log("Change CRD B/L Error \n");
            //lb_close(isfd);

            isfd = lb_freadx(&wf, FNO_BLMST, &bl_mst, FLAST);
            sprintf(snd_no_m, "%08x%c", bl_mst.mngt_no, '\0');
//lane_log("##### BL Master[%08x]", strtoul(snd_no_m, NULL, 16));
            if(isfd < 0 || strtoul(rq_seq_no, NULL, 16) <= strtoul(snd_no_m, NULL, 16))
            {
                lane_log("Master Request again\n");
                sprintf((char *)bl_tag_h->div, "01");
                //lb_close(isfd);
                return (sizeof(struct hi_bl_tbl_h));
            }
            sprintf((char *)bl_tag_h->div, "01");
            //lb_close(isfd);
            return (sizeof(struct hi_bl_tbl_h));
        }else
        {
            isfd = lb_freadx(&wf, FNO_BLCNG, &bl_chg, FLAST);
            sprintf(snd_no_c, "%08x%c", bl_chg.mngt_no, '\0');
//lane_log("BL 변경분 else 1[%x] 2[%x]\n", strtoul(rq_seq_no, NULL, 16), strtoul(snd_no_c, NULL, 16));
            if(strtoul(rq_seq_no, NULL, 16) > strtoul(snd_no_c, NULL, 16))
            {
                lane_log("Request Seq Error Master Request again\n");
                sprintf((char *)bl_tag_h->div, "01");
                //lb_close(isfd);
                return (sizeof(struct hi_bl_tbl_h));
            }else if(strtoul(rq_seq_no, NULL, 16) == strtoul(snd_no_c, NULL, 16))
            {
                lane_log( "CRD B/L Change not exist data ldyb [%08x] Request B/L[%.8s]\n",
                           bl_chg.mngt_no, rq_tbl->req_seq_no);
                sprintf((char *)bl_tag_h->div, "02");
                //lb_close(isfd);
                return (sizeof(struct hi_bl_tbl_h));
            }
        }

        isfd = lb_fopen(&wf, FNO_BLCNG, FINPUT+FC_MANULOCK);
        lseek(isfd, 0, SEEK_SET);

        sprintf(tmp_frame, "%.8s%c", rq_tbl->frame_no, '\0');
//lane_log("BL 변경분 Start [%x]\n", strtoul(tmp_frame, NULL, 16));
        switch (strtoul(tmp_frame, NULL, 16))
        {
            /* frame_no = 0 -> TABLE DATA HEADER */
            case 0:
                memset(bl_tag_h, 0, sizeof(struct hi_bl_tbl_h));
                memset(bl_tag_f, 0, sizeof(struct hi_bl_tbl_f));
                memset(&bl_chg, 0, sizeof(struct bl_chg_tbl));
                sprintf((char *)bl_tag_h->kind, "%02x", NS_TBL_DATA);
                sprintf((char *)bl_tag_h->tbl_typ, "%02d", TB_BL_CRD);
                sprintf((char *)bl_tag_h->frame_no, "00000000");
                sprintf((char *)bl_tag_h->frame_cnt, "00000000");
                sprintf((char *)bl_tag_h->rvs_no, "%.2s", hi_comm_ctrl.bas_tbl.rvs_tbl_info[8].rvs_no);

                row = lb_record_cnt(isfd,FNO_BLCNG);

                if (row < 0)
                {
                    row = 0;
                    lane_log( "CRD B/L MASTER row not exist\n");
                }

                nframe_cnt = row / 111;

                if ((nframe_cnt == 0 && row != 0) || (row % 111) != 0)
                    nframe_cnt++;

                hi_comm_ctrl.frame_no = 0;
                
                lb_close(isfd);
                
                sprintf((char *)bl_tag_h->frame_cnt, "%08x", nframe_cnt);
                sprintf((char *)bl_tag_h->rvs_no, "%.2s", hi_comm_ctrl.bas_tbl.rvs_tbl_info[8].rvs_no);
                sprintf((char *)bl_tag_h->div, "00");

                e_memcpy(bl_tag_h->bl_aply_year,  hi_comm_ctrl.bas_tbl.rvs_tbl_info[8].apl_year);
                e_memcpy(bl_tag_h->bl_aply_month, hi_comm_ctrl.bas_tbl.rvs_tbl_info[8].apl_mon);
                e_memcpy(bl_tag_h->bl_aply_day,   hi_comm_ctrl.bas_tbl.rvs_tbl_info[8].apl_day);
                e_memcpy(bl_tag_h->bl_aply_hour,  hi_comm_ctrl.bas_tbl.rvs_tbl_info[8].apl_hr);
                e_memcpy(bl_tag_h->bl_aply_min,   hi_comm_ctrl.bas_tbl.rvs_tbl_info[8].apl_min);
        
                e_memcpy(bl_tag_h->bl_modf_year,  hi_comm_ctrl.bas_tbl.rvs_tbl_info[8].modf_year);
                e_memcpy(bl_tag_h->bl_modf_month, hi_comm_ctrl.bas_tbl.rvs_tbl_info[8].modf_mon);
                e_memcpy(bl_tag_h->bl_modf_day,   hi_comm_ctrl.bas_tbl.rvs_tbl_info[8].modf_day);
                e_memcpy(bl_tag_h->bl_modf_hour,  hi_comm_ctrl.bas_tbl.rvs_tbl_info[8].modf_hr);
                e_memcpy(bl_tag_h->bl_modf_min,   hi_comm_ctrl.bas_tbl.rvs_tbl_info[8].modf_min);

                //lb_close(isfd);
                return (sizeof(struct hi_bl_tbl_h));

            case FRAME_LAST_I:
                memset(bl_tag_h, 0, sizeof(struct hi_bl_tbl_h));
                sprintf((char *)bl_tag_h->kind, "%02x", NS_TBL_DATA);
                sprintf((char *)bl_tag_h->tbl_typ, "%02d", TB_BL_CRD);
                sprintf((char *)bl_tag_h->frame_cnt, "00000000");
                sprintf((char *)bl_tag_h->frame_no, "%08x", FRAME_LAST_I);
                lb_close(isfd);
                return (sizeof(struct hi_bl_tbl_h));

            default :
                memset(bl_tag_f, 0, sizeof(struct hi_bl_tbl_f));
                memset(&bl_chg, 0, sizeof(struct bl_chg_tbl));

                lane_log( "CRD B/L Change Data Request\n");

                pos = (hexi-1) * 111;
                lseek(isfd, pos * sizeof(struct bl_chg_tbl),SEEK_SET);

                row = 0;

                for(ii = 0; ii < 111; ii++)
                {
                    isrc = lb_readl(isfd, &bl_chg, FNEXT, sizeof(struct bl_chg_tbl));
                    if (isrc <= 0) break;

                    sprintf(snd_no_c, "%08x%c", bl_chg.mngt_no, '\0');
                    tmp_ldyb[ii] = strtoul(snd_no_c, NULL, 16); 
                    row++;
                }

                sprintf((char *)bl_tag_f->kind, "%02x", NS_TBL_DATA);
                sprintf((char *)bl_tag_f->tbl_typ, "%02d", TB_BL_CRD);
                sprintf(tmp_frame, "%.8s%c", rq_tbl->frame_no, '\0');
                hi_comm_ctrl.frame_no = strtoul(tmp_frame, NULL, 16);
                e_memcpy(bl_tag_f->frame_no, rq_tbl->frame_no);

                if(row == 0)
                {
                    sprintf((char *)bl_tag_f->last_data_seq_no, "00000000");
                    sprintf((char *)bl_tag_f->item_cnt, "00");
                }
                else
                {
                    sprintf((char *)bl_tag_f->last_data_seq_no, "%08x", tmp_ldyb[row-1]);
                    sprintf((char *)bl_tag_f->item_cnt, "%02x", row);
                }

                lseek(isfd, -row*sizeof(struct bl_chg_tbl), SEEK_CUR);

                for(ii = 0; ii < 111; ii++)
                {
                    isrc = lb_readl(isfd, &bl_chg, FNEXT, sizeof(struct bl_chg_tbl));
                    if (isrc <= 0) break;
                
                    sprintf((char *)bl_tag_f->bl_data[ii].div, "%.2s", bl_chg.inst_yn);
                    sprintf((char *)bl_tag_f->bl_data[ii].crd_no, "%.16s", bl_chg.crd_no);
//lane_log("변경분 Frame 송신[%d] 8-1[%.2s][%.2s]\n", ii, bl_tag_f->rgstr_bl_data[ii].div, bl_chg.bl_div);
//lane_log("변경분 Frame 송신[%d] 8-2[%.16s][%.16s]\n", ii, bl_tag_f->rgstr_bl_data[ii].crd_no, bl_chg.crd_no);
                }

                if (isrc <= 0 && !ii)
                {
                    hi_comm_ctrl.frame_no = FRAME_LAST_I;
                    sprintf((char *)bl_tag_f->frame_no, "%08x", FRAME_LAST_I);
                    lb_close(isfd);
                    return (sizeof(struct hi_bl_tbl_f));
                }

                lb_close(isfd);
                return (sizeof(struct hi_bl_tbl_f));
        }
    }
    else{
        lane_log( "CRD B/L TableData Request Error!\n");
        //lb_close(isfd);
        return (-1);
    }
}

/*
*========================================================================
*
*   함 수 명 : snd_red_carno_tbl
*   작 성 자 : JBY
*   작 성 일 : 2019.05.11
*   수 정 일 :
*   설    명 : 차량번호 감면정보 TABLE을 송신
*
*========================================================================
*/

int snd_red_carno_tbl()
{
    struct write_info    wf;
#ifndef _MSTCHG_
    struct red_carno_info   red_carno_info;
#else
    struct red_carno_info   red_carno_mst;
    struct red_carno_info   red_carno_chg;
#endif
    struct hi_reduce_tbl_h *red_carno_h;
    struct hi_reduce_tbl_f *red_carno_f;
    struct hi_tbl_order    *rq_tbl;
#ifdef _MSTCHG_
    struct bl_struct           bl_struct;
#endif
    int    isrc;
    int    ii, pos, hexi;
    int    nframe_cnt, ret, row;
    int    tmp_ldyb[142];

	char   rq_seq_no[10]; memset(rq_seq_no, 0x00, sizeof(rq_seq_no));
    char   snd_no_m[10]; memset(snd_no_m, 0x00, sizeof(snd_no_m));
    char   snd_no_c[10]; memset(snd_no_c, 0x00, sizeof(snd_no_c));
    char   rtn[MAX_STRING_SIZE]; memset(rtn, 0x00, sizeof(rtn));
	char   bak[MAX_STRING_SIZE]; memset(bak, 0x00, sizeof(bak));
    char   tmp_frame[10]; memset(tmp_frame, 0x00, sizeof(tmp_frame));
	char   tmp_frameCnt[10]; memset(tmp_frameCnt, 0x00, sizeof(tmp_frameCnt));

	sprintf(wf.plz_id, "%.2s", PLZ_CODE2);
    lb_freadx(&wf, FNO_BASICTBL, &hi_comm_ctrl.bas_tbl, FFIRST);

    red_carno_h = (struct hi_reduce_tbl_h *)hi_comm_ctrl.snd.buf;
    red_carno_f = (struct hi_reduce_tbl_f *)hi_comm_ctrl.snd.buf;
    rq_tbl = (struct hi_tbl_order *)hi_comm_ctrl.rcv_ctrl.buf;
#ifndef _MSTCHG_
    memset(&red_carno_info, 0x00, sizeof(struct red_carno_info));

    isfd = lb_fopen(&wf, FNO_RED_CARNO, FINPUT+FC_MANULOCK);
    if (isfd < 0)
    {
        lane_log( "차량번호 감면정보 Open Fail[%d]\n", isfd);
        lb_close(isfd);
        return(-1);
    }

    sprintf(tmp_frame, "%.8s%c", rq_tbl->frame_no, '\0');
    hexi = hextodig(rq_tbl->frame_no);

    if (strtoul(tmp_frame, NULL, 16) == 0)
    {
        /* 차량번호 감면정보 TABLE HEADER */
        memset(red_carno_h, 0, sizeof(struct hi_reduce_tbl_h));

        sprintf((char *)red_carno_h->kind, "%02x", NS_TBL_DATA);
        sprintf((char *)red_carno_h->tbl_typ, "%02d", TB_RED_CARNO);
        e_memcpy(red_carno_h->frame_no, rq_tbl->frame_no);
        e_memcpy(red_carno_h->rvs_no, hi_comm_ctrl.bas_tbl.rvs_tbl_info[9].rvs_no);
        sprintf((char *)red_carno_h->frame_cnt, "%08x", lb_record_cnt(isfd, FNO_RED_CARNO) / 167);
        sprintf(tmp_frameCnt, "%.8s%c", red_carno_h->frame_cnt, '\0');
        if ((strtoul(tmp_frameCnt, NULL, 16) == 0) || (lb_record_cnt(isfd, FNO_RED_CARNO) % 167) != 0)
        {
            nframe_cnt = strtoul(tmp_frameCnt, NULL, 16);
            sprintf((char *)red_carno_h->frame_cnt, "%08x", nframe_cnt + 1);
        }
        hi_comm_ctrl.frame_no = 0;

        sprintf((char *)red_carno_h->red_cnt, "%08d", lb_record_cnt(isfd, FNO_RED_CARNO));

        e_memcpy(red_carno_h->red_aply_year,  hi_comm_ctrl.bas_tbl.rvs_tbl_info[9].apl_year);
        e_memcpy(red_carno_h->red_aply_month, hi_comm_ctrl.bas_tbl.rvs_tbl_info[9].apl_mon);
        e_memcpy(red_carno_h->red_aply_day,   hi_comm_ctrl.bas_tbl.rvs_tbl_info[9].apl_day);
        e_memcpy(red_carno_h->red_aply_hour,  hi_comm_ctrl.bas_tbl.rvs_tbl_info[9].apl_hr);
        e_memcpy(red_carno_h->red_aply_min,   hi_comm_ctrl.bas_tbl.rvs_tbl_info[9].apl_min);
        
        e_memcpy(red_carno_h->red_modf_year,  hi_comm_ctrl.bas_tbl.rvs_tbl_info[9].modf_year);
        e_memcpy(red_carno_h->red_modf_month, hi_comm_ctrl.bas_tbl.rvs_tbl_info[9].modf_mon);
        e_memcpy(red_carno_h->red_modf_day,   hi_comm_ctrl.bas_tbl.rvs_tbl_info[9].modf_day);
        e_memcpy(red_carno_h->red_modf_hour,  hi_comm_ctrl.bas_tbl.rvs_tbl_info[9].modf_hr);
        e_memcpy(red_carno_h->red_modf_min,   hi_comm_ctrl.bas_tbl.rvs_tbl_info[9].modf_min);

        lb_close(isfd);
        return (sizeof(struct hi_reduce_tbl_h));
    } else if(strtoul(tmp_frame, NULL, 16) == FRAME_LAST_I){
        memset(red_carno_f, 0, sizeof(struct hi_reduce_tbl_f));

        sprintf((char *)red_carno_f->kind, "%02x", NS_TBL_DATA);
        sprintf((char *)red_carno_f->tbl_typ, "%02d", TB_RED_CARNO);
        sprintf((char *)red_carno_f->frame_no, "%08x", FRAME_LAST_I);

        hi_comm_ctrl.frame_no = FRAME_LAST_I;
        lb_close(isfd);
        return (sizeof(struct hi_reduce_tbl_f));
    }

    pos = (hexi-1) * 167;
    lseek(isfd, pos * sizeof(struct red_carno_info),SEEK_SET);

    memset(red_carno_f, 0, sizeof(struct hi_reduce_tbl_f));
    sprintf((char *)red_carno_f->kind, "%02x", NS_TBL_DATA);
    sprintf((char *)red_carno_f->tbl_typ, "%02d", TB_RED_CARNO);
    e_memcpy(red_carno_f->frame_no, rq_tbl->frame_no);

    hi_comm_ctrl.frame_no = strtoul(tmp_frame, NULL, 16);

    for(ii=0; ii<167; ii++)
    {
        isrc = lb_readl(isfd, &red_carno_info, FNEXT, sizeof(struct red_carno_info));

        if (isrc <= 0)
        {
            //lb_close(isfd);
            break;
        }

        e_memcpy(&red_carno_f->red_data[ii].div   , red_carno_info.div);
        e_memcpy(&red_carno_f->red_data[ii].car_no, red_carno_info.carno_code);
    }

    lb_close(isfd);
    return (sizeof(struct hi_reduce_tbl_f));
#else
    sprintf(rq_seq_no, "%.8s%c", rq_tbl->req_seq_no, '\0');

    if(lb_data2atoi((char *)rq_tbl->data_div, 2) == 1)
    {
        e_memcpy(bl_struct.plz_id, hi_comm_ctrl.bas_tbl.plz_id);
        sprintf((char *)bl_struct.lane_no, "%02d", hi_comm_ctrl.lane_no);
        sprintf((char *)bl_struct.seq_no, "%08x", hi_comm_ctrl.snd.snd_no);
        sprintf((char *)bl_struct.file_id, "%02d", FNO_RED_CARNO);
        e_memcpy(bl_struct.rvs_no, hi_comm_ctrl.bas_tbl.rvs_tbl_info[9].rvs_no);
        e_memcpy(bl_struct.rvs_year,  hi_comm_ctrl.bas_tbl.rvs_tbl_info[9].apl_year);
        e_memcpy(bl_struct.rvs_month, hi_comm_ctrl.bas_tbl.rvs_tbl_info[9].apl_mon);
        e_memcpy(bl_struct.rvs_day,   hi_comm_ctrl.bas_tbl.rvs_tbl_info[9].apl_day);
        e_memcpy(bl_struct.rvs_hour,  hi_comm_ctrl.bas_tbl.rvs_tbl_info[9].apl_hr);
        e_memcpy(bl_struct.rvs_min,   hi_comm_ctrl.bas_tbl.rvs_tbl_info[9].apl_min);

        e_memcpy(bl_struct.modf_year,  hi_comm_ctrl.bas_tbl.rvs_tbl_info[9].modf_year);
        e_memcpy(bl_struct.modf_month, hi_comm_ctrl.bas_tbl.rvs_tbl_info[9].modf_mon);
        e_memcpy(bl_struct.modf_day,   hi_comm_ctrl.bas_tbl.rvs_tbl_info[9].modf_day);
        e_memcpy(bl_struct.modf_hour,  hi_comm_ctrl.bas_tbl.rvs_tbl_info[9].modf_hr);
        e_memcpy(bl_struct.modf_min,   hi_comm_ctrl.bas_tbl.rvs_tbl_info[9].modf_min);
        
        lane_log("[senddata_handle] FNO_RED_CARNO MST \n");
	sprintf(bak, "%.2s%.2s%.8s%.2s%.2s%.4s%.2s%.2s%.2s%.2s%.4s%.2s%.2s%.2s%.2s%c", bl_struct.plz_id, bl_struct.lane_no, bl_struct.seq_no, bl_struct.file_id, bl_struct.rvs_no,
	             bl_struct.rvs_year, bl_struct.rvs_month, bl_struct.rvs_day, bl_struct.rvs_hour, bl_struct.rvs_min,
				 bl_struct.modf_year, bl_struct.modf_month, bl_struct.modf_day, bl_struct.modf_hour, bl_struct.modf_min, '\0');
        ret = MessageSender(hi_comm_ctrl.rcv_ctrl.cmd, (char *)&bak, "lane_run", rtn);
        //lb_close(isfd);
        return(0);
    }else if(lb_data2atoi((char *)rq_tbl->data_div, 2) == 2)
    {
        sprintf((char *)red_carno_h->kind, "%02x", NS_TBL_DATA);
        sprintf((char *)red_carno_h->tbl_typ, "%02d", TB_RED_CARNO);
        sprintf((char *)red_carno_h->frame_no, "00000000");
        sprintf((char *)red_carno_h->frame_cnt, "00000000");

        isfd = lb_freadx(&wf, FNO_RED_CARNO, &red_carno_mst, FLAST);
        sprintf(snd_no_m, "%08x%c", lb_data2atoi(red_carno_mst.snd_no, 10), '\0');
        //lb_close(isfd);
        isfd = lb_freadx(&wf, FNO_RED_CARNO_CHG, &red_carno_chg, FFIRST);
        sprintf(snd_no_c, "%08x%c", lb_data2atoi(red_carno_chg.snd_no, 10), '\0');
//lane_log("IMM MST[%.8s] CHG[%.8s]\n", snd_no_m, snd_no_c);
        if(isfd < 0 || strtoul(rq_seq_no, NULL, 16) < strtoul(snd_no_c, NULL, 16) && strtoul(rq_seq_no, NULL, 16) < strtoul(snd_no_m, NULL, 16))
        {
            lane_log("Change RED CarNo Error \n");
            //lb_close(isfd);
            
            isfd = lb_freadx(&wf, FNO_RED_CARNO, &red_carno_mst, FLAST);
            sprintf(snd_no_m, "%08x%c", lb_data2atoi(red_carno_mst.snd_no, 10), '\0');

            if(isfd < 0 || strtoul(rq_seq_no, NULL, 16) <= strtoul(snd_no_m, NULL, 16))
            {
                lane_log("Master Request again\n");
                sprintf((char *)red_carno_h->div, "01");
                //lb_close(isfd);
                return(sizeof(struct hi_reduce_tbl_h));
            }
            sprintf((char *)red_carno_h->div, "01");
            //lb_close(isfd);
            return(sizeof(struct hi_reduce_tbl_h));
        }else
        {
            //lb_close(isfd);
            isfd = lb_freadx(&wf, FNO_RED_CARNO_CHG, &red_carno_chg, FLAST);
            sprintf(snd_no_c, "%08x%c", lb_data2atoi(red_carno_chg.snd_no, 10), '\0');

            if(strtoul(rq_seq_no, NULL, 16) > strtoul(snd_no_c, NULL, 16))
            {
                lane_log("Request Seq Error Master Request again\n");
                sprintf((char *)red_carno_h->div, "01");
                //lb_close(isfd);
                return(sizeof(struct hi_reduce_tbl_h));
            }else if(strtoul(rq_seq_no, NULL, 16) == strtoul(snd_no_c, NULL, 16))
            {
                lane_log("ISS Change Not exist RQ_SEQ[%.8s] Change[%.8s]\n", rq_seq_no, snd_no_c);
                sprintf((char *)red_carno_h->div, "02");
                //lb_close(isfd);
                return(sizeof(struct hi_reduce_tbl_h));
            }
        }

        isfd = lb_fopen(&wf, FNO_RED_CARNO_CHG, FINPUT+FC_MANULOCK);
        lseek(isfd, 0, SEEK_SET);
        
        sprintf(tmp_frame, "%.8s%c", rq_tbl->frame_no, '\0');
//lane_log("IMM Change Start\n");
        switch(strtoul(tmp_frame, NULL, 16))
        {
            case 0: //Header

            e_memcpy(red_carno_h->rvs_no, hi_comm_ctrl.bas_tbl.rvs_tbl_info[9].rvs_no);
            //memset(red_carno_f, 0, sizeof(struct hi_reduce_tbl_f));
            memset(&red_carno_chg, 0, sizeof(struct red_carno_info));
            
            row = lb_record_cnt(isfd, FNO_RED_CARNO_CHG);
            
            if(row < 0)
            {
                row = 0;
                lane_log("IMM Master row not exist\n"); 
            }
            
            nframe_cnt = row / 142;

            if ((nframe_cnt == 0 && row != 0) || (row % 142) != 0)
                nframe_cnt++;

            hi_comm_ctrl.frame_no = 0;

            lb_close(isfd);

            sprintf((char *)red_carno_h->frame_cnt, "%08x", nframe_cnt);
            sprintf((char *)red_carno_h->rvs_no, "%.2s", hi_comm_ctrl.bas_tbl.rvs_tbl_info[9].rvs_no);
            sprintf((char *)red_carno_h->div, "00");
            e_memcpy(red_carno_h->red_aply_year,  hi_comm_ctrl.bas_tbl.rvs_tbl_info[9].apl_year);
            e_memcpy(red_carno_h->red_aply_month, hi_comm_ctrl.bas_tbl.rvs_tbl_info[9].apl_mon);
            e_memcpy(red_carno_h->red_aply_day,   hi_comm_ctrl.bas_tbl.rvs_tbl_info[9].apl_day);
            e_memcpy(red_carno_h->red_aply_hour,  hi_comm_ctrl.bas_tbl.rvs_tbl_info[9].apl_hr);
            e_memcpy(red_carno_h->red_aply_min,   hi_comm_ctrl.bas_tbl.rvs_tbl_info[9].apl_min);
            
            e_memcpy(red_carno_h->red_modf_year,  hi_comm_ctrl.bas_tbl.rvs_tbl_info[9].modf_year);
            e_memcpy(red_carno_h->red_modf_month, hi_comm_ctrl.bas_tbl.rvs_tbl_info[9].modf_mon);
            e_memcpy(red_carno_h->red_modf_day,   hi_comm_ctrl.bas_tbl.rvs_tbl_info[9].modf_day);
            e_memcpy(red_carno_h->red_modf_hour,  hi_comm_ctrl.bas_tbl.rvs_tbl_info[9].modf_hr);
            e_memcpy(red_carno_h->red_modf_min,   hi_comm_ctrl.bas_tbl.rvs_tbl_info[9].modf_min);

            //lb_close(isfd);
            return (sizeof(struct hi_reduce_tbl_h));

            case FRAME_LAST_I:
            
            sprintf((char *)red_carno_h->frame_no, "%08x", FRAME_LAST_I);
            lb_close(isfd);

            return (sizeof(struct hi_reduce_tbl_h));
            
            default:
            
            memset(red_carno_f, 0, sizeof(struct hi_reduce_tbl_f));
            memset(&red_carno_chg, 0, sizeof(struct red_carno_info));
            
            lane_log("IMM Change Data[%.8s]\n", tmp_frame);
            
            pos = (hexi-1) * 142;
            lseek(isfd, pos * sizeof(struct red_carno_info),SEEK_SET);

            row = 0;
            
            for(ii = 0; ii < 142; ii++)
            {
                isrc = lb_readl(isfd, &red_carno_chg, FNEXT, sizeof(struct red_carno_info));
                if(isrc <= 0) break;
                
                sprintf(snd_no_c, "%08x%c", lb_data2atoi(red_carno_chg.snd_no, 10), '\0');
                tmp_ldyb[ii] = strtoul(snd_no_c, NULL, 16); 
                row++;
            }
            
            sprintf((char *)red_carno_f->kind, "%02x", NS_TBL_DATA);
            sprintf((char *)red_carno_f->tbl_typ, "%02d", TB_RED_CARNO);
            hi_comm_ctrl.frame_no = strtoul(tmp_frame, NULL, 16);
            e_memcpy(red_carno_f->frame_no, rq_tbl->frame_no);
            
            if(row == 0)
            {
                sprintf((char *)red_carno_f->last_data_seq_no, "00000000");
                sprintf((char *)red_carno_f->item_cnt, "00");
            }else{
                sprintf((char *)red_carno_f->last_data_seq_no, "%08x", tmp_ldyb[row-1]);
                sprintf((char *)red_carno_f->item_cnt, "%02x", row);
            }
            
            lseek(isfd, -row*sizeof(struct red_carno_info), SEEK_CUR);

            for(ii = 0; ii < 142; ii++)
            {
                isrc = lb_readl(isfd, &red_carno_chg, FNEXT, sizeof(struct red_carno_info));
                if (isrc <= 0) break;
            
                sprintf((char *)red_carno_f->red_data[ii].rgst_div, "%.2s", red_carno_chg.rgst_div);
                sprintf((char *)red_carno_f->red_data[ii].div, "%.2s", red_carno_chg.div);
                sprintf((char *)red_carno_f->red_data[ii].car_no, "%.24s", red_carno_chg.carno_code);
            }

            if (isrc <= 0 && !ii)
            {
                hi_comm_ctrl.frame_no = FRAME_LAST_I;
                sprintf((char *)red_carno_f->frame_no, "%08x", FRAME_LAST_I);
                lb_close(isfd);
                return (sizeof(struct hi_reduce_tbl_f));
            }

            lb_close(isfd);
            return (sizeof(struct hi_reduce_tbl_f));
        }
    }else{
        lane_log( "Red CarNo TableData Request Error!\n");
        //lb_close(isfd);
        return (-1);
    }
#endif
}

/*
 *========================================================================
 *
 *   Function : snd_warr_snd_no()
 *   Progrmer : JBY (baarong@neighbor21.co.kr)
 *   Date     : 2018.09.03
 *   Modified :
 *   Remark   : 보증 전송연번 송신
 *
 *========================================================================
*/

int snd_warr_snd_no()
{
    struct    hi_warr_snd_no    *warr;
//lane_log("보증전송연번 송신 1\n");
    warr = (struct hi_warr_snd_no *)hi_comm_ctrl.snd.buf;
    memset(warr, 0, sizeof(struct hi_warr_snd_no));
//lane_log("보증전송연번 송신 2\n");
    sprintf((char *)warr->kind, "%02x", NS_WARR_SND_NO);
    sprintf((char *)warr->warr_seq_no, "%08x", hi_comm_ctrl.warr_snd_no);
//lane_log("보증전송연번 송신 3[%08x]\n", hi_comm_ctrl.warr_snd_no);
    return (sizeof(struct hi_warr_snd_no));
}

/*
 *========================================================================
 *
 *   Function : lane_cir_test()
 *   Progrmer : JBY (baarong@neighbor21.co.kr)
 *   Date     : 2018.09.03
 *   Modified :
 *   Remark   : 차로측 기동 회선 TEST에 대한 응답 처리
*
*========================================================================
*/

int lane_cir_test()
{
    struct    hi_lane_line_test     *cir_test_q;
    struct    hi_lane_line_test     *cir_test_r;

    cir_test_q = (struct hi_lane_line_test *)hi_comm_ctrl.rcv_ctrl.buf;
    cir_test_r = (struct hi_lane_line_test *)hi_comm_ctrl.snd.buf;

    memset(cir_test_r, 0, sizeof(struct hi_lane_line_test));

    sprintf((char *)cir_test_r->kind, "%02x", NS_LANE_LINE_TEST_REPLY);
    memcpy(cir_test_r->test_data, cir_test_q->test_data, sizeof(cir_test_r->test_data));

    return (sizeof(struct hi_lane_line_test));
}

/*
*========================================================================
*
*   함 수 명 : rq_plz_cir_test
*   작 성 자 : JBY
*   작 성 일 : 2012.09.18
*   수 정 일 :
*   설    명 : 영업소측 회선 TEST 요구
*
*========================================================================
*/

int rq_plz_cir_test()
{
    struct    hi_lane_line_test     *cir_test_q;
    char     *buf = "1234567890abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ가나다라마바사아자차카타파하";

    cir_test_q = (struct hi_lane_line_test *)hi_comm_ctrl.snd.buf;

    memset(cir_test_q, 0, sizeof(struct hi_lane_line_test));

    sprintf((char *)cir_test_q->kind, "%02x", NS_PLZ_LINE_TEST);

    memcpy(cir_test_q->test_data, buf, strlen(buf));

    return (sizeof(struct hi_lane_line_test));
}

/*
*========================================================================
*
*   함 수 명 : target_cnt
*   작 성 자 : JBY
*   작 성 일 : 2019.05.12
*   수 정 일 :
*   설    명 : 특정 대상 건수 반환
*
*========================================================================
*/

int target_cnt(int isfd, int fno, char *target)
{
    int cnt, isrc;
    struct imm_carno_info s1;
	struct bef_mst_tbl    s2;
	struct red_carno_info s3;
	struct imm_card_info  s4;
//lane_log("TARGET[%s]\n", target);
    cnt = 0;

    switch(fno)
    {
    case FNO_IMM_CARNO:
	case FNO_IMM_CARNO_CHG:
        while( (isrc = lb_readl(isfd, &s1, FNEXT, sizeof(struct nonpay_info)))>0)
        {
            if (!memcmp(s1.carno_code, target, 10)) cnt++;
        }
        lseek(isfd, 0, SEEK_SET);
        break;
    case FNO_BEFMST:
	case FNO_BEFCNG:
        while( (isrc = lb_readl(isfd, &s2, FNEXT, sizeof(struct bef_mst_tbl)))>0)
        {
            if (!memcmp(s2.car_no, target, 10)) cnt++;
        }
        lseek(isfd, 0, SEEK_SET);
        break;
    case FNO_RED_CARNO:
	case FNO_RED_CARNO_CHG:
        while( (isrc = lb_readl(isfd, &s3, FNEXT, sizeof(struct bef_mst_tbl)))>0)
        {
            if (!memcmp(s3.carno_code, target, 10)) cnt++;
        }
        lseek(isfd, 0, SEEK_SET);
        break;
    case FNO_IMM_CARDNO:
	case FNO_IMM_CARDNO_CHG:
        while( (isrc = lb_readl(isfd, &s4, FNEXT, sizeof(struct bef_mst_tbl)))>0)
        {
            if (!memcmp(s4.carno_code, target, 10)) cnt++;
        }
        lseek(isfd, 0, SEEK_SET);
        break;
    }
//lane_log("CNT[%d]\n", cnt);    
    return cnt;
}

/*
*========================================================================
*
*   함 수 명 : snd_non_pay_srch_rlt
*   작 성 자 : JBY
*   작 성 일 : 2019.05.12
*   수 정 일 :
*   설    명 : 미납정보조회결과 데이터 송신
*
*========================================================================
*/

int snd_non_pay_srch_rlt(int rsp)
{
    struct hi_non_pay_srch *rq_srch;
    struct hi_non_pay_rlt  *hnpr;
    struct nonpay_info      ni;
    int srch_cnt = 0;
    int ii, isrc;

    rq_srch = (struct hi_non_pay_srch *)hi_comm_ctrl.rcv_ctrl.buf;
    hnpr = (struct hi_non_pay_rlt *)hi_comm_ctrl.snd.buf;

    memset(hnpr, 0x00, sizeof(struct hi_non_pay_rlt));

    isfd = lb_fopen(&hi_comm_ctrl.write_info, FNO_NONPAY, FINPUT+FC_MANULOCK);
    if (isfd < 0)
    {
        lane_log( "미납정보 Open Fail[%d]\n", isfd);
        lb_close(isfd);
        return(-1);
    }

    srch_cnt = target_cnt(isfd, FNO_NONPAY, rq_srch->car_code);
    sprintf((char *)hnpr->kind, "%02x", NS_NON_PAY_RLT); /* 종별        */

//lane_log("목표[%s][%d]\n", rq_srch->car_code, srch_cnt);

    while(1)
    {
        isrc = lb_readl(isfd, &ni, FNEXT, sizeof(struct nonpay_info));

        if (isrc <= 0)
        {
            //lb_close(isfd);
            break;
        }
        
		if(strncmp(rq_srch->car_code, ni.carno_code, 10) == 0)
		{
            sprintf((char *)hnpr->tot_cnt, "%04d", lb_data2atoi(ni.tot_cnt, 4));
	        sprintf((char *)hnpr->tot_fare, "%08d", lb_data2atoi(ni.tot_fare, 10));
	        sprintf((char *)hnpr->car_no, "%.10s", rq_srch->car_code);
            del_space(hnpr->car_no);
            for(ii =0; ii < 5; ii++)
			{
				sprintf((char *)hnpr->rlt_info[ii].wrk_dt    , "%.14s", ni.dtl[ii].hnd_datetm);
                sprintf((char *)hnpr->rlt_info[ii].lane_no   , "%02d" , lb_data2atoi(ni.dtl[ii].lane_no, 2));
                sprintf((char *)hnpr->rlt_info[ii].plz_id    , "%.2s" , ni.dtl[ii].plz_id);
                sprintf((char *)hnpr->rlt_info[ii].toll_amt  , "%08d" , lb_data2atoi(ni.dtl[ii].toll_amt, 8));
                sprintf((char *)hnpr->rlt_info[ii].notice_cnt, "%02d" , lb_data2atoi(ni.dtl[ii].notice_cnt,2));
                sprintf((char *)hnpr->rlt_info[ii].end_date  , "%.8s" , ni.dtl[ii].end_date);
			}
			break;
		}
    }

    lb_close(isfd);
    return (sizeof(struct hi_non_pay_rlt));
}

/*
*========================================================================
*
*   함 수 명 : snd_crd_no_srch_rlt
*   작 성 자 : JBY
*   작 성 일 : 2019.05.12
*   수 정 일 :
*   설    명 : 카드번호조회결과 데이터 송신
*
*========================================================================
*/

int snd_crd_no_srch_rlt(int rsp)
{
    struct hi_crd_srch *rq_srch;
    struct hi_crd_rlt  *hcr;
    struct nonpay_info  ni;
    struct bl_mst_tbl   bl_mst;
    struct bl_chg_tbl   bl_chg;
    char path[100];
    char buffer[1+1];
	char alias[10+1];
    int srch_cnt = 0;
    int ii;
    int isrc;
    int fileno = 0, location, rslt;
    FILE *fp = NULL;

    rq_srch = (struct hi_crd_srch *)hi_comm_ctrl.rcv_ctrl.buf;
    hcr = (struct hi_crd_rlt *)hi_comm_ctrl.snd.buf;
//lane_log("카드번호조회 1\n");
    memset(hcr, 0x00, sizeof(struct hi_crd_rlt));
    memset(path, 0x00, sizeof(path));
    memset(buffer, 0x00, sizeof(buffer));
//lane_log("카드번호조회 2[%02x]\n", rq_srch->div);
    switch(rq_srch->div)
    {
        case 1:
		    sprintf(alias, "%.10s%c", rq_srch->srch_number, '\0');
#if 0
            if(lb_data2atoi(alias, 10) > 900000000)
            {
                rslt = 0;
            }
            else
            {
#endif
            fileno = lb_data2atoi(alias, 10) / 100000000;
            location = lb_data2atoi(alias, 10) % 100000000;
//lane_log("FILE[%.10s][%d][%d]\n", alias, fileno, location);
			//location = lb_data2atoi(alias, 10);
            if(location == 0)
            {
                fileno--;
                location = 100000000;
            }

            //sprintf(path, "%s/%s/PLTPCARDMST", DIR_TCS, DIR_BASEINFO);
            sprintf(path, "%s/%s/PLBASE/PLMST%03d", DIR_TCS, DIR_BASEINFO, fileno);
            fp = fopen(path, "r+");
            if(fp == NULL)
            {
                lane_log("file(%s) open error!\n", path);
                return(-1);
            }

            fseek(fp, location-1, SEEK_SET);
            fread(buffer, sizeof(char), 1, fp);
            
			if( !strcmp(buffer, "0"))
			{
				rslt = 1;
			}else if( !strcmp(buffer, "1"))
			{
				rslt = 0;
			}else
				lane_log("location[%d]\n", location);

//lane_log("카드번호조회 5[%c][%d]\n", buffer[0], rslt);
            fclose(fp);
#if 0
            }
#endif
        break;
        case 2:
            isfd = lb_fopen(&hi_comm_ctrl.write_info, FNO_BLCNG, FINPUT+FC_MANULOCK);
            if (isfd < 0)
            {
                lane_log( "교통카드 BL 변경분 Open Fail[%d]\n", isfd);
                isfd = lb_fopen(&hi_comm_ctrl.write_info, FNO_BLMST, FINPUT+FC_MANULOCK);
                if(isfd < 0)
                {
                    lane_log( "교통카드 BL 마스터 Open Fail[%d]\n", isfd);
                    lb_close(isfd);
                    return(-1);
                }
                srch_cnt = lb_record_cnt(isfd, FNO_BLMST);
                
                for(ii = 0; ii < srch_cnt ; ii++)
                {
                    isrc = lb_readl(isfd, &bl_mst, FNEXT, sizeof(struct bl_mst_tbl));
                    
                    if (isrc <= 0)
                    {
                        //lb_close(isfd);
                        break;
                    }
                    
                    if(strncmp(bl_mst.crd_no, rq_srch->srch_number, sizeof(bl_mst.crd_no)) == 0)
                    {
                        rslt = lb_data2atoi(bl_mst.inst_yn, 2);

                        if(rslt == 0)
                            rslt = 1;
                        else 
                            rslt = 0;
                    }
                }
            }else
            {
                srch_cnt = lb_record_cnt(isfd, FNO_BLCNG);
                fileno = 0;

                for(ii = 0; ii < srch_cnt ; ii++)
                {
                    isrc = lb_readl(isfd, &bl_chg, FNEXT, sizeof(struct bl_chg_tbl));
                    
                    if (isrc <= 0)
                    {
                        //lb_close(isfd);
                        break;
                    }
                    
                    if(strncmp(bl_chg.crd_no, rq_srch->srch_number, sizeof(bl_chg.crd_no)) == 0)
                    {
                        fileno = 1;
                        rslt = lb_data2atoi(bl_chg.inst_yn, 2);

                        if(rslt == 0)
                            rslt = 1;
                        else 
                            rslt = 0;
                    }
                }
//lane_log("카드번호조회 6\n");
                if(fileno == 0)
                {
                    srch_cnt = lb_record_cnt(isfd, FNO_BLMST);
                    for(ii = 0; ii < srch_cnt ; ii++)
                    {
                        isrc = lb_readl(isfd, &bl_mst, FNEXT, sizeof(struct bl_mst_tbl));
                        
                        if (isrc <= 0)
                        {
                            //lb_close(isfd);
                            break;
                        }
                        
                        if(strncmp(bl_mst.crd_no, rq_srch->srch_number, sizeof(bl_mst.crd_no)) == 0)
                        {
                            rslt = lb_data2atoi(bl_mst.inst_yn, 2);
                    
                            if(rslt == 0)
                                rslt = 1;
                            else 
                                rslt = 0;
                        }
                    }
                }
            }
        break;
        default :
            lane_log("지정되지 않은 구분 값\n");
            return(-1);
        break;
    }
//lane_log("카드번호조회 7[%d]\n", rslt);
    sprintf((char *)hcr->kind, "%02x", NS_CRD_RLT); /* 종별 */
//lane_log("카드번호조회 8[%d]\n", rslt);
    sprintf((char *)hcr->rlt, "%02d", rslt);        /* 결과 */
//lane_log("카드번호조회 9[%d]\n", rslt);
    lb_close(isfd);
//lane_log("카드번호조회 10[%d]\n", rslt);
    //fclose(fp);
//lane_log("카드번호조회 11[%d]\n", rslt);
    return (sizeof(struct hi_crd_rlt));
}

/*
*========================================================================
*
*   함 수 명 : snd_imm_red_srch_rlt
*   작 성 자 : JBY
*   작 성 일 : 2019.06.18
*   수 정 일 :
*   설    명 : 면제감면조회결과 데이터 송신
*
*========================================================================
*/

int snd_imm_red_srch_rlt(int rsp)
{
    struct hi_immred_srch *rq_srch;
    struct hi_immred_rlt  *hnpr;
    struct imm_carno_info  s1;
	struct bef_mst_tbl     s2;
	struct red_carno_info  s3;
	struct imm_card_info   s4;
    int srch_cnt = 0;
    int ii, isrc;

    rq_srch = (struct hi_immred_srch *)hi_comm_ctrl.rcv_ctrl.buf;
    hnpr = (struct hi_immred_rlt *)hi_comm_ctrl.snd.buf;

    memset(hnpr, 0x00, sizeof(struct hi_immred_rlt));

    isfd = lb_fopen(&hi_comm_ctrl.write_info, FNO_IMM_CARNO_CHG, FINPUT+FC_MANULOCK);
    if (isfd < 0)
    {
        lane_log( "차량번호면제 CHG Open Fail[%d]\n", isfd);
		isfd = lb_fopen(&hi_comm_ctrl.write_info, FNO_IMM_CARNO, FINPUT+FC_MANULOCK);
		if(isfd < 0)
		{
			lane_log( "차량번호면제 MST Open Fail[%d]\n", isfd);
            lb_close(isfd);
            return(-1);
		}else
			srch_cnt = lb_record_cnt(isfd, FNO_IMM_CARNO);
    }else
		srch_cnt = lb_record_cnt(isfd, FNO_IMM_CARNO_CHG);

    sprintf((char *)hnpr->kind, "%02x", NS_IMMRED_RLT); /* 종별        */

//lane_log("목표[%s][%d]\n", rq_srch->car_no_cd, srch_cnt);

    for(ii = 0; ii < srch_cnt; ii++)
    {
        isrc = lb_readl(isfd, &s1, FNEXT, sizeof(struct imm_carno_info));

        if (isrc <= 0)
        {
            //lb_close(isfd);
            break;
        }
        
		if(strncmp(rq_srch->car_no_cd, s1.carno_code, 10)==0)
		{
            sprintf((char *)hnpr->rlt, "01");
	        hnpr->dtl = lb_data2atoi(s1.div, 2);
			
			return (sizeof(struct hi_immred_rlt));
		}
    }

    lb_close(isfd);

    isfd = lb_fopen(&hi_comm_ctrl.write_info, FNO_BEFCNG, FINPUT+FC_MANULOCK);
    if (isfd < 0)
    {
        lane_log( "사전등록 CHG Open Fail[%d]\n", isfd);
		isfd = lb_fopen(&hi_comm_ctrl.write_info, FNO_BEFMST, FINPUT+FC_MANULOCK);
		if(isfd < 0)
		{
			lane_log( "사전등록 MST Open Fail[%d]\n", isfd);
            lb_close(isfd);
            return(-1);
		}else
			srch_cnt = lb_record_cnt(isfd, FNO_BEFMST);
    }else
		srch_cnt = lb_record_cnt(isfd, FNO_BEFCNG);

    for(ii = 0; ii < srch_cnt; ii++)
    {
        isrc = lb_readl(isfd, &s2, FNEXT, sizeof(struct bef_mst_tbl));

        if (isrc <= 0)
        {
            //lb_close(isfd);
            break;
        }
        
		if(strncmp(rq_srch->car_no_cd, s2.car_no, 10)==0)
		{
            sprintf((char *)hnpr->rlt, "02");
	        hnpr->dtl = lb_data2atoi(s2.kind, 2);
			lb_close(isfd);
			return (sizeof(struct hi_immred_rlt));
		}
    }

    lb_close(isfd);

    isfd = lb_fopen(&hi_comm_ctrl.write_info, FNO_RED_CARNO_CHG, FINPUT+FC_MANULOCK);
    if (isfd < 0)
    {
        lane_log( "차량번호감면 CHG Open Fail[%d]\n", isfd);
		isfd = lb_fopen(&hi_comm_ctrl.write_info, FNO_RED_CARNO, FINPUT+FC_MANULOCK);
		if(isfd < 0)
		{
			lane_log( "차량번호감면 MST Open Fail[%d]\n", isfd);
            lb_close(isfd);
            return(-1);
		}else
			srch_cnt = lb_record_cnt(isfd, FNO_RED_CARNO);
    }else
		srch_cnt = lb_record_cnt(isfd, FNO_RED_CARNO_CHG);

    for(ii = 0; ii < srch_cnt; ii++)
    {
        isrc = lb_readl(isfd, &s3, FNEXT, sizeof(struct red_carno_info));

        if (isrc <= 0)
        {
            //lb_close(isfd);
            break;
        }
        
		if(strncmp(rq_srch->car_no_cd, s3.carno_code, 10)==0)
		{
            sprintf((char *)hnpr->rlt, "03");
	        hnpr->dtl = lb_data2atoi(s3.div, 2);
			
			return (sizeof(struct hi_immred_rlt));
		}
    }

    lb_close(isfd);

    isfd = lb_fopen(&hi_comm_ctrl.write_info, FNO_IMM_CARDNO_CHG, FINPUT+FC_MANULOCK);
    if (isfd < 0)
    {
        lane_log( "저공해/요일제 CHG Open Fail[%d]\n", isfd);
		isfd = lb_fopen(&hi_comm_ctrl.write_info, FNO_IMM_CARDNO, FINPUT+FC_MANULOCK);
		if(isfd < 0)
		{
			lane_log( "저공해/요일제 MST Open Fail[%d]\n", isfd);
            lb_close(isfd);
            return(-1);
		}else
			srch_cnt = lb_record_cnt(isfd, FNO_IMM_CARDNO);
    }else
		srch_cnt = lb_record_cnt(isfd, FNO_IMM_CARDNO_CHG);

    for(ii = 0; ii < srch_cnt; ii++)
    {
        isrc = lb_readl(isfd, &s4, FNEXT, sizeof(struct imm_card_info));

        if (isrc <= 0)
        {
            //lb_close(isfd);
            break;
        }
        
		if(strncmp(rq_srch->car_no_cd, s4.carno_code, 10)==0)
		{
            sprintf((char *)hnpr->rlt, "04");
	        hnpr->dtl = s4.div - '0';
			hnpr->unap_div = s4.non_cnt;
			hnpr->vio_div = s4.vio_cnt;

            lb_close(isfd);
			return (sizeof(struct hi_immred_rlt));
		}
    }

    lb_close(isfd);

    return (sizeof(struct hi_immred_rlt));
}

/*
*========================================================================
*
*   함 수 명 : chg_asc_ks_code
*   작 성 자 : JBY
*   작 성 일 : 2012.09.18
*   수 정 일 :
*   설    명 : ASCII 문자열을 DOUBLE BYTE의 KS CODE로 변환
*
*========================================================================
*/

void chg_asc_ks_code(uchar *ksc, int ksl, uchar *asc, int asl)
{
    int    mc;
    int    ii, jj;

    for (ii = 0, jj = 0; ii < asl; ii++)
    {
        if (asc[ii] == '\0')
            break;
        if (asc[ii] & 0x80)
        {
            ksc[jj++] = asc[ii];
            if (jj >= ksl)
            break;
            continue;
        }
        if ((jj + 1) >= ksl)
            break;

        if (asc[ii] <= ' ')
            mc = 0x8140;
        else
            mc = 0xa3a0 + (asc[ii] - 0x20);
        ksc[jj++] = mc >> 8;
        ksc[jj++] = mc;
    }
}
/*
*========================================================================
*
*   함 수 명 : hextodig
*   작 성 자 : JBY
*   작 성 일 : 2019.05.28
*   수 정 일 :
*   설    명 : HEX 문자를 Digit으로 변경
*
*========================================================================
*/
int hextodig(char *target)
{
    char hexadecimal[20];             // 16진수로 된 문자열
    int decimal = 0;                  // 10진수를 저장할 변수
    int i, j;
    memset(hexadecimal, 0x00, sizeof(hexadecimal));
    
    sprintf(hexadecimal, "%.8s", target);
//lane_log("16진수 문자열[%.8s]\n", hexadecimal);
    int position = 0;
    for (i = strlen(hexadecimal) - 1; i >= 0; i--)    // 문자열을 역순으로 반복
    {
        char ch = hexadecimal[i];         // 각 자릿수에 해당하는 문자를 얻음

        if (ch >= 48 && ch <= 57)         // 문자가 0~9이면(ASCII 코드 48~57)
        {
            // 문자에서 0에 해당하는 ASCII 코드 값을 빼고
            // 16에 자릿수를 거듭제곱한 값을 곱함
            decimal += (ch - 48) * pow(16, position);
        }
        else if (ch >= 65 && ch <= 70)    // 문자가 A~F이면(ASCII 코드 65~70)
        {                                 // 대문자로 된 16진수의 처리
            // 문자에서 (A에 해당하는 ASCII 코드 값 - 10)을 빼고
            // 16에 자릿수를 거듭제곱한 값을 곱함
            decimal += (ch - (65 - 10)) * pow(16, position);
        }
        else if (ch >= 97 && ch <= 102)   // 문자가 a~f이면(ASCII 코드 97~102)
        {                                 // 소문자로 된 16진수의 처리
            // 문자에서 (a에 해당하는 ASCII 코드 값 - 10)을 빼고
            // 16에 자릿수를 거듭제곱한 값을 곱함
            decimal += (ch - (97 - 10)) * pow(16, position);
        }

        position++;
    }

    printf("%d\n", decimal);    // 300

    return decimal;
}
