/* Generated by Pyrex 0.9 on Sat Mar 27 12:37:51 2004 */

#include "Python.h"
#include "structmember.h"
#include "hostlib.h"


static PyObject *__Pyx_UnpackItem(PyObject *, int); /*proto*/
static int __Pyx_EndUnpack(PyObject *, int); /*proto*/
static int __Pyx_PrintItem(PyObject *); /*proto*/
static int __Pyx_PrintNewline(void); /*proto*/
static void __Pyx_Raise(PyObject *type, PyObject *value, PyObject *tb); /*proto*/
static void __Pyx_ReRaise(void); /*proto*/
static PyObject *__Pyx_Import(PyObject *name, PyObject *from_list); /*proto*/
static PyObject *__Pyx_GetExcValue(void); /*proto*/
static PyObject *__Pyx_GetName(PyObject *dict, char *name); /*proto*/
static int __Pyx_ArgTypeTest(PyObject *obj, PyTypeObject *type, int none_allowed, char *name); /*proto*/
static int __Pyx_TypeTest(PyObject *obj, PyTypeObject *type); /*proto*/
static int __Pyx_GetStarArgs(PyObject **args, PyObject **kwds, char *kwd_list[], int nargs, PyObject **args2, PyObject **kwds2); /*proto*/
static void __Pyx_WriteUnraisable(char *name); /*proto*/
static void __Pyx_AddTraceback(char *funcname); /*proto*/
static PyTypeObject *__Pyx_ImportType(char *module_name, char *class_name, long size);  /*proto*/
static int __Pyx_SetVtable(PyObject *dict, void *vtable); /*proto*/
static int __Pyx_GetVtable(PyObject *dict, void **vtabptr); /*proto*/

static PyObject *__pyx_m;
static PyObject *__pyx_b;
static int __pyx_lineno;
static char *__pyx_filename;
staticforward char **__pyx_f;

/* Declarations from avr */

staticforward PyTypeObject __pyx_type_3avr_Avr;

struct __pyx_obj_3avr_Avr {
  PyObject_HEAD
  void (*device);
  int is_open;
};

static PyTypeObject *__pyx_ptype_3avr_Avr = 0;
static int __pyx_k1;
static PyObject *__pyx_k2;
static int __pyx_k3;
static PyObject *__pyx_k4;

/* Implementation of avr */



static int __pyx_f_3avr_3Avr___init__(PyObject *__pyx_v_self, PyObject *__pyx_args, PyObject *__pyx_kwds); /*proto*/
static int __pyx_f_3avr_3Avr___init__(PyObject *__pyx_v_self, PyObject *__pyx_args, PyObject *__pyx_kwds) {
  int __pyx_r;
  static char *__pyx_argnames[] = {0};
  if (!PyArg_ParseTupleAndKeywords(__pyx_args, __pyx_kwds, "", __pyx_argnames)) return -1;
  Py_INCREF(__pyx_v_self);

  /* "/home/jepler/avr/uavrp/avr.pyx":35 */
  ((struct __pyx_obj_3avr_Avr *)__pyx_v_self)->device = avr_open();

  /* "/home/jepler/avr/uavrp/avr.pyx":36 */
  ((struct __pyx_obj_3avr_Avr *)__pyx_v_self)->is_open = 1;

  __pyx_r = 0;
  goto __pyx_L0;
  __pyx_L1:;
  __Pyx_AddTraceback("avr.Avr.__init__");
  __pyx_r = -1;
  __pyx_L0:;
  Py_DECREF(__pyx_v_self);
  return __pyx_r;
}


