📄 smb380userdll.cpp
字号:
IOCTL_SMB380_GET_INTERRUPT_STATUS,
NULL,
0,
ist,
sizeof(unsigned char),
NULL,
NULL );
//
// if the operation failed, log an error condition
//
if(fRet == FALSE )
{
DEBUGMSG(1,(_T("smb380_get_interrupt_status failed!\r\n")));
return -1;
}
DEBUGMSG(1,(_T("smb380_get_interrupt_status Out<<<+++\r\n")));
return 0;
}
/** enable/ disable low-g interrupt feature
\param onoff enable=1, disable=0
\return result 0 -> success; -1 -> fail;
*/
int smb380_set_low_g_int(unsigned char onoff) {
BOOL fRet = TRUE;
DEBUGMSG(1,(_T("smb380_set_low_g_int In>>>---\r\n")));
if(smb380handle == NULL){
DEBUGMSG(1,(_T("Should do smb380_open first to get device handle\r\n")));
return -1;
}
fRet = DeviceIoControl( smb380handle,
IOCTL_SMB380_SET_LOW_G_INT,
&onoff,
sizeof(unsigned char),
NULL,
0,
NULL,
NULL );
//
// if the operation failed, log an error condition
//
if(fRet == FALSE )
{
DEBUGMSG(1,(_T("smb380_set_low_g_int failed!\r\n")));
return -1;
}
DEBUGMSG(1,(_T("smb380_set_low_g_int Out<<<+++\r\n")));
return 0;
}
/** enable/disable high-g interrupt feature
\param onoff enable=1, disable=0
\return result 0 -> success; -1 -> fail;
*/
int smb380_set_high_g_int(unsigned char onoff) {
BOOL fRet = TRUE;
DEBUGMSG(1,(_T("smb380_set_high_g_int In>>>---\r\n")));
if(smb380handle == NULL){
DEBUGMSG(1,(_T("Should do smb380_open first to get device handle\r\n")));
return -1;
}
fRet = DeviceIoControl( smb380handle,
IOCTL_SMB380_SET_HIGH_G_INT,
&onoff,
sizeof(unsigned char),
NULL,
0,
NULL,
NULL );
//
// if the operation failed, log an error condition
//
if(fRet == FALSE )
{
DEBUGMSG(1,(_T("smb380_set_high_g_int failed!\r\n")));
return -1;
}
DEBUGMSG(1,(_T("smb380_set_high_g_int Out<<<+++\r\n")));
return 0;
}
/** enable/disable any_motion interrupt feature
\param onoff enable=1, disable=0
\return result 0 -> success; -1 -> fail;
\note for any_motion interrupt feature usage see also \ref smb380_set_advanced_int()
*/
int smb380_set_any_motion_int(unsigned char onoff) {
BOOL fRet = TRUE;
DEBUGMSG(1,(_T("smb380_set_any_motion_int In>>>---\r\n")));
if(smb380handle == NULL){
DEBUGMSG(1,(_T("Should do smb380_open first to get device handle\r\n")));
return -1;
}
fRet = DeviceIoControl( smb380handle,
IOCTL_SMB380_SET_ANY_MOTION_INT,
&onoff,
sizeof(unsigned char),
NULL,
0,
NULL,
NULL );
//
// if the operation failed, log an error condition
//
if(fRet == FALSE )
{
DEBUGMSG(1,(_T("smb380_set_any_motion_int failed!\r\n")));
return -1;
}
DEBUGMSG(1,(_T("smb380_set_any_motion_int Out<<<+++\r\n")));
return 0;
}
/** enable/disable alert-int interrupt feature
\param onoff enable=1, disable=0
\return result 0 -> success; -1 -> fail;
\note for any_motion interrupt feature usage see also \ref smb380_set_advanced_int()
*/
int smb380_set_alert_int(unsigned char onoff) {
BOOL fRet = TRUE;
DEBUGMSG(1,(_T("smb380_set_alert_int In>>>---\r\n")));
if(smb380handle == NULL){
DEBUGMSG(1,(_T("Should do smb380_open first to get device handle\r\n")));
return -1;
}
fRet = DeviceIoControl( smb380handle,
IOCTL_SMB380_SET_ALERT_INT,
&onoff,
sizeof(unsigned char),
NULL,
0,
NULL,
NULL );
//
// if the operation failed, log an error condition
//
if(fRet == FALSE )
{
DEBUGMSG(1,(_T("smb380_set_alert_int failed!\r\n")));
return -1;
}
DEBUGMSG(1,(_T("smb380_set_alert_int Out<<<+++\r\n")));
return 0;
}
/** enable/disable advanced interrupt feature
\param onoff enable=1, disable=0
\return result 0 -> success; -1 -> fail;
\see smb380_set_any_motion_int()
\see smb380_set_alert_int()
*/
int smb380_set_advanced_int(unsigned char onoff) {
BOOL fRet = TRUE;
DEBUGMSG(1,(_T("smb380_set_advanced_int In>>>---\r\n")));
if(smb380handle == NULL){
DEBUGMSG(1,(_T("Should do smb380_open first to get device handle\r\n")));
return -1;
}
fRet = DeviceIoControl( smb380handle,
IOCTL_SMB380_SET_ADVANCED_INT,
&onoff,
sizeof(unsigned char),
NULL,
0,
NULL,
NULL );
//
// if the operation failed, log an error condition
//
if(fRet == FALSE )
{
DEBUGMSG(1,(_T("smb380_set_advanced_int failed!\r\n")));
return -1;
}
DEBUGMSG(1,(_T("smb380_set_advanced_int Out<<<+++\r\n")));
return 0;
}
/** enable/disable latched interrupt for all interrupt feature (global option)
\param latched (=1 for latched interrupts), (=0 for unlatched interrupts)
\return result 0 -> success; -1 -> fail;
*/
int smb380_latch_int(unsigned char latched) {
BOOL fRet = TRUE;
DEBUGMSG(1,(_T("smb380_latch_int In>>>---\r\n")));
if(smb380handle == NULL){
DEBUGMSG(1,(_T("Should do smb380_open first to get device handle\r\n")));
return -1;
}
fRet = DeviceIoControl( smb380handle,
IOCTL_SMB380_LATCH_INT,
&latched,
sizeof(unsigned char),
NULL,
0,
NULL,
NULL );
//
// if the operation failed, log an error condition
//
if(fRet == FALSE )
{
DEBUGMSG(1,(_T("smb380_latch_int failed!\r\n")));
return -1;
}
DEBUGMSG(1,(_T("smb380_latch_int Out<<<+++\r\n")));
return 0;
}
/** enable/disable new data interrupt feature
\param onoff enable=1, disable=0
\return result 0 -> success; -1 -> fail;
*/
int smb380_set_new_data_int(unsigned char onoff) {
BOOL fRet = TRUE;
DEBUGMSG(1,(_T("smb380_set_new_data_int In>>>---\r\n")));
if(smb380handle == NULL){
DEBUGMSG(1,(_T("Should do smb380_open first to get device handle\r\n")));
return -1;
}
fRet = DeviceIoControl( smb380handle,
IOCTL_SMB380_SET_NEW_DATA_INT,
&onoff,
sizeof(unsigned char),
NULL,
0,
NULL,
NULL );
//
// if the operation failed, log an error condition
//
if(fRet == FALSE )
{
DEBUGMSG(1,(_T("smb380_set_new_data_int failed!\r\n")));
return -1;
}
DEBUGMSG(1,(_T("smb380_set_new_data_int Out<<<+++\r\n")));
return 0;
}
/** Wait msec seconds
\int msec : mseconds to pause
\return result 0 -> success; -1 -> fail;
*/
int smb380_pause(int msec) {
BOOL fRet = TRUE;
DEBUGMSG(1,(_T("smb380_pause In>>>---\r\n")));
if(smb380handle == NULL){
DEBUGMSG(1,(_T("Should do smb380_open first to get device handle\r\n")));
return -1;
}
fRet = DeviceIoControl( smb380handle,
IOCTL_SMB380_PAUSE,
&msec,
sizeof(int),
NULL,
0,
NULL,
NULL );
//
// if the operation failed, log an error condition
//
if(fRet == FALSE )
{
DEBUGMSG(1,(_T("smb380_pause failed!\r\n")));
return -1;
}
DEBUGMSG(1,(_T("smb380_pause Out<<<+++\r\n")));
return 0;
}
/** wait until an interrupt rise up then return pending interrupts
\param unsigned char *status : point status contains pending interrupts
\return result 0 -> success; -1 -> fail;
*/
int smb380_wait_interrupt(unsigned char *mask) {
BOOL fRet = TRUE;
DEBUGMSG(1,(_T("smb380_wait_interrupt In>>>---\r\n")));
if(smb380handle == NULL){
DEBUGMSG(1,(_T("Should do smb380_open first to get device handle\r\n")));
return -1;
}
fRet = DeviceIoControl( smb380handle,
IOCTL_SMB380_WAIT_INTERRUPT,
NULL,
0,
mask,
sizeof(unsigned char),
NULL,
NULL );
//
// if the operation failed, log an error condition
//
if(fRet == FALSE )
{
DEBUGMSG(1,(_T("smb380_wait_interrupt failed!\r\n")));
return -1;
}
DEBUGMSG(1,(_T("smb380_wait_interrupt Out<<<+++\r\n")));
return 0;
}
/** Read "len" of data from "addr" to point "data"
\param read_reg * reg : *reg pointer to ref read_reg structure for address, length indicate where and how many to read.
\return result 0 -> success; -1 -> fail;
*/
int smb380_read_reg(read_reg *reg, unsigned char *data) {
BOOL fRet = TRUE;
DEBUGMSG(1,(_T("smb380_read_reg In>>>---\r\n")));
#ifdef DEBUG
printf("in user dll, reg.addr is %x, reg.len is %x, data is %x\r\n", reg->addr, reg->len, *data);
#endif
if(smb380handle == NULL){
DEBUGMSG(1,(_T("Should do smb380_open first to get device handle\r\n")));
return -1;
}
fRet = DeviceIoControl( smb380handle,
IOCTL_SMB380_READ_REG,
reg,
sizeof(read_reg),
data,
reg->len,
NULL,
NULL );
//
// if the operation failed, log an error condition
//
if(fRet == FALSE )
{
DEBUGMSG(1,(_T("smb380_read_reg failed!\r\n")));
return -1;
}
DEBUGMSG(1,(_T("smb380_read_reg Out<<<+++\r\n")));
return 0;
}
/** Write "length" of data to "addr"
\param write_reg * reg : *reg pointer to ref write_reg structure for address, length indicate where and how many to write and data point contains the data to be written.
\return result 0 -> success; -1 -> fail;
*/
int smb380_write_reg(unsigned char addr, unsigned char *data, unsigned char len) {
BOOL fRet = TRUE;
write_reg tmp;
tmp.addr = addr;
tmp.len = len;
tmp.data = data;
DEBUGMSG(1,(_T("smb380_write_reg In>>>---\r\n")));
if(smb380handle == NULL){
DEBUGMSG(1,(_T("Should do smb380_open first to get device handle\r\n")));
return -1;
}
fRet = DeviceIoControl( smb380handle,
IOCTL_SMB380_WRITE_REG,
&tmp,
sizeof(write_reg),
NULL,
0,
NULL,
NULL );
//
// if the operation failed, log an error condition
//
if(fRet == FALSE )
{
DEBUGMSG(1,(_T("smb380_write_reg failed!\r\n")));
return -1;
}
DEBUGMSG(1,(_T("smb380_write_reg Out<<<+++\r\n")));
return 0;
}
/** API DeInitialization routine
\return result 0 -> success; -1 -> fail;
*/
int smb380_deinit()
{
BOOL fRet = TRUE;
DEBUGMSG(1,(_T("smb380_deinit In>>>---\r\n")));
if(smb380handle == NULL){
DEBUGMSG(1,(_T("Should do smb380_init first to get device handle\r\n")));
return -1;
}
fRet = DeviceIoControl( smb380handle,
IOCTL_SMB380_DEINIT,
NULL,
0,
NULL,
0,
NULL,
NULL );
if( fRet == FALSE )
{
DEBUGMSG(1,(_T("smb380_deinit failed!\r\n")));
smb380handle = NULL;
return -1;
}
DEBUGMSG(1,(_T("smb380_close In>>>---\r\n")));
if(CloseHandle(smb380handle) == 0){
DEBUGMSG(1,(_T("smb380_close failed!\r\n")));
return -1;
}
smb380handle = NULL;
DEBUGMSG(1,(_T("smb380_close Out<<<+++\r\n")));
if(DeactivateDevice( smb380driverhandle) == 0){
DEBUGMSG(1,(_T("smb380 deactive device failed!\r\n")));
return -1;
}
smb380driverhandle = NULL;
DEBUGMSG(1,(_T("smb380_deinit Out<<<+++\r\n")));
return 0;
}
/** Dll entry routine
\return result TRUE -> success; FALSE -> fail;
*/
BOOL APIENTRY DllMain( HANDLE hModule,
DWORD ul_reason_for_call,
LPVOID lpReserved
)
{
return TRUE;
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -