/*
*========================================================================
*
*   SYSTEM   : AZN_PLAZA_LANE BACKGROUND
*   FILE     : send_tagbl.sc
*   Progrmer : JBY (baarong@neighbor21.co.kr)
*   Date     : 2019.04.29
*   Modified :
*   Remark   : Background Transfer Module
 *
 *========================================================================
*/

#include <stdio.h>
#include <stdlib.h>
#include <fcntl.h>
#include <time.h>
#include <sys/time.h>

#include "file_no.h"
#include "lo_packet_format.h"
#include "lo_ctrl.h"
#include "snd_rcv_knd.h"
#include "func_list.h"
#include "lb_func_list.h"
#include "bl_chg.h"
#include "bl_mst.h"
#include "pl_mst.h"
#include "pl_chg.h"
#include "pl_read.h"
#include "imm_carno_info.h"
#include "imm_card_info.h"
#include "red_carno_info.h"
#include "bef_mst.h"

extern    int    send_tcrd_bl();
extern    int    send_tcrd_pl();
extern    int    send_imm_carNo();
extern    int    send_imm_rfid();
extern    int    send_adv_carno();
extern    int    send_red_carno();

struct    file_tbl {
    int    file_id;                               /* File id 			*/
    int    (*func)();                             /* Transger Function 	*/
} file_tbl[] = {                                  /* File Table 		*/
    { FNO_BLMST         , send_tcrd_bl      },    /* 교통카드 B/L		*/
    { FNO_PLMST         , send_tcrd_pl      },    /* 교통카드 P/L		*/
    { FNO_IMM_CARNO     , send_imm_carNo    },    /* 차량번호면제		*/
    { FNO_IMM_CARDNO    , send_imm_rfid     },    /* 저공해/요일제		*/
    { FNO_BEFMST        , send_adv_carno    },    /* 사전결제           */
    { FNO_RED_CARNO     , send_red_carno    },    /* 차량번호감면		*/
    { -1                , NULL              }     /* End of tables   	*/
};

struct    lo_comm_ctrl    lo_comm_ctrl; 

int send_tagbl(struct bl_struct *cs)
{
    int    retc;
    int    ii;
	char   tmp[2+1];

proc_log("Back Send 1[%d]\n", lb_data2atoi(cs->file_id, 2));
    for (ii = 0; file_tbl[ii].file_id != -1; ii++)
    {
proc_log("[%d][%d]\n", ii, file_tbl[ii].file_id);
        if (file_tbl[ii].file_id == lb_data2atoi(cs->file_id, 2))
            break;
    }
proc_log("Back Send 2[%d][%d]\n", lb_data2atoi(cs->file_id, 2), file_tbl[ii].file_id);
    if (file_tbl[ii].file_id == -1) 
    {
        return (0);
    }
proc_log("Back Send 3[%d][%d]\n", lb_data2atoi(cs->file_id, 2), file_tbl[ii].file_id);
    retc = (*file_tbl[ii].func)(cs); 
proc_log("Back Send End\n");
    return (retc);
}

/*
 *========================================================================
 *
 *   Function : send_tcrd_bl()
 *   Progrmer : JBY (baarong@neighbor21.co.kr)
 *   Date     : 2019.04.29
 *   Modified :
 *   Remark   : 교통카드 B/L Master data Background Transfer
 *
 *========================================================================
*/

