Beispiel #1
0
static int
getmsec(int c, int *int_r, gnc_t gnc, void *closure)
{
    char *t;
    int i;
    c = getword(c, &t, gnc, closure);
    if(c < -1)
        return c;
    i = parse_msec(t);
    if(i < 0) {
        free(t);
        return -2;
    }
    free(t);
    *int_r = i;
    return c;
}
Beispiel #2
0
bool hp98035_io_card::parse_unit_command(const uint8_t*& p, unsigned unit_no)
{
	unit_no--;
	timer_unit_t& unit = m_units[ unit_no ];
	bool get_out = false;
	unsigned msec;
	uint8_t to_match[ 5 ];
	std::ostringstream out;

	LOG(("U %c %u %p\n" , *p , unit_no , &unit));

	switch (*p++) {
	case '=':
		// Assign unit
		if (*p == 'I') {
			p++;
			get_out = assign_unit(unit , p , true);
		} else if (*p == 'O') {
			p++;
			get_out = assign_unit(unit , p , false);
		}
		break;

	case 'C':
		// Clear input unit
		if (unit.m_input && unit.m_port) {
			unit.m_value = 0;
		} else {
			set_error(ERR_MASK_WRONG_UNIT);
		}
		break;

	case 'D':
		// Set delay on output unit
		if (parse_msec(p , msec)) {
			if (!unit.m_input && unit.m_port) {
				if (unit.m_state == UNIT_IDLE) {
					unit.m_delay = msec;
				} else {
					set_error(ERR_MASK_CANT_EXEC);
				}
			} else {
				set_error(ERR_MASK_WRONG_UNIT);
			}
		} else {
			set_error(ERR_MASK_WRONG_INS);
		}
		get_out = true;
		break;

	case 'G':
		// Activate unit
		if (unit.m_port && unit.m_state == UNIT_IDLE) {
			unit.adv_state(true);

			LOG(("act %p %d %d %u %02u:%02u:%02u:%02u %u %u %u\n" , &unit , unit.m_state , unit.m_input , unit.m_port , unit.m_match_datetime[ 0 ] , unit.m_match_datetime[ 1 ] , unit.m_match_datetime[ 2 ] , unit.m_match_datetime[ 3 ] , unit.m_delay , unit.m_period , unit.m_value));
		} else {
			set_error(ERR_MASK_WRONG_UNIT);
		}
		break;

	case 'H':
		// Halt unit
		if (unit.m_port) {
			unit.deactivate();
		} else {
			set_error(ERR_MASK_WRONG_UNIT);
		}
		break;

	case 'M':
		// Set date/time to match on output unit
		if (!unit.m_input && unit.m_port) {
			if (unit.m_state == UNIT_IDLE) {
				if (*p == '\0') {
					unit.m_match_datetime[ 0 ] = EMPTY_FIELD;
					unit.m_match_datetime[ 1 ] = EMPTY_FIELD;
					unit.m_match_datetime[ 2 ] = EMPTY_FIELD;
					unit.m_match_datetime[ 3 ] = EMPTY_FIELD;
				} else if (parse_datetime(p , to_match) && *p == '\0') {
					unit.m_match_datetime[ 0 ] = to_match[ 1 ];
					unit.m_match_datetime[ 1 ] = to_match[ 2 ];
					unit.m_match_datetime[ 2 ] = to_match[ 3 ];
					unit.m_match_datetime[ 3 ] = to_match[ 4 ];
				} else {
					set_error(ERR_MASK_WRONG_INS);
				}
			} else {
				set_error(ERR_MASK_CANT_EXEC);
			}
		} else {
			set_error(ERR_MASK_WRONG_UNIT);
		}
		get_out = true;
		break;

	case 'P':
		// Set period on output unit
		if (parse_msec(p , msec)) {
			if (!unit.m_input && unit.m_port) {
				if (unit.m_state == UNIT_IDLE) {
					unit.m_period = msec;
				} else {
					set_error(ERR_MASK_CANT_EXEC);
				}
			} else {
				set_error(ERR_MASK_WRONG_UNIT);
			}
		} else {
			set_error(ERR_MASK_WRONG_INS);
		}
		get_out = true;
		break;

	case 'V':
		// Get value of input unit
		if (unit.m_input && unit.m_port) {
			util::stream_format(out , "%010u" , unit.m_value);
			set_obuffer(out.str().c_str());
		} else {
			set_error(ERR_MASK_WRONG_UNIT);
		}
		break;
	}

	return get_out;
}