Project

General

Profile

Revision 425

compatibility updates with colonet server

View differences:

trunk/code/projects/colonet/ColonetGUI/Colonet.java
594 594
	* @see ColonetServerInterface#sendXBeeIDRequest()
595 595
	*/
596 596
	public void parseXBeeIDs (String line) {
597
		//TODO: check if this string actually has xbee command codes
598
		System.out.println("Got XBee ID String: \n" + line);
599 597
	
600 598
		String [] str = line.split(" ");
601 599
		int num = Integer.parseInt(str[2]);
......
628 626
	* @see ColonetServerInterface#sendBatteryRequest(int)
629 627
	*/
630 628
	public void parseBattery (String line) {
631
		System.out.println("Got battery update: " + line);
632 629
		String [] str = line.split(" ");
633
		int botNum = (int) line.charAt(4);
634
		int batteryVal = (int) line.charAt(6);
635
		if (cmbRobotNum != null && cmbRobotNum.getSelectedIndex()-1 == botNum) {
636
			//TODO: update battery info graphically
630
		int botNum = Integer.parseInt(str[2]);
631
		int level = Integer.parseInt(str[3]);
632
		int selectedBot = 0;
633
		try { 
634
		    selectedBot = Integer.parseInt((String)cmbRobotNum.getSelectedItem());
635
		} catch (Exception e) {
637 636
		}
638
		// For now, just update the bar whenever we get an update.
639
		batteryIcon.setLevel((int) (100.0 * batteryVal / 255));
637
		if (selectedBot == botNum) {
638
			batteryIcon.setLevel(level);
639
		}
640 640
	}
641 641
	
642 642
	//
......
920 920
	*
921 921
	*/
922 922
	class DataUpdater extends Thread {
923
		final int DATAUPDATER_DELAY = 4000;
923
		final int DATAUPDATER_DELAY = 2200;
924 924
		
925 925
		public DataUpdater () {
926 926
			super("Colonet DataUpdater");
......
933 933
					//request more data
934 934
					if (csi != null && csi.isReady()) {
935 935
						//csi.sendSensorDataRequest();
936
						//csi.sendXBeeIDRequest();
937
						if (cmbRobotNum.getSelectedIndex() > 0)
938
							csi.sendBatteryRequest(cmbRobotNum.getSelectedIndex()-1);
939
						else
936
						csi.sendXBeeIDRequest();
937
						if (cmbRobotNum.getSelectedIndex() > 0) {
938
						    String sel = (String) cmbRobotNum.getSelectedItem();
939
						    int num = Integer.parseInt(sel);
940
							csi.sendBatteryRequest(num);
941
						} else {
940 942
							csi.sendBatteryRequest(200);
943
						}
941 944
					}
942 945
					Thread.sleep(DATAUPDATER_DELAY);
943 946
				} catch (InterruptedException e) {
......
1243 1246
		public void sendToServer () {
1244 1247
			System.out.println("Attempting to send angle = " + getAngle() + ", speed = " + getSpeed() + "");
1245 1248
			String dest = ColonetServerInterface.GLOBAL_DEST;
1246
			if (cmbRobotNum != null && cmbRobotNum.getSelectedIndex() > 0)
1247
				dest = "" + (cmbRobotNum.getSelectedIndex()-1);
1249
			if (cmbRobotNum != null && cmbRobotNum.getSelectedIndex() > 0) {
1250
				dest = (String)cmbRobotNum.getSelectedItem();
1251
			}
1248 1252
			
1249 1253
			if (csi != null) {
1250 1254
				/*
......
1440 1444
	        g2d.drawString(level + "%", greenX + greenWidth/2 - 10, greenY + greenHeight/2 + 5);
1441 1445
	        
1442 1446
	        g2d.dispose();
1447
	        System.out.println("Painted icon");
1443 1448
	    }
1444 1449
	    
1445 1450
		/**
......
1450 1455
		*/
1451 1456
	    public void setLevel(int newLevel) {
1452 1457
	    	level = convert(newLevel);
1458
	    	repaint();
1459
	    	System.out.println("Updated level to " + level);
1453 1460
	    }
1454 1461
		
1455 1462
	    public int getIconWidth() {
......
1470 1477
		*/
1471 1478
		private int convert (int level) {
1472 1479
			// TODO: make this a forreals conversion.
1473
			return (int) (1.0 * level / 255);
1480
			return (int) (100.0 * level / 128);
1474 1481
		}
1475 1482
		
1476 1483
	}
trunk/code/projects/colonet/ColonetGUI/ColonetServerInterface.java
314 314
	* @see Colonet#parseXBeeIDs(String)
315 315
	*/
316 316
	public void sendXBeeIDRequest () {
317
		System.out.println("Sending XBee ID request");
318 317
		sendRequest(ColonetServerInterface.REQUEST_XBEE_IDS, "");
319 318
	}
320 319
	
......
331 330
	* @see Colonet#parseBattery(String)
332 331
	*/
333 332
	public void sendBatteryRequest (int robotNum) {
334
		sendData(ColonetServerInterface.BATTERY, "" + robotNum);
333
		//create packet
334
		String packet = "";
335
		packet += ColonetServerInterface.SEND_TO_ROBOT;
336
		packet += " " + robotNum;
337
		packet += " " + ColonetServerInterface.COLONET_REQUEST;
338
		packet += " " + ColonetServerInterface.BATTERY;  //add  the command code here
339
		packet += "\n";
340
		sendString(packet);
335 341
	}
336 342
	
337 343
	/*
......
485 491
				ColonetServerInterface.REQUEST_XBEE_IDS))
486 492
				colonet.parseXBeeIDs(line);
487 493
			// Battery
488
			else if (line.charAt(0) == Integer.parseInt(ColonetServerInterface.RESPONSE_TO_CLIENT_REQUEST)
489
				&& line.charAt(2) == Integer.parseInt(ColonetServerInterface.BATTERY))
490
				colonet.parseBattery(line);
491
			/*
492 494
			else if (line.startsWith(ColonetServerInterface.RESPONSE_TO_CLIENT_REQUEST + " " +
493 495
				ColonetServerInterface.BATTERY))
494 496
				colonet.parseBattery(line);
495
			*/
496 497
			// Unknown type
497 498
			else
498 499
				System.out.println("Got data:" + line);

Also available in: Unified diff