int send_tcrd_bl(struct bl_struct *cs)
{
    struct write_info   wf;
    struct bl_mst_tbl   bl_tcrd_mst;
    struct hi_bl_tbl_h *bl_tcrd_h;
    struct hi_bl_tbl_f *bl_tcrd_f;
    int  pos, isrc,ii, jj,row=0, row2=0;
    int  tmp_ldyb[111];
    int  frame_cnt = 0;
    int  repeat_cnt;
    int  ret=0;
	char tmp[10+1];
	int isfd;

    bl_tcrd_h = (struct hi_bl_tbl_h *)hi_comm_ctrl.snd.buf;
    bl_tcrd_f = (struct hi_bl_tbl_f *)hi_comm_ctrl.snd.buf;

    memset(tmp_ldyb, '0', sizeof(tmp_ldyb));

	/* Master Header Transfer */
    memset(bl_tcrd_h, 0, sizeof(struct hi_bl_tbl_h));
    sprintf((char *)bl_tcrd_h->seq_no, "%.8s", cs->seq_no);
    sprintf((char *)bl_tcrd_h->kind, "%02x", NS_TBL_DATA);
    sprintf((char *)bl_tcrd_h->tbl_typ, "%02d", TB_BL_CRD);
    sprintf((char *)bl_tcrd_h->frame_no, "00000000");
    sprintf((char *)bl_tcrd_h->frame_cnt, "00000000");

    isfd = lb_fopen(&wf, FNO_BLMST, FINPUT+FC_MANULOCK);
    
    if (isfd < 0)
    {
        proc_log( "교통카드 B/L Master open error\n");
    }

    row = lb_record_cnt(isfd, FNO_BLMST); 

    if (row < 0)
    {
        row = 0;
        proc_log( "교통카드 B/L MASTER row not exist\n");
    }

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

    memcpy(&bl_tcrd_h->rvs_no, &cs->rvs_no, sizeof(bl_tcrd_h->rvs_no));
    hi_comm_ctrl.frame_no = 0;

    sprintf((char *)bl_tcrd_h->frame_cnt, "%08x", frame_cnt);
    sprintf((char *)bl_tcrd_h->rvs_no, "%.2s", cs->rvs_no);
    sprintf((char *)bl_tcrd_h->div, "00");

    e_memcpy(bl_tcrd_h->bl_aply_year , cs->rvs_year );
	e_memcpy(bl_tcrd_h->bl_aply_month, cs->rvs_month);
	e_memcpy(bl_tcrd_h->bl_aply_day  , cs->rvs_day  );
	e_memcpy(bl_tcrd_h->bl_aply_hour , cs->rvs_hour );
	e_memcpy(bl_tcrd_h->bl_aply_min  , cs->rvs_min  );
	
    e_memcpy(bl_tcrd_h->bl_modf_year , cs->modf_year );
	e_memcpy(bl_tcrd_h->bl_modf_month, cs->modf_month);
	e_memcpy(bl_tcrd_h->bl_modf_day  , cs->modf_day  );
	e_memcpy(bl_tcrd_h->bl_modf_hour , cs->modf_hour );
	e_memcpy(bl_tcrd_h->bl_modf_min  , cs->modf_min  );

    lb_close(isfd);

    memset(lo_comm_ctrl.pkt.buf, 0, sizeof(lo_comm_ctrl.pkt.buf));

    tcrdbl_hd_packet_chng(hi_comm_ctrl.snd.buf, lo_comm_ctrl.pkt.buf);
    
    lo_comm_ctrl.pkt.len = sizeof(struct tbl_data);
    lo_comm_ctrl.pkt.buf[lo_comm_ctrl.pkt.len++] = ETX;
    lo_comm_ctrl.pkt.flg = LP_SEND;
    
    memcpy(lo_comm_ctrl.snd.buf, lo_comm_ctrl.pkt.buf, lo_comm_ctrl.pkt.len);

    lo_comm_ctrl.snd.len = lo_comm_ctrl.pkt.len;

    ret = sock_send_data();

    if (ret == 0)
    {
        proc_log( "교통카드 B/L MASTER Transfer[%.2s]\n", cs->lane_no);
    }
    else if (ret < 0) return ret;

	/* Master data Transfer */
    repeat_cnt = frame_cnt;
    for(ii = 0; ii < repeat_cnt; ii++)
    {
        //lb_close(isfd);
        isfd = lb_fopen(&wf, FNO_BLMST, FINPUT+FC_MANULOCK);
        if (isfd < 0) return (-1);
        pos = (ii)*111 ;

        row = lb_record_cnt(isfd,FNO_BLMST);
        if (row < 0) row = 0;

        lseek(isfd, pos * sizeof(struct bl_mst_tbl),SEEK_SET);

        row2 = 0;

        memset(bl_tcrd_f, 0, sizeof(struct hi_bl_tbl_f));
        memset(&bl_tcrd_mst, 0, sizeof(struct bl_mst_tbl));

        for(jj = 0; jj < 111; jj++)
        {
            isrc = lb_readl(isfd, &bl_tcrd_mst, FNEXT, sizeof(struct bl_mst_tbl));
            if (isrc <= 0) break;

            sprintf(tmp, "%08x%c", bl_tcrd_mst.mngt_no, '\0');
            tmp_ldyb[jj] = strtoul(tmp, NULL, 16); 
            row2++;
        }

        sprintf((char *)bl_tcrd_f->seq_no, "%.8s", cs->seq_no);
        sprintf((char *)bl_tcrd_f->kind, "%02x", NS_TBL_DATA);
        sprintf((char *)bl_tcrd_f->tbl_typ, "%02d", TB_BL_CRD);
        sprintf((char *)bl_tcrd_f->frame_no, "%08x", ii+1);
        sprintf((char *)bl_tcrd_f->last_data_seq_no, "%08x", tmp_ldyb[jj-1]);
        sprintf((char *)bl_tcrd_f->item_cnt, "%02x", row2);

        lseek(isfd, -row2*sizeof(struct bl_mst_tbl), SEEK_CUR);

        for(jj = 0; jj < 111; jj++)
        {
            isrc = lb_readl(isfd, &bl_tcrd_mst, FNEXT, sizeof(struct bl_mst_tbl));
            if (isrc <= 0) break;

            e_memcpy(bl_tcrd_f->bl_data[jj].div, bl_tcrd_mst.inst_yn);
            e_memcpy(bl_tcrd_f->bl_data[jj].crd_no, bl_tcrd_mst.crd_no);
        }

        lb_close(isfd);

        memset(lo_comm_ctrl.pkt.buf, 0, sizeof(struct tbl_data));

        tcrdbl_fr_packet_chng(hi_comm_ctrl.snd.buf, lo_comm_ctrl.pkt.buf);

        lo_comm_ctrl.pkt.len = sizeof(struct tbl_data);
        lo_comm_ctrl.pkt.buf[lo_comm_ctrl.pkt.len++] = ETX;
        lo_comm_ctrl.pkt.flg = LP_SEND;
        
        memcpy(lo_comm_ctrl.snd.buf, lo_comm_ctrl.pkt.buf, lo_comm_ctrl.pkt.len);

        lo_comm_ctrl.snd.len = lo_comm_ctrl.pkt.len;

        ret = sock_send_data();
        if (ret == 0)
        {
            if((ii%1000==0) || (ii+1==repeat_cnt))
                proc_log( "교통카드 B/L Master[%.2s] data Transfer Completion(%d/%d)\n", cs->lane_no, ii+1, repeat_cnt);
        }
        else if(ret < 0) return ret;
    }
    return (0);
}

/*
 *========================================================================
 *
 *   Function : send_tcrd_pl()
 *   Progrmer : JBY (baarong@neighbor21.co.kr)
 *   Date     : 2019.04.29
 *   Modified :
 *   Remark   : 교통카드 P/L TABLE 송신
 *
 *========================================================================
*/

