コード例 #1
0
ファイル: addpath.c プロジェクト: x64ports/kliu-code
void addpath( )
{
	UINT argc = 0;
	PTSTR *argv = GetArgv(&argc);
	PBUFFER pBuffer = LocalAlloc(LMEM_FIXED, sizeof(BUFFER));

	UINT uExitCode = EntryMain(argc, argv, pBuffer);

	LocalFree(pBuffer);
	LocalFree(argv);
	ExitProcess(uExitCode);
}
コード例 #2
0
ファイル: command_line.cpp プロジェクト: ballmillsapest/KBase
StringType CommandLine::GetArgvStringWithoutProgram() const
{
    ArgList argv = GetArgv();

    // Skipt program part.
    ArgList quoted_args;
    std::move(std::next(argv.begin()), argv.end(), std::back_inserter(quoted_args));

    // Quotes each part only if necessary.
    std::transform(quoted_args.begin(), quoted_args.end(), quoted_args.begin(),
                   QuoteArg);

    return JoinString(quoted_args, L" ");
}
コード例 #3
0
//---------------------------------------------------------------------------
int RunAutoTestCmd2(const char *cmdstr, COMMAND_TABLE *pTestCmdTable, int len )
{
	int		argc ;
	char**		argv ;
	int		i, retval ;
		
		argc = GetArgc( (const char *)cmdstr );
		argv = GetArgv( (const char *)cmdstr );
		if( argc < 1 ) return 0;
		StrUpr( argv[0] );



		//----		
		if(!strcmp( argv[0], "~") || !strcmp( argv[0], "Q") )	//return 1 to go back up directory
			return 1;
		if( *(argv[0])=='#' )	
			return 0;		
		if( *(argv[0])=='/' && *(argv[0]+1)=='/' )		// meet "//" to do nothing
			return 0;
/*
		if(argv[1])	cmd_line.fr= strtoul((const char*)(argv[1]), (char **)NULL, 16);	
		else			cmd_line.fr=0;
		if(argv[2])	cmd_line.sc= strtoul((const char*)(argv[2]), (char **)NULL, 16);	
*/
		//execute function
		//int len=sizeof(pTestCmdTable) / sizeof(COMMAND_TABLE);

		for( i=0 ; i < len ; i++ )
		{
			if( ! strcmp( argv[0], pTestCmdTable[i].cmd ) )
			{				
				if(pTestCmdTable[i].func)
					retval = pTestCmdTable[i].func( argc - 1 , argv+1 );
				memset(argv[0],0,sizeof(argv[0]));
				break;
			}
		}
		if(i==len) dprintf("Unknown command !\r\n");

		return 0;
}
コード例 #4
0
void RunMonitor(char *PROMOPT, COMMAND_TABLE *TestCmdTable, int len)
{
	char		buffer[ MAX_MONITOR_BUFFER +1 ];
	int		argc ;
	char**		argv ;
	int		i, retval ;
	
	
	while(1)
	{	
		//printf( "%s", TEST_PROMPT );
		dprintf( "%s", PROMOPT );
		memset( buffer, 0, MAX_MONITOR_BUFFER );
		GetLine( buffer, MAX_MONITOR_BUFFER,1);
		dprintf( "\n" );
		argc = GetArgc( (const char *)buffer );
		argv = GetArgv( (const char *)buffer );
		if( argc < 1 ) continue ;
		StrUpr( argv[0] );

		if(!strcmp( argv[0], "..") || !strcmp( argv[0], "Q") )
			return;
		
		//for( i=0 ; i < (sizeof(TestCmdTable) / sizeof(COMMAND_TABLE)) ; i++ )
		for( i=0 ; i < (len) ; i++ )
		{
			if( ! strcmp( argv[0], TestCmdTable[i].cmd ) )
			{
				if(TestCmdTable[i].func)
					retval = TestCmdTable[i].func( argc - 1 , argv+1 );
				//dprintf("End run code\n");
				memset(argv[0],0,sizeof(argv[0]));
				break;
			}
		}
		//if(i==sizeof(TestCmdTable) / sizeof(COMMAND_TABLE)) printf("Unknown command !\r\n");
		if(i==len) printf("Unknown command !\r\n");
	}
}
コード例 #5
0
ファイル: Plugin_017.c プロジェクト: pcastel/Nodo-Core
boolean Plugin_017(byte function, struct NodoEventStruct *event, char *string)
  {
  boolean success=false;
  
  int x;
  
  switch(function)
    {    
    case PLUGIN_INIT:
      {
      for(x=0;x<WIRED_PORTS;x++)
        pinMode(PIN_WIRED_OUT_1+x,INPUT); // definieer Arduino pin's voor Wired-Out
      }

    case PLUGIN_EVENT_IN:
      {
      if(event->Type     == NODO_TYPE_EVENT && 
         event->Command  == EVENT_USEREVENT &&
         event->Par1     == 255 &&
         event->Par2     == 255)
        {
        switch(event->Port)
          {
          case VALUE_SOURCE_IR:
            bitWrite(HW_Config,HW_IR_TX,true);
            break;
          case VALUE_SOURCE_RF:
            bitWrite(HW_Config,HW_RF_TX,true);
            break;
          }
        }          
      }

    case PLUGIN_ONCE_A_SECOND:
      {
      if(Active)
        {
        switch(HWSecCounter++)
          {
          case 1:
            HWSendTestEvent(VALUE_SOURCE_RF);
            break;

          case 5:
            HWSendTestEvent(VALUE_SOURCE_IR);
            break;

          case 7:
            HWSendTestEvent(VALUE_SOURCE_I2C);
            break;

          case 8:
            {            
            CheckWiredLines();          
            ShowTestResults();
            if(HW_ConfigCheck)
              {
              if(HW_Config==HW_ConfigCheck)
                {
                for(x=0;x<=4;x++)
                  {
                  Beep(2500,25);
                  delay(100);
                  }
                Serial.println(F("NodoTest: HWConfig is correct!"));
                }
              else
                {
                Beep(500,1000);
                Serial.println(F("NodoTest: HWConfig is NOT correct!"));
                }
              }
            Active=false;
            }
          }
        }
      break;
      }
      
    case PLUGIN_COMMAND:
      {
      Beep(1000,250);
      Settings.TransmitIR=VALUE_ON;
      Settings.TransmitRF=VALUE_ON;
      Settings.RawSignalReceive=VALUE_OFF;
    
      HWSecCounter=0;

      for(x=0;x<WIRED_PORTS;x++)
        {
        Settings.WiredInputPullUp[x]=VALUE_ON;
        pinMode(A0+PIN_WIRED_IN_1+x,INPUT_PULLUP);
        }

      HW_ConfigCheck=event->Par2;
      Active=true;
      Serial.println(F("NodoTest: Running...(please wait a few seconds)\n"));
      Beep(1000,50);

      success=true;
      break;
      }      
    
    #if NODO_MEGA // alleen relevant voor een Nodo Mega want de Small heeft geen MMI!
    case PLUGIN_MMI_IN:
      {
      char *TempStr=(char*)malloc(INPUT_COMMAND_SIZE);

      if(GetArgv(string,TempStr,1))
        {
        if(strcasecmp(TempStr,PLUGIN_NAME)==0)
          {
          event->Type    = NODO_TYPE_PLUGIN_COMMAND;
          event->Command = PLUGIN_ID; // nummer van dit plugin
          if(GetArgv(string,TempStr,2))
            event->Par2    = str2int(TempStr);
          success=true;
          }
        }
      free(TempStr);
      break;
      }

    case PLUGIN_MMI_OUT:
      {
      strcpy(string,PLUGIN_NAME);               // Commando 
      strcat(string," ");
      strcat(string,int2str(event->Par2));

      break;
      }
    #endif //MMI
    }
    
  return success;
  }
