From: Brian G. <ge...@us...> - 2007-10-18 15:43:13
|
Update of /cvsroot/playerstage/code/player/client_libs/libplayerc/bindings/python In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv22222/client_libs/libplayerc/bindings/python Modified Files: playerc.i Log Message: applied patch 1784991 Index: playerc.i =================================================================== RCS file: /cvsroot/playerstage/code/player/client_libs/libplayerc/bindings/python/playerc.i,v retrieving revision 1.24 retrieving revision 1.25 diff -C2 -d -r1.24 -r1.25 *** playerc.i 9 Jul 2007 17:21:08 -0000 1.24 --- playerc.i 18 Oct 2007 22:43:15 -0000 1.25 *************** *** 8,11 **** --- 8,59 ---- %include "typemaps.i" + + // Provide array access to the RFID tags + // We will return a list of tuples. Each tuple contains the RFID type, and the RFID ID. + // The RFID ID is a Python string containing the unprocessed bytes of the RFID tag. + // In Python, use rfid.tags[i][1].encode('hex') to see the regular Hex-ASCII representation. + %typemap(out) playerc_rfidtag_t [ANY] + { + int i; + $result = PyList_New($1_dim0); //we will return a Python List + + //At this level, we don't get the ammount of tags, so we just produce a long list, of size PLAYER_RFID_MAX_TAGS + //(this is the size of the array of playerc_rfidtag_t contained in the RFID data packet) + for (i = 0; i != $1_dim0; ++i) + { + + PyObject *tuple = PyTuple_New(2); // we will make a tuple with 2 fields: type(int) and RFID ID(string) + + const unsigned int blength=PLAYERC_RFID_MAX_GUID; + char buffer[blength]; + memset(buffer, 0, blength ); + + //result is of type playerc_rfidtag_t + unsigned int j; + unsigned int guid_count=$1[i].guid_count; + + //copy the bytes into the buffer + for (j=0 ; j != guid_count ; ++j) { + buffer[j]=$1[i].guid[j]; + } + + //generate a Python string from the buffer + PyObject *ostring = PyString_FromStringAndSize(buffer,guid_count); + + //generate an Int from the tag type + PyObject *otype = PyInt_FromLong($1[i].type); + + //set the previous objects into the tuple + PyTuple_SetItem(tuple,0,otype); + PyTuple_SetItem(tuple,1,ostring); + + //set the tupple into the corresponding place of the list + PyList_SetItem($result,i,tuple); + } + + //$result is the Python List that gets returned automatically at the end of this function + } + + // Special rules for functions that return multiple results via pointers *************** *** 68,72 **** } ! %typemap(python,in) uint8_t data[] { int temp = 0; --- 116,120 ---- } ! %typemap(in) uint8_t data[] { int temp = 0; *************** *** 97,101 **** /*// typemap to free the array created in the previous typemap ! %typemap(python,freearg) uint8_t data[] { if ($input) free ((uint8_t*) $input); --- 145,149 ---- /*// typemap to free the array created in the previous typemap ! %typemap(freearg) uint8_t data[] { if ($input) free ((uint8_t*) $input); *************** *** 103,107 **** // typemap for passing points into the graphics2d interface ! %typemap(python,in) player_point_2d_t pts[] { // Check if is a list --- 151,155 ---- // typemap for passing points into the graphics2d interface ! %typemap(in) player_point_2d_t pts[] { // Check if is a list *************** *** 141,145 **** // typemap for passing 3d points into the graphics3d interface ! %typemap(python,in) player_point_3d_t pts[] { // Check if is a list --- 189,193 ---- // typemap for passing 3d points into the graphics3d interface ! %typemap(in) player_point_3d_t pts[] { // Check if is a list *************** *** 180,184 **** // typemap to free the array created in the previous typemap ! %typemap(python,freearg) player_point2d_t pts[] { if ($input) free ((player_point2d_t*) $input); --- 228,232 ---- // typemap to free the array created in the previous typemap ! %typemap(freearg) player_point2d_t pts[] { if ($input) free ((player_point2d_t*) $input); *************** *** 186,190 **** // typemap for tuples to colours ! %typemap(python,in) player_color_t (player_color_t temp) { // Check it is a tuple --- 234,238 ---- // typemap for tuples to colours ! %typemap(in) player_color_t (player_color_t temp) { // Check it is a tuple |