int send_tcrd_pl(struct bl_struct *cs)
{
    struct  write_info     wf;
    struct  pl_read_tbl    pl_tcrd_mst;
    struct  hi_pl_tbl_h   *pl_tcrd_h;
    struct  hi_pl_tbl_f   *pl_tcrd_f;
    int    pos, isrc,ii, jj,row=0, row2=0, row3=0;
    int    tmp_ldyb[1004], len, value, vfrst;
	int frame_cnt = 0;
    int repeat_cnt;
    int ret=0;
	char *st;
	char tmp_snd[8+1];
	int isfd;
//printf("01\n");
    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;
//printf("02\n");
    memset(tmp_ldyb, '0', sizeof(tmp_ldyb));
//printf("03\n");
/* 마스터 헤더 전송 */
    memset(pl_tcrd_h, 0, sizeof(struct hi_pl_tbl_h));
//printf("04\n");
    sprintf((char *)pl_tcrd_h->seq_no, "%.8s", cs->seq_no);
    sprintf((char *)pl_tcrd_h->kind, "%02x", NS_TBL_DATA);
    sprintf((char *)pl_tcrd_h->tbl_typ, "%02d", TB_PL_CRD);
    sprintf((char *)pl_tcrd_h->frame_no, "00000000");
    sprintf((char *)pl_tcrd_h->frame_cnt, "00000000");
//printf("05\n");
    for(ii=0; ii<17; ii++)
    {
        sprintf((char *)pl_tcrd_h->pl_block[ii].block_st_no, "00000000");
        sprintf((char *)pl_tcrd_h->pl_block[ii].block_cnt, "00000000");
    }
//printf("06\n");
    isfd = lb_fopen(&wf, FNO_PLREAD, FINPUT+FC_MANULOCK);
//printf("07\n");
    if (isfd < 0)
    {   
        proc_log( "교통카드 P/L MASTER OPEN ERROR\n");
    }
//printf("08\n");
    row = lb_record_cnt(isfd, FNO_PLREAD);   /* PL총레코드수구하기 */

	proc_log("pl[%d] 레코드수 row = %d\n", isfd, row);
    if (row < 0)
    {
        row = 0;
        proc_log( "교통카드  P/L MASTER row 없음\n");
    }
//proc_log("PL File Read Cnt[%d]\n", row);
	frame_cnt = row / 1003;
//proc_log("PL Frame Cnt[%d]\n", frame_cnt);
    sprintf((char *)pl_tcrd_h->frame_cnt, "%08x", frame_cnt);
    sprintf((char *)pl_tcrd_h->rvs_no, "%.2s", cs->rvs_no);

    row3 = row / 1003;
    if ((frame_cnt == 0 && row != 0) || (row % 1003) != 0)
    {
        frame_cnt++;
		sprintf((char *)pl_tcrd_h->frame_cnt, "%08x", frame_cnt);
        row3++;
    }

    hi_comm_ctrl.frame_no = 0;
    sprintf((char *)pl_tcrd_h->frame_cnt, "%08x", frame_cnt);
    sprintf((char *)pl_tcrd_h->rvs_no, "%.2s", cs->rvs_no);
    sprintf((char *)pl_tcrd_h->div, "00");

    e_memcpy(pl_tcrd_h->pl_aply_year , cs->rvs_year );
	e_memcpy(pl_tcrd_h->pl_aply_month, cs->rvs_month);
	e_memcpy(pl_tcrd_h->pl_aply_day  , cs->rvs_day  );
	e_memcpy(pl_tcrd_h->pl_aply_hour , cs->rvs_hour );
	e_memcpy(pl_tcrd_h->pl_aply_min  , cs->rvs_min  );
	
    e_memcpy(pl_tcrd_h->pl_modf_year , cs->modf_year );
	e_memcpy(pl_tcrd_h->pl_modf_month, cs->modf_month);
	e_memcpy(pl_tcrd_h->pl_modf_day  , cs->modf_day  );
	e_memcpy(pl_tcrd_h->pl_modf_hour , cs->modf_hour );
	e_memcpy(pl_tcrd_h->pl_modf_min  , cs->modf_min  );

    sprintf((char *)pl_tcrd_h->pl_block[0].block_st_no, "%08x", 1);
    sprintf((char *)pl_tcrd_h->pl_block[0].block_cnt, "%08x", row / 1003 + 1);

    lb_close(isfd);
    
    memset(lo_comm_ctrl.pkt.buf, 0, sizeof(struct tbl_data));

    tcrdpl_hd_packet_chng(hi_comm_ctrl.snd.buf, lo_comm_ctrl.pkt.buf);

    lo_comm_ctrl.pkt.len = sizeof(struct tbl_data);
    lo_comm_ctrl.pkt.buf[lo_comm_ctrl.pkt.len++] = ETX;
    lo_comm_ctrl.pkt.flg = LP_SEND;
//proc_log("---------------------------------------------------");
//proc_log("PL Frame Cnd[%08x]\n", pl_tcrd_h->frame_cnt);
//proc_log("---------------------------------------------------");
    memcpy(lo_comm_ctrl.snd.buf, lo_comm_ctrl.pkt.buf, lo_comm_ctrl.pkt.len);

    lo_comm_ctrl.snd.len = lo_comm_ctrl.pkt.len;

	ret = sock_send_data();
    if (ret == 0)
    {
        proc_log( "교통카드  P/L MASTER [%.2s]전송\n", cs->lane_no);
    }
	else if(ret < 0) return ret;
//printf("PL1[%d]\n", row3);
/* 마스터 DATA 전송 */
    for(ii = 0; ii < row3; ii++)
    {
        //lb_close(isfd);
        isfd = lb_fopen(&wf, FNO_PLREAD, FINPUT+FC_MANULOCK);
        if (isfd < 0) return (-1);
        pos = (ii)*1003 ;

        row = lb_record_cnt(isfd,FNO_PLREAD);
        if (row < 0) row = 0;
//printf("PL2[%d][%d]\n", ii, row);
        lseek(isfd, pos * sizeof(struct pl_read_tbl),SEEK_SET);

        sprintf((char *)pl_tcrd_f->seq_no, "%.8s", cs->seq_no);
        sprintf((char *)pl_tcrd_f->kind, "%02x", NS_TBL_DATA);
        sprintf((char *)pl_tcrd_f->tbl_typ, "%02d", TB_PL_CRD);
//printf("PL2-1[%d][%d]\n", ii, row);     
        row2 = 0;

        memset(pl_tcrd_f, 0, sizeof(struct hi_pl_tbl_f));
        memset(&pl_tcrd_mst, 0, sizeof(struct pl_read_tbl));
//printf("PL2-2[%d][%d]\n", ii, row);
        for(jj = 0; jj < 1003; jj++)
        {
            isrc = read(isfd, &pl_tcrd_mst, sizeof(struct pl_read_tbl));

            if (isrc <= 0) break;

            sprintf((char *)tmp_snd, "%.8s%c", pl_tcrd_mst.inst_yn, '\0');
            value=strtoul(tmp_snd, NULL, 2);
if(jj == 0)
{
	vfrst = value;
}
            sprintf((char *)pl_tcrd_f->seq_no, "%.8s", cs->seq_no);
            sprintf((char *)pl_tcrd_f->kind, "%02x", NS_TBL_DATA);
            sprintf((char *)pl_tcrd_f->tbl_typ, "%02d", TB_PL_CRD);
            sprintf((char *)pl_tcrd_f->frame_no, "%08x", ii+1);
            sprintf((char *)pl_tcrd_f->item_cnt, "%04x", row2+1);

            pl_tcrd_f->div[jj] = value;
//proc_log("ALIAS[%02x][%02x][%02x]", pl_tcrd_f->div[jj], value, strtoul(tmp_snd, NULL, 16));
            row2++;
        }

        lb_close(isfd);

        memset(lo_comm_ctrl.pkt.buf, 0, sizeof(struct tbl_data));

        tcrdpl_fr_packet_chng(hi_comm_ctrl.snd.buf, lo_comm_ctrl.pkt.buf);
//proc_log("LAST [%02x][%02x][%02x][%02x]\n", pl_tcrd_f->div[0], pl_tcrd_f->div[1], lo_comm_ctrl.pkt.buf[12], lo_comm_ctrl.pkt.buf[13]);
        lo_comm_ctrl.pkt.buf[12] = vfrst;
        lo_comm_ctrl.pkt.len = sizeof(struct tbl_data);
        lo_comm_ctrl.pkt.buf[lo_comm_ctrl.pkt.len++] = ETX;
        lo_comm_ctrl.pkt.flg = LP_SEND;

        memcpy(lo_comm_ctrl.snd.buf, lo_comm_ctrl.pkt.buf, lo_comm_ctrl.pkt.len);
//for(jj = 0; jj < 1016; jj++)
//{
//	proc_log("PL[%02x]", lo_comm_ctrl.snd.buf[jj]);
//}
        lo_comm_ctrl.snd.len = lo_comm_ctrl.pkt.len;
        
		ret = sock_send_data();
        if (ret == 0)
        {
	    	if((ii%1000==0) || (ii+1==row3))
            	proc_log( "교통카드 P/L MASTER DATA [%.2s]전송(%d/%d)\n", cs->lane_no, ii+1, row3);
        }
		else if(ret < 0) return ret;
    }
    return (0);
}