static PyObject *__pyx_f_3avr_3Avr___del__(PyObject *__pyx_v_self, PyObject *__pyx_args, PyObject *__pyx_kwds); /*proto*/
static PyObject *__pyx_f_3avr_3Avr___del__(PyObject *__pyx_v_self, PyObject *__pyx_args, PyObject *__pyx_kwds) {
  PyObject *__pyx_r;
  PyObject *__pyx_1 = 0;
  PyObject *__pyx_2 = 0;
  PyObject *__pyx_3 = 0;
  static char *__pyx_argnames[] = {0};
  if (!PyArg_ParseTupleAndKeywords(__pyx_args, __pyx_kwds, "", __pyx_argnames)) return 0;
  Py_INCREF(__pyx_v_self);

  /* "/home/jepler/avr/uavrp/avr.pyx":39 */
  __pyx_1 = PyObject_GetAttrString(__pyx_v_self, "close"); if (!__pyx_1) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 39; goto __pyx_L1;}
  __pyx_2 = PyTuple_New(0); if (!__pyx_2) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 39; goto __pyx_L1;}
  __pyx_3 = PyObject_CallObject(__pyx_1, __pyx_2); if (!__pyx_3) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 39; goto __pyx_L1;}
  Py_DECREF(__pyx_1); __pyx_1 = 0;
  Py_DECREF(__pyx_2); __pyx_2 = 0;
  Py_DECREF(__pyx_3); __pyx_3 = 0;

  __pyx_r = Py_BuildValue("");
  goto __pyx_L0;
  __pyx_L1:;
  Py_XDECREF(__pyx_1);
  Py_XDECREF(__pyx_2);
  Py_XDECREF(__pyx_3);
  __Pyx_AddTraceback("avr.Avr.__del__");
  __pyx_r = 0;
  __pyx_L0:;
  Py_DECREF(__pyx_v_self);
  return __pyx_r;
}


static PyObject *__pyx_f_3avr_3Avr_close(PyObject *__pyx_v_self, PyObject *__pyx_args, PyObject *__pyx_kwds); /*proto*/
static PyObject *__pyx_f_3avr_3Avr_close(PyObject *__pyx_v_self, PyObject *__pyx_args, PyObject *__pyx_kwds) {
  PyObject *__pyx_r;
  int __pyx_1;
  static char *__pyx_argnames[] = {0};
  if (!PyArg_ParseTupleAndKeywords(__pyx_args, __pyx_kwds, "", __pyx_argnames)) return 0;
  Py_INCREF(__pyx_v_self);

  /* "/home/jepler/avr/uavrp/avr.pyx":42 */
  __pyx_1 = ((struct __pyx_obj_3avr_Avr *)__pyx_v_self)->is_open;
  if (__pyx_1) {

    /* "/home/jepler/avr/uavrp/avr.pyx":43 */
    ((struct __pyx_obj_3avr_Avr *)__pyx_v_self)->is_open = 0;

    /* "/home/jepler/avr/uavrp/avr.pyx":44 */
    avr_close(((struct __pyx_obj_3avr_Avr *)__pyx_v_self)->device);
    goto __pyx_L2;
  }
  __pyx_L2:;

  __pyx_r = Py_BuildValue("");
  goto __pyx_L0;
  __pyx_L1:;
  __Pyx_AddTraceback("avr.Avr.close");
  __pyx_r = 0;
  __pyx_L0:;
  Py_DECREF(__pyx_v_self);
  return __pyx_r;
}


static PyObject *__pyx_f_3avr_3Avr_send_command(PyObject *__pyx_v_self, PyObject *__pyx_args, PyObject *__pyx_kwds); /*proto*/
static PyObject *__pyx_f_3avr_3Avr_send_command(PyObject *__pyx_v_self, PyObject *__pyx_args, PyObject *__pyx_kwds) {
  int __pyx_v_cmd;
  int __pyx_v_val;
  PyObject *__pyx_v_idx = 0;
  PyObject *__pyx_r;
  int __pyx_1;
  static char *__pyx_argnames[] = {"cmd","val","idx",0};
  __pyx_v_val = __pyx_k1;
  __pyx_v_idx = __pyx_k2;
  if (!PyArg_ParseTupleAndKeywords(__pyx_args, __pyx_kwds, "i|iO", __pyx_argnames, &__pyx_v_cmd, &__pyx_v_val, &__pyx_v_idx)) return 0;
  Py_INCREF(__pyx_v_self);
  Py_INCREF(__pyx_v_idx);

  /* "/home/jepler/avr/uavrp/avr.pyx":47 */
  __pyx_1 = PyInt_AsLong(__pyx_v_idx); if (PyErr_Occurred()) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 47; goto __pyx_L1;}
  avr_send_command_idx(((struct __pyx_obj_3avr_Avr *)__pyx_v_self)->device,__pyx_v_cmd,__pyx_v_val,__pyx_1);

  __pyx_r = Py_BuildValue("");
  goto __pyx_L0;
  __pyx_L1:;
  __Pyx_AddTraceback("avr.Avr.send_command");
  __pyx_r = 0;
  __pyx_L0:;
  Py_DECREF(__pyx_v_self);
  Py_DECREF(__pyx_v_idx);
  return __pyx_r;
}


