package safeluck.drive.evaluation.im; import android.util.Log; import com.anyun.im_lib.util.ByteUtil; import safeluck.drive.evaluation.platformMessage.RegisterResp; import safeluck.drive.evaluation.util.CThreadPoolExecutor; import safeluck.drive.evaluation.util.Utils; /** * MyApplication2 * Created by lzw on 2019/12/12. 16:14:33 * 邮箱:632393724@qq.com * All Rights Saved! Chongqing AnYun Tech co. LTD */ public class MessageProcessor implements IMessageProcessor { private static final String TAG = MessageProcessor.class.getSimpleName(); private MessageProcessor(){ } private static class MessageProcessorInstance{ private static final IMessageProcessor INSTANCE = new MessageProcessor(); } public static IMessageProcessor getInstance(){ return MessageProcessorInstance.INSTANCE; } @Override public void receiveMsg(byte[] message) { byte[] datas = Utils.parseMsg(message); Log.i(TAG, "receiveMsg: "+ ByteUtil.byte2HexStr(datas)); byte checkcolde=Utils.calCheckCode(ByteUtil.subArray(datas,0,datas.length-1)); if (checkcolde == datas[datas.length-1]){ Log.i(TAG, "receiveMsg: 消息正确"); parseMessage(datas); } } private void parseMessage(byte[] datas) { byte[] msgidBytes = ByteUtil.subArray(datas,1,2); short msgid = ByteUtil.getShort(msgidBytes); switch (msgid){ case (short) 0x8100: RegisterResp registerResp = new RegisterResp(datas); break; } } @Override public void sendMessage(final byte[] msg) { CThreadPoolExecutor.runInBackground(new Runnable() { @Override public void run() { if (IMSClientBootstrap.getInstance().isActive()){ IMSClientBootstrap.getInstance().sendMessage(msg); }else{ Log.e(TAG, "run: 发送消息失败,未初始化连接NettyTcp"); } } }); } }