All Downloads are FREE. Search and download functionalities are using the official Maven repository.

ch.epfl.gsn.wrappers.ieee1451.TEDS Maven / Gradle / Ivy

The newest version!
/**
* Global Sensor Networks (GSN) Source Code
* Copyright (c) 2006-2016, Ecole Polytechnique Federale de Lausanne (EPFL)
* 
* This file is part of GSN.
* 
* GSN is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
* 
* GSN is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
* GNU General Public License for more details.
* 
* You should have received a copy of the GNU General Public License
* along with GSN.  If not, see .
* 
* File: src/ch/epfl/gsn/wrappers/ieee1451/TEDS.java
*
* @author Ali Salehi
*
*/

package ch.epfl.gsn.wrappers.ieee1451;

import java.util.Hashtable;
import java.util.Vector;

public class TEDS {
   
   /**
    * Holds the meta data for a transducer. One is a Record to hand out to
    * getMetaData() requests while the other is a Vector to provide number based
    * indexing.
    */
   public Record       metaData       = new Record( );
   
   /**
    * A list of all the current meta data for the TIM. Index zero contains meta
    * data for the TIM itself.
    */
   protected Vector    metaDataVector = new Vector( );
   
   /**
    * A helper object containing a mapping from channel name to channel number.
    */
   protected Hashtable namesToChan    = new Hashtable( );
   
   public TEDS ( Object teds[][][] ) {
      
      for ( int ch = 0 ; ch < teds.length ; ch++ ) {
         Object rawChanTeds[][] = teds[ ch ];
         Measurement chanTeds = new Measurement( );
         for ( int i = 0 ; i < rawChanTeds.length ; i++ ) {
            chanTeds.put( ( String ) rawChanTeds[ i ][ 0 ] , rawChanTeds[ i ][ 1 ] );
         }
         addChannelTeds( ch , chanTeds );
      }
   }
   
   /**
    * Add a channel of meta data to the overall meta data collection. Also
    * update the internal namesToChan hashtable for quick lookup later.
    * 
    * @param chNum - The integer channel number used for reads. Use -1 to allow
    * automatic number incrementing and replacment of duplicate channel name
    * teds.
    * @param chanMetaData - The meta data for this channel
    */
   @SuppressWarnings( "unchecked" )
   public synchronized void addChannelTeds ( int chNum , Measurement chanMetaData ) {
      String name = chanMetaData.getString( MeasAttr.NAME );
      
      if ( chNum == -1 && ( metaDataVector.size( ) == 0 ) ) chNum = 0;
      
      if ( chNum == 0 ) {
         chanMetaData.put( MeasAttr.METADATA_TYPE , MeasAttr.METADATA_T_TIM );
      } else {
         chanMetaData.put( MeasAttr.METADATA_TYPE , MeasAttr.METADATA_T_CHANNEL );
      }
      chanMetaData.lock( );
      
      // // test to see if the name is already added. This is a fatal error if
      // // chNum!= -1 as we cannot have two channels with the same name
      // Object test = metaData.get(name);
      // if (test != null) {
      // if (chNum != -1) {
      // String msg = "Duplicate channel name for " + name;
      // ArrayStoreException e = new ArrayStoreException(msg);
      // // log.log(Log.SEVERE, msg, e);
      // throw e;
      // } else {
      // // We have a duplicate name. Replace this chan teds with the new
      // // chan teds.
      // Integer chan = (Integer) namesToChan.get(name);
      // if (chan != null)
      // chNum = chan.intValue();
      // }
      // }
      metaData.put( name , chanMetaData );
      
      // Check for auto chan numbering
      if ( chNum == -1 ) chNum = metaDataVector.size( );
      
      // check to see if we need to grow the vector
      if ( chNum >= metaDataVector.size( ) ) metaDataVector.setSize( chNum + 1 );
      metaDataVector.setElementAt( chanMetaData , chNum );
      namesToChan.put( new Integer( chNum ) , name );
   }
   
   public int NumberOfChannels ( ) {
      return namesToChan.size( );
   }
   
   public ArgArray GetChannel ( int channelNo ) {
      return ( ArgArray ) metaData.get( namesToChan.get( new Integer( channelNo ) ).toString( ) );
      
   }
   
   public String toString ( ) {
      return metaData.toString( );
   }
   
   public String toHtmlString ( ) {
      return metaData.toHtmlString( );
   }
   
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy