---
# System prepended metadata

title: Regular Meeting (2022.4.18)
tags: [Regular Meeting, DeWei]

---

# Regular Meeting (2022.4.18)

* About doc for VME downloader.
* Enhance SW code: 
  * [Jserv-你所不知道的C語言-goto](https://hackmd.io/@sysprog/c-prog/%2Fs%2FB1e2AUZeM)
    * [Ref](https://hackmd.io/@xB7TVSr_T0mpDKOBcyhI4Q/rJtQx8DFm?type=view)
    * 下水道風格(**Sewer style**)
  * [Jserv](http://wiki.csie.ncku.edu.tw/User/jserv)


Original:
``` C
if (sread(fd, cmd, 2) != 1)
			return 1;

		if (memcmp(cmd, "ge", 2) == 0) {
			if (sread(fd, cmd, 6) != 1)
				return 1;
			memcpy(result, xvcInfo, strlen(xvcInfo));
			if (write(fd, result, strlen(xvcInfo)) != strlen(xvcInfo)) {
				perror("write");
				return 1;
			}
			if (verbose) {
				printf("%u : Received command: 'getinfo'\n", (int)time(NULL));
				printf("\t Replied with %s\n", xvcInfo);
			}
			break;
		} else if (memcmp(cmd, "se", 2) == 0) {
			if (sread(fd, cmd, 9) != 1)
				return 1;
			memcpy(result, cmd + 5, 4);
			if (write(fd, result, 4) != 4) {
				perror("write");
				return 1;
			}
			if (verbose) {
				printf("%u : Received command: 'settck'\n", (int)time(NULL));
				printf("\t Replied with '%.*s'\n\n", 4, cmd + 5);
			}
			break;
		} else if (memcmp(cmd, "sh", 2) == 0) {
			if (sread(fd, cmd, 4) != 1)
				return 1;
			if (verbose) {
				printf("%u : Received command: 'shift'\n", (int)time(NULL));
			}
		} else {

			fprintf(stderr, "invalid cmd '%s'\n", cmd);
			return 1;
		}

```

Modified:

``` C

    if (!StreamRead(eth_fd, cmd, 2) )
      goto out;

    /* Read and judge command */
    if (memcmp(cmd, "ge", 2) == (int) 0 ) {
      jtag_eth_err = 1;
      if (!StreamRead(eth_fd, cmd, 6) ) 
        goto out;
      memcpy(result, kXVCInfo, strlen(kXVCInfo) );
      if ( write(eth_fd, result, strlen(kXVCInfo)) != strlen(kXVCInfo) ) 
        goto err;
      DEBUG_MSG("Received command getXVCInfo, Replied with:");
      DEBUG_MSG(kXVCInfo);
      break;
    } else if (memcmp(cmd, "se", 2) == (int) 0) {
      jtag_eth_err = 2;
      if (!StreamRead(eth_fd, cmd, 9) ) 
        goto out;;
      memcpy(result, cmd+5, 4);
      if (write(eth_fd, result, 4) != (int) 4) 
        goto err;
      DEBUG_MSG("Received command: setTCK, Replied with");
      DEBUG_MSG(cmd+5);
      break;
    } else if (memcmp(cmd, "sh", 2) == (int) 0) {
      if (!StreamRead(eth_fd, cmd, 4) ) 
        goto out;
    } else {
      jtag_eth_err = 3;
      goto err;
    }
    
err:
  switch(jtag_eth_err) {
    case 1: ERROR_MSG("Failed to write XVCInfo");
    case 2: ERROR_MSG("Failed to write setSCK");
    case 3: ERROR_MSG("Invaild cmd");
  }
  return false;

out:
  return true;
    
    
```

###### tags: `Regular Meeting` `DeWei`