Ejemplo n.º 1
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
}
Ejemplo n.º 2
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处理
	}

}
Ejemplo n.º 3
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
}
Ejemplo n.º 4
0
//远程调试信息
func handleRemoteConn(tcpConn *net.TCPConn) {
	if tcpConn == nil {
		return
	}
	addConnection(tcpConn)
	utils.Info("received remote debug client:%s", tcpConn.LocalAddr().String())
	tcpConn.Write([]byte("welcome to debug service...."))
	for {
		_, err := tcpConn.Read(buff)
		if err == io.EOF {
			utils.Info("remote disconnect:%s", tcpConn.RemoteAddr().String())
			removeConnection(tcpConn)
			tcpConn.Close()
			return
		}
	}
}
Ejemplo n.º 5
0
//往接口中写入数据,读取数据。返回条件
//1 读到ter结束符后返回.如果ter后有多余字符,将被截断
//2 流结束
//3 读取错误
//4 超时
//5 超时后执行的指令
func WritePortAndReadWithTerminator(port string, baud int, writedata []byte, ter []byte, timeout int, ains []byte) ([]byte, error) {
	utils.Trace("received WritePortAndReadWithTerminator,port is %s", port)
	w, err := hardware.GetPortInstance(port, baud)
	if err != nil {
		return nil, err
	}
	defer w.Close()
	b, s := WriteAndReadWithTer(w, writedata, ter, timeout)
	if s == ErrIOTimeOut && ains != nil && len(ains) > 0 {
		utils.Info("detected device oper exceed maxinum time,write instructon : %x", ains)
		WriteData(w, ains)
	}
	return b, s
}
Ejemplo n.º 6
0
//本地调试信息
func handleLocalConn(tcpConn *net.TCPConn) {
	if tcpConn == nil {
		return
	}
	var v *net.TCPConn
	var ll int
	var err error
	utils.Info("received local debug client:%s", tcpConn.LocalAddr().String())
	for {
		ll, err = tcpConn.Read(rcvbuffer)
		if err == io.EOF {
			tcpConn.Close()
			return
		} else {
			con.rw.RLock()
			for _, v = range con.conlist {
				v.Write(rcvbuffer[0:ll])
			}
			con.rw.RUnlock()
		}
	}
	tcpConn.Close()
}
Ejemplo n.º 7
0
func StartDriverService(drivers []UseDriverCategory) error {
	var err error
	var v UseDriverCategory
	var k int
	var drvbase driverlayer.DriverBase
	var facname string

	Rollback := func(driver driverlayer.DriverBase, arg *driverlayer.DriverArg) {
		if err != nil {
			driver.Deinit(arg)
		}
	}

	for _, v = range drivers {
		drvbase = nil
		k, err = getDeviceIndex(v.Category)
		if err != nil {
			utils.Error("can't find Category impl:%s", v.Category)
			continue
		}
		facname = findFactoryParam(v.Kind)
		if facname == "" {
			utils.Error("can't find Category:%v's factory", v.Category)
			continue
		}

		switch k {
		case PIN:
			switch facname {
			case "南天":

				break

			case "通用类型":
				drvbase = &pin.PinGeneral{}
				break

			default:

			}

		case FP:
			switch facname {
			case "通用类型":
				drvbase = &finger.ZZFinger{}
				break

				//			case "天诚":
				//				drvbase = &finger.TCFinger{}
				//				break

			case "中正":
				drvbase = &finger.ZZFinger{}
				break

			default:

			}

		case PINGJIA:
			switch facname {
			case "南天":

				break

			case "升腾":
				drvbase = &pingjia.STPingjia{}
				break

			case "通用类型":
				drvbase = &pingjia.HTPingjia{}

			default:
			}

		case MSF:
			switch facname {
			case "实达":
				drvbase = &bankcard.SDMsf{}
				break

			default:

			}

		case IC:
			switch facname {
			case "通用类型":
				drvbase = &iccard.ICGeneral{}
				break
				//			case "升腾":
				//				drvbase = &iccard.STICCard{}
				//				break
			default:

			}

		case IDR:
			switch facname {
			case "通用类型":
				drvbase = &idccard.IDCGeneral{}
				break

				//			case "升腾":
				//				drvbase = &idccard.STIdr{}
				//				break
			default:

			}

		case PR2PRT:
			switch facname {
			case "PR2":
				drvbase = &pr2.OlevittePrinter{}
				break
			case "OKI":
				drvbase = &pr2.OkiPrinter{}
			default:

			}

		case KVM:
			switch facname {
			case "通用类型":
				drvbase = &kvm.KVMGeneral{}
				break
			}

		}
		//进行初始化
		if drvbase != nil {
			cat, _ := getDeviceCategory(k)
			utils.Info("%s  use %s driver", cat, drvbase.GetFactoryName())
			t := populateArg(v.Kind)
			setDeviceImp(k, drvbase, t)
			drvbase.Initdriver(t)
			defer Rollback(drvbase, t)
		} else {
			utils.Error(`Category %s could not find factory %s`, v.Category, facname)
		}
	}
	return err
}
Ejemplo n.º 8
0
//解析需要打印的内容
//需要解析子结构,深度遍历->广度遍历
//cur:解析树中的当前节点
//par:父节点
func parsePrintContent(cur dom.Element, par PrintInterface, p *PageSetting) PrintInterface {
	var i int
	var (
		n    dom.Node
		t    dom.Element
		z    PrintInterface
		prev PrintInterface
		te   dom.Text
	)
	f := cur.ChildNodes()

	for i = 0; i < len(f); i++ {
		n = f[i]
		z = nil
		switch n.Kind() {
		case dom.ElementKind:
			t = n.(dom.Element)
			utils.Info("find element %s", t.Name())

			switch t.Name() {
			case "Br":
				z = parseBrElement(t, p)
			case "Table":
				z = parseTableElement(t, p)
			case "Rect":
				z = parseRectElement(t, p)
			case "Tr":
				z = parseTrElement(t, p)
			case "Td":
				z = parseTdElement(t, p)
			case "Bold":
				z = parseBoldElement(t, p)
			case "Sup":
				z = parseSupElement(t, p)
			case "Sub":
				z = parseSubElement(t, p)
			case "Underline":
				z = parseUnderElement(t, p)
			case "Doubleheight":
				z = parseDoubleHeightElement(t, p)
			case "Doublewidth":
				z = parseDoubleWidthElement(t, p)

			default:
				utils.Error("can't find element name: %s", t.Name())
				continue
			}

		case dom.TextKind:
			te = n.(dom.Text)
			t := strings.TrimSpace(te.Data())
			//可能是换行符
			//if t == "" || strings.HasPrefix(t, "\r") || strings.HasPrefix(t, "\n") {
			//utils.Info("detect text line character,text is %s", te.Data())
			//continue
			// changed by jinsl 20151222
			if t == "" {
				utils.Info("detect text line character,text is null")
				continue
			} else if strings.HasPrefix(t, "\r") {
				utils.Info("detect text line character,text is \\r")
				continue
			} else if strings.HasPrefix(t, "\n") {
				utils.Info("detect text line character,text is \\n")
				continue
			} else {
				utils.Info("find text node,content %s", te.Data())
				z = parseTextNode(te, p)
			}

		default:
			utils.Debug("find default node %s ,kind %d", n.String(), n.Kind())
		}
		if z == nil {
			continue
		}
		if par != nil {
			par.AddChild(z)
			z.SetParent(par)
		}
		//加入到列表
		if prev == nil {
			prev = z
		}
	}
	return prev
}
Ejemplo n.º 9
0
func main() {
	flag.Parse()

	//开启调试服务
	utils.Info("%s", "begin start local debug service....")
	go protocol.StartLocalDebugServer()
	utils.Info("%s", "end start local debug service success....")

	//初始化日志系统,因为要连接调试端口,所以放在debug服务后面
	switch *logl {
	case "development":
		utils.InitializeLogging(1)
		break
	case "production":
		utils.InitializeLogging(2)
		break
	default:
		utils.InitializeLogging(2)
		break
	}

	utils.Info("%s", "begin start remote debug service....")
	go protocol.StartRemoteDebugServer()
	utils.Info("%s", "end start remote debug service success....")

	defer utils.Flush()

	utils.Info("%s", "begin to parse all drivers...")
	//读入配置文件
	err := protocol.ParserDrivers()
	if err != nil {
		utils.Critical("parse xml file,error is : %s", err.Error())
		return
	}

	utils.Debug("find all devices category:%+v", protocol.AllDevice)
	utils.Info("%s", "end parse all drivers suceess....")

	utils.Info("%s", "begin parse use drivers....")

	err = protocol.ParseUseDriver()
	if err != nil {
		utils.Critical("parser use file error,error is:%s", err.Error())
		return
	}
	utils.Debug("find all user driver: %+v", protocol.CurDrivers)
	utils.Info("%s", "end parse use drivers success....")

	//add by yangxiaolong
	utils.Info("%s", "begin parse connect method...")
	/*err = protocol.ParserConnMethod()
	  if err != nil {
	     utils.Critical("parser connect method file error,error is:%s", err.Error())
	     return
	  }
	  utils.Debug("find method: %s, find ip address: %s", protocol.Connect.Method, protocol.Connect.Address)
	  utils.Info("%s", "end parse connect method success...")*/

	if protocol.Connect.Method == "WIFI" {
		wserver := protocol.Wificonn{}
		wserver.Addr = protocol.Connect.Address
		err = wserver.StartWifiServer()
		if err != nil {

		}
	}

	//开启跨域代理服务
	utils.Info("begin start proxy service...")
	go crossframe.CrossFrameProxyServer()

	//启动硬件服务
	utils.Info("%s", "begin start driver service....")
	err = protocol.StartDriverService(protocol.CurDrivers.Device)
	if err != nil {
		utils.Critical("failed to start device ,error is %s", err.Error())
		return
	}

	utils.Info("%s", "end start driver service success....")

	//开启json服务
	jserver := protocol.JsonDriverServer{}
	jserver.Port = 8888
	utils.Info("begin start json service....")
	err = jserver.StartServer()
	if err != nil {
		utils.Error("detect error,error is %s", err.Error())
		return
	}

	utils.Info("%s", "end start json service success....")

	//写入所有的log日志
	utils.Flush()
}