static void Main(string[] args) { EZRoboNetDevice netdev = new EZRoboNetDevice(1, (byte)t_Robot.t_Station); // creating a network device as a station rnd = new Random((int)DateTime.Now.Ticks); MyRobot myrobot = new MyRobot(netdev, 2, // this is the ID of the robot which MyRobot controls (in this case it is the arduino, and its assigned id is 2) rnd // this is an unused/useless parameter for now... ); // send something out // sending a sample answer CommandMsg outmsg = new CommandMsg(); outmsg.robot = t_Robot.t_Station; outmsg.Cmd = RobotCmd.rc_ManualCommand; outmsg.CmdParams = new byte[] { (byte)'H', (byte)'E', (byte)'L', (byte)'L', (byte)'O' }; outmsg.ParamsLength = (byte)outmsg.CmdParams.Length; // 5 bytes // send it myrobot.sendCommandMessage(outmsg); while (true) { Application.DoEvents(); } }
public MyRobot(EZRoboNetDevice netdevice, // the robonet device byte avatarnodeid, // an id for the robot Random randgen // and a random number generator (not necessary. residual parameter from early implementations) ) : base(netdevice, avatarnodeid, randgen) { // initialize your robot here }
public EZStationPacketFSM(EZRoboNetDevice device, EZFrame frame) { // registering the Net Device NetDevice = device; // capturing time of first reception ReceptionStartTime = DateTime.Now; // acknowledging NetDevice.sendAcknowledge(PacketSenderID); // retrieving sender id PacketSenderID = frame.SenderID; // calculating total packet length ushort packetlength = (ushort)(frame.Payload[3] + 256 * frame.Payload[4] + 5); CurrentPacketLength = packetlength; // calculating total number of frames required for full packet transmission TotalFrames = packetlength / EZRoboNetDevice.MAX_FRAME_PAYLOAD_LENGTH + 1; // allocating memory space for the packet being received CurrentPacket = new byte[packetlength]; // now filling initial space in CurrentPacket int i; for (i = 0; i < frame.PayloadLength; i++) { CurrentPacket[i] = frame.Payload[i]; } // done copying // setting number of frames received to 1 FramesReceived = 1; // sending an acknowledgement frame NetDevice.sendAcknowledge(frame.SenderID); if (FramesReceived < TotalFrames) { // need to receive more state = EZRoboNetDevice.stReceiving; // marrking time of acknowledgement FrameReceptionStartTime = DateTime.Now; } else { state = EZRoboNetDevice.stPacketReady; FramesReceived = 0; TotalFrames = 0; } }
public RoboEntity(EZRoboNetDevice netdevice, byte avatarnodeid, Random randgen) { NetDevice = netdevice; AvatarNodeID = avatarnodeid; // assigning random generator RandGen = randgen; // initializing the timer SyncTimer = new Timer(); SyncTimer.Interval = 500; // 0.5 s interval SyncTimer.Elapsed += handleMessages; // initializing the incoming packet queue ReceivedPackets = new EZPacket[MAX_RECEIVED_PACKETS_NUM]; ReceivedPacketsNum = 0; // registering the entity to the NetDevice server EntityID = NetDevice.registerEntity(this); // starting the Timer SyncTimer.Start(); }