Ejemplo n.º 1
0
Archivo: input.go Proyecto: knz/reg
func parse(input <-chan string, ticksctl chan<- t.Ticks, supplycmd chan<- SupplyCmd, acmd chan<- bool, statusctl chan<- bool) {
	for cmd := range input {
		cmdargs := strings.Split(cmd, " ")

		switch cmdargs[0] {
		case ".":
			Assert(len(cmdargs) == 2, "invalid syntax for . on input: ", cmd)
			v, err := strconv.ParseFloat(cmdargs[1], 64)
			Assert(err == nil, "parsing . on input", ":", err)
			ticksctl <- t.Ticks(v)
		case "+":
			Assert(len(cmdargs) == 2, "invalid syntax for + on input: ", cmd)
			v, err := strconv.ParseFloat(cmdargs[1], 64)
			Assert(err == nil, "parsing + on input", ":", err)
			supplycmd <- SupplyCmd{t.StuffSteps(v)}
		case "aon":
			acmd <- true
		case "aoff":
			acmd <- false
		case "?":
			Assert(len(cmdargs) == 1, "invalid syntax for ? on input: ", cmd)
			statusctl <- true
		}
	}
}
Ejemplo n.º 2
0
Archivo: integrate.go Proyecto: knz/reg
func (d *Domain) integrate(
	status chan<- t.Status,
	action chan<- t.Status,
	supplycmd <-chan SupplyCmd,
	acmd <-chan bool,
	query <-chan bool,
	measure <-chan t.Sample) {

	var supply t.StuffSteps
	var as, qs qstate

	engage := true

	for {
		update := false
		select {
		case m := <-measure:

			delta := t.StuffSteps(float64(m.Steps) * float64(m.Usage))
			supply -= delta
			update = true

			qs.dticks += m.Ticks
			as.dticks += m.Ticks
			qs.dsteps += m.Steps
			as.dsteps += m.Steps

		case s := <-supplycmd:
			supply += s.supply
			update = true

		case a := <-acmd:
			engage = a

		case <-query:
			status <- qs.make_status(supply)
		}

		if update && ((engage && supply < 0) || (supply >= 0 && as.psupply < 0)) {
			action <- as.make_status(supply)
		}

	}
}