/*
 *========================================================================
 *
 *   Function : send_imm_carNo()
 *   Progrmer : JBY (baarong@neighbor21.co.kr)
 *   Date     : 2019.06.18
 *   Modified :
 *   Remark   : 차량번호면제 Master data Background Transfer
 *
 *========================================================================
*/

int send_imm_carNo(struct bl_struct *cs)
{
    struct write_info   wf;
    struct imm_carno_info   imm_carno_mst;
    struct hi_imm_carno_tbl_h *carno_h;
    struct hi_imm_carno_tbl_f *carno_f;
    int  pos, isrc,ii, jj,row=0, row2=0;
    int  tmp_ldyb[142];
    int  frame_cnt = 0;
    int  repeat_cnt;
    int  ret=0;
	char tmp[10+1];
	int isfd;

    carno_h = (struct hi_imm_carno_tbl_h *)hi_comm_ctrl.snd.buf;
    carno_f = (struct hi_imm_carno_tbl_f *)hi_comm_ctrl.snd.buf;

    memset(tmp_ldyb, '0', sizeof(tmp_ldyb));

	/* Master Header Transfer */
    memset(carno_h, 0, sizeof(struct hi_imm_carno_tbl_h));
    sprintf((char *)carno_h->seq_no, "%.8s", cs->seq_no);
    sprintf((char *)carno_h->kind, "%02x", NS_TBL_DATA);
    sprintf((char *)carno_h->tbl_typ, "%02d", TB_IMM_CARNO);
    sprintf((char *)carno_h->frame_no, "00000000");
    sprintf((char *)carno_h->frame_cnt, "00000000");

    isfd = lb_fopen(&wf, FNO_IMM_CARNO, FINPUT+FC_MANULOCK);

    if (isfd < 0)
    {
        proc_log( "차량번호면제 Master open error\n");
    }

    row = lb_record_cnt(isfd, FNO_IMM_CARNO); 

    if (row < 0)
    {
        row = 0;
        proc_log( "차량번호면제 MASTER row not exist\n");
    }

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

    memcpy(&carno_h->rvs_no, &cs->rvs_no, sizeof(carno_h->rvs_no));
    hi_comm_ctrl.frame_no = 0;

    sprintf((char *)carno_h->frame_cnt, "%08x", frame_cnt);
    sprintf((char *)carno_h->rvs_no, "%.2s", cs->rvs_no);
    sprintf((char *)carno_h->div, "00");

    e_memcpy(carno_h->imm_aply_year , cs->rvs_year );
	e_memcpy(carno_h->imm_aply_month, cs->rvs_month);
	e_memcpy(carno_h->imm_aply_day  , cs->rvs_day  );
	e_memcpy(carno_h->imm_aply_hour , cs->rvs_hour );
	e_memcpy(carno_h->imm_aply_min  , cs->rvs_min  );
	
    e_memcpy(carno_h->imm_modf_year , cs->modf_year );
	e_memcpy(carno_h->imm_modf_month, cs->modf_month);
	e_memcpy(carno_h->imm_modf_day  , cs->modf_day  );
	e_memcpy(carno_h->imm_modf_hour , cs->modf_hour );
	e_memcpy(carno_h->imm_modf_min  , cs->modf_min  );

    lb_close(isfd);

    memset(lo_comm_ctrl.pkt.buf, 0, sizeof(lo_comm_ctrl.pkt.buf));

    carno_hd_packet_chng(hi_comm_ctrl.snd.buf, lo_comm_ctrl.pkt.buf);

    lo_comm_ctrl.pkt.len = sizeof(struct tbl_data);
    lo_comm_ctrl.pkt.buf[lo_comm_ctrl.pkt.len++] = ETX;
    lo_comm_ctrl.pkt.flg = LP_SEND;

    memcpy(lo_comm_ctrl.snd.buf, lo_comm_ctrl.pkt.buf, lo_comm_ctrl.pkt.len);

    lo_comm_ctrl.snd.len = lo_comm_ctrl.pkt.len;
//printf("1[%d]\n", lo_comm_ctrl.snd.len);
    ret = sock_send_data();
//printf("2[%d]\n", ret);
    if (ret == 0)
    {
        proc_log( "차량번호면제 MASTER [%.2s]Transfer\n", cs->lane_no);
    }
    else if (ret < 0) return ret;

	/* Master data Transfer */
    repeat_cnt = frame_cnt;
    for(ii = 0; ii < repeat_cnt; ii++)
    {
        //lb_close(isfd);
        isfd = lb_fopen(&wf, FNO_IMM_CARNO, FINPUT+FC_MANULOCK);
        if (isfd < 0) return (-1);
        pos = (ii)*142 ;

        row = lb_record_cnt(isfd,FNO_IMM_CARNO);
        if (row < 0) row = 0;

        lseek(isfd, pos * sizeof(struct imm_carno_info),SEEK_SET);

        row2 = 0;

        memset(carno_f, 0, sizeof(struct hi_imm_carno_tbl_f));
        memset(&imm_carno_mst, 0, sizeof(struct imm_carno_info));

        for(jj = 0; jj < 142; jj++)
        {
            isrc = lb_readl(isfd, &imm_carno_mst, FNEXT, sizeof(struct imm_carno_info));
            if (isrc <= 0) break;

            sprintf(tmp, "%08x%c", lb_data2atoi(imm_carno_mst.snd_no, 10), '\0');
            tmp_ldyb[jj] = strtoul(tmp, NULL, 16); 
            row2++;
        }

        sprintf((char *)carno_f->seq_no, "%.8s", cs->seq_no);
        sprintf((char *)carno_f->kind, "%02x", NS_TBL_DATA);
        sprintf((char *)carno_f->tbl_typ, "%02d", TB_IMM_CARNO);
        sprintf((char *)carno_f->frame_no, "%08x", ii+1);
        sprintf((char *)carno_f->last_data_seq_no, "%08x", tmp_ldyb[jj-1]);
        sprintf((char *)carno_f->item_cnt, "%02x", row2);

        lseek(isfd, -row2*sizeof(struct imm_carno_info), SEEK_CUR);

        for(jj = 0; jj < 142; jj++)
        {
            isrc = lb_readl(isfd, &imm_carno_mst, FNEXT, sizeof(struct imm_carno_info));
            if (isrc <= 0) break;

            e_memcpy(carno_f->imm_info[jj].rgst_div, imm_carno_mst.rgst_div);
			e_memcpy(carno_f->imm_info[jj].imm_div, imm_carno_mst.div);
            e_memcpy(carno_f->imm_info[jj].car_no, imm_carno_mst.carno_code);
        }

        lb_close(isfd);

        memset(lo_comm_ctrl.pkt.buf, 0, sizeof(struct tbl_data));

        carno_fr_packet_chng(hi_comm_ctrl.snd.buf, lo_comm_ctrl.pkt.buf);

        lo_comm_ctrl.pkt.len = sizeof(struct tbl_data);
        lo_comm_ctrl.pkt.buf[lo_comm_ctrl.pkt.len++] = ETX;
        lo_comm_ctrl.pkt.flg = LP_SEND;
        
        memcpy(lo_comm_ctrl.snd.buf, lo_comm_ctrl.pkt.buf, lo_comm_ctrl.pkt.len);

        lo_comm_ctrl.snd.len = lo_comm_ctrl.pkt.len;

        ret = sock_send_data();
        if (ret == 0)
        {
            if((ii%1000==0) || (ii+1==repeat_cnt))
                proc_log( "차량번호면제 Master data [%.2s]Transfer Completion(%d/%d)\n", cs->lane_no, ii+1, repeat_cnt);
        }
        else if(ret < 0) return ret;
    }
    return (0);
}

