pyToC.c

Go to the documentation of this file.
00001 
00006 #include "pyToC.h"
00007 #include <limits.h>
00008 
00009 #undef __FILE_ID__
00010 #define __FILE_ID__ 0x71
00011 
00012 PmReturn_t
00013 getInt32(pPmObj_t ppo, int32_t* pi32_val)
00014 {
00015     PmReturn_t retval = PM_RET_OK;
00016 
00017     // Raise TypeError if Python object isn't an int
00018     EXCEPTION_UNLESS(OBJ_GET_TYPE(ppo) == OBJ_TYPE_INT, PM_RET_EX_TYPE, 
00019       "Object must be an int");
00020 
00021     // Get the value, now that we know it's an int
00022     *pi32_val = ((pPmInt_t) ppo)->val;
00023 
00024     return retval;
00025 }
00026 
00027 PmReturn_t
00028 getFloat(pPmObj_t ppo, float* pf_val)
00029 {
00030     PmReturn_t retval = PM_RET_OK;
00031 
00032     // Raise TypeError if Python object isn't an int
00033     EXCEPTION_UNLESS(OBJ_GET_TYPE(ppo) == OBJ_TYPE_FLT, PM_RET_EX_TYPE, 
00034       "Object must be a float");
00035 
00036     // Get the value, now that we know it's an int
00037     *pf_val = ((pPmFloat_t) ppo)->val;
00038 
00039     return retval;
00040 }
00041 
00042 PmReturn_t 
00043 getUint32(pPmObj_t ppo, uint32_t* pu32_val)
00044 {
00045     PmReturn_t retval = PM_RET_OK;
00046     int32_t i32_val;
00047 
00048     // Get the int32 from the Python arguments passed to this function
00049     PM_CHECK_FUNCTION( getInt32(ppo, &i32_val) );
00050 
00051     // Raise a ValueError if address is < min or > max
00052     EXCEPTION_UNLESS(i32_val >= 0, PM_RET_EX_VAL, 
00053         "Object value must be non-negative");
00054     *pu32_val = i32_val;
00055 
00056     return retval;
00057 }
00058 
00059 PmReturn_t
00060 getRangedInt(pPmObj_t ppo,
00061   int32_t i32_min, int32_t i32_max, int32_t* pi32_val)
00062 {
00063     PmReturn_t retval = PM_RET_OK;
00064 
00065     // Get the int32 from the Python arguments passed to this function
00066     PM_CHECK_FUNCTION( getInt32(ppo, pi32_val) );
00067 
00068     // Raise a ValueError if address is < min or > max
00069     EXCEPTION_UNLESS((*pi32_val >= i32_min) && 
00070       (*pi32_val <= i32_max), PM_RET_EX_VAL, 
00071         "Object value must be between %ld and %ld.", 
00072         i32_min, i32_max);
00073 
00074     return retval;
00075 }
00076 
00077 PmReturn_t
00078 getUint16(pPmObj_t ppo, uint16_t* pu16_val)
00079 {
00080     PmReturn_t retval = PM_RET_OK;
00081     int32_t i32;
00082 
00083     PM_CHECK_FUNCTION( getRangedInt(ppo, 0, 65535, &i32) );
00084     *pu16_val = (uint16_t) i32;
00085     return retval;
00086 }
00087 
00088 PmReturn_t
00089 getInt16(pPmObj_t ppo, int16_t* pi16_val)
00090 {
00091     PmReturn_t retval = PM_RET_OK;
00092     int32_t i32;
00093 
00094     PM_CHECK_FUNCTION( getRangedInt(ppo, -32768, 32767, &i32) );
00095     *pi16_val = (int16_t) i32;
00096     return retval;
00097 }
00098 
00099 PmReturn_t
00100 getBool(pPmObj_t ppo, bool_t* pb_bool)
00101 {
00102     PmReturn_t retval = PM_RET_OK;
00103 
00104     // Raise TypeError if Python object isn't a bool
00105     EXCEPTION_UNLESS(OBJ_GET_TYPE(ppo) == OBJ_TYPE_BOOL, PM_RET_EX_TYPE, 
00106       "Object must be a bool");
00107     
00108     *pb_bool = ((pPmBoolean_t) ppo)->val;
00109 
00110     return retval;
00111 }

Generated on Mon Oct 18 07:40:47 2010 for Python-on-a-chip by  doxygen 1.5.9