##################  buildmodel.rb -- brent@mbari.org  ######################
# $Source: /home/cvs/ESP/gen2/software/esp/admin/buildmodel.rb,v $
#    Copyright (C) 2004 MBARI
#    MBARI Proprietary Information. All rights reserved.
# $Id: buildmodel.rb,v 1.6 2005/11/01 07:42:26 brent Exp $
#
#  common code for setting up simulation modes
#
############################################################################

require 'base'

module ESP

  class ModelPart < Hash
  #behaviors for each model component
  #(typically maps to individual dwarves)

    def add (typ, *args)
    #add classSym to Model with specified .new args
      modelType = typ.const_get(:Model)
      store modelType, modelType.new(*args)
      self
    end
  end

  #environmental parameters shared among all model parts
  Environment = Struct.new nil, :temperature, :voltage
  Ambient = Environment.new(18, 12)  #can be changed at any time

  Model=ModelPart.new
                
  I2C::DwarfAdr.each {|name, address|
    Model[name]=model=ModelPart[Environment=>Ambient].
      add(I2C::Servo).
      add(I2C::Solenoid).
      add(I2C::Shaft).
      add(I2C::Thermal)
    I2C::Dwarf[name] = dwarfTarget = I2C::Target.new(name, I2C::DwarfParser,
                       I2C::DwarfNet, :address=>address.last, :model=>model)
    MsgTarget[name]=[address.first, dwarfTarget]
  }
  
end

I2C.buildControllers
