int _write(int file, char *ptr, int len) { if (len == 0) return 0; if (file == 0 || file == 1) { usbSend(ptr, len); return len; } else if (file < 10) { unsigned int port = UART_FD[file]; if (port) { int totalSent = 0; while (len > 0) { int sent = sendUART(port, ptr, len); len -= sent; ptr += sent; totalSent += sent; } return totalSent; } else { return -1; } } else { int fd = file-10; if (fd < fatFilesOpen) { unsigned int res; if (fatFiles[fd].append) { _lseek(file, 0, SEEK_END); } FRESULT rr = f_write(&fatFiles[fd].fil, ptr, len, &res); if (rr) { fiprintf(stderr, "Failed to write FAT file %d (bytes: %d): %d\n\r", fd, len, rr); errno = EINVAL; return -1; } else { errno = 0; return res; } } } errno = EINVAL; return -1; }
EzspStatus serialSendCommand() { EzspStatus status; if (!checkConnection()) { ezspTraceEzspVerbose("serialSendCommand(): EZSP_NOT_CONNECTED"); return EZSP_NOT_CONNECTED; } ezspTraceEzspFrameId("send command", ezspFrameContents); status = usbSend(ezspFrameLength, ezspFrameContents); if (status != EZSP_SUCCESS) { ezspTraceEzspVerbose("serialSendCommand(): usbSend(): 0x%x", status); return status; } waitingForResponse = true; ezspTraceEzspVerbose("serialSendCommand(): ID=0x%x Seq=0x%x", ezspFrameContents[EZSP_FRAME_ID_INDEX], ezspFrameContents[EZSP_SEQUENCE_INDEX]); waitStartTime = halCommonGetInt16uMillisecondTick(); return status; }
int main(int argc, char **argv) { usb_dev_handle *handle = NULL; int j; char string[64]; usb_init(); if (argc < 2) { usage(); } if (usbOpenDevice(&handle, USBDEV_SHARED_VENDOR, "www.sri-dev.de", USBDEV_SHARED_PRODUCT, "USB-Dingens") != 0) { fprintf(stderr, "Could not find USB device \"USB-Dingens\" with vid=0x%x pid=0x%x\n", USBDEV_SHARED_VENDOR, USBDEV_SHARED_PRODUCT); exit(1); } usbSend(handle, DONE); if (strcmp(argv[1], "clear") == 0) { usbSend(handle, CLEAR); exit(0); } else if (strcmp(argv[1], "helo") == 0) { usbSend(handle, READY); exit(0); } else if (argc == 2) { fprintf(stderr, "Not enough arguments"); usage(); } strlcpy(string, argv[2], 64); if (strcmp(argv[1], "symbol") == 0) { usbSend(handle, SYMBOL); if (strcmp(string, "email=active") == 0) { usbSend(handle, EMAIL_A); } else if (strcmp(string, "email=inactive") == 0) { usbSend(handle, EMAIL_I); } else if (strcmp(string, "icq=active") == 0) { usbSend(handle, ICQ_A); } else if (strcmp(string, "icq=inactive") == 0) { usbSend(handle, ICQ_I); } else { fprintf(stderr, "unknown: %s\n", string); usbSend(handle, DONE); exit(1); } usbSend(handle, DONE); exit(0); } if (strcmp(argv[1], "line0") == 0) { usbSend(handle, SETLINE); usbSend(handle, LINE0); } else if (strcmp(argv[1], "line1") == 0) { usbSend(handle, SETLINE); usbSend(handle, LINE1); } else if (strcmp(argv[1], "line2") == 0) { usbSend(handle, SETLINE); usbSend(handle, LINE2); } else if (strcmp(argv[1], "line3") == 0) { usbSend(handle, SETLINE); usbSend(handle, LINE3); } else if (strcmp(argv[1], "line4") == 0) { usbSend(handle, SETLINE); usbSend(handle, LINE4); } else if (strcmp(argv[1], "line5") == 0) { usbSend(handle, SETLINE); usbSend(handle, LINE5); } else if (strcmp(argv[1], "line6") == 0) { usbSend(handle, SETLINE); usbSend(handle, LINE6); } else if (strcmp(argv[1], "line7") == 0) { usbSend(handle, SETLINE); usbSend(handle, LINE7); } else { fprintf(stderr, "unknown: %s\n", argv[1]); usage(); } usbSend(handle, DONE); usbSend(handle, STRING); for(j=0; j < strlen(string); j++){ usbSend(handle, transform(string[j])); } usbSend(handle, DONE); return 0; }