コード例 #6
0
ファイル: interface.c プロジェクト: hsptools/hsp-wrap
/*-------------- main starts here --------------------------*/
extern Int2 Main (void)
{

RecT r1, r2;

#ifdef WIN_MAC
    m = AppleMenu (NULL);
    DeskAccGroup(m);
    m = PulldownMenu(NULL,  "File");
  
    s = SubMenu(m, "Open");
    i = CommandItem(m, "Quit/Q", QuitProc);
#endif

    InitProc(GetArgc(), GetArgv());

    w = RoundWindow(-50, -33,  -10,  -10,  "PDBeast: Taxonomy Assignment",  NULL);

#ifndef WIN_MAC

    SetUpDrawingTools();
/*  Red();
    SetColor(5);  */
    InvertColors();

    wpdb = RoundWindow(-53, -33, -10,  -10, "PDB File Display", NULL);
    p = StaticPrompt(wpdb, "Pdb File", 0, dialogTextHeight,  systemFont,  '1');
    Advance(wpdb);
    PdbOpen = DefaultButton(wpdb, "Open", PdbOpenProc);
    Break(wpdb);

    p = StaticPrompt(wpdb, "Blast Search", 0, dialogTextHeight,  systemFont,  '1');
    Advance(wpdb);
    lBlastChain = SingleList(wpdb, 10, 3, ListBlastChainProc);
    Advance(wpdb);
    BlastSearchAccept = DefaultButton(wpdb, "Send Query", BlastSearchAcceptProc);
    Break(wpdb);
 
    p = StaticPrompt(wpdb, "String Search", 0, dialogTextHeight,  systemFont,  '1');
    Advance(wpdb);
    Pdbfile_string = DialogText(wpdb, "", 15, NULL);
    Advance(wpdb);
    Pdbfile_string_accept = DefaultButton(wpdb, "Find", PdbfileStringAcceptProc);
    Break(wpdb);

    pdbfile_panel = DocumentPanel(wpdb, 650, 20*stdLineHeight);
    Break(wpdb);
    p = StaticPrompt(wpdb,"                ", 0, dialogTextHeight,  systemFont,  '1');
    Advance(wpdb);
    PdbClose = PushButton(wpdb,"Close", PdbCloseProc);
    Break(wpdb);

    m = PulldownMenu(w, "File");
    s1 = SubMenu(m, "Open");
    i = CommandItem(s1, "Entry", EntryProc);
    s2 = SubMenu(s1, "List");
    c = ChoiceGroup(s2, ListOpenProc); 
    ChoiceItem(c, myargs[6].strvalue);
   
/*  s3 = SubMenu(m, "Update");
    c = ChoiceGroup(s3, ListUpdateProc);
    ChoiceItem(c, myargs[6].strvalue);    */
    
    i = CommandItem(m,  "Quit/Q",  QuitProc);

/*  edit = PulldownMenu(w, "Edit");
    i = CommandItem(edit, "cut", StdCutTextProc);
    i = CommandItem(edit, "copy", StdCopyTextProc);
    i = CommandItem(edit, "paste", StdPasteTextProc);   */
#endif

    infilemode = NormalGroup(w, 3, 0, "Data Mode of Input Entry",systemFont, InFileTypeProc);
    RadioButton(infilemode, "Text"); 
    RadioButton(infilemode, "Binary"); 
/*  SafeSetValue(infilemode, 2);  */
    GetPosition(infilemode, &r1);

    outfilemode = NormalGroup(w, 3, 0, "Data Mode of Output Entry",systemFont, OutFileTypeProc);
    RadioButton(outfilemode, "Text"); 
    RadioButton(outfilemode, "Binary"); 
/*  SafeSetValue(outfilemode, 2);  */
    r2.top = r1.top; r2.bottom = r1.bottom; 
    r2.left = r1.right + 80;
    r2. right = r2.left + r1.right - r1.left;
    SetPosition(outfilemode, &r2);      
    Break(w);

    p = StaticPrompt(w, "Seq-entry", 0, dialogTextHeight,  systemFont,  '1');
    Advance (w);
    l = SingleList(w, 20, 3, ListProc);
    Disable(l);
    Advance(w);
    ListEntry_start = DefaultButton(w, "Start", ListEntryStartProc);
    Disable(ListEntry_start);
    Advance(w);
    ListEntry_next = DefaultButton(w, "Next", ListEntryNextProc);
    Disable(ListEntry_next);
    Advance(w);
    ListEntry_specific = DefaultButton(w, "Specific", ListEntrySpecificProc);
    Disable(ListEntry_specific);
    Break(w);
 
    p = StaticPrompt(w, "Enter Entry Code", 0, dialogTextHeight,  systemFont,  '1');
    Advance (w);
    Entry_code = DialogText(w, "", 15, (TxtActnProc) EnableProc);
    Select(Entry_code);
    Advance (w);
    Entry_accept = DefaultButton(w, "Open", EntryOpenProc);    
    Disable(Entry_accept);
    Break(w);

    p = StaticPrompt(w, "Chain", 0, dialogTextHeight,  systemFont,  '1');
    chain_panel = DocumentPanel(w, 200, stdLineHeight);
    Break(w);
    p = StaticPrompt(w, "Pdb Source:", 0, dialogTextHeight,  systemFont,  '1');
    pdb_source = ScrollText(w, 38, 3, systemFont, TRUE, NULL);
    Advance(w);
    Break(w);
    p = StaticPrompt(w, "Taxonomy Data:", 0, dialogTextHeight,  systemFont,  '1');
    org = DocumentPanel(w,400,6*stdLineHeight);
    Break(w);
    
    p = StaticPrompt(w, "Taxonomy Accept?", 0, dialogTextHeight,  systemFont,  '1');
    Break(w);
    Tax_accept = DefaultButton(w, "Yes", TaxAcceptProc);
    Advance(w);
    p = StaticPrompt(w, "to    ", 0, dialogTextHeight,  systemFont,  '1');
    Advance(w);
    Tax_all_accept = DefaultButton(w, "All", TaxAllAcceptProc);
    Disable(Tax_all_accept);
    Advance(w);
    p = StaticPrompt(w, "         or          ", 0, dialogTextHeight,  systemFont,  '1');
    Advance(w);      
    Tax_part_accept = DefaultButton(w, "Chain", TaxPartAcceptProc);
    Disable(Tax_part_accept);
    Advance(w);
    lchain = SingleList(w, 2, 4, TaxPartAssignProc);
    Advance(w);
    Tax_finish = DefaultButton(w, "All Done", TaxFinishProc);
    Disable(Tax_finish);
    Break(w); 
    Tax_reject = DefaultButton(w, "No", ReLookupProc);
    Disable(Tax_accept);
    Disable(Tax_reject);
    Break(w);

    p = StaticPrompt(w, "Look up Taxonomy Database with another String?", 0, dialogTextHeight,  systemFont,  '1');
    Advance(w);
    ReLookup_accept = DefaultButton(w, "Yes", AddStringProc);
    Advance(w);
    ReLookup_reject = DefaultButton(w, "No", ReLookupRejectProc);
    Disable(ReLookup_accept);
    Disable(ReLookup_reject);
    Break(w);

    p = StaticPrompt(w,"Search Taxonomy Database with", 0, dialogTextHeight,  systemFont,  '1');
    Advance(w);
    Source_string = DialogText(w, "", 15, NULL);
    Advance(w);
    Source_string_accept = DefaultButton(w, "Start", SourceStringAcceptProc);
    Disable(Source_string_accept);
    Break(w);

    Show(w);
    Show(wpdb);
    ProcessEvents();

    return 0;
}
コード例 #7
0
int OGRGPSBabelDataSource::Open( const char * pszDatasourceName, int bUpdateIn)