static PyObject *__pyx_f_3avr_3Avr_get_response(PyObject *__pyx_v_self, PyObject *__pyx_args, PyObject *__pyx_kwds); /*proto*/
static PyObject *__pyx_f_3avr_3Avr_get_response(PyObject *__pyx_v_self, PyObject *__pyx_args, PyObject *__pyx_kwds) {
  int __pyx_v_cmd;
  int __pyx_v_val;
  PyObject *__pyx_v_idx = 0;
  char (__pyx_v_res[4]);
  int __pyx_v_len;
  PyObject *__pyx_r;
  int __pyx_1;
  PyObject *__pyx_2 = 0;
  static char *__pyx_argnames[] = {"cmd","val","idx",0};
  __pyx_v_val = __pyx_k3;
  __pyx_v_idx = __pyx_k4;
  if (!PyArg_ParseTupleAndKeywords(__pyx_args, __pyx_kwds, "i|iO", __pyx_argnames, &__pyx_v_cmd, &__pyx_v_val, &__pyx_v_idx)) return 0;
  Py_INCREF(__pyx_v_self);
  Py_INCREF(__pyx_v_idx);

  /* "/home/jepler/avr/uavrp/avr.pyx":52 */
  __pyx_1 = PyInt_AsLong(__pyx_v_idx); if (PyErr_Occurred()) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 52; goto __pyx_L1;}
  __pyx_v_len = avr_get_response_idx(((struct __pyx_obj_3avr_Avr *)__pyx_v_self)->device,__pyx_v_cmd,__pyx_v_val,__pyx_1,__pyx_v_res,4);

  /* "/home/jepler/avr/uavrp/avr.pyx":53 */
  __pyx_2 = PyString_FromStringAndSize(__pyx_v_res,__pyx_v_len); if (!__pyx_2) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 53; goto __pyx_L1;}
  __pyx_r = __pyx_2;
  __pyx_2 = 0;
  goto __pyx_L0;

  __pyx_r = Py_BuildValue("");
  goto __pyx_L0;
  __pyx_L1:;
  Py_XDECREF(__pyx_2);
  __Pyx_AddTraceback("avr.Avr.get_response");
  __pyx_r = 0;
  __pyx_L0:;
  Py_DECREF(__pyx_v_self);
  Py_DECREF(__pyx_v_idx);
  return __pyx_r;
}

static PyObject *__pyx_tp_new_3avr_Avr(struct _typeobject *t, PyObject *a, PyObject *k) {
  PyObject *o = (*t->tp_alloc)(t, 0);
  struct __pyx_obj_3avr_Avr *p = (struct __pyx_obj_3avr_Avr *)o;
  return o;
}

static void __pyx_tp_dealloc_3avr_Avr(PyObject *o) {
  struct __pyx_obj_3avr_Avr *p = (struct __pyx_obj_3avr_Avr *)o;
  (*o->ob_type->tp_free)(o);
}

static int __pyx_tp_traverse_3avr_Avr(PyObject *o, visitproc v, void *a) {
  int e;
  struct __pyx_obj_3avr_Avr *p = (struct __pyx_obj_3avr_Avr *)o;
  return 0;
}

static int __pyx_tp_clear_3avr_Avr(PyObject *o) {
  struct __pyx_obj_3avr_Avr *p = (struct __pyx_obj_3avr_Avr *)o;
  return 0;
}

static struct PyMethodDef __pyx_methods_3avr_Avr[] = {
  {"__del__", (PyCFunction)__pyx_f_3avr_3Avr___del__, METH_VARARGS|METH_KEYWORDS, 0},
  {"close", (PyCFunction)__pyx_f_3avr_3Avr_close, METH_VARARGS|METH_KEYWORDS, 0},
  {"send_command", (PyCFunction)__pyx_f_3avr_3Avr_send_command, METH_VARARGS|METH_KEYWORDS, 0},
  {"get_response", (PyCFunction)__pyx_f_3avr_3Avr_get_response, METH_VARARGS|METH_KEYWORDS, 0},
  {0, 0, 0, 0}
};

