Example #1
0
/*
 * processiSolUserInput
 *
 * Act on user input into the ISOL session.  The only reason this
 * is complicated is that we have to process escape sequences.
 *
 * return   0 on success
 *          1 if we should exit
 *        < 0 on error (BMC probably closed the session)
 */
static int
processiSolUserInput(struct ipmi_intf * intf,
		    uint8_t * input,
		    uint16_t  buffer_length)
{
	static int escape_pending = 0;
	static int last_was_cr    = 1;
	struct ipmi_v2_payload v2_payload;
	int  length               = 0;
	int  retval               = 0;
	char ch;
	int  i;

	memset(&v2_payload, 0, sizeof(v2_payload));
	
	/*
	 * Our first order of business is to check the input for escape
	 * sequences to act on.
	 */
	for (i = 0; i < buffer_length; ++i)
	{
		ch = input[i];

		if (escape_pending){
			escape_pending = 0;
			
			/*
			 * Process a possible escape sequence.
			 */
			switch (ch) {
			case '.':
				printf("%c. [terminated ipmitool]\n", ISOL_ESCAPE_CHARACTER);
				retval = 1;
				break;
			case 'Z' - 64:
				printf("%c^Z [suspend ipmitool]\n", ISOL_ESCAPE_CHARACTER);
				suspendSelf(1); /* Restore tty back to raw */
				continue;

			case 'X' - 64:
				printf("%c^X [suspend ipmitool]\n", ISOL_ESCAPE_CHARACTER);
				suspendSelf(0); /* Don't restore to raw mode */
				continue;

			case 'B':
				printf("%cb [send break]\n", ISOL_ESCAPE_CHARACTER);
				sendBreak(intf);
				continue;

			case '?':
				printiSolEscapeSequences();
				continue;
			default:
				if (ch != ISOL_ESCAPE_CHARACTER)
					v2_payload.payload.sol_packet.data[length++] =
						ISOL_ESCAPE_CHARACTER;
				v2_payload.payload.sol_packet.data[length++] = ch;
			}
		}

		else
		{
			if (last_was_cr && (ch == ISOL_ESCAPE_CHARACTER)) {
				escape_pending = 1;
				continue;
			}

			v2_payload.payload.sol_packet.data[length++] =	ch;
		}


		/*
		 * Normal character.  Record whether it was a newline.
		 */
		last_was_cr = (ch == '\r' || ch == '\n');
	}

	/*
	 * If there is anything left to process we dispatch it to the BMC,
	 * send intf->session->sol_data.max_outbound_payload_size bytes
	 * at a time.
	 */
	if (length)
	{
		struct ipmi_rs * rsp;

		v2_payload.payload.sol_packet.flush_outbound = 1; /* Not sure if necessary ? */
		v2_payload.payload.sol_packet.character_count = length;
		rsp = intf->send_sol(intf, &v2_payload);

		if (! rsp) {
			lprintf(LOG_ERR, "Error sending SOL data");
			retval = -1;
		}

		/* If the sequence number is set we know we have new data */
		else if ((rsp->session.payloadtype == IPMI_PAYLOAD_TYPE_SOL)        &&
			 (rsp->payload.sol_packet.packet_sequence_number))
			output(rsp);
	}
	return retval;
}
Example #2
0
void SRF01::sendCommand(uint8_t address, uint8_t command)
{
  sendBreak();
  Serial1.write(address); // Address
  Serial1.write(command); // Real range cm
}