예제 #1
0
	void dump(const VertexDecl& _decl)
	{
		if (BX_ENABLED(BGFX_CONFIG_DEBUG) )
		{
			dbgPrintf("vertexdecl %08x (%08x), stride %d\n"
				, _decl.m_hash
				, bx::hashMurmur2A(_decl.m_attributes)
				, _decl.m_stride
				);

			for (uint32_t attr = 0; attr < Attrib::Count; ++attr)
			{
				if (UINT16_MAX != _decl.m_attributes[attr])
				{
					uint8_t num;
					AttribType::Enum type;
					bool normalized;
					bool asInt;
					_decl.decode(Attrib::Enum(attr), num, type, normalized, asInt);

					dbgPrintf("\tattr %d - %s, num %d, type %d, norm %d, asint %d, offset %d\n"
						, attr
						, getAttribName(Attrib::Enum(attr) )
						, num
						, type
						, normalized
						, asInt
						, _decl.m_offset[attr]
					);
				}
			}
		}
	}
void eliza(void){

    uint8_t i, dlci = btRfcommReserveDlci(RFCOMM_DLCI_NEED_EVEN);
    int f;

    if(!dlci) dbgPrintf("ELIZA: failed to allocate DLCI\n");
    else{

        //change descriptor to be valid...
        for(i = 0, f = -1; i < sizeof(sdpDescrEliza); i++){

            if(sdpDescrEliza[i] == MAGIX){
                if(f == -1) f = i;
                else break;
            }
        }

        if(i != sizeof(sdpDescrEliza) || f == -1){

            dbgPrintf("ELIZA: failed to find a single marker in descriptor\n");
            btRfcommReleaseDlci(dlci);
            return;
        }

        sdpDescrEliza[f] = dlci >> 1;

        btRfcommRegisterPort(dlci, elzPortOpen, elzPortClose, elzPortRx);
        btSdpServiceDescriptorAdd(sdpDescrEliza, sizeof(sdpDescrEliza));
    }
}
예제 #3
0
파일: btL2CAP.c 프로젝트: Bhuva28/xda-adk
void l2capServiceTx(uint16_t conn, uint16_t remChan, sg_buf* data){

    uint8_t hdr[4];
    uint16_t len = sg_length(data);

    putLE16(hdr + 0, len);
    putLE16(hdr + 2, remChan);

    if(sg_add_front(data, hdr, 4, SG_FLAG_MAKE_A_COPY)){

        #if UGLY_SCARY_DEBUGGING_CODE
            uint32_t i;
            uint8_t buf[256];
            sg_copyto(data, buf);
            dbgPrintf("L2CAP TX: ");
            for(i = 0; i < sg_length(data); i++) dbgPrintf(" %02X", buf[i]);
            dbgPrintf("\n");
        #endif

        btAclDataTx(conn, 1, BT_BCAST_NONE, data);
    }
    else{

        sg_free(data);
        free(data);
    }
}
예제 #4
0
파일: io.c 프로젝트: mohit-shrma/coursework
void logFArray(const float *arr, int len, const int rank, FILE *logFile) {
  int i;
  if (DEBUG) {
    for (i = 0; i < len; i++) {
      dbgPrintf(logFile, "\nrank=%d arr[%d]=%f ", rank, i,arr[i]);
    }
    dbgPrintf(logFile, "\n");
  }
}
예제 #5
0
파일: io.c 프로젝트: mohit-shrma/coursework
void logArray(const int *arr, int len, const int rank, FILE *logFile) {
  int i;
  if (DEBUG) {
    dbgPrintf(logFile, " rank:%d ", rank);
    for (i = 0; i < len; i++) {
      dbgPrintf(logFile, "%d ", arr[i]);
    }
    dbgPrintf(logFile,"\n");
  }
}
예제 #6
0
void dbgPrintfData(const void* _data, uint32_t _size, const char* _format, ...)
{
#define HEX_DUMP_WIDTH 16
#define HEX_DUMP_SPACE_WIDTH 48
#define HEX_DUMP_FORMAT "%-" DBG_STRINGIZE(HEX_DUMP_SPACE_WIDTH) "." DBG_STRINGIZE(HEX_DUMP_SPACE_WIDTH) "s"

	va_list argList;
	va_start(argList, _format);
	dbgPrintfVargs(_format, argList);
	va_end(argList);

	dbgPrintf("\ndata: " DBG_ADDRESS ", size: %d\n", _data, _size);

	if (NULL != _data)
	{
		const uint8_t* data = reinterpret_cast<const uint8_t*>(_data);
		char hex[HEX_DUMP_WIDTH*3+1];
		char ascii[HEX_DUMP_WIDTH+1];
		uint32_t hexPos = 0;
		uint32_t asciiPos = 0;
		for (uint32_t ii = 0; ii < _size; ++ii)
		{
			bx::snprintf(&hex[hexPos], sizeof(hex)-hexPos, "%02x ", data[asciiPos]);
			hexPos += 3;

			ascii[asciiPos] = isprint(data[asciiPos]) ? data[asciiPos] : '.';
			asciiPos++;

			if (HEX_DUMP_WIDTH == asciiPos)
			{
				ascii[asciiPos] = '\0';
				dbgPrintf("\t" DBG_ADDRESS "\t" HEX_DUMP_FORMAT "\t%s\n", data, hex, ascii);
				data += asciiPos;
				hexPos = 0;
				asciiPos = 0;
			}
		}

		if (0 != asciiPos)
		{
			ascii[asciiPos] = '\0';
			dbgPrintf("\t" DBG_ADDRESS "\t" HEX_DUMP_FORMAT "\t%s\n", data, hex, ascii);
		}
	}

#undef HEX_DUMP_WIDTH
#undef HEX_DUMP_SPACE_WIDTH
#undef HEX_DUMP_FORMAT
}
예제 #7
0
static char btVerboseScanCbkF(void* userData, BtDiscoveryResult* dr){

    if(bt_drF) return bt_drF(dr->mac, dr->PSRM, dr->PSPM, dr->PSM, dr->co, dr->dc);

    dbgPrintf("BT: no callback for scan makes the scan useless, no?");
    return 0;
}
예제 #8
0
static char btConnReqF(void* userData, const uint8_t* mac, uint32_t devClass, uint8_t linkType){	//return 1 to accept

    if(bt_crF) return bt_crF(mac, devClass, linkType);

    dbgPrintf("BT connection request: %s connection from %02x:%02x:%02x:%02x:%02x:%02x (class %06X) -> accepted due to lack of handler\n", linkType ? "ACL" : "SCO", mac[5], mac[4], mac[3], mac[2], mac[1], mac[0], devClass);
    return 1;
}
예제 #9
0
static char btLinkKeyRequest(void* userData, const uint8_t* mac, uint8_t* buf){

    if(bt_krF) return bt_krF(mac, buf);

    dbgPrintf("BT Link key request from %02x:%02x:%02x:%02x:%02x:%02x -> denied due to lack of handler", mac[5], mac[4], mac[3], mac[2], mac[1], mac[0]);
    return 0;
}
예제 #10
0
static uint8_t btPinRequestF(void* userData, const uint8_t* mac, uint8_t* buf){	//fill buff with PIN code, return num bytes used (16 max) return 0 to decline

    if(bt_prF) return bt_prF(mac, buf);

    dbgPrintf("BT PIN request from %02x:%02x:%02x:%02x:%02x:%02x -> '0000' due to lack of handler", mac[5], mac[4], mac[3], mac[2], mac[1], mac[0]);

    buf[0] = buf[1] = buf[2] = buf[3] = '0';
    return 4;
}
예제 #11
0
파일: btRFCOMM.c 프로젝트: Bhuva28/xda-adk
static void btRfcommSend(uint16_t conn, uint16_t remChan, const uint8_t* data, uint16_t sz){

    int i;

    #if UGLY_SCARY_DEBUGGING_CODE
        dbgPrintf("Sending RFCOMM packet:");
        for(i = 0; i < sz; i++) dbgPrintf(" %02X", data[i]);
        dbgPrintf("\n\n");
    #endif

    sg_buf* buf = sg_alloc();
    if(!buf) return;
    if(sg_add_front(buf, data, sz, SG_FLAG_MAKE_A_COPY)){

        l2capServiceTx(conn, remChan, buf);
        return;
    }
    sg_free(buf);
    free(buf);
}
예제 #12
0
파일: Group.cpp 프로젝트: prjemian/iocdoc
void CGroup::SetRefreshTimer(int iRefreshTime)
{
	if(DBG_OPC_REFRESH & dbg_level)
	{
		sprintf(szDbgMessage,"SetRefreshTimer: %s will be refreshed every %d ms ",m_sGroupName.c_str(),iRefreshTime);
		dbgPrintf(DBG_OPC_REFRESH);
		szDbgMessage[0] = NULL;
	}
	m_iRefreshTime = iRefreshTime;
	if(m_hRefreshTimer == 0)
		m_hRefreshTimer = _beginthread(RefreshTimer, 0, this);
//	printf("(%lu)\n",m_hRefreshTimer);
}
예제 #13
0
void adkInit(void){

    //bt init
    static const BtFuncs myBtFuncs = {this, btVerboseScanCbkF, btConnReqF, btConnStartF, btConnEndF, btPinRequestF, btLinkKeyRequest, btLinkKeyCreated, btAclDataRxF, btSspShowF};
    btInit(&myBtFuncs);              //BT UART & HCI driver
    btSdpRegisterL2capService();     //SDP daemon
    btRfcommRegisterL2capService();  //RFCOMM framework

    uint8_t mac[BT_MAC_SIZE];

    if(btLocalMac(mac)) dbgPrintf("BT MAC: %02X:%02X:%02X:%02X:%02X:%02X\n", mac[5], mac[4], mac[3], mac[2], mac[1], mac[0]);

}
예제 #14
0
파일: io.c 프로젝트: mohit-shrma/coursework
void logSparseMat(CSRMat *csrMat, int rank, FILE* myLogFile) {
  
  int i, j;
  
  int startValInd, endValInd;
  
  if (DEBUG) {
  
    dbgPrintf(myLogFile, "\nmyCSRMat Rank:%d numRows:%d", rank, csrMat->numRows);
    dbgPrintf(myLogFile, "\nmyCSRMat Rank:%d nnz count:%d", rank, csrMat->nnzCount);
    dbgPrintf(myLogFile, "\nmyCSRMat Rank: %d rowPtr: ", rank);
    logArray(csrMat->rowPtr, csrMat->numRows+1, rank, myLogFile);
    
    for (i = 0; i < csrMat->numRows; i++) {
      startValInd = csrMat->rowPtr[i] - csrMat->rowPtr[0];
      endValInd = csrMat->rowPtr[i+1] - csrMat->rowPtr[0];
      for (j = startValInd; j < endValInd; j++) {
	//dbgPrintf(myLogFile, "\nrank=%d\t%d\t%d\t%f\t%d", rank, i, csrMat->colInd[j], csrMat->values[j], j);
      }
    }
    dbgPrintf(myLogFile, "\n");
  }
}
예제 #15
0
파일: Group.cpp 프로젝트: prjemian/iocdoc
void CGroup::RefreshTimer(void *param)
{
	if(DBG_OPC_REFRESH & dbg_level)
	{
		sprintf(szDbgMessage,"\nRefresh-circle of Group %s started with %d ms refresh cycle.\n\tWaiting for \"iocInit()\" ...\n",((CGroup*)(param))->m_sGroupName.c_str(),((CGroup*)param)->m_iRefreshTime);
		dbgPrintf(DBG_OPC_REFRESH);
		szDbgMessage[0] = NULL;
	}
	while(((CGroup*)(param))->m_iRefreshTime > 0)
	{
		Sleep(((CGroup*)param)->m_iRefreshTime);
		if(iIocInitReady==1)
		{
			((CGroup*)param)->asyncRefresh(OPC_DS_DEVICE);//OPC_DS_CACHE);
			if(DBG_OPC_REFRESH & dbg_level)
			{
				sprintf(szDbgMessage,"Group %s refreshed.",((CGroup*)(param))->m_sGroupName.c_str());
				dbgPrintf(DBG_OPC_REFRESH);
				szDbgMessage[0] = NULL;
			}
		}
	}
	_endthread();
}
예제 #16
0
파일: Group.cpp 프로젝트: prjemian/iocdoc
BOOL CGroup::AddItem(LPCTSTR szItemID, LPCTSTR szPvName)
{
	BOOL bResult = FALSE;
	if(m_ItemArray = (CItem**)realloc(m_ItemArray, (1+m_ItemCount)*sizeof(CItem**)))
	{
		if(m_ItemArray[m_ItemCount] = (CItem*)addItem(szItemID))
		{
			m_ItemArray[m_ItemCount]->m_soItemID = szItemID;
			m_ItemArray[m_ItemCount]->m_sPvName  = szPvName;
			m_ItemCount++;
			if(DBG_OPC_VARS & dbg_level)
			{
				sprintf(szDbgMessage,"   %s <==> %s (%d)",m_ItemArray[m_ItemCount-1]->m_soItemID,m_ItemArray[m_ItemCount-1]->m_sPvName.c_str(),m_ItemCount);
				dbgPrintf(DBG_OPC_VARS);
				szDbgMessage[0] = NULL;
			}
			bResult = TRUE;
		}
	}
	return bResult;
}
예제 #17
0
파일: io.c 프로젝트: mohit-shrma/coursework
//read the sparse vector of size dim and return
void readSparseVec(float *bVec, char* vecFileName, int dim) {

  FILE *vecFile;
  char *line;
  int i;

  line = (char *)0;

  if ((vecFile = fopen(vecFileName, "r")) == NULL) {
    dbgPrintf(stderr, "Error: failed to read file %s \n", vecFileName);
  } else {
    line = malloc(BUF_SZ);
    for (i = 0; i < dim; i++) {
      fgets(line, BUF_SZ, vecFile);
      bVec[i] = atof(line);
    }
  }

  if (line) {
    free(line);
  }
  fclose(vecFile);
}
예제 #18
0
파일: io.c 프로젝트: mohit-shrma/coursework
//count the number of lines to know the dimension of matrix and vector
void getDimNCount(char *matFileName, int *dim, int *nnz) {
  int nnzCount, ch;
  FILE *fin;
  char *line, *dupLine;

  int row, col;
  float val;

  nnzCount = 0;
  line = malloc(BUF_SZ);
  dupLine = malloc(BUF_SZ);


  if ((fin = fopen(matFileName, "r")) == NULL) {
    dbgPrintf(stderr, \
	    "Error: failed to read file %s while calculating dimensions\n",\
	    matFileName);
    exit(1);
  } else {

    while ((fgets(line, BUF_SZ, fin)) != NULL) {
      nnzCount++;
      memcpy(dupLine, line, BUF_SZ);      
    }

    //get the last row ind
    splitMatRow(dupLine, &row, &col, &val);
    *nnz = nnzCount;
    *dim = row+1;
  }

  
  fclose(fin);
  free(line);
  free(dupLine);
}
bool    AutoUpdate_UartXMODEM_24G(void)
{
    enum SM_FIRMWARE_UPDATE
    {
        SM_FIRMWARE_UPDATE_SOH,
        SM_FIRMWARE_UPDATE_BLOCK,
        SM_FIRMWARE_UPDATE_BLOCK_CMP,
        SM_FIRMWARE_UPDATE_DATA,
        SM_FIRMWARE_UPDATE_CHECKSUM,
        SM_FIRMWARE_UPDATE_FINISH,
    } state;

    uint8_t c;
    // MPFS_HANDLE handle;
    bool lbDone;
    uint8_t blockLen=0;
    bool lResult = false;
    uint8_t BlockNumber=0, preBlockNum=0;
    uint8_t checksum=0;

    uint32_t lastTick;
    uint32_t currentTick;
    state = SM_FIRMWARE_UPDATE_SOH;
    lbDone = false;

#if 0 //use button to begin update
    if( BUTTON3_IO == 1u) return false;
    putsUART("\n\rPress S2 (on Explorer16) to start the update.\n\r");
    while(BUTTON2_IO == 1u);
#else //use console command to begin update
    if(false == wf_update_begin_uart) return false;
    wf_update_begin_uart = false;
#endif

    MACInit();
    DelayMs(100);
    AutoUpdate_Initialize();
    putsUART("Please initiate file transfer of firmware patch by XMODEM.\r\n");
    putsUART("If S3 pressed (on Explorer16), update will stop and previous image will be restored.\r\n");
    lastTick = TickGet();
    do
    {
        currentTick = TickGet();
        if ( currentTick - lastTick >= (TICK_SECOND*2) )
        {
            lastTick = TickGet();
            while(BusyUART());
            WriteUART(XMODEM_NAK);
        }

    } while(!DataRdyUART());


    while(!lbDone)
    {
        if (BUTTON3_IO == 0u)   // If you want to cancel AutoUpdate, please press S3
        {
            putsUART("You press S3 button, revert begin...\r\n");
            AutoUpdate_Restore();
            putsUART("revert done\r\n");
            return false;
        }
        if(DataRdyUART())
        {
            c = ReadUART();
            lastTick = TickGet();
        }
        else
        {
            // put some timeout to make sure  that we do not wait forever.
            currentTick = TickGet();
            if ( currentTick - lastTick >= (TICK_SECOND*10) )
            {
                //if time out, copy old patch image from bank2 to bank1
                putsUART("timeout, revert begin...\r\n");
                AutoUpdate_Restore();
                putsUART("revert done\r\n");
                return false;
            }
            continue;
        }
        //dbgPrintf("(%02x) ",c);
        switch(state)
        {
        case SM_FIRMWARE_UPDATE_SOH:
            if(c == XMODEM_SOH)
            {
                state = SM_FIRMWARE_UPDATE_BLOCK;
                dbgPrintf("\r\n! ");
                checksum = c;
                lResult = true;
            }
            else if ( c == XMODEM_EOT )
            {
                state = SM_FIRMWARE_UPDATE_FINISH;

                while(BusyUART());
                WriteUART(XMODEM_ACK);
                lbDone = true;
            }
            else
            {
                dbgPrintf("\n!error\n");
                while(1);
            }
            break;
        case SM_FIRMWARE_UPDATE_BLOCK:
            BlockNumber = c;
            dbgPrintf("BLK=%d ",BlockNumber);
            checksum += c;
            state = SM_FIRMWARE_UPDATE_BLOCK_CMP;
            break;

        case SM_FIRMWARE_UPDATE_BLOCK_CMP:
            dbgPrintf("%d ",c);
            dbgPrintf("@:");
            //Judge: Is it correct ?
            if(c != (BlockNumber ^ 0xFF))
            {
                lResult = false;
                dbgPrintf("\nBLOCK_CMP err: %x,%x\n", c, BlockNumber ^ 0xFF );
            }
            else
            {
                if((uint8_t)(preBlockNum+1) != BlockNumber)
                {
                    lResult = false;
                    dbgPrintf("\nBLOCK  err %x %x\n",preBlockNum+1,BlockNumber);
                }
            }
            checksum += c;
            blockLen = 0;
            state = SM_FIRMWARE_UPDATE_DATA;
            break;
        case SM_FIRMWARE_UPDATE_DATA:
            // Buffer block data until it is over.
            tempData[blockLen++] = c;
            if ( blockLen == XMODEM_BLOCK_LEN )
            {
                state = SM_FIRMWARE_UPDATE_CHECKSUM;
            }
            checksum += c;

            break;
        case SM_FIRMWARE_UPDATE_CHECKSUM:
            dbgPrintf("Checksum=%x=%x ",checksum,c);
            if(checksum != c)
            {
                lResult = false;
                dbgPrintf("\nchecksum  err\n");
            }
            XMODEM_SendToModule(tempData);
            while(BusyUART());
            if(lResult == true)
            {
                WriteUART(XMODEM_ACK);
                preBlockNum++;
            }
            else
            {
                WriteUART(XMODEM_NAK);
            }
            state = SM_FIRMWARE_UPDATE_SOH;
            break;

        default:
            dbgPrintf("\n!error\n");
            while(1);
            break;
        }

    }

    AutoUpdate_Completed();

    return true;
}
예제 #20
0
파일: btL2CAP.c 프로젝트: Bhuva28/xda-adk
void l2capAclLinkDataRx(uint16_t conn, char first, const uint8_t* data, uint16_t size){

    uint16_t chan, len;
    unsigned i;
    char freeIt = 0;

    #if UGLY_SCARY_DEBUGGING_CODE
        dbgPrintf("L2CAP data:");
        for(chan = 0; chan < size; chan++) dbgPrintf(" %02X", data[chan]);
        dbgPrintf("\n\n");
    #endif

    if(first){

        len = getLE16(data + 0);
        chan = getLE16(data + 2);
        data += 4;
        size -= 4;

        if(size >= len){
            if(size > len) dbgPrintf("L2CAP: ACL provided likely invalid L2CAP packet (ACL.len=%u L2CAP.len=%u)\n", size, len);
        }
        else{
            for(i = 0; i < L2CAP_MAX_PIECED_MESSAGES; i++){

                if(gIncomingPieces[i].conn == conn){

                    dbgPrintf("L2CAP: conn %d: 'first' frame while another incomplete already buffered. Dropping the old one.\n", conn);
                    free(gIncomingPieces[i].buf);
                    gIncomingPieces[i].conn = 0;
                    break;
                }
            }
            if(i == L2CAP_MAX_PIECED_MESSAGES) for(i = 0; i < L2CAP_MAX_PIECED_MESSAGES && gIncomingPieces[i].conn; i++);
            if(i == L2CAP_MAX_PIECED_MESSAGES){

                dbgPrintf("L2CAP: not enough buffer slots to buffer incomplete frame. Dropping\n");
            }
            else{

                uint8_t* ptr = malloc(size);
                if(!ptr){

                    dbgPrintf("L2CAP: cannot allocate partial frame buffer. Dropping\n");
                    return;
                }
                memcpy(ptr, data, size);
                gIncomingPieces[i].buf = ptr;
                gIncomingPieces[i].lenGot = size;
                gIncomingPieces[i].lenNeed = len - size;
                gIncomingPieces[i].chan = chan;
                gIncomingPieces[i].conn = conn;
            }
            return;
        }
    }
    else{

        uint8_t* ptr;

        for(i = 0; i < L2CAP_MAX_PIECED_MESSAGES && gIncomingPieces[i].conn != conn; i++);
        if(i == L2CAP_MAX_PIECED_MESSAGES){
            dbgPrintf("L2CAP: unexpected 'non-first' frame for conn %u. Dropping.\n", conn);
            return;
        }

        if(size > gIncomingPieces[i].lenNeed){

            dbgPrintf("L2CAP: 'non-first' frame too large. Need %u bytes, got %u. Dropping.\n", gIncomingPieces[i].lenNeed, size);
            return;
        }

        ptr = realloc(gIncomingPieces[i].buf, gIncomingPieces[i].lenGot + size);
        if(!ptr){

            dbgPrintf("L2CAP: failed to resize buffer for partial frame receive. Droping\n");
            free(gIncomingPieces[i].buf);
            gIncomingPieces[i].conn = 0;
            return;
        }

        memcpy(ptr + gIncomingPieces[i].lenGot, data, size);
        gIncomingPieces[i].buf = ptr;
        gIncomingPieces[i].lenGot += size;
        gIncomingPieces[i].lenNeed -= size;

        if(gIncomingPieces[i].lenNeed) return; //data still not complete

        gIncomingPieces[i].conn = 0;
        chan = gIncomingPieces[i].chan;
        len = gIncomingPieces[i].lenGot;
        data = ptr;
        freeIt = 1;
    }

    if(chan == 0) dbgPrintf("L2CAP: data on connection %u.0\n", conn);
    else if(chan == 1) l2capHandleControlChannel(conn, data, len);
    else if(chan == 2){	//connectionless

        uint16_t PSM = getLE16(data + 0);
        data += 2;
        len -= 2;

        Service* s = services;

        while(s && s->PSM != PSM) s = s->next;
        if(!s || !(s->descr.flags & L2CAP_FLAG_SUPPORT_CONNECTIONLESS)) dbgPrintf("L2CAP: connectionless data on %u.2 for unknown PSM 0x%04X\n", conn, PSM);
        else s->descr.serviceRx(NULL, data, len);
    }
    else{			//conection-oriented

        Connection* c = l2capFindConnection(conn, chan, NULL);
        if(!c) dbgPrintf("L2CAP: data for nonexistent connection %u.%u\n", conn, chan);
        else c->service->descr.serviceRx(c->serviceInstance, data, len);
    }

    if(freeIt) free(data);
}
예제 #21
0
파일: btL2CAP.c 프로젝트: Bhuva28/xda-adk
static void l2capHandleControlChannel(uint16_t conn, const uint8_t* data, uint16_t size){

    char rejectCommand = 0;
    uint16_t rejectReason = L2CAP_REJECT_REASON_WTF;
    Service* s = services;
    Connection* c;
    uint8_t cmd, id;
    uint8_t buf[16];
    uint16_t chan, remChan, len;

    if(!gL2capID) gL2capID++;

    if(size < 2){

        rejectCommand = 1;
        dbgPrintf("L2CAP: control packet too small\n");
    }
    else{

        cmd = *data++;
        id = *data++;
        len = getLE16(data);
        data += 2;
        size -= 4;

        if(len != size){

            dbgPrintf("L2CAP (control packet internal sizes mismatch (%u != %u)\n", len, size);
            rejectCommand = 1;
        }
        else switch(cmd){

            case L2CAP_CMD_CONN_REQ:{

                uint16_t PSM;

                //get some request data
                if(size != 4){

                    dbgPrintf("L2CAP: ConnectionRequest packet size is wrong(%u)\n", size);
                    rejectCommand = 1;
                    break;
                }

                PSM = getLE16(data + 0);
                remChan = getLE16(data + 2);

                //init the reply
                buf[0] = L2CAP_CMD_CONN_RESP;
                buf[1] = id;
                putLE16(buf + 2, 8);		//length
                putLE16(buf + 4, 0);		//DCID
                putLE16(buf + 6, remChan);	//SCID
                putLE16(buf + 10, 0);		//no further information

                //find the service
                while(s && s->PSM != PSM) s = s->next;
                if(!s || !(s->descr.flags & L2CAP_FLAG_SUPPORT_CONNECTIONS)){

                    dbgPrintf("L2CAP: rejecting conection to unknown PSM 0x%04X\n", PSM);
                    putLE16(buf + 8, L2CAP_CONN_FAIL_NO_SUCH_PSM);
                }
                else{

                    void* instance = NULL;

                    chan = 0;
                    c = malloc(sizeof(Connection));
                    if(c) chan = l2capFindFreeLocalChannel(conn);
                    if(chan) instance = s->descr.serviceInstanceAllocate(conn, chan, remChan);

                    if(instance){

                        putLE16(buf + 4, chan);
                        putLE16(buf + 8, L2CAP_CONN_SUCCESS);

                        c->service = s;
                        c->serviceInstance = instance;
                        c->conn = conn;
                        c->chan = chan;
                        c->remChan = remChan;
                        c->next = connections;
                        connections = c;
                    }
                    else{

                        putLE16(buf + 8, L2CAP_CONN_FAIL_RESOURCES);

                        if(c) free(c);
                    }
                }
                size = 12;
                break;
            }

            case L2CAP_CMD_CONFIG_REQ:{

                uint16_t flags;

                //get some request data
                if(size < 4){
                    dbgPrintf("L2CAP: ConfigurationRequest packet size is wrong(%u)\n", size);
                    rejectCommand = 1;
                    break;
                }

                chan = getLE16(data + 0);
                flags = getLE16(data + 2);
                if(flags & 1){ //flags continue - we do not support that

                    size = 0;
                    break;
                }
                size -= 4;
                data += 4;

                //locate the connection at hand
                c = l2capFindConnection(conn, chan, NULL);
                if(!c){
                    dbgPrintf("L2CAP: ConfigurationRequest for an unknown channel %u.%u\n", conn, chan);
                    rejectCommand = 1;
                    break;
                }
                chan = c->remChan;

                //reply with just our rx-MTU
                buf[0] = L2CAP_CMD_CONFIG_RESP;	
                buf[1] = id;
                putLE16(buf + 2, 10);			//length
                putLE16(buf + 4, c->remChan);		//SCID
                putLE16(buf + 6, 0);			//flags
                putLE16(buf + 8, 0);			//success
                buf[10] = L2CAP_OPTION_MTU;		//mtu_property.type
                buf[11] = 2;				//mtu_property.len
                putLE16(buf + 12, BT_RX_BUF_SZ - 8);	//mtu value
                l2capSendControlRawBuf(conn, buf, 14);	//send it
                
                //we need to send such a packet there too
                buf[0] = L2CAP_CMD_CONFIG_REQ;		//configuration request
                buf[1] = gL2capID++;
                putLE16(buf + 2, 4);			//length
                putLE16(buf + 4, c->remChan);		//SCID
                putLE16(buf + 6, 0);			//flags
                size = 8;
                break;
            }

            case L2CAP_CMD_CONFIG_RESP:{

                //we do nothing here - perhaps we should?
                size = 0;
                break;
            }

            case L2CAP_CMD_DISC_REQ:{

                Connection* p;

                //get some request data
                if(size != 4){

                    dbgPrintf("L2CAP: DisconnectionRequest packet size is wrong(%u)\n", size);
                    rejectCommand = 1;
                    break;
                }
                chan = getLE16(data + 0);
                remChan = getLE16(data + 2);
                c = l2capFindConnection(conn, chan, &p);

                //handle some likely error cases
                if(!c){
                    dbgPrintf("L2CAP: DisconnectionRequest for an unknown channel %u.%u\n", conn, chan);
                    rejectReason = L2CAP_REJECT_REASON_INVALID_CID;
                    rejectCommand = 1;	//reject as per spec
                    break;
                }
                if(c->remChan != remChan){
                    dbgPrintf("L2CAP: DisconnectionRequest for an unmatched channel on %u.%u (%u != %u)\n", conn, chan, c->remChan, remChan);
                    size = 0;		//drop as per spec
                    break;
                }

                //perform needed cleanup
                l2capConnectionCloseEx(c, p, 0);

                //send the reply
                buf[0] = L2CAP_CMD_DISC_RESP;	//disconnection response
                buf[1] = id;			//copied as required
                putLE16(buf + 2, 4);		//length
                putLE16(buf + 4, chan);		//DCID
                putLE16(buf + 6, remChan);	//SCID
                size = 8;
                break;
            }

            case L2CAP_CMD_DISC_RESP:{

                //nothing to do - we did cleanup when we requested the connection closure...
                size = 0;
                break;
            }

            case L2CAP_CMD_ECHO_REQ:{

                buf[0] = L2CAP_CMD_ECHO_RESP;	//ping response
                buf[1] = id;			//copied as required
                putLE16(buf + 2, 0);		//0-length replies are ok
                size = 4;
                break;
            }

            case L2CAP_CMD_INFO_REQ:{

                uint16_t info;

                //get some request data
                if(size != 2){

                    dbgPrintf("L2CAP: InformationRequest packet size is wrong(%u)\n", size);
                    rejectCommand = 1;
                    break;
                }
                info = getLE16(data + 0);

                buf[0] = L2CAP_CMD_INFO_RESP;	//information response
                buf[1] = id;			//copied as required
                putLE16(buf + 4, info);		//info type
                if(info == 1){	//connectionless mtu

                    putLE16(buf + 6, 0);	//success
                    putLE16(buf + 8, BT_RX_BUF_SZ - 8);
                    putLE16(buf + 2, 6);	//length
                    size = 10;
                }
                else if(info == 2){ //extended features

                    putLE16(buf + 6, 0);	//success
                    putLE16(buf + 8, 0); 
                    putLE16(buf + 10, 0); 
                    putLE16(buf + 2, 8);	//length
                    size = 12;
                }
                else{		//whatever this request is, we do not support it

                    putLE16(buf + 6, 1);	//info type not supported
                    putLE16(buf + 2, 4);	//length
                    size = 8;
                }
                break;
            }

            default:{

                dbgPrintf("L2CAP: unexpected command 0x%02X recieved\n", cmd);
                size = 0;
            }
        }
    }

    if(rejectCommand){

        buf[0] = L2CAP_CMD_REJECT;	//disconnection response
        buf[1] = id;			//copied as required
        putLE16(buf + 2, 4);		//length
        putLE16(buf + 4, rejectReason);	//rejection reason
        size = 6;
    }

    if(size) l2capSendControlRawBuf(conn, buf, size);
}
bool    WF_FirmwareUpdate_Uart_24G(void)
{
    enum SM_FIRMWARE_UPDATE
    {
        SM_FIRMWARE_UPDATE_SOH,
        SM_FIRMWARE_UPDATE_BLOCK,
        SM_FIRMWARE_UPDATE_BLOCK_CMP,
        SM_FIRMWARE_UPDATE_DATA,
        SM_FIRMWARE_UPDATE_CHECKSUM,
        SM_FIRMWARE_UPDATE_FINISH,
    } state;

    BYTE c;
   // MPFS_HANDLE handle;
    BOOL lbDone;
    BYTE blockLen=0;
    BOOL lResult = FALSE;
    BYTE BlockNumber=0, preBlockNum=0;
    BYTE checksum=0;
    
    SYS_TICK lastTick;
    SYS_TICK currentTick;
    state = SM_FIRMWARE_UPDATE_SOH;
    lbDone = FALSE;

    TCPIP_NET_HANDLE netH;
    netH = TCPIP_STACK_NetHandle("MRF24W");
    
    if( BUTTON3_IO == 1u) return FALSE;    
    printf("\n\rPress S2 (on Explorer16) to start the update.\n\r");
    while(BUTTON2_IO == 1u);
	printf("1\n");
    WF_Init(netH);//MACInit();
    printf("2\n");
    SYS_TICK_MsDelay(100);
	printf("3\n");
    AutoUpdate_Initialize();
    printf("I am ready, Please transfer firmware patch by XMODEM.\r\n"); 
    printf("If you press S3(On Explorwe16), I will stop update, and restore back to previous firmware.\r\n"); 
    lastTick = SYS_TICK_Get();
    do
    {
        currentTick = SYS_TICK_Get();
        if ( currentTick - lastTick >= (SYS_TICK_TicksPerSecondGet()*2) )
        {
            lastTick = SYS_TICK_Get();
            //todo jw  //while(BusyUART());
            _SYS_CONSOLE_PUTC(XMODEM_NAK); //WriteUART(XMODEM_NAK);
        }

    } while(!_SYS_CONSOLE_DATA_RDY()); //(!DataRdyUART());

    
    while(!lbDone)
    {
        if (BUTTON3_IO == 0u)   // If you want to cancel AutoUpdate, please press S3
        {
            printf("You press S3 button, revert begin...\r\n");
            AutoUpdate_Restore();
            printf("revert done\r\n");
            return FALSE;
        }
        if(_SYS_CONSOLE_DATA_RDY()) //(DataRdyUART())
        {
            c = _SYS_CONSOLE_GETC();//ReadUART();
            lastTick = SYS_TICK_Get();
        }
        else
        {
            // put some timeout to make sure  that we do not wait forever.
             currentTick = SYS_TICK_Get();
            if ( currentTick - lastTick >= (SYS_TICK_TicksPerSecondGet()*10) )
            {
                //if time out, copy old patch image from bank2 to bank1
                printf("timeout, revert begin...\r\n");
                AutoUpdate_Restore();
                printf("revert done\r\n");
                return FALSE;
            }
            continue;
        }
        //dbgPrintf("(%02x) ",c); 
        switch(state)
        {
        case SM_FIRMWARE_UPDATE_SOH:
            if(c == XMODEM_SOH)
            {
                state = SM_FIRMWARE_UPDATE_BLOCK;
                dbgPrintf("\r\n! ");
                checksum = c;
                lResult = TRUE;
            }
            else if ( c == XMODEM_EOT )
            {
                state = SM_FIRMWARE_UPDATE_FINISH;
                
                // todo jw://while(BusyUART());
                _SYS_CONSOLE_PUTC(XMODEM_ACK); //WriteUART(XMODEM_ACK);
                lbDone = TRUE;
            }  
            else
            {
                dbgPrintf("\n!error\n");
                while(1);
            }
            break;
        case SM_FIRMWARE_UPDATE_BLOCK:
            BlockNumber = c;
            dbgPrintf("BLK=%d ",BlockNumber);         
            checksum += c;
            state = SM_FIRMWARE_UPDATE_BLOCK_CMP;
            break;

        case SM_FIRMWARE_UPDATE_BLOCK_CMP:
            dbgPrintf("%d ",c);
            dbgPrintf("@:");
            //Judge: Is it correct ?
            if(c != (BlockNumber ^ 0xFF))
            {
                lResult = FALSE;
                dbgPrintf("\nBLOCK_CMP err: %x,%x\n", c, BlockNumber ^ 0xFF );
            }
            else 
            {
                if((BYTE)(preBlockNum+1) != BlockNumber)
                {
                    lResult = FALSE;
                    dbgPrintf("\nBLOCK  err %x %x\n",preBlockNum+1,BlockNumber);
                }
            }
            checksum += c;
            blockLen = 0;
            state = SM_FIRMWARE_UPDATE_DATA;
            break;
        case SM_FIRMWARE_UPDATE_DATA:
            // Buffer block data until it is over.
            tempData[blockLen++] = c;
            if ( blockLen == XMODEM_BLOCK_LEN )
            {
                state = SM_FIRMWARE_UPDATE_CHECKSUM;
            }
            checksum += c;
            
            break;
        case SM_FIRMWARE_UPDATE_CHECKSUM:
            dbgPrintf("Checksum=%x=%x ",checksum,c);
            if(checksum != c)
            {
                lResult = FALSE;
                dbgPrintf("\nchecksum  err\n");
            }
            XMODEM_SendToModule(tempData);
            // todo jw://while(BusyUART());
            if(lResult == TRUE)
            {
                _SYS_CONSOLE_PUTC(XMODEM_ACK);//WriteUART(XMODEM_ACK);
                preBlockNum++;
            }
            else
            {
                _SYS_CONSOLE_PUTC(XMODEM_NAK);//WriteUART(XMODEM_NAK);
            }
            state = SM_FIRMWARE_UPDATE_SOH;
            break;

        default:
            dbgPrintf("\n!error\n");
            while(1);
            break;
        }

    }
    
    AutoUpdate_Completed();

    return TRUE;
}
예제 #23
0
void
mcos_resched(mInfo_t * mInfo)
{
	fcb_t	  * cfcb;
	fcb_t	  * nfcb;
	int16_t		pid;
	uint32_t	bitmap;

	// Grab and save the vector bitmap and clear the bitmap.
	bitmap = mcos_clear_interrupts(mInfo);

	// Look for interrupts and add the fcb_t to the ready queue.
	if ( unlikely(bitmap) ) {
		int32_t		bit;

		dbgPrintf("Bitmap Vectors %08x\n", bitmap);

		// Loop testing the bitmap bits to see which vectors are active.
		while( (bit = ffs(bitmap)) ) {
			bit--;
			// If the vector array value is not EMPTY then make the pid ready
			if ( mInfo->vector[bit] != FCB_EMPTY ) {
				// Can not call mcos_resume inside of mcos_resched its recursive.
				mcos_ready(mInfo, mInfo->vector[bit], RESCHED_NO);
			}
			// Clear the bit and loop again
			bitmap &= ~(1 << bit);
		}
	}

	// If the current thread and we are the highest priority then continue running.
	if ( ((cfcb = mInfo->curr)->state == FCB_CURR) &&
		 (mcos_lastkey(mInfo, mInfo->rdytail) < cfcb->priority) ) {
		return;
	}

	// Force context switch
	if ( unlikely(cfcb->state == FCB_CURR) ) {
		cfcb->state = FCB_READY;
		cfcb->semid	= 0;
		mcos_insert(mInfo, cfcb->pid, mInfo->rdyhead, cfcb->priority);
	}

	// MCOS exits when it does not have any fibers to run.
	if ( unlikely((pid = mcos_getlast(mInfo, mInfo->rdytail)) == E_EMPTY) ) {
		dbgPrintf("No more fibers to run!\n");
		return;
	}

	nfcb = mcos_getfcb(mInfo, pid);

	// Setup for the new state.
	nfcb->state		= FCB_CURR;
	mInfo->curr		= nfcb;
	mInfo->currpid	= pid;

	// Count the number of times the scheduler has been called.
	mInfo->scheduler_cnt++;

	dbgPrintf("Switch to (%s) state: %s\n", nfcb->name, mcos_state(nfcb->state));
	swapcontext(cfcb->uctx, nfcb->uctx);
}
uint8_t i2cOp(uint8_t instance, uint8_t addr, const uint8_t* sendData, uint8_t sendSz, uint8_t* recvData, uint8_t recvSz){

    uint8_t ret = I2C_ERR_NAK;
    uint32_t stat;

#if I2C_PDC
    uint8_t dat[256];
    uint8_t i;
    uint32_t tmp;
    if (sendData != NULL && (uint32_t)sendData < 0x20000000) {  /* Undocumented feature: PDC can't read from flash */
        if (sendSz > 256)
            return I2C_ERR_INVAL;
        for (i = 0; i < sendSz; i++)
            dat[i] = *sendData++;
        sendData = dat;
    }
#endif

#if !I2C_BITBANG
    Twi *pTwi;
#endif

    if(instance >= I2C_NUM_INSTANCES) return I2C_ERR_INVAL;

#if !I2C_BITBANG
    pTwi = (instance == 0) ? TWI0 : TWI1;
#endif

#if I2C_BITBANG
    addr <<= 1;

    if(sendSz || !recvSz){	//if neither send nor recv requested, do a single send -> this is for a scan

        i2cStart(instance);

        if(!i2cSend(instance, addr)) goto out;
        while(sendSz--) if(!i2cSend(instance, *sendData++)) goto out;
    }
    if(recvSz){

        i2cStart(instance); //if we already sent something, restart

        if(!i2cSend(instance, addr | 1)) goto out;
        while(recvSz){
            recvSz--;
            *recvData++ = i2cRecv(instance, !!recvSz);
        }
    }

    ret = I2C_ALL_OK;
#else

    if (sendSz == 0 && recvSz == 0) {   // Quick (for a scan)
        pTwi->TWI_MMR = 0;
        pTwi->TWI_MMR = (addr << 16);
        pTwi->TWI_CR = TWI_CR_QUICK;
        if (TWI_SR_NACK & i2cWaitTx(pTwi)) {
            i2cWaitComplete(pTwi);
            ret = I2C_ERR_NAK;
            goto out;
        }
        i2cWaitComplete(pTwi);
    }

#if I2C_PDC
    if (sendSz != 0) {
        pTwi->TWI_TPR = (uint32_t)sendData;
        pTwi->TWI_TCR = sendSz;
        pTwi->TWI_MMR = 0;
        pTwi->TWI_MMR = (addr << 16);
        pTwi->TWI_IADR = 0;
        pTwi->TWI_IADR = 0;
        pTwi->TWI_PTCR = TWI_PTCR_TXTEN;
#if I2C_INT_PDC
        i2cInst[instance].status = I2C_STAT_BUSY;
        pTwi->TWI_IER = TWI_IER_TXBUFE | TWI_IER_NACK;
        while((i2cInst[instance].status != I2C_STAT_DONE) &&
              (i2cInst[instance].status != I2C_STAT_NACK))
            coopYield();
        if (i2cInst[instance].status == I2C_STAT_NACK) {
            ret = I2C_ERR_NAK;
            goto out;
        }
#else

        if (TWI_SR_NACK & i2cWaitPdcTx(pTwi)) {
            i2cPdcDisable(pTwi);
            i2cWaitComplete(pTwi);
            ret = I2C_ERR_NAK;
            goto out;
        }
        i2cPdcDisable(pTwi);
        pTwi->TWI_CR = TWI_CR_STOP;
        i2cWaitComplete(pTwi);
#endif
    }

    if (recvSz == 1) {              // We are forced to do the one byte reads manually.
        pTwi->TWI_RPR = (uint32_t)recvData;
        pTwi->TWI_RCR = 1;
        pTwi->TWI_MMR = 0;
        pTwi->TWI_MMR = TWI_MMR_MREAD | (addr << 16);
        pTwi->TWI_CR = TWI_CR_START | TWI_CR_STOP;
        pTwi->TWI_PTCR = TWI_PTCR_RXTEN;
#if I2C_INT_PDC
        i2cInst[instance].status = I2C_STAT_LASTREAD;
        pTwi->TWI_IER = TWI_IER_RXBUFF | TWI_IER_NACK;
        while((i2cInst[instance].status != I2C_STAT_DONE) &&
              (i2cInst[instance].status != I2C_STAT_NACK))
            coopYield();
        if (i2cInst[instance].status == I2C_STAT_NACK) {
            ret = I2C_ERR_NAK;
            goto out;
        }
#else

        if (TWI_SR_NACK & i2cWaitPdcRx(pTwi)) {
            i2cPdcDisable(pTwi);
            i2cWaitComplete(pTwi);
            ret = I2C_ERR_NAK;
            goto out;
        }
        i2cPdcDisable(pTwi);
        i2cWaitComplete(pTwi);
#endif
    }

    if (recvSz > 1) {
        pTwi->TWI_RPR = (uint32_t)recvData;
        pTwi->TWI_RCR = recvSz - 1; // Last byte read is handled manually
        pTwi->TWI_MMR = 0;
        pTwi->TWI_MMR = TWI_MMR_MREAD | (addr << 16);
        pTwi->TWI_CR = TWI_CR_START;
        pTwi->TWI_PTCR = TWI_PTCR_RXTEN;

#if I2C_INT_PDC
        i2cInst[instance].lastByte = recvData + recvSz - 1;
        i2cInst[instance].status = I2C_STAT_BUSY;
        pTwi->TWI_IER = TWI_IER_RXBUFF | TWI_IER_NACK;
        while((i2cInst[instance].status != I2C_STAT_DONE) &&
              (i2cInst[instance].status != I2C_STAT_NACK))
            coopYield();
        if (i2cInst[instance].status == I2C_STAT_NACK) {
            ret = I2C_ERR_NAK;
            goto  out;
        }
#else
        if (TWI_SR_NACK & i2cWaitPdcRx(pTwi)) {
            i2cPdcDisable(pTwi);
            i2cWaitComplete(pTwi);
            ret = I2C_ERR_NAK;
            goto out;
        }
        i2cPdcDisable(pTwi);
        pTwi->TWI_CR = TWI_CR_STOP;
        pTwi->TWI_RPR = (uint32_t)(recvData + recvSz - 1);
        pTwi->TWI_RCR = 1;
        pTwi->TWI_PTCR = TWI_PTCR_RXTEN;
        if (TWI_SR_NACK & i2cWaitPdcRx(pTwi)) {
            i2cPdcDisable(pTwi);
            i2cWaitComplete(pTwi);
            ret = I2C_ERR_NAK;
            goto out;
        }
        i2cPdcDisable(pTwi);
        i2cWaitComplete(pTwi);
#endif
    }
    ret = I2C_ALL_OK;
#else
    if (sendSz != 0) {
        pTwi->TWI_MMR = 0;
        pTwi->TWI_MMR = (addr << 16);
        pTwi->TWI_IADR = 0;
        pTwi->TWI_IADR = 0;
        while (sendSz--) {
            pTwi->TWI_THR = *sendData++;
            stat = i2cWaitTx(pTwi);
            if (stat & TWI_SR_NACK) {
                ret = I2C_ERR_NAK;
                goto out;
            }
        }
        pTwi->TWI_CR = TWI_CR_STOP;
        i2cWaitComplete(pTwi);
    }

    if (recvSz == 1) {
        pTwi->TWI_MMR = 0;
        pTwi->TWI_MMR = TWI_MMR_MREAD | (addr << 16);
        pTwi->TWI_IADR = 0;
        pTwi->TWI_IADR = 0;
        pTwi->TWI_CR = TWI_CR_START | TWI_CR_STOP;
        if (TWI_SR_NACK & i2cWaitRx(pTwi)) {
            ret = I2C_ERR_NAK;
            goto out;
        }
        *recvData = pTwi->TWI_RHR;
        i2cWaitComplete(pTwi);
    } else if (recvSz >= 1) {
        pTwi->TWI_MMR = 0;
        pTwi->TWI_MMR = TWI_MMR_MREAD | (addr << 16);
        pTwi->TWI_IADR = 0;
        pTwi->TWI_IADR = 0;
        pTwi->TWI_CR = TWI_CR_START;
        while (recvSz--) {
            if (TWI_SR_NACK & i2cWaitRx(pTwi)) {
                ret = I2C_ERR_NAK;
                goto out;
            }
            dbgPrintf("\0");
            *recvData++ = pTwi->TWI_RHR;
            if (recvSz == 1) pTwi->TWI_CR = TWI_CR_STOP;
        }
        i2cWaitComplete(pTwi);
    }

    ret = I2C_ALL_OK;
#endif
#endif

out:

#if I2C_BITBANG
    i2cStop(instance);
#else
    if (ret != I2C_ALL_OK) {
        pTwi->TWI_CR = TWI_CR_STOP;
        i2cWaitComplete(pTwi);
    }
#endif

    return ret;
}
예제 #25
0
void SipPhoneProxy::incomingSubscribe( SipCallMember *member, bool sendSubscribe )
{
	//clist->auditList();
	if( member == 0 )
	{
		return;
	}
	dbgPrintf( "KPhoneView: Incoming Subscribe\n" );
	bool remove_subscribe = false;
	SipUri uri = member->getUri();
	QString uristr = member->getUri().reqUri();
	//for ( QStringList::Iterator it = rejectedContactList.begin(); it != rejectedContactList.end(); ++it )
	//{
	//  if( uristr == QString(*it) )
	//  {
	//    dbgPrintf( "KPhoneView: Incoming Subscribe Rejected\n" );
	//    remove_subscribe = true;
	//  }
	//}
	SipCallIterator it( _pSipClient->getCallList() );
	SipCall* current = NULL;
	bool find = false;
	if( !remove_subscribe )
	{
		it.toFront();
		while(it.hasNext())
		{
			current = it.next();
			if(current->getCallType() == SipCall::outSubscribeCall)
			{
				if(current->getMember(uri) != NULL)
				{
					find = true;
				}
			}
		}

	}
	if( !find && !remove_subscribe)
	{
		QString uristr = member->getUri().reqUri();
		QMessageBox mb( tr("Contacts"),
			tr("Subscribe message from uri:") + "\n" + uristr + "\n\n" +
			tr("Do you want to accept and create a contact ?"),
			QMessageBox::Information,
			QMessageBox::Yes | QMessageBox::Default,
			QMessageBox::No,
			QMessageBox::Cancel | QMessageBox::Escape );
		mb.setButtonText( QMessageBox::Yes, tr("Accept") );
		mb.setButtonText( QMessageBox::No, tr("Reject permanently") );
		mb.setButtonText( QMessageBox::Cancel, tr("Reject this time") );
		switch( mb.exec() )
		{
		case QMessageBox::Yes:
			//addContactToPhoneBook( member );
			sendSubscribe = false;
			break;
		case QMessageBox::No:
			//rejectedContactList.append( member->getUri().reqUri() );
			//saveRejectContactList();
			remove_subscribe = true;
			break;
		case QMessageBox::Cancel:
			remove_subscribe = true;
			break;
		}
	}
	if( remove_subscribe )
	{
		current = NULL;
		it.toFront();
		while(it.hasNext())
		{
			current = it.next();
			if(current->getCallType() == SipCall::inSubscribeCall)
			{
				if(current->getMember(uri))
				{
					delete current;
				}
			}
		}

		return;
	}
	if( _isOnline )
	{
		connect( member, SIGNAL( statusUpdated( SipCallMember * ) ), _pSipAuthentication, SLOT( authRequest( SipCallMember * ) ) );
		sendNotify( ONLINE, member );
	}

	current = NULL;
	it.toFront();
	while(it.hasNext())
	{
		current = it.next();
		if( current->getCallType() == SipCall::outSubscribeCall )
		{
			if( current->getCallStatus() != SipCall::callDead )
			{
				if( current->getMember( uri ) )
				{
					if( sendSubscribe )
					{
						if( _pSipRegister->getRegisterState() == SipRegister::Connected )
						{
							QString uristr = current->getSubject();
							QString contactStr = current->getContactStr();
							if( current->getCallStatus() == SipCall::callInProgress )
							{
								current->getMember( uri )->requestClearSubscribe();
							}
							delete current;
							SipCall *newcall = new SipCall( _pSipUser, QString::null, SipCall::outSubscribeCall );
							newcall->setSubject( uristr );
							SipUri remoteuri( uristr );
							member = new SipCallMember( newcall, remoteuri );
							//connect( member, SIGNAL( statusUpdated( SipCallMember * ) ), clist, SLOT( auditList() ) );
							connect( member, SIGNAL( statusUpdated( SipCallMember * ) ), _pSipAuthentication, SLOT( authRequest( SipCallMember * ) ) );
							member->requestSubscribe( _subscribeExpiresTime );
							newcall->setContactStr( contactStr );
							break;
						}
					}
				}
			}
		}
	}
}
static void elzPortClose(void* port, uint8_t dlci){

    dbgPrintf("Remote client left...\n");
}
static void elzPortOpen(void* port, uint8_t dlci){

    dbgPrintf("Remote client joined...\n");
    elzSetup();
}
예제 #28
0
DWORD WINAPI CardDeleteContainer(__in PCARD_DATA pCardData, __in BYTE bContainerIndex, __in DWORD dwReserved)
{ dbgPrintf("[%s:%d] CardDeleteContainer:dummy",__FUNCTION__, __LINE__); return ret(E_UNSUPPORTED); }
예제 #29
0
파일: rxmain.c 프로젝트: ahopper/rc24
/****************************************************************************
 *
 * NAME: AppColdStart
 *
 * DESCRIPTION:
 * Entry point for application from boot loader. Initialises system and runs
 * main loop.
 *
 * RETURNS:
 * Never returns.
 *
 ****************************************************************************/
