Revision 52
Updated libwireless to include new token ring functions.
wl_token_ring.c | ||
---|---|---|
70 | 70 |
//queue containing ids of interruption requests |
71 | 71 |
Queue* interrupting = NULL; |
72 | 72 |
|
73 |
//current robot to check in the iterator |
|
74 |
int iteratorCount = 0; |
|
75 |
|
|
73 | 76 |
#ifdef ROBOT |
74 | 77 |
void (*bom_on_function) (void) = bom_on; |
75 | 78 |
void (*bom_off_function) (void) = bom_off; |
... | ... | |
705 | 708 |
} |
706 | 709 |
|
707 | 710 |
/** |
711 |
* Returns the number of robots in the token ring. |
|
712 |
* |
|
713 |
* @return the number of robots in the token ring |
|
714 |
**/ |
|
715 |
int wl_token_get_robots_in_ring(void) |
|
716 |
{ |
|
717 |
return sensor_matrix_get_joined(sensorMatrix); |
|
718 |
} |
|
719 |
|
|
720 |
/** |
|
721 |
* Returns true if the specified robot is in the token ring, false |
|
722 |
* otherwise. |
|
723 |
* |
|
724 |
* @param robot the robot to check for whether it is in the token ring |
|
725 |
* @return nonzero if the robot is in the token ring, zero otherwise |
|
726 |
**/ |
|
727 |
int wl_token_is_robot_in_ring(int robot) |
|
728 |
{ |
|
729 |
return sensor_matrix_get_in_ring(sensorMatrix, robot); |
|
730 |
} |
|
731 |
|
|
732 |
/** |
|
733 |
* Begins iterating through the robots in the token ring. |
|
734 |
* |
|
735 |
* @see wl_token_iterator_has_next, wl_token_iterator_next |
|
736 |
**/ |
|
737 |
void wl_token_iterator_begin(void) |
|
738 |
{ |
|
739 |
int i; |
|
740 |
iteratorCount = 0; |
|
741 |
while (!sensor_matrix_get_in_ring(sensorMatrix, i) && |
|
742 |
i < sensor_matrix_get_size(sensorMatrix)) |
|
743 |
i++; |
|
744 |
if (i == sensor_matrix_get_size(sensorMatrix)) |
|
745 |
i = -1; |
|
746 |
} |
|
747 |
|
|
748 |
/** |
|
749 |
* Returns true if there are more robots in the token ring |
|
750 |
* to iterate through, and false otherwise. |
|
751 |
* |
|
752 |
* @return nonzero if there are more robots to iterate through, |
|
753 |
* zero otherwise |
|
754 |
* |
|
755 |
* @see wl_token_iterator_begin, wl_token_iterator_next |
|
756 |
**/ |
|
757 |
int wl_token_iterator_has_next(void) |
|
758 |
{ |
|
759 |
return iteratorCount == -1; |
|
760 |
} |
|
761 |
|
|
762 |
/** |
|
763 |
* Returns the next robot ID in the token ring. |
|
764 |
* |
|
765 |
* @return the next robot ID in the token ring, or -1 if none exists |
|
766 |
* |
|
767 |
* @see wl_token_iterator_begin, wl_token_iterator_has_next |
|
768 |
**/ |
|
769 |
int wl_token_iterator_next(void) |
|
770 |
{ |
|
771 |
int result = iteratorCount; |
|
772 |
if (result < 0) |
|
773 |
return result; |
|
774 |
|
|
775 |
iteratorCount++; |
|
776 |
while (!sensor_matrix_get_in_ring(sensorMatrix, iteratorCount) && |
|
777 |
iteratorCount < sensor_matrix_get_size(sensorMatrix)) |
|
778 |
iteratorCount++; |
|
779 |
if (iteratorCount == sensor_matrix_get_size(sensorMatrix)) |
|
780 |
iteratorCount = -1; |
|
781 |
return result; |
|
782 |
} |
|
783 |
|
|
784 |
/** |
|
708 | 785 |
* Called when we receive a request to interrupt the token ring. |
709 | 786 |
* We add the robot to our list of interrupt requests, |
710 | 787 |
* and will send the token to this robot when we next receive the |
Also available in: Unified diff