// SendLongSMS sends an SMS message with given text to the given address, // the encoding and other parameters are default. // If the message is very long, it will be sent in parts. func (d *Device) SendLongSMS(text string, address sms.PhoneNumber) (err error) { defer func() { multipartReferenceNumber = uint16((uint32(multipartReferenceNumber) + 1) & 0xFFFF) }() msg := sms.Message{ Text: text, Type: sms.MessageTypes.Submit, Encoding: sms.Encodings.Gsm7Bit, Address: address, VPFormat: sms.ValidityPeriodFormats.Relative, VP: sms.ValidityPeriod(24 * time.Hour * 4), } maxSize := 130 for _, w := range text { // detected a double-width char if w > 1 { msg.Encoding = sms.Encodings.UCS2 maxSize = 60 break } } msgParts := util.SplitStringBySize(text, maxSize) numberOfParts := byte(255) if len(msgParts) <= 255 { numberOfParts = byte(len(msgParts)) } msg.UserDataStartsWithHeader = numberOfParts > 1 for index, part := range msgParts { msg.MessageReference = messageReferenceCounter msg.Text = part if msg.Encoding == sms.Encodings.UCS2 { } if numberOfParts > 1 { msg.UserDataHeader.ConcatenationIE = sms.ConcatenationInformationElement{NumberOfParts: numberOfParts, PartNumber: byte(index + 1), ReferenceNumber: multipartReferenceNumber} } messageReferenceCounter = byte((uint16(messageReferenceCounter) + 1) & 0xFF) if index >= int(numberOfParts) { break } n, octets, err := msg.PDU() if err != nil { return err } if err = d.Commands.CMGS(n, octets); err != nil { return err } } return }
// SendSMS sends an SMS message with given text to the given address, // the encoding and other parameters are default. func (d *Device) SendSMS(text string, address sms.PhoneNumber) (err error) { msg := sms.Message{ Text: text, Type: sms.MessageTypes.Submit, Encoding: sms.Encodings.Gsm7Bit, Address: address, VPFormat: sms.ValidityPeriodFormats.Relative, VP: sms.ValidityPeriod(24 * time.Hour * 4), } for _, w := range text { // detected a double-width char if w > 1 { msg.Encoding = sms.Encodings.UCS2 break } } n, octets, err := msg.PDU() if err != nil { return err } err = d.Commands.CMGS(n, octets) return }