func (m *GSMModem) SendLongPduSms(mobile string, message string) string { mes := []rune(message) numberOfMessages := len(mes) / 67 if len(mes)%67 > 0 { numberOfMessages++ } log.Debug("Total messages", numberOfMessages, "length:", len(message)) udh := createUDH(numberOfMessages) encodedPhoneNumber := encodePhoneNumber(mobile) phoneLength := fmt.Sprintf("%02X", len(mobile)) var status string for i := 0; i < numberOfMessages; i++ { status = m.SendCommand("AT+CMGF=0\r", false) log.Debug(status) telNumber := "41" + getNextTpmr() + phoneLength + "91" + encodedPhoneNumber startByte := i * 67 stopByte := (i + 1) * 67 if stopByte >= len(mes) { stopByte = len(mes) - 1 } text := string(mes[startByte:stopByte]) log.Debug(startByte, stopByte, text) encodedText := pdu.EncodeUcs2ToString(text) textLen := lenInHex(udh[i] + encodedText) text = telNumber + "0008" + textLen + udh[i] + encodedText status = m.SendCommand("AT+CMGS="+strconv.Itoa(lenInBytes(text))+"\r", false) log.Debug(status) text = "00" + text status = m.SendCommand(text+string(26), true) log.Debug(status) } return status }
func (m *GSMModem) SendPduSMS(mobile string, message string) string { log.Info("SendPduSMS ", mobile, message) if len([]rune(message)) > 70 { log.Info("This is long message. Will split") return m.SendLongPduSms(mobile, message) } // Put Modem in SMS Binary Mode status := m.SendCommand("AT+CMGF=0\r", false) telNumber := "01" + "00" + fmt.Sprintf("%02X", len(mobile)) + "91" + encodePhoneNumber(mobile) encodedText := pdu.EncodeUcs2ToString(message) textLen := lenInHex(encodedText) text := telNumber + "0008" + textLen + encodedText status = m.SendCommand("AT+CMGS="+strconv.Itoa(lenInBytes(text))+"\r", false) text = "00" + text // EOM CTRL-Z = 26 status = m.SendCommand(text+string(26), true) return status }