/*主动上报设备状态,需要用户自己实现*/ int ICACHE_FLASH_ATTR alink_device_post_raw_data(void) { /* do your job here */ int len = 8, ret = 0; char rawdata[8] = { 0 }; if (device_status_change) { wsf_deb("[%s][%d| Available memory:%d.\n", __FILE__, __LINE__, system_get_free_heap_size()); delta_time = system_get_time() - delta_time; wsf_deb("%s %d \n delta_time = %d ", __FUNCTION__, __LINE__, delta_time / 1000); get_device_status(rawdata, len); ret = alink_post_device_rawdata(rawdata, len); device_status_change = 0; if (ret) { wsf_err("post failed!\n"); } else { wsf_deb("dev post raw data success!\n"); } } /* do your job end */ return ret; }
/* * The main terminal loop: * - If there are characters received send them * to the screen via the appropriate translate function. */ int do_terminal(void) { char buf[128]; int buf_offset = 0; int c; int x; int blen; int zauto = 0; static const char zsig[] = "**\030B00"; int zpos = 0; const char *s; dirflush = 0; WIN *error_on_open_window = NULL; dirty_goto: /* Show off or online time */ update_status_time(); /* If the status line was shown temporarily, delete it again. */ if (tempst) { tempst = 0; mc_wclose(st, 1); st = NULL; } /* Auto Zmodem? */ if (P_PAUTO[0] >= 'A' && P_PAUTO[0] <= 'Z') zauto = P_PAUTO[0]; /* Set the terminal modes */ setcbreak(2); /* Raw, no echo */ keyboard(KSTART, 0); /* Main loop */ while (1) { /* See if window size changed */ if (size_changed) { size_changed = 0; wrapln = us->wrap; /* I got the resize code going again! Yeah! */ mc_wclose(us, 0); us = NULL; if (st) mc_wclose(st, 0); st = NULL; mc_wclose(stdwin, 0); if (win_init(tfcolor, tbcolor, XA_NORMAL) < 0) leave(_("Could not re-initialize window system.")); /* Set the terminal modes */ setcbreak(2); /* Raw, no echo */ init_emul(terminal, 0); } /* Update the timer. */ timer_update(); /* check if device is ok, if not, try to open it */ if (!get_device_status(portfd_connected)) { /* Ok, it's gone, most probably someone unplugged the USB-serial, we * need to free the FD so that a replug can get the same device * filename, open it again and be back */ int reopen = portfd == -1; close(portfd); lockfile_remove(); portfd = -1; if (open_term(reopen, reopen, 1) < 0) { if (!error_on_open_window) error_on_open_window = mc_tell(_("Cannot open %s!"), dial_tty); } else { if (error_on_open_window) { mc_wclose(error_on_open_window, 1); error_on_open_window = NULL; } } } /* Check for I/O or timer. */ x = check_io(portfd_connected, 0, 1000, buf + buf_offset, sizeof(buf) - buf_offset, &blen); blen += buf_offset; buf_offset = 0; /* Data from the modem to the screen. */ if ((x & 1) == 1) { char obuf[sizeof(buf)]; char *ptr; if (using_iconv()) { char *otmp = obuf; size_t output_len = sizeof(obuf); size_t input_len = blen; ptr = buf; do_iconv(&ptr, &input_len, &otmp, &output_len); // something happened at all? if (output_len < sizeof(obuf)) { if (input_len) { // something remained, we need to adapt buf accordingly memmove(buf, ptr, input_len); buf_offset = input_len; } blen = sizeof(obuf) - output_len; ptr = obuf; } else ptr = buf; } else { ptr = buf; } while (blen-- > 0) { /* Auto zmodem detect */ if (zauto) { if (zsig[zpos] == *ptr) zpos++; else zpos = 0; } if (P_PARITY[0] == 'M' || P_PARITY[0] == 'S') *ptr &= 0x7f; if (display_hex) { unsigned char c = *ptr++; unsigned char u = c >> 4; c &= 0xf; vt_out(u > 9 ? 'a' + (u - 10) : '0' + u); vt_out(c > 9 ? 'a' + (c - 10) : '0' + c); vt_out(' '); } else vt_out(*ptr++); if (zauto && zsig[zpos] == 0) { dirflush = 1; keyboard(KSTOP, 0); updown('D', zauto - 'A'); dirflush = 0; zpos = 0; blen = 0; goto dirty_goto; } } mc_wflush(); }
static unsigned int handle_standard_requests() { switch(usb_setup_buffer.bmRequestType) { case 0x80: /* standard device IN requests */ switch(usb_setup_buffer.bRequest) { case GET_DESCRIPTOR: switch (HIGH_BYTE(usb_setup_buffer.wValue)) { case DEVICE: get_device_descriptor(); break; case CONFIGURATION: get_configuration_descriptor(); break; case STRING: get_string_descriptor(); break; default: /* Unknown descriptor */ return 0; } break; case GET_CONFIGURATION: get_configuration(); break; case GET_STATUS: get_device_status(); break; case GET_INTERFACE: get_interface(); break; default: return 0; } break; case 0x81: /* standard interface IN requests */ switch(usb_setup_buffer.bRequest) { case GET_STATUS: get_interface_status(); break; #ifdef HID_ENABLED case GET_DESCRIPTOR: switch (USB_setup_buffer.wValue.byte.high) { case REPORT: get_report_descriptor(); break; } break; #endif default: return 0; } break; case 0x82: /* standard endpoint IN requests */ switch(usb_setup_buffer.bRequest) { case GET_STATUS: get_endpoint_status(); break; default: return 0; } break; case 0x00: /* standard device OUT requests */ switch(usb_setup_buffer.bRequest) { case SET_ADDRESS: PRINTF("Address: %d\r\n", LOW_BYTE(usb_setup_buffer.wValue)); usb_flags |= USB_FLAG_ADDRESS_PENDING; /* The actual setting of the address is done when the status packet is sent. */ usb_send_ctrl_status(); break; #if SETABLE_STRING_DESCRIPTORS > 0 case SET_DESCRIPTOR: if (usb_setup_buffer.wValue.byte.high == STRING) { set_string_descriptor(); } else { return 0; } break; #endif case SET_CONFIGURATION: if (set_configuration()) { #if 0 config_msg.data.config = LOW_BYTE(usb_setup_buffer.wValue); notify_user(&config_msg); #endif } break; default: return 0; } break; case 0x01: /* standard interface OUT requests */ switch(usb_setup_buffer.bRequest) { case SET_INTERFACE: /* Change interface here if we support more than one */ usb_send_ctrl_status(); break; default: return 0; } break; case 0x02: /* standard endpoint OUT requests */ switch(usb_setup_buffer.bRequest) { case SET_FEATURE: case CLEAR_FEATURE: if (usb_setup_buffer.wValue == ENDPOINT_HALT_FEATURE) { usb_arch_halt_endpoint(usb_setup_buffer.wIndex, usb_setup_buffer.bRequest== SET_FEATURE); usb_send_ctrl_status(); } else { usb_error_stall(); } break; default: return 0; } break; #ifdef HID_ENABLED case 0xa1: /* class specific interface IN request*/ switch(USB_setup_buffer.bRequest) { case GET_HID_REPORT: PRINTF("Get report\r\n"); send_ctrl_response((code u_int8_t*)&zero_byte, sizeof(zero_byte)); break; case GET_HID_IDLE: PRINTF("Get idle\r\n"); send_ctrl_response((code u_int8_t*)&zero_byte, sizeof(zero_byte)); break; default: return 0; } break; case 0x21: /* class specific interface OUT request*/ switch(USB_setup_buffer.bRequest) { case SET_HID_IDLE: PRINTF("Set idle\r\n"); send_ctrl_status(); break; default: return 0; } break; #endif default: return 0; } return 1; }