class Plug

Public Instance Methods

add_stat(msg, type, dir) click to toggle source
# File Entities/Plug.rb, line 84
def add_stat(msg, type, dir)
  PlugStats.create(time: Time.now, msg: msg, msg_type: [type],
                   msg_dir: [dir], plug: self)
end
new_sms(sms) click to toggle source
# File Entities/Plug.rb, line 65
def new_sms(sms)
  add_stat(sms._msg, :sms, :rcv)
  log_msg :Plug, "Got new sms #{sms.inspect}"
  case sms._msg
    when /^stat: (.*): (.*) :: (.*) :: (.*)/
      host, state, disk, time = $1, $2, $3, $4
      _, _, _, internet, credit = state.split(':')
      dputs(2) { "Host #{host} has state #{state}" }
      self.internal_id = host
      if internet != 'noop'
        self.internet_left = internet.gsub(/[^0-9]/, '').to_i * 1_000_000
        self.credit = credit
        dputs(2) { "Host #{host} has #{internet} Bytes and #{self.credit} left" }
      end
    else
      log_msg :Plut, "Unknown message from #{host}"
  end
end
send_cmd_sms(*cmds) click to toggle source
# File Entities/Plug.rb, line 50
def send_cmd_sms(*cmds)
  return unless telephone.to_s.length > 0 &&
      !$MobileControl.operator_missing?
  msg = "cmd: #{cmds.join('::')}"
  add_stat(msg, :sms, :send)
  $MobileControl.device.sms_send(telephone.to_s, msg)
end
send_credit(amount) click to toggle source
# File Entities/Plug.rb, line 58
def send_credit(amount)
  return unless telephone.to_s.length > 0 &&
      !$MobileControl.operator_missing?
  add_stat(amount.to_s, :credit, :send)
  $MobileControl.operator.credit_send(telephone.to_s, amount)
end