|
|||||||||||
Technical Support On-Line Manuals RL-ARM User's Guide (MDK v4) ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() |
A long reply message requires multiple calls to the function tnet_process_cmd. Each call to this function generates part of the reply message until the entire message is generated and sent. To distinguish between different calls to the function, the argument pvar is used. This argument is a pointer to a variable that is set to 0 on the first call and not altered on each subsequent call to this function. The function's return value, which specifies the number of bytes in the reply message, cannot exceed 1500. Hence the high bits of the function's return value is used to store the flags:
In the following example, the MEAS command is given by the user using the Telnet client. MCB2100> MEAS 100 When a new telnet command is received, the function tnet_process_cmd is called with the argument *pvar set to 0. The command buffer cmd is checked to identify the command. U16 tnet_process_cmd (U8 *cmd, U8 *buf, U16 buflen, U32 *pvar) { switch (MYBUF(pvar)->id) { case 0: /* First call to this function, the value of '*pvar' is 0 */ break; case 1: /* Repeated call, command 'MEAS' measurements display. */ .. /* Request a repeated call, bit 14 is a repeat flag. */ return (len | 0x4000); .. } /* Check if the command 'MEAS' is entered. */ if (tnet_ccmp (cmd, "MEAS") == __TRUE) { MYBUF(pvar)->id = 1; if (len > 5) { /* We must be careful here, because data is overlaid. */ sscanf ((const S8 *)&cmd[5], "%d", &temp); MYBUF(pvar)->nmax = temp; } len = str_copy (buf,(U8 *)meas_header); if (MYBUF(pvar)->nmax) { /* Bit 14 is a repeat flag. */ len |= 0x4000; } return (len); }
When a command is recognized, you can reuse the same command
buffer to store local variables, which might be needed in repeated
calls. During the repeated call to this function, the cmd
buffer is locked and is not altered by the system. You can use it as
temporary storage of variables for the repeated calls. Each Telnet
session has its own buffer of size 96 bytes. You can use only 95
bytes since the last byte is not available. typedef struct { U8 id; U8 nmax; U8 idx; } MY_BUF; #define MYBUF(p) ((MY_BUF *)p) When the call to tnet_process_cmd() is repeated for the same command, the value of a storage variable pointed to by argument pvar is not altered anymore. You can use the value of *pvar to process the command differently. The *pvar buffer now holds the private structure MY_BUF, which is valid for the lifetime of processing the command. When the command processing is finished, this buffer is not used anymore until the next command. U16 tnet_process_cmd (U8 *cmd, U8 *buf, U16 buflen, U32 *pvar) { switch (MYBUF(pvar)->id) { case 0: /* First call to this function, the value of '*pvar' is 0 */ break; case 1: /* Repeated call, command 'MEAS' measurements display. */ while (len < buflen-80) { /* Let's use as much of the buffer as possible. */ /* This will produce less packets and speedup the transfer. */ len += sprintf ((S8 *)(buf+len), "\r\n%4d", MYBUF(pvar)->idx); for (val = 0; val < 8; val++) { len += sprintf ((S8 *)(buf+len), "%7d", AD_in(val)); } if (++MYBUF(pvar)->idx >= MYBUF(pvar)->nmax) { /* OK, we are done. */ return (len); } } /* Request a repeated call, bit 14 is a repeat flag. */ return (len | 0x4000); case 2: /* Repeated call, TCP status display. */ .. } After giving a MEAS command, the Telnet Client screen looks like this:
| ||||||||||
|
Arm’s Privacy Policy has been updated. By continuing to use our site, you consent to Arm’s Privacy Policy. Please review our Privacy Policy to learn more about our collection, use and transfers
of your data.