//Note, the preq needs to be able to set the EN flag
void process_PReq(uintptr_t rx_buffer_address, chanend c_can_open){
  frame * frm = (frame *)rx_buffer_address;

  PReq_t * p = &(frm->pl_frame.preq);

  if(p->RD==0)
    return;

  //read from 0x1600:0
  unsigned char number_of_entries;
  unsigned no_of_bytes;
  co_error_code_t err = co_read(c_can_open, 0x1600, 0, &number_of_entries, &no_of_bytes);
  //TODO check the err

  for(unsigned short subindex=1;subindex<=number_of_entries;subindex++){
    uint16_t rx_index;
    uint8_t rx_subindex;
    uint16_t rx_offset;
    uint16_t rx_length;
    co_read_PDO_entry(c_can_open, 0x1600, subindex, &rx_index, &rx_subindex, &rx_length, &rx_offset);
    uint8_t data[C_DLL_ISOCHR_MAX_PAYL];
    unsigned number_of_bytes = rx_length>>3;
    co_error_code_t e = co_write(c_can_open, rx_index, rx_subindex, p->payload, number_of_bytes);
  }
  //TODO deal with the error flags in much the same way as soa
  //if(error_signalling_data_present)
  //    async_state->EN = 1 - p->EA;
}
Beispiel #2
0
static void main_thread(co_context_t *co, void *user) {
	co_file_t *peer;
	const char *request =
		"GET / HTTP/1.0\r\n"
		"Host: google.com\r\n"
		"Connection: close\r\n"
		"User-Agent: libco/0.1\r\n"
		"\r\n";
	char buf;
	ssize_t rsize;

	printf("connecting...\n");
	peer = co_connect_tcp(co, "google.com", 80);

	if (peer == NULL) {
		printf("connect failed :(\n");
		return;
	}

	printf("connected! sending request...\n");
	co_write(co, peer, request, strlen(request), NULL);
	printf("request sent! reading response, a byte at a time...\n");

	do {
		buf = 0;
		co_read(co, peer, &buf, 1, &rsize);
		putchar(buf);
	} while (rsize);

	printf("end of response. bye!\n");
}
void prepare_PRes(uintptr_t tx_buffer_address, chanend c_can_open){
  unsigned char number_of_entries;
  unsigned no_of_bytes;
  co_error_code_t err = co_read(c_can_open, 0x1a00, 0, &number_of_entries, &no_of_bytes);
  //TODO check the err
  frame * frm = (frame *)tx_buffer_address;

  PRes_t * p = &(frm->pl_frame.pres);

  for(unsigned short subindex=1;subindex<=number_of_entries;subindex++){
    uint16_t rx_index;
    uint8_t rx_subindex;
    uint16_t rx_offset;
    uint16_t rx_length;
    co_read_PDO_entry(c_can_open, 0x1a00, subindex, &rx_index, &rx_subindex, &rx_length, &rx_offset);
    uint8_t data[C_DLL_ISOCHR_MAX_PAYL];
    unsigned number_of_bytes;
    co_error_code_t e = co_read(c_can_open, rx_index, rx_subindex, p->payload, &number_of_bytes);
  }

  p->size = 1;
}
Beispiel #4
0
static void connector_thread(co_context_t *co, void *_conn) {
	co_file_t *peer;
	struct connector *conn = _conn;
	const char *request_fmt =
		"GET / HTTP/1.0\r\n"
		"Host: %s\r\n"
		"User-Agent: libco/0.0\r\n"
		"Accept: */*\r\n"
		"Connection: close\r\n"
		"\r\n";
	char buf[BUFSIZE];
	ssize_t rsize;

	snprintf(buf, BUFSIZE, request_fmt, conn->host);

	printf("%s: connecting to %s\n", conn->name, conn->host);
	peer = co_connect_tcp(co, conn->host, 80);

	if (peer == NULL) {
		printf("%s: connect failed :(\n", conn->name);
		return;
	}

	printf("%s: connected! sending request...\n", conn->name);
	co_write(co, peer, buf, strlen(buf), NULL);
	printf("%s: request sent!\n", conn->name);
	printf("%s: reading response...\n", conn->name);

	do {
		memset(buf, 0, sizeof(buf));
		co_read(co, peer, buf, BUFSIZE, &rsize);
		printf("%s: got %d bytes\n", conn->name, rsize);
	} while (rsize);

	printf("%s: bye!\n", conn->name);

	free(conn);
}