PUBLIC void AppColdStart(void)
{
#if (defined JN5148 || defined JN5168 )
	// TODO - use watch dog and probably disable brownout reset
	vAHI_WatchdogStop();
#endif
#ifdef JN5139
	vAppApiSetBoostMode(TRUE);
#endif

	// Initialise the hopping mode status
	// TODO - move to settings?
	setHopMode(hoppingRxStartup);

	connectObjects();
	RX.ro.version=2;

	// Initialise the system
	vInitSystem();

	// set up the exception handlers
	setExceptionHandlers();


	if(!radioDebug)debugRoute=&pcViaComPort;
	else debugRoute=&pcViaTx;

	if (debugRoute->routeNodes[0] == CONPC)
	{
		// Don't use uart pins for servo op
		initPcComs(&pccoms, CONPC, 0, rxHandleRoutedMessage);
		rxHardware.uart0InUse=TRUE;
	}


	// Initialise the clock
	// TODO - fix this
	/* the jn5148 defaults to 16MHz for the processor,
	   it can be switched to 32Mhz however the servo driving
	   code would need tweaking
	   */
	//bAHI_SetClockRate(3);


	resetType rt=getResetReason();
	if(rt!=NOEXCEPTION)
	{
		dbgPrintf("EXCEPTION %d \r\n",rt);
	}


	// Set handler for incoming data
	setRadioDataCallback(rxHandleRoutedMessage, CONTX);

	// Retrieve the MAC address and log it to the PC
	module_MAC_ExtAddr_s* macptr = (module_MAC_ExtAddr_s*)pvAppApiGetMacAddrLocation();


	// Send init string to PC log rx mac and bound tx mac to pc
	dbgPrintf("rx24 2.10 rx %x %x tx %x %x",macptr->u32H, macptr->u32L,txMACh ,txMACl );


	// Use dio 16 for test sync pulse
	vAHI_DioSetDirection(0, 1 << 16);


	// Set demands to impossible values
	// TODO - fix magic numbers grrr
	int i;
	for (i = 0; i < 20; i++)
	{
		RX.rxDemands[i] = 4096;
		RX.rxMixedDemands[i] = 4096;
	}
	rxHardware.i2cInUse=imu.enabled;
	startIMU(&imu);


	// Set up digital inputs and outputs
	initInputs(&rxHardware);
	initOutputs(&rxHardware);



	if(rxHardware.oneWireEnabled==TRUE)
	{
		// enable onewire sensor bus
		initOneWireBus(&sensorBus1,CONONEWIRE,rxHardware.oneWirePort,rxHandleRoutedMessage);

	}
	if(rxHardware.gpsEnabled==TRUE)
	{
		initNmeaGps(rxHardware.gpsPort, E_AHI_UART_RATE_38400);
	}

	// Setup DIO  for the LED
	vAHI_DioSetDirection(0, rxHardware.ledBit);

	// Initialise Analogue peripherals
	vAHI_ApConfigure(E_AHI_AP_REGULATOR_ENABLE, E_AHI_AP_INT_DISABLE,
			E_AHI_AP_SAMPLE_8, E_AHI_AP_CLOCKDIV_500KHZ, E_AHI_AP_INTREF);

	while (bAHI_APRegulatorEnabled() == 0)
		;


	// Start the servo pwm generator
	setFrameCallback(frameStartEvent);
	setMixCallback(mixEvent);



	startServoPwm(RX.servoUpdateRate);


	// Enter the never ending main handler
	while (1)
	{
		// Process any events
		vProcessEventQueues();
	}
}
예제 #30
0
파일: rxmain.c 프로젝트: ahopper/rc24
/****************************************************************************
 *
 * NAME: vHandleMcpsDataInd
 *
 * DESCRIPTION:  Handler for received data
 *
 * PARAMETERS:      Name            RW  Usage
 *					psMcpsInd		R	pointer to received data struct
 * RETURNS:
 *
 * NOTES:
 ****************************************************************************/