/*
 *========================================================================
 *
 *   Function : send_imm_rfid()
 *   Progrmer : JBY (baarong@neighbor21.co.kr)
 *   Date     : 2019.06.18
 *   Modified :
 *   Remark   : 저공해/요일제 Master data Background Transfer
 *
 *========================================================================
*/

int send_imm_rfid(struct bl_struct *cs)
{
    struct write_info   wf;
    struct imm_card_info   imm_rfid_mst;
    struct hi_imm_crdno_tbl_h *rfid_h;
    struct hi_imm_crdno_tbl_f *rfid_f;
    int  pos, isrc,ii, jj,row=0, row2=0;
    int  tmp_ldyb[49];
    int  frame_cnt = 0;
    int  repeat_cnt;
    int  ret=0;
	char tmp[10+1];
	int isfd;

    rfid_h = (struct hi_imm_crdno_tbl_h *)hi_comm_ctrl.snd.buf;
    rfid_f = (struct hi_imm_crdno_tbl_f *)hi_comm_ctrl.snd.buf;

    memset(tmp_ldyb, '0', sizeof(tmp_ldyb));

	/* Master Header Transfer */
    memset(rfid_h, 0, sizeof(struct hi_imm_crdno_tbl_h));
    sprintf((char *)rfid_h->seq_no, "%.8s", cs->seq_no);
    sprintf((char *)rfid_h->kind, "%02x", NS_TBL_DATA);
    sprintf((char *)rfid_h->tbl_typ, "%02d", TB_IMM_CRDNO);
    sprintf((char *)rfid_h->frame_no, "00000000");
    sprintf((char *)rfid_h->frame_cnt, "00000000");

    isfd = lb_fopen(&wf, FNO_IMM_CARDNO, FINPUT+FC_MANULOCK);
    
    if (isfd < 0)
    {
        proc_log( "저공해/요일제 Master open error\n");
    }

    row = lb_record_cnt(isfd, FNO_IMM_CARDNO); 

    if (row < 0)
    {
        row = 0;
        proc_log( "저공해/요일제 MASTER row not exist\n");
    }

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

    hi_comm_ctrl.frame_no = 0;

    sprintf((char *)rfid_h->frame_cnt, "%08x", frame_cnt);
    sprintf((char *)rfid_h->rvs_no, "%.2s", cs->rvs_no);
    sprintf((char *)rfid_h->div, "00");

    e_memcpy(rfid_h->imm_aply_year , cs->rvs_year );
	e_memcpy(rfid_h->imm_aply_month, cs->rvs_month);
	e_memcpy(rfid_h->imm_aply_day  , cs->rvs_day  );
	e_memcpy(rfid_h->imm_aply_hour , cs->rvs_hour );
	e_memcpy(rfid_h->imm_aply_min  , cs->rvs_min  );
	
    e_memcpy(rfid_h->imm_modf_year , cs->modf_year );
	e_memcpy(rfid_h->imm_modf_month, cs->modf_month);
	e_memcpy(rfid_h->imm_modf_day  , cs->modf_day  );
	e_memcpy(rfid_h->imm_modf_hour , cs->modf_hour );
	e_memcpy(rfid_h->imm_modf_min  , cs->modf_min  );

    lb_close(isfd);

    memset(lo_comm_ctrl.pkt.buf, 0, sizeof(lo_comm_ctrl.pkt.buf));

    rfid_hd_packet_chng(hi_comm_ctrl.snd.buf, lo_comm_ctrl.pkt.buf);
    
    lo_comm_ctrl.pkt.len = sizeof(struct tbl_data);
    lo_comm_ctrl.pkt.buf[lo_comm_ctrl.pkt.len++] = ETX;
    lo_comm_ctrl.pkt.flg = LP_SEND;
    
    memcpy(lo_comm_ctrl.snd.buf, lo_comm_ctrl.pkt.buf, lo_comm_ctrl.pkt.len);

    lo_comm_ctrl.snd.len = lo_comm_ctrl.pkt.len;

    ret = sock_send_data();

    if (ret == 0)
    {
        proc_log( "저공해/요일제 MASTER [%.2s]Transfer\n", cs->lane_no);
    }
    else if (ret < 0) return ret;

	/* Master data Transfer */
    repeat_cnt = frame_cnt;
    for(ii = 0; ii < repeat_cnt; ii++)
    {
        //lb_close(isfd);
        isfd = lb_fopen(&wf, FNO_IMM_CARDNO, FINPUT+FC_MANULOCK);
        if (isfd < 0) return (-1);
        pos = (ii)*49 ;

        row = lb_record_cnt(isfd,FNO_IMM_CARDNO);
        if (row < 0) row = 0;

        lseek(isfd, pos * sizeof(struct imm_card_info),SEEK_SET);

        row2 = 0;

        memset(rfid_f, 0, sizeof(struct hi_imm_crdno_tbl_f));
        memset(&imm_rfid_mst, 0, sizeof(struct imm_card_info));

        for(jj = 0; jj < 49; jj++)
        {
            isrc = lb_readl(isfd, &imm_rfid_mst, FNEXT, sizeof(struct imm_card_info));
            if (isrc <= 0) break;

            sprintf(tmp, "%08x%c", lb_data2atoi(imm_rfid_mst.snd_no, 10), '\0');
            tmp_ldyb[jj] = strtoul(tmp, NULL, 16); 
            row2++;
        }

        sprintf((char *)rfid_f->seq_no, "%.8s", cs->seq_no);
        sprintf((char *)rfid_f->kind, "%02x", NS_TBL_DATA);
        sprintf((char *)rfid_f->tbl_typ, "%02d", TB_IMM_CRDNO);
        sprintf((char *)rfid_f->frame_no, "%08x", ii+1);
        sprintf((char *)rfid_f->last_data_seq_no, "%08x", tmp_ldyb[jj-1]);
        sprintf((char *)rfid_f->item_cnt, "%02x", row2);

        lseek(isfd, -row2*sizeof(struct imm_card_info), SEEK_CUR);

        for(jj = 0; jj < 49; jj++)
        {
            isrc = lb_readl(isfd, &imm_rfid_mst, FNEXT, sizeof(struct imm_card_info));
            if (isrc <= 0) break;

            e_memcpy(rfid_f->imm_info[jj].rgst_div, imm_rfid_mst.rgst_div);
			rfid_f->imm_info[jj].car_div = imm_rfid_mst.div;
            e_memcpy(rfid_f->imm_info[jj].crd_no, imm_rfid_mst.tag_id);
			e_memcpy(rfid_f->imm_info[jj].car_no, imm_rfid_mst.carno_code);
			rfid_f->imm_info[jj].unap_div = imm_rfid_mst.non_cnt;
			rfid_f->imm_info[jj].vio_div = imm_rfid_mst.vio_cnt;
        }

        lb_close(isfd);

        memset(lo_comm_ctrl.pkt.buf, 0, sizeof(struct tbl_data));

        rfid_fr_packet_chng(hi_comm_ctrl.snd.buf, lo_comm_ctrl.pkt.buf);

        lo_comm_ctrl.pkt.len = sizeof(struct tbl_data);
        lo_comm_ctrl.pkt.buf[lo_comm_ctrl.pkt.len++] = ETX;
        lo_comm_ctrl.pkt.flg = LP_SEND;
        
        memcpy(lo_comm_ctrl.snd.buf, lo_comm_ctrl.pkt.buf, lo_comm_ctrl.pkt.len);

        lo_comm_ctrl.snd.len = lo_comm_ctrl.pkt.len;

        ret = sock_send_data();
        if (ret == 0)
        {
            if((ii%1000==0) || (ii+1==repeat_cnt))
                proc_log( "저공해/요일제 Master data [%.2s]Transfer Completion(%d/%d)\n", cs->lane_no, ii+1, repeat_cnt);
        }
        else if(ret < 0) return ret;
    }
    return (0);
}