static PyNumberMethods __pyx_tp_as_number_Avr = {
  0, /*nb_add*/
  0, /*nb_subtract*/
  0, /*nb_multiply*/
  0, /*nb_divide*/
  0, /*nb_remainder*/
  0, /*nb_divmod*/
  0, /*nb_power*/
  0, /*nb_negative*/
  0, /*nb_positive*/
  0, /*nb_absolute*/
  0, /*nb_nonzero*/
  0, /*nb_invert*/
  0, /*nb_lshift*/
  0, /*nb_rshift*/
  0, /*nb_and*/
  0, /*nb_xor*/
  0, /*nb_or*/
  0, /*nb_coerce*/
  0, /*nb_int*/
  0, /*nb_long*/
  0, /*nb_float*/
  0, /*nb_oct*/
  0, /*nb_hex*/
  0, /*nb_inplace_add*/
  0, /*nb_inplace_subtract*/
  0, /*nb_inplace_multiply*/
  0, /*nb_inplace_divide*/
  0, /*nb_inplace_remainder*/
  0, /*nb_inplace_power*/
  0, /*nb_inplace_lshift*/
  0, /*nb_inplace_rshift*/
  0, /*nb_inplace_and*/
  0, /*nb_inplace_xor*/
  0, /*nb_inplace_or*/
  0, /*nb_floor_divide*/
  0, /*nb_true_divide*/
  0, /*nb_inplace_floor_divide*/
  0, /*nb_inplace_true_divide*/
};

static PySequenceMethods __pyx_tp_as_sequence_Avr = {
  0, /*sq_length*/
  0, /*sq_concat*/
  0, /*sq_repeat*/
  0, /*sq_item*/
  0, /*sq_slice*/
  0, /*sq_ass_item*/
  0, /*sq_ass_slice*/
  0, /*sq_contains*/
  0, /*sq_inplace_concat*/
  0, /*sq_inplace_repeat*/
};

static PyMappingMethods __pyx_tp_as_mapping_Avr = {
  0, /*mp_length*/
  0, /*mp_subscript*/
  0, /*mp_ass_subscript*/
};

static PyBufferProcs __pyx_tp_as_buffer_Avr = {
  0, /*bf_getreadbuffer*/
  0, /*bf_getwritebuffer*/
  0, /*bf_getsegcount*/
  0, /*bf_getcharbuffer*/
};

statichere PyTypeObject __pyx_type_3avr_Avr = {
  PyObject_HEAD_INIT(0)
  0, /*ob_size*/
  "avr.Avr", /*tp_name*/
  sizeof(struct __pyx_obj_3avr_Avr), /*tp_basicsize*/
  0, /*tp_itemsize*/
  __pyx_tp_dealloc_3avr_Avr, /*tp_dealloc*/
  0, /*tp_print*/
  0, /*tp_getattr*/
  0, /*tp_setattr*/
  0, /*tp_compare*/
  0, /*tp_repr*/
  &__pyx_tp_as_number_Avr, /*tp_as_number*/
  &__pyx_tp_as_sequence_Avr, /*tp_as_sequence*/
  &__pyx_tp_as_mapping_Avr, /*tp_as_mapping*/
  0, /*tp_hash*/
  0, /*tp_call*/
  0, /*tp_str*/
  0, /*tp_getattro*/
  0, /*tp_setattro*/
  &__pyx_tp_as_buffer_Avr, /*tp_as_buffer*/
  Py_TPFLAGS_DEFAULT|Py_TPFLAGS_CHECKTYPES|Py_TPFLAGS_BASETYPE, /*tp_flags*/
  0, /*tp_doc*/
  __pyx_tp_traverse_3avr_Avr, /*tp_traverse*/
  __pyx_tp_clear_3avr_Avr, /*tp_clear*/
  0, /*tp_richcompare*/
  0, /*tp_weaklistoffset*/
  0, /*tp_iter*/
  0, /*tp_iternext*/
  __pyx_methods_3avr_Avr, /*tp_methods*/
  0, /*tp_members*/
  0, /*tp_getset*/
  0, /*tp_base*/
  0, /*tp_dict*/
  0, /*tp_descr_get*/
  0, /*tp_descr_set*/
  0, /*tp_dictoffset*/
  __pyx_f_3avr_3Avr___init__, /*tp_init*/
  0, /*tp_alloc*/
  __pyx_tp_new_3avr_Avr, /*tp_new*/
  0, /*tp_free*/
  0, /*tp_is_gc*/
  0, /*tp_bases*/
  0, /*tp_mro*/
  0, /*tp_cache*/
  0, /*tp_subclasses*/
  0, /*tp_weaklist*/
};

