Пример #1
0
func (vs *VariableSet) GetCovers() (*[]cdd.Cover, *cdd.CoverState, bool) {
	descriptions := vs.GetSubtree(PrinterCoverDescription).Variables()
	statuses := vs.GetSubtree(PrinterCoverStatus).Variables()

	if len(descriptions) < 1 ||
		len(descriptions) != len(statuses) {
		return nil, nil, false
	}

	covers := make([]cdd.Cover, 0, len(descriptions))
	coverState := cdd.CoverState{make([]cdd.CoverStateItem, 0, len(statuses))}

	for i := 0; i < len(descriptions); i++ {
		index := cdd.NewSchizophrenicInt64(descriptions[i].Name[len(descriptions[i].Name)-1])
		description := descriptions[i].Value
		state := PrinterCoverStatusToGCP[statuses[i].Value]
		cover := cdd.Cover{
			VendorID: index.String(),
			Index:    index,
		}

		switch strings.ToLower(description) {
		case "cover":
			cover.Type = cdd.CoverTypeCover
		case "door":
			cover.Type = cdd.CoverTypeDoor
		default:
			cover.Type = cdd.CoverTypeCustom
			cover.CustomDisplayNameLocalized = cdd.NewLocalizedString(description)
		}
		covers = append(covers, cover)

		coverStateItem := cdd.CoverStateItem{
			VendorID: index.String(),
			State:    state,
		}
		if state == cdd.CoverStateFailure {
			coverStateItem.VendorMessage = PrinterCoverStatusTC[statuses[i].Value]
		}
		coverState.Item = append(coverState.Item, coverStateItem)
	}

	return &covers, &coverState, true
}
Пример #2
0
func (vs *VariableSet) GetOutputBins() (*[]cdd.OutputBinUnit, *cdd.OutputBinState, bool) {
	capacitiesMax := vs.GetSubtree(PrinterOutputMaxCapacity).Variables()
	capacitiesRemaining := vs.GetSubtree(PrinterOutputRemainingCapacity).Variables()
	statuses := vs.GetSubtree(PrinterOutputStatus).Variables()
	names := vs.GetSubtree(PrinterOutputName).Variables()

	if len(names) < 1 ||
		len(names) != len(capacitiesMax) ||
		len(names) != len(capacitiesRemaining) ||
		len(names) != len(statuses) {
		return nil, nil, false
	}

	outputBinUnits := make([]cdd.OutputBinUnit, 0, len(names))
	outputBinState := cdd.OutputBinState{make([]cdd.OutputBinStateItem, 0, len(names))}

	for i := 0; i < len(names); i++ {
		index := cdd.NewSchizophrenicInt64(statuses[i].Name[len(statuses[i].Name)-1])

		status, err := strconv.ParseUint(statuses[i].Value, 10, 8)
		if err != nil {
			return nil, nil, false
		}
		state := cdd.OutputBinStateOK
		stateMessage := []string{}
		if (status & PrinterSubUnitUnavailable) != 0 {
			stateMessage = append(stateMessage, "unavailable")
			switch status & 7 {
			case PrinterSubUnitUnavailableAndOnRequest:
				stateMessage = append(stateMessage, "on request")
			case PrinterSubUnitUnavailableBecauseBroken:
				state = cdd.OutputBinStateFailure
				stateMessage = append(stateMessage, "broken")
			case PrinterSubUnitUnknown:
				state = cdd.OutputBinStateFailure
				stateMessage = append(stateMessage, "reason unknown")
			}
		}
		if (status & PrinterSubUnitNonCritical) != 0 {
			stateMessage = append(stateMessage, "non-critical")
		}
		if (status & PrinterSubUnitCritical) != 0 {
			state = cdd.OutputBinStateFailure
			stateMessage = append(stateMessage, "critical")
		}
		if (status & PrinterSubUnitOffline) != 0 {
			state = cdd.OutputBinStateOff
			stateMessage = append(stateMessage, "offline")
		}
		outputState := cdd.OutputBinStateItem{
			VendorID:      index.String(),
			State:         state,
			VendorMessage: strings.Join(stateMessage, ","),
		}

		capacityMax, err := strconv.ParseInt(capacitiesMax[i].Value, 10, 32)
		if err != nil {
			return nil, nil, false
		}
		capacityRemaining, err := strconv.ParseInt(capacitiesRemaining[i].Value, 10, 32)
		if err != nil {
			return nil, nil, false
		}
		if capacityMax >= 0 && capacityRemaining >= 0 {
			if capacityRemaining == 0 && state == cdd.OutputBinStateOK {
				outputState.State = cdd.OutputBinStateFull
			}
			levelPercent := 100 - int32(100*capacityRemaining/capacityMax)
			outputState.LevelPercent = &levelPercent
		}
		outputBinState.Item = append(outputBinState.Item, outputState)

		outputBinUnits = append(outputBinUnits, cdd.OutputBinUnit{
			VendorID: index.String(),
			Type:     cdd.OutputBinUnitCustom,
			Index:    index,
			CustomDisplayNameLocalized: cdd.NewLocalizedString(names[i].Value),
		})
	}

	return &outputBinUnits, &outputBinState, true
}
Пример #3
0
func (vs *VariableSet) GetInputTrays() (*[]cdd.InputTrayUnit, *cdd.InputTrayState, bool) {
	levelsMax := vs.GetSubtree(PrinterInputMaxCapacity).Variables()
	levelsCurrent := vs.GetSubtree(PrinterInputCurrentLevel).Variables()
	statuses := vs.GetSubtree(PrinterInputStatus).Variables()
	names := vs.GetSubtree(PrinterInputName).Variables()

	if len(levelsMax) < 1 ||
		len(levelsMax) != len(levelsCurrent) ||
		len(levelsMax) != len(statuses) ||
		len(levelsMax) != len(names) {
		return nil, nil, false
	}

	inputTrayUnits := make([]cdd.InputTrayUnit, 0, len(statuses))
	inputTrayState := cdd.InputTrayState{make([]cdd.InputTrayStateItem, 0, len(statuses))}

	for i := 0; i < len(statuses); i++ {
		index := cdd.NewSchizophrenicInt64(statuses[i].Name[len(statuses[i].Name)-1])

		status, err := strconv.ParseUint(statuses[i].Value, 10, 8)
		if err != nil {
			return nil, nil, false
		}
		state := cdd.InputTrayStateOK
		stateMessage := []string{}
		if (status & PrinterSubUnitUnavailable) != 0 {
			stateMessage = append(stateMessage, "unavailable")
			switch status & 7 {
			case PrinterSubUnitUnavailableAndOnRequest:
				stateMessage = append(stateMessage, "on request")
			case PrinterSubUnitUnavailableBecauseBroken:
				state = cdd.InputTrayStateFailure
				stateMessage = append(stateMessage, "broken")
			case PrinterSubUnitUnknown:
				state = cdd.InputTrayStateFailure
				stateMessage = append(stateMessage, "reason unknown")
			}
		}
		if (status & PrinterSubUnitNonCritical) != 0 {
			stateMessage = append(stateMessage, "non-critical")
		}
		if (status & PrinterSubUnitCritical) != 0 {
			state = cdd.InputTrayStateFailure
			stateMessage = append(stateMessage, "critical")
		}
		if (status & PrinterSubUnitOffline) != 0 {
			state = cdd.InputTrayStateOff
			stateMessage = append(stateMessage, "offline")
		}
		inputState := cdd.InputTrayStateItem{
			VendorID:      index.String(),
			State:         state,
			VendorMessage: strings.Join(stateMessage, ", "),
		}

		levelMax, err := strconv.ParseInt(levelsMax[i].Value, 10, 32)
		if err != nil {
			return nil, nil, false
		}
		levelCurrent, err := strconv.ParseInt(levelsCurrent[i].Value, 10, 32)
		if err != nil {
			return nil, nil, false
		}
		if levelMax >= 0 && levelCurrent >= 0 {
			if levelCurrent == 0 && state == cdd.InputTrayStateOK {
				inputState.State = cdd.InputTrayStateEmpty
			}
			var levelPercent int32
			if levelMax > 0 {
				levelPercent = int32(100 * levelCurrent / levelMax)
			}
			inputState.LevelPercent = &levelPercent
		}

		if inputState.State == cdd.InputTrayStateOK ||
			inputState.State == cdd.InputTrayStateEmpty {
			// No message necessary when state says everything.
			inputState.VendorMessage = ""
		}
		inputTrayState.Item = append(inputTrayState.Item, inputState)

		inputTrayUnits = append(inputTrayUnits, cdd.InputTrayUnit{
			VendorID: index.String(),
			Type:     cdd.InputTrayUnitCustom,
			Index:    index,
			CustomDisplayNameLocalized: cdd.NewLocalizedString(names[i].Value),
		})
	}

	return &inputTrayUnits, &inputTrayState, true
}