Esempio n. 1
0
static void
log_current_data(void)
{
	response_t *r;
	ecu_data_t *ep;
	unsigned int i;

	if (!global_logfp)
		return;

	log_timestamp("D");
	fprintf(global_logfp, "MODE 1 DATA\n");
	for (i=0, ep=ecu_info; i<ecu_count; i++, ep++) {
		for (r = ep->mode1_data;
			r < &ep->mode1_data[ARRAY_SIZE(ep->mode1_data)]; r++) {
				log_response((int)i, r);
		}
	}

	log_timestamp("D");
	fprintf(global_logfp, "MODE 2 DATA\n");
	for (i=0, ep=ecu_info; i<ecu_count; i++, ep++) {
		for (r = ep->mode2_data;
			r < &ep->mode2_data[ARRAY_SIZE(ep->mode2_data)]; r++) {
			log_response((int)i, r);
		}
	}
}
Esempio n. 2
0
File: session.c Progetto: Xion/reefs
int respond(struct session* ses, int code, const char* resp)
{
    if (!ses || !resp)                  { errno = EFAULT; return -1; }
    if (code < 0 || code > 999)         { errno = EINVAL; return -1; }

    // convert response code to text
    char code_str[4];
    code_str[0] = (code / 100) + '0';   code %= 100;
    code_str[1] = (code / 10) + '0';    code %= 10;
    code_str[2] = code + '0';
    code_str[3] = '\0';

    int len = strlen(resp); if (len < 4) len = 4;
    char* buf = (char*)malloc((2 * len + 1) * sizeof(char));
    if (!buf)   return -1;

    // count lines in response
    int lines = 1; const char* p;
    for (p = resp; *p; ++p)
        if (*p == '\n') ++lines;

    // response format requires having a correct prefixing of response lines:
    // - for single line: code + space
    // - for multiline: code + dash in first line, space in following ones, code + space on last line
    int i, j = 0;
    for (i = 0; i < lines; ++i)
    {
        if (i == 0 || i + 1 == lines)
        {
            strcpy (buf + j, code_str); j += strlen(code_str);
            buf[j++] = (i == 0 && lines > 1 ? '-' : ' ');
        }
        else    buf[j++] = ' ';

        for (; *resp && *resp != '\n'; ++resp)
            buf[j++] = *resp;
        buf[j++] = '\n';
        ++resp; // jump through \n in response
    }
    buf[j] = '\0';  // this \0 goes to log but not to client

    if (write_data(ses->control_socket, buf, (size_t)j) < 0)
    {
        if (errno == EPIPE || errno == ECONNRESET)  ses->terminated = 1;
        else                                        return -1;
    }
    if (log_response(ses, buf) == -1)                           return -1;

    free (buf);
    return 0;
}
Esempio n. 3
0
UINT8 threecom3c505_device::read_command_port()
{
	UINT8 data;

	// the interrupt request is cleared when the Command Register is read
	set_interrupt(CLEAR_LINE);

	if (m_response_index == 0)
	{
		data = m_response.command;
	}
	else if (m_response_index == 1)
	{
		data = m_response.length;
	}
	else if (m_response_index < m_response_length)
	{
		data = m_response.data.raw[m_response_index - 2];
	}
	else if (m_response_index == m_response_length)
	{
		data = m_response.length + 2;
	}
	else if (m_response_index == m_response_length + 1 /*&& m_microcode_running*/)
	{
		// FIXME: special for SR10.4 microcode, content doesn't matter?
		data = 0; // ?
		m_response_index++;

		m_status &= ~ACRF; /* the adapter command register is no longer full */

		LOG2(("read_command_port: !!! reading 3C505 Command Register = %02x - m_status=%02x m_control=%02x",
						data, m_status, m_control));

		// wait for nak in control register
		set_command_pending(2);
	}
	else
	{
		// should never happen
		data = 0; // 0xff;
		LOG(("read_command_port: unexpected reading Command Register at index %04x", m_response_index));
	}

	if (m_response_index <= m_response_length + 1)
	{
		if (++m_response_index == m_response_length)
		{
			m_status = (m_status & ~ASF_PCB_MASK) | ASF_PCB_END;
		}
		else if (m_response_index == m_response_length + 1)
		{
			log_response();

			switch (m_response.command)
			{
			case CMD_MC_E1_RESPONSE:
				m_status |= HRDY; /* data register ready */
				// prepend data length
				m_rx_data_index = -2;
				break;

			case CMD_RECEIVE_PACKET_COMPLETE:
				m_status |= HRDY; /* data register ready */
				m_rx_data_index = 0;
				break;

			case CMD_TRANSMIT_PACKET_COMPLETE:
			case CMD_TRANSMIT_PACKET_18_COMPLETE:
				m_netstat.tot_xmit++;

				if (!send(m_tx_data_buffer.get_data(),  m_tx_data_buffer.get_length()))
				{
					// FIXME: failed to send the Ethernet packet
					LOG(("read_command_port(): !!! failed to send Ethernet packet"));
				}

				if (tx_data != NULL && //
						(*tx_data)(this, m_tx_data_buffer.get_data(), m_tx_data_buffer.get_length()) == 0)
				{
					// FIXME: failed to transmit the Ethernet packet
					LOG(("read_command_port(): !!! failed to transmit Ethernet packet"));
				}

				m_tx_data_buffer.reset();
				if (m_command_buffer[0] != CMD_TRANSMIT_PACKET_F9)
				{
					set_command_pending(2);
				}
				break;

			case CMD_DOWNLOAD_PROGRAM_RESPONSE:
				m_program_buffer.reset();
				set_command_pending(2);
				break;

			default:
				set_command_pending(2);
				break;
			}
		}
	}
	return data;
}
Esempio n. 4
0
UINT8 threecom3c505_device::read_command_port()
{
	UINT8 data;
	if (m_response_index == 0)
	{
//      set_command_pending(1);
		data = m_response.command;
	}
	else if (m_response_index == 1)
	{
		data = m_response.length;
	}
	else if (m_response_index < m_response_length)
	{
		data = m_response.data.raw[m_response_index - 2];
	}
	else if (m_response_index == m_response_length)
	{
		data = m_response.length + 2;
	}
	else if (m_response_index == m_response_length+1 /*&& m_microcode_running*/)
	{
		// FIXME: special for SR10.4 microcode, content doesn't matter?
		data = 0; // ?
		m_response_index++;

		m_status &= ~ACRF; /* adapter command register no longer full */

		LOG2(("FIXME: reading 3C505 Command Register at offset %02x with index %02x = %02x",
				PORT_COMMAND, m_response_index, data));

		if (m_mc_f9_pending == 1)
		{
			m_mc_f9_pending++;
		}
	}
	else
	{
		// should never happen
		data = 0; // 0xff;
		LOG(("UNEXPECTED: reading 3C505 Command Register at offset %02x = %02x", PORT_COMMAND, data));
	}

	if (m_response_index <= m_response_length + 1)
	{
		if (++m_response_index == m_response_length)
		{
			m_status = (m_status & ~ASF_PCB_MASK) | ASF_PCB_END;
		}
		else if (m_response_index == m_response_length + 1)
		{
			// FIXME:
			if (!(m_status & DIR_))
			{
				m_status &= ~HRDY; /* data register no longer ready */
			}

			log_response();

			switch (m_response.command)
			{
			case CMD_MC_E1_RESPONSE:
				m_status |= HRDY; /* data register ready */
				// prepend data length
				m_rx_data_index = -2;
				break;

			case CMD_RECEIVE_PACKET_COMPLETE:
				m_status |= HRDY; /* data register ready */
				m_rx_data_index = 0;
				break;

			case CMD_TRANSMIT_PACKET_COMPLETE:
			case CMD_TRANSMIT_PACKET_18_COMPLETE:
				m_netstat.tot_xmit++;

				if(!send(m_tx_data_buffer.get_data(), m_tx_data_buffer.get_length()))
				{
					// FIXME: failed to send the ethernet packet
					LOG(("read_command_port(): failed to send ethernet packet"));
				}

				if (tx_data != NULL && //
					(*tx_data)(this, m_tx_data_buffer.get_data(), m_tx_data_buffer.get_length()) == 0)
				{
					// FIXME: failed to transmit the ethernet packet
					LOG(("read_command_port(): failed to transmit ethernet packet"));
				}

				m_tx_data_buffer.reset();
				if (m_command_buffer[0] != CMD_MC_F9)
				{
//                  set_command_pending(0);
					m_wait_for_ack = 1;
				}
				break;

			case CMD_DOWNLOAD_PROGRAM_RESPONSE:
				m_program_buffer.reset();
//              set_command_pending(0);
				m_wait_for_ack = 1;
				break;

			default:
//              set_command_pending(0);
				m_wait_for_ack = 1;
				break;
			}
		}
	}
	return data;
}