Package it.hakvoort.neuroclient.agent

Source Code of it.hakvoort.neuroclient.agent.EEGAgent

package it.hakvoort.neuroclient.agent;

import it.hakvoort.neuroclient.NeuroServerHeader;
import it.hakvoort.neuroclient.NeuroServerPacket;
import it.hakvoort.neuroclient.NeuroServerConnection.Command;
import it.hakvoort.neuroclient.reply.HeaderReply;
import it.hakvoort.neuroclient.reply.Reply;
import it.hakvoort.neuroclient.reply.Reply.ResponseCode;

/**
*
* @author Gido Hakvoort (gido@hakvoort.it)
*
*/
public class EEGAgent extends DefaultAgent {

  public EEGAgent() {
    super();
  }

  public EEGAgent(String HOST) {
    super(HOST);
  }
 
  public EEGAgent(String HOST, int PORT) {
    super(HOST, PORT);
  }
 
  protected void init() {
    setRole(Role.EEG);
  }
 
  public Reply setHeader(NeuroServerHeader header) {
    if(!header.isValid()) {
      System.err.println(String.format("Header not valid."));
      return new HeaderReply(ResponseCode.ERROR, null);
    }
   
    return executeCommand(Command.SET_HEADER, header.getData());
  }
 
  public void sendPacket(NeuroServerPacket packet) {
    // expect: 200 OK, but we don't care cause we don't want this function to block.
    // send it direct to the connection
    current = Command.SEND_PACKET;
    connection.sendCommand(Command.SEND_PACKET, packet.toString());
  }
 
  @Override
  public void receivedLine(String line) {
    switch(current) {
      case SEND_PACKET:
        // do nothing
        break;
      default:
        super.receivedLine(line);
    }
  }
}
TOP

Related Classes of it.hakvoort.neuroclient.agent.EEGAgent

TOP
Copyright © 2018 www.massapi.com. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.