make it work on the mecker-compiler
[enigma2.git] / lib / dvb_ci / dvbci_mmi.cpp
index 463c91b..a6a0c8b 100644 (file)
@@ -1,6 +1,31 @@
 /* DVB CI MMI */
 
 #include <lib/dvb_ci/dvbci_mmi.h>
+#include <lib/dvb_ci/dvbci_ui.h>
+#include <lib/base/estring.h>
+
+/*
+PyObject *list = PyList_New(len);
+for (i=0; i<len; ++i) {
+       PyObject *tuple = PyTuple_New(3); // 3 eintrge im tuple
+       PyTuple_SetItem(tuple, 0, PyString_FromString("eintrag 1"))
+       PyTuple_SetItem(tuple, 1, PyInt_FromLong(31337));
+       PyTuple_SetItem(tuple, 2, PyString_FromString("eintrag 3"))
+       PyList_SetItem(list, i, tuple);
+}
+return list;
+*/
+
+eDVBCIMMISession::eDVBCIMMISession(eDVBCISlot *tslot)
+{
+       slot = tslot;
+       slot->mmi_session = this;
+}
+
+eDVBCIMMISession::~eDVBCIMMISession()
+{
+       slot->mmi_session = 0;
+}
 
 int eDVBCIMMISession::receivedAPDU(const unsigned char *tag, const void *data, int len)
 {
@@ -19,15 +44,52 @@ int eDVBCIMMISession::receivedAPDU(const unsigned char *tag, const void *data, i
                                printf("kann ich nicht. aber das sag ich dem modul nicht.\n");
                        state=stateDisplayReply;
                        return 1;
-               case 0x09:
-               case 0x0c:
+               case 0x07:              //Tmenu_enq
+               {
+                       unsigned char *d=(unsigned char*)data;
+                       unsigned char *max=((unsigned char*)d) + len;
+                       int textlen = len - 2;
+                       int i;
+
+                       printf("in enq\n");
+                       
+                       if ((d+2) > max)
+                               break;
+                               
+                       int blind = *d++ & 1;
+                       int alen = *d++;
+
+                       printf("%d bytes text\n", textlen);
+                       if ((d+textlen) > max)
+                               break;
+                       
+                       char str[textlen + 1];
+                       memcpy(str, ((char*)d), textlen);
+                       str[textlen] = '\0';
+                       
+                       printf("enq-text: %s\n",str);
+                       
+                       eDVBCI_UI::getInstance()->mmiScreenEnq(0, blind, alen, (char*)convertDVBUTF8(str).c_str());
+
+                       break;          
+               }
+               case 0x09:              //Tmenu_last
+               case 0x0c:              //Tlist_last
                {
                        unsigned char *d=(unsigned char*)data;
                        unsigned char *max=((unsigned char*)d) + len;
+                       int pos = 0;
                        printf("Tmenu_last\n");
                        if (d > max)
                                break;
                        int n=*d++;
+                       
+                       //FIXME: slotid
+                       if(tag[2] == 0x09)      //menu
+                               eDVBCI_UI::getInstance()->mmiScreenBegin(0, 0);
+                       else                                                            //list
+                               eDVBCI_UI::getInstance()->mmiScreenBegin(0, 1);
+                       
                        if (n == 0xFF)
                                n=0;
                        else
@@ -44,10 +106,19 @@ int eDVBCIMMISession::receivedAPDU(const unsigned char *tag, const void *data, i
                                printf("%d bytes text\n", textlen);
                                if ((d+textlen) > max)
                                        break;
+                                       
+                               char str[textlen + 1];
+                               memcpy(str, ((char*)d), textlen);
+                               str[textlen] = '\0';
+                               
+                               eDVBCI_UI::getInstance()->mmiScreenAddText(0, pos++, (char*)convertDVBUTF8(str).c_str());
+                                       
                                while (textlen--)
                                        printf("%c", *d++);
                                printf("\n");
                        }
+                       //FIXME: slotid
+                       eDVBCI_UI::getInstance()->mmiScreenFinish(0);
                        break;
                }
                default:
@@ -90,3 +161,37 @@ int eDVBCIMMISession::doAction()
        return 0;
 }
 
+int eDVBCIMMISession::stopMMI()
+{
+       printf("eDVBCIMMISession::stopMMI()\n");
+
+       unsigned char tag[]={0x9f, 0x88, 0x00};
+       unsigned char data[]={0x00};
+       sendAPDU(tag, data, 1);
+       
+       return 0;
+}
+
+int eDVBCIMMISession::answerText(int answer)
+{
+       printf("eDVBCIMMISession::answerText(%d)\n",answer);
+
+       unsigned char tag[]={0x9f, 0x88, 0x0B};
+       unsigned char data[]={0x00};
+       data[0] = answer & 0xff;
+       sendAPDU(tag, data, 1);
+       
+       return 0;
+}
+
+int eDVBCIMMISession::cancelEnq()
+{
+       printf("eDVBCIMMISession::cancelEnq()\n");
+
+       unsigned char tag[]={0x9f, 0x88, 0x08};
+       unsigned char data[]={0x00};
+       sendAPDU(tag, data, 1);
+       
+       return 0;
+}
+