Forum: Mikrocontroller und Digitale Elektronik lwip raw tcp_write() buffer loop


von Pascal H. (_pascal_)


Lesenswert?

Hallo,

ich versuche gerade mit lwip raw eine einfache verbindung mit telnet 
aufzubauen und ein paar commands zu implementieren.

lwip funktioniert soweit, also ein ping ist moeglich und mit telnet kann 
ich mich auch connecten.

jetzt habe ich aber ein problem mit tcp_write(). Ich weis dass diese 
funktion das senden nicht initiiert sondern nur die send daten anhaengt. 
Mit tcp_output() sollte ich dann aber in der lage sein das Senden zu 
erzwingen egal ob noch patz in den tx buffern ist. Leider funktioniert 
das bei mir nicht :(

hier erst mal eine funktion welche funktioniert:
1
void openCommandCallback(struct tcp_pcb *pcb, const char *cmd, const char *args) {
2
3
  char idx;
4
  char write_buff[150];
5
  char line_buff[50];
6
  char tmp_buff[16];
7
  ip_addr_t remote;
8
  u16_t port;
9
10
  strcpy(write_buff, "Currently opened connections:\r\n\n");
11
12
  int open = 0;
13
  for(int i = 0; i < MAX_OPEN_CON; i++) {
14
15
    if(open_pcbs[i] != NULL) {
16
17
      memset(line_buff, 0, 50);
18
      fillSpace(line_buff, 10);
19
20
      itoa(i + 1, tmp_buff, 10);
21
      strcpy(line_buff, "[ ");
22
      strcat(line_buff, tmp_buff);
23
      strcat(line_buff, " ] ");
24
25
      ipaddr_ntoa_r((const ip_addr_t *) &open_pcbs[i]->remote_ip, tmp_buff, 16);
26
27
      strcat(line_buff, tmp_buff);
28
      strcat(line_buff, ":");
29
30
      itoa(open_pcbs[i]->remote_port, tmp_buff, 10);
31
      strcat(line_buff, tmp_buff);
32
33
      strcat(line_buff, "\r\n");
34
35
      strcat(write_buff, line_buff);
36
37
      open++;
38
39
    }
40
  }
41
42
  strcat(write_buff, "\r\n");
43
44
  tcp_write(pcb, write_buff, strlen(write_buff), TCP_WRITE_FLAG_COPY);
45
  tcp_output(pcb);
46
47
}

urspruenglich hat das auch nicht funktioniert, bis ich mir den buffer 
erst vollstaendig zusammenbaue und dann sende.

Der folgende help command funktioniert nicht:
1
void helpCommandCallback(struct tcp_pcb *pcb, const char *cmd, const char *args) {
2
3
  err_t e = tcp_write(pcb, "\r\nFollowing commands are available:\r\n\n", 38, TCP_WRITE_FLAG_COPY);
4
5
  char tmp_b[10];
6
  itoa(tcp_sndbuf(pcb), tmp_b, 10);
7
  DEBUGSTR("LEFT: ");
8
  DEBUGSTR(tmp_b);
9
  DEBUGSTR("\r\n");
10
11
  Command_List_t *listItem = commands;
12
  while(listItem != NULL) {
13
14
    char buffer[100];
15
    Command_t *cmd = listItem->cmd;
16
17
    memset(buffer, 0, 100);
18
19
    fillSpace(buffer, 10);
20
    strcat(buffer, cmd->cmd);
21
    fillSpace(buffer, 25);
22
    strcat(buffer, cmd->help);
23
    strcat(buffer, "\r\n");
24
25
    err_t e = tcp_write(pcb, buffer, strlen(buffer), TCP_WRITE_FLAG_COPY);
26
27
    listItem = listItem->next;
28
29
    char tmp_b[10];
30
    itoa(tcp_sndbuf(pcb), tmp_b, 10);
31
    DEBUGSTR("LEFT: ");
32
    DEBUGSTR(tmp_b);
33
    DEBUGSTR("\r\n");
34
35
  }
36
37
  e = tcp_write(pcb, "\r\n", 2, TCP_WRITE_FLAG_COPY);
38
39
  itoa(tcp_sndbuf(pcb), tmp_b, 10);
40
  DEBUGSTR("LEFT: ");
41
  DEBUGSTR(tmp_b);
42
  DEBUGSTR("\r\n");
43
44
  e = tcp_output(pcb);
45
46
  itoa(tcp_sndbuf(pcb), tmp_b, 10);
47
  DEBUGSTR("LEFT: ");
48
  DEBUGSTR(tmp_b);
49
  DEBUGSTR("\r\n");
50
51
  itoa(e, tmp_b, 10);
52
  DEBUGSTR("TCP_OUT ERROR: ");
53
  DEBUGSTR(tmp_b);
54
  DEBUGSTR("\r\n");
55
56
}

ich habe immer genug platz, tcp_sndbuf() sag dass immer noch platz ist. 
Leider seh ich in telnet aber keine ausgabe.

Hier die DEBUGSTR vom uart
1
LEFT: 2882
2
LEFT: 2833
3
LEFT: 2782
4
LEFT: 2718
5
LEFT: 2649
6
LEFT: 2598
7
LEFT: 2549
8
LEFT: 2547
9
LEFT: 2547
10
TCP_OUT ERROR: 0

meiner meinung nach ist alles ok.

Hat jemand eine idee?

Vielen Dank

Bitte melde dich an um einen Beitrag zu schreiben. Anmeldung ist kostenlos und dauert nur eine Minute.
Bestehender Account
Schon ein Account bei Google/GoogleMail? Keine Anmeldung erforderlich!
Mit Google-Account einloggen
Noch kein Account? Hier anmelden.