{
    int bExplicitFeatures = FALSE;
    int bWaypoints = TRUE, bTracks = TRUE, bRoutes = TRUE;
    if (bUpdateIn)
    {
        CPLError(CE_Failure, CPLE_NotSupported,
                    "OGR/GPSBabel driver does not support opening a file in update mode");
        return FALSE;
    }

    if (!EQUALN(pszDatasourceName, "GPSBABEL:", 9))
    {
        VSILFILE* fp = VSIFOpenL(pszDatasourceName, "rb");
        if (fp == NULL)
            return FALSE;

        char szHeader[1024 + 1];
        memset(szHeader, 0, 1024+1);
        VSIFReadL(szHeader, 1, 1024, fp);
        if (memcmp(szHeader, "MsRcd", 5) == 0)
            pszGPSBabelDriverName = CPLStrdup("mapsource");
        else if (memcmp(szHeader, "MsRcf", 5) == 0)
            pszGPSBabelDriverName = CPLStrdup("gdb");
        else if (strstr(szHeader, "<osm") != NULL)
            pszGPSBabelDriverName = CPLStrdup("osm");
        else if (strstr(szHeader, "$GPGSA") != NULL ||
                 strstr(szHeader, "$GPGGA") != NULL)
            pszGPSBabelDriverName = CPLStrdup("nmea");
        else if (EQUALN(szHeader, "OziExplorer",11))
            pszGPSBabelDriverName = CPLStrdup("ozi");
        else if (strstr(szHeader, "Grid") && strstr(szHeader, "Datum") && strstr(szHeader, "Header"))
            pszGPSBabelDriverName = CPLStrdup("garmin_txt");
        else if (szHeader[0] == 13 && szHeader[10] == 'M' && szHeader[11] == 'S' &&
                 (szHeader[12] >= '0' && szHeader[12] <= '9') &&
                 (szHeader[13] >= '0' && szHeader[13] <= '9') &&
                 szHeader[12] * 10 + szHeader[13] >= 30 &&
                 (szHeader[14] == 1 || szHeader[14] == 2) && szHeader[15] == 0 &&
                 szHeader[16] == 0 && szHeader[17] == 0)
            pszGPSBabelDriverName = CPLStrdup("mapsend");
        else if (strstr(szHeader, "$PMGNWPL") != NULL ||
                 strstr(szHeader, "$PMGNRTE") != NULL)
            pszGPSBabelDriverName = CPLStrdup("magellan");

        VSIFCloseL(fp);

        if (pszGPSBabelDriverName == NULL)
        {
            return FALSE;
        }

        pszFilename = CPLStrdup(pszDatasourceName);
    }

    pszName = CPLStrdup( pszDatasourceName );

    if (pszGPSBabelDriverName == NULL)
    {
        const char* pszSep = strchr(pszDatasourceName + 9, ':');
        if (pszSep == NULL)
        {
            CPLError(CE_Failure, CPLE_AppDefined,
                    "Wrong syntax. Expected GPSBabel:driver_name:file_name");
            return FALSE;
        }

        pszGPSBabelDriverName = CPLStrdup(pszDatasourceName + 9);
        *(strchr(pszGPSBabelDriverName, ':')) = '\0';

        /* A bit of validation to avoid command line injection */
        if (!IsValidDriverName(pszGPSBabelDriverName))
            return FALSE;

        /* Parse optionnal features= option */
        if (EQUALN(pszSep+1, "features=", 9))
        {
            const char* pszNextSep = strchr(pszSep+1, ':');
            if (pszNextSep == NULL)
            {
                CPLError(CE_Failure, CPLE_AppDefined,
                        "Wrong syntax. Expected GPSBabel:driver_name[,options]*:[features=waypoints,tracks,routes:]file_name");
                return FALSE;
            }

            char* pszFeatures = CPLStrdup(pszSep+1+9);
            *strchr(pszFeatures, ':') = 0;
            char** papszTokens = CSLTokenizeString(pszFeatures);
            char** papszIter = papszTokens;
            int bErr = FALSE;
            bExplicitFeatures = TRUE;
            bWaypoints = bTracks = bRoutes = FALSE;
            while(papszIter && *papszIter)
            {
                if (EQUAL(*papszIter, "waypoints"))
                    bWaypoints = TRUE;
                else if (EQUAL(*papszIter, "tracks"))
                    bTracks = TRUE;
                else if (EQUAL(*papszIter, "routes"))
                    bRoutes = TRUE;
                else
                {
                    CPLError(CE_Failure, CPLE_AppDefined, "Wrong value for 'features' options");
                    bErr = TRUE;
                }
                papszIter ++;
            }
            CSLDestroy(papszTokens);
            CPLFree(pszFeatures);

            if (bErr)
                return FALSE;

            pszSep = pszNextSep;
        }

        pszFilename = CPLStrdup(pszSep+1);
    }

    const char* pszOptionUseTempFile = CPLGetConfigOption("USE_TEMPFILE", NULL);
    if (pszOptionUseTempFile && CSLTestBoolean(pszOptionUseTempFile))
        osTmpFileName = CPLGenerateTempFilename(NULL);
    else
        osTmpFileName.Printf("/vsimem/ogrgpsbabeldatasource_%p", this);

    int bRet = FALSE;
    if (IsSpecialFile(pszFilename))
    {
        /* Special file : don't try to open it */
        char** argv = GetArgv(bExplicitFeatures, bWaypoints, bRoutes,
                              bTracks, pszGPSBabelDriverName, pszFilename);
        VSILFILE* tmpfp = VSIFOpenL(osTmpFileName.c_str(), "wb");
        bRet = (CPLSpawn(argv, NULL, tmpfp, TRUE) == 0);
        VSIFCloseL(tmpfp);
        tmpfp = NULL;
        CSLDestroy(argv);
        argv = NULL;
    }
    else
    {
        VSILFILE* fp = VSIFOpenL(pszFilename, "rb");
        if (fp == NULL)
        {
            CPLError(CE_Failure, CPLE_AppDefined,
                    "Cannot open file %s", pszFilename);
            return FALSE;
        }

        char** argv = GetArgv(bExplicitFeatures, bWaypoints, bRoutes,
                              bTracks, pszGPSBabelDriverName, "-");

        VSILFILE* tmpfp = VSIFOpenL(osTmpFileName.c_str(), "wb");

        CPLPushErrorHandler(CPLQuietErrorHandler);
        bRet = (CPLSpawn(argv, fp, tmpfp, TRUE) == 0);
        CPLPopErrorHandler();

        CSLDestroy(argv);
        argv = NULL;

        CPLErr nLastErrorType = CPLGetLastErrorType();
        int nLastErrorNo = CPLGetLastErrorNo();
        CPLString osLastErrorMsg = CPLGetLastErrorMsg();

        VSIFCloseL(tmpfp);
        tmpfp = NULL;

        VSIFCloseL(fp);
        fp = NULL;

        if (!bRet)
        {
            if (strstr(osLastErrorMsg.c_str(), "This format cannot be used in piped commands") == NULL)
            {
                CPLError(nLastErrorType, nLastErrorNo, "%s", osLastErrorMsg.c_str());
            }
            else
            {
                VSIStatBuf sStatBuf;
                if (VSIStat(pszFilename, &sStatBuf) != 0)
                {
                    CPLError(CE_Failure, CPLE_NotSupported,
                            "Driver %s only supports real (non virtual) files", pszGPSBabelDriverName);
                    return FALSE;
                }

                /* Try without piping in */
                argv = GetArgv(bExplicitFeatures, bWaypoints, bRoutes,
                              bTracks, pszGPSBabelDriverName, pszFilename);
                tmpfp = VSIFOpenL(osTmpFileName.c_str(), "wb");
                bRet = (CPLSpawn(argv, NULL, tmpfp, TRUE) == 0);
                VSIFCloseL(tmpfp);
                tmpfp = NULL;

                CSLDestroy(argv);
                argv = NULL;
            }
        }
    }


    if (bRet)
    {
        poGPXDS = OGRSFDriverRegistrar::Open(osTmpFileName.c_str());
        if (poGPXDS)
        {
            OGRLayer* poLayer;

            if (bWaypoints)
            {
                poLayer = poGPXDS->GetLayerByName("waypoints");
                if (poLayer != NULL && poLayer->GetFeatureCount() != 0)
                    apoLayers[nLayers++] = poLayer;
            }

            if (bRoutes)
            {
                poLayer = poGPXDS->GetLayerByName("routes");
                if (poLayer != NULL && poLayer->GetFeatureCount() != 0)
                    apoLayers[nLayers++] = poLayer;
                poLayer = poGPXDS->GetLayerByName("route_points");
                if (poLayer != NULL && poLayer->GetFeatureCount() != 0)
                    apoLayers[nLayers++] = poLayer;
            }

            if (bTracks)
            {
                poLayer = poGPXDS->GetLayerByName("tracks");
                if (poLayer != NULL && poLayer->GetFeatureCount() != 0)
                    apoLayers[nLayers++] = poLayer;
                poLayer = poGPXDS->GetLayerByName("track_points");
                if (poLayer != NULL && poLayer->GetFeatureCount() != 0)
                    apoLayers[nLayers++] = poLayer;
            }
        }
    }

    return nLayers > 0;
}
コード例 #8
0
ファイル: Plugin_005.c プロジェクト: stuntteam/Nodo-Core
boolean Plugin_005(byte function, struct NodoEventStruct *event, char *string)
  {
  boolean success=false;
  static byte Call_Status = 0x00; // Each bit represents one relative port. 0=not called before, 1=already called before. 
  
  switch(function)
    {
    #ifdef PLUGIN_005_CORE

    case PLUGIN_COMMAND:
      {
      int DSTemp;                           // Temperature in 16-bit Dallas format.
      byte ScratchPad[12];                  // Scratchpad buffer Dallas sensor.   
      byte var=event->Par2;                 // Variabele die gevuld moet worden.
      byte RelativePort=event->Par1-1;
      
      UserVariablePayload(var,0x0011);

      // De Dallas sensor kan worden aangesloten op iedere digitale poort van de Arduino. In ons geval kiezen we er voor
      // om de sensor aan te sluiten op de Wired-Out poorten van de Nodo. Met Par2 is de Wired poort aangegeven.
      // 1 = WiredOut poort 1.  
      DallasPin=PIN_WIRED_OUT_1+event->Par1-1;
      
      ClearEvent(event);                                      // Ga uit van een default schone event. Oude eventgegevens wissen.        
  
      noInterrupts();
      while (!(bitRead(Call_Status, RelativePort)))
        {
        // if this is the very first call to the sensor on this port, reset it to wake it up 
        boolean present=DS_reset();
        bitSet(Call_Status, RelativePort);
        }        
      boolean present=DS_reset();DS_write(0xCC /* rom skip */); DS_write(0x44 /* start conversion */);
      interrupts();
              
      if(present)
        {
        delay(800);     // uitleestijd die de sensor nodig heeft
    
        noInterrupts();
        DS_reset(); DS_write(0xCC /* rom skip */); DS_write(0xBE /* Read Scratchpad */);
    
        // Maak de lijn floating zodat de sensor de data op de lijn kan zetten.
        digitalWrite(DallasPin,LOW);
        pinMode(DallasPin,INPUT);
    
        for (byte i = 0; i < 9; i++)            // copy 8 bytes
          ScratchPad[i] = DS_read();
        interrupts();
      
        DSTemp = (ScratchPad[1] << 8) + ScratchPad[0];  
        TempFloat=float(DSTemp)*0.0625; // DS18B20 variant. Waarde terugstoppen in de variabele
        success=(UserVariableSet(var,TempFloat,PLUGIN_05_EVENT)!=-1);
        }
      break;
      }
    #endif // CORE
      
    #if NODO_MEGA
    case PLUGIN_MMI_IN:
      {
      char *TempStr=(char*)malloc(INPUT_COMMAND_SIZE);

      if(GetArgv(string,TempStr,1))
        {
        if(strcasecmp(TempStr,PLUGIN_NAME)==0)
          {
          // Par1 en Par2 hoeven niet te worden geparsed omdat deze default al door de MMI invoer van de Nodo 
          // worden gevuld indien het integer waarden zijn. Toetsen op bereiken moet nog wel plaats vinden.
          if(event->Par1>0 && event->Par1<=HARDWARE_WIRED_OUT_PORTS && event->Par2>0 && event->Par2<=USER_VARIABLES_MAX_NR)            
            {
            success=true;
            event->Type = NODO_TYPE_PLUGIN_COMMAND;
            event->Command = 5; // Plugin nummer  
            }
          }
        }
      free(TempStr);
      break;
      }

    case PLUGIN_MMI_OUT:
      {
      strcpy(string,PLUGIN_NAME);            // Eerste argument=het commando deel
      strcat(string," ");
      strcat(string,int2str(event->Par1));
      strcat(string,",");
      strcat(string,int2str(event->Par2));

      break;
      }
    #endif //MMI
    }      
  return success;
  }
