예제 #1
0
/* return GOOD if any found */
static GOOD_OR_BAD DS2482_detect_sys( int any, enum ds2482_address chip_num, struct port_in *pin_original)
{
    DIR * i2c_list_dir ;
    struct dirent * i2c_bus ;
    int found = 0 ;
    struct port_in * pin_current = pin_original ;

    // We'll look in this directory for available i2c adapters.
    // This may be linux 2.6 specific
    i2c_list_dir = opendir( SYSFS_I2C_Path ) ;
    if ( i2c_list_dir == NULL ) {
        ERROR_CONNECT( "Cannot open %d to find available i2c devices",SYSFS_I2C_Path ) ;
        // Use the cruder approach of trying all possible numbers
        return DS2482_detect_dir( any, chip_num, pin_original ) ;
    }

    /* cycle through entries in /sys/class/i2c-adapter */
    while ( (i2c_bus=readdir(i2c_list_dir)) != NULL ) {
        char dev_name[128] ; // room for /dev/name
        int sn_ret ;

        UCLIBCLOCK ;
        sn_ret = snprintf( dev_name, 128, "/dev/%s", i2c_bus->d_name ) ;
        UCLIBCUNLOCK ;
        if ( sn_ret < 0 ) {
            break ;
        }

        // Now look for the ds2482's
        if ( BAD( DS2482_detect_bus( chip_num, dev_name, pin_current ) ) ) {
            continue ; // none found on this i2c bus
        }

        // at least one found on this i2c bus
        ++found ;
        if ( any ) { // found one -- that's enough
            closedir( i2c_list_dir ) ;
            return gbGOOD ;
        }

        // ALL? then set up a new connection_in slot for the next one
        pin_current = NewPort(pin_current) ;
        if ( pin_current == NULL ) {
            break ;
        }
    }

    closedir( i2c_list_dir ) ;

    if ( found==0 ) {
        return gbBAD ;
    }

    if ( pin_current != pin_original ) {
        RemovePort( pin_current ) ;
    }
    return gbGOOD ;
}
예제 #2
0
파일: ow_ds9490.c 프로젝트: M-o-a-T/owfs
/* Open a DS9490  -- low level code (to allow for repeats)  */
static GOOD_OR_BAD DS9490_detect_all_adapters(struct port_in * pin_first)
{
	// discover devices
	struct port_in * pin = pin_first ;
	libusb_device **device_list;
	int n_devices = libusb_get_device_list( Globals.luc, &device_list) ;
	int i_device ;
	
	if ( n_devices < 1 ) {
		LEVEL_CONNECT("Could not find a list of USB devices");
		if ( n_devices<0 ) {
			LEVEL_DEBUG("<%s>",libusb_error_name(n_devices));
		}
		return gbBAD ;
	}

	for ( i_device = 0 ; i_device < n_devices ; ++i_device ) {
		libusb_device * current = device_list[i_device] ;
		if ( GOOD( USB_match( current ) ) ) {
			struct connection_in * in = pin->first ;
			if ( BAD(DS9490_open_and_name( current, in)) ) {
				LEVEL_DEBUG("Cannot open USB device %.d:%.d", libusb_get_device_address(current), libusb_get_bus_number(current) );
				continue ;
			} else if ( BAD(DS9490_ID_this_master(in)) ) {
				DS9490_close(in) ;
				LEVEL_DEBUG("Cannot access USB device %.d:%.d", libusb_get_device_address(current), libusb_get_bus_number(current) );
				continue;
			} else{
				pin = NewPort(NULL) ; // no reason to copy anything
				if ( pin == NULL ) {
					return gbGOOD ;
				}
				// set up the new connection for the next adapter
				DS9490_setroutines(in);
			}
		}
	}
	
	libusb_free_device_list(device_list, 1);

	if ( pin == pin_first ) {
		LEVEL_CONNECT("No USB DS9490 bus masters used");
		return gbBAD;
	}
	// Remove the extra connection
	RemovePort(pin);
	return gbGOOD ;
}
예제 #3
0
/* returns GOOD if any adpters found */
static GOOD_OR_BAD DS2482_detect_dir( int any, enum ds2482_address chip_num, struct port_in *pin_original)
{
    int found = 0 ;
    struct port_in * pin_current = pin_original ;
    int bus = 0 ;
    int sn_ret ;

    for ( bus=0 ; bus<99 ; ++bus ) {
        char dev_name[128] ;

        UCLIBCLOCK ;
        sn_ret = snprintf( dev_name, 128-1, "/dev/i2c-%d", bus ) ;
        UCLIBCUNLOCK ;
        if ( sn_ret < 0 ) {
            break ;
        }

        if ( access(dev_name, F_OK) < 0 ) {
            continue ;
        }

        // Now look for the ds2482's
        if ( BAD( DS2482_detect_bus( chip_num, dev_name, pin_current ) ) ) {
            continue ;
        }

        // at least one found
        ++found ;
        if ( any ) {
            return gbGOOD ;
        }

        // ALL? then set up a new connection_in slot
        pin_current = NewPort(pin_current) ;
        if ( pin_current == NULL ) {
            break ;
        }
    }

    if ( found == 0 ) {
        return gbBAD ;
    }

    if ( pin_original != pin_current ) {
        RemovePort(pin_current) ;
    }
    return gbGOOD ;
}
예제 #4
0
DWORD
WINAPI
PortsClassInstaller(IN DI_FUNCTION InstallFunction,
                    IN HDEVINFO DeviceInfoSet,
                    IN PSP_DEVINFO_DATA DeviceInfoData OPTIONAL)
{
    TRACE("PortsClassInstaller(%lu, %p, %p)\n",
          InstallFunction, DeviceInfoSet, DeviceInfoData);

    switch (InstallFunction)
    {
        case DIF_INSTALLDEVICE:
            return InstallPort(DeviceInfoSet, DeviceInfoData);

        case DIF_REMOVE:
            return RemovePort(DeviceInfoSet, DeviceInfoData);

        default:
            TRACE("Install function %u ignored\n", InstallFunction);
            return ERROR_DI_DO_DEFAULT;
    }
}
예제 #5
0
/* This allows removing Bus Masters while program is running
 * The master is usually only read-locked for normal operation
 * write lock is done in a separate thread when no requests are being processed */
