Exemplo n.º 1
0
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
}
Exemplo n.º 2
0
//从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
}
Exemplo n.º 3
0
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
}
Exemplo n.º 4
0
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
}
Exemplo n.º 5
0
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
}
Exemplo n.º 6
0
//解析通用的属性
func parsePosCommonAttribute(cur dom.Element, ps PrintPosInterface) {
	var tmp string
	var fval float64
	var err error
	tmp, err = getAttr(cur.Attr(), "Width")
	if err == nil {
		fval, err = strconv.ParseFloat(tmp, 32)
		if err != nil {
			utils.Error("can't format Height attribute %s,expected int value", tmp)
		}
		ps.SetWidth(float32(fval))
	}

	tmp, err = getAttr(cur.Attr(), "Height")
	if err == nil {
		fval, err = strconv.ParseFloat(tmp, 32)
		if err != nil {
			utils.Error("can't format Height attribute %s,expected int value", tmp)
		}
		ps.SetHeight(float32(fval))
	}

	tmp, err = getAttr(cur.Attr(), "Pos")
	ps.SetPos(tmp)

	tmp, err = getAttr(cur.Attr(), "Align")
	ps.SetAlign(tmp)

	tmp, err = getAttr(cur.Attr(), "Left")
	ps.SetLeft(tmp)

	tmp, err = getAttr(cur.Attr(), "Top")
	ps.SetTop(tmp)
}
Exemplo n.º 7
0
//计算规则:
//表示一个Table中的一行,移动X坐标为起始位置,移动Y坐标为下一行
//Tr的设置:X坐标设为Table的起始坐标
//          Y坐标移动一个间距
//这里需要注意:很有可能会出现Td一行排列不下,进而往下移的情况。
//长度为最高的Td的长度。如果有需要,调整td的长度
func (j *PrintTr) CalcExtentValue(pc *PrintCurState) {
	//寻找最高高度
	s := findChildMaxValue(j, 2)
	//寻找累计宽度
	t := findChildCalValue(j, 1)

	utils.Trace("find tr max height [%f]", s)

	par := findparentPosNodeWithName(j, "Table")
	if par == nil {
		utils.Error("can't find Tr's parent node,maybe error")
		return
	}

	table, found2 := par.(*PrintTable)
	if !found2 {
		utils.Error("table element can't convert to PrintTable,maybe error")
		return
	}
	pc.CurX = par.GetRealLeft()
	j.SetRealHeight(s)
	j.SetRealWidth(t)

	//加上表格宽度
	pc.CurY += (s + table.LineSeperate)

}
Exemplo n.º 8
0
//下电
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
}
Exemplo n.º 9
0
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
}
Exemplo n.º 10
0
//开启调试服务
func StartLocalDebugServer() {
	port := "8887"

	tcpAddr, err1 := net.ResolveTCPAddr("tcp4", "0.0.0.0:"+port)
	if err1 != nil {
		utils.Error("start resolving socket error:%s", err1.Error())
		return
	}

	tcpListener, err2 := net.ListenTCP("tcp", tcpAddr) //监听
	if err2 != nil {
		utils.Error("start listening debug socket error:%s", err2.Error())
		return
	} else {
		utils.Info("debug server start listening ip 0.0.0.0 port %s", port)
	}

	defer tcpListener.Close()
	for {
		tcpConn, err3 := tcpListener.AcceptTCP()
		if err3 != nil {
			utils.Error("establish tcp connection error:%s", err3.Error())
			continue
		}
		go handleLocalConn(tcpConn) //起一个goroutine处理
	}

}
Exemplo n.º 11
0
//保存所有设备配置
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
}
Exemplo n.º 12
0
//注册指纹
func (jst *ZZFinger) GetValidateFg(pin *driverlayer.DriverArg, timeout int) ([]byte, error) {
	utils.Debug("receive ZZFinger GetRegisterFg request")

	var term_type int = 0
	var func_id int = 1
	var buf_size int = 1024
	var func_arg int = 1

	t := make([]byte, 1024)
	tty_name := make([]byte, 1)
	tty_name[0] = 0

	var func_arg_pointer []*byte
	func_arg_pointer = make([]*byte, 1)

	_, port, _ := driverlayer.GetPortDescription(pin.Port)

	func_arg_pointer[0] = &([]byte("X"))[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 {
		return t, nil
	} else {
		empocc := utils.IndexByteRune(t, 0, 1)
		if empocc != -1 {
			t = t[0:empocc]
		}
		out, _ := utils.TransUTF8FromCode(t, utils.GBK)
		utils.Error("end ZZFinger GetRegisterFg request error %s", string(out))
		return nil, errors.New(string(out))
	}
}
Exemplo n.º 13
0
//组装arg,如果有不是通用参数的,则放入extractarg中
func populateArg(ps []DevParam) *driverlayer.DriverArg {
	t := driverlayer.DriverArg{}
	t.Baud = 9600
	for _, v := range ps {
		switch v.Name {
		case "Factory":
			t.FactoryName = v.Value
			break

		case "Port":
			t.Port = v.Value
			break

		case "ExtPort":
			t.ExtPort = v.Value
			break

		case "Baud":
			p, err := strconv.Atoi(v.Value)
			if err != nil {
				utils.Error("parse Baud error,set default value 9600 : %+v", v)
				continue
			}
			t.Baud = p
			break

		default:
			ext := driverlayer.DriverExtraParam{Name: v.Name, Value: v.Value}
			t.ExtraParam = append(t.ExtraParam, ext)
		}
	}
	return &t
}
Exemplo n.º 14
0
func (jst *IDCGeneral) Initdriver(pin *driverlayer.DriverArg) {
	var err error
	jst.termdll, err = syscall.LoadLibrary("third_party/general/sdtapi.dll")
	if err != nil {
		panic("load library error:" + err.Error())
	}

	f := func(n string, res *uintptr) bool {
		*res, err = syscall.GetProcAddress(jst.termdll, n)
		if err != nil {
			syscall.FreeLibrary(jst.termdll)
			panic("load proc " + n + " error:" + err.Error())
		}
		return true
	}

	//获得dll的各种handle
	if f("SDT_OpenPort", &jst.initcomm) &&
		f("SDT_ClosePort", &jst.closecomm) &&
		f("SDT_StartFindIDCard", &jst.findcard) &&
		f("SDT_SelectIDCard", &jst.selectcard) &&
		f("SDT_ReadBaseMsg", &jst.readbasemsg) {
	} else {
		utils.Error("Init shensi Driver error...%s", err.Error())
	}

}
Exemplo n.º 15
0
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
}
Exemplo n.º 16
0
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
}
Exemplo n.º 17
0
//解析Table元素
func parseTableElement(table dom.Element, p *PageSetting) *PrintTable {
	var (
		tmp  string
		err  error
		fval float64
	)
	z := NewPrintTable()
	parsePosCommonAttribute(table, z)
	if z.GetWidth() == 0 {
		z.SetWidth(p.Width)
	}
	z.SetName("Table")

	tmp, err = getAttr(table.Attr(), "LineSeperate")
	if err == nil {
		fval, err = strconv.ParseFloat(tmp, 32)
		if err != nil {
			utils.Error("can't format LineSeperate attribute %s,expected float32 value", tmp)
		}
		z.LineSeperate = float32(fval)
	}

	parsePrintContent(table, z, p)
	return z
}
Exemplo n.º 18
0
func (server *JsonDriverServer) StartServer() error {
	s := rpc.NewServer()
	s.RegisterCodec(json2.NewCodec(), "application/json-rpc")
	s.RegisterService(new(PinProtocol), "")
	s.RegisterService(new(FinProtocol), "")
	s.RegisterService(new(PingjiaProtocol), "")
	s.RegisterService(new(MsfProtocol), "")
	s.RegisterService(new(IcProtocol), "")
	s.RegisterService(new(IdcProtocol), "")
	s.RegisterService(new(DebugProtocol), "")
	s.RegisterService(new(ConfigProtocol), "")
	s.RegisterService(new(Pr2Protocol), "")
	http.Handle("/rpc", s)
	p := strconv.Itoa(server.Port)
	var err error
	//具有多个ip

	err = http.ListenAndServe("0.0.0.0:"+p, nil)
	utils.Info("json rpc server start listening ip 0.0.0.0 port %s", p)
	if err != nil {
		utils.Error("start listening ip 0.0.0.0 error:%s", err.Error())
	}

	return nil
}
Exemplo n.º 19
0
//生成PrintLine
func GeneratePrintLine(cur PrintInterface) *PrintLine {
	var s *PrintLine
	var c *PrintLine
	child := cur.GetChild()
	sibling := cur.GetNextSibling()
	//如果有子节点的,则首先计算子节点
	if child != nil {
		c = GeneratePrintLine(child)
	}

	//子节点计算完毕后,计算自身
	switch value := cur.(type) {
	case PrintControlInterface:
		break

	case PrintPosInterface:
		z := cur.(PrintPosInterface)
		s = z.GetPrintLine()
		break
		//需要进行回写处理
	default:
		utils.Error("find not correct kind element %+v", value)
		return nil
	}
	//self child rewrite by jinsl
	s = AdjustPrintLine(s, c)

	if sibling != nil { //计算相邻节点,并且获得值
		s = AdjustPrintLine(s, GeneratePrintLine(sibling))
	}

	return s
}
Exemplo n.º 20
0
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)))
	}
}
Exemplo n.º 21
0
//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
}
Exemplo n.º 22
0
func CrossFrameProxyServer() {
	http.Handle("/", http.StripPrefix("/", http.FileServer(http.Dir("Htmls"))))
	err := http.ListenAndServe(":8880", nil)
	if err != nil {
		utils.Error("fail to start Proxy,error is %s", err.Error())
		return
	}
}
Exemplo n.º 23
0
func (server *Wificonn) StartWifiServer() error {
	conn, err := net.Dial("tcp", server.Addr)
	if err != nil {
		utils.Error("start wifi service:%s", err.Error())
		return err
	}
	driverlayer.SaveWifiConn(conn)
	return nil
}
Exemplo n.º 24
0
//传入端口代码,获得操作流
//一般用于程序自己操作端口
//支持com口,并口,转换口
//com口和并口操作类似
func GetPortInstance(port string, baud int) (io.ReadWriteCloser, error) {
	utils.Trace("received Get Port request,port is %s,baud is %d", port, baud)
	if strings.HasPrefix(port, "COM") {
		c := &serial.Config{Name: port, Baud: baud}
		utils.Trace("achieve com port : %s,baud : %d", port, baud)
		return serial.OpenPort(c)
	} else if strings.HasPrefix(port, "LPT") {
		c := &parallel.Config{Name: port}
		utils.Trace("achieve parallel port : %s,baud : %d", port, baud)
		return parallel.OpenPort(c)
	} else if strings.HasPrefix(port, "USB") {
		utils.Error("yet haven't implementd usb,port is %s ", port)
		return nil, DEVICE_NOT_IMPLEMENTED
	} else {
		utils.Error("non recognized port %s ", port)
		return nil, DEVICE_NOT_IMPLEMENTED
	}

}
Exemplo n.º 25
0
//进行坐标的转换
//如果是绝对坐标:则返回绝对坐标值
//如果是相对坐标:则返回相对于原值后的值
func convertaxistype(raw float32, newexp string, postype string) (float32, error) {
	//utils.Trace("received convertaxistype,raw :[%f],exp [%s],postype [%s]", raw, newexp, postype)
	if strings.EqualFold(postype, "") {
		return raw, nil
	}
	var sign = true
	if (newexp[0] == '+') || (newexp[0] == '-') {
		if strings.EqualFold(postype, "absolute") {
			return 0, UNSUPPORTED_MEASURE_FORMAT
		}
		if newexp[0] == '-' {
			sign = false
		}
		newexp = newexp[1 : len(newexp)-1]
	}

	s, e := strconv.ParseFloat(newexp, 32)
	if e != nil {
		if strings.HasSuffix(newexp, "mm") {
			newexp = newexp[0 : len(newexp)-2]
			s, e = strconv.ParseFloat(newexp, 32)
		} else {
			utils.Error("unsupported measure unit %s", newexp)
			return raw, UNSUPPORTED_MEASURE_FORMAT
		}
	}

	//绝对定位
	switch postype {
	case "absolute":
		return float32(s), nil
	case "relative":
		if sign {
			return (raw + float32(s)), nil
		} else {
			return (raw - float32(s)), nil
		}
	default:
		utils.Error("unsupported pos type %s", postype)
		return raw, UNSUPPORTED_MEASURE_FORMAT
	}

}
Exemplo n.º 26
0
func GetAllDeviceList() ([]byte, error) {
	var (
		err error
	)
	buffer := make([]byte, 0, 700)
	buffer, err = ioutil.ReadFile("devices/Deviceslist.xml")
	if err != nil {
		utils.Error("can't read config file,config file is [devices/Devicelist.xml]")
	}
	return buffer, nil
}
Exemplo n.º 27
0
func ParserPrintXml(s string) (*PrintFacade, error) {
	utils.Debug("begin parse pr2 string")
	db := dom.NewDOMBuilder(strings.NewReader(s), dom.NewDOMStore())
	d, err := db.Build()
	if err != nil {
		utils.Error("parse xml error %s", err.Error())
		return nil, err
	}
	tmp := parsePrintFormat(d.Root())
	return tmp, nil
}
Exemplo n.º 28
0
//向com口中写入任意数据即可
func (jst *SDMsf) Read(pin *driverlayer.DriverArg, read_type int, timeout int) ([]byte, error) {
	utils.Debug("SDMsf received read request")
	if read_type < 1 || read_type > 3 {
		utils.Error("not implementd read type %d,expected 1<=mode<=3", read_type)
		return nil, CARDNO_NOT_FORMULAED
	}
	var s []byte
	switch read_type {
	case 1:
		s, _ = hex.DecodeString("1b301b5d")
		break
	case 2:
		s, _ = hex.DecodeString("1b301b545d")
		break
	case 3:
		s, _ = hex.DecodeString("1b301b425d")
		break
	}
	b, e := driverlayer.WritePortAndReadWithTerminator(pin.Port, pin.Baud, s, []byte{0x3F}, timeout, nil)
	if e != nil {
		return nil, nil
	} else {
		var epos = 0
		if b[0] != 0x1b || b[1] != 0x73 {
			utils.Error("SDMsf data %s,left data not standard,expected %s", b, "1b73")
			return nil, CARDNO_NOT_FORMULAED
		}
		for i := 0; i < len(b); i++ {
			if b[i] == 0x41 && read_type == 3 {
				b[i] = '|'
			}
			if b[i] == 0x3f {
				epos = i
			}
		}
		b = b[2 : epos+1]

		return b, nil
	}

}
Exemplo n.º 29
0
func (p *KvmProtocol) DeSync(r *http.Request, arg *JsonGeneralInputAgr, res *JsonResponse) error {
	utils.Debug("received KvmProtocol DeSync request,arg is : %+v", *arg)
	f, a, err := getKVMImpl()
	if err != nil {
		utils.Error("get kvm impl error: %s", err.Error())
		res.Code = driverlayer.DEVICE_IN_USE
		res.ErrMsg = err.Error()
		utils.Debug("end KvmProtocol DeSync request")
		return nil
	}
	defer MarkDeviceIDLE(KVM)
	err = f.DeSync(a, arg.Timeout)
	if err != nil {
		utils.Error("invoke kvm DeSync error:%s", err.Error())
		res.Code = driverlayer.DEVICE_OPER_ERROR
	} else {
		res.Code = driverlayer.DEVICE_OPER_SUCCESS
		utils.Debug("KvmProtocol DeSync success ")
	}
	utils.Debug("end KvmProtocol DeSync request")
	return nil
}
Exemplo n.º 30
0
//保存单一设备配置
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
}