Esempio n. 1
0
static void InitApp(void)
{
	int file;
	u8 buf[32];

	//sdk_open_lcd();
	InitParam();
	sdk_clear_lcd();
	//sdk_fill_lcd(DEV_LCD_FONT_ROW / 2, 0, (char*)"系统初始化...", SHOW_MID);
	//sdk_open_com(DEVICE_BT);
	//my_printf("获取蓝牙\r\n");
	//sdk_get_bt_name(g_blue_name);
	//my_printf("蓝牙名字 %s\r\n", g_blue_name);
	//sdk_close_com(DEVICE_BT);
	//sdk_open_com(gSysParam.m_CommMode);
	
	//file = sdk_open_file(FILENAME_MASTKEY, FILE_OPEN_CREATE | FILE_OPEN_WRITE);
	
	//sdk_read_file((char*)buf,16,file);
	
	/*
	memcpy(buf, "\xDC\xB6\x62\x98\x76\xBC\xAE\x58\xDF\x01\x5E\x73\xC2\x64\x19\x64", 16);
	if(sdk_write_file((char*)buf,16,file))
	{
		DEBUG
		printf("file write error\r\n");
	}
	*/
	
	//sdk_close_file(file);
	//sdk_clear_lcd();
}
Esempio n. 2
0
int main(){
	/*allocation*/
	/*RecvBuf*/
	RecvBuf.len = 0;
	RecvBuf.size = SHORT_BUFF_SIZE;
	if((RecvBuf.buf = malloc(sizeof(char) * RecvBuf.size)) == NULL){perror("malloc"); exit(0);}
	RecvBuf.buf[0] = '\0';
	/*CommBuf*/
	CommBuf.len = 0;
	//CommBuf.size = SHORT_BUFF_SIZE;
	CommBuf.size = LONG_BUFF_SIZE;
	//CommBuf.size = HUGE_BUFF_SIZE;
	if((CommBuf.buf = malloc(sizeof(char) * CommBuf.size)) == NULL){perror("malloc"); exit(0);}
	CommBuf.buf[0] = '\0';

	/*version*/
	PrintVersion();
	/*init parametas*/
	InitParam();
	/*init socket*/
	//InitSocket();
	if(InitSocket() == -1){
		return(-1);
	}
	/*init signal*/
	InitSignal();
	/*main loop*/
	MainLoop();
	/*close socket*/
	CloseSocket();

	return(0);
}
Esempio n. 3
0
/**********************************************************
  Checks if the GSM module is responding 
  to the AT command
  - if YES  nothing is made 
  - if NO   switch on sequence is repeated until there is a response
				from GSM module
**********************************************************/
void GSM::TurnOn(void)
{
  SetCommLineStatus(CLS_ATCMD);

  while (AT_RESP_ERR_NO_RESP == SendATCmdWaitResp("AT", 500, 20, "OK", 5)) {
    // there is no response => turn on the module
  
#ifdef DEBUG_PRINT
    // parameter 0 - because module is off so it is not necessary 
    // to send finish AT<CR> here
    DebugPrint("DEBUG: GSM module is off\r\n", 0);
#endif
    
    // generate switch on pulse
    digitalWrite(GSM_ON, HIGH);
    delay(1200);
    digitalWrite(GSM_ON, LOW);
    delay(1200);

    delay(1500); // wait before next try
  }
  SetCommLineStatus(CLS_FREE);

  // send collection of first initialization parameters for the GSM module    
  InitParam(PARAM_SET_0);
}
Esempio n. 4
0
/**********************************************************
 Method checks if the GSM module is registered in the GSM net
 - this method communicates directly with the GSM module
 in contrast to the method IsRegistered() which reads the
 flag from the module_status (this flag is set inside this method)

 - must be called regularly - from 1sec. to cca. 10 sec.

 return values:
 REG_NOT_REGISTERED  - not registered
 REG_REGISTERED      - GSM module is registered
 REG_NO_RESPONSE     - GSM doesn't response
 REG_COMM_LINE_BUSY  - comm line between GSM module and Arduino is not free
 for communication
 **********************************************************/
