diff --git a/app/src/main/java/com/casic/endoscope/greendao/DaoMaster.java b/app/src/main/java/com/casic/endoscope/greendao/DaoMaster.java index a455fd0..514d3ba 100644 --- a/app/src/main/java/com/casic/endoscope/greendao/DaoMaster.java +++ b/app/src/main/java/com/casic/endoscope/greendao/DaoMaster.java @@ -13,18 +13,23 @@ // THIS CODE IS GENERATED BY greenDAO, DO NOT EDIT. + /** * Master of DAO (schema version 1): knows all DAOs. */ public class DaoMaster extends AbstractDaoMaster { public static final int SCHEMA_VERSION = 1; - /** Creates underlying database table using DAOs. */ + /** + * Creates underlying database table using DAOs. + */ public static void createAllTables(Database db, boolean ifNotExists) { GasValueBeanDao.createTable(db, ifNotExists); } - /** Drops underlying database table using DAOs. */ + /** + * Drops underlying database table using DAOs. + */ public static void dropAllTables(Database db, boolean ifExists) { GasValueBeanDao.dropTable(db, ifExists); } @@ -75,7 +80,9 @@ } } - /** WARNING: Drops all table on Upgrade! Use only during development. */ + /** + * WARNING: Drops all table on Upgrade! Use only during development. + */ public static class DevOpenHelper extends OpenHelper { public DevOpenHelper(Context context, String name) { super(context, name); diff --git a/app/src/main/java/com/casic/endoscope/greendao/DaoMaster.java b/app/src/main/java/com/casic/endoscope/greendao/DaoMaster.java index a455fd0..514d3ba 100644 --- a/app/src/main/java/com/casic/endoscope/greendao/DaoMaster.java +++ b/app/src/main/java/com/casic/endoscope/greendao/DaoMaster.java @@ -13,18 +13,23 @@ // THIS CODE IS GENERATED BY greenDAO, DO NOT EDIT. + /** * Master of DAO (schema version 1): knows all DAOs. */ public class DaoMaster extends AbstractDaoMaster { public static final int SCHEMA_VERSION = 1; - /** Creates underlying database table using DAOs. */ + /** + * Creates underlying database table using DAOs. + */ public static void createAllTables(Database db, boolean ifNotExists) { GasValueBeanDao.createTable(db, ifNotExists); } - /** Drops underlying database table using DAOs. */ + /** + * Drops underlying database table using DAOs. + */ public static void dropAllTables(Database db, boolean ifExists) { GasValueBeanDao.dropTable(db, ifExists); } @@ -75,7 +80,9 @@ } } - /** WARNING: Drops all table on Upgrade! Use only during development. */ + /** + * WARNING: Drops all table on Upgrade! Use only during development. + */ public static class DevOpenHelper extends OpenHelper { public DevOpenHelper(Context context, String name) { super(context, name); diff --git a/app/src/main/java/com/casic/endoscope/greendao/DaoSession.java b/app/src/main/java/com/casic/endoscope/greendao/DaoSession.java index 259243d..f252abc 100644 --- a/app/src/main/java/com/casic/endoscope/greendao/DaoSession.java +++ b/app/src/main/java/com/casic/endoscope/greendao/DaoSession.java @@ -14,7 +14,7 @@ /** * {@inheritDoc} - * + * * @see org.greenrobot.greendao.AbstractDaoSession */ public class DaoSession extends AbstractDaoSession { @@ -34,7 +34,7 @@ registerDao(GasValueBean.class, gasValueBeanDao); } - + public void clear() { gasValueBeanDaoConfig.clearIdentityScope(); } diff --git a/app/src/main/java/com/casic/endoscope/greendao/DaoMaster.java b/app/src/main/java/com/casic/endoscope/greendao/DaoMaster.java index a455fd0..514d3ba 100644 --- a/app/src/main/java/com/casic/endoscope/greendao/DaoMaster.java +++ b/app/src/main/java/com/casic/endoscope/greendao/DaoMaster.java @@ -13,18 +13,23 @@ // THIS CODE IS GENERATED BY greenDAO, DO NOT EDIT. + /** * Master of DAO (schema version 1): knows all DAOs. */ public class DaoMaster extends AbstractDaoMaster { public static final int SCHEMA_VERSION = 1; - /** Creates underlying database table using DAOs. */ + /** + * Creates underlying database table using DAOs. + */ public static void createAllTables(Database db, boolean ifNotExists) { GasValueBeanDao.createTable(db, ifNotExists); } - /** Drops underlying database table using DAOs. */ + /** + * Drops underlying database table using DAOs. + */ public static void dropAllTables(Database db, boolean ifExists) { GasValueBeanDao.dropTable(db, ifExists); } @@ -75,7 +80,9 @@ } } - /** WARNING: Drops all table on Upgrade! Use only during development. */ + /** + * WARNING: Drops all table on Upgrade! Use only during development. + */ public static class DevOpenHelper extends OpenHelper { public DevOpenHelper(Context context, String name) { super(context, name); diff --git a/app/src/main/java/com/casic/endoscope/greendao/DaoSession.java b/app/src/main/java/com/casic/endoscope/greendao/DaoSession.java index 259243d..f252abc 100644 --- a/app/src/main/java/com/casic/endoscope/greendao/DaoSession.java +++ b/app/src/main/java/com/casic/endoscope/greendao/DaoSession.java @@ -14,7 +14,7 @@ /** * {@inheritDoc} - * + * * @see org.greenrobot.greendao.AbstractDaoSession */ public class DaoSession extends AbstractDaoSession { @@ -34,7 +34,7 @@ registerDao(GasValueBean.class, gasValueBeanDao); } - + public void clear() { gasValueBeanDaoConfig.clearIdentityScope(); } diff --git a/app/src/main/java/com/casic/endoscope/greendao/GasValueBeanDao.java b/app/src/main/java/com/casic/endoscope/greendao/GasValueBeanDao.java index 5149375..6025bbf 100644 --- a/app/src/main/java/com/casic/endoscope/greendao/GasValueBeanDao.java +++ b/app/src/main/java/com/casic/endoscope/greendao/GasValueBeanDao.java @@ -12,9 +12,10 @@ import org.greenrobot.greendao.internal.DaoConfig; // THIS CODE IS GENERATED BY greenDAO, DO NOT EDIT. -/** + +/** * DAO for table "GAS_VALUE_BEAN". -*/ + */ public class GasValueBeanDao extends AbstractDao { public static final String TABLENAME = "GAS_VALUE_BEAN"; @@ -34,14 +35,16 @@ public GasValueBeanDao(DaoConfig config) { super(config); } - + public GasValueBeanDao(DaoConfig config, DaoSession daoSession) { super(config, daoSession); } - /** Creates the underlying database table. */ + /** + * Creates the underlying database table. + */ public static void createTable(Database db, boolean ifNotExists) { - String constraint = ifNotExists? "IF NOT EXISTS ": ""; + String constraint = ifNotExists ? "IF NOT EXISTS " : ""; db.execSQL("CREATE TABLE " + constraint + "\"GAS_VALUE_BEAN\" (" + // "\"_id\" INTEGER PRIMARY KEY AUTOINCREMENT ," + // 0: id "\"TIME\" TEXT," + // 1: time @@ -49,7 +52,9 @@ "\"LOCATION\" TEXT);"); // 3: location } - /** Drops the underlying database table. */ + /** + * Drops the underlying database table. + */ public static void dropTable(Database db, boolean ifExists) { String sql = "DROP TABLE " + (ifExists ? "IF EXISTS " : "") + "\"GAS_VALUE_BEAN\""; db.execSQL(sql); @@ -58,18 +63,18 @@ @Override protected final void bindValues(DatabaseStatement stmt, GasValueBean entity) { stmt.clearBindings(); - + Long id = entity.getId(); if (id != null) { stmt.bindLong(1, id); } - + String time = entity.getTime(); if (time != null) { stmt.bindString(2, time); } stmt.bindLong(3, entity.getValue()); - + String location = entity.getLocation(); if (location != null) { stmt.bindString(4, location); @@ -79,18 +84,18 @@ @Override protected final void bindValues(SQLiteStatement stmt, GasValueBean entity) { stmt.clearBindings(); - + Long id = entity.getId(); if (id != null) { stmt.bindLong(1, id); } - + String time = entity.getTime(); if (time != null) { stmt.bindString(2, time); } stmt.bindLong(3, entity.getValue()); - + String location = entity.getLocation(); if (location != null) { stmt.bindString(4, location); @@ -100,36 +105,36 @@ @Override public Long readKey(Cursor cursor, int offset) { return cursor.isNull(offset + 0) ? null : cursor.getLong(offset + 0); - } + } @Override public GasValueBean readEntity(Cursor cursor, int offset) { GasValueBean entity = new GasValueBean( // - cursor.isNull(offset + 0) ? null : cursor.getLong(offset + 0), // id - cursor.isNull(offset + 1) ? null : cursor.getString(offset + 1), // time - cursor.getInt(offset + 2), // value - cursor.isNull(offset + 3) ? null : cursor.getString(offset + 3) // location + cursor.isNull(offset + 0) ? null : cursor.getLong(offset + 0), // id + cursor.isNull(offset + 1) ? null : cursor.getString(offset + 1), // time + cursor.getInt(offset + 2), // value + cursor.isNull(offset + 3) ? null : cursor.getString(offset + 3) // location ); return entity; } - + @Override public void readEntity(Cursor cursor, GasValueBean entity, int offset) { entity.setId(cursor.isNull(offset + 0) ? null : cursor.getLong(offset + 0)); entity.setTime(cursor.isNull(offset + 1) ? null : cursor.getString(offset + 1)); entity.setValue(cursor.getInt(offset + 2)); entity.setLocation(cursor.isNull(offset + 3) ? null : cursor.getString(offset + 3)); - } - + } + @Override protected final Long updateKeyAfterInsert(GasValueBean entity, long rowId) { entity.setId(rowId); return rowId; } - + @Override public Long getKey(GasValueBean entity) { - if(entity != null) { + if (entity != null) { return entity.getId(); } else { return null; @@ -145,5 +150,5 @@ protected final boolean isEntityUpdateable() { return true; } - + } diff --git a/app/src/main/java/com/casic/endoscope/greendao/DaoMaster.java b/app/src/main/java/com/casic/endoscope/greendao/DaoMaster.java index a455fd0..514d3ba 100644 --- a/app/src/main/java/com/casic/endoscope/greendao/DaoMaster.java +++ b/app/src/main/java/com/casic/endoscope/greendao/DaoMaster.java @@ -13,18 +13,23 @@ // THIS CODE IS GENERATED BY greenDAO, DO NOT EDIT. + /** * Master of DAO (schema version 1): knows all DAOs. */ public class DaoMaster extends AbstractDaoMaster { public static final int SCHEMA_VERSION = 1; - /** Creates underlying database table using DAOs. */ + /** + * Creates underlying database table using DAOs. + */ public static void createAllTables(Database db, boolean ifNotExists) { GasValueBeanDao.createTable(db, ifNotExists); } - /** Drops underlying database table using DAOs. */ + /** + * Drops underlying database table using DAOs. + */ public static void dropAllTables(Database db, boolean ifExists) { GasValueBeanDao.dropTable(db, ifExists); } @@ -75,7 +80,9 @@ } } - /** WARNING: Drops all table on Upgrade! Use only during development. */ + /** + * WARNING: Drops all table on Upgrade! Use only during development. + */ public static class DevOpenHelper extends OpenHelper { public DevOpenHelper(Context context, String name) { super(context, name); diff --git a/app/src/main/java/com/casic/endoscope/greendao/DaoSession.java b/app/src/main/java/com/casic/endoscope/greendao/DaoSession.java index 259243d..f252abc 100644 --- a/app/src/main/java/com/casic/endoscope/greendao/DaoSession.java +++ b/app/src/main/java/com/casic/endoscope/greendao/DaoSession.java @@ -14,7 +14,7 @@ /** * {@inheritDoc} - * + * * @see org.greenrobot.greendao.AbstractDaoSession */ public class DaoSession extends AbstractDaoSession { @@ -34,7 +34,7 @@ registerDao(GasValueBean.class, gasValueBeanDao); } - + public void clear() { gasValueBeanDaoConfig.clearIdentityScope(); } diff --git a/app/src/main/java/com/casic/endoscope/greendao/GasValueBeanDao.java b/app/src/main/java/com/casic/endoscope/greendao/GasValueBeanDao.java index 5149375..6025bbf 100644 --- a/app/src/main/java/com/casic/endoscope/greendao/GasValueBeanDao.java +++ b/app/src/main/java/com/casic/endoscope/greendao/GasValueBeanDao.java @@ -12,9 +12,10 @@ import org.greenrobot.greendao.internal.DaoConfig; // THIS CODE IS GENERATED BY greenDAO, DO NOT EDIT. -/** + +/** * DAO for table "GAS_VALUE_BEAN". -*/ + */ public class GasValueBeanDao extends AbstractDao { public static final String TABLENAME = "GAS_VALUE_BEAN"; @@ -34,14 +35,16 @@ public GasValueBeanDao(DaoConfig config) { super(config); } - + public GasValueBeanDao(DaoConfig config, DaoSession daoSession) { super(config, daoSession); } - /** Creates the underlying database table. */ + /** + * Creates the underlying database table. + */ public static void createTable(Database db, boolean ifNotExists) { - String constraint = ifNotExists? "IF NOT EXISTS ": ""; + String constraint = ifNotExists ? "IF NOT EXISTS " : ""; db.execSQL("CREATE TABLE " + constraint + "\"GAS_VALUE_BEAN\" (" + // "\"_id\" INTEGER PRIMARY KEY AUTOINCREMENT ," + // 0: id "\"TIME\" TEXT," + // 1: time @@ -49,7 +52,9 @@ "\"LOCATION\" TEXT);"); // 3: location } - /** Drops the underlying database table. */ + /** + * Drops the underlying database table. + */ public static void dropTable(Database db, boolean ifExists) { String sql = "DROP TABLE " + (ifExists ? "IF EXISTS " : "") + "\"GAS_VALUE_BEAN\""; db.execSQL(sql); @@ -58,18 +63,18 @@ @Override protected final void bindValues(DatabaseStatement stmt, GasValueBean entity) { stmt.clearBindings(); - + Long id = entity.getId(); if (id != null) { stmt.bindLong(1, id); } - + String time = entity.getTime(); if (time != null) { stmt.bindString(2, time); } stmt.bindLong(3, entity.getValue()); - + String location = entity.getLocation(); if (location != null) { stmt.bindString(4, location); @@ -79,18 +84,18 @@ @Override protected final void bindValues(SQLiteStatement stmt, GasValueBean entity) { stmt.clearBindings(); - + Long id = entity.getId(); if (id != null) { stmt.bindLong(1, id); } - + String time = entity.getTime(); if (time != null) { stmt.bindString(2, time); } stmt.bindLong(3, entity.getValue()); - + String location = entity.getLocation(); if (location != null) { stmt.bindString(4, location); @@ -100,36 +105,36 @@ @Override public Long readKey(Cursor cursor, int offset) { return cursor.isNull(offset + 0) ? null : cursor.getLong(offset + 0); - } + } @Override public GasValueBean readEntity(Cursor cursor, int offset) { GasValueBean entity = new GasValueBean( // - cursor.isNull(offset + 0) ? null : cursor.getLong(offset + 0), // id - cursor.isNull(offset + 1) ? null : cursor.getString(offset + 1), // time - cursor.getInt(offset + 2), // value - cursor.isNull(offset + 3) ? null : cursor.getString(offset + 3) // location + cursor.isNull(offset + 0) ? null : cursor.getLong(offset + 0), // id + cursor.isNull(offset + 1) ? null : cursor.getString(offset + 1), // time + cursor.getInt(offset + 2), // value + cursor.isNull(offset + 3) ? null : cursor.getString(offset + 3) // location ); return entity; } - + @Override public void readEntity(Cursor cursor, GasValueBean entity, int offset) { entity.setId(cursor.isNull(offset + 0) ? null : cursor.getLong(offset + 0)); entity.setTime(cursor.isNull(offset + 1) ? null : cursor.getString(offset + 1)); entity.setValue(cursor.getInt(offset + 2)); entity.setLocation(cursor.isNull(offset + 3) ? null : cursor.getString(offset + 3)); - } - + } + @Override protected final Long updateKeyAfterInsert(GasValueBean entity, long rowId) { entity.setId(rowId); return rowId; } - + @Override public Long getKey(GasValueBean entity) { - if(entity != null) { + if (entity != null) { return entity.getId(); } else { return null; @@ -145,5 +150,5 @@ protected final boolean isEntityUpdateable() { return true; } - + } diff --git a/app/src/main/java/com/casic/endoscope/view/MainActivity.kt b/app/src/main/java/com/casic/endoscope/view/MainActivity.kt index 6c32dad..39709c9 100644 --- a/app/src/main/java/com/casic/endoscope/view/MainActivity.kt +++ b/app/src/main/java/com/casic/endoscope/view/MainActivity.kt @@ -65,6 +65,8 @@ import com.pengxh.kt.lite.utils.LoadingDialogHub import com.pengxh.kt.lite.utils.WeakReferenceHandler import kotlinx.coroutines.Dispatchers +import kotlinx.coroutines.delay +import kotlinx.coroutines.flow.flow import kotlinx.coroutines.launch import kotlinx.coroutines.withContext import java.io.File @@ -451,7 +453,45 @@ } binding.resetButton.setOnClickListener { - executeAngle(60, 0) + //建立透明通道 + val serialStart = NET_DVR_SERIALSTART_V40() + //串口类型:1- 232 串口,2- 485 串口 + serialStart.dwSerialPort = 2 + //串口编号 + serialStart.wPort = 0 + val serialHandle = hkSDK.NET_DVR_SerialStart_V40(returnUserId, serialStart) + { _, _, _, _ -> } + //链式执行 + lifecycleScope.launch(Dispatchers.IO) { + flow { + //向透明通道发送数据,水平 + val horizontalCommand = 60.createHorizontalCommand() + val serialSend = hkSDK.NET_DVR_SerialSend( + serialHandle, 1, horizontalCommand, horizontalCommand.size + ) + + delay(500) + emit(serialSend) + }.collect { value -> + if (value) { + //向透明通道发送数据,垂直 + val verticalCommand = 0.createVerticalCommand() + val serialSend = hkSDK.NET_DVR_SerialSend( + serialHandle, 1, verticalCommand, verticalCommand.size + ) + + delay(500) + if (!serialSend) { + "垂直角度指令执行失败".show(context) + } + + //关闭通道 + hkSDK.NET_DVR_SerialStop(serialHandle) + } else { + "水平角度指令执行失败".show(context) + } + } + } } } @@ -531,45 +571,6 @@ } } - /** - * 角度执行 - * */ - private fun executeAngle(horizontal: Int, vertical: Int) { - //建立透明通道 - val serialStart = NET_DVR_SERIALSTART_V40() - //串口类型:1- 232 串口,2- 485 串口 - serialStart.dwSerialPort = 2 - //串口编号 - serialStart.wPort = 0 - val serialHandle = hkSDK.NET_DVR_SerialStart_V40(returnUserId, serialStart) { _, _, _, _ -> - - } - - //向透明通道发送数据,水平和垂直需要分开发送 - hkSDK.NET_DVR_SerialSend( - serialHandle, - 1, - horizontal.createHorizontalCommand(), - horizontal.createHorizontalCommand().size - ) - try { - Thread.sleep(100) - } catch (e: InterruptedException) { - e.printStackTrace() - } - hkSDK.NET_DVR_SerialSend( - serialHandle, 1, vertical.createVerticalCommand(), vertical.createVerticalCommand().size - ) - - try { - Thread.sleep(100) - } catch (e: InterruptedException) { - e.printStackTrace() - } - //关闭通道 - hkSDK.NET_DVR_SerialStop(serialHandle) - } - override fun observeRequestState() { }