PRIVATE void vHandleMcpsDataInd(MAC_McpsDcfmInd_s *psMcpsInd)
{
	// Get the received data structure
	MAC_RxFrameData_s *psFrame = &psMcpsInd->uParam.sIndData.sFrame;

	// Get the mac address
	// TODO - pvAppApiGetMacAddrLocation not in docs
	// TODO - macptr not used as code is commented out
	module_MAC_ExtAddr_s* macptr = (module_MAC_ExtAddr_s*)pvAppApiGetMacAddrLocation();

	uint8 realTimeDataLen=psFrame->au8Sdu[0];
	uint8 lowPriorityDataLen=psFrame->u8SduLength-1-realTimeDataLen;


	// If not associated ??
	// TODO - should this be merged with similar code below [1]
	if (sEndDeviceData.eState != E_STATE_ASSOCIATED)
	{
		// Check for bind acceptance
		// if routed packet, handle it
		if(lowPriorityDataLen>0)
		{
			handleLowPriorityData(&psFrame->au8Sdu[realTimeDataLen+1], lowPriorityDataLen);
			return;
		}
	}

	// Only accept from bound tx
	// TODO - the TX_ADDRESS_MODE stops the following code from being reached


	if (TX_ADDRESS_MODE == 3 && (psFrame->sSrcAddr.uAddr.sExt.u32H != txMACh
			|| psFrame->sSrcAddr.uAddr.sExt.u32L != txMACl))
	{


		return;
	}
	//debugCount1++;

	// First frame, we have an association
	// TODO - Should this be merged with code above [1]
	if (sEndDeviceData.eState != E_STATE_ASSOCIATED)
	{
//		dbgPrintf("tx found \r\n");
		dbgPrintf("tx found %x %x\r\n",txMACh ,txMACl );


		// Update the association state
		sEndDeviceData.eState = E_STATE_ASSOCIATED;

		// Set the hopping mode
		setHopMode(hoppingContinuous);
	}

	//the same packet can be received many times if the ack was not received by the sender

	if(!frameReceived)
	{
		frameReceived=TRUE;
		// Record the link quality
		txLinkQuality = psFrame->u8LinkQuality;

		/*
		 * TODO - define a structure for this
		 * packet layout:
		 * [0] - 8 bit seqno
		 * [1] - 16 bit tx time
		 */
/* now done in interrupt context
		// retrieve the tx time, calculate the rx time ??
		// TODO - explain rx time calc
		int txTime = (psFrame->au8Sdu[1] + (psFrame->au8Sdu[2] << 8)) * 160;
		//allow for latencies along the way and calculate the time we think the tx has now.
		//allow for variations in packet length @ 250kbps
		//32us per byte is 512 clocks per byte
		int rxTime = (txTime + 2000* 16 +(psFrame->u8SduLength-8)*512  ) % (31* 20000* 16 ) ;

		// TODO - Explain this
		calcSyncError(rxTime);
*/
		// Update global rx data packet counter
		rxdpackets++;

		// Update latest received se. no.
		sEndDeviceData.u8RxPacketSeqNb = psFrame->au8Sdu[0];

		// Process the data packet
		vProcessReceivedDataPacket(&psFrame->au8Sdu[3], realTimeDataLen-2);

		// If there is more data, process it
		if(lowPriorityDataLen>0)
		{
		//	debugCount1++;
			handleLowPriorityData(&psFrame->au8Sdu[realTimeDataLen+1], lowPriorityDataLen);
		}

		// Send some data back
		// should check there is time to do this and limit retries

#ifdef JN5168
		//don't send if near the end of the frame as jn5168 gets upset
		//if channel changed during transmission
	//	if(getSeqClock()%(20000*16)>14000*16)return;
	//	return;
#endif

		// Declare the return packet data and default size
		uint8 au8Packet[6];
		uint8 packetLen = 4;

		// Set the return packet data indicator
		au8Packet[1] = returnPacketIdx;

		uint16 val = 0;
		switch (returnPacketIdx)
		{
		case 0:
		case 1:
		case 2:
		case 3:
		case 4:
		case 5:
		{
			// 0 - 5 ADC channels
			val = u16ReadADC(returnPacketIdx);
			au8Packet[2] = val & 0xff;
			au8Packet[3] = val >> 8;
			break;
		}
		case 6:
		{
			// 6 - TX Quality
			au8Packet[2] = getErrorRate();
			au8Packet[3] = txLinkQuality;

			// If unable to read GPS data skip the GPS data items
			if (readNmeaGps(&gpsData) == FALSE)
				returnPacketIdx = 13;
			break;
		}
		case 7:
		{
			// 7 - GPS speed
			readNmeaGps(&gpsData);
			memcpy(&au8Packet[2], &gpsData.nmeaspeed, sizeof(gpsData.nmeaspeed));
			packetLen = 6;
			break;
		}
		case 8:
		{
			// 8 - GPS height
			readNmeaGps(&gpsData);
			memcpy(&au8Packet[2], &gpsData.nmeaheight,
					sizeof(gpsData.nmeaheight));
			packetLen = 6;
			break;
		}
		case 9:
		{
			// 9 - GPS track
			readNmeaGps(&gpsData);
			memcpy(&au8Packet[2], &gpsData.nmeatrack, sizeof(gpsData.nmeatrack));
			packetLen = 6;
			break;
		}
		case 10:
		{
			// 10 - GPS time
			readNmeaGps(&gpsData);
			memcpy(&au8Packet[2], &gpsData.nmeatime, sizeof(gpsData.nmeatime));
			packetLen = 6;
			break;
		}
		case 11:
		{
			// 11 - GPS latitude
			readNmeaGps(&gpsData);
			memcpy(&au8Packet[2], &gpsData.nmealat, sizeof(gpsData.nmealat));
			packetLen = 6;
			break;
		}
		case 12:
		{
			// 12 - GPS longitude
			readNmeaGps(&gpsData);
			memcpy(&au8Packet[2], &gpsData.nmealong, sizeof(gpsData.nmealong));
			packetLen = 6;
			break;
		}
		case 13:
		{
			// 13 - satellites
			readNmeaGps(&gpsData);
			memcpy(&au8Packet[2], &gpsData.nmeasats, sizeof(gpsData.nmeasats));
			packetLen = 6;
			break;
		}
		case 14:
		{
			//corrected battery voltage in 0.01v units
			val = u16ReadADC(rxHardware.batVoltageChannel);
			int volts=val*rxHardware.batVoltageMultiplier/4096+rxHardware.batVoltageOffset;
			au8Packet[2] = volts & 0xff;
			au8Packet[3] = volts >> 8;


		}
		}

		// Set the data length
		au8Packet[0] = packetLen - 1;

		// Send the packet
		vTransmitDataPacket(au8Packet, packetLen, FALSE);

		// Update the data type for the next packet
		returnPacketIdx++;

		// If the last data type has been sent, reset to 0
		if (returnPacketIdx >= 15)
			returnPacketIdx = 0;
	}