static struct PyMethodDef __pyx_methods[] = {
  {0, 0, 0, 0}
};

DL_EXPORT(void) initavr(void); /*proto*/
DL_EXPORT(void) initavr(void) {
  PyObject *__pyx_1 = 0;
  PyObject *__pyx_2 = 0;
  __pyx_m = Py_InitModule4("avr", __pyx_methods, 0, 0, PYTHON_API_VERSION);
  __pyx_b = PyImport_AddModule("__builtin__");
  PyObject_SetAttrString(__pyx_m, "__builtins__", __pyx_b);
  if (PyType_Ready(&__pyx_type_3avr_Avr) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 30; goto __pyx_L1;}
  if (PyObject_SetAttrString(__pyx_m, "Avr", (PyObject *)&__pyx_type_3avr_Avr) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 30; goto __pyx_L1;}
  __pyx_ptype_3avr_Avr = &__pyx_type_3avr_Avr;

  /* "/home/jepler/avr/uavrp/avr.pyx":46 */
  __pyx_k1 = 0;
  __pyx_1 = PyInt_FromLong(0); if (!__pyx_1) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 46; goto __pyx_L1;}
  __pyx_k2 = __pyx_1;
  __pyx_1 = 0;

  /* "/home/jepler/avr/uavrp/avr.pyx":49 */
  __pyx_k3 = 0;
  __pyx_2 = PyInt_FromLong(0); if (!__pyx_2) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 49; goto __pyx_L1;}
  __pyx_k4 = __pyx_2;
  __pyx_2 = 0;
  return;
  __pyx_L1:;
  Py_XDECREF(__pyx_1);
  Py_XDECREF(__pyx_2);
  __Pyx_AddTraceback("avr");
}

static char *__pyx_filenames[] = {
  "/home/jepler/avr/uavrp/avr.pyx",
};
statichere char **__pyx_f = __pyx_filenames;

/* Runtime support code */

#include "compile.h"
#include "frameobject.h"
#include "traceback.h"

static void __Pyx_AddTraceback(char *funcname) {
	PyObject *py_srcfile = 0;
	PyObject *py_funcname = 0;
	PyObject *py_globals = 0;
	PyObject *empty_tuple = 0;
	PyObject *empty_string = 0;
	PyCodeObject *py_code = 0;
	PyFrameObject *py_frame = 0;
	
	py_srcfile = PyString_FromString(__pyx_filename);
	if (!py_srcfile) goto bad;
	py_funcname = PyString_FromString(funcname);
	if (!py_funcname) goto bad;
	py_globals = PyModule_GetDict(__pyx_m);
	if (!py_globals) goto bad;
	empty_tuple = PyTuple_New(0);
	if (!empty_tuple) goto bad;
	empty_string = PyString_FromString("");
	if (!empty_string) goto bad;
	py_code = PyCode_New(
		0,            /*int argcount,*/
		0,            /*int nlocals,*/
		0,            /*int stacksize,*/
		0,            /*int flags,*/
		empty_string, /*PyObject *code,*/
		empty_tuple,  /*PyObject *consts,*/
		empty_tuple,  /*PyObject *names,*/
		empty_tuple,  /*PyObject *varnames,*/
		empty_tuple,  /*PyObject *freevars,*/
		empty_tuple,  /*PyObject *cellvars,*/
		py_srcfile,   /*PyObject *filename,*/
		py_funcname,  /*PyObject *name,*/
		__pyx_lineno,   /*int firstlineno,*/
		empty_string  /*PyObject *lnotab*/
	);
	if (!py_code) goto bad;
	py_frame = PyFrame_New(
		PyThreadState_Get(), /*PyThreadState *tstate,*/
		py_code,             /*PyCodeObject *code,*/
		py_globals,          /*PyObject *globals,*/
		0                    /*PyObject *locals*/
	);
	if (!py_frame) goto bad;
	py_frame->f_lineno = __pyx_lineno;
	PyTraceBack_Here(py_frame);
bad:
	Py_XDECREF(py_srcfile);
	Py_XDECREF(py_funcname);
	Py_XDECREF(empty_tuple);
	Py_XDECREF(empty_string);
	Py_XDECREF(py_code);
	Py_XDECREF(py_frame);
}

