Ejemplo n.º 1
0
void cHpiSubProviderEntity::GetInstrumentEntries( SaHpiRdrTypeT type,
                                                  std::deque<HpiEntry>& entries ) const
{
    SaErrorT rv;
    // TODO update_cnt
    SaHpiUint32T update_cnt;
    SaHpiResourceIdT rid;
    SaHpiInstrumentIdT instr_id;
    SaHpiRdrT rdr;

    SaHpiUint32T i = SAHPI_FIRST_ENTRY;
    while( i != SAHPI_LAST_ENTRY ) {
        SaHpiUint32T instance_id = i;

        rv = saHpiGetIdByEntityPath( m_ctx.session_id,
                                     m_ctx.entity_path,
                                     type,
                                     &i,
                                     &rid,
                                     &instr_id,
                                     &update_cnt );
        if( rv != SA_OK ) {
            break;
        }

        rv = saHpiRdrGetByInstrumentId( m_ctx.session_id, rid, type, instr_id, &rdr );
        if( rv != SA_OK ) {
            break;
        }

        std::wstring name;
        MakeNameForInstrument( rdr, name );
        entries.push_back( HpiEntry( RdrType2EntryType( type ), instance_id, name ) );
    }
}
Ejemplo n.º 2
0
ret_code_t ctrl_block(void)
{
	SaHpiRdrT		rdr_entry;
	SaHpiResourceIdT	rptid;
	SaHpiInstrumentIdT	rdrnum;
	SaHpiRdrTypeT		type;
	SaErrorT		rv;
	char			buf[256];
	ret_code_t		ret;
	term_def_t		*term;
	int			res;

	ret = ask_rpt(&rptid);
	if (ret != HPI_SHELL_OK) return(ret);
	type = SAHPI_CTRL_RDR;
	ret = ask_rdr(rptid, type, &rdrnum);
	if (ret != HPI_SHELL_OK) return(ret);
	rv = saHpiRdrGetByInstrumentId(Domain->sessionId, rptid, type, rdrnum,
		&rdr_entry);
	if (rv != SA_OK) {
		printf("saHpiRdrGetByInstrumentId error %s\n", oh_lookup_error(rv));
		printf("ERROR!!! Can not get rdr: ResourceId=%d RdrType=%d RdrNum=%d\n",
			rptid, type, rdrnum);
		return(HPI_SHELL_CMD_ERROR);
	};
	show_control(Domain->sessionId, rptid, rdrnum, ui_print);
	for (;;) {
		block_type = CTRL_COM;
		res = get_new_command("control block ==> ");
		if (res == 2) {
			unget_term();
			return HPI_SHELL_OK;
		};
		term = get_next_term();
		if (term == NULL) continue;
		snprintf(buf, 256, "%s", term->term);
		if ((strcmp(buf, "q") == 0) || (strcmp(buf, "quit") == 0)) break;
		if (strcmp(buf, "state") == 0) {
			show_control_state(Domain->sessionId, rptid, rdrnum, ui_print);
			continue;
		};
		if (strcmp(buf, "setstate") == 0) {
			set_control_state(Domain->sessionId, rptid, rdrnum);
			continue;
		};
		if (strcmp(buf, "show") == 0) {
			show_control(Domain->sessionId, rptid, rdrnum, ui_print);
			continue;
		}
	};
	block_type = MAIN_COM;
	return SA_OK;
}
Ejemplo n.º 3
0
ret_code_t fumi_block( void )
{
    SaErrorT           rv;
    ret_code_t         ret;
    SaHpiResourceIdT   rptid;
    SaHpiInstrumentIdT rdrnum;
    SaHpiRdrT          rdr;

    ret = ask_rpt( &rptid );
    if ( ret != HPI_SHELL_OK ) {
        return ret;
    };
    ret = ask_rdr( rptid, SAHPI_FUMI_RDR, &rdrnum );
    if ( ret != HPI_SHELL_OK ) {
        return ret;
    }
    rv = saHpiRdrGetByInstrumentId( Domain->sessionId, rptid, SAHPI_FUMI_RDR, rdrnum, &rdr );
    if ( rv != SA_OK ) {
        printf( "ERROR!!! saHpiRdrGetByInstrumentId"
                "(Rpt=%d RdrType=%d Rdr=%d): %s\n",
                rptid, SAHPI_FUMI_RDR, rdrnum,
                oh_lookup_error( rv )
              );
        return HPI_SHELL_CMD_ERROR;
    };

    fumi_block_env.rptid   = rptid;
    fumi_block_env.fuminum = rdr.RdrTypeUnion.FumiRec.Num;

    block_type = FUMI_COM;
    for ( ;; ) {
        int res;
        term_def_t * term ;
        char buf[256];

        res = get_new_command( "FUMI block ==> " );
        if ( res == 2 ) {
            unget_term();
            break;
        };
        term = get_next_term();
        if ( term == NULL ) continue;
        snprintf( buf, 256, "%s", term->term );
        if ( ( strcmp( buf, "q" ) == 0) || ( strcmp( buf, "quit" ) == 0 ) ) {
            break;
        }
    }
    block_type = MAIN_COM;
    return HPI_SHELL_OK;
}
Ejemplo n.º 4
0
void cHpiSubProviderWatchdog::GetInfo( std::deque<HpiInfo>& info ) const
{
    info.clear();

    SaErrorT rv;
    SaHpiRdrT rdr;
    rv = saHpiRdrGetByInstrumentId( m_ctx.session_id,
                                    m_ctx.resource_id,
                                    SAHPI_WATCHDOG_RDR,
                                    m_ctx.instrument_id,
                                    &rdr );
    if ( rv != SA_OK ) {
        Line( info, L"saHpiRdrGetByInstrumentId failed", rv, I32_SaError );
        return;
    }

    Line( info, L"Resource Id", m_ctx.resource_id, UI32_SaHpiResourceId );
    Line( info, L"Entity", rdr.Entity );
    Line( info, L"IsFru", rdr.IsFru, UI8_SaHpiBool );

    const SaHpiWatchdogRecT& wr = rdr.RdrTypeUnion.WatchdogRec;

    Line( info, L"Watchdog Num", wr.WatchdogNum, UI32_SaHpiWatchdogNum );
    Line( info, L"OEM", wr.Oem );
    Line( info, L"IdString", rdr.IdString );

    SaHpiWatchdogT w;
    rv = saHpiWatchdogTimerGet( m_ctx.session_id,
                                m_ctx.resource_id,
                                m_ctx.instrument_id,
                                &w );
    if ( rv != SA_OK ) {
        Line( info, L"saHpiWatchdogTimerGet failed", rv, I32_SaError );
        return;
    }

    Line( info, L"Current Settings and Configuration", L"" );
    Line( info, L"  Log", w.Log, UI8_SaHpiBool );
    Line( info, L"  Running", w.Running, UI8_SaHpiBool );
    Line( info, L"  Timer Use", w.TimerUse );
    Line( info, L"  Timer Action", w.TimerAction );
    Line( info, L"  Pre-Timer Interrupt", w.PretimerInterrupt );
    Line( info, L"  Pre-Timeout Interval, ms", w.PreTimeoutInterval );
    Line( info, L"  Timer Use Expiration Flags",
          w.TimerUseExpFlags,
          UI8_SaHpiWatchdogExpFlags );
    Line( info, L"  Initial Count", w.InitialCount );
    Line( info, L"  Present Count", w.PresentCount );
}
Ejemplo n.º 5
0
ret_code_t ann_block(void)
{
	SaHpiResourceIdT	rptid;
	SaHpiInstrumentIdT	rdrnum;
	SaHpiRdrTypeT		type;
	SaErrorT		rv;
	char			buf[256];
	ret_code_t		ret;
	term_def_t		*term;
	int			res;

	ret = ask_rpt(&rptid);
	if (ret != HPI_SHELL_OK) return(ret);
	type = SAHPI_ANNUNCIATOR_RDR;
	ret = ask_rdr(rptid, type, &rdrnum);
	if (ret != HPI_SHELL_OK) return(ret);
	rv = saHpiRdrGetByInstrumentId(Domain->sessionId, rptid, type, rdrnum,
		&(ann_block_env.rdr_entry));
	if (rv != SA_OK) {
		printf("saHpiRdrGetByInstrumentId error %s\n", oh_lookup_error(rv));
		printf("ERROR!!! Can not get rdr: ResourceId=%d RdrType=%d RdrNum=%d\n",
			rptid, type, rdrnum);
		return(HPI_SHELL_CMD_ERROR);
	};
	ann_block_env.rptid = rptid;
	ann_block_env.rdrnum = rdrnum;
	show_rdr_attrs(&(ann_block_env.rdr_entry));
	for (;;) {
		block_type = ANN_COM;
		res = get_new_command("annunciator block ==> ");
		if (res == 2) {
			unget_term();
			block_type = MAIN_COM;
			return HPI_SHELL_OK;
		};
		term = get_next_term();
		if (term == NULL) continue;
		snprintf(buf, 256, "%s", term->term);
		if ((strcmp(buf, "q") == 0) || (strcmp(buf, "quit") == 0)) break;
	};
	block_type = MAIN_COM;
	return HPI_SHELL_OK;
}
Ejemplo n.º 6
0
void cHpiSubProviderIdr::GetInfo( std::deque<HpiInfo>& info ) const
{
    info.clear();

    SaErrorT rv;

    SaHpiRdrT rdr;
    rv = saHpiRdrGetByInstrumentId( m_ctx.session_id,
                                    m_ctx.resource_id,
                                    SAHPI_INVENTORY_RDR,
                                    m_ctx.instrument_id,
                                    &rdr );
    if ( rv != SA_OK ) {
        Line( info, L"saHpiRdrGetByInstrumentId failed", rv, I32_SaError );
        return;
    }

    Line( info, L"Resource Id", m_ctx.resource_id, UI32_SaHpiResourceId );
    Line( info, L"Entity", rdr.Entity );
    Line( info, L"IsFru", rdr.IsFru, UI8_SaHpiBool );

    const SaHpiInventoryRecT& ir = rdr.RdrTypeUnion.InventoryRec;

    Line( info, L"Idr Id", ir.IdrId, UI32_SaHpiIdrId );
    Line( info, L"Persistent", ir.Persistent, UI8_SaHpiBool );
    Line( info, L"OEM", ir.Oem );
    Line( info, L"IdString", rdr.IdString );

    SaHpiIdrInfoT idr_info;
    rv = saHpiIdrInfoGet( m_ctx.session_id,
                          m_ctx.resource_id,
                          m_ctx.instrument_id,
                          &idr_info );
    if ( rv != SA_OK ) {
        Line( info, L"saHpiIdrInfoGet failed", rv, I32_SaError );
        return;
    }
    Line( info, L"Update Count", idr_info.UpdateCount );
    Line( info, L"Read Only", idr_info.ReadOnly, UI8_SaHpiBool );
    Line( info, L"Number of Areas", idr_info.NumAreas );
}
Ejemplo n.º 7
0
int Test_Resource(SaHpiSessionIdT session_id, SaHpiRptEntryT rpt_entry,
		  callback2_t func)
{
	SaErrorT status;
	int retval = SAF_TEST_UNKNOWN;
	SaHpiRdrT newRdr;
	if (!(rpt_entry.ResourceCapabilities & SAHPI_CAPABILITY_RDR)) {
		status = saHpiRdrGetByInstrumentId(session_id,
						   rpt_entry.ResourceId,
						   SAHPI_SENSOR_RDR,
						   0, &newRdr);
		if (status != SA_ERR_HPI_CAPABILITY) {
			e_print(saHpiRdrGetByInstrumentId,
				SA_ERR_HPI_CAPABILITY, status);
			retval = SAF_TEST_FAIL;
		} else {
			retval = SAF_TEST_PASS;
		}

	} else			//Resource Does not support RDR's
		retval = SAF_TEST_NOTSUPPORT;
	return (retval);

}
Ejemplo n.º 8
0
static ret_code_t show_rdr(void)
{
	Rdr_t			tmp_rdr;
	SaHpiRdrT		rdr_entry;
	SaHpiResourceIdT	rptid = 0;
	SaHpiInstrumentIdT	rdrnum;
	SaHpiRdrTypeT		type;
	SaErrorT		rv;
	int			i;
	char			buf[10], t;
	term_def_t		*term;
	ret_code_t		ret;

	term = get_next_term();
	if (term == NULL) {
		if (read_file) return(HPI_SHELL_CMD_ERROR);
		i = show_rpt_list(Domain, SHOW_ALL_RPT, rptid, ui_print);
		if (i == 0) {
			printf("NO rpt!\n");
			return(HPI_SHELL_CMD_ERROR);
		};
		i = get_string_param("RPT (ID | all) ==> ", buf, 9);
		if (i != 0) return HPI_SHELL_CMD_ERROR;
		if (strncmp(buf, "all", 3) == 0) {
			show_rpt_list(Domain, SHOW_ALL_RDR, rptid, ui_print);
			return(HPI_SHELL_OK);
		};
		rptid = (SaHpiResourceIdT)atoi(buf);
	} else {
		if (strcmp(term->term, "all") == 0) {
			show_rpt_list(Domain, SHOW_ALL_RDR, rptid, ui_print);
			return(HPI_SHELL_OK);
		};
		if (isdigit(term->term[0]))
			rptid = (SaHpiResourceIdT)atoi(term->term);
		else
			return HPI_SHELL_PARM_ERROR;
	};
	term = get_next_term();
	if (term == NULL) {
		if (read_file) return(HPI_SHELL_CMD_ERROR);
		i = get_string_param("RDR Type (s|a|c|w|i|all) ==> ",
			buf, 9);
		if (i != 0) return HPI_SHELL_PARM_ERROR;
	} else {
		memset(buf, 0, 10);
		strncpy(buf, term->term, 3);
	};
	if (strncmp(buf, "all", 3) == 0) t = 'n';
	else t = *buf;
	if (t == 'c') type = SAHPI_CTRL_RDR;
	else if (t == 's') type = SAHPI_SENSOR_RDR;
	else if (t == 'i') type = SAHPI_INVENTORY_RDR;
	else if (t == 'w') type = SAHPI_WATCHDOG_RDR;
	else if (t == 'a') type = SAHPI_ANNUNCIATOR_RDR;
	else type = SAHPI_NO_RECORD;
	ret = ask_rdr(rptid, type, &rdrnum);
	if (ret != HPI_SHELL_OK) return(ret);
	if (type == SAHPI_NO_RECORD)
		rv = find_rdr_by_num(Domain->sessionId, rptid,
			rdrnum, type, 0, &rdr_entry);
	else
		rv = saHpiRdrGetByInstrumentId(Domain->sessionId,
			rptid, type, rdrnum, &rdr_entry);
	if (rv != SA_OK) {
		printf("ERROR!!! Get rdr: ResourceId=%d RdrType=%d"
			"RdrNum=%d: %s\n",
			rptid, type, rdrnum, oh_lookup_error(rv));
		return(HPI_SHELL_CMD_ERROR);
	};
	make_attrs_rdr(&tmp_rdr, &rdr_entry);
	show_Rdr(&tmp_rdr, ui_print);
	free_attrs(&(tmp_rdr.Attrutes));
	return HPI_SHELL_OK;
}
Ejemplo n.º 9
0
SaErrorT show_sensor(SaHpiSessionIdT sessionid, SaHpiResourceIdT resourceid,
	SaHpiSensorNumT sensornum, hpi_ui_print_cb_t proc)
{
        SaHpiSensorReadingT	reading;
	SaHpiEventStateT	status, assert, deassert;
	SaHpiRdrT		rdr;
        SaErrorT		rv;
	SaHpiBoolT		val;
	char			buf[SHOW_BUF_SZ];
	char			errbuf[SHOW_BUF_SZ];
	Pr_ret_t		res;

	rv = saHpiRdrGetByInstrumentId(sessionid, resourceid, SAHPI_SENSOR_RDR,
		sensornum, &rdr);
	if (rv != SA_OK) {
		snprintf(errbuf, SHOW_BUF_SZ,
			"\nERROR: saHpiRdrGetByInstrumentId: error: %s\n",
			oh_lookup_error(rv));
		proc(errbuf);
		return(rv);
	};
	snprintf(buf, SHOW_BUF_SZ, "Sensor(%d/%d) %s", resourceid, sensornum,
		oh_lookup_sensortype(rdr.RdrTypeUnion.SensorRec.Type));
	proc(buf);
	res = print_text_buffer_text("  ", &(rdr.IdString), "\n", proc);
	if (res != HPI_UI_OK) return(SA_OK);
	rv = saHpiSensorEnableGet(sessionid, resourceid, sensornum, &val);
	if (rv != SA_OK) {
		snprintf(errbuf, SHOW_BUF_SZ,
			"\nERROR: saHpiSensorEnableGet: error: %s\n",
			oh_lookup_error(rv));
		if (proc(errbuf) != HPI_UI_OK) return(rv);
	} else {
		if (val) res = proc("Enable ");
		else res = proc("Disable ");
		if (res != HPI_UI_OK) return(SA_OK);
	};
	rv = saHpiSensorEventEnableGet(sessionid, resourceid, sensornum, &val);
	if (rv != SA_OK) {
		snprintf(errbuf, SHOW_BUF_SZ,
			"\nERROR: saHpiSensorEventEnableGet: error: %s\n",
			oh_lookup_error(rv));
		if (proc(errbuf) != HPI_UI_OK) return(rv);
	} else {
		if (proc("    event : ") != HPI_UI_OK) return(SA_OK);
		if (val) res = proc("Enable");
		else res = proc("Disable");
		if (res != HPI_UI_OK) return(SA_OK);
	};
	rv = saHpiSensorEventMasksGet(sessionid, resourceid, sensornum,
		&assert, &deassert);
	if (rv != SA_OK) {
		snprintf(errbuf, SHOW_BUF_SZ,
			"\nERROR: saHpiSensorEventMasksGet: error: %s\n",
			oh_lookup_error(rv));
		if (proc(errbuf) != HPI_UI_OK) return(rv);
	} else {
		snprintf(buf, SHOW_BUF_SZ,
			"   supported: 0x%4.4x  masks: assert = 0x%4.4x"
			"   deassert = 0x%4.4x\n",
			rdr.RdrTypeUnion.SensorRec.Events, assert, deassert);
		if (proc(buf) != HPI_UI_OK) return(rv);
	};
	rv = saHpiSensorReadingGet(sessionid, resourceid, sensornum,
		&reading, &status);
	if (rv != SA_OK) {
		snprintf(errbuf, SHOW_BUF_SZ,
			"\nERROR: saHpiSensorReadingGet: error: %s\n",
			oh_lookup_error(rv));
		proc(errbuf);
		return(rv);
	};
	snprintf(buf, SHOW_BUF_SZ, "\tEvent states = 0x%x\n", status);
	if (proc(buf) != HPI_UI_OK) return(SA_OK);
        if (reading.IsSupported) {
		res = print_thres_value(&reading, "\tReading Value =",
			NULL, 0, proc);
		if (res == HPI_UI_END) return(SA_OK);
	} else {
		if (proc("\tReading not supported\n") != HPI_UI_OK) return(SA_OK);
	}

	show_threshold(sessionid, resourceid, sensornum,
		&(rdr.RdrTypeUnion.SensorRec), proc);

	return SA_OK;
}
Ejemplo n.º 10
0
SaErrorT show_control(SaHpiSessionIdT sessionid, SaHpiResourceIdT resourceid,
	SaHpiCtrlNumT num, hpi_ui_print_cb_t proc)
{
        SaErrorT		rv;
	SaHpiRdrT		rdr;
	SaHpiCtrlRecT		*ctrl;
	char			*str, *str1;
	char			buf[SHOW_BUF_SZ];
	char			errbuf[SHOW_BUF_SZ];
	SaHpiCtrlTypeT		type;
	SaHpiCtrlRecDigitalT	*digit;
	SaHpiCtrlRecDiscreteT	*discr;
	SaHpiCtrlRecAnalogT	*analog;
	SaHpiCtrlRecStreamT	*stream;
	SaHpiCtrlRecTextT	*text;
	SaHpiCtrlRecOemT	*oem;
	int			i;

	rv = saHpiRdrGetByInstrumentId(sessionid, resourceid, SAHPI_CTRL_RDR,
		num, &rdr);
	if (rv != SA_OK) {
		snprintf(errbuf, SHOW_BUF_SZ,
			"\nERROR: saHpiRdrGetByInstrumentId: error: %s\n",
			oh_lookup_error(rv));
		proc(errbuf);
		return(rv);
	};
	ctrl = &(rdr.RdrTypeUnion.CtrlRec);
	type = ctrl->Type;
	if (ctrl->WriteOnly) str = "(Write Only)";
	else str = " ";
	snprintf(buf, SHOW_BUF_SZ, "Control(%d/%d) Type: %s  %s  Output: %s\n",
		resourceid, num, oh_lookup_ctrltype(type), str,
		oh_lookup_ctrloutputtype(ctrl->OutputType));
	if (proc(buf) != HPI_UI_OK) return(SA_OK);
	if (ctrl->DefaultMode.ReadOnly) str = "(Read Only)";
	else str = " ";
	snprintf(buf, SHOW_BUF_SZ, "  Mode: %s  %s\n",
		oh_lookup_ctrlmode(ctrl->DefaultMode.Mode), str);
	if (proc(buf) != HPI_UI_OK) return(SA_OK);

	if (proc("Data:\n") != HPI_UI_OK) return(SA_OK);
	switch (type) {
		case SAHPI_CTRL_TYPE_DIGITAL:
			digit = &(ctrl->TypeUnion.Digital);
			str = oh_lookup_ctrlstatedigital(digit->Default);
			if (str == (char *)NULL) {
				snprintf(errbuf, SHOW_BUF_SZ, "Invalid value (0x%x)",
					digit->Default);
				str = errbuf;
			};
			snprintf(buf, SHOW_BUF_SZ, "\tDefault: %s\n", str);
			break;
		case SAHPI_CTRL_TYPE_DISCRETE:
			discr = &(ctrl->TypeUnion.Discrete);
			snprintf(buf, SHOW_BUF_SZ, "\tDefault: %d\n", discr->Default);
			break;
		case SAHPI_CTRL_TYPE_ANALOG:
			analog = &(ctrl->TypeUnion.Analog);
			snprintf(buf, SHOW_BUF_SZ,
				"\tDefault: %d  (min = %d  max = %d)\n",
				analog->Default, analog->Min, analog->Max);
			break;
		case SAHPI_CTRL_TYPE_STREAM:
			stream = &(ctrl->TypeUnion.Stream);
			snprintf(buf, SHOW_BUF_SZ,
				"\tDefault: Repeat = %d  lendth = %d  stream = %s\n",
				stream->Default.Repeat, stream->Default.StreamLength,
				stream->Default.Stream);
			break;
		case SAHPI_CTRL_TYPE_TEXT:
			text = &(ctrl->TypeUnion.Text);
			snprintf(buf, SHOW_BUF_SZ, "\tMaxChars = %d  MaxLines = %d\n",
				text->MaxChars, text->MaxLines);
			if (proc(buf) != HPI_UI_OK) return(SA_OK);
			str = oh_lookup_language(text->Language);
			if (str == (char *)NULL) str = "UNKNOWN";
			str1 = oh_lookup_texttype(text->DataType);
			if (str1 == (char *)NULL) str1 = "UNKNOWN";
			snprintf(buf, SHOW_BUF_SZ,
				"\tLanguage = %s  DataType = %s\n", str, str1);
			if (proc(buf) != HPI_UI_OK) return(SA_OK);
			snprintf(buf, SHOW_BUF_SZ, "\tDefault: Line # = %d",
				text->Default.Line);
			if (proc(buf) != HPI_UI_OK) return(SA_OK);
			print_text_buffer_text("  Text = ", &(text->Default.Text),
				"\n", proc);
			return SA_OK;
		case SAHPI_CTRL_TYPE_OEM:
			oem = &(ctrl->TypeUnion.Oem);
			snprintf(buf, SHOW_BUF_SZ, "\tMId = %d  Config data = ",
				oem->MId);
			proc(buf);
			str = (char *)(oem->ConfigData);
			for (i = 0; i < SAHPI_CTRL_OEM_CONFIG_LENGTH; i++)
				sprintf(buf + i * 3, "%2.2X ", (unsigned char)(str[i]));
			strcat(buf, "\n\t");
			if (proc(buf) != HPI_UI_OK) return(SA_OK);
			sprintf(buf, "Default: MId = %d  Body = ", oem->MId);
			str = (char *)(oem->Default.Body);
			for (i = 0; i < oem->Default.BodyLength; i++)
				sprintf(buf + i * 3, "%2.2X ", (unsigned char)(str[i]));
			strcat(buf, "\n");
			break;
		default: strcpy(buf, "Unknown control type\n");
	};
	proc(buf);
	return SA_OK;
}
Ejemplo n.º 11
0
static ret_code_t set_control_state(SaHpiSessionIdT sessionid,
	SaHpiResourceIdT resourceid, SaHpiCtrlNumT num)
{
        SaErrorT		rv;
	SaHpiRdrT		rdr;
	SaHpiCtrlRecT		*ctrl;
	SaHpiCtrlTypeT		type;
	SaHpiCtrlStateDigitalT	state_val = 0;
	SaHpiCtrlModeT		mode;
	SaHpiCtrlStateT		state;
	char			buf[SAHPI_MAX_TEXT_BUFFER_LENGTH];
	char			*str;
	int			i, res;

	rv = saHpiRdrGetByInstrumentId(sessionid, resourceid, SAHPI_CTRL_RDR,
		num, &rdr);
	if (rv != SA_OK) {
		printf("saHpiRdrGetByInstrumentId: error: %s\n", oh_lookup_error(rv));
		return(HPI_SHELL_CMD_ERROR);
	};
	memset(&state, 0, sizeof(SaHpiCtrlStateT));
	i = get_string_param("Mode(auto|manual): ", buf, 7);
	if (i != 0) return(HPI_SHELL_CMD_ERROR);
	if (strcmp(buf, "auto") == 0) mode = SAHPI_CTRL_MODE_AUTO;
	else if (strcmp(buf, "manual") == 0) mode = SAHPI_CTRL_MODE_MANUAL;
	else return(HPI_SHELL_CMD_ERROR);
	if (mode == SAHPI_CTRL_MODE_AUTO) {
		rv = saHpiControlSet(sessionid, resourceid, num,
			mode, (SaHpiCtrlStateT *)NULL);
		if (rv != SA_OK) {
			printf("saHpiControlSet: error: %s\n",
				oh_lookup_error(rv));
			return(HPI_SHELL_CMD_ERROR);
		};
		return(HPI_SHELL_OK);
	};
	ctrl = &(rdr.RdrTypeUnion.CtrlRec);
	type = ctrl->Type;
	state.Type = type;
	switch (type) {
		case SAHPI_CTRL_TYPE_DIGITAL:
			i = get_string_param(
				"New state(on|off|pulseon|pulseoff): ", buf, 9);
			if (i != 0) return(HPI_SHELL_CMD_ERROR);
			if (strcmp(buf, "on") == 0) state_val = SAHPI_CTRL_STATE_ON;
			if (strcmp(buf, "off") == 0) state_val = SAHPI_CTRL_STATE_OFF;
			if (strcmp(buf, "pulseon") == 0)
				state_val = SAHPI_CTRL_STATE_PULSE_ON;
			if (strcmp(buf, "pulseoff") == 0)
				state_val = SAHPI_CTRL_STATE_PULSE_OFF;
			state.StateUnion.Digital = state_val;
			break;
		case SAHPI_CTRL_TYPE_DISCRETE:
			i = get_int_param("Value ==> ", &res);
			if (i != 1) {
				printf("Invalid value\n");
				return HPI_SHELL_CMD_ERROR;
			};
			state.StateUnion.Discrete = res;
			break;
		case SAHPI_CTRL_TYPE_ANALOG:
			i = get_int_param("Value ==> ", &res);
			if (i != 1) {
				printf("Invalid value\n");
				return HPI_SHELL_CMD_ERROR;
			};
			state.StateUnion.Analog = res;
			break;
		case SAHPI_CTRL_TYPE_STREAM:
			i = get_string_param("Repeat(yes|no): ", buf, 4);
			if (i != 0) return(HPI_SHELL_CMD_ERROR);
			str = buf;
			while (*str == ' ') str++;
			if (strncmp(str, "yes", 3) == 0)
				state.StateUnion.Stream.Repeat = 1;
			i = get_string_param("Stream: ", buf, 4);
			i = strlen(buf);
			if (i > 4) i = 4;
			state.StateUnion.Stream.StreamLength = i;
			strncpy((char *)(state.StateUnion.Stream.Stream), buf, i);
			break;
		case SAHPI_CTRL_TYPE_TEXT:
			i = get_int_param("Line #: ", &res);
			if (i != 1) {
				printf("Invalid value\n");
				return HPI_SHELL_CMD_ERROR;
			};
			state.StateUnion.Text.Line = res;
			printf("Text: ");
			i = set_text_buffer(&(state.StateUnion.Text.Text));
			if (i != 0) {
				printf("Invalid text\n");
				return(HPI_SHELL_CMD_ERROR);
			};
			break;
		case SAHPI_CTRL_TYPE_OEM:
			i = get_int_param("Manufacturer Id: ", &res);
			if (i != 1) {
				printf("Invalid value\n");
				return HPI_SHELL_CMD_ERROR;
			};
			state.StateUnion.Oem.MId = res;
			memset(state.StateUnion.Oem.Body, 0,
				SAHPI_CTRL_MAX_OEM_BODY_LENGTH);
			i = get_hex_string_param("Oem body: ",
				(char *)(state.StateUnion.Oem.Body),
				SAHPI_CTRL_MAX_OEM_BODY_LENGTH);
			state.StateUnion.Oem.BodyLength = i;
			break;
		default:
			strcpy(buf, "Unknown control type\n");
			return(HPI_SHELL_CMD_ERROR);
	};
	rv = saHpiControlSet(sessionid, resourceid, num,
		SAHPI_CTRL_MODE_MANUAL, &state);
	if (rv != SA_OK) {
		printf("saHpiControlSet: error: %s\n",
			oh_lookup_error(rv));
		return(HPI_SHELL_CMD_ERROR);
	};
	return(HPI_SHELL_OK);
}
Ejemplo n.º 12
0
int main(int argc, char **argv)
{
        int number_resources = 0, modeOption;
        SaErrorT rv;
        SaHpiSessionIdT sessionid;
        SaHpiResourceIdT resourceid;
        SaHpiResourceIdT resourceid_list[RESOURCE_CAP_LENGTH] = {0};
        SaHpiCtrlNumT controlNumber = OA_SOAP_RES_CNTRL_NUM;
        SaHpiCtrlModeT controlMode;
        SaHpiCtrlStateT controlState;
        SaHpiCapabilitiesT capability = SAHPI_CAPABILITY_CONTROL;
        SaHpiCtrlTypeT control_type = SAHPI_CTRL_TYPE_DIGITAL;
        SaHpiRdrT rdr;
        SaHpiCtrlRecT *ctrl;
        SaHpiCtrlRecAnalogT *analog;

        printf("saHpiControlSet: Test for hpi control set function\n");

        rv = saHpiSessionOpen(SAHPI_UNSPECIFIED_DOMAIN_ID, &sessionid, NULL);
        if (rv != SA_OK) {
                printf("saHpiSessionOpen failed with error: %s\n",
                       oh_lookup_error(rv));
                return rv;
        }

        /* Discover the resources with control capability */
        printf("\nListing the resource with control capability\n\n");
        rv = discover_resources(sessionid, capability, resourceid_list,
                                &number_resources);
        if (rv != SA_OK) {
                exit(-1);
        }

        printf("\nPlease enter the resource id: ");
        scanf("%d", &resourceid);

        printf("\nSupported controls on the resource are:");
        if (resourceid == powerSubsystemResId) {
          printf("\nPower mode control(Press 3)");
          printf("\nDynamic power mode control(Press 4)");
          printf("\nPower limit mode control(Press 5)");
          printf("\nStatic power limit control(Press 6)");
          printf("\nDynamic power cap control(Press 7)");
          printf("\nDerated circuit cap control(Press 8)");
          printf("\nRated circuit cap control(Press 9)");
        }
        else {
          printf("\nUID LED control(Press 0)");
          printf("\nPower control(Press 1)");
        }

        printf("\nEnter your option:");
        scanf("%d", &controlNumber);

        if (resourceid == powerSubsystemResId) {
          switch (controlNumber) {
            case OA_SOAP_DYNAMIC_PWR_CNTRL:
              control_type = SAHPI_CTRL_TYPE_DIGITAL;
              break;
            case OA_SOAP_PWR_MODE_CNTRL:
            case OA_SOAP_PWR_LIMIT_MODE_CNTRL:
              control_type = SAHPI_CTRL_TYPE_DISCRETE;
              break;
            case OA_SOAP_STATIC_PWR_LIMIT_CNTRL:
            case OA_SOAP_DYNAMIC_PWR_CAP_CNTRL:
            case OA_SOAP_DERATED_CIRCUIT_CAP_CNTRL:
            case OA_SOAP_RATED_CIRCUIT_CAP_CNTRL:
              control_type = SAHPI_CTRL_TYPE_ANALOG;
              break; 
          }
        }

        printf("Possible control mode options are: \n");
        printf("\tPress 1 for AUTO MODE \n");
        printf("\tPress 2 for MANUAL MODE \n");
        printf("Please enter your option: ");

        scanf("%d", &modeOption);
        if (modeOption == 1)
                controlMode=SAHPI_CTRL_MODE_AUTO;
        else if (modeOption == 2)
                controlMode=SAHPI_CTRL_MODE_MANUAL;
        else {
                printf("Wrong option selected. Exiting");
                exit (-1);
        }

        controlState.Type = control_type;

        switch (control_type) {
          case SAHPI_CTRL_TYPE_DIGITAL:
            printf("Possible control state options are: \n");
            printf("\tPress 1 for ON \n");
            printf("\tPress 2 for OFF \n");
            printf("Please enter your option: ");
            scanf("%d", &modeOption);
            switch (modeOption) {
                    case 1 :
                            controlState.StateUnion.Digital =
                              SAHPI_CTRL_STATE_ON;
                            break;
                    case 2 :
                            controlState.StateUnion.Digital =
                              SAHPI_CTRL_STATE_OFF;
                            break;
                    default :
                            printf("Wrong option selected. Exiting");
                            exit (-1);
            }

            break;
          case SAHPI_CTRL_TYPE_DISCRETE:
            printf("Possible control state options are: \n");
            if (controlNumber == OA_SOAP_PWR_MODE_CNTRL) {
              printf("\tPress 1 for C7000_PWR_NON_REDUNDANT \n");
              printf("\tPress 2 for C7000_PWR_AC_REDUNDANT \n");
              printf("\tPress 3 for C7000_PWR_SUPPLY_REDUNDANT \n");
            } else {
              printf("\tPress 0 for C7000_PWR_LIMIT_NONE \n");
              printf("\tPress 1 for C7000_PWR_LIMIT_STATIC \n");
              printf("\tPress 2 for C7000_PWR_LIMIT_DYNAMIC_CAP \n");
            }
            printf("Please enter your option: ");
            scanf("%d", &modeOption);
            controlState.StateUnion.Discrete = modeOption;
            break;
          case SAHPI_CTRL_TYPE_ANALOG:
            rv = saHpiRdrGetByInstrumentId(sessionid, resourceid,
                                           SAHPI_CTRL_RDR,
                                           controlNumber, &rdr);
            if (rv != SA_OK) {
              printf("Error: cannot get ctrl rdr by instrument id. Exiting");
              exit (-1);
            };
            ctrl = &(rdr.RdrTypeUnion.CtrlRec);
            analog = &(ctrl->TypeUnion.Analog);
            printf("Choose an analog value for the control (range = %d - %d): \
\n", analog->Min, analog->Max);
            scanf("%d", &modeOption);
            controlState.StateUnion.Analog = modeOption;
            break; 
        }

        rv = saHpiControlSet(sessionid, resourceid, controlNumber,
                             controlMode, &controlState);

        /* Print the test case status*/
        if (rv != SA_OK) {
                printf("saHpiControlSet returns %s\n",oh_lookup_error(rv));
                printf("Test case - FAIL\n");
        }
        else
                printf("Test case - PASS\n");

        rv = saHpiSessionClose(sessionid);
        return 0;
}
Ejemplo n.º 13
0
int Test_Resource(SaHpiSessionIdT session_id, SaHpiRptEntryT rpt_entry,
		  callback2_t func)
{
	SaErrorT status;
	int retval = SAF_TEST_UNKNOWN;
	SaHpiEntryIdT CurrRdr, NextRdr;
	SaHpiRdrT Rdr, newRdr;
	SaHpiInstrumentIdT Id;
	SaHpiRdrTypeT Type;
	if (rpt_entry.ResourceCapabilities & SAHPI_CAPABILITY_RDR) {
		NextRdr = SAHPI_FIRST_ENTRY;
		while (NextRdr != SAHPI_LAST_ENTRY) {
			CurrRdr = NextRdr;
			status = saHpiRdrGet(session_id,
					     rpt_entry.ResourceId,
					     CurrRdr, &NextRdr, &Rdr);
			if (status != SA_OK) {
				e_print(saHpiRdrGet, SA_OK, status);
				retval = SAF_TEST_UNRESOLVED;
				break;
			}

			if ((Type = Rdr.RdrType) == SAHPI_NO_RECORD) {
				m_print("No Rdr Record found.");
				retval = SAF_TEST_UNRESOLVED;
				break;
			}

			switch (Type) {
			case SAHPI_SENSOR_RDR:
				Id = (SaHpiInstrumentIdT) Rdr.RdrTypeUnion.
				    SensorRec.Num;
				break;
			case SAHPI_CTRL_RDR:
				Id = (SaHpiInstrumentIdT) Rdr.RdrTypeUnion.
				    CtrlRec.Num;
				break;
			case SAHPI_INVENTORY_RDR:
				Id = (SaHpiInstrumentIdT) Rdr.RdrTypeUnion.
				    InventoryRec.IdrId;
				break;
			case SAHPI_WATCHDOG_RDR:
				Id = (SaHpiInstrumentIdT) Rdr.RdrTypeUnion.
				    WatchdogRec.WatchdogNum;
				break;
			case SAHPI_ANNUNCIATOR_RDR:
				Id = (SaHpiInstrumentIdT) Rdr.RdrTypeUnion.
				    AnnunciatorRec.AnnunciatorNum;
				break;
			default:
				break;
			}

			if (Type != SAHPI_NO_RECORD) {
				status = saHpiRdrGetByInstrumentId(session_id,
								   rpt_entry.
								   ResourceId,
								   SAHPI_NO_RECORD,
								   Id, &newRdr);
				if (status != SA_ERR_HPI_INVALID_PARAMS) {
					e_print(saHpiRdrGetByInstrumentId,
						SA_ERR_HPI_INVALID_PARAMS,
						status);
					retval = SAF_TEST_FAIL;
					break;
				} else {
					retval = SAF_TEST_PASS;
					break;
				}

			}
		}
		if (retval == SAF_TEST_UNKNOWN)
			retval = SAF_TEST_PASS;
	} else			//Resource Does not support RDR's
		retval = SAF_TEST_NOTSUPPORT;
	return (retval);

}
Ejemplo n.º 14
0
ret_code_t ann_block(void)
{
	SaHpiRdrT		rdr_entry;
	SaHpiResourceIdT	rptid;
	SaHpiInstrumentIdT	rdrnum;
	SaHpiAnnunciatorModeT	mode;
	SaHpiRdrTypeT		type;
	SaErrorT		rv;
	char			buf[256];
	char			*str;
	ret_code_t		ret;
	term_def_t		*term;
	int			res, val;

	ret = ask_rpt(&rptid);
	if (ret != HPI_SHELL_OK) return(ret);
	type = SAHPI_ANNUNCIATOR_RDR;
	ret = ask_rdr(rptid, type, &rdrnum);
	if (ret != HPI_SHELL_OK) return(ret);
	rv = saHpiRdrGetByInstrumentId(Domain->sessionId, rptid, type, rdrnum,
		&rdr_entry);
	if (rv != SA_OK) {
		printf("saHpiRdrGetByInstrumentId error %s\n", oh_lookup_error(rv));
		printf("ERROR!!! Can not get rdr: ResourceId=%d RdrType=%d RdrNum=%d\n",
			rptid, type, rdrnum);
		return(HPI_SHELL_CMD_ERROR);
	};
	show_rdr_attrs(&rdr_entry);
	for (;;) {
		block_type = ANN_COM;
		res = get_new_command("annunciator block ==> ");
		if (res == 2) {
			unget_term();
			block_type = MAIN_COM;
			return HPI_SHELL_OK;
		};
		term = get_next_term();
		if (term == NULL) continue;
		snprintf(buf, 256, "%s", term->term);
		if ((strcmp(buf, "q") == 0) || (strcmp(buf, "quit") == 0)) break;
		if (strcmp(buf, "acknow") == 0) {
			set_acknowledge(rptid, rdrnum);
			continue;
		};
		if (strcmp(buf, "list") == 0) {
			list_cond(rptid, rdrnum);
			continue;
		};
		if (strcmp(buf, "add") == 0) {
			add_announ(rptid, rdrnum);
			continue;
		};
		if (strcmp(buf, "delete") == 0) {
			delete_announ(rptid, rdrnum);
			continue;
		};
		if (strcmp(buf, "modeget") == 0) {
			rv = saHpiAnnunciatorModeGet(Domain->sessionId, rptid,
				rdrnum, &mode);
			if (rv != SA_OK) {
				printf("saHpiAnnunciatorModeGet error %s\n",
					oh_lookup_error(rv));
				continue;
			};
			switch (mode) {
				case SAHPI_ANNUNCIATOR_MODE_AUTO:
					str = "AUTO"; break;
				case SAHPI_ANNUNCIATOR_MODE_USER:
					str = "USER"; break;
				case SAHPI_ANNUNCIATOR_MODE_SHARED:
					str = "SHARED"; break;
				default: str = "Unknown"; break;
			};
			printf("Annunciator Mode: %s\n", str);
			continue;
		};
		if (strcmp(buf, "modeset") == 0) {
			res = get_string_param("Mode(auto|user|shared): ",
				buf, 10);
			if (res != 0) {
				printf("Invalid mode: %s\n", buf);
				continue;
			};
			if (strcmp(buf, "auto") == 0)
				mode = SAHPI_ANNUNCIATOR_MODE_AUTO;
			else if (strcmp(buf, "user") == 0)
				mode = SAHPI_ANNUNCIATOR_MODE_USER;
			else if (strcmp(buf, "shared") == 0)
				mode = SAHPI_ANNUNCIATOR_MODE_SHARED;
			else {
				printf("Invalid mode: %s\n", buf);
				continue;
			};
			rv = saHpiAnnunciatorModeSet(Domain->sessionId, rptid,
				rdrnum, mode);
			if (rv != SA_OK) {
				printf("saHpiAnnunciatorModeSet error %s\n",
					oh_lookup_error(rv));
			};
			continue;
		};
		if (strcmp(buf, "show") == 0) {
			term = get_next_term();
			if (term == NULL) {
				show_rdr_attrs(&rdr_entry);
				continue;
			};
			unget_term();
			res = get_int_param(" ", &val);
			if (res != 1) unget_term();
			else show_cond(rptid, rdrnum, val);
			continue;
		}
	};
	block_type = MAIN_COM;
	return SA_OK;
}