/*
 *========================================================================
 *
 *   Function : send_adv_carno()
 *   Progrmer : JBY (baarong@neighbor21.co.kr)
 *   Date     : 2019.06.15
 *   Modified :
 *   Remark   : 사전결제 Master data Background Transfer
 *
 *========================================================================
*/

int send_adv_carno(struct bl_struct *cs)
{
    struct write_info   wf;
    struct bef_mst_tbl   bef_mst;
    struct hi_adv_payment_tbl_h *adv_h;
    struct hi_adv_payment_tbl_f *adv_f;
    int  pos, isrc,ii, jj,row=0, row2=0;
    int  tmp_ldyb[142];
    int  frame_cnt = 0;
    int  repeat_cnt;
    int  ret=0;
	char tmp[10+1];
	int isfd;

    adv_h = (struct hi_adv_payment_tbl_h *)hi_comm_ctrl.snd.buf;
    adv_f = (struct hi_adv_payment_tbl_f *)hi_comm_ctrl.snd.buf;

    memset(tmp_ldyb, '0', sizeof(tmp_ldyb));

	/* Master Header Transfer */
    memset(adv_h, 0, sizeof(struct hi_adv_payment_tbl_h));
    sprintf((char *)adv_h->seq_no, "%.8s", cs->seq_no);
    sprintf((char *)adv_h->kind, "%02x", NS_TBL_DATA);
    sprintf((char *)adv_h->tbl_typ, "%02d", TB_ADV_PAY);
    sprintf((char *)adv_h->frame_no, "00000000");
    sprintf((char *)adv_h->frame_cnt, "00000000");

    isfd = lb_fopen(&wf, FNO_BEFMST, FINPUT+FC_MANULOCK);
    
    if (isfd < 0)
    {
        proc_log( "사전결제 Master open error\n");
    }

    row = lb_record_cnt(isfd, FNO_BEFMST); 

    if (row < 0)
    {
        row = 0;
        proc_log( "사전결제 MASTER row not exist\n");
    }

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

    hi_comm_ctrl.frame_no = 0;

    sprintf((char *)adv_h->frame_cnt, "%08x", frame_cnt);
    sprintf((char *)adv_h->rvs_no, "%.2s", cs->rvs_no);
    sprintf((char *)adv_h->div, "00");

    e_memcpy(adv_h->adv_aply_year , cs->rvs_year );
	e_memcpy(adv_h->adv_aply_month, cs->rvs_month);
	e_memcpy(adv_h->adv_aply_day  , cs->rvs_day  );
	e_memcpy(adv_h->adv_aply_hour , cs->rvs_hour );
	e_memcpy(adv_h->adv_aply_min  , cs->rvs_min  );
	
    e_memcpy(adv_h->adv_modf_year , cs->modf_year );
	e_memcpy(adv_h->adv_modf_month, cs->modf_month);
	e_memcpy(adv_h->adv_modf_day  , cs->modf_day  );
	e_memcpy(adv_h->adv_modf_hour , cs->modf_hour );
	e_memcpy(adv_h->adv_modf_min  , cs->modf_min  );

    lb_close(isfd);

    memset(lo_comm_ctrl.pkt.buf, 0, sizeof(lo_comm_ctrl.pkt.buf));

    adv_hd_packet_chng(hi_comm_ctrl.snd.buf, lo_comm_ctrl.pkt.buf);
    
    lo_comm_ctrl.pkt.len = sizeof(struct tbl_data);
    lo_comm_ctrl.pkt.buf[lo_comm_ctrl.pkt.len++] = ETX;
    lo_comm_ctrl.pkt.flg = LP_SEND;
    
    memcpy(lo_comm_ctrl.snd.buf, lo_comm_ctrl.pkt.buf, lo_comm_ctrl.pkt.len);

    lo_comm_ctrl.snd.len = lo_comm_ctrl.pkt.len;

    ret = sock_send_data();

    if (ret == 0)
    {
        proc_log( "사전결제 MASTER [%.2s]Transfer\n", cs->lane_no);
    }
    else if (ret < 0) return ret;

	/* Master data Transfer */
    repeat_cnt = frame_cnt;
    for(ii = 0; ii < repeat_cnt; ii++)
    {
        //lb_close(isfd);
        isfd = lb_fopen(&wf, FNO_BEFMST, FINPUT+FC_MANULOCK);
        if (isfd < 0) return (-1);
        pos = (ii)*142 ;

        row = lb_record_cnt(isfd,FNO_BEFMST);
        if (row < 0) row = 0;

        lseek(isfd, pos * sizeof(struct bef_mst_tbl),SEEK_SET);

        row2 = 0;

        memset(adv_f, 0, sizeof(struct hi_adv_payment_tbl_f));
        memset(&bef_mst, 0, sizeof(struct bef_mst_tbl));

        for(jj = 0; jj < 142; jj++)
        {
            isrc = lb_readl(isfd, &bef_mst, FNEXT, sizeof(struct bef_mst_tbl));
            if (isrc <= 0) break;

            sprintf(tmp, "%08x%c", lb_data2atoi(bef_mst.snd_no, 10), '\0');
            tmp_ldyb[jj] = strtoul(tmp, NULL, 16); 
            row2++;
        }

        sprintf((char *)adv_f->seq_no, "%.8s", cs->seq_no);
        sprintf((char *)adv_f->kind, "%02x", NS_TBL_DATA);
        sprintf((char *)adv_f->tbl_typ, "%02d", TB_ADV_PAY);
        sprintf((char *)adv_f->frame_no, "%08x", ii+1);
        sprintf((char *)adv_f->last_data_seq_no, "%08x", tmp_ldyb[jj-1]);
        sprintf((char *)adv_f->item_cnt, "%02x", row2);

        lseek(isfd, -row2*sizeof(struct bef_mst_tbl), SEEK_CUR);

        for(jj = 0; jj < 142; jj++)
        {
            isrc = lb_readl(isfd, &bef_mst, FNEXT, sizeof(struct bef_mst_tbl));
            if (isrc <= 0) break;

            e_memcpy(adv_f->adv_info[jj].rgst_div, bef_mst.div);
			e_memcpy(adv_f->adv_info[jj].div, bef_mst.kind);
			e_memcpy(adv_f->adv_info[jj].car_no, bef_mst.car_no);
        }

        lb_close(isfd);

        memset(lo_comm_ctrl.pkt.buf, 0, sizeof(struct tbl_data));

        adv_fr_packet_chng(hi_comm_ctrl.snd.buf, lo_comm_ctrl.pkt.buf);

        lo_comm_ctrl.pkt.len = sizeof(struct tbl_data);
        lo_comm_ctrl.pkt.buf[lo_comm_ctrl.pkt.len++] = ETX;
        lo_comm_ctrl.pkt.flg = LP_SEND;
        
        memcpy(lo_comm_ctrl.snd.buf, lo_comm_ctrl.pkt.buf, lo_comm_ctrl.pkt.len);

        lo_comm_ctrl.snd.len = lo_comm_ctrl.pkt.len;

        ret = sock_send_data();
        if (ret == 0)
        {
            if((ii%1000==0) || (ii+1==repeat_cnt))
                proc_log( "사전결제 Master data [%.2s]Transfer Completion(%d/%d)\n", cs->lane_no, ii+1, repeat_cnt);
        }
        else if(ret < 0) return ret;
    }
    return (0);
}

