//向线程池中加入任务 int pool_add_worker(void * (*process) (const void *arg), void *arg) { if(pool->cur_queue_size==pool->max_thread_num){ printfs(2,"线程池满!\n"); return 0; } //构造一个新任务 CThread_worker *newworker =(CThread_worker *) malloc (sizeof (CThread_worker)); newworker->process = process; newworker->arg = arg; newworker->next = NULL;//别忘置空 pthread_mutex_lock (&(pool->queue_lock)); //将任务加入到等待队列中 CThread_worker *member = pool->queue_head; if (member != NULL) { while (member->next != NULL) member = member->next; member->next = newworker; }else{ pool->queue_head = newworker; } assert(pool->queue_head != NULL); pool->cur_queue_size++; pthread_mutex_unlock (&(pool->queue_lock)); //好了,等待队列中有任务了,唤醒一个等待线程; //注意如果所有线程都在忙碌,这句没有任何作用 pthread_cond_signal (&(pool->queue_ready)); return 1; }
void *thread_routine(void *arg) { printfs(2,"starting thread 0x%x\n", pthread_self()); while (1) { pthread_mutex_lock (&(pool->queue_lock)); /*如果等待队列为0并且不销毁线程池,则处于阻塞状态; 注意pthread_cond_wait是一个原子操作,等待前会解锁,唤醒后会加锁*/ while (pool->cur_queue_size == 0 && !pool->shutdown) { printfs(2,"thread 0x%x is waiting\n", pthread_self ()); pthread_cond_wait (&(pool->queue_ready), &(pool->queue_lock)); } /*线程池要销毁了*/ if (pool->shutdown) { /*遇到break,continue,return等跳转语句,千万不要忘记先解锁*/ pthread_mutex_unlock (&(pool->queue_lock)); printfs(2,"thread 0x%x will exit\n", pthread_self ()); pthread_exit (NULL); } printfs(2,"thread 0x%x is starting to work\n", pthread_self ()); /*assert是调试的好帮手*/ assert(pool->cur_queue_size != 0); assert(pool->queue_head != NULL); /*等待队列长度减去1,并取出链表中的头元素*/ pool->cur_queue_size--; CThread_worker *worker = pool->queue_head; pool->queue_head = worker->next; pthread_mutex_unlock (&(pool->queue_lock)); /*调用回调函数,执行任务*/ (*(worker->process)) (worker->arg); free (worker); worker = NULL; } /*这一句应该是不可达的*/ pthread_exit(NULL); }
/****************************************************************************** 处理名 : 停止子线程处理 函数名 : ThreadStop() 参数 : 无 返回值 : 无 ******************************************************************************/ void CChannelItem::ThreadStop(){ if ( m_pSocketMonitorThread ) { /* 1. 终止线程中对端口的监控操作,关闭Socket */ m_pSocketMonitor->TerminateProcess(); /* 2. 停止子线程处理 */ m_pSocketMonitorThread->Stop(); printfs(1, "<CChannelItem>Stop channel Thread succeed!"); } }
/****************************************************************************** 处理名 : 停止处理(本机能暂时未使用) 函数名 : Join() 参数 : 无 返回值 : 无 ******************************************************************************/ int CChannelItem::Join(){ if ( m_pSocketMonitorThread ) { /* 1. 等待子线程停止处理 */ m_pSocketMonitorThread->Join(); printfs(1, "<CChannelItem>Join channel Thread complete!"); m_bStarted = false; } return 0; }
/****************************************************************************** 处理名 : 本类的构造处理 函数名 : CChannelItem() 参数 : (I) :pConfigInfo - 频道配置信息 返回值 : 无 ******************************************************************************/ CChannelItem::CChannelItem(int nSocketPort) : m_nSocketPort(nSocketPort){ m_pSocketMonitor = NULL; /* 端口监视器 */ m_pSocketMonitorThread = NULL; /* 端口监视器子线程 */ m_bStarted = false; /* 启动状态标志 */ if(m_nSocketPort > 0) { m_bCanStart = true; /* 可否启动标志 */ } else { m_bCanStart = false; printfs(0, "<CChannelItem>Socket port error! Socket port[%d]", m_nSocketPort); } }
/****************************************************************************** 处理名 : 启动处理 函数名 : Start() 参数 : 无 返回值 : 无 ******************************************************************************/ int CChannelItem::Start(){ printfs(1, "<CChannelItem>Start command received!"); if(m_bStarted) { return 0; } /* 生成各个子线程的处理类 */ if(CreateProcess() < 0) { m_bCanStart = false; return -1; } /* 生成各个子线程 */ ThreadCreate(); /* 启动各个子线程 */ ThreadStart(); m_bStarted = true; return 0; }
/****************************************************************************** 处理名 : 创建处理类 函数名 : CreateProcess() 参数 : 无 返回值 : = 0 : 创建处理类成功 <> 0 : 创建处理类失败 ******************************************************************************/ int CChannelItem::CreateProcess() { int nRet = 0; CProcessFactory* pFactoryInstance = NULL; /* 对象实例工厂 */ pFactoryInstance = CProcessFactory::GetInstance(); /* 创建端口监控处理类 */ if (!m_pSocketMonitor){ m_pSocketMonitor = (CSocketMonitorProcess*)(pFactoryInstance->GetProcessModule(PRC_TYPE_SOCKET_MONITOR)); printfs(1, "<CChannelItem>Process create succeed!"); } if (m_pSocketMonitor == NULL){ nRet = -1; } /* 向端口监控处理类追加频道配置信息 */ m_pSocketMonitor->SetChannelPort(m_nSocketPort); printf("创建处理类 %d\n", nRet); return nRet; }
void _main(void) { LED_GPIO_Configuration(); USART_Configuration(USART1); #ifdef __DEBUG__ printfs("this is in init fuction.\r\n"); printfs("usart1's initation is compelete.\r\n"); printfs("three lights can bright.\r\n"); #endif systick_init(); #ifdef __DEBUG__ printfs("system ticket clock's initation is compelete.\r\n"); printfs("\r\n"); printfs("now into the tft's initation.\r\n"); #endif LCD_Init(); set_orgin(120, 120); }
/****************************************************************************** 处理名 : 业务处理 函数名 : Do() 参数 : 无 返回值 : 无 ******************************************************************************/ void CWDSStationRegisterProcess::Do(){ printfs(1,"<CWDSStationRegisterProcess::Do()> WDSStationRegisterProcess start!"); int nStatus = 0; int nRet = 0; char chSyncStep[DICT_VALUE_LENGTH + 1] = "\0"; char chHeartStep[DICT_VALUE_LENGTH + 1] = "\0"; // 取得小时气象信息的长度 int nLength = sizeof(stStationRegister) - sizeof(stHeader); stStationRegister stationRegister; memset(&stationRegister, 0, sizeof(stationRegister)); WDS_DBHelper* pWDSHelper = NULL; do{ if (m_pRecvSocket == NULL){ printfs(0,"<CWDSStationRegisterProcess::Do()> m_pRecvSocket == NULL"); nStatus = 0; break;; } // 【业务处理】1. 取得端口传入的小时气象数据信息数据 nRet = m_pRecvSocket->Receive((char*)(&stationRegister) + sizeof(stHeader), nLength); if(nRet == 0) { printfs(0,"<CWDSStationRegisterProcess::Do()> Receive packet time out"); m_pRecvSocket->Close(); nStatus = 0; break; } if(nRet == -1) { printfs(0, "<CWDSStationRegisterProcess::Do()> Receive packet failed"); m_pRecvSocket->Close(); nStatus = 0; break; } printfs(2, "<CWDSStationRegisterProcess::Do()> Receive struct info:cCurTime[%s], cStationID[%.10s]",stationRegister.cCurTime,stationRegister.cStationID); MYSQL* pMysqlConnection = CObjectFactory::GetInstance()->GetMySQLPool()->GetIdleMySql(); if (pMysqlConnection == NULL){ printfs(0,"<CWDSStationRegisterProcess::Do()> No enough mysql connections!"); nStatus = 0; break; } pWDSHelper = new WDS_DBHelper(); if (pWDSHelper == NULL){ printfs(0,"<CWDSStationRegisterProcess::Do()> Can not connect to DB!"); nStatus = 0; break; } pWDSHelper->SetMysqlHandle(pMysqlConnection); // step 1.业务处理,从DB取得当前台站的实时心跳记录数量 int nCount = 0; nStatus = pWDSHelper->GetStationRealtimeStatusCount(stationRegister.cStationID, stationRegister.cCurTime, nCount); if (!nStatus){ break; } stStationHeartBeat stationHeartBeat; memset(&stationHeartBeat, 0x00, sizeof(stationHeartBeat)); memcpy(stationHeartBeat.cStationID, stationRegister.cStationID, STATION_ID_LENGTH); memcpy(stationHeartBeat.cCurTime, stationRegister.cCurTime, DATE_TIME_LENGTH); if (nCount != 0){ // step 2.1业务处理,向DB更新当前台站的心跳信息 nStatus = pWDSHelper->UpdateStationRealtimeStatus(&stationHeartBeat); } else{ // step 2.2业务处理,向DB插入当前台站的心跳信息 nStatus = pWDSHelper->InsertStationRealtimeStatus(&stationHeartBeat); } if (!nStatus){ printfs(0,"<CWDSStationRegisterProcess::Do()> Station realtime status operation failed!"); break; } // 业务处理,取得系统配置表中的同步时间间隔、心跳时间间隔 nStatus = pWDSHelper->GetSysConfigValuebyCode(SYSTEM_CONFIG_SYNC_STEP, chSyncStep); if (!nStatus){ printfs(0,"<CWDSStationRegisterProcess::Do()> GetSysConfigValuebyCode-SyncStep operation failed!"); break; } nStatus = pWDSHelper->GetSysConfigValuebyCode(SYSTEM_CONFIG_HEART_STEP, chHeartStep); if (!nStatus){ printfs(0,"<CWDSStationRegisterProcess::Do()> GetSysConfigValuebyCode-HeartStep operation failed!"); break; } } while(0); if (pWDSHelper){ CObjectFactory::GetInstance()->GetMySQLPool()->SetIdleMysql(pWDSHelper->GetMysqlHandle()); delete pWDSHelper; pWDSHelper = NULL; } // 发送标准应答 stAnswer answerInfo; memset(&answerInfo, 0, sizeof(answerInfo)); answerInfo.nVerify1 = stationRegister.nVerify1; answerInfo.nStatus = nStatus; answerInfo.nVerify2 = stationRegister.nVerify2; // 应答电文送信 nRet = m_pRecvSocket->Send((char*)(&answerInfo), sizeof(answerInfo)); if(nRet == 0) { printfs(0,"<CWDSStationRegisterProcess::Do()> Send status code time out"); } if(nRet == -1) { printfs(0, "<CWDSStationRegisterProcess::Do()> Send status code failed"); } // 发送系统配置应答 if(nStatus) { // 业务处理 取得当前系统本地时间 struct tm *pTime; time_t nowTime; time(&nowTime); pTime = gmtime(&nowTime); stStationRegisterAnswer stationRegisterAnswer; memset(&stationRegisterAnswer, 0, sizeof(stationRegisterAnswer)); stationRegisterAnswer.nVerify1 = stationRegister.nVerify1; // 设置当前时间 snprintf(stationRegisterAnswer.cCurTime, DATE_TIME_LENGTH, "%04d-%02d-%02d %02d:%02d:%02d", (1900+pTime->tm_year), (1+pTime->tm_mon), pTime->tm_mday, pTime->tm_hour, pTime->tm_min, pTime->tm_sec); stationRegisterAnswer.nSyncStep = atoi(chSyncStep); stationRegisterAnswer.nHeartStep = atoi(chHeartStep); stationRegisterAnswer.nVerify2 = stationRegister.nVerify2; // 应答电文送信 nRet = m_pRecvSocket->Send((char*)(&stationRegisterAnswer), sizeof(stationRegisterAnswer)); if(nRet == 0) { printfs(0,"<CWDSStationRegisterProcess::Do()> Send status code time out"); } if(nRet == -1) { printfs(0, "<CWDSStationRegisterProcess::Do()> Send status code failed"); } } m_pRecvSocket->Close(); printfs(1,"<CWDSStationRegisterProcess::Do()> WDSStationRegisterProcess end!"); }
/****************************************************************************** 处理名 : 启动子线程处理 函数名 : ThreadStart() 参数 : 无 返回值 : 无 ******************************************************************************/ void CChannelItem::ThreadStart(){ if ( m_pSocketMonitorThread ){ m_pSocketMonitorThread->Create(); } printfs(1, "<CChannelItem>Create channel monitor thread succeed!"); }
/** * @brief 使用lcd显示文字 * @param word_display: 将会显示的目标字符串 * 这个参数可以取得到以下的值:\n * @arg * @param x0: 字符串显示的横坐标 * @param y0: 字符串显示的纵坐标 * @retval none * \date 2012-3-31 下午4:45:29 * @note */ void LCD_Display_Words(INT8U* word_display , INT16U x0 , INT16U y0) { INT32U myfont_index[50] ; INT32U count = 1 ; Unicode_Index_MyFont(word_display , myfont_index) ; //转换unicode码 #ifdef __DEBUG__ printfs("myfont_index[0] :") ; printf_num(*myfont_index, 'h') ; printfs("\r\n") ; printfs("myfont_index[1] :") ; printf_num(*(myfont_index + 1), 'h') ; printfs("\r\n") ; printfs("myfont_index[2] :") ; printf_num(*(myfont_index + 2), 'h') ; printfs("\r\n") ; printfs("myfont_index[3] :") ; printf_num(*(myfont_index + 3), 'h') ; printfs("\r\n") ; printfs("myfont_index[4] :") ; printf_num(*(myfont_index + 4), 'h') ; printfs("\r\n") ; #endif #if LIB_FONT == POINT_LIB while(myfont_index[0] --) { display_word_mode((INT8U*) &chinese_font_mode[ *(myfont_index + count)] , x0 , y0) ; //显示一个汉字,只需要给显示字模函数一个字库索引 x0 += WORD_FONT_WIDTH ; #ifdef __DEBUG__ printfs("chinese_font_mode[*(myfont_index + count)] :") ; printf_num(&chinese_font_mode, 'h') ; printfs("\r\n") ; #endif count ++ ; } #elif LIB_FONT == IMAGE_LIB while (myfont_index[0]--) { display_word_mode(chinese_font_mode[*(myfont_index + count)], x0, y0) ; //显示一个汉字,只需要给显示字模函数一个字库索引 count++ ; x0 += WORD_FONT_WIDTH ; } #endif }
/** * @brief 将字体的点阵模显示出来 * @param index_word_lib 该字体的模所在的首地址 * 这个参数可以取得到以下的值:\n * @arg * @param x0 该字体的模显示的横坐标 * @param y0 该字体的模显示的纵坐标 * @retval none * \date 2012-3-31 下午4:55:52 * @note 不足的是不能显示不够整数方框个数的字模,如果能显示也会有安全隐患 */ void display_word_mode(INT8U* index_word_lib , INT16U x0 , INT16U y0) { #if LIB_FONT == POINT_LIB INT32U word_mode_size = WORD_FONT_SIZE ; //为了确认到字模什么时候能够写完 INT8U temp ; INT16U count = 0 ; INT16U x0_no_change = x0 ; INT16U x = x0 ; INT16U y = y0 ; //这两个变量是为了方便控制x0,y0。 #ifdef __DEBUG__ printfs("index_word_lib:") ; printf_num((INT32U) index_word_lib, 'h') ; printfs("\r\n") ; #endif /* * 假设下面是一个点阵汉字,取模由4个8*8的方框按顺序组成 * * * 一开始的时候 * |x=x0,count指的是字库里面的原始数据,x0_no_change,这个变量不会变,如果y>8的适合将x0被这个变量置位 * | * V y=y0--> ****************************** * * * * * * * 1 * 2 * * * * * * * ****************************** * * * * * * * 3 * 4 * * * * * * * ****************************** * 当一个字节写好后 * |x * |x0_no_change |count * | |x0 * | | * V v y--> ****************************** y0--> * * * y0指向下一行的时候,x0将会被x置位,即x0,又回到一开始的位置 * * * * 1 * 2 * * * * * * * ****************************** * * * * * * * 3 * 4 * * * * * * * ****************************** * 当八个字节写好后,x,y的坐标将会指向下一个方框的首地址,都是被x,y值重置了,因为到了同一行的另外一个字框,所以x的指向会被修改为x+8,而count是只管增加就行了 * | * |x0_no_change |count * | |x * | |x0 * V v y0=y--> ****************************** * * * * * * * 1 * 2 * * * * * * * ****************************** * * * * * * * 3 * 4 * * * * * * * ****************************** *第一行的方框全部写完后,x0,x将会被原本的x0_no_change改变,重新修改为指向第一列 * |x0 * |x0_no_change | * |x | * | | * V v ****************************** * * * * * * * 1 * 2 * * * * * * * y0=y--> ****************************** * <--count * * * * * * 3 * 4 * * * * * * * ****************************** */ while(word_mode_size --) { temp = *(index_word_lib + count) ; count ++ ; if (temp == 0) { y0 ++ ; } else { while(temp) { if (temp & 0x80) { draw_word_point(x0 , y0) ; x0 ++ ; } else { x0 ++ ; } temp <<= 1 ; } y0 ++ ; x0 = x ; } if (count % 8 == 0) { y0 = y ; x += 8 ; x0 = x ; } if (count % WORD_FONT_WIDTH == 0) { y += 8 ; y0 = y ; x = x0_no_change ; x0 = x0_no_change ; } } #elif LIB_FONT == IMAGE_LIB #ifdef __DEBUG__ printf_num((INT32U) index_word_lib, 'h') ; #endif set_rect(x0, y0,WORD_FONT_WIDTH,WORD_FONT_HIGH) ; write_to_FramRam((INT16U*)index_word_lib,WORD_FONT_WIDTH,WORD_FONT_HIGH) ; #endif }
/****************************************************************************** 处理名 : 业务处理 函数名 : Do() 参数 : 无 返回值 : 无 ******************************************************************************/ void CWDSMinuteDataProcess::Do(){ printfs(1,"<CWDSMinuteDataProcess::Do()> WDSMinuteDataProcess start!"); int nStatus = 0; int nRet = 0; // 取得分钟气象信息的长度 int nLength = sizeof(stElementsMinuteData) - sizeof(stHeader); stElementsMinuteData elementsMinuteData; memset(&elementsMinuteData, 0, sizeof(elementsMinuteData)); WDS_DBHelper* pWDSHelper = NULL; do{ if (m_pRecvSocket == NULL){ printfs(0,"<CWDSMinuteDataProcess::Do()> m_pRecvSocket == NULL"); break; } // 【业务处理】1. 取得端口传入的分钟气象数据信息数据 nRet = m_pRecvSocket->Receive((char*)(&elementsMinuteData) + sizeof(stHeader), nLength); if(nRet == 0) { printfs(0,"<CWDSMinuteDataProcess::Do()> Receive packet time out"); m_pRecvSocket->Close(); break; } if(nRet == -1) { printfs(0, "<CWDSMinuteDataProcess::Do()> Receive packet failed"); m_pRecvSocket->Close(); break; } printfs(2, "<CWDSMinuteDataProcess::Do()> Receive struct info:cCurTime[%s], cStationID[%.10s], fCurTemp[%f], fRainfall[%f], cWindDirection[%.4s], fWindVelocity[%f], fCurAP[%f], fHumidity[%f]", elementsMinuteData.cCurTime, elementsMinuteData.cStationID, elementsMinuteData.fCurTemp, elementsMinuteData.fRainfall, elementsMinuteData.cWindDirection, elementsMinuteData.fWindVelocity, elementsMinuteData.fCurAP, elementsMinuteData.fHumidity); // 修改方向为标准方向 nStatus = CObjectFactory::GetInstance()->ChangeDirection(elementsMinuteData.cWindDirection); if (!nStatus){ printfs(0,"<CWDSMinuteDataProcess::Do()> Wind direction error! input wind direct [%s]", elementsMinuteData.cWindDirection); break; } MYSQL* pMysqlConnection = CObjectFactory::GetInstance()->GetMySQLPool()->GetIdleMySql(); if (pMysqlConnection == NULL){ printfs(0,"<CWDSMinuteDataProcess::Do()> No enough mysql connections!"); nStatus = 0; break; } pWDSHelper = new WDS_DBHelper(); if (pWDSHelper == NULL){ printfs(0,"<CWDSMinuteDataProcess::Do()> Can not connect to DB!"); nStatus = 0; break; } pWDSHelper->SetMysqlHandle(pMysqlConnection); // step 1.业务处理,从DB取得当前台站的分钟气象数据个数 int nCount = 0; nStatus = pWDSHelper->GetElementsMinuteDataCount(elementsMinuteData.cStationID, nCount); if (!nStatus){ printfs(0,"<CWDSMinuteDataProcess::Do()> GetElementsMinuteDataCount() operation failed!"); break; } if (nCount != 0){ // step 2.1业务处理,向DB更新当前台站的分钟气象数据 nStatus = pWDSHelper->UpdateElementsMinuteData(&elementsMinuteData); } else{ // step 2.2业务处理,向DB插入当前台站的分钟气象数据 nStatus = pWDSHelper->InsertElementsMinuteData(&elementsMinuteData); } if (!nStatus){ printfs(0,"<CWDSMinuteDataProcess::Do()> Process elements minute data failed!"); break; } } while(0); if (pWDSHelper){ CObjectFactory::GetInstance()->GetMySQLPool()->SetIdleMysql(pWDSHelper->GetMysqlHandle()); delete pWDSHelper; pWDSHelper = NULL; } stAnswer answerInfo; memset(&answerInfo, 0, sizeof(answerInfo)); answerInfo.nVerify1 = elementsMinuteData.nVerify1; answerInfo.nStatus = nStatus; answerInfo.nVerify2 = elementsMinuteData.nVerify1; // 应答电文送信 nRet = m_pRecvSocket->Send((char*)(&answerInfo), sizeof(answerInfo)); if(nRet == 0) { printfs(0,"<CWDSMinuteDataProcess::Do()> Send status code time out"); } if(nRet == -1) { printfs(0, "<CWDSMinuteDataProcess::Do()> Send status code failed"); } m_pRecvSocket->Close(); printfs(1,"<CWDSMinuteDataProcess::Do()> WDSMinuteDataProcess end!"); }
int main(int argc, char *argv[]) { const char *avalue, *jvalue, *Jvalue, *Lvalue, *lvalue, *Nvalue, *nvalue; const char *tvalue; const char *special, *on; const char *name; int active; int Aflag, aflag, eflag, evalue, fflag, fvalue, jflag, Jflag, kflag; int kvalue, Lflag, lflag, mflag, mvalue, Nflag, nflag, oflag, ovalue; int pflag, sflag, svalue, Svalue, tflag; int ch, found_arg, i; const char *chg[2]; struct ufs_args args; struct statfs stfs; if (argc < 3) usage(); Aflag = aflag = eflag = fflag = jflag = Jflag = kflag = Lflag = 0; lflag = mflag = Nflag = nflag = oflag = pflag = sflag = tflag = 0; avalue = jvalue = Jvalue = Lvalue = lvalue = Nvalue = nvalue = NULL; evalue = fvalue = mvalue = ovalue = svalue = Svalue = 0; active = 0; found_arg = 0; /* At least one arg is required. */ while ((ch = getopt(argc, argv, "Aa:e:f:j:J:k:L:l:m:N:n:o:ps:S:t:")) != -1) switch (ch) { case 'A': found_arg = 1; Aflag++; break; case 'a': found_arg = 1; name = "POSIX.1e ACLs"; avalue = optarg; if (strcmp(avalue, "enable") && strcmp(avalue, "disable")) { errx(10, "bad %s (options are %s)", name, "`enable' or `disable'"); } aflag = 1; break; case 'e': found_arg = 1; name = "maximum blocks per file in a cylinder group"; evalue = atoi(optarg); if (evalue < 1) errx(10, "%s must be >= 1 (was %s)", name, optarg); eflag = 1; break; case 'f': found_arg = 1; name = "average file size"; fvalue = atoi(optarg); if (fvalue < 1) errx(10, "%s must be >= 1 (was %s)", name, optarg); fflag = 1; break; case 'j': found_arg = 1; name = "softdep journaled file system"; jvalue = optarg; if (strcmp(jvalue, "enable") && strcmp(jvalue, "disable")) { errx(10, "bad %s (options are %s)", name, "`enable' or `disable'"); } jflag = 1; break; case 'J': found_arg = 1; name = "gjournaled file system"; Jvalue = optarg; if (strcmp(Jvalue, "enable") && strcmp(Jvalue, "disable")) { errx(10, "bad %s (options are %s)", name, "`enable' or `disable'"); } Jflag = 1; break; case 'k': found_arg = 1; name = "space to hold for metadata blocks"; kvalue = atoi(optarg); if (kvalue < 0) errx(10, "bad %s (%s)", name, optarg); kflag = 1; break; case 'L': found_arg = 1; name = "volume label"; Lvalue = optarg; i = -1; while (isalnum(Lvalue[++i])); if (Lvalue[i] != '\0') { errx(10, "bad %s. Valid characters are alphanumerics.", name); } if (strlen(Lvalue) >= MAXVOLLEN) { errx(10, "bad %s. Length is longer than %d.", name, MAXVOLLEN - 1); } Lflag = 1; break; case 'l': found_arg = 1; name = "multilabel MAC file system"; lvalue = optarg; if (strcmp(lvalue, "enable") && strcmp(lvalue, "disable")) { errx(10, "bad %s (options are %s)", name, "`enable' or `disable'"); } lflag = 1; break; case 'm': found_arg = 1; name = "minimum percentage of free space"; mvalue = atoi(optarg); if (mvalue < 0 || mvalue > 99) errx(10, "bad %s (%s)", name, optarg); mflag = 1; break; case 'N': found_arg = 1; name = "NFSv4 ACLs"; Nvalue = optarg; if (strcmp(Nvalue, "enable") && strcmp(Nvalue, "disable")) { errx(10, "bad %s (options are %s)", name, "`enable' or `disable'"); } Nflag = 1; break; case 'n': found_arg = 1; name = "soft updates"; nvalue = optarg; if (strcmp(nvalue, "enable") != 0 && strcmp(nvalue, "disable") != 0) { errx(10, "bad %s (options are %s)", name, "`enable' or `disable'"); } nflag = 1; break; case 'o': found_arg = 1; name = "optimization preference"; if (strcmp(optarg, "space") == 0) ovalue = FS_OPTSPACE; else if (strcmp(optarg, "time") == 0) ovalue = FS_OPTTIME; else errx(10, "bad %s (options are `space' or `time')", name); oflag = 1; break; case 'p': found_arg = 1; pflag = 1; break; case 's': found_arg = 1; name = "expected number of files per directory"; svalue = atoi(optarg); if (svalue < 1) errx(10, "%s must be >= 1 (was %s)", name, optarg); sflag = 1; break; case 'S': found_arg = 1; name = "Softdep Journal Size"; Svalue = atoi(optarg); if (Svalue < SUJ_MIN) errx(10, "%s must be >= %d (was %s)", name, SUJ_MIN, optarg); break; case 't': found_arg = 1; name = "trim"; tvalue = optarg; if (strcmp(tvalue, "enable") != 0 && strcmp(tvalue, "disable") != 0) { errx(10, "bad %s (options are %s)", name, "`enable' or `disable'"); } tflag = 1; break; default: usage(); } argc -= optind; argv += optind; if (found_arg == 0 || argc != 1) usage(); on = special = argv[0]; if (ufs_disk_fillout(&disk, special) == -1) goto err; if (disk.d_name != special) { if (statfs(special, &stfs) != 0) warn("Can't stat %s", special); if (strcmp(special, stfs.f_mntonname) == 0) active = 1; } if (pflag) { printfs(); exit(0); } if (Lflag) { name = "volume label"; strlcpy(sblock.fs_volname, Lvalue, MAXVOLLEN); } if (aflag) { name = "POSIX.1e ACLs"; if (strcmp(avalue, "enable") == 0) { if (sblock.fs_flags & FS_ACLS) { warnx("%s remains unchanged as enabled", name); } else if (sblock.fs_flags & FS_NFS4ACLS) { warnx("%s and NFSv4 ACLs are mutually " "exclusive", name); } else { sblock.fs_flags |= FS_ACLS; warnx("%s set", name); } } else if (strcmp(avalue, "disable") == 0) { if ((~sblock.fs_flags & FS_ACLS) == FS_ACLS) { warnx("%s remains unchanged as disabled", name); } else { sblock.fs_flags &= ~FS_ACLS; warnx("%s cleared", name); } } } if (eflag) { name = "maximum blocks per file in a cylinder group"; if (sblock.fs_maxbpg == evalue) warnx("%s remains unchanged as %d", name, evalue); else { warnx("%s changes from %d to %d", name, sblock.fs_maxbpg, evalue); sblock.fs_maxbpg = evalue; } } if (fflag) { name = "average file size"; if (sblock.fs_avgfilesize == (unsigned)fvalue) { warnx("%s remains unchanged as %d", name, fvalue); } else { warnx("%s changes from %d to %d", name, sblock.fs_avgfilesize, fvalue); sblock.fs_avgfilesize = fvalue; } } if (jflag) { name = "soft updates journaling"; if (strcmp(jvalue, "enable") == 0) { if ((sblock.fs_flags & (FS_DOSOFTDEP | FS_SUJ)) == (FS_DOSOFTDEP | FS_SUJ)) { warnx("%s remains unchanged as enabled", name); } else if (sblock.fs_clean == 0) { warnx("%s cannot be enabled until fsck is run", name); } else if (journal_alloc(Svalue) != 0) { warnx("%s can not be enabled", name); } else { sblock.fs_flags |= FS_DOSOFTDEP | FS_SUJ; warnx("%s set", name); } } else if (strcmp(jvalue, "disable") == 0) { if ((~sblock.fs_flags & FS_SUJ) == FS_SUJ) { warnx("%s remains unchanged as disabled", name); } else { journal_clear(); sblock.fs_flags &= ~FS_SUJ; sblock.fs_sujfree = 0; warnx("%s cleared but soft updates still set.", name); warnx("remove .sujournal to reclaim space"); } } } if (Jflag) { name = "gjournal"; if (strcmp(Jvalue, "enable") == 0) { if (sblock.fs_flags & FS_GJOURNAL) { warnx("%s remains unchanged as enabled", name); } else { sblock.fs_flags |= FS_GJOURNAL; warnx("%s set", name); } } else if (strcmp(Jvalue, "disable") == 0) { if ((~sblock.fs_flags & FS_GJOURNAL) == FS_GJOURNAL) { warnx("%s remains unchanged as disabled", name); } else { sblock.fs_flags &= ~FS_GJOURNAL; warnx("%s cleared", name); } } } if (kflag) { name = "space to hold for metadata blocks"; if (sblock.fs_metaspace == kvalue) warnx("%s remains unchanged as %d", name, kvalue); else { kvalue = blknum(&sblock, kvalue); if (kvalue > sblock.fs_fpg / 2) { kvalue = blknum(&sblock, sblock.fs_fpg / 2); warnx("%s cannot exceed half the file system " "space", name); } warnx("%s changes from %jd to %d", name, sblock.fs_metaspace, kvalue); sblock.fs_metaspace = kvalue; } } if (lflag) { name = "multilabel"; if (strcmp(lvalue, "enable") == 0) { if (sblock.fs_flags & FS_MULTILABEL) { warnx("%s remains unchanged as enabled", name); } else { sblock.fs_flags |= FS_MULTILABEL; warnx("%s set", name); } } else if (strcmp(lvalue, "disable") == 0) { if ((~sblock.fs_flags & FS_MULTILABEL) == FS_MULTILABEL) { warnx("%s remains unchanged as disabled", name); } else { sblock.fs_flags &= ~FS_MULTILABEL; warnx("%s cleared", name); } } } if (mflag) { name = "minimum percentage of free space"; if (sblock.fs_minfree == mvalue) warnx("%s remains unchanged as %d%%", name, mvalue); else { warnx("%s changes from %d%% to %d%%", name, sblock.fs_minfree, mvalue); sblock.fs_minfree = mvalue; if (mvalue >= MINFREE && sblock.fs_optim == FS_OPTSPACE) warnx(OPTWARN, "time", ">=", MINFREE); if (mvalue < MINFREE && sblock.fs_optim == FS_OPTTIME) warnx(OPTWARN, "space", "<", MINFREE); } } if (Nflag) { name = "NFSv4 ACLs"; if (strcmp(Nvalue, "enable") == 0) { if (sblock.fs_flags & FS_NFS4ACLS) { warnx("%s remains unchanged as enabled", name); } else if (sblock.fs_flags & FS_ACLS) { warnx("%s and POSIX.1e ACLs are mutually " "exclusive", name); } else { sblock.fs_flags |= FS_NFS4ACLS; warnx("%s set", name); } } else if (strcmp(Nvalue, "disable") == 0) { if ((~sblock.fs_flags & FS_NFS4ACLS) == FS_NFS4ACLS) { warnx("%s remains unchanged as disabled", name); } else { sblock.fs_flags &= ~FS_NFS4ACLS; warnx("%s cleared", name); } } } if (nflag) { name = "soft updates"; if (strcmp(nvalue, "enable") == 0) { if (sblock.fs_flags & FS_DOSOFTDEP) warnx("%s remains unchanged as enabled", name); else if (sblock.fs_clean == 0) { warnx("%s cannot be enabled until fsck is run", name); } else { sblock.fs_flags |= FS_DOSOFTDEP; warnx("%s set", name); } } else if (strcmp(nvalue, "disable") == 0) { if ((~sblock.fs_flags & FS_DOSOFTDEP) == FS_DOSOFTDEP) warnx("%s remains unchanged as disabled", name); else { sblock.fs_flags &= ~FS_DOSOFTDEP; warnx("%s cleared", name); } } } if (oflag) { name = "optimization preference"; chg[FS_OPTSPACE] = "space"; chg[FS_OPTTIME] = "time"; if (sblock.fs_optim == ovalue) warnx("%s remains unchanged as %s", name, chg[ovalue]); else { warnx("%s changes from %s to %s", name, chg[sblock.fs_optim], chg[ovalue]); sblock.fs_optim = ovalue; if (sblock.fs_minfree >= MINFREE && ovalue == FS_OPTSPACE) warnx(OPTWARN, "time", ">=", MINFREE); if (sblock.fs_minfree < MINFREE && ovalue == FS_OPTTIME) warnx(OPTWARN, "space", "<", MINFREE); } } if (sflag) { name = "expected number of files per directory"; if (sblock.fs_avgfpdir == (unsigned)svalue) { warnx("%s remains unchanged as %d", name, svalue); } else { warnx("%s changes from %d to %d", name, sblock.fs_avgfpdir, svalue); sblock.fs_avgfpdir = svalue; } } if (tflag) { name = "issue TRIM to the disk"; if (strcmp(tvalue, "enable") == 0) { if (sblock.fs_flags & FS_TRIM) warnx("%s remains unchanged as enabled", name); else { sblock.fs_flags |= FS_TRIM; warnx("%s set", name); } } else if (strcmp(tvalue, "disable") == 0) { if ((~sblock.fs_flags & FS_TRIM) == FS_TRIM) warnx("%s remains unchanged as disabled", name); else { sblock.fs_flags &= ~FS_TRIM; warnx("%s cleared", name); } } } if (sbwrite(&disk, Aflag) == -1) goto err; ufs_disk_close(&disk); if (active) { bzero(&args, sizeof(args)); if (mount("ufs", on, stfs.f_flags | MNT_UPDATE | MNT_RELOAD, &args) < 0) err(9, "%s: reload", special); warnx("file system reloaded"); } exit(0); err: if (disk.d_error != NULL) errx(11, "%s: %s", special, disk.d_error); else err(12, "%s", special); }
void OperatorControl()//TODO remember that this is the beginning of operator controll { printf( "****************************VERSION .00017****************************\n"); #if CAMERA AxisCamera &camera = AxisCamera::GetInstance("10.26.43.11"); #endif GetWatchdog().SetEnabled(true); shooter_reset ->Start(); #if TIMER_RESET pid_code_timer->Reset(); #endif front_shooter_encoder->Reset(); back_shooter_encoder->Reset(); /*float prev_error_front = 0; float prev_error_back = 0; int test_back = 5; int test_front = 6;*/ integral_back = 0.0; integral_front = 0.0; desired_RPS_control = 0.0; //RETRACTS PISTON WHEN TELEOP STARTS override_timer->Reset(); stabilizing_timer ->Reset(); retraction_timer ->Reset(); shooter_fire_piston_A ->Set(true); shooter_fire_piston_B ->Set(false); shooter_stop_timer->Start(); while (IsOperatorControl() && IsEnabled()) { GetWatchdog().Feed(); //---------------------Display Output--------------------------- dsLCD = DriverStationLCD::GetInstance(); DriverLCD(); //printf("PRINTFS\n"); printfs(); //-------------------------Climber----------------------------- //climber_code(); //dumb_climber_code(); climber_state(); //---------------------------Drive----------------------------- arcade_tank_code(); constant_RPS_code(); //dumb_drive_code(); // In case our smart code doesnt work //--------------------------PID------------------------------- integral_reset(); //-------------------------Shooter---------------------------- pneumatic_shooter_angler_code(); pneumatic_feeder_code(); //dump_code(); //intelligent_shooter(); //-------------------------Test Code-------------------------- //camera_test(); //cin_code_get(); //prev_error_back = RPS_control_code(shooter_motor_back, back_shooter_encoder, prev_error_back, desired_RPS_control); //interpolated_test_code(); //pointer_test(shooter_motor_front); //PIDController(first_pterm, iterm, dterm, front_shooter_encoder, shooter_motor_front); //------------cRIO Housekeeping Timing-MUST HAVE-------------- Wait(0.005); }//while operator }//operator ctrl
void Autonomous() { GetWatchdog().SetEnabled(true); autonomous_timer->Reset(); #if TIMER_RESET pid_code_timer->Reset(); #endif front_shooter_encoder->Reset(); back_shooter_encoder->Reset(); shooter_angle_1 ->Set(true); shooter_angle_2 ->Set(false); retraction_timer->Reset(); stabilizing_timer->Reset(); override_timer->Reset(); //shooter_motor_front->Set(0.8); //shooter_motor_front->Set(0.8); integral_back = 0.0; integral_front = 0.0; error_back = 0.0; error_front = 0.0; desired_RPS_control = back_position_RPS_1; smart_autonomous_state = unstable;//default is unstable while (IsAutonomous() && IsEnabled()) { printfs(); GetWatchdog().Feed(); RPS_control_code(desired_RPS_control); Wait(.001); if (autonomous_timer->Get() >= first_fire && autonomous_timer->Get() <(first_fire + 1))//fire { shooter_fire_piston_A ->Set(false); shooter_fire_piston_B ->Set(true); } if (autonomous_timer->Get() >= first_retract && autonomous_timer->Get() < (first_retract + 2))//retract { shooter_fire_piston_A ->Set(true); shooter_fire_piston_B ->Set(false); } if (autonomous_timer->Get() >= second_fire && autonomous_timer->Get() < (second_fire + 1))//fire { shooter_fire_piston_A ->Set(false); shooter_fire_piston_B ->Set(true); } if (autonomous_timer->Get() >= second_retract && autonomous_timer->Get() < (second_retract +2))//retract { shooter_fire_piston_A ->Set(true); shooter_fire_piston_B ->Set(false); } if (autonomous_timer->Get() >= third_fire && autonomous_timer->Get() < (third_fire + 1))//fire { shooter_fire_piston_A ->Set(false); shooter_fire_piston_B ->Set(true); } if (autonomous_timer->Get() >= third_retract)//final retract { shooter_fire_piston_A ->Set(true); shooter_fire_piston_B ->Set(false); } } autonomous_timer->Reset(); }
int main(int argc, char **argv) { char *cp, *special; const char *name, *action; struct stat st; int i; int Aflag = 0, active = 0; struct fstab *fs; const char *chg[2]; char device[MAXPATHLEN]; struct ufs_args args; struct statfs stfs; argc--, argv++; if (argc < 2) usage(); special = argv[argc - 1]; fs = getfsfile(special); if (fs) { if (statfs(special, &stfs) == 0 && strcmp(special, stfs.f_mntonname) == 0) { active = 1; } special = fs->fs_spec; } again: if (stat(special, &st) < 0) { if (*special != '/') { if (*special == 'r') special++; snprintf(device, sizeof(device), "%s%s", _PATH_DEV, special); special = device; goto again; } err(1, "%s", special); } if (fs == NULL && (st.st_mode & S_IFMT) == S_IFDIR) errx(10, "%s: unknown file system", special); getsb(&sblock, special); for (; argc > 0 && argv[0][0] == '-'; argc--, argv++) { for (cp = &argv[0][1]; *cp; cp++) switch (*cp) { case 'A': Aflag++; continue; case 'p': printfs(); exit(0); case 'a': name = "maximum contiguous block count"; if (argc < 1) errx(10, "-a: missing %s", name); argc--, argv++; i = atoi(*argv); if (i < 1) errx(10, "%s must be >= 1 (was %s)", name, *argv); warnx("%s changes from %d to %d", name, sblock.fs_maxcontig, i); sblock.fs_maxcontig = i; continue; case 'd': name = "rotational delay between contiguous blocks"; if (argc < 1) errx(10, "-d: missing %s", name); argc--, argv++; i = atoi(*argv); warnx("%s changes from %dms to %dms", name, sblock.fs_rotdelay, i); sblock.fs_rotdelay = i; continue; case 'e': name = "maximum blocks per file in a cylinder group"; if (argc < 1) errx(10, "-e: missing %s", name); argc--, argv++; i = atoi(*argv); if (i < 1) errx(10, "%s must be >= 1 (was %s)", name, *argv); warnx("%s changes from %d to %d", name, sblock.fs_maxbpg, i); sblock.fs_maxbpg = i; continue; case 'f': name = "average file size"; if (argc < 1) errx(10, "-a: missing %s", name); argc--, argv++; i = atoi(*argv); if (i < 1) errx(10, "%s must be >= 1 (was %s)", name, *argv); if (sblock.fs_avgfilesize == i) { warnx("%s remains unchanged as %d", name, i); } else { warnx("%s changes from %d to %d", name, sblock.fs_avgfilesize, i); sblock.fs_avgfilesize = i; } break; case 'm': name = "minimum percentage of free space"; if (argc < 1) errx(10, "-m: missing %s", name); argc--, argv++; i = atoi(*argv); if (i < 0 || i > 99) errx(10, "bad %s (%s)", name, *argv); warnx("%s changes from %d%% to %d%%", name, sblock.fs_minfree, i); sblock.fs_minfree = i; if (i >= MINFREE && sblock.fs_optim == FS_OPTSPACE) warnx(OPTWARN, "time", ">=", MINFREE); if (i < MINFREE && sblock.fs_optim == FS_OPTTIME) warnx(OPTWARN, "space", "<", MINFREE); continue; case 'n': name = "soft updates"; if (argc < 1) errx(10, "-n: missing %s", name); argc--, argv++; if (strcmp(*argv, "enable") == 0) { sblock.fs_flags |= FS_DOSOFTDEP; action = "set"; } else if (strcmp(*argv, "disable") == 0) { sblock.fs_flags &= ~FS_DOSOFTDEP; action = "cleared"; } else { errx(10, "bad %s (options are %s)", name, "`enable' or `disable'"); } warnx("%s %s", name, action); continue; case 'o': name = "optimization preference"; if (argc < 1) errx(10, "-o: missing %s", name); argc--, argv++; chg[FS_OPTSPACE] = "space"; chg[FS_OPTTIME] = "time"; if (strcmp(*argv, chg[FS_OPTSPACE]) == 0) i = FS_OPTSPACE; else if (strcmp(*argv, chg[FS_OPTTIME]) == 0) i = FS_OPTTIME; else errx(10, "bad %s (options are `space' or `time')", name); if (sblock.fs_optim == i) { warnx("%s remains unchanged as %s", name, chg[i]); continue; } warnx("%s changes from %s to %s", name, chg[sblock.fs_optim], chg[i]); sblock.fs_optim = i; if (sblock.fs_minfree >= MINFREE && i == FS_OPTSPACE) warnx(OPTWARN, "time", ">=", MINFREE); if (sblock.fs_minfree < MINFREE && i == FS_OPTTIME) warnx(OPTWARN, "space", "<", MINFREE); continue; case 's': name = "expected number of files per directory"; if (argc < 1) errx(10, "-a: missing %s", name); argc--, argv++; i = atoi(*argv); if (i < 1) errx(10, "%s must be >= 1 (was %s)", name, *argv); if (sblock.fs_avgfpdir == i) { warnx("%s remains unchanged as %d", name, i); } else { warnx("%s changes from %d to %d", name, sblock.fs_avgfpdir, i); sblock.fs_avgfpdir = i; } break; default: usage(); } } if (argc != 1) usage(); putsb(&sblock, special, Aflag); if (active) { bzero(&args, sizeof(args)); if (mount("ufs", fs->fs_file, stfs.f_flags | MNT_UPDATE | MNT_RELOAD, &args) < 0) err(9, "%s: reload", special); warnx("file system reloaded"); } exit(0); }
/****************************************************************************** 处理名 : 创建子线程处理 函数名 : ThreadCreate() 参数 : 无 返回值 : 无 ******************************************************************************/ void CChannelItem::ThreadCreate(){ if(m_pSocketMonitor != NULL) { m_pSocketMonitorThread = new HProcessThread( (IProcess*)m_pSocketMonitor ); } printfs(1, "<CChannelItem>Create channel monitor process succeed! "); }
/****************************************************************************** 处理名 : 停止处理 函数名 : Stop() 参数 : 无 返回值 : 无 ******************************************************************************/ int CChannelItem::Stop(){ printfs(1, "<CChannelItem>Stop command received!"); ThreadStop(); m_bStarted = false; return 0; }