コード例 #9
0
ファイル: Plugin_027.c プロジェクト: ESP8266nu/NodoClassic
boolean Plugin_027(byte function, struct NodoEventStruct *event, char *string)
  {
  boolean success=false;

  #ifdef PLUGIN_027_CORE
  switch(function)
    {
    case PLUGIN_COMMAND:
      {
        if (!Servo_attached(event->Par1-1))
          {
            Servo_Init(event->Par1-1);
            Servo_attach(event->Par1-1,PIN_WIRED_OUT_1 + event->Par1-1);
          }
        Servo_write(event->Par1-1,event->Par2);
        success=true;
        break;
      }
      
    #endif // CORE
    
    #if NODO_MEGA // alleen relevant voor een Nodo Mega want de Small heeft geen MMI!
    case PLUGIN_MMI_IN:
      {
      char *TempStr=(char*)malloc(INPUT_COMMAND_SIZE);

      if(GetArgv(string,TempStr,1))
        {
        if(strcasecmp(TempStr,PLUGIN_NAME_027)==0)
          {
          if(GetArgv(string,TempStr,2)) 
            {
            if(GetArgv(string,TempStr,3))
              {
              if(event->Par1>0 && event->Par1<5 && event->Par2>=0 && event->Par2<=180)            
                {
                  event->Type = NODO_TYPE_PLUGIN_COMMAND;
                  event->Command = 27; // Plugin nummer
                  success=true;
                }
              }
            }
          }
        }
      free(TempStr);
      break;
      }

    case PLUGIN_MMI_OUT:
      {
      strcpy(string,PLUGIN_NAME_027);
      strcat(string," ");
      strcat(string,int2str(event->Par1));
      strcat(string,",");
      strcat(string,int2str(event->Par2));
      break;
      }
    #endif //MMI
    }
    
  return success;
  }