/*
 *========================================================================
 *
 *   Function : send_red_carno()
 *   Progrmer : JBY (baarong@neighbor21.co.kr)
 *   Date     : 2019.06.18
 *   Modified :
 *   Remark   : 차량번호감면 Master data Background Transfer
 *
 *========================================================================
*/

int send_red_carno(struct bl_struct *cs)
{
    struct write_info   wf;
    struct red_carno_info   red_mst;
    struct hi_reduce_tbl_h *red_h;
    struct hi_reduce_tbl_f *red_f;
    int  pos, isrc,ii, jj,row=0, row2=0;
    int  tmp_ldyb[142];
    int  frame_cnt = 0;
    int  repeat_cnt;
    int  ret=0;
	char tmp[10+1];
	int isfd;

    red_h = (struct hi_reduce_tbl_h *)hi_comm_ctrl.snd.buf;
    red_f = (struct hi_reduce_tbl_f *)hi_comm_ctrl.snd.buf;

    memset(tmp_ldyb, '0', sizeof(tmp_ldyb));

	/* Master Header Transfer */
    memset(red_h, 0, sizeof(struct hi_reduce_tbl_h));
    sprintf((char *)red_h->seq_no, "%.8s", cs->seq_no);
    sprintf((char *)red_h->kind, "%02x", NS_TBL_DATA);
    sprintf((char *)red_h->tbl_typ, "%02d", TB_RED_CARNO);
    sprintf((char *)red_h->frame_no, "00000000");
    sprintf((char *)red_h->frame_cnt, "00000000");

    isfd = lb_fopen(&wf, FNO_RED_CARNO, FINPUT+FC_MANULOCK);
    
    if (isfd < 0)
    {
        proc_log( "차량번호감면 Master open error\n");
    }

    row = lb_record_cnt(isfd, FNO_RED_CARNO); 

    if (row < 0)
    {
        row = 0;
        proc_log( "차량번호감면 MASTER row not exist\n");
    }

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

    hi_comm_ctrl.frame_no = 0;

    sprintf((char *)red_h->frame_cnt, "%08x", frame_cnt);
    sprintf((char *)red_h->rvs_no, "%.2s", cs->rvs_no);
    sprintf((char *)red_h->div, "00");

    e_memcpy(red_h->red_aply_year , cs->rvs_year );
	e_memcpy(red_h->red_aply_month, cs->rvs_month);
	e_memcpy(red_h->red_aply_day  , cs->rvs_day  );
	e_memcpy(red_h->red_aply_hour , cs->rvs_hour );
	e_memcpy(red_h->red_aply_min  , cs->rvs_min  );
	
    e_memcpy(red_h->red_modf_year , cs->modf_year );
	e_memcpy(red_h->red_modf_month, cs->modf_month);
	e_memcpy(red_h->red_modf_day  , cs->modf_day  );
	e_memcpy(red_h->red_modf_hour , cs->modf_hour );
	e_memcpy(red_h->red_modf_min  , cs->modf_min  );

    lb_close(isfd);

    memset(lo_comm_ctrl.pkt.buf, 0, sizeof(lo_comm_ctrl.pkt.buf));

    red_hd_packet_chng(hi_comm_ctrl.snd.buf, lo_comm_ctrl.pkt.buf);
    
    lo_comm_ctrl.pkt.len = sizeof(struct tbl_data);
    lo_comm_ctrl.pkt.buf[lo_comm_ctrl.pkt.len++] = ETX;
    lo_comm_ctrl.pkt.flg = LP_SEND;
    
    memcpy(lo_comm_ctrl.snd.buf, lo_comm_ctrl.pkt.buf, lo_comm_ctrl.pkt.len);

    lo_comm_ctrl.snd.len = lo_comm_ctrl.pkt.len;

    ret = sock_send_data();

    if (ret == 0)
    {
        proc_log( "차량번호감면 MASTER [%.2s]Transfer\n", cs->lane_no);
    }
    else if (ret < 0) return ret;

	/* Master data Transfer */
    repeat_cnt = frame_cnt;
    for(ii = 0; ii < repeat_cnt; ii++)
    {
        //lb_close(isfd);
        isfd = lb_fopen(&wf, FNO_RED_CARNO, FINPUT+FC_MANULOCK);
        if (isfd < 0) return (-1);
        pos = (ii)*142 ;

        row = lb_record_cnt(isfd,FNO_RED_CARNO);
        if (row < 0) row = 0;

        lseek(isfd, pos * sizeof(struct red_carno_info),SEEK_SET);

        row2 = 0;

        memset(red_f, 0, sizeof(struct hi_reduce_tbl_f));
        memset(&red_mst, 0, sizeof(struct red_carno_info));

        for(jj = 0; jj < 142; jj++)
        {
            isrc = lb_readl(isfd, &red_mst, FNEXT, sizeof(struct red_carno_info));
            if (isrc <= 0) break;

            sprintf(tmp, "%08x%c", lb_data2atoi(red_mst.snd_no, 10), '\0');
            tmp_ldyb[jj] = strtoul(tmp, NULL, 16); 
            row2++;
        }

        sprintf((char *)red_f->seq_no, "%.8s", cs->seq_no);
        sprintf((char *)red_f->kind, "%02x", NS_TBL_DATA);
        sprintf((char *)red_f->tbl_typ, "%02d", TB_RED_CARNO);
        sprintf((char *)red_f->frame_no, "%08x", ii+1);
        sprintf((char *)red_f->last_data_seq_no, "%08x", tmp_ldyb[jj-1]);
        sprintf((char *)red_f->item_cnt, "%02x", row2);

        lseek(isfd, -row2*sizeof(struct red_carno_info), SEEK_CUR);

        for(jj = 0; jj < 142; jj++)
        {
            isrc = lb_readl(isfd, &red_mst, FNEXT, sizeof(struct red_carno_info));
            if (isrc <= 0) break;

            e_memcpy(red_f->red_data[jj].rgst_div, red_mst.rgst_div);
			e_memcpy(red_f->red_data[jj].div, red_mst.div);
			e_memcpy(red_f->red_data[jj].car_no, red_mst.carno_code);
        }

        lb_close(isfd);

        memset(lo_comm_ctrl.pkt.buf, 0, sizeof(struct tbl_data));

        red_fr_packet_chng(hi_comm_ctrl.snd.buf, lo_comm_ctrl.pkt.buf);

        lo_comm_ctrl.pkt.len = sizeof(struct tbl_data);
        lo_comm_ctrl.pkt.buf[lo_comm_ctrl.pkt.len++] = ETX;
        lo_comm_ctrl.pkt.flg = LP_SEND;
        
        memcpy(lo_comm_ctrl.snd.buf, lo_comm_ctrl.pkt.buf, lo_comm_ctrl.pkt.len);

        lo_comm_ctrl.snd.len = lo_comm_ctrl.pkt.len;

        ret = sock_send_data();
        if (ret == 0)
        {
            if((ii%1000==0) || (ii+1==repeat_cnt))
                proc_log( "차량번호감면 Master data [%.2s]Transfer Completion(%d/%d)\n", cs->lane_no, ii+1, repeat_cnt);
        }
        else if(ret < 0) return ret;
    }
    return (0);
}
