|
@@ -1,12 +1,23 @@
|
|
|
package com.develop.common.utils;
|
|
|
|
|
|
import android.content.Context;
|
|
|
+import android.os.PowerManager;
|
|
|
import android.util.Log;
|
|
|
|
|
|
+import com.develop.base.util.AppActivityManager;
|
|
|
import com.develop.base.util.MMkvUtils;
|
|
|
+import com.develop.common.bean.TuyaEvent;
|
|
|
import com.develop.common.tuya_bean.TuyaQRUrlBean;
|
|
|
+import com.kuyuntech.cofarcooking.device.sdk.constant.core.DevModes;
|
|
|
+import com.kuyuntech.cofarcooking.device.sdk.constant.core.HeatModes;
|
|
|
+import com.kuyuntech.cofarcooking.device.sdk.constant.core.MotorDirections;
|
|
|
+import com.kuyuntech.cofarcooking.device.sdk.devmode.core.BaseDevMode;
|
|
|
+import com.kuyuntech.cofarcooking.device.sdk.eventbus.core.DevInfo;
|
|
|
+import com.kuyuntech.cofarcooking.device.sdk.util.core.CofarSDK;
|
|
|
import com.sun.jna.Pointer;
|
|
|
+import com.tuya.smartai.iot_sdk.DPEvent;
|
|
|
|
|
|
+import org.greenrobot.eventbus.EventBus;
|
|
|
import org.json.JSONObject;
|
|
|
|
|
|
public class TuyaUtilsSo {
|
|
@@ -78,33 +89,225 @@ public class TuyaUtilsSo {
|
|
|
tuyaDp();
|
|
|
tuyaLog();
|
|
|
tuyaInit(getmPid(), getmUid(), getmAk(), version);
|
|
|
+ tuyaRestart();
|
|
|
}
|
|
|
|
|
|
public void tuyaInit(String pid, String uuid, String authkey, String version) {
|
|
|
getTuyaApi().init(0, new String[]{}, pid, uuid, authkey, version);
|
|
|
}
|
|
|
|
|
|
- public int sendDp(){
|
|
|
- return getTuyaApi().send_dp();
|
|
|
- }
|
|
|
|
|
|
+ //注销设备
|
|
|
public void tuyaRemove() {
|
|
|
getTuyaApi().example_soc_device_remove(0, new String[]{});
|
|
|
}
|
|
|
|
|
|
|
|
|
- TuyaApi.DpCallback dpCallback = new TuyaApi.DpCallback() {
|
|
|
+ //dp回调
|
|
|
+ TuyaApi.DpCallback dpCallback = new TuyaApi.DpCallback() {
|
|
|
+ public void invoke(int dpid, byte type, int intValue, int enumValue, String strValue, int boolValue, int bitmapValue) {
|
|
|
+ /**
|
|
|
+ * type 类型 0 对应着 boolValue ; 1 对应 intValue ,2 对应 strValue ,3 对应 enumValue ,4对应 bitmapValue
|
|
|
+ * */
|
|
|
+
|
|
|
+ /**
|
|
|
+ * -> 启动/停止 dpid = 2 ; type = 0 ,dp_bool: 1启动, 0关闭
|
|
|
+ * -> 自动程序 dpid = 3 ; type = 3 , dp_enum: 0 DIY,1 和面(Knead) ,2 蒸汽(Steam), 3 低温慢煮(Sous_vide) ,4 煮米饭(Rice) ,
|
|
|
+ * 5 搅碎(Chop) , 6 奶昔(Smoothie),7 称重(Weight) ,8 切丁(Dive), 9 去皮(Peeling) ,10 烧水(Boil_water),11 切丝切片 (Food_processor)
|
|
|
+ * 12 自动清洁(Auto_clean) ,13 预加热 (Preheating) , 14 间接性搅拌 (Intermittent_Stir) 15 警告 (Warning)
|
|
|
+ * -> 工作状态 dpid = 5 (只上报) {”5“:”Stop“}
|
|
|
+ * -> 烹饪温度 dpid = 6 ;type = 1, dp_value : 6 温度度数
|
|
|
+ * -> 当前温度 dpid = 7 (只上报) {”7“:88}
|
|
|
+ * -> 烹饪时间 dpid = 10 ;type = 1, dp_value : 5 时间(分钟)
|
|
|
+ * -> 剩余时间 dpid = 11 (只上报) {”11“:3}
|
|
|
+ * -> 多步骤执行 dpid = 12 __soc_dev_raw_dp_cmd_cb 这个回调 暂时没完善 {”12“:"22"}
|
|
|
+ * ->故障警告 dpid = 13 (只上报) {"13":123456} 只能数字
|
|
|
+ * -> 暂停 dpid = 18 ; type:0 ,dp_bool:1暂停 ,0没暂停
|
|
|
+ * ->云食谱 dpid = 22 __soc_dev_raw_dp_cmd_cb 这个回调 {”22“:"551234"}
|
|
|
+ * ->烹饪历史 dpid = 23 __soc_dev_raw_dp_cmd_cb 这个回调 {”23“:"casd"}
|
|
|
+ * -> 扭橙功能 dpid = 101 (只上报) {"101":true}
|
|
|
+ * -> 称重功能 dpid = 102 ;type = 0, dp_bool = 1 打开 0 关闭
|
|
|
+ * -> 速度 dpid = 103;type = 1, dp_value : 2 速度
|
|
|
+ * -> 正反转 dpid = 104 ;type = 0, dp_bool = 1 打开 0 关闭
|
|
|
+ * -> 称重清零 dpid = 105 ;type = 0, dp_bool = 1 打开 0 关闭
|
|
|
+ * -> 锅状态 dpid = 106 (只上报) {"106":1}
|
|
|
+ * -> 称重数据 dpid =107 (只上报) {"107":2200}
|
|
|
+ * -> 机器是否就绪 dpid = 110 ;type = 1 ;dp_value: 1 具体不知道什么回事,看之前代码就是调用就跳DIY
|
|
|
+ * -> 开盖状态 dpid = 111 (只上报) {"111":1} 锅盖状态
|
|
|
+ * -> 设备功能模式 dpid = 114 ; type = 2 ; dp_str:巴拉克 随便输入的
|
|
|
+ * -> 时间设置最大值 dpid 119 (只上报) {"119":1}
|
|
|
+ * -> 时间设置最小值 dpid 120 (只上报) {"120":0}
|
|
|
+ * -> 温度设置最大值 dpid 121 (只上报) {"121":1}
|
|
|
+ * -> 温度设置最小值 dpid 122 (只上报) {"122":0}
|
|
|
+ * -> 转速设置最大值 dpid 123 (只上报) {"123":1}
|
|
|
+ * -> 转速设置最小值 dpid 124 (只上报) {"124":0}
|
|
|
+ * -> 当前菜谱编号 dpid = 127 ; type = 2 ; dp_str:21321231 随便输入的
|
|
|
+ * -> 当前菜谱步骤 dpid = 128 ; type = 2 ; dp_str:3 随便输入的
|
|
|
+ * -> 蒸汽量大小 dpid = 129 ; type = 3 ; dp_enum: 0 high 1 mid 2 low
|
|
|
+ *
|
|
|
+ *
|
|
|
+ *
|
|
|
+ * **/
|
|
|
+
|
|
|
+
|
|
|
+ Log.i("tuya_iot", "dpCallback dpid:" + dpid
|
|
|
+ + " type:" + type + " dp_value:" + intValue
|
|
|
+ + " dp_enum: " + enumValue + " dp_str:" + strValue + " dp_bool:" + boolValue + " dp_bitmap:" + bitmapValue);
|
|
|
+// Log.v("tuya_iot","dpCallback");
|
|
|
+ switch (dpid) {
|
|
|
+ case TuyaSoDp.ON_OFF:
|
|
|
+ break;
|
|
|
+ case TuyaSoDp.START_STOP:
|
|
|
+ //启动/停止
|
|
|
+ String str = boolValue == 1 ? "start" : "stop";
|
|
|
+ tuyaEvent(str);
|
|
|
+ break;
|
|
|
+ case TuyaSoDp.AUTOMATIC_PROGRAM:
|
|
|
+ //自动程序
|
|
|
+ getModes(enumValue);
|
|
|
+ break;
|
|
|
+ case TuyaSoDp.COOKING_TEMPERATURE:
|
|
|
+ //烹饪温度
|
|
|
+ CofarSDK.cfgHeat((short) (int) intValue, HeatModes.PU_TONG);
|
|
|
+ tuyaEvent("change_temp");
|
|
|
+
|
|
|
+ break;
|
|
|
+ case TuyaSoDp.PAUSE:
|
|
|
+ // 暂停
|
|
|
+ String aa = "";
|
|
|
+ if (boolValue == 1) {
|
|
|
+ aa = "pause";
|
|
|
+ } else {
|
|
|
+ aa = "start";
|
|
|
+ }
|
|
|
+ tuyaEvent(aa);
|
|
|
+ break;
|
|
|
+ case TuyaSoDp.COOKING_TIME:
|
|
|
+ //烹饪时间
|
|
|
+ CofarSDK.cfgTime((int) intValue);
|
|
|
+ tuyaEvent("change_time");
|
|
|
+
|
|
|
+
|
|
|
+ break;
|
|
|
+ case TuyaSoDp.WEIGHT:
|
|
|
+ //称重功能
|
|
|
+
|
|
|
+ break;
|
|
|
+ case TuyaSoDp.SPEED:
|
|
|
+ //速度
|
|
|
+ CofarSDK.cfgMotorGear((byte) ((int) intValue & 0xFF));
|
|
|
+ break;
|
|
|
+ case TuyaSoDp.REVERSIBLE:
|
|
|
+ //正反转
|
|
|
+ CofarSDK.cfgMotorDirection((int) boolValue == 0 ? MotorDirections.FORWARD : MotorDirections.REVERSE);
|
|
|
+ //按照以前的涂鸦,上面修改转向没有图标没有变动,估在发送一个eventbus
|
|
|
+ tuyaEvent("change_direction");
|
|
|
+ break;
|
|
|
+ case TuyaSoDp.WEIGHT_CLEAR:
|
|
|
+ //称重清零
|
|
|
+
|
|
|
+ break;
|
|
|
+ case TuyaSoDp.DEV_READY:
|
|
|
+ //机器是否准备就绪 按照之前做法,这个回调是跳DIY
|
|
|
+
|
|
|
+ break;
|
|
|
+
|
|
|
+ }
|
|
|
+ }
|
|
|
+ };
|
|
|
+
|
|
|
+ private void tuyaEvent(String type) {
|
|
|
+ TuyaEvent tuya = new TuyaEvent();
|
|
|
+ tuya.setType(type);
|
|
|
+ EventBus.getDefault().post(tuya);
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
+ private void getModes(int enumValue) {
|
|
|
+ /**
|
|
|
+ * 0 DIY,1 和面(Knead) ,2 蒸汽(Steam), 3 低温慢煮(Sous_vide) ,4 煮米饭(Rice) ,
|
|
|
+ * 5 搅碎(Chop) , 6 奶昔(Smoothie),7 称重(Weight) ,8 切丁(Dive), 9 去皮(Peeling) ,10 烧水(Boil_water),11 切丝切片 (Food_processor)
|
|
|
+ * 12 自动清洁(Auto_clean) ,13 预加热 (Preheating) , 14 间接性搅拌 (Intermittent_Stir) 15 警告 (Warning)
|
|
|
+ * */
|
|
|
+ String type = "";
|
|
|
+ switch (enumValue) {
|
|
|
+ case 0:
|
|
|
+ type = "ADAPTED_COOKING";
|
|
|
+ break;
|
|
|
+ case 1:
|
|
|
+ type = "KNEAD_TOUGH";
|
|
|
+ break;
|
|
|
+ case 2:
|
|
|
+ type = "STEAM";
|
|
|
+ break;
|
|
|
+ case 3:
|
|
|
+ type = "SOVS_VIDE";
|
|
|
+ break;
|
|
|
+ case 4:
|
|
|
+ type = "COOK_RICE";
|
|
|
+ break;
|
|
|
+ case 5:
|
|
|
+ type = "CHOP";
|
|
|
+ break;
|
|
|
+ case 6:
|
|
|
+ type = "SMOOTHIE";
|
|
|
+ break;
|
|
|
+ case 7:
|
|
|
+ type = "WIGHT";
|
|
|
+ break;
|
|
|
+ case 8:
|
|
|
+ type = "DICING";
|
|
|
+ break;
|
|
|
+ case 9:
|
|
|
+ type = "POTATO_PEELER";
|
|
|
+ break;
|
|
|
+ case 10:
|
|
|
+ type = "BOIL_WATER";
|
|
|
+ break;
|
|
|
+ case 11:
|
|
|
+ type = "FOOD_PROCESSOR";
|
|
|
+ break;
|
|
|
+ case 12:
|
|
|
+ type = "AUTO_CLEAN";
|
|
|
+ break;
|
|
|
+ case 13:
|
|
|
+ type = "SPECIAL_DIY_MODE";
|
|
|
+ break;
|
|
|
+ case 14:
|
|
|
+ type = "ROAST";
|
|
|
+ break;
|
|
|
+ case 15:
|
|
|
+ type = "ADAPTED_COOKING";
|
|
|
+ break;
|
|
|
+ default:
|
|
|
+ type = "ADAPTED_COOKING";
|
|
|
+ break;
|
|
|
+ }
|
|
|
+
|
|
|
+ CommonTuyaSoUtils.INSTANCE.navigateToAdaptedCooking(type);
|
|
|
+
|
|
|
+
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
+ public void tuyaDp() {
|
|
|
+ getTuyaApi().register_dp_callback(dpCallback);
|
|
|
+ }
|
|
|
|
|
|
+ public void tuyaRestart() {
|
|
|
+ getTuyaApi().restart_cofa_callback(restartCallback);
|
|
|
+ }
|
|
|
|
|
|
+ TuyaApi.RestartCallback restartCallback = new TuyaApi.RestartCallback() {
|
|
|
@Override
|
|
|
- public void invoke(byte dpid, byte type, int intValue, int enumValue, String strValue, int boolValue, int bitmapValue) {
|
|
|
-// Log.i("tuya_iot", "dpCallback dpid:"+dpid
|
|
|
-// + " type:"+type+" time_stamp:"+time_stamp + " dp_value:"+dp_value
|
|
|
-// + " dp_enum: "+dp_enum+" dp_str:"+dp_str + " dp_bool:"+dp_bool +" dp_bitmap:"+dp_bitmap );
|
|
|
- Log.v("tuya_iot","dpCallback");
|
|
|
+ public void invoke() {
|
|
|
+ PowerManager pm = (PowerManager) AppActivityManager.getInstance().getTopActivity().getSystemService(Context.POWER_SERVICE);
|
|
|
+ pm.reboot("");
|
|
|
}
|
|
|
};
|
|
|
|
|
|
+
|
|
|
+ //日志回调
|
|
|
TuyaApi.LogCallback logCallback = new TuyaApi.LogCallback() {
|
|
|
@Override
|
|
|
public void invoke(String tag, String message) {
|
|
@@ -135,10 +338,6 @@ public class TuyaUtilsSo {
|
|
|
};
|
|
|
|
|
|
|
|
|
- public void tuyaDp() {
|
|
|
- getTuyaApi().register_dp_callback(dpCallback);
|
|
|
- }
|
|
|
-
|
|
|
public void tuyaLog() {
|
|
|
getTuyaApi().register_log_callback(logCallback);
|
|
|
}
|
|
@@ -177,6 +376,118 @@ public class TuyaUtilsSo {
|
|
|
}
|
|
|
|
|
|
|
|
|
+ public void uploadData() {
|
|
|
+ if (!tuyaNetwork) {
|
|
|
+ return;
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
+ new Thread(new Runnable() {
|
|
|
+ @Override
|
|
|
+ public void run() {
|
|
|
+ DevInfo info = CofarSDK.devInfo();
|
|
|
+ BaseDevMode mode = info.getMode();
|
|
|
+ //getStatus 0 stop 1 start 2 pause
|
|
|
+ int start_stop = info.getStatus() == 0 ? 0 : 1; // 这里有个暂停,个人认为,暂停算是运行的一部分
|
|
|
+ int pause = info.getStatus() == 2 ? 1 : 0;
|
|
|
+ int pot_status = 0;
|
|
|
+ if (info.getDevMode().equals("SOUP")) {
|
|
|
+ pot_status = 0;
|
|
|
+ } else if (info.getDevMode().equals("AIR_FRYER")) {
|
|
|
+ pot_status = 1;
|
|
|
+ } else if (info.getDevMode().equals("STAND_MIXER")) {
|
|
|
+ pot_status = 3;
|
|
|
+ } else {
|
|
|
+ pot_status = 0;
|
|
|
+ }
|
|
|
+
|
|
|
+ DPEvent[] dpEvents = new DPEvent[]{
|
|
|
+ new DPEvent(TuyaSoDp.ON_OFF, (byte) DPEvent.Type.PROP_BOOL, 1, 0),
|
|
|
+ new DPEvent(TuyaSoDp.START_STOP, (byte) DPEvent.Type.PROP_BOOL, start_stop, 0),
|
|
|
+ new DPEvent(TuyaSoDp.WORK_STATE, (byte) DPEvent.Type.PROP_ENUM, info.getStatus(), 0),
|
|
|
+ new DPEvent(TuyaSoDp.COOKING_TEMPERATURE, (byte) DPEvent.Type.PROP_VALUE, (int) (info.getTargetTempBuffer() != -1 ? info.getTargetTempBuffer() : info.getTargetTemp()), 0),
|
|
|
+ new DPEvent(TuyaSoDp.CURRENT_TEMPERATURE, (byte) DPEvent.Type.PROP_VALUE, (int) CofarUtils.parseTemp(info.getTemp()), 0),
|
|
|
+ new DPEvent(TuyaSoDp.COOKING_TIME, (byte) DPEvent.Type.PROP_VALUE, info.getTargetTimeBuffer() != -1 ? info.getTargetTimeBuffer() : info.getTargetTime(), 0),
|
|
|
+ new DPEvent(TuyaSoDp.REMAINING_TIME, (byte) DPEvent.Type.PROP_VALUE, info.getRemainTime(), 0),
|
|
|
+ new DPEvent(TuyaSoDp.PAUSE, (byte) DPEvent.Type.PROP_BOOL, pause, 0),
|
|
|
+ new DPEvent(TuyaSoDp.SPEED, (byte) DPEvent.Type.PROP_VALUE, (int) (info.getMotorGearBuffer() != -1 ? info.getMotorGearBuffer() : info.getMotorGear()), 0),
|
|
|
+ new DPEvent(TuyaSoDp.REVERSIBLE, (byte) DPEvent.Type.PROP_BOOL, (int) (info.getMotorDirectionBuffer() != -1 ? info.getMotorDirectionBuffer() : info.getMotorDirection()), 0),
|
|
|
+ new DPEvent(TuyaSoDp.POT_STATUS, (byte) DPEvent.Type.PROP_VALUE, pot_status, 0),
|
|
|
+ new DPEvent(TuyaSoDp.WEIGHT_NUMBER, (byte) DPEvent.Type.PROP_VALUE, info.getWeight(), 0),
|
|
|
+ new DPEvent(TuyaSoDp.POT_CLOVER_STATUS, (byte) DPEvent.Type.PROP_VALUE, (int) info.getPotCloverStatus(), 0),
|
|
|
+ new DPEvent(TuyaSoDp.MAX_TIME, (byte) DPEvent.Type.PROP_VALUE, mode == null ? 0 : mode.getMaxTime(), 0),
|
|
|
+ new DPEvent(TuyaSoDp.MIN_TIME, (byte) DPEvent.Type.PROP_VALUE, mode == null ? 0 : mode.getMinTime(), 0),
|
|
|
+ new DPEvent(TuyaSoDp.MAX_TEMP, (byte) DPEvent.Type.PROP_VALUE, mode == null ? 0 : mode.getMaxTemp(), 0),
|
|
|
+ new DPEvent(TuyaSoDp.MIN_TEMP, (byte) DPEvent.Type.PROP_VALUE, mode == null ? 0 : mode.getMinTemp(), 0),
|
|
|
+ new DPEvent(TuyaSoDp.MAX_MOTOR_GEAR, (byte) DPEvent.Type.PROP_VALUE, mode == null ? 0 : mode.getMaxMotorGear(), 0),
|
|
|
+ new DPEvent(TuyaSoDp.MIN_MOTOR_GEAR, (byte) DPEvent.Type.PROP_VALUE, mode == null ? 0 : mode.getMinMotorGear(), 0)
|
|
|
+ };
|
|
|
+
|
|
|
+
|
|
|
+ //上报指令
|
|
|
+ for (DPEvent event : dpEvents) {
|
|
|
+ int value = -1;
|
|
|
+ Object eventValue = event.value;
|
|
|
+ if (eventValue instanceof Short) {
|
|
|
+ Short shortValue = (Short) eventValue;
|
|
|
+ value = shortValue.intValue();
|
|
|
+ } else if (eventValue instanceof Integer) {
|
|
|
+ value = (int) eventValue;
|
|
|
+ } else if (eventValue instanceof Byte) {
|
|
|
+ Byte byteValue = (Byte) eventValue;
|
|
|
+ value = byteValue.intValue();
|
|
|
+ } else {
|
|
|
+ value = (int) eventValue;
|
|
|
+ }
|
|
|
+
|
|
|
+ if (event.type == DPEvent.Type.PROP_BOOL) {
|
|
|
+ getTuyaApi().send_dp_bool(event.dpid, value);
|
|
|
+ }
|
|
|
+ if (event.type == DPEvent.Type.PROP_VALUE) {
|
|
|
+ getTuyaApi().send_dp_value(event.dpid, value);
|
|
|
+ }
|
|
|
+ if (event.type == DPEvent.Type.PROP_STR) {
|
|
|
+ getTuyaApi().send_dp_str(event.dpid, String.valueOf(value));
|
|
|
+ }
|
|
|
+ if (event.type == DPEvent.Type.PROP_ENUM) {
|
|
|
+ getTuyaApi().send_dp_enum(event.dpid, value);
|
|
|
+ }
|
|
|
+
|
|
|
+ }
|
|
|
+ }
|
|
|
+ });
|
|
|
+// ioTSDKManager.sendDP(dpEvents);
|
|
|
+ }
|
|
|
+
|
|
|
+ public void sendDpEnum(int dpid,int value){
|
|
|
+ getTuyaApi().send_dp_enum(dpid, value);
|
|
|
+ }
|
|
|
+ public void sendDpStr(int dpid,String value){
|
|
|
+ getTuyaApi().send_dp_str(dpid, value);
|
|
|
+ }
|
|
|
+ public void sendDpValue(int dpid,int value){
|
|
|
+ getTuyaApi().send_dp_value(dpid, value);
|
|
|
+ }
|
|
|
+ public void sendDpBool(int dpid,int value){
|
|
|
+ getTuyaApi().send_dp_bool(dpid, value);
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+ public Integer parse(int e) {
|
|
|
+
|
|
|
+ if (e <= 0) {
|
|
|
+ return 0;
|
|
|
+ }
|
|
|
+
|
|
|
+ StringBuilder a = new StringBuilder("1");
|
|
|
+ for (int i = 0; i < e - 1; i++) {
|
|
|
+ a.append("0");
|
|
|
+ }
|
|
|
+ return Integer.parseInt(a.toString(), 2);
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
public void appendFile(String filename, String string) {
|
|
|
getTuyaApi().append_log_to_file(filename, string);
|
|
|
|