コード例 #10
0
ファイル: Plugin_022.c プロジェクト: stuntteam/Nodo-Core
boolean Plugin_022(byte function, struct NodoEventStruct *event, char *string)
{
    boolean success=false;
    switch(function)
    {
#ifdef PLUGIN_022_CORE
    case PLUGIN_COMMAND:
    {
        // start de meting en zend een trigger puls van 10mSec.
        noInterrupts();
        digitalWrite(PIN_WIRED_OUT_1, LOW);
        delayMicroseconds(2);
        digitalWrite(PIN_WIRED_OUT_1, HIGH);
        delayMicroseconds(10);
        digitalWrite(PIN_WIRED_OUT_1, LOW);

        // meet de tijd van de echo puls. Uit dit gegeven berekenen we de afstand.
        float distance=pulseIn(PIN_WIRED_OUT_1+1,HIGH);
        interrupts();

        UserVariablePayload(event->Par1,0x0032);
        distance=distance/58;
        UserVariableSet(event->Par1,distance,false);
        success=true;
        break;
    }

    case PLUGIN_INIT:
    {
        pinMode(PIN_WIRED_OUT_1  , OUTPUT); // TRIG
        pinMode(PIN_WIRED_OUT_1+1, INPUT ); // ECHO
        break;
    }
#endif // CORE

#if NODO_MEGA
    case PLUGIN_MMI_IN:
    {
        char *TempStr=(char*)malloc(INPUT_COMMAND_SIZE);

        if(GetArgv(string,TempStr,1))
        {
            if(strcasecmp(TempStr,PLUGIN_NAME_22)==0)
            {
                if(event->Par1>0 && event->Par1<=USER_VARIABLES_MAX_NR)
                {
                    success=true;
                    event->Type = NODO_TYPE_PLUGIN_COMMAND;
                    event->Command = 22; // Plugin nummer
                }
            }
        }
        free(TempStr);
        break;
    }

    case PLUGIN_MMI_OUT:
    {
        strcpy(string,PLUGIN_NAME_22);            // Eerste argument=het commando deel
        strcat(string," ");
        strcat(string,int2str(event->Par1));
        break;
    }
#endif //CORE_22
    }
    return success;
}
コード例 #11
0
ファイル: Plugin_029.c プロジェクト: ESP8266nu/NodoClassic
boolean Plugin_029(byte function, struct NodoEventStruct *event, char *string)
  {
  boolean success=false;

  #ifdef PLUGIN_029_CORE
  static byte portValue=0;

  switch(function)
    {
    
    case PLUGIN_COMMAND:
      {
      byte unit = (event->Par1-1) / 4;
      byte port = event->Par1 - (unit * 4);
      uint8_t address = 0x48 + unit;

      // get the current pin value
      WireNodo.beginTransmission(address);
      WireNodo.write(port-1);
      WireNodo.endTransmission();

      WireNodo.requestFrom(address, (uint8_t)0x2);
      if(WireNodo.available())
      {
        WireNodo.read(); // Read older value first (stored in chip)
        UserVar[event->Par2-1] = (float)WireNodo.read();// now read actual value and store into Nodo var
        success=true;
      }
      break;
      }
    #endif // CORE
    
    #if NODO_MEGA // alleen relevant voor een Nodo Mega want de Small heeft geen MMI!
    case PLUGIN_MMI_IN:
      {
      char *TempStr=(char*)malloc(INPUT_COMMAND_SIZE);

      if(GetArgv(string,TempStr,1))
        {
        if(strcasecmp(TempStr,PLUGIN_NAME_029)==0)
          {
          if(GetArgv(string,TempStr,2)) 
            {
            if(GetArgv(string,TempStr,3))
              {
              if(event->Par1>0 && event->Par1<33 && event->Par2>=0 && event->Par2<=USER_VARIABLES_MAX)            
                {
                  event->Type = NODO_TYPE_PLUGIN_COMMAND;
                  event->Command = 29; // Plugin nummer  
                  success=true;
                }
              }
            }
          }
        }
      free(TempStr);
      break;
      }

    case PLUGIN_MMI_OUT:
      {
      strcpy(string,PLUGIN_NAME_029);
      strcat(string," ");
      strcat(string,int2str(event->Par1));
      strcat(string,",");
      strcat(string,int2str(event->Par2));
      break;
      }
    #endif //MMI
    }
    
  return success;
  }
コード例 #12
0
ファイル: Plugin_026.c プロジェクト: pcastel/Nodo-Core
boolean Plugin_026(byte function, struct NodoEventStruct *event, char *string)
  {
  boolean success=false;

  #ifdef PLUGIN_026_CORE
  static byte portValue=0;

  switch(function)
    {
    case PLUGIN_INIT:
    {
      // get the current pin status
      uint8_t address = 0x20;
      Wire.requestFrom(address, (uint8_t)0x1);
      if(Wire.available()) portValue = Wire.read();
      break;
    }
    
    case PLUGIN_ONCE_A_SECOND:
      {
      byte tmpPortValue=0;
      uint8_t address = 0x20;

      // get the current pin status
      Wire.requestFrom(address, (uint8_t)0x1);
      if(Wire.available())
      {
        tmpPortValue = Wire.read();
        if (tmpPortValue != portValue)
          {
            for (byte x=0; x<8; x++)
              {
                if ((portValue & (1 << x)) != (tmpPortValue & (1 << x)))
                  {
                    struct NodoEventStruct tmpEvent;
                    ClearEvent(&tmpEvent);
                    tmpEvent.Type         = NODO_TYPE_PLUGIN_EVENT;
                    tmpEvent.Command      = PLUGIN_ID;
                    tmpEvent.Par1         = x+1;
                    tmpEvent.Par2         = VALUE_ON;
                    if (tmpPortValue & (1 << x)) tmpEvent.Par2 = VALUE_OFF;
                    ProcessEvent(&tmpEvent);
                    //QueueAdd(&tmpEvent);
                  }
              }
            portValue = tmpPortValue;
          }
        success=true;
      }
      break;
      }
    #endif // CORE
    
    #if NODO_MEGA // alleen relevant voor een Nodo Mega want de Small heeft geen MMI!
    case PLUGIN_MMI_IN:
      {
      char *TempStr=(char*)malloc(INPUT_COMMAND_SIZE);

      if(GetArgv(string,TempStr,1))
        {
        if(strcasecmp(TempStr,PLUGIN_NAME_026)==0)
          {
          if(GetArgv(string,TempStr,2)) 
            {
            if(GetArgv(string,TempStr,3))
              {
              if(event->Par1>0 && event->Par1<65 && (event->Par2==VALUE_ON || event->Par2==VALUE_OFF))            
                {
                  event->Type = NODO_TYPE_PLUGIN_EVENT;
                  event->Command = 26; // Plugin nummer  
                  success=true;
                }
              }
            }
          }
        }
      free(TempStr);
      break;
      }

    case PLUGIN_MMI_OUT:
      {
      strcpy(string,PLUGIN_NAME_026);
      strcat(string," ");
      strcat(string,int2str(event->Par1));
      strcat(string,",");
      if(event->Par2==VALUE_ON)
        strcat(string,"On");  
      else strcat(string,"Off");
      break;
      }
    #endif //MMI
    }
    
  return success;
  }
コード例 #13
0
ファイル: Plugin_006.c プロジェクト: stuntteam/Nodo-Core
boolean Plugin_006(byte function, struct NodoEventStruct *event, char *string)
  {
  boolean success=false;
  
  switch(function)
    {
    #ifdef PLUGIN_006_CORE
  
    
    case PLUGIN_COMMAND:
      {
      DHT_Pin=PIN_WIRED_OUT_1+event->Par1-1;
      byte dht_dat[5];
      byte dht_in;
      byte i;
      byte Retry=0;

      UserVariablePayload(event->Par2,  0x0011); // Temperature
      UserVariablePayload(event->Par2+1,0x00d1); // Relative humidity %

      do
        {  
        pinMode(DHT_Pin,OUTPUT);                                                // DHT start condition, pull-down i/o pin for 18ms
        digitalWrite(DHT_Pin,LOW);                                              // Pull low
        delay(18);
        digitalWrite(DHT_Pin,HIGH);                                             // Pull high
        delayMicroseconds(40);
        pinMode(DHT_Pin,INPUT);                                                 // change pin to input
        delayMicroseconds(40);
        dht_in = digitalRead(DHT_Pin);

        if(!dht_in)
          {
          delayMicroseconds(80);
          dht_in = digitalRead(DHT_Pin);

          if(dht_in)
            {
            delayMicroseconds(40);                                              // now ready for data reception
            for (i=0; i<5; i++)
              dht_dat[i] = read_dht_dat();
              
            byte dht_check_sum = dht_dat[0]+dht_dat[1]+dht_dat[2]+dht_dat[3];   // check checksum. Checksum calculation is a Rollover Checksum by design.

            if(dht_dat[4]== dht_check_sum)
              {

              #if PLUGIN_006_CORE==11                                           // Code door de DHT-11 variant
              TempFloat=float(dht_dat[2]);                                      // Temperatuur
              UserVariableSet(event->Par2  ,TempFloat,DHT_EVENT);
              TempFloat=float(dht_dat[0]);                                      // Vochtigheid
              UserVariableSet(event->Par2+1,TempFloat,DHT_EVENT);
              #endif
              
              
              #if PLUGIN_006_CORE==22 || PLUGIN_006_CORE==33                    // Code door de DHT-22 of DHT-33 variant
              if (dht_dat[2] & 0x80)                                            // negative temperature
                {
                TempFloat=-0.1 * word(dht_dat[2] & 0x7F, dht_dat[3]);
                UserVariableSet(event->Par2,TempFloat,DHT_EVENT);
                }
              else
                {
                TempFloat=0.1 * word(dht_dat[2], dht_dat[3]);
                UserVariableSet(event->Par2,TempFloat,DHT_EVENT);
                }
              TempFloat=word(dht_dat[0], dht_dat[1]) * 0.1;                     // vochtigheid
              UserVariableSet(event->Par2+1,TempFloat,DHT_EVENT);
              #endif

              success=true;
              }
            }
          }
        if(!success)
          delay(1000);

        }while(!success && ++Retry<3);        
      break;
      }
    #endif // CORE
    
    #if NODO_MEGA
    case PLUGIN_MMI_IN:
      {
      char *TempStr=(char*)malloc(INPUT_COMMAND_SIZE);
  
      if(GetArgv(string,TempStr,1))
        {
        if(strcasecmp(TempStr,PLUGIN_NAME)==0)
          {
          if(event->Par1>0 && event->Par1<HARDWARE_WIRED_OUT_PORTS && event->Par2>0 && event->Par2<=USER_VARIABLES_MAX_NR-1)
            {
            event->Type = NODO_TYPE_PLUGIN_COMMAND;
            event->Command = PLUGIN_ID;                                         // Plugin nummer  
            success=true;
            }
          }
        }
      free(TempStr);
      break;
      }
  
    case PLUGIN_MMI_OUT:
      {
      strcpy(string,PLUGIN_NAME);                                               // Eerste argument=het commando deel
      strcat(string," ");
      strcat(string,int2str(event->Par1));
      strcat(string,",");
      strcat(string,int2str(event->Par2));
      break;
      }
    #endif // MMI
    }      
  return success;
  }
