Exemple #1
0
/*
 * @brief	主程序
 */
int main(void)
{
	Request req;
	char weightBUf[32];
	char devCode[32];

  	SystemInit();
	ModulesInit();

	SelectChannel(GPRS_CHANNEL);
	GPRS_GetDevCode(devCode, sizeof(devCode));

	SelectChannel(BLUETOOTH_CHANNEL);
	while(GetRequest() != SYS_START){}	/* 等待接收SYS_START信号以开始工作 */
	SendResponse(SYS_START);

	BT_Println(devCode);

	while(1) {
		myWDGInit(30);	/* 设置定时器,值为30*2=60s=1min。超时会导致系统认为蓝牙已断开,从而进入alarm模式。 */

		req = GetRequest();	/* 获取应用请求,并调用相应功能API */
		if(FALSE == TimeoutFlag) {
			switch(req) {
				case KEEP_ALIVE:
					SendResponse(KEEP_ALIVE);
					ResetWDGCounter();
					break;

				case GET_WEIGHT:
					SendResponse(GET_WEIGHT);
					GetWeight(weightBUf);
					BT_Println(weightBUf);
					ResetWDGCounter();
					break;

				case UNLOCK_DEVICE:
					SendResponse(UNLOCK_DEVICE);
					LOCK_Unlock();	/* 解锁电子锁 */
					ResetWDGCounter();
					break;

				default:
					BT_Println("Request invalid.");
			}
		}else {
			while(1) { ReportLocation(); }
		}

	}

	return 0;
}
Exemple #2
0
ChannelHandler::ChannelHandler(int height, int width,int leftbarsize)
{
	ChannelList = new std::list<MessageBoxCF *>;
	Resize(height, width);
	this->leftbarsize = leftbarsize;
	this->SelectedChannel = NULL;
	SelectChannel("unknownRecievedMsgs");
}
Exemple #3
0
void ChannelHandler::ScrollChannelUp(int Lines)
{
	std::list<MessageBoxCF *>::iterator CurrentChannelIter = FindChannelIteratorByName(this->SelectedChannel->GetName());
	if(ChannelList->begin() != CurrentChannelIter)
	{
		CurrentChannelIter--;
	}
	SelectChannel(*CurrentChannelIter);
}
Exemple #4
0
void ChannelHandler::CloseAll()
{
	while(ChannelList->begin() != ChannelList->end())
	{
		delete(*ChannelList->begin());
		ChannelList->erase(ChannelList->begin());
	}
	SelectChannel("unknownRecievedMsgs");
}
Exemple #5
0
void ChannelHandler::CloseChannel(string Name)
{

	MessageBoxCF *temp = FindChannel(Name);
	bool WasMainChannel = false;
	if(!SelectedChannel->GetName().compare(Name)){
		SelectChannel("unknownRecievedMsgs");
		if(!Name.compare( "unknownRecievedMsgs")) WasMainChannel = true;
	}
	ChannelList->remove(temp);
	delete(temp);
	if(WasMainChannel)
	{
		this->SelectedChannel = NULL;
		SelectChannel(Name);
	}
	SendMessage(g_pWindow,WM_PAINT,0,0);
}
Exemple #6
0
void ChannelHandler::ScrollChannelDown(int Lines)
{
	std::list<MessageBoxCF *>::iterator CurrentChannelIter = FindChannelIteratorByName(this->SelectedChannel->GetName());
	CurrentChannelIter++;
	if(CurrentChannelIter == ChannelList->end())
	{
		CurrentChannelIter--;
	}
	SelectChannel(*CurrentChannelIter);
}
Exemple #7
0
  void CPVRGUIChannelNavigator::SelectPreviousChannel(ChannelSwitchMode eSwitchMode)
  {
    if (!CServiceBroker::GetGUI()->GetInfoManager().GetInfoProviders().GetPlayerInfoProvider().GetShowInfo() && eSwitchMode == ChannelSwitchMode::NO_SWITCH)
    {
      // show info for current channel on first previous channel selection.
      ShowInfo(false);
      return;
    }

    const CPVRChannelPtr prevChannel = GetNextOrPrevChannel(false);
    if (prevChannel)
      SelectChannel(prevChannel, eSwitchMode);
  }
