/* Checks for delays in communication from the Gumstix to Robostix 1 as well as delays in communication from Robostix 2 to Robostix 1 */ void check_receive_delay( ) { /* check if new motor signals have been received */ if( !flag_new_signals ) { /* DO NOT modify motor signals in shut-down mode! */ if( !flag_shut_down ) { if( motor_signals.front > 0 || motor_signals.right > 0 || motor_signals.rear > 0 || motor_signals.left > 0 ) { /* we're possibly airborne, so reduce motor signals to force descending */ motor_signals.front -= MOTOR_DEC; motor_signals.right -= MOTOR_DEC; motor_signals.rear -= MOTOR_DEC; motor_signals.left -= MOTOR_DEC; } else { /* we're possibly grounded, so keep motor signals set to the minimum */ motor_signals.front = 0; motor_signals.right = 0; motor_signals.rear = 0; motor_signals.left = 0; } /* set new motor signals */ pwm_set_signals( &motor_signals ); } /* reset Gumstix-to-Robostix-1 interface */ serial_reset( ); LED_ON( YELLOW ); /////////////////////////////////////////////////////////////////// enable_sensors( 0 ); /////////////////////////////////////////////////////////////////// } /* check if new sensor data have been received */ if( !flag_new_sensors ) { /* reset Robostix-2-to-Robostix-1 interface */ //parallel_reset( ); LED_ON( BLUE ); } /* update sensor status */ //enable_sensors( flag_new_signals ); flag_check_delay = 0; flag_new_signals = 0; flag_new_sensors = 0; }
int serial_int(void) { if(-1==sem_init(&s_sem_serial, 0, 1)){ DEBUG("s_sem_insert_insts init failed\n"); return -1; } g_serialfd = -1; return serial_reset(); }
/* 兼容这样的情况,返回处的开头一段是非法值: 例1、以继电器闭合操作为例 发送:68 20 11 12 21 06 36 68 04 09 56 16 33 33 33 33 44 44 44 81 16 返回:56 7b 16 68 20 11 06 02 41 56 68 81 06 43 c3 33 33 33 33 f9 16 68 20 11 12 21 06 36 68 c5 03 e9 04 56 7b 16 68 20 11 12 21 06 36 68 c5 03 e9 04 56 7b 16 68 20 11 12 21 06 36 68 c5 03 e9 04 56 7b 16 68 20 11 12 21 06 36 68 c5 03 e9 04 56 7b 16 68 20 11 06 00 41 56 68 81 06 43 c3 33 3b 33 33 ff 16 68 20 11 12 21 06 36 68 c5 03 e9 04 56 7b 16 68 20 11 06 00 41 56 68 81 06 43 c3 33 33 33 33 f7 16 68 20 11 12 21 06 36 68 c5 03 e9 04 56 7b 16 68 20 11 12 21 06 36 68 c5 03 e9 04 56 7b 16 68 20 11 12 21 06 36 68 c5 03 e9 04 56 7b 16 68 20 11 12 21 06 36 68 c5 03 e9 04 56 7b 16 68 20 11 12 21 06 36 68 c5 03 e9 04 56 7b 16 68 20 11 12 21 06 36 68 c5 03 e9 04 56 7b 16 68 20 11 12 21 06 36 68 c5 03 e9 04 56 7b 16 68 20 11 12 21 06 36 68 c5 03 e9 04 56 7b 16 68 20 11 实际上有用的是:68 20 11 12 21 06 36 68 c5 03 e9 04 56 7b 16,表示通信错误。 例2、验证插座是否存在 发送:68 20 11 12 21 06 36 68 07 00 77 16 返回:68 99 99 99 99 99 99 68 c5 03 e9 99 99 49 16 68 20 11 12 21 06 36 68 87 06 53 44 45 54 39 69 cf 16 实际上有用的是:68 20 11 12 21 06 36 68 87 06 53 44 45 54 39 69 cf 16 完全正确的是: 68 20 11 12 21 06 36 68 87 06 33 33 33 33 33 33 cf 16 例3、继电器闭合 发送:68 20 11 12 21 09 51 68 04 09 56 16 33 33 33 33 44 44 44 9f 16 返回:68 20 11 12 21 09 51 68 c5 03 e9 04 56 99 16 68 20 11 12 21 09 51 68 84 02 89 89 第一段说明通信失败,第二段是执行成功。这有点儿操蛋,怎样才能获取到正确的命令返回? 还需要解决一个问题:如果插座连续通信失败怎么办?应该关闭串口,重启smarthome应用。 */ static int serial_access_son(unsigned char *buf, unsigned int buf_len, unsigned int buf_size) { int has_read_len = -1; int ret = -1; if(NULL==buf || buf_len<SERIAL_CMD_SEND_LEN_MIN || buf_len>SERIAL_CMD_SEND_LEN_MAX){ DEBUG("invalid serial cmd, buf_len=%u\n", buf_len); ret = -1; } else{ sem_wait(&s_sem_serial); usleep(20000); // 期望合法指令识别:68 a0 a1 a2 a3 a4 a5 68 unsigned char distinguish_cmd[32]; memset(distinguish_cmd, 0, sizeof(distinguish_cmd)); memcpy(distinguish_cmd, buf, 8); //识别段: 68 20 11 12 21 06 36 68 if(0!=sendto_serial(buf, buf_len)){ DEBUG("send to serial failed\n"); ret = -1; } else{ memset(buf, 0, buf_size); usleep(250000); unsigned char serial_response_buf[128000]; unsigned int start_pos = 0; memset(serial_response_buf,0,sizeof(serial_response_buf)); has_read_len = recvfrom_serial(serial_response_buf, &start_pos, sizeof(serial_response_buf), distinguish_cmd); if(has_read_len>10){ memset(buf,0,buf_size); memcpy(buf,serial_response_buf+start_pos,buf_size); ret = has_read_len; } else{ DEBUG("has read len: %d, perhaps failed\n", has_read_len); ret = -1; } } sem_post(&s_sem_serial); if(s_serial_failed_count>2) serial_reset(); } return ret; }
void pc_reset() { cpu_set(); resetx86(); mem_updatecache(); //timer_reset(); dma_reset(); fdc_reset(); pic_reset(); pit_reset(); serial_reset(); setpitclock(models[model].cpu[cpu_manufacturer].cpus[cpu].rspeed); // sb_reset(); ali1429_reset(); // video_init(); }
void main_reset() { m6502_reset(); crtc_reset(); video_reset(); sysvia_reset(); uservia_reset(); serial_reset(); acia_reset(&sysacia); wd1770_reset(); i8271_reset(); scsi_reset(); vdfs_reset(); sid_reset(); music4000_reset(); music5000_reset(); sn_init(); if (curtube != -1) tubes[curtube].reset(); else tube_exec = NULL; tube_reset(); memset(ram, 0, 64 * 1024); }
static int SerialOpen(const char *name, const char *arg) { const char *port_name = name; #ifdef DEBUG printf("SerialOpen: name %s arg %s\n", name, arg ? arg : "<NULL>"); #endif #ifdef COMPILING_ON_WINDOWS if (IsOpenSerial()) return -1; #else if (Unix_IsSerialInUse()) return -1; #endif #ifdef COMPILING_ON_WINDOWS if (SerialMatch(name, arg) != adp_ok) return adp_failed; #else port_name = Unix_MatchValidSerialDevice(port_name); # ifdef DEBUG printf("translated port to %s\n", port_name == 0 ? "NULL" : port_name); # endif if (port_name == 0) return adp_failed; #endif user_options_set = FALSE; /* interpret and store the arguments */ if ( arg != NULL ) { unsigned int target_baud_rate; target_baud_rate = (unsigned int)strtoul(arg, NULL, 10); if (target_baud_rate > 0) { #ifdef DEBUG printf( "user selected baud rate %u\n", target_baud_rate ); #endif process_baud_rate( target_baud_rate ); } #ifdef DEBUG else printf( "could not understand baud rate %s\n", arg ); #endif } else if (baud_rate > 0) { /* If the user specified a baud rate on the command line "-b" or via the "set remotebaud" command then try to use that one */ process_baud_rate( baud_rate ); } #ifdef COMPILING_ON_WINDOWS { int port = IsValidDevice(name); if (OpenSerial(port, FALSE) != COM_OK) return -1; } #else if (Unix_OpenSerial(port_name) < 0) return -1; #endif serial_reset(); #if defined(__unix) || defined(__CYGWIN__) Unix_ioctlNonBlocking(); #endif Angel_RxEngineInit(&config, &rxstate); /* * DANGER!: passing in NULL as the packet is ok for now as it is just * IGNOREd but this may well change */ Angel_TxEngineInit(&config, NULL, &wstate.txstate); return 0; }
/** \brief Vitual COM Port reset The function resets the internal states of the port used as the Virtual COM Port. \return 0 Function failed. \return 1 Function succeeded. */ int32_t USBD_CDC_ACM_PortReset (void) { return (serial_reset ()); }