private static ByteBuffer addHeaders2OTAData(ByteBuffer otaData, String mobileOperator, int contentType) throws EMSException { ByteBuffer buffer = null; switch(contentType) { case 3: // '\003' Cli cli = new Cli(); cli.setOTB(otaData.getBuffer()); cli.encode(); buffer = cli.getEncoded(); break; case 2: // '\002' OperatorLogo logo = new OperatorLogo(); logo.setOTB(otaData.getBuffer()); logo.setMobileOperator(mobileOperator); logo.encode(); buffer = logo.getEncoded(); break; default: buffer = otaData; break; } return buffer; }
public static Collection buildSubmitEMS(String filename, String srcAddress, String destAddress, int contentType, int MsgType, String sCommand_code, int TotalSegments) throws EMSException { Vector vRequests; SubmitSM request = null; vRequests = new Vector(); ByteBuffer otaData = null; short port = 0; switch(contentType) { case 3: // '\003' port = 5507; Cli cli = new Cli(filename); cli.encode(); otaData = cli.getEncoded(); break; case 2: // '\002' port = 5506; OperatorLogo logo = new OperatorLogo(filename); logo.setMobileOperator(Preference.mobileOperator); logo.encode(); otaData = logo.getEncoded(); break; case 4: // '\004' port = 5514; PictureMessage pic = new PictureMessage(filename); pic.encode(); otaData = pic.getEncoded(); break; case 1: // '\001' port = 5505; otaData = loadByteBuffer(filename); break; default: throw new EMSException("Invalid content type " + contentType + ")"); } if(otaData.length() <= 133) { MAX_LENGTH = 133; isFragmented = false; totalSegments = 1; } else { MAX_LENGTH = 128; isFragmented = true; totalSegments = (byte)(otaData.length() / MAX_LENGTH + 1); } ByteBuffer message = null; for(byte i = 1; i <= totalSegments; i++) { SubmitSM request = new SubmitSM(); request.setSourceAddr((byte)0, (byte)0, srcAddress); request.setDestAddr((byte)1, (byte)1, destAddress); message = new ByteBuffer(); if(isFragmented) message.appendByte((byte)11); else message.appendByte((byte)6); message.appendByte((byte)5); message.appendByte((byte)4); message.appendShort(port); message.appendShort((short)0); if(isFragmented) { message.appendByte((byte)0); message.appendByte((byte)3); message.appendByte((byte)0); message.appendByte(totalSegments); message.appendByte(i); } if(otaData.length() <= MAX_LENGTH) message.appendBuffer(otaData); else message.appendBuffer(otaData.removeBuffer(MAX_LENGTH)); request.setShortMessageData(message); request.setEsmClass((byte)64); request.setDataCoding((byte)-11); request.setSequenceNumber(i + 1); if(MsgType == 2 || MsgType > 19 && MsgType < 30) MsgType = 0; else if((MsgType == 1 || MsgType == 3) && i == 1) MsgType = 1; else MsgType = 4; if(srcAddress.equals("996") && MsgType == 0 && (sCommand_code.equals("XSMN") || sCommand_code.equals("XSMT") || sCommand_code.equals("XSMN") || sCommand_code.equals("XSTD"))) MsgType = 4; if(TotalSegments == 0) TotalSegments = 1; ByteBuffer Charge = new ByteBuffer(); Charge.appendByte((byte)-96); Charge.appendString(sCommand_code + "," + MsgType + "," + TotalSegments); request.setSourceSubaddress(Charge); vRequests.addElement(request); } return vRequests; Exception e; e; throw new EMSException(e.getMessage()); }