func (p *IdcProtocol) ReadData(r *http.Request, arg *JsonGeneralInputAgr, res *JsonResponse) error { utils.Debug("received Idccard ReadData request,arg is : %+v", *arg) f, a, err := getIDCImpl() if err != nil { utils.Error("get Idc impl error: %s", err.Error()) res.Code = driverlayer.DEVICE_IN_USE res.ErrMsg = err.Error() utils.Debug("end Idc ReadData request") return nil } defer MarkDeviceIDLE(IDR) s, err := f.ReadData(a, arg.Timeout) if err != nil { utils.Error("invoke Idccard read error:%s", err.Error()) res.Code = driverlayer.DEVICE_OPER_ERROR res.ErrMsg = "" res.ResMsg = string(s) } else { res.Code = driverlayer.DEVICE_OPER_SUCCESS res.ErrMsg = "" res.ResMsg = string(s) utils.Debug("IdcProtocol ReadData success") } utils.Debug("end Idccard ReadData request") return nil }
//从ic卡获取arqc func (p *IcProtocol) GenARQC(r *http.Request, arg *JsonICInputAgr, res *JsonResponse) error { utils.Debug("received iccard GenARQC request,arg is :%+v", *arg) var out []byte f, a, err := getICImpl() if err != nil { utils.Error("get ic impl error: %s", err.Error()) res.Code = driverlayer.DEVICE_IN_USE res.ErrMsg = err.Error() utils.Debug("end ic GenARQC request") return nil } defer MarkDeviceIDLE(IC) out, err = f.GenARQC(a, arg.Timeout, []byte(arg.TagList), []byte(arg.LpicAppData)) if err != nil { utils.Error("invoke iccard GenARQC error:%s", err.Error()) res.Code = driverlayer.DEVICE_OPER_ERROR res.ErrMsg = string(err.Error()) } else { res.Code = driverlayer.DEVICE_OPER_SUCCESS res.ResMsg = string(out) utils.Debug("received GenARQC read") } utils.Debug("end iccard GenARQC request") return nil }
func (jst *STICCard) CtrScriptData(pin *driverlayer.DriverArg, timeout int, taglist []byte, lpicappdata []byte, arpc []byte) ([]byte, error) { utils.Debug("receive STICCard CtrScriptData request") var term_type int = 0 var func_id int = 2 var buf_size int = 4096 var func_arg int = 4 t := make([]byte, 4096) tty_name := make([]byte, 1) tty_name[0] = 0 var func_arg_pointer []*byte func_arg_pointer = make([]*byte, 4) if taglist == nil || len(taglist) == 0 { taglist = tty_name } if lpicappdata == nil || len(lpicappdata) == 0 { lpicappdata = tty_name } if arpc == nil || len(arpc) == 0 { arpc = tty_name } porttype, port, _ := driverlayer.GetPortDescription(pin.Port) switch porttype { case "USB": func_arg_pointer[0] = &([]byte("U"))[0] case "COM": func_arg_pointer[0] = &([]byte("C"))[0] } //taglist func_arg_pointer[2] = &lpicappdata[0] func_arg_pointer[1] = &taglist[0] func_arg_pointer[3] = &arpc[0] r, _, _ := dllinterop.CallProc(jst.read, uintptr(term_type), uintptr(unsafe.Pointer(&tty_name[0])), uintptr(port), uintptr(timeout), uintptr(func_id), uintptr(func_arg), uintptr(unsafe.Pointer(&func_arg_pointer[0])), uintptr(unsafe.Pointer(&t[0])), uintptr(buf_size)) if int(r) == 0 { var empocc int empocc = utils.IndexByteRune(t, 0, 1) if empocc != -1 { t = t[0:empocc] } empocc = utils.IndexByteRune(t, '|', 2) if empocc != -1 { t = t[empocc+1 : len(t)] } utils.Debug("end STICCard GenARQC request ,data [%s]", string(t)) return t, nil } else { utils.Error("end STICCard GenARQC request error %s", int(r)) return nil, errors.New(fmt.Sprintf("%d", int(r))) } }
//add by yangxiaolong func (p *Pr2Protocol) PrintEx(r *http.Request, arg *JsonPr2InputAgr, res *JsonResponse) error { utils.Debug("received pr2 print request,arg is : %+v", *arg) f, s, err := getPr2Impl() if err != nil { utils.Error("get pr2 impl error: %s", err.Error()) res.Code = driverlayer.DEVICE_IN_USE res.ErrMsg = err.Error() utils.Debug("end pr2 print request") return nil } defer MarkDeviceIDLE(PR2PRT) f.BeginPrintJob(s, 20) defer f.EndPrinterJob() //debug by jinsl //f.Init() f.SetTop(10) f.SetLeftMargin(2) f.OutputString(arg.Con) f.EjectPaper() res.ResMsg = "成功" res.ErrMsg = "0" utils.Debug("end pr2 print request") return nil }
//下电 func (p *IcProtocol) PowerOff(r *http.Request, arg *JsonGeneralInputAgr, res *JsonResponse) error { utils.Debug("received iccard PowerOff request,arg is :%+v", *arg) f, a, err := getICImpl() if err != nil { utils.Error("get ic impl error: %s", err.Error()) res.Code = driverlayer.DEVICE_IN_USE res.ErrMsg = err.Error() utils.Debug("end ic PowerOff request") return nil } defer MarkDeviceIDLE(IC) err = f.PowerOff(a, arg.Timeout) if err != nil { utils.Error("invoke iccard PowerOff error:%s", err.Error()) res.Code = driverlayer.DEVICE_OPER_ERROR res.ErrMsg = "" res.ResMsg = string(err.Error()) } else { res.Code = driverlayer.DEVICE_OPER_SUCCESS res.ErrMsg = "" utils.Debug("received PowerOff read") } utils.Debug("end iccard PowerOff request") return nil }
func (p *PinProtocol) Readonce(r *http.Request, arg *JsonGeneralInputAgr, res *JsonResponse) error { utils.Debug("received pin readonce request,arg is : %+v", *arg) f, a, err := getPinImpl() if err != nil { utils.Error("get pin impl error: %s", err.Error()) res.Code = driverlayer.DEVICE_IN_USE res.ErrMsg = err.Error() utils.Debug("end pin readonce request") return nil } defer MarkDeviceIDLE(PIN) s, err := f.Readonce(a, arg.Timeout) if err != nil { utils.Error("invoke pin Readonce error: %s", err.Error()) res.Code = driverlayer.DEVICE_OPER_ERROR res.ErrMsg = err.Error() } else { res.Code = driverlayer.DEVICE_OPER_SUCCESS res.ResMsg = string(s) utils.Debug("pin Readonce request success,reteive data %s", string(s)) } utils.Debug("end pin readonce request") return nil }
//调用winscard.dll实现 func (jst *ICGeneral) ReadCardNo(pin *driverlayer.DriverArg, timeout int) ([]byte, error) { utils.Debug("receive ICGeneral ReadCardNo request") cardno := make([]byte, 100) errmsg := make([]byte, 300) var len = 100 r, _, _ := dllinterop.CallProc(jst.readcard, uintptr(timeout), uintptr(unsafe.Pointer(&cardno[0])), uintptr(unsafe.Pointer(&len)), uintptr(unsafe.Pointer(&errmsg[0]))) if int(r) == 0 { utils.Debug("reteive card no %s", string(cardno[0:len])) cardno = cardno[0:len] for i, v := range cardno { if v == 0x3D { cardno = cardno[0:i] break } } utils.Debug("end ICGeneral ReadCardNo request") return cardno, nil } else { utils.Debug("end ICGeneral ReadCardNo request") return nil, errors.New(string(errmsg)) } }
func (p *MsfProtocol) Read(r *http.Request, arg *JsonGeneralReadInputAgr, res *JsonResponse) error { utils.Debug("received MsfProtocol read request,arg is : %+v", *arg) f, a, err := getMSFImpl() if err != nil { utils.Error("get msf impl error: %s", err.Error()) res.Code = driverlayer.DEVICE_IN_USE res.ErrMsg = err.Error() utils.Debug("end MsfProtocol Read request") return nil } defer MarkDeviceIDLE(MSF) s, err := f.Read(a, arg.Readtype, arg.Timeout) if err != nil { utils.Error("invoke msf read error:%s", err.Error()) res.Code = driverlayer.DEVICE_OPER_ERROR res.ResMsg = string(s) } else { res.Code = driverlayer.DEVICE_OPER_SUCCESS res.ResMsg = string(s) utils.Debug("MsfProtocol read success %s", string(s)) } utils.Debug("end MsfProtocol read request") return nil }
func (p *FinProtocol) MatchFinger(r *http.Request, arg *JsonFingerMatchInputAgr, res *JsonResponse) error { utils.Debug("received FinProtocol MatchFinger request,arg is : %+v", *arg) f, a, err := getFingerImpl() if err != nil { utils.Error("get fin impl error: %s", err.Error()) res.Code = driverlayer.DEVICE_IN_USE res.ErrMsg = err.Error() utils.Debug("end fin GetValidateFg request") return nil } defer MarkDeviceIDLE(FP) s := f.MatchFinger(a, arg.Timeout, []byte(arg.Reg), []byte(arg.Vad)) if s >= 0 { utils.Debug("match finger success") } else { utils.Debug("match finger error") } res.Code = driverlayer.DEVICE_OPER_SUCCESS res.ErrMsg = "" if s >= 0 { res.ResMsg = "true" } else { res.ResMsg = "false" } utils.Debug("end FinProtocol MatchFinger request") return nil }
func RunPr2Engine(s string, pr2 driverlayer.IPr2Print, pin *driverlayer.DriverArg) error { var pc PrintCurState pf, e := ParserPrintXml(s) if e != nil { utils.Error("parse xml file error %s", e.Error()) } else { utils.Info("parse xml file success") } ps := pf.S pi := pf.V pc.BottomMargin = ps.ps.Bottommargin pc.LeftMargin = ps.ps.Leftmargin pc.PageHeight = ps.ps.Height pc.PageWidth = ps.ps.Width pc.TopMargin = ps.ps.Topmargin pc.RightMargin = ps.ps.Rightmargin pc.CurX = 0 pc.CurY = 0 pc.CurPage = 1 pc.Flags = 0 pc.LineInterval = ps.ps.LineInterval pc.ColInterval = ps.ps.ColInterval RecurCalcExtent(pi, &pc) utils.Info("RecurCalcExtent success") fl := GeneratePrintLine(pi) utils.Debug("begin print printline----------------------------") PrintPrintLine(fl) utils.Debug("end print printline----------------------------") pr2.BeginPrintJob(pin, 20) defer pr2.EndPrinterJob() RunRealPrinter(ps, fl, pr2) return nil }
func (p *PingjiaProtocol) StartEstimate(r *http.Request, arg *JsonGeneralInputAgr, res *JsonResponse) error { utils.Debug("received PingjiaProtocol StartEstimate request,arg is : %+v", *arg) f, a, err := getPingjiaImpl() if err != nil { utils.Error("get Pingjia impl error: %s", err.Error()) res.Code = driverlayer.DEVICE_IN_USE res.ErrMsg = err.Error() utils.Debug("end fin StartEstimate request") return nil } defer MarkDeviceIDLE(PINGJIA) s, err := f.StartEsitimate(a, arg.Timeout) if err != nil { utils.Error("invoke StartEstimate read error: %s", err.Error()) res.Code = driverlayer.DEVICE_OPER_ERROR res.ErrMsg = err.Error() } else { res.Code = driverlayer.DEVICE_OPER_SUCCESS res.ResMsg = string(s) utils.Debug("Pingjia StartEstimate request success,reteive data %s", string(s)) } utils.Debug("end PingjiaProtocol StartEstimate request") return nil }
func (p *FinProtocol) GetValidateFg(r *http.Request, arg *JsonGeneralInputAgr, res *JsonResponse) error { utils.Debug("received FinProtocol GetValidateFg request,arg is : %+v", *arg) f, a, err := getFingerImpl() if err != nil { utils.Error("get fin impl error: %s", err.Error()) res.Code = driverlayer.DEVICE_IN_USE res.ErrMsg = err.Error() utils.Debug("end fin GetValidateFg request") return nil } defer MarkDeviceIDLE(FP) s, err := f.GetValidateFg(a, arg.Timeout) if err != nil { utils.Error("invoke GetValidateFg read error: %s", err.Error()) res.Code = driverlayer.DEVICE_OPER_ERROR res.ErrMsg = err.Error() } else { res.Code = driverlayer.DEVICE_OPER_SUCCESS res.ResMsg = string(s) utils.Debug("fin GetValidateFg request success,reteive data %s", string(s)) } utils.Debug("end FinProtocol GetValidateFg request") return nil }
//获取所有运行设备 func (p *DebugProtocol) GetUsableDevice(r *http.Request, arg *JsonGeneralInputAgr, res *JsonResponse) error { utils.Debug("%s", "received DebugProtocol GetUsableDevice request") var buf bytes.Buffer rad.Execute(&buf, getAllDevice()) utils.Debug("get all runnable device: %s", buf.String()) res.ResMsg = buf.String() utils.Debug("%s", "end DebugProtocol GetUsableDevice request") return nil }
func (jst *OkiPrinter) ChanageToIBM() error { utils.Debug("OlevittePrinter received ChanageToIBM request") s, _ := hex.DecodeString("1B5E30") utils.Debug("OlevittePrinter send ChanageToIBM pi %x", s) if jst.checkJobInPrint() { return driverlayer.WriteData(jst.w, s) } else { return PR2NOTINJOB } }
//打印机初始化 func (jst *OkiPrinter) Init() error { utils.Debug("OlevittePrinter received initPrinter request") s, _ := hex.DecodeString("1042") utils.Debug("OlevittePrinter send initPrinter pi %x", s) if jst.checkJobInPrint() { return driverlayer.WriteData(jst.w, s) } else { return PR2NOTINJOB } }
//进纸一行 func (jst *OkiPrinter) AdvanceOneLine() error { utils.Debug("OkiPrinter received Initfirstline request") s, _ := hex.DecodeString("0d0a20") utils.Debug("OkiPrinter send Initfirstline pi %x", s) if jst.checkJobInPrint() { return driverlayer.WriteData(jst.w, s) } else { return PR2NOTINJOB } }
//清除上/下标打印 func (jst *OkiPrinter) CancelSuperSubscript() error { utils.Debug("OlevittePrinter received CancelSuperSubscript request") s, _ := hex.DecodeString("1B7B") utils.Debug("OlevittePrinter send CancelSuperSubscript pi %x", s) if jst.checkJobInPrint() { return driverlayer.WriteData(jst.w, s) } else { return PR2NOTINJOB } }
//三倍高 func (jst *OkiPrinter) SetThreeHigh() error { utils.Debug("OlevittePrinter received SetThreeHigh request") s, _ := hex.DecodeString("1b7732") utils.Debug("OlevittePrinter send SetThreeHigh pi %x", s) if jst.checkJobInPrint() { return driverlayer.WriteData(jst.w, s) } else { return PR2NOTINJOB } }
func (jst *STPingjia) CancelEsitimate(pin *driverlayer.DriverArg, timeout int) error { utils.Debug("STPingjia received CancelEsitimate request") t, _ := hex.DecodeString("1b5b3443") utils.Debug("STPingjia send CancelEsitimate pi %x", t) e := driverlayer.WritePortData(pin.Port, pin.Baud, t) utils.Debug("STPingjia CancelEsitimate") return e }
func (jst *OlevittePrinter) OutputString(s string) error { utils.Debug("OlevittePrinter received OutputString request") ds, _ := utils.TransGBKFromUTF8(s) utils.Debug("OlevittePrinter send OutputString pi %x", ds) if jst.checkJobInPrint() { return driverlayer.WriteData(jst.w, ds) } else { return PR2NOTINJOB } }
func (jst *OlevittePrinter) CancelBold() error { utils.Debug("OlevittePrinter received CancelBold request") s, _ := hex.DecodeString("1b29") utils.Debug("OlevittePrinter send CancelBold pi %x", s) if jst.checkJobInPrint() { return driverlayer.WriteData(jst.w, s) } else { return PR2NOTINJOB } }
//换行 func (jst *OlevittePrinter) ChangeLine() error { utils.Debug("OlevittePrinter received ChangeLine request") s, _ := hex.DecodeString("0A20") utils.Debug("OlevittePrinter send ChangeLine pi %x", s) if jst.checkJobInPrint() { return driverlayer.WriteData(jst.w, s) } else { return PR2NOTINJOB } }
//倍宽 func (jst *OlevittePrinter) DoublePrintWidth() error { utils.Debug("OlevittePrinter received DoublePrintWidth request") s, _ := hex.DecodeString("1b33") utils.Debug("OlevittePrinter send DoublePrintWidth pi %x", s) if jst.checkJobInPrint() { return driverlayer.WriteData(jst.w, s) } else { return PR2NOTINJOB } }
//背景打印。最后一位:0取消;1逆打印;2密网打印;3梳网打印 func (jst *OkiPrinter) BackgroundPrint() error { utils.Debug("OlevittePrinter received BackgroundPrint request") s, _ := hex.DecodeString("1C2831") utils.Debug("OlevittePrinter send BackgroundPrint pi %x", s) if jst.checkJobInPrint() { return driverlayer.WriteData(jst.w, s) } else { return PR2NOTINJOB } }
func (jst *KVMGeneral) InnSyncOuter(pin *driverlayer.DriverArg, timeout int) error { utils.Debug("KVMGeneral received InnSyncOuter request") s, _ := hex.DecodeString("fa5a1101000066") b, e := driverlayer.WritePortAndReadWithLen(pin.Port, pin.Baud, s, 0, timeout, nil) if e != nil { return e } else { utils.Debug("KVMGeneral InnSyncOuter data %s,begin to process", b) return nil } }
//保存所有设备配置 func (p *ConfigProtocol) SaveAllDevConfig(r *http.Request, arg *JsonConfigInputAgr, res *JsonResponse) error { utils.Debug("received ConfigProtocol SaveAllDevConfig request") var ( n dom.Node t dom.Element dt dom.Attribute ) db := dom.NewDOMBuilder(strings.NewReader(arg.Content), dom.NewDOMStore()) d, err2 := db.Build() if err2 != nil { res.Code = 1 res.ErrMsg = fmt.Sprintf("parse xml file error,category :[%+v] ", err2.Error()) utils.Error("parse xml file error,category:[%+v]", err2.Error()) return nil } f := d.ChildNodes() for i := 0; i < len(f); i++ { n = f[i] switch n.Kind() { case dom.ElementKind: t = n.(dom.Element) switch t.Name() { case "Device": // 解析设置 var v []dom.Attribute v = t.Attr() for j := 0; j < len(v); j++ { dt = v[j] if strings.EqualFold(dt.Name(), "Category") { err := SaveDrvConfig(dt.Value(), t.String()) if err != nil { res.Code = 1 res.ErrMsg = fmt.Sprintf("save file error,category :%s content is : [%s]", dt.Value(), t.String()) utils.Error("can't save category [%s] ,content is : [%s]", dt.Value(), t.String()) return nil } } } break default: utils.Error("can't recognize element name: %s", t.Name()) } break } } res.Code = 0 utils.Debug("end ConfigProtocol SaveAllDevConfig request") return nil }
func (jst *IDCGeneral) ReadData(pin *driverlayer.DriverArg, timeout int) ([]byte, error) { utils.Debug("receive general ReadData request") out, err := jst.genIDC(pin.Port, timeout, 2) if err != nil { utils.Debug("end general ReadData request") return nil, err } else { utils.Debug("reteive id card info %s", string(out)) utils.Debug("end general ReadData request") return out, nil } }
func (jst *PinGeneral) Readonce(pin *driverlayer.DriverArg, timeout int) ([]byte, error) { utils.Debug("PinGeneral received Readonce request") s, _ := hex.DecodeString("1b49") t, _ := hex.DecodeString("83") utils.Debug("PinGeneral send readonce pi %x", s) b, e := driverlayer.WritePortAndReadWithTerminator(pin.Port, pin.Baud, s, []byte{0x03}, timeout, t) if e == nil { utils.Debug("begin process received data %x", b) b = b[1 : len(b)-1] utils.Debug("after process received data %x", b) } return b, e }
//保存单一设备配置 func (p *ConfigProtocol) SaveDevConfig(r *http.Request, arg *JsonConfigInputAgr, res *JsonResponse) error { utils.Debug("received ConfigProtocol SaveDevConfig request") err := SaveDrvConfig(arg.Dev, arg.Content) if err != nil { res.Code = 1 res.ErrMsg = err.Error() utils.Error("save %s config file content error,detail is %s", arg.Dev, err.Error()) } else { res.Code = 0 utils.Debug("save config file content success") } utils.Debug("end ConfigProtocol SaveDevConfig request") return nil }
//保存设备配置 func (p *ConfigProtocol) SaveUpdateUrl(r *http.Request, arg *JsonUpdateInputAgr, res *JsonResponse) error { utils.Debug("received ConfigProtocol SaveUpdateUrl request") err := ioutil.WriteFile("config/updateurl.xml", []byte(arg.Content), 0644) if err != nil { res.Code = 1 res.ErrMsg = err.Error() utils.Error("save updateurl file content error,detail is %s", err.Error()) } else { res.Code = 0 utils.Debug("save updateurl file content success") } utils.Debug("end ConfigProtocol SaveUpdateUrl request") return nil }