[med-svn] [aghermann] 02/31: lua-enabled rk1968 part 2/2

andrei zavada hmmr-guest at alioth.debian.org
Sun Nov 10 00:34:14 UTC 2013


This is an automated email from the git hooks/post-receive script.

hmmr-guest pushed a commit to branch WIP
in repository aghermann.

commit f8f6cc4f01deaae809938161e54876cb7d069894
Author: Andrei Zavada <hmmr at ra>
Date:   Thu Nov 7 02:31:09 2013 +0200

    lua-enabled rk1968 part 2/2
---
 upstream/src/aghermann/rk1968/rk1968.cc |   69 +++++++++++++++++++------------
 1 file changed, 43 insertions(+), 26 deletions(-)

diff --git a/upstream/src/aghermann/rk1968/rk1968.cc b/upstream/src/aghermann/rk1968/rk1968.cc
index 63687ca..1a00c5a 100644
--- a/upstream/src/aghermann/rk1968/rk1968.cc
+++ b/upstream/src/aghermann/rk1968/rk1968.cc
@@ -196,7 +196,7 @@ host_get_data( lua_State *L)
         auto make_arity_mismatch_return = [&L, &nargsin, &opcode] ( int correct_nargsin)
                 {
                         lua_pushboolean( L, false);
-                        lua_pushfstring( L, "Bad arity for opcode %d (need %d, got %d)", opcode, correct_nargsin, nargsin);
+                        lua_pushfstring( L, "Bad arity for opcode %d (need %d or more, got %d)", opcode, correct_nargsin, nargsin);
                         lua_error(L);
                 };
         auto make_error_return = [&L] ( const char* fmt, ...) __attribute__ ((format (printf, 2, 3)))
@@ -208,15 +208,17 @@ host_get_data( lua_State *L)
                         va_end (ap);
                         lua_error(L);
                 };
-#define NEED_ARITY(A) \
-        if ( nargsin != A ) { make_arity_mismatch_return(A); return 2; }
+#define NEED_ARITY_ATLEAST(A) \
+        if ( nargsin < A ) { make_arity_mismatch_return(A); }
+#define NEED_ARITY_EXACT(A) \
+        if ( nargsin != A ) { make_arity_mismatch_return(A); }
 
         switch ( opcode ) {
         case op_noop:
                 return 0;
 
         case op_get_channel_list: {
-                NEED_ARITY(0);
+                NEED_ARITY_EXACT(0);
 
                 list<const char*> A;
                 for ( auto& H : E.recordings )
@@ -227,7 +229,7 @@ host_get_data( lua_State *L)
         }
 
         case op_get_channel_list_of_type: {
-                NEED_ARITY(1);
+                NEED_ARITY_EXACT(1);
 
                 const char* type = lua_tostring( L, 3);
 
@@ -241,7 +243,7 @@ host_get_data( lua_State *L)
         }
 
         case op_get_channel_data: {
-                NEED_ARITY(1);
+                NEED_ARITY_EXACT(1);
 
                 const char* channel = lua_tostring( L, 3);
                 auto Hi = E.recordings.find( sigfile::SChannel (channel));
@@ -249,43 +251,58 @@ host_get_data( lua_State *L)
                         make_error_return( "No such channel (%s)", channel);
                 } else {
                         auto& R = Hi->second;
+                        lua_pushinteger( L, R.full_pages());
+                        lua_pushinteger( L, R.total_pages());
+                        lua_pushinteger( L, R.pagesize());
                         lua_pushinteger( L, R.F().samplerate(R.h()));
-                        return 1;
+                        return 3;
                 }
         }
 
-        case op_get_psd: {
-                NEED_ARITY(4);
+        case op_get_psd:
+        case op_get_mc :
+        case op_get_swu: {
+                NEED_ARITY_EXACT(5);
 
                 const char* channel = lua_tostring( L, 3);
                 auto Hi = E.recordings.find( sigfile::SChannel (channel));
                 if ( Hi == E.recordings.end() ) {
                         make_error_return( "No such channel (%s)", channel);
+                } else if ( !Hi->first.is_fftable() ) {
+                        make_error_return( "Request of profile metric from a non-EEG channel channel %s", channel);
                 } else {
                         auto& R = Hi->second;
-                        int page = lua_tointeger( L, 4);
-                        if ( page < 0 || (size_t)page >= R.full_pages() ) {
-                                make_error_return( "Page %d out of range (%zu is last full)", page, R.full_pages());
-                        }
-                        double fa = lua_tonumber( L, 5);
-                        double fz = lua_tonumber( L, 6);
-                        if ( fa >= fz ) {
-                                make_error_return( "Invalid frequency range for PSD");
-                        }
-
-                        lua_pushnumber( L, R.psd_profile.course( fa, fz)[page]);
-                        return 1;
+                        int pa = lua_tointeger( L, 4);
+                        int pz = lua_tointeger( L, 5);
+                        if ( !(pa <= pz) )
+                                make_error_return( "Invalid (inclusive) range: %d..%d", pa, pz);
+                        if ( pa < 0 || (size_t)pa >= R.full_pages() )
+                                make_error_return( "Page %d out of valid range (%zu is last full)", pa, R.full_pages());
+                        if ( pz < 0 || (size_t)pz >= R.full_pages() )
+                                make_error_return( "Page %d out of valid range (%zu is last full)", pz, R.full_pages());
+                        double fa = lua_tonumber( L, 6);
+                        double fz = lua_tonumber( L, 7);
+                        if ( fa >= fz )
+                                make_error_return( "Ill-formed frequency range");
+
+                        auto C =
+                                opcode == op_get_psd
+                                ? R.psd_profile.course( fa, fz)
+                                : opcode == op_get_mc
+                                ? R.mc_profile.course( fa)
+                                : R.swu_profile.course( fa);
+                        auto p = pa;
+                        while ( p <= pz )
+                                lua_pushnumber( L, C[p++]);
+                        return pz - pa;
                 }
         }
 
-        case op_get_mc:
-
-        case op_get_swu:
-
         default:
                 make_error_return( "Invalid host opcode %d", opcode);
         }
-#undef NEED_ARITY
+#undef NEED_ARITY_EXACT
+#undef NEED_ARITY_ATLEAST
 
         return 0; // unreachable because lua_error has a longjmp
 }

-- 
Alioth's /git/debian-med/git-commit-notice on /srv/git.debian.org/git/debian-med/aghermann.git



More information about the debian-med-commit mailing list