nstat.c
Go to the documentation of this file.
00001 /*------------------------------------------------------------------------
00002  *---------------------           RT-WMP              --------------------
00003  *------------------------------------------------------------------------
00004  *                                                         V7.0B  11/05/10
00005  *
00006  *
00007  *  File: ./src/core/nstat.c
00008  *  Authors: Danilo Tardioli
00009  *  ----------------------------------------------------------------------
00010  *  Copyright (C) 2000-2010, Universidad de Zaragoza, SPAIN
00011  *
00012  *  Contact Addresses: Danilo Tardioli                   dantard@unizar.es
00013  *
00014  *  RT-WMP is free software; you can  redistribute it and/or  modify it
00015  *  under the terms of the GNU General Public License  as published by the
00016  *  Free Software Foundation;  either  version 2, or (at  your option) any
00017  *  later version.
00018  *
00019  *  RT-WMP  is distributed  in the  hope  that  it will be   useful, but
00020  *  WITHOUT  ANY  WARRANTY;     without  even the   implied   warranty  of
00021  *  MERCHANTABILITY  or  FITNESS FOR A  PARTICULAR PURPOSE.    See the GNU
00022  *  General Public License for more details.
00023  *
00024  *  You should have received  a  copy of  the  GNU General Public  License
00025  *  distributed with RT-WMP;  see file COPYING.   If not,  write to the
00026  *  Free Software  Foundation,  59 Temple Place  -  Suite 330,  Boston, MA
00027  *  02111-1307, USA.
00028  *
00029  *  As a  special exception, if you  link this  unit  with other  files to
00030  *  produce an   executable,   this unit  does  not  by  itself cause  the
00031  *  resulting executable to be covered by the  GNU General Public License.
00032  *  This exception does  not however invalidate  any other reasons why the
00033  *  executable file might be covered by the GNU Public License.
00034  *
00035  *----------------------------------------------------------------------*/
00036 
00037 /* X7 X6 X5 X4 X3 X2 X1 X0
00038 * X4 X3 X2 X1 X0 => Node that have to search
00039 * X5 : 1 : BC Reached
00040 * X6 : 1 : Lost
00041 * X7 : 0 Unreached 1: Reached
00042 */
00043 #include "include/nstat.h"
00044 unsigned char * nstat;
00045 
00046 void  init_nstat(int size){
00047         int i;
00048         nstat= (unsigned char *) MALLOC(sizeof(char)*size);
00049         for (i=0;i<size;i++){
00050                 nstat[i]=0;
00051         }
00052 }
00053 
00054 void  free_nstat(){
00055         FREE(nstat);
00056 }
00057 
00058 /* BIT FUNCTIONS */
00059 void nstat_set_bit(unsigned char *a, unsigned char n){
00060    *a |= (1 << n);
00061 }
00062 int nstat_test_bit(unsigned char e, unsigned char n){
00063    e = e & (1 << n);
00064    return (e>0);
00065 }
00066 
00067 void nstat_clear_bit(unsigned char *b, unsigned char n){
00068    *b &= ~(1 << n);
00069 }
00070 void nstat_set_if_set(unsigned char src, unsigned char *dst,unsigned char n){
00071         if (nstat_test_bit(src,n)){
00072                 nstat_set_bit(dst,n);
00073         } else{
00074                 nstat_clear_bit(dst,n);
00075         }
00076 }
00077 
00078 /* EXPORTED FUNCTIONS */
00079 
00080 void nstat_set_val(int idx, unsigned char id){
00081         int i;
00082         unsigned char *val=&nstat[idx];
00083         unsigned char tmp=*val;
00084         *val=id;
00085         for (i=5;i<8;i++){
00086                 nstat_set_if_set(tmp,val,i);
00087         }
00088         val=&id;
00089 }
00090 unsigned char nstat_get_val(int idx){
00091         int i;
00092         unsigned char val=nstat[idx];
00093         for (i=5;i<8;i++){
00094                 nstat_clear_bit(&val,i);
00095         }
00096         return val;
00097 }
00098 int nstat_isReached(int idx){
00099    unsigned char val=nstat[idx];
00100    return nstat_test_bit(val,7);
00101 }
00102 int nstat_isLost(int idx){
00103    unsigned char val=nstat[idx];
00104    return nstat_test_bit(val,6);
00105 }
00106 void nstat_clearReached(int idx){
00107         unsigned char *val=&nstat[idx];
00108     return nstat_clear_bit(val,7);
00109 }
00110 void  nstat_setReached(int idx){
00111     unsigned char *val=&nstat[idx];
00112     nstat_set_bit(val,7);
00113 }
00114 int nstat_hasFailed(int idx){
00115         unsigned char val=nstat[idx];
00116     return nstat_test_bit(val,5);
00117 }
00118 void nstat_clearFailed(int idx){
00119    unsigned char *val=&nstat[idx];
00120    nstat_clear_bit(val,5);
00121 }
00122 void  nstat_setFailed(int idx){
00123    unsigned char *val=&nstat[idx];
00124    nstat_set_bit(val,5);
00125 }
00126 void  nstat_setLost(int idx){
00127    unsigned char *val=&nstat[idx];
00128    nstat_set_bit(val,6);
00129 }
00130 void  nstat_clearLost(int idx){
00131    unsigned char *val=&nstat[idx];
00132    nstat_clear_bit(val,6);
00133 }
00134 
00135 char nstat_get_byte(int idx){
00136         return (char) nstat[idx];
00137 }
00138 void nstat_set_byte(int idx,char val){
00139         nstat[idx]=(unsigned char) val;
00140 }
00141 
00142 
00143 
00144 
00145 


ros_rt_wmp
Author(s): Danilo Tardioli, dantard@unizar.es
autogenerated on Mon Oct 6 2014 08:27:10