コード例 #14
0
ファイル: Plugin_011.c プロジェクト: ESP8266nu/NodoClassic
boolean Plugin_011(byte function, struct NodoEventStruct *event, char *string)
  {
  boolean success=false;

  // Deze plugin code wordt vanuit meerdere plaatsen in de Nodo code aangeroepen, steeds met een doel. Dit doel bevindt zich
  // in de variabele [function]. De volgende zijn gedefinieerd:
  //
  // PLUGIN_RAWSIGNAL_IN  => Afhandeling van een via RF/IR ontvangen event
  // PLUGIN_COMMAND       => Commando voor afhandelen/uitsturen van een event.
  // PLUGIN_MMI_IN        => Invoer van de gebruiker/script omzetten naar een event. (Alleen voor mega)
  // PLUGIN_MMI_OUT       => Omzetten van een event naar een voor de gebruiker leesbare tekst (Alleen voor Mega)
  // DEVIDE_ONCE_A_SECOND => ongeveer iedere seconde.
  // PLUGIN_INIT          => Eenmalig, direct na opstarten van de Nodo
  // PLUGIN_EVENT_IN      => Vlak voor verwerking van een binnengekomen event.
  // PLUGIN_SERIAL_IN     => Zodra er bytes via de seriele poort zijn ontvangen
  // PLUGIN_ETHERNET_IN   => Zodra er bytes via de seriele poort zijn ontvangen
  
  
  switch(function)
    {    
    #ifdef PLUGIN_011_CORE

    case PLUGIN_INIT:
      {
      Serial.println(F("*** debug: BRC Plugin started.")); //??? Debug
      break;
      }

    case PLUGIN_EVENT_IN:
      {
      Serial.println(F("*** debug: BRC: PLUGIN_EVENT_IN"));
      break;      
      }

    case PLUGIN_ONCE_A_SECOND:
      {
      break;
      }

    case PLUGIN_RAWSIGNAL_IN:
      {
      Serial.println(F("*** debug: BRC: PLUGIN_RAWSIGNAL_IN"));
      break;
      }
      
    case PLUGIN_COMMAND:
      {
      Serial.print(F("*** debug: BRC: PLUGIN_COMMAND"));
      Serial.print(", Par1=");    Serial.print(event->Par1);
      Serial.print(", Par2=");    Serial.println(event->Par2);
      
      // Als voorbeeld wordt hier variabele 5 gevuld met 123.45
      byte Variable = 5;
      float Value   = 123.45;

      ClearEvent(event);                                      // Ga uit van een default schone event. Oude eventgegevens wissen.      
      event->Type         = NODO_TYPE_COMMAND;                // Het event is een uit te voeren commando
      event->Command      = CMD_VARIABLE_SET;                 // Commando "VariableSet"
      event->Par1         = Variable;                         // Par1 draagt het variabelenummer
      event->Par2         = float2ul(Value);                  // Par2 de waarde. float2ul() zet de waarde m naar een geschikt format.
      
      success=true;                                           // Als verlaten wordt met een true, en er is een nieuw event in de struct geplaatst
                                                              // dan wordt deze automatisch uitgevoerd.
                                                              // Een plugin kan geen andere plugin aanroepen.
                                                              // verder is er geen beperking en kunnen alle events/commando's worden
                                                              // opgegeven voor verdere verwerking.
      break;
      }      

    #endif // CORE
    
    #if NODO_MEGA // alleen relevant voor een Nodo Mega want de Small heeft geen MMI!
    case PLUGIN_MMI_IN:
      {
      Serial.print(F("*** debug: BRC: PLUGIN_MMI_IN, string="));Serial.println(string); //??? Debug
      // Zodra er via een script, HTTP, Telnet of Serial een commando wordt ingevoerd, wordt dit deel van de code langs gelopen.
      // Op deze plek kan de invoer [string] worden geparsed en omgezet naar een struct [event]. Als parsen van de invoerstring [string]
      // is gelukt en de struct is gevuld, dan de variabele [success] vullen met true zodat de Nodo zorg kan dragen voor verdere verwerking van het event.

      char *TempStr=(char*)malloc(INPUT_COMMAND_SIZE);

      // Met PLUGIN_MMI_IN wordt de invoer van de gebruiker (string) omgezet naar een event zodat de Nodo deze intern kan verwerken.
      // Hier aangekomen bevat string het volledige commando. Test als eerste of het opgegeven commando overeen komt met PLUGIN_NAME
      // Dit is het eerste argument in het commando. 
      if(GetArgv(string,TempStr,1))
        {
        // Als het door de gebruiker ingegeven ommando/event overeenkomt met de naam van dit plugin...
        if(strcasecmp(TempStr,PLUGIN_NAME)==0)
          {
          // in dit voorbeeld even laten weten dat de code wordt geraakt. Directe output naar
          // Serial is normaal gesproken NIET wenselijk in een plugin. 

          // Vervolgens tweede parameter gebruiken
          if(GetArgv(string,TempStr,2)) 
            {
            // plaats hier je code die de eerste parameter die zich in [TempStr] bevindt verder uitparsed
            // De byte Par1 en unsigned long Par2 die zich in de struct [event] bevindt kunnen worden gebruikt.
              
            if(GetArgv(string,TempStr,3))
              {
              // indien gewenst kan een tweede parameter worden gebruikt (=derde argument)
              // Plaats wederom de code paar uitparsen van de parameter hier.
              // heb je het laatste parameter geparsen, dan de variabele [success] vullen 
              // met een true zodat verdere verwerking van het event plaats kan vinden.

              // Een plugin kan worden verwerkt als een commando of een event. Geef dit aan want 
              // op moment van invoer moet de Nodo t.b.v. latere verwerking weten hoe de zaken afgehandeld moeten worden
              event->Type    = NODO_TYPE_PLUGIN_COMMAND;
              event->Command = PLUGIN_ID; // nummer van dit plugin
              
              // Als success wordt gevuld met true, dan wordt het commando/event
              // geaccepteerd als geldig.
              
              success=true;
              }
            }
          }
        }
      free(TempStr);
      break;
      }

    case PLUGIN_MMI_OUT:
      {
      // De code die zich hier bevindt zorgt er voor dan een event met het unieke ID in de struct [event] weer wordt
      // omgezet naar een leesbaar event voor de gebruiker. het resultaat moet worden geplaatst in de string [string]
      // let op dat het totale commando niet meer dan 25 posities in beslag neemt.
      // Dit deel van de code wordt alleen uitgevoerd door een Nodo Mega, omdat alleen deze over een MMI beschikt.
      Serial.println(F("*** debug: BRC: PLUGIN_MMI_OUT")); //??? Debug

      strcpy(string,PLUGIN_NAME);               // Commando 
      strcat(string," ");
      strcat(string,int2str(event->Par1));      // Parameter-1 (8-bit)
      strcat(string,",");
      strcat(string,int2str(event->Par2));      // Parameter-2 (32-bit)

      break;
      }
    #endif //MMI
    }
  return success;
  }