//Set channel back to base channel
void base_channel_workitem_callback(struct work_struct *work)
{
	struct sta_info *ptdls_sta = container_of(work, struct sta_info, base_ch_workitem);
	_adapter *padapter = ptdls_sta->padapter;
	struct mlme_ext_priv *pmlmeext = &padapter->mlmeextpriv;
	
	SelectChannel(ptdls_sta->padapter, pmlmeext->cur_channel);
	issue_nulldata(ptdls_sta->padapter, 0);

	DBG_8192C("change channel to base ch:%02x\n", pmlmeext->cur_channel);

	ptdls_sta->state &= ~(TDLS_PEER_AT_OFF_STATE| TDLS_AT_OFF_CH_STATE);

	_set_timer(&ptdls_sta->off_ch_timer, 500);	

}
//Set channel back to off channel
void off_channel_workitem_callback(struct work_struct *work)
{
	struct sta_info *ptdls_sta = container_of(work, struct sta_info, off_ch_workitem);
	_adapter *padapter = ptdls_sta->padapter;
	struct mlme_ext_priv *pmlmeext = &padapter->mlmeextpriv;
	
	issue_nulldata(ptdls_sta->padapter, 1);

	SelectChannel(ptdls_sta->padapter, ptdls_sta->off_ch);

	DBG_8192C("change channel to off ch:%02x\n", ptdls_sta->off_ch);
	ptdls_sta->state |= TDLS_AT_OFF_CH_STATE;

	if((ptdls_sta->state & TDLS_PEER_AT_OFF_STATE) != TDLS_PEER_AT_OFF_STATE){
		issue_nulldata_to_TDLS_peer_STA(ptdls_sta->padapter, ptdls_sta, 0);
	}

	_set_timer(&ptdls_sta->base_ch_timer, 500);	
}
Exemple #10
0
bool DVBChannel::SelectInput(const QString &inputname, const QString &chan,
                             bool use_sm)
{
    int input = GetInputByName(inputname);

    if (input >= 0)
    {
        nextInputID = input;
        SelectChannel(chan, use_sm);
    }
    else
    {
        VERBOSE(VB_IMPORTANT,
                QString("DVBChannel: Could not find input: %1 on card when "
                        "setting channel %2\n").arg(inputname).arg(chan));
        return false;
    }
    return true;
}
Exemple #11
0
void	expire_timeout_chk(struct adapter *padapter)
{
	struct list_head *phead, *plist;
	u8 updated = 0;
	struct sta_info *psta = NULL;
	struct sta_priv *pstapriv = &padapter->stapriv;
	u8 chk_alive_num = 0;
	char chk_alive_list[NUM_STA];
	int i;

	spin_lock_bh(&pstapriv->auth_list_lock);

	phead = &pstapriv->auth_list;
	plist = phead->next;

	/* check auth_queue */
	while (phead != plist) {
		psta = container_of(plist, struct sta_info, auth_list);
		plist = plist->next;

		if (psta->expire_to > 0) {
			psta->expire_to--;
			if (psta->expire_to == 0) {
				list_del_init(&psta->auth_list);
				pstapriv->auth_list_cnt--;

				DBG_88E("auth expire %6ph\n",
					psta->hwaddr);

				spin_unlock_bh(&pstapriv->auth_list_lock);

				spin_lock_bh(&pstapriv->sta_hash_lock);
				rtw_free_stainfo(padapter, psta);
				spin_unlock_bh(&pstapriv->sta_hash_lock);

				spin_lock_bh(&pstapriv->auth_list_lock);
			}
		}
	}
	spin_unlock_bh(&pstapriv->auth_list_lock);

	psta = NULL;

	spin_lock_bh(&pstapriv->asoc_list_lock);

	phead = &pstapriv->asoc_list;
	plist = phead->next;

	/* check asoc_queue */
	while (phead != plist) {
		psta = container_of(plist, struct sta_info, asoc_list);
		plist = plist->next;

		if (chk_sta_is_alive(psta) || !psta->expire_to) {
			psta->expire_to = pstapriv->expire_to;
			psta->keep_alive_trycnt = 0;
			psta->under_exist_checking = 0;
		} else {
			psta->expire_to--;
		}

		if (psta->expire_to <= 0) {
			struct mlme_ext_priv *pmlmeext = &padapter->mlmeextpriv;

			if (padapter->registrypriv.wifi_spec == 1) {
				psta->expire_to = pstapriv->expire_to;
				continue;
			}

			if (psta->state & WIFI_SLEEP_STATE) {
				if (!(psta->state & WIFI_STA_ALIVE_CHK_STATE)) {
					/* to check if alive by another methods
					 * if station is at ps mode.
					 */
					psta->expire_to = pstapriv->expire_to;
					psta->state |= WIFI_STA_ALIVE_CHK_STATE;

					/* to update bcn with tim_bitmap
					 * for this station
					 */
					pstapriv->tim_bitmap |= BIT(psta->aid);
					update_beacon(padapter, _TIM_IE_, NULL,
						      false);

					if (!pmlmeext->active_keep_alive_check)
						continue;
				}
			}
			if (pmlmeext->active_keep_alive_check) {
				int stainfo_offset;

				stainfo_offset =
					rtw_stainfo_offset(pstapriv, psta);
				if (stainfo_offset_valid(stainfo_offset))
					chk_alive_list[chk_alive_num++] =
						stainfo_offset;
				continue;
			}

			list_del_init(&psta->asoc_list);
			pstapriv->asoc_list_cnt--;

			DBG_88E("asoc expire %pM, state = 0x%x\n", (psta->hwaddr), psta->state);
			updated = ap_free_sta(padapter, psta, true, WLAN_REASON_DEAUTH_LEAVING);
		} else {
			/* TODO: Aging mechanism to digest frames in sleep_q to avoid running out of xmitframe */
			if (psta->sleepq_len > (NR_XMITFRAME / pstapriv->asoc_list_cnt) &&
			    padapter->xmitpriv.free_xmitframe_cnt < (NR_XMITFRAME / pstapriv->asoc_list_cnt / 2)) {
				DBG_88E("%s sta:%pM, sleepq_len:%u, free_xmitframe_cnt:%u, asoc_list_cnt:%u, clear sleep_q\n", __func__,
					(psta->hwaddr), psta->sleepq_len,
					padapter->xmitpriv.free_xmitframe_cnt,
					pstapriv->asoc_list_cnt);
				wakeup_sta_to_xmit(padapter, psta);
			}
		}
	}

	spin_unlock_bh(&pstapriv->asoc_list_lock);

	if (chk_alive_num) {
		u8 backup_oper_channel = 0;
		struct mlme_ext_priv *pmlmeext = &padapter->mlmeextpriv;
		/* switch to correct channel of current network  before issue keep-alive frames */
		if (rtw_get_oper_ch(padapter) != pmlmeext->cur_channel) {
			backup_oper_channel = rtw_get_oper_ch(padapter);
			SelectChannel(padapter, pmlmeext->cur_channel);
		}

		/* issue null data to check sta alive*/
		for (i = 0; i < chk_alive_num; i++) {
			int ret = _FAIL;

			psta = rtw_get_stainfo_by_offset(pstapriv, chk_alive_list[i]);

			if (psta->state & WIFI_SLEEP_STATE)
				ret = issue_nulldata(padapter, psta->hwaddr, 0, 1, 50);
			else
				ret = issue_nulldata(padapter, psta->hwaddr, 0, 3, 50);

			psta->keep_alive_trycnt++;
			if (ret == _SUCCESS) {
				DBG_88E("asoc check, sta(%pM) is alive\n", (psta->hwaddr));
				psta->expire_to = pstapriv->expire_to;
				psta->keep_alive_trycnt = 0;
				continue;
			} else if (psta->keep_alive_trycnt <= 3) {
				DBG_88E("ack check for asoc expire, keep_alive_trycnt =%d\n", psta->keep_alive_trycnt);
				psta->expire_to = 1;
				continue;
			}

			psta->keep_alive_trycnt = 0;

			DBG_88E("asoc expire %pM, state = 0x%x\n", (psta->hwaddr), psta->state);
			spin_lock_bh(&pstapriv->asoc_list_lock);
			list_del_init(&psta->asoc_list);
			pstapriv->asoc_list_cnt--;
			updated = ap_free_sta(padapter, psta, true, WLAN_REASON_DEAUTH_LEAVING);
			spin_unlock_bh(&pstapriv->asoc_list_lock);
		}

		if (backup_oper_channel > 0) /* back to the original operation channel */
			SelectChannel(padapter, backup_oper_channel);
	}

	associated_clients_update(padapter, updated);
}
Exemple #12
0
// 1: write RCR DATA BIT
// 2: issue peer traffic indication
// 3: go back to the channel linked with AP, terminating channel switch procedure
// 4: init channel sensing, receive all data and mgnt frame
// 5: channel sensing and report candidate channel
// 6: first time set channel to off channel
// 7: go back tp the channel linked with AP when set base channel as target channel
void TDLS_option_workitem_callback(struct work_struct *work)
{
	struct sta_info *ptdls_sta = container_of(work, struct sta_info, option_workitem);
	_adapter *padapter = ptdls_sta->padapter;
	struct mlme_ext_priv *pmlmeext = &padapter->mlmeextpriv;
	struct mlme_ext_info *pmlmeinfo = &pmlmeext->mlmext_info;
	u32 bit_6=1<<6, bit_7=1<<7, bit_4=1<<4;
	u8 survey_channel, i, min;
	
	switch(ptdls_sta->option){
		case 1:
			//As long as TDLS handshake success, we should set RCR_CBSSID_DATA bit to 0
			//such we can receive all kinds of data frames.
			rtw_write32(padapter, 0x0608, rtw_read32(padapter, 0x0608)&(~bit_6));
			DBG_8192C("wirte 0x0608, set bit6 off\n");
			break;
		case 2:
			issue_tdls_peer_traffic_indication(padapter, ptdls_sta);
			break;
		case 3:
			_cancel_timer_ex(&ptdls_sta->base_ch_timer);
			_cancel_timer_ex(&ptdls_sta->off_ch_timer);
			SelectChannel(padapter, pmlmeext->cur_channel);
			ptdls_sta->state &= ~(TDLS_CH_SWITCH_ON_STATE | 
								TDLS_PEER_AT_OFF_STATE | 
								TDLS_AT_OFF_CH_STATE);
			DBG_8192C("go back to base channel\n ");
			issue_nulldata(padapter, 0);
			break;
		case 4:
			rtw_write32(padapter, 0x0608, rtw_read32(padapter, 0x0608)&(~bit_6)&(~bit_7));
			rtw_write16(padapter, 0x06A4,0xffff);	//maybe don't need to write here

			//disable update TSF
			rtw_write8(padapter, 0x0550, rtw_read8(padapter, 0x0550)|bit_4);

			pmlmeext->sitesurvey_res.channel_idx = 0;
			ptdls_sta->option = 5;
			_set_workitem(&ptdls_sta->option_workitem);
			break;
		case 5:
			survey_channel = pmlmeext->channel_set[pmlmeext->sitesurvey_res.channel_idx].ChannelNum;
			if(survey_channel){
				SelectChannel(padapter, survey_channel);
				pmlmeinfo->tdls_cur_channel = survey_channel;
				pmlmeext->sitesurvey_res.channel_idx++;
				_set_timer(&ptdls_sta->option_timer, SURVEY_TO);
			}else{
				SelectChannel(padapter, pmlmeext->cur_channel);

				//enable update TSF
				rtw_write8(padapter, 0x0550, rtw_read8(padapter, 0x0550)&(~bit_4));
				rtw_write32(padapter, 0x0608, rtw_read32(padapter, 0x0608)|(bit_7));

				if(pmlmeinfo->tdls_ch_sensing==1){
					pmlmeinfo->tdls_ch_sensing=0;
					pmlmeinfo->tdls_cur_channel=1;
					min=pmlmeinfo->tdls_collect_pkt_num[0];
					for(i=1; i<14-1; i++){
						if(min > pmlmeinfo->tdls_collect_pkt_num[i]){
							pmlmeinfo->tdls_cur_channel=i+1;
							min=pmlmeinfo->tdls_collect_pkt_num[i];
						}
						pmlmeinfo->tdls_collect_pkt_num[i]=0;
					}
					pmlmeinfo->tdls_collect_pkt_num[0]=0;
					pmlmeinfo->tdls_candidate_ch=pmlmeinfo->tdls_cur_channel;
					DBG_8192C("TDLS channel sensing done, candidate channel: %02x\n", pmlmeinfo->tdls_candidate_ch);
					pmlmeinfo->tdls_cur_channel=0;

				}

				if(ptdls_sta->state & TDLS_PEER_SLEEP_STATE){
					ptdls_sta->state |= TDLS_APSD_CHSW_STATE;
				}else{
					//send null data with pwrbit==1 before send ch_switching_req to peer STA.
					issue_nulldata(padapter, 1);

					ptdls_sta->state |= TDLS_CH_SW_INITIATOR_STATE;

					issue_tdls_ch_switch_req(padapter, ptdls_sta->hwaddr);
					DBG_8192C("issue tdls ch switch req\n");
				}
			}
			break;
		case 6:
			issue_nulldata(padapter, 1);
			SelectChannel(padapter, ptdls_sta->off_ch);

			DBG_8192C("change channel to tar ch:%02x\n", ptdls_sta->off_ch);
			ptdls_sta->state |= TDLS_AT_OFF_CH_STATE;
			ptdls_sta->state &= ~(TDLS_PEER_AT_OFF_STATE);
			_set_timer(&ptdls_sta->option_timer, (u32)ptdls_sta->ch_switch_time);
			break;
		case 7:
			_cancel_timer_ex(&ptdls_sta->base_ch_timer);
			_cancel_timer_ex(&ptdls_sta->off_ch_timer);
			SelectChannel(padapter, pmlmeext->cur_channel);
			ptdls_sta->state &= ~(TDLS_CH_SWITCH_ON_STATE | 
								TDLS_PEER_AT_OFF_STATE | 
								TDLS_AT_OFF_CH_STATE);
			DBG_8192C("go back to base channel\n ");
			issue_nulldata(padapter, 0);
			_set_timer(&ptdls_sta->option_timer, (u32)ptdls_sta->ch_switch_time);
			break;			
	}
	
}
void
MainWin::MessageReceived(BMessage *msg)
{
	switch (msg->what) {
		case B_ACQUIRE_OVERLAY_LOCK:
			printf("B_ACQUIRE_OVERLAY_LOCK\n");
			fVideoView->OverlayLockAcquire();
			break;

		case B_RELEASE_OVERLAY_LOCK:
			printf("B_RELEASE_OVERLAY_LOCK\n");
			fVideoView->OverlayLockRelease();
			break;

		case B_MOUSE_WHEEL_CHANGED:
		{
			printf("B_MOUSE_WHEEL_CHANGED\n");
			float dx = msg->FindFloat("be:wheel_delta_x");
			float dy = msg->FindFloat("be:wheel_delta_y");
			bool inv = modifiers() & B_COMMAND_KEY;
			if (dx > 0.1)	PostMessage(inv ? M_VOLUME_DOWN : M_CHANNEL_PREV);
			if (dx < -0.1)	PostMessage(inv ? M_VOLUME_UP : M_CHANNEL_NEXT);
			if (dy > 0.1)	PostMessage(inv ? M_CHANNEL_PREV : M_VOLUME_DOWN);
			if (dy < -0.1)	PostMessage(inv ? M_CHANNEL_NEXT : M_VOLUME_UP);
			break;
		}

		case M_CHANNEL_NEXT:
		{
			printf("M_CHANNEL_NEXT\n");
			int chan = fController->CurrentChannel();
			if (chan != -1) {
				chan++;
				if (chan < fController->ChannelCount())
					SelectChannel(chan);
			}
			break;
		}

		case M_CHANNEL_PREV:
		{
			printf("M_CHANNEL_PREV\n");
			int chan = fController->CurrentChannel();
			if (chan != -1) {
				chan--;
				if (chan >= 0)
					SelectChannel(chan);
			}
			break;
		}

		case M_VOLUME_UP:
			printf("M_VOLUME_UP\n");
			fController->VolumeUp();
			break;

		case M_VOLUME_DOWN:
			printf("M_VOLUME_DOWN\n");
			fController->VolumeDown();
			break;

		case M_ASPECT_100000_1:
			VideoFormatChange(fSourceWidth, fSourceHeight, 1.0, 1.0);
			break;

		case M_ASPECT_106666_1:
			VideoFormatChange(fSourceWidth, fSourceHeight, 1.06666, 1.0);
			break;

		case M_ASPECT_109091_1:
			VideoFormatChange(fSourceWidth, fSourceHeight, 1.09091, 1.0);
			break;

		case M_ASPECT_141176_1:
			VideoFormatChange(fSourceWidth, fSourceHeight, 1.41176, 1.0);
			break;

		case M_ASPECT_720_576:
			VideoFormatChange(720, 576, 1.06666, 1.0);
			break;

		case M_ASPECT_704_576:
			VideoFormatChange(704, 576, 1.09091, 1.0);
			break;

		case M_ASPECT_544_576:
			VideoFormatChange(544, 576, 1.41176, 1.0);
			break;

		case B_REFS_RECEIVED:
			printf("MainWin::MessageReceived: B_REFS_RECEIVED\n");
//			RefsReceived(msg);
			break;

		case B_SIMPLE_DATA:
			printf("MainWin::MessageReceived: B_SIMPLE_DATA\n");
//			if (msg->HasRef("refs"))
//				RefsReceived(msg);
			break;

		case M_FILE_QUIT:
//			be_app->PostMessage(B_QUIT_REQUESTED);
			PostMessage(B_QUIT_REQUESTED);
			break;

		case M_SCALE_TO_NATIVE_SIZE:
			printf("M_SCALE_TO_NATIVE_SIZE\n");
			if (fIsFullscreen) {
				ToggleFullscreen();
			}
			ResizeTo(int(fSourceWidth * fWidthScale),
					 int(fSourceHeight * fHeightScale) + (fNoMenu ? 0
					 	: fMenuBarHeight));
//			Sync();
			break;

		case M_TOGGLE_FULLSCREEN:
			ToggleFullscreen();
			fSettingsMenu->ItemAt(1)->SetMarked(fIsFullscreen);
			break;

		case M_TOGGLE_NO_MENU:
			ToggleNoMenu();
			fSettingsMenu->ItemAt(3)->SetMarked(fNoMenu);
			break;

		case M_TOGGLE_NO_BORDER:
			ToggleNoBorder();
			fSettingsMenu->ItemAt(4)->SetMarked(fNoBorder);
			break;

		case M_TOGGLE_ALWAYS_ON_TOP:
			ToggleAlwaysOnTop();
			fSettingsMenu->ItemAt(5)->SetMarked(fAlwaysOnTop);
			break;

		case M_TOGGLE_KEEP_ASPECT_RATIO:
			ToggleKeepAspectRatio();
			fSettingsMenu->ItemAt(6)->SetMarked(fKeepAspectRatio);
			break;

		case M_TOGGLE_NO_BORDER_NO_MENU:
			ToggleNoBorderNoMenu();
			break;

		case M_PREFERENCES:
			break;

		default:
			if (msg->what >= M_SELECT_CHANNEL
				&& msg->what <= M_SELECT_CHANNEL_END) {
				SelectChannel(msg->what - M_SELECT_CHANNEL);
				break;
			}
			if (msg->what >= M_SELECT_INTERFACE
				&& msg->what <= M_SELECT_INTERFACE_END) {
				SelectInterface(msg->what - M_SELECT_INTERFACE - 1);
				break;
			}
	}
}
void CExpressDlg::Execute()
{
	int res, id;
	char msg[256], buf[256];
	GtkTreeModel *pList = g_Project->FileList();
	GtkTreeIter iter, iter2;

	m_Updating = true;

	// Default state
	GtkTreeSelection *pSel = g_MainWnd->GetSelection();
	gtk_widget_set_sensitive(m_SelBtn, gtk_tree_selection_count_selected_rows(pSel)>0);
	m_Selected = gtk_tree_selection_count_selected_rows(pSel)>1;
	if (m_Selected)
		gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(m_SelBtn), true);
	else
		gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(m_AllBtn), true);

	// Restore last settings
	if (m_ConvertBtn) {
		gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(m_ConvertBtn), 
			g_Project->GetBool("ExpressReduction", "Convert", true));
		CmpackChannel channel = (CmpackChannel)g_Project->GetInt("Convert", "ColorChannel", CMPACK_CHANNEL_DEFAULT);
		SelectChannel(channel);
	}
	if (m_TimeCorrBtn) {
		m_TimeCorr = g_Project->GetDbl("TimeCorr", "Seconds", 0);
		gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(m_TimeCorrBtn), 
			g_Project->GetBool("ExpressReduction", "TimeCorr", false));
		UpdateTimeCorrection();
	}
	if (m_BiasCorrBtn && m_BiasFrameEdit) {
		gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(m_BiasCorrBtn), 
			g_Project->GetBool("ExpressReduction", "BiasCorr", false));
		char *bias = g_Project->GetStr("BiasCorr", "File", NULL);
		if (bias)
			gtk_entry_set_text(GTK_ENTRY(m_BiasFrameEdit), bias);
		else
			gtk_entry_set_text(GTK_ENTRY(m_BiasFrameEdit), "");
		g_free(bias);
	}
	if (m_DarkCorrBtn && m_DarkFrameEdit) {
		gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(m_DarkCorrBtn), 
			g_Project->GetBool("ExpressReduction", "DarkCorr", false));
		char *dark = g_Project->GetStr("DarkCorr", "File", NULL);
		if (dark)
			gtk_entry_set_text(GTK_ENTRY(m_DarkFrameEdit), dark);
		else
			gtk_entry_set_text(GTK_ENTRY(m_DarkFrameEdit), "");
		g_free(dark);
	}
	if (m_FlatCorrBtn && m_FlatFrameEdit) {
		gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(m_FlatCorrBtn), 
			g_Project->GetBool("ExpressReduction", "FlatCorr", false));
		char *flat = g_Project->GetStr("FlatCorr", "File", NULL);
		if (flat)
			gtk_entry_set_text(GTK_ENTRY(m_FlatFrameEdit), flat);
		else
			gtk_entry_set_text(GTK_ENTRY(m_FlatFrameEdit), "");
		g_free(flat);
	}
	if (m_PhotometryBtn) {
		gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(m_PhotometryBtn), 
			g_Project->GetBool("ExpressReduction", "Photometry", false));
	}
	if (m_MatchingBtn && m_RefBtn && m_CatBtn) {
		m_Matching = g_Project->GetBool("ExpressReduction", "Matching", false);
		gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(m_MatchingBtn), m_Matching && !m_Selected);
		if (g_Project->GetInt("MatchingDlg", "Select", 0)==0)
			gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(m_RefBtn), true);
		else
			gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(m_CatBtn), true);
	}
	if (m_RefFrameCombo) {
		gtk_combo_box_set_model(GTK_COMBO_BOX(m_RefFrameCombo), NULL);
		gtk_list_store_clear(m_Frames);
		gboolean ok = gtk_tree_model_get_iter_first(pList, &iter);
		while (ok) {
			gtk_tree_model_get(GTK_TREE_MODEL(pList), &iter, FRAME_ID, &id, -1);
			gtk_list_store_append(m_Frames, &iter2);
			sprintf(buf, "Frame #%d", id);
			gtk_list_store_set(m_Frames, &iter2, 0, id, 1, buf, -1);
			ok = gtk_tree_model_iter_next(pList, &iter);
		}
		gtk_combo_box_set_model(GTK_COMBO_BOX(m_RefFrameCombo), GTK_TREE_MODEL(m_Frames));
		SelectRefFrame(g_Project->GetInt("MatchingDlg", "Frame", 0));
		if (gtk_combo_box_get_active(GTK_COMBO_BOX(m_RefFrameCombo))<0) {
			GtkTreeIter iter3;
			if (gtk_tree_model_get_iter_first(GTK_TREE_MODEL(m_Frames), &iter3))
				gtk_combo_box_set_active_iter(GTK_COMBO_BOX(m_RefFrameCombo), &iter3);
		}
	}
	if (m_CatFrameEdit) {
		char *path = g_Project->GetStr("MatchingDlg", "File", NULL);
		if (path)
			gtk_entry_set_text(GTK_ENTRY(m_CatFrameEdit), path);
		else
			gtk_entry_set_text(GTK_ENTRY(m_CatFrameEdit), "");
		g_free(path);
	}
	m_Updating = false;

	UpdateControls();

	if (gtk_dialog_run(GTK_DIALOG(m_pDlg))!=GTK_RESPONSE_ACCEPT)
		return;
	gtk_widget_hide(m_pDlg);

	// Save parameters
	memset(&m_Params, 0, sizeof(tProcParams));
	if (m_ConvertBtn) {
		m_Params.Convert = gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(m_ConvertBtn))!=0;
		g_Project->SetBool("ExpressReduction", "Convert", m_Params.Convert);
		g_Project->SetInt("Convert", "ColorChannel", SelectedChannel());
	}
	if (m_TimeCorrBtn) {
		m_Params.TimeCorr = gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(m_TimeCorrBtn))!=0;
		g_Project->SetBool("ExpressReduction", "TimeCorr", m_Params.TimeCorr);
		m_Params.Seconds = m_TimeCorr;
		g_Project->SetDbl("TimeCorr", "Seconds", m_Params.Seconds);
	}
	if (m_BiasCorrBtn && m_BiasFrameEdit) {
		m_Params.BiasCorr = gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(m_BiasCorrBtn))!=0;
		g_Project->SetBool("ExpressReduction", "BiasCorr", m_Params.BiasCorr);
		m_Params.BiasFrame = gtk_entry_get_text(GTK_ENTRY(m_BiasFrameEdit));
		g_Project->SetStr("BiasCorr", "File", m_Params.BiasFrame);
		CConfig::SetStr("BiasCorr", "File", m_Params.BiasFrame);
	}
	if (m_DarkCorrBtn && m_DarkFrameEdit) {
		m_Params.DarkCorr = gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(m_DarkCorrBtn))!=0;
		g_Project->SetBool("ExpressReduction", "DarkCorr", m_Params.DarkCorr);
		m_Params.DarkFrame = gtk_entry_get_text(GTK_ENTRY(m_DarkFrameEdit));
		g_Project->SetStr("DarkCorr", "File", m_Params.DarkFrame);
		CConfig::SetStr("DarkCorr", "File", m_Params.DarkFrame);
	}
	if (m_FlatCorrBtn && m_FlatFrameEdit) {
		m_Params.FlatCorr = gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(m_FlatCorrBtn))!=0;
		g_Project->SetBool("ExpressReduction", "FlatCorr", m_Params.FlatCorr);
		m_Params.FlatFrame = gtk_entry_get_text(GTK_ENTRY(m_FlatFrameEdit));
		g_Project->SetStr("FlatCorr", "File", m_Params.FlatFrame);
		CConfig::SetStr("FlatCorr", "File", m_Params.FlatFrame);
	}
	if (m_PhotometryBtn) {
		m_Params.Photometry = gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(m_PhotometryBtn))!=0;
		g_Project->SetBool("ExpressReduction", "Photometry", m_Params.Photometry);
	}
	if (m_MatchingBtn && m_RefBtn) {
		m_Params.Matching = gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(m_MatchingBtn))!=0;
		g_Project->SetBool("ExpressReduction", "Matching", m_Matching);
		m_Params.UseRef = gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(m_RefBtn))!=0;
		g_Project->SetInt("MatchingDlg", "Select", (m_Params.UseRef ? 0 : 1));
	}
	if (m_RefFrameCombo) {
		m_Params.RefFrame = SelectedRefFrame();
		g_Project->SetInt("MatchingDlg", "Frame", m_Params.RefFrame);
	}
	if (m_CatFrameEdit) {
		m_Params.CatFile = gtk_entry_get_text(GTK_ENTRY(m_CatFrameEdit));
		g_Project->SetStr("MatchingDlg", "File", m_Params.CatFile);
		CConfig::SetStr("MatchingDlg", "File", m_Params.CatFile);
	}
	
	// Make list of unprocessed frames
	if (!m_Selected) {
		// All files
		GtkTreeModel *pList = g_Project->FileList();
		if (gtk_tree_model_iter_n_children(pList, NULL)>0) 
			gtk_tree_model_foreach(pList, foreach_all_files, &m_Params.FileList);
		else
			ShowError(m_pParent, "There are no files in the project.");
	} else {
		// Selected files
		GtkTreeSelection *pSel = g_MainWnd->GetSelection();
		if (gtk_tree_selection_count_selected_rows(pSel)>0) 
			gtk_tree_selection_selected_foreach(pSel, foreach_sel_files, &m_Params.FileList);
		else
			ShowError(m_pParent, "There are no selected files.");
	}

	if (m_Params.FileList) {
		if (m_Params.Convert && !m_Selected) {
			g_Project->ClearThumbnails();
			g_Project->ClearTempFiles();
			g_Project->ClearCorrections();
			g_Project->ClearReference();
			g_Project->ClearObject();
		}
		if (m_Params.Matching)
			g_Project->ClearReference();
		CProgressDlg pDlg(m_pParent, "Processing files");
		pDlg.SetMinMax(0, g_list_length(m_Params.FileList));
		res = pDlg.Execute(ExecuteProc, this);
		if (res!=0) {
			char *msg = cmpack_formaterror(res);
			ShowError(m_pParent, msg, true);
			cmpack_free(msg);
		} else
		if (m_Params.OutFiles==0) {
			ShowError(m_pParent, "No file was successfully processed.", true);
		} else 
		if (m_Params.OutFiles!=m_Params.InFiles) {
			sprintf(msg, "%d file(s) were successfully processed, %d file(s) failed.", 
				m_Params.OutFiles, m_Params.InFiles-m_Params.OutFiles);
			ShowWarning(m_pParent, msg, true);
		} else {
			sprintf(msg, "All %d file(s) were successfully processed.", m_Params.OutFiles);
			ShowInformation(m_pParent, msg, true);
		}
		g_list_foreach(m_Params.FileList, (GFunc)gtk_tree_row_reference_free, NULL);
		g_list_free(m_Params.FileList);
	}
	g_Project->Save();
}