void Del_InFlight( GOOD_OR_BAD (*nomatch)(struct port_in * trial,struct port_in * existing), struct port_in * old_pin )
{
	struct connection_in * old_in ;
	if ( old_pin == NULL ) {
		return ;
	}

	old_in = old_pin->first ;
	LEVEL_DEBUG("Request master be removed: %s", DEVICENAME(old_in));

	if ( nomatch != NULL ) {
		struct port_in * pin ;

		CONNIN_WLOCK ;
		for ( pin = Inbound_Control.head_port ; pin != NULL ; pin = pin->next ) {
			if ( BAD( nomatch( old_pin, pin )) ) {
				LEVEL_DEBUG("Removing BUS index=%d %s",pin->first->index,SAFESTRING(DEVICENAME(pin->first)));
				RemovePort(pin) ;
			}
		}
		CONNIN_WUNLOCK ;
	}
}
예제 #6
0
/* Includes  a fix from Pascal Baerten */
static GOOD_OR_BAD DS2482_detect_bus(enum ds2482_address chip_num, char * i2c_device, struct port_in * pin_original)
{
    switch (chip_num) {
    case ds2482_any:
        // usual case, find the first adapter
        return DS2482_detect_single( 0, 7, i2c_device, pin_original ) ;
    case ds2482_all:
        // Look through all the possible i2c addresses
    {
        int start_chip = 0 ;
        struct port_in * all_pin = pin_original ;
        do {
            if ( BAD( DS2482_detect_single( start_chip, 7, i2c_device, all_pin ) ) ) {
                if ( pin_original == all_pin ) { //first time
                    return gbBAD ;
                }
                LEVEL_DEBUG("Cleaning excess allocated i2c structure");
                RemovePort(all_pin); //Pascal Baerten :this removes the false DS2482-100 provisioned
                return gbGOOD ;
            }
            start_chip = all_pin->first->master.i2c.i2c_index + 1 ;
            if ( start_chip > 7 ) {
                return gbGOOD ;
            }
            all_pin = NewPort(all_pin) ;
            if ( all_pin == NULL ) {
                return gbBAD ;
            }
        } while (1) ;
    }
    break ;
    default:
        // specific i2c address
        return DS2482_detect_single( chip_num, chip_num, i2c_device, pin_original ) ;
    }
}
예제 #7
0
bool SelectSIPAccount(CString number, pjsua_acc_id &acc_id, pj_str_t &pj_uri)
{
	SIPURI sipuri;
	ParseSIPURI(number, &sipuri);
	if (pjsua_acc_is_valid(account) && pjsua_acc_is_valid(account_local)) {
		acc_id = account;
		if (accountSettings.account.domain != sipuri.domain) {
			int pos = sipuri.domain.Find(_T(":"));
			CString domainWithoutPort = RemovePort(sipuri.domain);
			if (domainWithoutPort.CompareNoCase(_T("localhost"))==0 || IsIP(domainWithoutPort)) {
				acc_id = account_local;
			}
		}

	} else if (pjsua_acc_is_valid(account)) {
		acc_id = account;
	} else if (pjsua_acc_is_valid(account_local)) {
		acc_id = account_local;
	} else {
		return false;
	}
	pj_uri = StrToPjStr ( GetSIPURI(number, acc_id == account_local, acc_id == account_local) );
	return true;
}
예제 #8
0
MessagesContact* MessagesDlg::AddTab(CString number, CString name, BOOL activate, pjsua_call_info *call_info, BOOL notShowWindow, BOOL ifExists)
{
	MessagesContact* messagesContact;

	SIPURI sipuri;
	ParseSIPURI(number, &sipuri);
	if (!accountSettings.account.domain.IsEmpty() && RemovePort(accountSettings.account.domain) == RemovePort(sipuri.domain) ) {
		sipuri.domain = accountSettings.account.domain;
	}

	number = (sipuri.user.GetLength() ? sipuri.user + _T("@") : _T("")) + sipuri.domain;

	LONG exists = -1;
	for (int i=0; i < tab->GetItemCount(); i++)
	{
		messagesContact = GetMessageContact(i);

		CString compareNumber = messagesContact->number;
#ifdef _GLOBAL_NUMBER_PREFIX
		compareNumber = _T(_GLOBAL_NUMBER_PREFIX) + compareNumber;
#endif
		if (messagesContact->number == number || compareNumber == number) {
			exists=i;
			if (call_info)
			{
				if (messagesContact->callId != -1) {
					if (messagesContact->callId != call_info->id) {
						if (call_info->state != PJSIP_INV_STATE_DISCONNECTED) {
							microsipDlg->PostMessage(MYWM_CALL_ANSWER, (WPARAM)call_info->id, -486);
						}
						return NULL;
					}
				} else {
					messagesContact->callId = call_info->id;
				}
			}
			break;
		}
	}
	if (exists==-1)
	{
		if (ifExists)
		{
			return NULL;
		}
#ifndef _GLOBAL_NO_CONTACTS
		if (!name.GetLength()) {
			name = microsipDlg->pageContacts->GetNameByNumber(number);
#endif
			if (!name.GetLength()) {
				if (!sipuri.name.GetLength())
				{
					name = (sipuri.domain == accountSettings.account.domain ? sipuri.user : number);
				} else 
				{
					name = sipuri.name + _T(" (") + (sipuri.domain == accountSettings.account.domain ? sipuri.user : number) + _T(")");
				}
			}
#ifndef _GLOBAL_NO_CONTACTS
		}
#endif
		messagesContact = new MessagesContact();
		messagesContact->callId = call_info ? call_info->id : -1;
		messagesContact->number = number;
		messagesContact->name = name;
		
		TCITEM item;
		item.mask = TCIF_PARAM | TCIF_TEXT;
		name.Format(_T("   %s  "), name);
		item.pszText=name.GetBuffer();
		item.cchTextMax=0;
		item.lParam = (LPARAM)messagesContact;
		exists = tab->InsertItem(tab->GetItemCount(),&item);
		if (tab->GetCurSel() == exists)
		{
			OnChangeTab(call_info);
		}
	} else
	{
		if (tab->GetCurSel() == exists && call_info)
		{
			UpdateCallButton(messagesContact->callId != -1, call_info);
		}
	}
	//if (tab->GetCurSel() != exists && (activate || !IsWindowVisible()))
	if (tab->GetCurSel() != exists && activate)
	{
		long result;
		OnTcnSelchangingTab(NULL, &result);
		tab->SetCurSel(exists);
		OnChangeTab(call_info);
	}
	if (!IsWindowVisible()) {
		if (!notShowWindow) 
		{
			if (!accountSettings.hidden) {
				ShowWindow(SW_SHOW);
				CRichEditCtrl* richEdit = (CRichEditCtrl*)GetDlgItem(IDC_MESSAGE);
				GotoDlgCtrl(richEdit);
			}
		}
	}
	return messagesContact;
}
예제 #9
0
MRESULT EXPENTRY fnwpClient(HWND hwnd,USHORT msg,MPARAM mp1,MPARAM mp2)
{
    RECTL   rcl;
    USHORT   Command;
    ULONG *pulPtr;

    switch(msg)
    {
    case WM_CREATE:
        stCell.cy = 12;
        stCell.cx = 8;
        hdcPs = WinOpenWindowDC(hwnd);

        /****************************************************************/
        /* Set the size and position of the frame window by making the  */
        /* client area width and height integral numbers of AVIO cell   */
        /* units.  Calculate the frame window values necessary to       */
        /* achieve this.                                                */
        /****************************************************************/

        rcl.yBottom = 0L;
        rcl.xLeft   = 0L;
        rcl.yTop    = 20 * stCell.cy;
        rcl.xRight  = 40 * stCell.cx;

        WinCalcFrameRect(WinQueryWindow(hwnd,QW_PARENT),&rcl,FALSE);

        WinSetWindowPos(WinQueryWindow(hwnd,QW_PARENT),
                        0,
                        7 * stCell.cx,
                        2 * stCell.cy,
                        (SHORT)(rcl.xRight - rcl.xLeft),
                        (SHORT)(rcl.yTop - rcl.yBottom),
                        SWP_MOVE | SWP_SIZE);

        WinPostMsg(hwnd,UM_INIT,0L,0L);
        break;
    case WM_ACTIVATE:
        if(LOUSHORT(LONGFROMMP(mp1)))
            WinSetFocus(HWND_DESKTOP,hwnd);
        break;
    case UM_INIT:
        if (szPortName[0] != 0)
            WinSetWindowText(hwndFrame,szPortName);
        else
            MenuItemEnable(hwndFrame,IDM_PROCESS,FALSE);
        WinShowWindow(hwndFrame,TRUE);
        WinQueryWindowRect(hwndClient,&rcl);
        ulWindowWidth = rcl.xRight;
        ulWindowHeight = rcl.yTop;
        ClearScreen();
        break;
    case WM_PAINT:
        Paint();
        break;
    case WM_SIZE:
        WndSize(hwnd,mp2);
        ClearScreen();
        return WinDefWindowProc(hwnd,msg,mp1,mp2);
    case WM_COMMAND:
        switch (SHORT1FROMMP(mp1))
        {
        case IDM_SELECT:
            if (WinDlgBox(HWND_DESKTOP,
                          hwnd,
                          (PFNWP)fnwpSelectPortDlg,
                          (USHORT)NULL,
                          PS_DLG,
                          NULL))
                WinSetWindowText(hwndFrame,szPortDesc);
            break;
        case IDM_RECOVER_USER_INI:
            RecoverProfile(HINI_USERPROFILE);
            break;
        case IDM_RECOVER_SYS_INI:
            RecoverProfile(HINI_SYSTEMPROFILE);
            break;
        case IDM_EXIT:
            WinPostMsg(hwnd,WM_QUIT,0L,0L);
            break;
        case IDM_SETUP:
            SetupPort();
            break;
        case IDM_REMOVE:
            RemovePort();
            break;
        case IDM_INSTALL:
            InstallPort();
            break;
        case IDM_INIT:
            InitializePort();
            break;
        case IDM_TERM:
            TerminatePort();
//          TerminatePort(szPortName);
            break;
        case IDM_QUERY:
            ulItemCount = QueryPort(achBuffer,4096);
            break;
        default:
            return WinDefWindowProc(hwnd,msg,mp1,mp2);
        }
        break;
    case WM_CLOSE:
        WinPostMsg(hwnd,WM_QUIT,0L,0L);  /* Cause termination     */
        break;
    default:
        return WinDefWindowProc(hwnd,msg,mp1,mp2);
    }
    return(FALSE);
}