summaryrefslogtreecommitdiff
path: root/gr-trellis/src
diff options
context:
space:
mode:
Diffstat (limited to 'gr-trellis/src')
-rw-r--r--gr-trellis/src/lib/fsm.cc20
-rw-r--r--gr-trellis/src/lib/interleaver.cc13
-rwxr-xr-xgr-trellis/src/python/qa_trellis.py12
3 files changed, 31 insertions, 14 deletions
diff --git a/gr-trellis/src/lib/fsm.cc b/gr-trellis/src/lib/fsm.cc
index c65b13456..5950b56b9 100644
--- a/gr-trellis/src/lib/fsm.cc
+++ b/gr-trellis/src/lib/fsm.cc
@@ -86,16 +86,30 @@ fsm::fsm(const char *name)
if((fsmfile=fopen(name,"r"))==NULL)
throw std::runtime_error ("fsm::fsm(const char *name): file open error\n");
//printf("file open error in fsm()\n");
+
+ if(fscanf(fsmfile,"%d %d %d\n",&d_I,&d_S,&d_O) == EOF) {
+ if(ferror(fsmfile) != 0)
+ throw std::runtime_error ("fsm::fsm(const char *name): file read error\n");
+ }
- fscanf(fsmfile,"%d %d %d\n",&d_I,&d_S,&d_O);
d_NS.resize(d_I*d_S);
d_OS.resize(d_I*d_S);
for(int i=0;i<d_S;i++) {
- for(int j=0;j<d_I;j++) fscanf(fsmfile,"%d",&(d_NS[i*d_I+j]));
+ for(int j=0;j<d_I;j++) {
+ if(fscanf(fsmfile,"%d",&(d_NS[i*d_I+j])) == EOF) {
+ if(ferror(fsmfile) != 0)
+ throw std::runtime_error ("fsm::fsm(const char *name): file read error\n");
+ }
+ }
}
for(int i=0;i<d_S;i++) {
- for(int j=0;j<d_I;j++) fscanf(fsmfile,"%d",&(d_OS[i*d_I+j]));
+ for(int j=0;j<d_I;j++) {
+ if(fscanf(fsmfile,"%d",&(d_OS[i*d_I+j])) == EOF) {
+ if(ferror(fsmfile) != 0)
+ throw std::runtime_error ("fsm::fsm(const char *name): file read error\n");
+ }
+ }
}
generate_PS_PI();
diff --git a/gr-trellis/src/lib/interleaver.cc b/gr-trellis/src/lib/interleaver.cc
index 077416f80..ff15eeadc 100644
--- a/gr-trellis/src/lib/interleaver.cc
+++ b/gr-trellis/src/lib/interleaver.cc
@@ -75,11 +75,20 @@ interleaver::interleaver(const char *name)
throw std::runtime_error ("file open error in interleaver()");
//printf("file open error in interleaver()\n");
- fscanf(interleaverfile,"%d\n",&d_K);
+ if(fscanf(interleaverfile,"%d\n",&d_K) == EOF) {
+ if(ferror(interleaverfile) != 0)
+ throw std::runtime_error ("interleaver::interleaver(const char *name): file read error\n");
+ }
+
d_INTER.resize(d_K);
d_DEINTER.resize(d_K);
- for(int i=0;i<d_K;i++) fscanf(interleaverfile,"%d",&(d_INTER[i]));
+ for(int i=0;i<d_K;i++) {
+ if(fscanf(interleaverfile,"%d",&(d_INTER[i])) == EOF) {
+ if(ferror(interleaverfile) != 0)
+ throw std::runtime_error ("interleaver::interleaver(const char *name): file read error\n");
+ }
+ }
// generate DEINTER table
for(int i=0;i<d_K;i++) {
diff --git a/gr-trellis/src/python/qa_trellis.py b/gr-trellis/src/python/qa_trellis.py
index 306bf994d..cfeefea06 100755
--- a/gr-trellis/src/python/qa_trellis.py
+++ b/gr-trellis/src/python/qa_trellis.py
@@ -1,6 +1,6 @@
#!/usr/bin/env python
#
-# Copyright 2004 Free Software Foundation, Inc.
+# Copyright 2004,2010 Free Software Foundation, Inc.
#
# This file is part of GNU Radio
#
@@ -23,7 +23,7 @@
from gnuradio import gr, gr_unittest
import trellis
-class qa_trellis (gr_unittest.TestCase):
+class test_trellis (gr_unittest.TestCase):
def setUp (self):
self.tb = gr.top_block ()
@@ -68,11 +68,5 @@ class qa_trellis (gr_unittest.TestCase):
i = trellis.interleaver(K,IN)
self.assertEqual((K,IN,DIN),(i.K(),i.INTER(),i.DEINTER()))
-
-
-
-
-
-
if __name__ == '__main__':
- gr_unittest.main ()
+ gr_unittest.run(test_trellis, "test_trellis.xml")