コード例 #15
0
ファイル: Plugin_021.c プロジェクト: rtenklooster/ESPConnexio
boolean Plugin_021(byte function, struct NodoEventStruct *event, char *string)
  {
  boolean success=false;

  switch(function)
   {
   case PLUGIN_INIT:
     {
       LCD_I2C_init();
       break;
     }

  case PLUGIN_COMMAND:
     {
     byte Par2=event->Par2 & 0xff;		// Column
     byte Par3=event->Par2>>8 & 0xff;		// Data to display
     byte Par4=event->Par2>>16 & 0xff;		// In case of var, variable number
     boolean Print = true;

     if (event->Par1 >= 0 && event->Par1 <= PLUGIN_021_ROWS)
       {
       char TempString[80];
       TempString[0]=0;

       switch (Par3)
         {
           case 0:
           case CMD_RESET:
             if (event->Par1 == 0)
               LCD_I2C_clear();
             else
               LCD_I2C_printline(event->Par1-1,0, (char*)"");
             Print=false;
             break;

           case EVENT_BOOT:
             LCD_I2C_init();
             break;

           case VALUE_ON:
             _backlightval=LCD_BACKLIGHT;
             LCD_I2C_expanderWrite(0);
             Print=false;
             break;

           case VALUE_OFF:
             _backlightval=LCD_NOBACKLIGHT;
             LCD_I2C_expanderWrite(0);
             Print=false;
             break;

           case EVENT_MESSAGE:
             if ((Par4 > 0) && (Par4 <= LCDI2C_MSG_MAX))
               {
                 sprintf(TempString,"%s", LCDText_tabel[Par4-1]);
                 LCD_I2C_printline(event->Par1-1, Par2-1, TempString);
               }
             break;

           case EVENT_VARIABLE:
             if (Par4 > 0 && Par4 <16)
               {
                 int d1 = UserVar[Par4-1];            // Get the integer part
                 float f2 = UserVar[Par4-1] - d1;     // Get fractional part
                 int d2 = trunc(f2 * 10);   // Turn into integer
                 if (d2<0) d2=d2*-1;
                 sprintf(TempString,"%d.%01d", d1,d2);
                 LCD_I2C_printline(event->Par1-1, Par2-1, TempString);
               }
             break;

         }  // case

         //if (Print)
         //  LCD_I2C_printline(event->Par1-1, Par2-1, TempString);

         Wire.endTransmission(true);
         success=true;
       } // if

     break;
     }

   case PLUGIN_MMI_IN:
     {
     char *TempStr=(char*)malloc(INPUT_COMMAND_SIZE);
     
     if(GetArgv(string,TempStr,1))
       {
       if(strcasecmp(TempStr,PLUGIN_NAME_021)==0)
         {
         if(event->Par1 >= 0 && event->Par1 <= PLUGIN_021_ROWS)
           {

           if(GetArgv(string,TempStr,4))
               event->Par2|=str2cmd(TempStr)<<8;

           if(GetArgv(string,TempStr,5))
               event->Par2|=str2int(TempStr)<<16;

           event->Type = ESP_TYPE_PLUGIN_COMMAND;
           event->Command = PLUGIN_ID_021;
           success=true;
           }
         }
       }
     free(TempStr);
     break;
     }

   case PLUGIN_MMI_OUT:
     {
     //strcpy(string,PLUGIN_NAME_021);
     //strcat(string," ");
     //strcat(string,int2str(event->Par1));
     //strcat(string,",");
     //strcat(string,int2str(event->Par2 & 0xff));
     //strcat(string,",");
     //strcat(string,cmd2str(event->Par2>>8 & 0xff));
     //strcat(string,",");
     //strcat(string,int2str(event->Par2>>16 & 0xff));
     sprintf(string,"%s",PLUGIN_NAME_021);
     sprintf(string,"%s%s",string," ");
     sprintf(string,"%s%s",string,int2str(event->Par1));
     sprintf(string,"%s%s",string,",");
     sprintf(string,"%s%s",string,int2str(event->Par2 & 0xff));
     sprintf(string,"%s%s",string,",");
     sprintf(string,"%s%s",string,cmd2str(event->Par2>>8 & 0xff));
     sprintf(string,"%s%s",string,",");
     sprintf(string,"%s%s",string,int2str(event->Par2>>16 & 0xff));
     break;
     }
 }      
 return success;
}
コード例 #16
0
int OGRGPSBabelDataSource::Open( const char * pszDatasourceName,
                                 const char* pszGPSBabelDriverNameIn,
                                 char** papszOpenOptionsIn )

