Important changes to repositories hosted on mbed.com
Mbed hosted mercurial repositories are deprecated and are due to be permanently deleted in July 2026.
To keep a copy of this software download the repository Zip archive or clone locally using Mercurial.
It is also possible to export all your personal repositories from the account settings page.
Dependents: oldheating gps motorhome heating
tcp/tcb.c@167:3ba4e3c49631, 2020-04-02 (annotated)
- Committer:
- andrewboyson
- Date:
- Thu Apr 02 19:08:25 2020 +0000
- Revision:
- 167:3ba4e3c49631
- Parent:
- 164:84b20bcd0941
- Child:
- 168:59d286f933a0
Modified resolution cache ajaxs to include the index
Who changed what in which revision?
| User | Revision | Line number | New contents of line |
|---|---|---|---|
| andrewboyson | 61:aad055f1b0d1 | 1 | #include <stdint.h> |
| andrewboyson | 61:aad055f1b0d1 | 2 | |
| andrewboyson | 161:89609cf070b4 | 3 | #include "log.h" |
| andrewboyson | 161:89609cf070b4 | 4 | #include "tcp.h" |
| andrewboyson | 161:89609cf070b4 | 5 | #include "tcb.h" |
| andrewboyson | 161:89609cf070b4 | 6 | #include "http.h" |
| andrewboyson | 161:89609cf070b4 | 7 | #include "mstimer.h" |
| andrewboyson | 52:fbc5a46b5e16 | 8 | |
| andrewboyson | 164:84b20bcd0941 | 9 | #define TCB_COUNT 40 |
| andrewboyson | 10:f0854784e960 | 10 | |
| andrewboyson | 10:f0854784e960 | 11 | struct tcb tcbs[TCB_COUNT]; |
| andrewboyson | 10:f0854784e960 | 12 | |
| andrewboyson | 10:f0854784e960 | 13 | uint32_t TcbGetIsn() |
| andrewboyson | 10:f0854784e960 | 14 | { |
| andrewboyson | 10:f0854784e960 | 15 | static uint32_t isn = 0; |
| andrewboyson | 10:f0854784e960 | 16 | isn += 100000; //Gives each tcb 100,000 packets and won't repeat before 42,940 tcbs. |
| andrewboyson | 10:f0854784e960 | 17 | return isn; |
| andrewboyson | 10:f0854784e960 | 18 | } |
| andrewboyson | 80:4ef1500fca1d | 19 | struct tcb* TcbGetExisting(int ipType, int remArIndex, int locIpScope, uint16_t remPort, uint16_t locPort) |
| andrewboyson | 10:f0854784e960 | 20 | { |
| andrewboyson | 10:f0854784e960 | 21 | for (int i = 0; i < TCB_COUNT; i++) |
| andrewboyson | 10:f0854784e960 | 22 | { |
| andrewboyson | 10:f0854784e960 | 23 | struct tcb* pTcb = tcbs + i; |
| andrewboyson | 78:9d8fc88df405 | 24 | if (pTcb->state && |
| andrewboyson | 78:9d8fc88df405 | 25 | pTcb->ipType == ipType && |
| andrewboyson | 78:9d8fc88df405 | 26 | pTcb->remArIndex == remArIndex && |
| andrewboyson | 80:4ef1500fca1d | 27 | pTcb->locIpScope == locIpScope && |
| andrewboyson | 80:4ef1500fca1d | 28 | pTcb->remPort == remPort && |
| andrewboyson | 80:4ef1500fca1d | 29 | pTcb->locPort == locPort) return pTcb; |
| andrewboyson | 10:f0854784e960 | 30 | } |
| andrewboyson | 10:f0854784e960 | 31 | return NULL; |
| andrewboyson | 10:f0854784e960 | 32 | } |
| andrewboyson | 10:f0854784e960 | 33 | struct tcb* TcbGetEmpty() |
| andrewboyson | 10:f0854784e960 | 34 | { |
| andrewboyson | 10:f0854784e960 | 35 | for (int i = 0; i < TCB_COUNT; i++) |
| andrewboyson | 10:f0854784e960 | 36 | { |
| andrewboyson | 10:f0854784e960 | 37 | struct tcb* pTcb = tcbs + i; |
| andrewboyson | 57:e0fb648acf48 | 38 | if (pTcb->state == TCB_EMPTY) return pTcb; |
| andrewboyson | 10:f0854784e960 | 39 | } |
| andrewboyson | 10:f0854784e960 | 40 | return NULL; |
| andrewboyson | 10:f0854784e960 | 41 | } |
| andrewboyson | 83:08c983006a6e | 42 | struct tcb* TcbGetNext(struct tcb* pTcb) |
| andrewboyson | 74:c3756bfa960e | 43 | { |
| andrewboyson | 83:08c983006a6e | 44 | if (!pTcb) return tcbs; //Initialise if passed NULL |
| andrewboyson | 83:08c983006a6e | 45 | ++pTcb; //Increment |
| andrewboyson | 83:08c983006a6e | 46 | if (pTcb < tcbs + TCB_COUNT) return pTcb; |
| andrewboyson | 83:08c983006a6e | 47 | else return tcbs; |
| andrewboyson | 83:08c983006a6e | 48 | |
| andrewboyson | 74:c3756bfa960e | 49 | } |
| andrewboyson | 161:89609cf070b4 | 50 | void TcbSendAjax() |
| andrewboyson | 161:89609cf070b4 | 51 | { |
| andrewboyson | 161:89609cf070b4 | 52 | for (int i = 0; i < TCB_COUNT; i++) |
| andrewboyson | 161:89609cf070b4 | 53 | { |
| andrewboyson | 161:89609cf070b4 | 54 | struct tcb* pTcb = tcbs + i; |
| andrewboyson | 161:89609cf070b4 | 55 | if (pTcb->state) |
| andrewboyson | 161:89609cf070b4 | 56 | { |
| andrewboyson | 162:fe50a1dcd043 | 57 | HttpAddByteAsHex (pTcb->state); HttpAddChar('\t'); |
| andrewboyson | 161:89609cf070b4 | 58 | HttpAddInt32AsHex(MsTimerCount - pTcb->timeLastRcvd); HttpAddChar('\t'); |
| andrewboyson | 161:89609cf070b4 | 59 | HttpAddInt16AsHex(pTcb->ipType); HttpAddChar('\t'); |
| andrewboyson | 161:89609cf070b4 | 60 | HttpAddInt32AsHex(pTcb->remArIndex); HttpAddChar('\t'); |
| andrewboyson | 162:fe50a1dcd043 | 61 | HttpAddInt16AsHex(pTcb->locPort); HttpAddChar('\t'); |
| andrewboyson | 162:fe50a1dcd043 | 62 | HttpAddInt16AsHex(pTcb->remPort); HttpAddChar('\t'); |
| andrewboyson | 162:fe50a1dcd043 | 63 | HttpAddInt32AsHex(pTcb->bytesRcvdFromRem); HttpAddChar('\t'); |
| andrewboyson | 164:84b20bcd0941 | 64 | HttpAddInt32AsHex(pTcb->bytesSentToRem); HttpAddChar('\n'); |
| andrewboyson | 161:89609cf070b4 | 65 | } |
| andrewboyson | 161:89609cf070b4 | 66 | } |
| andrewboyson | 161:89609cf070b4 | 67 | } |
| andrewboyson | 161:89609cf070b4 | 68 | |
| andrewboyson | 156:be12b8fd5b21 | 69 | int TcbGetId(struct tcb* pTcb) //0 means none |
| andrewboyson | 156:be12b8fd5b21 | 70 | { |
| andrewboyson | 156:be12b8fd5b21 | 71 | return pTcb - tcbs + 1; |
| andrewboyson | 156:be12b8fd5b21 | 72 | } |
| andrewboyson | 10:f0854784e960 | 73 | void TcbInit() |
| andrewboyson | 10:f0854784e960 | 74 | { |
| andrewboyson | 57:e0fb648acf48 | 75 | for (int i = 0; i < TCB_COUNT; i++) tcbs[i].state = TCB_EMPTY; |
| andrewboyson | 52:fbc5a46b5e16 | 76 | } |