GSM::RegistrationStatus GSM::CheckRegistration(void)
{
	RXstateRes status;
	RegistrationStatus ret_val = REG_NOT_REGISTERED;

	if (CLS_FREE != getCOMStatus())
		return REG_COMM_LINE_BUSY;
	setCOMStatus(CLS_ATCMD);
	print(F("AT+CREG?"));
	print("\r");
	// 5 sec. for initial comm tmout
	// 50 msec. for inter character timeout
	status = WaitResp(5000, 50);

	if (status == RX_FINISHED)
	{
		// something was received but what was received?
		// ---------------------------------------------
		if (IsStringReceived("+CREG: 0,1") || IsStringReceived("+CREG: 0,5"))
		{
			// it means module is registered
			// ----------------------------
			setRegistrationStatus(REG_REGISTERED);

			// in case GSM module is registered first time after reset
			// sets flag STATUS_INITIALIZED
			// it is used for sending some init commands which
			// must be sent only after registration
			// --------------------------------------------
			if (!isInitialized())
			{
				setGSMStatus(GSM_INITIALIZED);
				setCOMStatus(CLS_FREE);
				InitParam(PARAM_SET_1);
				DEBUG(F("Status: Initialized"));
			}
			ret_val = REG_REGISTERED;
			INFO(F("Status: Registered"));
		}
		else
		{
			// NOT registered
			// --------------
			setRegistrationStatus(REG_NOT_REGISTERED);
			ret_val = REG_NOT_REGISTERED;
			DATA(F("Status: Not registered"));
		}
	}
	else
	{
		// nothing was received
		// --------------------
		ret_val = REG_NO_RESPONSE;
		WARNING(F("Status: Not response"));
	}
	setCOMStatus(CLS_FREE);

	return (ret_val);
}
Esempio n. 5
0
void main(void)
{
	serialBegin(9600);
	TurnOn(9600);          		//module power on
	InitParam(PARAM_SET_1);		//configure the module  
	Echo(1);               		//enable AT echo
	
    ver=LibVer();
    printf("Response Ver %d\n",ver);

}
/**********************************************************
Method checks if the GSM module is registered in the GSM net
- this method communicates directly with the GSM module
  in contrast to the method IsRegistered() which reads the
  flag from the module_status (this flag is set inside this method)

- must be called regularly - from 1sec. to cca. 10 sec.

return values: 
      REG_NOT_REGISTERED  - not registered
      REG_REGISTERED      - GSM module is registered
      REG_NO_RESPONSE     - GSM doesn't response
      REG_COMM_LINE_BUSY  - comm line between GSM module and Arduino is not free
                            for communication
**********************************************************/
byte GSM::CheckRegistration(void)
{
  byte status;
  byte ret_val = REG_NOT_REGISTERED;

  if (CLS_FREE != GetCommLineStatus()) return (REG_COMM_LINE_BUSY);
  SetCommLineStatus(CLS_ATCMD);
  _cell.println(F("AT+CREG?"));
  // 5 sec. for initial comm tmout
  // 50 msec. for inter character timeout
  status = WaitResp(5000, 50); 

  if (status == RX_FINISHED) {
    // something was received but what was received?
    // ---------------------------------------------
    if(IsStringReceived("+CREG: 0,1") 
      || IsStringReceived("+CREG: 0,5")) {
      // it means module is registered
      // ----------------------------
      module_status |= STATUS_REGISTERED;
    
    
      // in case GSM module is registered first time after reset
      // sets flag STATUS_INITIALIZED
      // it is used for sending some init commands which 
      // must be sent only after registration
      // --------------------------------------------
      if (!IsInitialized()) {
        module_status |= STATUS_INITIALIZED;
        SetCommLineStatus(CLS_FREE);
        InitParam(PARAM_SET_1);
      }
      ret_val = REG_REGISTERED;      
    }
    else {
      // NOT registered
      // --------------
      module_status &= ~STATUS_REGISTERED;
      ret_val = REG_NOT_REGISTERED;
    }
  }
  else {
    // nothing was received
    // --------------------
    ret_val = REG_NO_RESPONSE;
  }
  SetCommLineStatus(CLS_FREE);
 

  return (ret_val);
}
Esempio n. 7
0
gmShellPlink::gmShellPlink(pCSTR login, pCSTR host, pCSTR plink_args) :
  auth_defined(false)
{
  // Global parameters which could be read from XML
  InitParam("login", login);
  InitParam("host", host);
  InitParam("plink_args", plink_args);
  InitParam("plink_path", UNINITIALIZED_PARAM);
  InitParam("pscp_path", UNINITIALIZED_PARAM);
  InitParam("plink_att_num", "1");
  InitParam("plink_retry_delay", "3000");
}
Esempio n. 8
0
QSysParamPage::QSysParamPage(QWidget* parent_)
    :QBasePage( parent_)
{
    m_nShowColumn = 0;
    m_pFileList = new QListBox(this);
    m_pFileList->SetWindPos(0, 0,853, 618);
    QStringList _listHead;
    _listHead << "编号"<<"参数名"<<"参数值"<<"单位";
    m_pFileList->SetColumnHeadName( _listHead);

    m_pFileList->SetColumnWidth(0, 135);
    m_pFileList->SetColumnWidth(1, 340);
    m_pFileList->SetColumnWidth(2, 180);
    m_pFileList->SetColumnWidth(3, 180);
    m_pFileList->SetColumnHeight(18);    
    InitParam();
    UpdateView(0);
}
Esempio n. 9
0
void KJxUpdaterDlg::CheckUpdate()
{
	int nRetCode = false;
	int nResult  = false;

	::GetCurrentDirectory(MAX_PATH, m_szAppPath);
	
	_sntprintf(m_szUpdatePath, MAX_PATH, "%s%s%s", m_szAppPath, 
		CONFIG_PATH, "\\");

	nRetCode = CreateLogPath(m_szUpdatePath);
	KG_PROCESS_ERROR(nRetCode);
	nRetCode = ClearFile(m_szUpdatePath);
	KG_PROCESS_ERROR(nRetCode);
	InitParam();
// 	nRetCode = LoadConfig();
// 	KG_PROCESS_ERROR(nRetCode);
// 	nRetCode = CheckVersion();
// 	KG_PROCESS_ERROR(nRetCode);

	if (m_bNeedUpdate)
	{
		nRetCode = Update();
		KG_PROCESS_ERROR(nRetCode);
		m_CtrlStatus.SetWindowText(MSG_SUCCESS);
	}
	else
	{
		//m_CtrlStatus.SetWindowText(MSG_ISNEW);
		//OnBnClickedQuit();
		EndDialog(TRUE);
	}

	nResult = true;
Exit0:
	if (!nResult)
		m_CtrlStatus.SetWindowText(MSG_ERROR);
	return;
}
Esempio n. 10
0
std::deque<AStar::Vec2> AStar::Search(const Param &param)
{
	std::deque<Vec2> paths;
	if (!IsVlidParam(param))
	{
		assert(false);
	}
	else
	{
		InitParam(param);
		std::vector<Vec2> nearby_nodes;
		nearby_nodes.reserve(param.allow_corner ? 8 : 4);

		// 起点放入开启列表
		Node *start_node = new Node(param.start);
		open_list_.push_back(start_node);

		// 设置起点所对应节点的状态
		Node *&node_ptr = maps_[start_node->pos.y * height_ + start_node->pos.x];
		node_ptr = start_node;
		node_ptr->state = IN_OPENLIST;

		while (!open_list_.empty())
		{
			// 取出F值最小的节点
			Node *current_node = *open_list_.begin();
			std::pop_heap(open_list_.begin(), open_list_.end(), [](const Node *a, const Node *b)->bool
			{
				return a->f() > b->f();
			});
			open_list_.pop_back();
			maps_[current_node->pos.y * height_ + current_node->pos.x]->state = IN_CLOSELIST;

			// 搜索附近可通行的位置
			FindCanreachPos(current_node->pos, param.allow_corner, nearby_nodes);

			size_t index = 0;
			const size_t size = nearby_nodes.size();
			while (index < size)
			{
				// 如果存在于开启列表
				Node *new_node = nullptr;
				if (HasNoodeInOpenList(nearby_nodes[index], new_node))
				{
					HandleFoundNode(current_node, new_node);
				}
				else
				{
					// 如果不存在于开启列表
					new_node = new Node(nearby_nodes[index]);
					HndleNotFoundNode(current_node, new_node, param.end);

					// 找到终点
					if (nearby_nodes[index] == param.end)
					{
						while (new_node->parent)
						{
							paths.push_front(new_node->pos);
							new_node = new_node->parent;
						}
						goto __end__;
					}
				}
				++index;
			}
		}
	}

__end__:
	Clear();
	return paths;
}
Esempio n. 11
0
MyCrypto::MyCrypto(QObject *parent) :
    QObject(parent)
{
    InitParam();
}
Esempio n. 12
0
bool TRI_ValidateArgsFunctionAql (TRI_aql_context_t* const context,
                                  const TRI_aql_function_t* const function,
                                  const TRI_aql_node_t* const parameters) {
  param_t allowed;
  const char* pattern;
  size_t i, n;
  bool eof = false;
  bool repeat = false;

  assert(function);
  assert(parameters);
  assert(parameters->_type == TRI_AQL_NODE_LIST);

  n = parameters->_members._length;

  // validate number of arguments
  if (n < function->_minArgs || n > function->_maxArgs) {
    // invalid number of arguments
    TRI_SetErrorContextAql(context, TRI_ERROR_QUERY_FUNCTION_ARGUMENT_NUMBER_MISMATCH, function->_externalName);
    return false;
  }

  pattern = function->_argPattern;

  // validate argument types
  for (i = 0; i < n; ++i) {
    TRI_aql_node_t* parameter = (TRI_aql_node_t*) TRI_AQL_NODE_MEMBER(parameters, i);
    bool parse = true;
    bool foundArg = false;

    if (repeat) {
      // last argument is repeated
      ARG_CHECK
    }
    else {
      // last argument is not repeated
      allowed = InitParam();

      foundArg = false;

      while (parse && !eof) {
        char c = *pattern++;
        
        switch (c) {
          case '\0':
            parse = false;
            eof = true;
            if (foundArg) {
              ARG_CHECK
            }
            break;
          case '|': // optional marker
            if (foundArg) {
              parse = false;
              ARG_CHECK
              if (*pattern == '+') {
                repeat = true;
                eof = true;
              }
            }
            break;
          case ',': // next argument
            assert(foundArg);
            parse = false;
            ARG_CHECK
            break;
          case '+': // repeat last argument
            repeat = true;
            parse = false;
            eof = true;
            ARG_CHECK
            break;
          case '.': // any type except collections
            allowed._list = true;
            allowed._array = true;
            // break intentionally missing!!
          case 'p': // primitive types
            allowed._null = true;
            allowed._bool = true;
            allowed._number = true;
            allowed._string = true;
            foundArg = true;
            break;
          case 'z': // null
            allowed._null = true;
            foundArg = true;
            break;
          case 'b': // bool
            allowed._bool = true;
            foundArg = true;
            break;
          case 'n': // number
            allowed._number = true;
            foundArg = true;
            break;
          case 's': // string
            allowed._string = true;
            foundArg = true;
            break;
          case 'l': // list
            allowed._list = true;
            foundArg = true;
            break;
          case 'a': // array
            allowed._array = true;
            foundArg = true;
            break;
          case 'c': // collection name => list
            allowed._collection = true;
            foundArg = true;
            break;
          case 'h': // collection name => string
            allowed._collection = true;
            foundArg = true;
            break;
        }
      }
    }

  }
Esempio n. 13
0
static bool CheckArgumentType (TRI_aql_node_t* parameter, 
                               const param_t* const allowed) {
  param_t found = InitParam(); 

  if (parameter->_type == TRI_AQL_NODE_PARAMETER) {
    // node is a bind parameter
    char* name = TRI_AQL_NODE_STRING(parameter);

    if (*name == '@') {
      // collection bind parameter. this is an error
      found._collection = true;
      found._list = true; // a collection is a list of documents
    }
    else {
      // regular bind parameter
      found._null = true;
      found._bool = true;
      found._number = true;
      found._string = true;
      found._list = true;
      found._array = true;
    }
  }
  else if (parameter->_type == TRI_AQL_NODE_VALUE) {
    switch (parameter->_value._type) {
      case TRI_AQL_TYPE_FAIL:
      case TRI_AQL_TYPE_NULL:
        found._null = true;
        break;
      case TRI_AQL_TYPE_BOOL:
        found._bool = true;
        break;
      case TRI_AQL_TYPE_INT:
      case TRI_AQL_TYPE_DOUBLE:
        found._number = true;
        break;
      case TRI_AQL_TYPE_STRING:
        found._string = true;
        break;
    }
  }
  else if (parameter->_type == TRI_AQL_NODE_LIST) {
    // actual parameter is a list
    found._list = true;
  }
  else if (parameter->_type == TRI_AQL_NODE_ARRAY) {
    // actual parameter is an array
    found._array = true;
  }
  else if (parameter->_type == TRI_AQL_NODE_COLLECTION) {
    // actual parameter is a collection
    found._collection = true;
    found._list = true; // a collection is a list of documents
  }
  else {
    // we cannot yet determine the type of the parameter
    // this is the case if the argument is an expression, a function call etc.

    if (!allowed->_collection) {
      // if we do require anything else but a collection, we don't know the
      // type and must exit here
      return true;
    }

    // if we require a collection, it must be passed in a form that we know
    // the collection name at parse time. otherwise, an error will be raised
  }


  if (allowed->_null && found._null) {
    // argument is a null value, and this is allowed
    return true;
  }

  if (allowed->_bool && found._bool) {
    // argument is a bool value, and this is allowed
    return true;
  }
  
  if (allowed->_number && found._number) {
    // argument is a numeric value, and this is allowed
    return true;
  }
  
  if (allowed->_string && found._string) {
    // argument is a string value, and this is allowed
    return true;
  }
  
  if (allowed->_list && found._list) {
    // argument is a list, and this is allowed
    return true;
  }

  if (allowed->_array && found._array) {
    // argument is an array, and this is allowed
    return true;
  }

  if (allowed->_collection && found._collection) {
    // argument is a collection, and this is allowed
    return true;
  }

  return false;
}
Esempio n. 14
0
/*---------------------------------------------------------------------*/
static int OldLitGcgFichCoeff( FILE* FICH, char* NomFich, t_pParamAlign Param )
{
	register int i,j;
	register int c;
	float Flottant;
	int DebutDesCoeffs;
	int FinDesCommentaires;
	long PosDebLigne;
	t_score s, ss;

	/*------------------------ passer les commentaires */
	for( c=' ', FinDesCommentaires=faux; (c!=EOF) && !FinDesCommentaires;
				c=fgetc(FICH)  )
	{
		if( c=='.' )
		{
			if( (c=fgetc(FICH))=='.' )
				FinDesCommentaires= vrai;
			else
				ungetc( c, FICH );
		}
		/* memoriser les debuts de ligne */
		if( c=='\n' )
			PosDebLigne= ftell( FICH );

	}
	fseek( FICH, PosDebLigne, 0 );

	/*------------------- lire la ligne des symboles */
	for(c=' ',i=Param->PremLettre,DebutDesCoeffs=faux; (c!= EOF) && !DebutDesCoeffs;
					c= fgetc(FICH) )
	{
		if( c=='.' )
		{
			if( (c= fgetc(FICH))=='.')
				DebutDesCoeffs= vrai;
			else
				ungetc( c, FICH );
		}
		else if( !isspace(c) )
		{
			Param->Symb[i]= c;
			Param->NumSymb[c]=i;
			i++;
		}

	}
	Param->DerLettre= i-1;

	if(feof(FICH)||(i>=DERLETTREMAX))
	{
		TraiteErr(12, NomFich );
		InitParam (Param);
		return faux;
	}


	/*-------------------- lire les coefficients */
	for( i=Param->PremLettre,ss=0; i<=Param->DerLettre; i++ )
	{
		for( j=i; j<=Param->DerLettre; j++ )
			if( (fscanf(FICH,"%f",&Flottant))==EOF )
			{
				TraiteErr(12, NomFich );
				InitParam (Param);
				return faux;
			}
			else
			{
				Param->Coeff[i][j]= s = float_to_score(Flottant*10);
				if (s>ss) ss=s;
			}
		fscanf(FICH,"%*s \n");
	}
	Param->CoeffMax=ss;

	/*---------- rendre symetrique la matrice de coefficients */
	for( i=Param->PremLettre; i<Param->DerLettre; i++ )
		for( j=i+1; j<=Param->DerLettre; j++ )
			Param->Coeff[j][i]= Param->Coeff[i][j];

	return vrai;
}
Esempio n. 15
0
BOOL CConfigApp::InitInstance()
{
	// InitCommonControlsEx() is required on Windows XP if an application
	// manifest specifies use of ComCtl32.dll version 6 or later to enable
	// visual styles.  Otherwise, any window creation will fail.
	INITCOMMONCONTROLSEX InitCtrls;
	InitCtrls.dwSize = sizeof(InitCtrls);
	// Set this to include all the common control classes you want to use
	// in your application.
	InitCtrls.dwICC = ICC_WIN95_CLASSES;
	InitCommonControlsEx(&InitCtrls);

	CWinApp::InitInstance();

	if (!AfxSocketInit())
	{
		AfxMessageBox(IDP_SOCKETS_INIT_FAILED);
		return FALSE;
	}

	// Initialize OLE libraries
	if (!AfxOleInit())
	{
		AfxMessageBox(IDP_OLE_INIT_FAILED);
		return FALSE;
	}
	AfxEnableControlContainer();

	globalData.SetDPIAware ();

	// Standard initialization
	// If you are not using these features and wish to reduce the size
	// of your final executable, you should remove from the following
	// the specific initialization routines you do not need
	// Change the registry key under which our settings are stored
	// TODO: You should modify this string to be something appropriate
	// such as the name of your company or organization

	SetRegistryKey(_T("BCGP AppWizard-Generated Applications"));
	LoadStdProfileSettings(4);  // Load standard INI file options (including MRU)

	SetRegistryBase (_T("Settings"));

	InitContextMenuManager();
	InitKeyboardManager();
	InitShellManager();
	InitParam();
	// Register the application's document templates.  Document templates
	//  serve as the connection between documents, frame windows and views
	CSingleDocTemplate* pDocTemplate;
	pDocTemplate = new CSingleDocTemplate(
		IDR_MAINFRAME,
		RUNTIME_CLASS(CConfigDoc),
		RUNTIME_CLASS(CMainFrame),       // main SDI frame window
		RUNTIME_CLASS(CConfigView));
	if (!pDocTemplate)
		return FALSE;
	AddDocTemplate(pDocTemplate);

	// Parse command line for standard shell commands, DDE, file open
	CCommandLineInfo cmdInfo;
	ParseCommandLine(cmdInfo);

	// Dispatch commands specified on the command line.  Will return FALSE if
	// app was launched with /RegServer, /Register, /Unregserver or /Unregister.
	if (!ProcessShellCommand(cmdInfo))
		return FALSE;
	LoadCustomState ();
	// The one and only window has been initialized, so show and update it
	m_pMainWnd->ShowWindow(SW_SHOW);
	m_pMainWnd->UpdateWindow();
	// call DragAcceptFiles only if there's a suffix
	//  In an SDI app, this should occur after ProcessShellCommand
	
	return TRUE;
}
Esempio n. 16
0
static int LitMulFichCoeff( FILE* FICH, char* NomFich, t_pParamAlign Param )
{
	register int i,j;
	register int c;
	int cc;
	int DebutDesCoeff,OK;
	float lu;
	t_score s,ss;

	/*------------------------ passer les commentaires */
	DebutDesCoeff= faux;
	while( !DebutDesCoeff && !feof(FICH) )
	{
		/* passer les blancs */
		while( (c= fgetc(FICH))!=EOF && isspace(c) );

		/* passer les commentaires */
		if( c=='>')
			while( (c=fgetc(FICH))!='\n' && c!=EOF  ); /* passer a la ligne */

		else
			DebutDesCoeff= vrai;	/* on est au debut de la sequence */
	}

	/*------------------- lire la ligne des symboles */
	if (c==' ') while ((c= fgetc(FICH))==' ');
	for(i=Param->PremLettre-1; (i<DERLETTREMAX) && c!= EOF && c!='\n';)
	{
		if( Param->NumSymb[c]!= FreeSymb )
		{
			TraiteErr (12,NomFich);
			InitParam (Param);
			return faux;
		}
		i++;
		Param->Symb[i]= c;
		Param->NumSymb[c]=i;
		while ((c= fgetc(FICH))==' ');
	}

	Param->DerLettre= i;

	/*-------------------- lire les coefficients */
	for( i=Param->PremLettre,OK=1,ss=0;(OK==1) &&(i<=Param->DerLettre); i++ )
	{
		for( j=i;(OK==1) && (j<=Param->DerLettre); j++ )
		{
			while( ((OK=fscanf(FICH,"%g",&lu))!=1 ) && (OK!=EOF)) c=fgetc(FICH);
			Param->Coeff[i][j]= s=(t_score)lu;
			if (s > ss) ss=s;
		}
		while( (c=fgetc(FICH))!='\n' && c!=EOF  );
	}
	Param->CoeffMax = ss;

	if (i<=Param->DerLettre)
	{
		TraiteErr (12,NomFich);
		InitParam (Param);
		return faux;
	}
	/* rendre symetrique la matrice de coefficients */
	for( i=Param->PremLettre; i<Param->DerLettre; i++ )
		for( j=i+1; j<=Param->DerLettre; j++ )
			Param->Coeff[j][i]= Param->Coeff[i][j];

	while( (c=fgetc(FICH))!='\n' && c!=EOF  ); /* passer a la ligne */
	if (feof(FICH)) return vrai;

	/*------------------- lire la valeur de gap */
	if( fscanf(FICH,"%f",&lu)== 1 )
	{
		Param->Gap= lu;
		if( fscanf(FICH,"%f",&lu)== 1 )
			Param->Gap2= lu;
	}

	while( (c=fgetc(FICH))!='\n' && c!=EOF  ); /* passer a la ligne */



	/*------------------ initialisation des clusters de symboles */
	cc = Param->DerLettre;
	while( !feof(FICH) )
	{
		/* lire le symbole representant les symboles homologues dans le consensus */
		/* passer les blancs */
		while( ((c=fgetc(FICH))!=EOF) && isspace(c) );
		if (c==EOF) break;
		i=Param->NumSymb[c];
		if ((i==FreeSymb)&&(cc<DERLETTREMAX))
		{
			cc++;
			Param->NumSymb[c]=cc;
			i=cc;
			Param->Symb[i]=c;
		}
		if ((i>0)&&(i<=DERLETTREMAX))
			while ((c!=EOF) && (c!='\n'))
			{
				while ((c=fgetc(FICH))!=EOF && (c==' ') && !(c=='\n'));
				if ((c>0) && ((j = Param->NumSymb[c])>0)&&(j<=DERLETTREMAX))
					Param->Hom[j] = i;
			}
		else
			while( (c=fgetc(FICH))!='\n' && c!=EOF  ); /* passer a la ligne */
	}

	return vrai;
}
Esempio n. 17
0
static int LitGcgFichCoeff( FILE* FICH, char* NomFich, t_pParamAlign Param )
{
	char Line[256],*s;
	int i, j, OK, lu;
	t_score ss, sc;
	s=fgets(Line,256,FICH);
	if (s && strncmp(Line,"!!",2))
	{
		rewind(FICH);
		return OldLitGcgFichCoeff(FICH,NomFich,Param);
	}
	/*------------------------ passer les commentaires */
	while (s && !strstr(Line,"..\n")) s=fgets(Line,256,FICH);

	while (((s=fgets(Line,256,FICH))!=NULL) && (Line[0]=='\n'));
	if (s && (Line[0]=='{'))
	/*------------------- lire la valeur de gap */
	{
		while (fgets(Line,256,FICH) && (Line[0]!='}')) if (Line[0]!='!')
		{
			if (strstr(Line,"GAP_CREATE")) sscanf(Line,"%*s %d",&Param->Gap);
			else if (strstr(Line,"GAP_EXTEND")) sscanf(Line,"%*s %d",&Param->Gap2);
		}
		while (((s=fgets(Line,256,FICH))!=NULL) && (Line[0]=='\n'));
	}
	if (!s)
	{
		TraiteErr (12,NomFich);
		InitParam (Param);
		return faux;
	}

	/*------------------- lire la ligne des symboles */
	for(s=Line,i=Param->PremLettre; (i<DERLETTREMAX) && *s && *s!='\n';s++,i++)
	{
		while (isspace(*s)) s++;
		if (!*s) break;
		if( Param->NumSymb[*s]!= FreeSymb )
		{
			TraiteErr (12,NomFich);
			InitParam (Param);
			return faux;
		}
		Param->Symb[i]= *s;
		Param->NumSymb[*s]=i;
	}

	Param->DerLettre= i-1;
	/*-------------------- lire les coefficients */
	for( i=Param->PremLettre,OK=1,ss=0;OK &&(i<=Param->DerLettre);)
	{
		if (!fgets(Line,256,FICH)) break;
		s = strtok(Line," ");
		if (s && (Param->Symb[i]==s[0]))
		{
			for( j=Param->PremLettre;OK && (j<=i); j++ )
			{
				s = strtok(NULL," ");
				OK = s && (sscanf(s,"%d",&lu)==1);
				Param->Coeff[i][j]= sc=(t_score)lu;
				if (sc > ss) ss=sc;
			}
			i++;
		}
	}
	Param->CoeffMax = ss;

	if (i<=Param->DerLettre)
	{
		TraiteErr (12,NomFich);
		InitParam (Param);
		return faux;
	}
	/* rendre symetrique la matrice de coefficients */
	for( i=Param->PremLettre; i<Param->DerLettre; i++ )
	{
/*		fprintf (stderr,"\n%c ",Param->Symb[i]);*/
		for( j=Param->PremLettre; j<i; j++ )
		{
			Param->Coeff[j][i]= Param->Coeff[i][j];
/*			fprintf(stderr,"%4d",Param->Coeff[i][j]);*/
		}
	}
	return vrai;
}
int GSM::begin(long baud_rate){
	#ifdef UNO
		if (baud_rate==115200){
			Serial.println("Don't use baudrate 115200 with Software Serial.\nAutomatically changed at 9600.");
			baud_rate=9600;
		}
	#endif
	int response=-1;
	int cont=0;
	boolean norep=true;
	boolean turnedON=false;
	SetCommLineStatus(CLS_ATCMD);
	_cell.begin(baud_rate);
	p_comm_buf = &comm_buf[0];
	setStatus(IDLE); 

	// if no-reply we turn to turn on the module
	for (cont=0; cont<3; cont++){
		if (AT_RESP_ERR_NO_RESP == SendATCmdWaitResp("AT", 500, 100, "OK", 5)&&!turnedON) {		//check power
	    // there is no response => turn on the module
			#ifdef DEBUG_ON
				Serial.println("DB:NO RESP");
			#endif
			// generate turn on pulse
			digitalWrite(GSM_ON, HIGH);
			delay(1200);
			digitalWrite(GSM_ON, LOW);
			delay(10000);
			WaitResp(1000, 1000); 
		}
		else{
			#ifdef DEBUG_ON
				Serial.println("DB:ELSE");
			#endif
			WaitResp(1000, 1000); 
		}
	}
	
	
	if (AT_RESP_OK == SendATCmdWaitResp("AT", 500, 100, "OK", 5)){
		#ifdef DEBUG_ON
			Serial.println(F("DB:CORRECT BR"));
		#endif
		turnedON=true;
			norep=false;
	}


	if (AT_RESP_ERR_DIF_RESP == SendATCmdWaitResp("AT", 500, 100, "OK", 5)&&!turnedON){		//check OK
		#ifdef DEBUG_ON
			Serial.println(F("DB:AUTO BAUD RATE"));
		#endif
		for (int i=0;i<8;i++){
			switch (i) {
			case 0:
			  _cell.begin(1200);
			  break;
			  
			case 1:
			  _cell.begin(2400);
			  break;
			  
			case 2:
			  _cell.begin(4800);
			  break;
			  
			case 3:
			  _cell.begin(9600);
			  break;
			   
			case 4:
			  _cell.begin(19200);
			  break;
			  
			case 5:
			  _cell.begin(38400);
			  break;
			  
			case 6:
			  _cell.begin(57600);
			  break;
			  
			case 7:
			  _cell.begin(115200);
			  break;
  
			// if nothing else matches, do the default
			// default is optional
			}
					
			delay(100);

			#ifdef DEBUG_PRINT
				// parameter 0 - because module is off so it is not necessary 
				// to send finish AT<CR> here
				DebugPrint("DEBUG: Stringa ", 0);
				DebugPrint(buff, 0);
			#endif
				

			if (AT_RESP_OK == SendATCmdWaitResp("AT", 500, 100, "OK", 5)){
				#ifdef DEBUG_ON
					Serial.println(F("DB:FOUND PREV BR"));
				#endif
				_cell.print(F("AT+IPR="));
				_cell.print(baud_rate);    
				_cell.print("\r"); // send <CR>
				delay(500);
				_cell.begin(baud_rate);
				delay(100);
				if (AT_RESP_OK == SendATCmdWaitResp("AT", 500, 100, "OK", 5)){
					#ifdef DEBUG_ON
						Serial.println("DB:OK BR");
					#endif
				}
				turnedON=true;
				break;					
			}
			#ifdef DEBUG_ON
				Serial.println("DB:NO BR");
			#endif			
		}
		// communication line is not used yet = free
		SetCommLineStatus(CLS_FREE);
		// pointer is initialized to the first item of comm. buffer
		p_comm_buf = &comm_buf[0];
	}

	if(norep==true&&!turnedON){
		Serial.println(F("Trying to force the baud-rate to 9600\n"));
		for (int i=0;i<8;i++){
		switch (i) {
			case 0:
			  _cell.begin(1200);
			  delay(1000);
			  Serial.println(F("1200"));
			  _cell.print(F("AT+IPR=9600\r"));
			  delay(1000);
			  _cell.begin(9600);
			  delay(1000);
			  SendATCmdWaitResp("AT", 500, 100, "OK", 5);
			  delay(1000);
			  WaitResp(1000,1000);
			  break;
			  
			case 1:
			  _cell.begin(2400);
			  delay(1000);
			  Serial.println(F("2400"));
			  _cell.print(F("AT+IPR=9600\r"));
			  delay(1000);
			  _cell.begin(9600);
			  delay(1000);
			  SendATCmdWaitResp("AT", 500, 100, "OK", 5);
			  delay(1000);
			  WaitResp(1000,1000);
			  break;
			  
			case 2:
			  _cell.begin(4800);
			  delay(1000);
			  Serial.println(F("4800"));
			  _cell.print(F("AT+IPR=9600\r"));
			  delay(1000);
			  _cell.begin(9600);
			  delay(1000);
			  SendATCmdWaitResp("AT", 500, 100, "OK", 5);
			  delay(1000);
			  WaitResp(1000,1000);
			  break;
			  
			case 3:
			  _cell.begin(9600);
			  delay(1000);
			  Serial.println(F("9600"));
			  _cell.print(F("AT+IPR=9600\r"));
			  delay(1000);
			  _cell.begin(9600);
			  delay(1000);
			  SendATCmdWaitResp("AT", 500, 100, "OK", 5);
			  delay(1000);
			  WaitResp(1000,1000);
			  break;
			   
			case 4:
			  _cell.begin(19200);
			  delay(1000);
			  Serial.println(F("19200"));
			  _cell.print(F("AT+IPR=9600\r"));
			  delay(1000);
			  _cell.begin(9600);
			  delay(1000);
			  SendATCmdWaitResp("AT", 500, 100, "OK", 5);
			  delay(1000);
			  WaitResp(1000,1000);
			  break;
			  
			case 5:
			  _cell.begin(38400);
			  delay(1000);
			  Serial.println(F("38400"));
			  _cell.print(F("AT+IPR=9600\r"));
			  delay(1000);
			  _cell.begin(9600);
			  delay(1000);
			  SendATCmdWaitResp("AT", 500, 100, "OK", 5);
			  delay(1000);
			  WaitResp(1000,1000);
			  break;
			  
			case 6:
			  _cell.begin(57600);
			  delay(1000);
			  Serial.println(F("57600"));
			  _cell.print(F("AT+IPR=9600\r"));
			  delay(1000);
			  _cell.begin(9600);
			  delay(1000);
			  SendATCmdWaitResp("AT", 500, 100, "OK", 5);
			  delay(1000);
			  WaitResp(1000,1000);
			  break;
			  
			case 7:
			  _cell.begin(115200);
			  delay(1000);
			  Serial.println(F("115200"));
			  _cell.print(F("AT+IPR=9600\r"));
			  delay(1000);
			  _cell.begin(9600);
			  delay(1000);
			  SendATCmdWaitResp("AT", 500, 100, "OK", 5);
			  delay(1000);
			  WaitResp(1000,1000);
			  break;
			}	
		}
		
		Serial.println(F("ERROR: SIM900 doesn't answer. Check power and serial pins in GSM.cpp"));
		digitalWrite(GSM_ON, HIGH);
		delay(1200);
		digitalWrite(GSM_ON, LOW);
		delay(10000);
		return 0;
	}
	
	SetCommLineStatus(CLS_FREE);

	if(turnedON){
		WaitResp(50, 50);
		InitParam(PARAM_SET_0);
		InitParam(PARAM_SET_1);//configure the module  
		Echo(0);               //enable AT echo
		setStatus(READY);
		return(1);

	}
	else{
		//just to try to fix some problems with 115200 baudrate
		_cell.begin(115200);
		delay(1000);
		_cell.print(F("AT+IPR="));
		_cell.print(baud_rate);    
		_cell.print("\r"); // send <CR>		
		return(0);
	}
}
Esempio n. 19
0
BOOL CInstallApp::InitInstance()
{
    HWND oldHWnd = NULL;
    EnumWindows(EnumWndProc,(LPARAM)&oldHWnd);    //枚举所有运行的窗口
    if(oldHWnd != NULL)
    {
        ::ShowWindow(oldHWnd,SW_SHOWNORMAL);          //激活找到的前一个程序
        ::SetForegroundWindow(oldHWnd);                //把它设为前景窗口
        return false;                                  //退出本次运行
    }
    // 如果一个运行在 Windows XP 上的应用程序清单指定要
    // 使用 ComCtl32.dll 版本 6 或更高版本来启用可视化方式,
    //则需要 InitCommonControlsEx()。否则,将无法创建窗口。
    INITCOMMONCONTROLSEX InitCtrls;
    InitCtrls.dwSize = sizeof(InitCtrls);
    // 将它设置为包括所有要在应用程序中使用的
    // 公共控件类。
    InitCtrls.dwICC = ICC_WIN95_CLASSES;
    InitCommonControlsEx(&InitCtrls);

    CWinApp::InitInstance();

    if (!AfxSocketInit())
    {
        AfxMessageBox(IDP_SOCKETS_INIT_FAILED);
        return FALSE;
    }

    // 初始化 OLE 库
    if (!AfxOleInit())
    {
        AfxMessageBox(IDP_OLE_INIT_FAILED);
        return FALSE;
    }
    AfxEnableControlContainer();
    // 标准初始化
    // 如果未使用这些功能并希望减小
    // 最终可执行文件的大小,则应移除下列
    // 不需要的特定初始化例程
    // 更改用于存储设置的注册表项
    // TODO: 应适当修改该字符串,
    // 例如修改为公司或组织名
    SetRegistryKey(_T("BCGSoft\\BCGControlBarPro\\Samples"));

//	LoadStdProfileSettings();  // 加载标准 INI 文件选项(包括 MRU)
    SetRegistryBase (_T("Settings"));

    InitContextMenuManager();
    InitKeyboardManager();
    InitParam();
    // 注册应用程序的文档模板。文档模板
    // 将用作文档、框架窗口和视图之间的连接
    CSingleDocTemplate* pDocTemplate;
    pDocTemplate = new CSingleDocTemplate(
        IDR_MAINFRAME,
        RUNTIME_CLASS(CInstallDoc),
        RUNTIME_CLASS(CMainFrame),       // 主 SDI 框架窗口
        RUNTIME_CLASS(CInstallView));
    if (!pDocTemplate)
        return FALSE;
    AddDocTemplate(pDocTemplate);



    // 分析标准外壳命令、DDE、打开文件操作的命令行
    CCommandLineInfo cmdInfo;
    ParseCommandLine(cmdInfo);


    // 调度在命令行中指定的命令。如果
    // 用 /RegServer、/Register、/Unregserver 或 /Unregister 启动应用程序,则返回 FALSE。
    if (!ProcessShellCommand(cmdInfo))
        return FALSE;

    LoadCustomState ();

    // 唯一的一个窗口已初始化,因此显示它并对其进行更新
    m_pMainWnd->ShowWindow(SW_SHOW);
    m_pMainWnd->UpdateWindow();
    // 仅当具有后缀时才调用 DragAcceptFiles
    //  在 SDI 应用程序中,这应在 ProcessShellCommand 之后发生
    return TRUE;
}