{
    if (!STARTS_WITH_CI(pszDatasourceName, "GPSBABEL:"))
    {
        CPLAssert(pszGPSBabelDriverNameIn);
        pszGPSBabelDriverName = CPLStrdup(pszGPSBabelDriverNameIn);
        pszFilename = CPLStrdup(pszDatasourceName);
    }
    else
    {
        if( CSLFetchNameValue(papszOpenOptionsIn, "FILENAME") )
            pszFilename = CPLStrdup(CSLFetchNameValue(papszOpenOptionsIn,
                                                      "FILENAME"));

        if( CSLFetchNameValue(papszOpenOptionsIn, "GPSBABEL_DRIVER") )
        {
            if( pszFilename == NULL )
            {
                CPLError(CE_Failure, CPLE_AppDefined, "Missing FILENAME");
                return FALSE;
            }

            pszGPSBabelDriverName
                = CPLStrdup(CSLFetchNameValue(papszOpenOptionsIn, "DRIVER"));

            /* A bit of validation to avoid command line injection */
            if (!IsValidDriverName(pszGPSBabelDriverName))
                return FALSE;
        }
    }

    pszName = CPLStrdup( pszDatasourceName );

    bool bExplicitFeatures = false;
    bool bWaypoints = true;
    bool bTracks = true;
    bool bRoutes = true;

    if (pszGPSBabelDriverName == NULL)
    {
        const char* pszSep = strchr(pszDatasourceName + 9, ':');
        if (pszSep == NULL)
        {
            CPLError( CE_Failure, CPLE_AppDefined,
                      "Wrong syntax. Expected GPSBabel:driver_name:file_name");
            return FALSE;
        }

        pszGPSBabelDriverName = CPLStrdup(pszDatasourceName + 9);
        *(strchr(pszGPSBabelDriverName, ':')) = '\0';

        /* A bit of validation to avoid command line injection */
        if (!IsValidDriverName(pszGPSBabelDriverName))
            return FALSE;

        /* Parse optional features= option */
        if (STARTS_WITH_CI(pszSep+1, "features="))
        {
            const char* pszNextSep = strchr(pszSep+1, ':');
            if (pszNextSep == NULL)
            {
                CPLError(CE_Failure, CPLE_AppDefined,
                        "Wrong syntax. Expected "
                         "GPSBabel:driver_name[,options]*:["
                         "features=waypoints,tracks,routes:]file_name");
                return FALSE;
            }

            char* pszFeatures = CPLStrdup(pszSep+1+9);
            *strchr(pszFeatures, ':') = 0;
            char** papszTokens = CSLTokenizeString(pszFeatures);
            char** papszIter = papszTokens;
            bool bErr = false;
            bExplicitFeatures = true;
            bWaypoints = false;
            bTracks = false;
            bRoutes = false;
            while(papszIter && *papszIter)
            {
                if (EQUAL(*papszIter, "waypoints"))
                    bWaypoints = true;
                else if (EQUAL(*papszIter, "tracks"))
                    bTracks = true;
                else if (EQUAL(*papszIter, "routes"))
                    bRoutes = true;
                else
                {
                    CPLError( CE_Failure, CPLE_AppDefined,
                              "Wrong value for 'features' options");
                    bErr = true;
                }
                papszIter++;
            }
            CSLDestroy(papszTokens);
            CPLFree(pszFeatures);

            if (bErr)
                return FALSE;

            pszSep = pszNextSep;
        }

        if( pszFilename == NULL )
            pszFilename = CPLStrdup(pszSep+1);
    }

    const char* pszOptionUseTempFile = CPLGetConfigOption("USE_TEMPFILE", NULL);
    if (pszOptionUseTempFile && CPLTestBool(pszOptionUseTempFile))
        osTmpFileName = CPLGenerateTempFilename(NULL);
    else
        osTmpFileName.Printf("/vsimem/ogrgpsbabeldatasource_%p", this);

    bool bRet = false;
    if (IsSpecialFile(pszFilename))
    {
        /* Special file : don't try to open it */
        char** argv = GetArgv(bExplicitFeatures, bWaypoints, bRoutes,
                              bTracks, pszGPSBabelDriverName, pszFilename);
        VSILFILE* tmpfp = VSIFOpenL(osTmpFileName.c_str(), "wb");
        bRet = (CPLSpawn(argv, NULL, tmpfp, TRUE) == 0);
        VSIFCloseL(tmpfp);
        tmpfp = NULL;
        CSLDestroy(argv);
        argv = NULL;
    }
    else
    {
        VSILFILE* fp = VSIFOpenL(pszFilename, "rb");
        if (fp == NULL)
        {
            CPLError(CE_Failure, CPLE_AppDefined,
                    "Cannot open file %s", pszFilename);
            return FALSE;
        }

        char** argv = GetArgv(bExplicitFeatures, bWaypoints, bRoutes,
                              bTracks, pszGPSBabelDriverName, "-");

        VSILFILE* tmpfp = VSIFOpenL(osTmpFileName.c_str(), "wb");

        CPLPushErrorHandler(CPLQuietErrorHandler);
        bRet = (CPLSpawn(argv, fp, tmpfp, TRUE) == 0);
        CPLPopErrorHandler();

        CSLDestroy(argv);
        argv = NULL;

        CPLErr nLastErrorType = CPLGetLastErrorType();
        CPLErrorNum nLastErrorNo = CPLGetLastErrorNo();
        CPLString osLastErrorMsg = CPLGetLastErrorMsg();

        VSIFCloseL(tmpfp);
        tmpfp = NULL;

        VSIFCloseL(fp);
        fp = NULL;

        if (!bRet)
        {
            if ( strstr(osLastErrorMsg.c_str(),
                        "This format cannot be used in piped commands") == NULL)
            {
                CPLError( nLastErrorType, nLastErrorNo, "%s",
                          osLastErrorMsg.c_str());
            }
            else
            {
                VSIStatBuf sStatBuf;
                if (VSIStat(pszFilename, &sStatBuf) != 0)
                {
                    CPLError( CE_Failure, CPLE_NotSupported,
                              "Driver %s only supports real (non virtual) "
                              "files",
                              pszGPSBabelDriverName );
                    return FALSE;
                }

                /* Try without piping in */
                argv = GetArgv(bExplicitFeatures, bWaypoints, bRoutes,
                              bTracks, pszGPSBabelDriverName, pszFilename);
                tmpfp = VSIFOpenL(osTmpFileName.c_str(), "wb");
                bRet = (CPLSpawn(argv, NULL, tmpfp, TRUE) == 0);
                VSIFCloseL(tmpfp);
                tmpfp = NULL;

                CSLDestroy(argv);
                argv = NULL;
            }
        }
    }


    if (bRet)
    {
        poGPXDS = static_cast<GDALDataset *>(
            GDALOpenEx( osTmpFileName.c_str(),
                        GDAL_OF_VECTOR, NULL, NULL, NULL ) );
        if (poGPXDS)
        {
            if (bWaypoints)
            {
                OGRLayer* poLayer = poGPXDS->GetLayerByName("waypoints");
                if (poLayer != NULL && poLayer->GetFeatureCount() != 0)
                    apoLayers[nLayers++] = poLayer;
            }

            if (bRoutes)
            {
                OGRLayer* poLayer = poGPXDS->GetLayerByName("routes");
                if (poLayer != NULL && poLayer->GetFeatureCount() != 0)
                    apoLayers[nLayers++] = poLayer;
                poLayer = poGPXDS->GetLayerByName("route_points");
                if (poLayer != NULL && poLayer->GetFeatureCount() != 0)
                    apoLayers[nLayers++] = poLayer;
            }

            if (bTracks)
            {
                OGRLayer* poLayer = poGPXDS->GetLayerByName("tracks");
                if (poLayer != NULL && poLayer->GetFeatureCount() != 0)
                    apoLayers[nLayers++] = poLayer;
                poLayer = poGPXDS->GetLayerByName("track_points");
                if (poLayer != NULL && poLayer->GetFeatureCount() != 0)
                    apoLayers[nLayers++] = poLayer;
            }
        }
    }

    return nLayers > 0;
}
コード例 #17
0
ファイル: Plugin_098.c プロジェクト: ESP8266nu/NodoClassic
boolean Plugin_098(byte function, struct NodoEventStruct *event, char *string)
{
  boolean success=false;

  switch(function)
  {
#ifdef PLUGIN_098_CORE

  #if NODO_MEGA
  case PLUGIN_COMMAND:
    {
					  // Par 1 ='command/type'
      byte Par2=event->Par2 & 0xff;	  // Par 2 = Variabel nr or 0=Off, 1=On 
      byte Par3=event->Par2>>8 & 0xff; 	  // Par 3 = sensortype
      byte Par4=event->Par2>>16 & 0xffff; // Par 4 = IDX

      byte x;
      char *HttpRequest=(char*)malloc(INPUT_LINE_SIZE+1);

      if (event->Par1 == CMD_VARIABLE_SEND)
        {
          if (Par3 == 1)			// Single value Sensor
            {
              strcpy(HttpRequest,"/json.htm?type=command&param=udevice&idx=");
              strcat(HttpRequest,int2str(Par4));
              strcat(HttpRequest,"&nvalue=0&svalue=");
              //strcat(HttpRequest,int2str(UserVar[Par2-1]));
              dtostrf(UserVar[Par2-1], 0, 2,HttpRequest+strlen(HttpRequest));
            }

          if (Par3 == 10)		// switch
            {
              strcpy(HttpRequest,"/json.htm?type=command&param=switchlight&idx=");
              strcat(HttpRequest,int2str(Par4));
              strcat(HttpRequest,"&switchcmd=");
              if (Par3==1)
                strcat(HttpRequest,"On");
              else
                strcat(HttpRequest,"Off");
              strcat(HttpRequest,"&level=0");
            }

        }

      if (event->Par1 == CMD_VARIABLE_GET)
        {
          if (Par3 == 1)			// Get Sensor Data
            {
              strcpy(HttpRequest,"/json.htm?type=devices&rid=");
              strcat(HttpRequest,int2str(Par4));
            }
        }

      x=P098SendCustomHTTPRequest(HttpRequest,PLUGIN_098_IP,PLUGIN_098_PORT,Par2);
      free(HttpRequest);

      success=true;
      break;
     }
  #endif

#endif // PLUGIN_098_CORE

   #if NODO_MEGA
   case PLUGIN_MMI_IN:
     {
     char *TempStr=(char*)malloc(INPUT_COMMAND_SIZE);
     if(GetArgv(string,TempStr,1))
       {
       if(strcasecmp(TempStr,PLUGIN_NAME)==0)
         {
           if(GetArgv(string,TempStr,3))
               event->Par2=str2int(TempStr);

           if(GetArgv(string,TempStr,4))
               event->Par2|=str2int(TempStr)<<8;

           if(GetArgv(string,TempStr,5))
               event->Par2|=str2int(TempStr)<<16;

           event->Type = NODO_TYPE_PLUGIN_COMMAND;
           event->Command = PLUGIN_ID; // Plugin nummer  
           success=true;
         }
       }
     free(TempStr);
     break;
     }

   case PLUGIN_MMI_OUT:
     {
     strcpy(string,PLUGIN_NAME);            // Eerste argument=het commando deel
     strcat(string," ");
     strcat(string,cmd2str(event->Par1));
     strcat(string,",");
     strcat(string,int2str(event->Par2 & 0xff));
     strcat(string,",");
     strcat(string,int2str(event->Par2>>8 & 0xff));
     strcat(string,",");
     strcat(string,int2str(event->Par2>>16 & 0xffff));
     break;
     }
   #endif //NODO_MEGA

  }

  return success;
}