Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Concatenated problem #114

Open
parsibox opened this issue Jul 4, 2023 · 1 comment
Open

Concatenated problem #114

parsibox opened this issue Jul 4, 2023 · 1 comment

Comments

@parsibox
Copy link

parsibox commented Jul 4, 2023

hi
dear i have a message with 134 chars and it should be 2 message but when i send with your code it go 3 message
it seem you send utf16 ( 66 chars for each part ) but i need utf8 ( 67 chars for each part )
what can i do?

pdutext.UCS2("🍉تخفیف ویژه شب یلدا 🍉\n💉بوتاکس و کلیه خدمات زیبایی\nتست داوری🍉🍉🍉تست\nدرسته\nالان بایدپیام باشد\nباید تست کرد\n🍉🍉🍉🍉🍉🍉🍉🍉🍉🍉🍉💉"),
@parsibox
Copy link
Author

parsibox commented Jul 4, 2023

please add this method to your transmitter.go :


func (t *Transmitter) SubmitLongMsg8bit(sm *ShortMessage) ([]ShortMessage, error) {
	maxLen := 134 // 140-6 (UDH)
	rawMsg := sm.Text.Encode()
	countParts := int((len(rawMsg)-1)/maxLen) + 1
	ri := uint8(t.r.Intn(128))
	UDHHeader := make([]byte, 6)
	UDHHeader[0] = 5
	UDHHeader[1] = 0
	UDHHeader[2] = 3
	UDHHeader[3] = ri
	UDHHeader[4] = uint8(countParts)
	responses := []ShortMessage{}
	for i := 0; i < countParts; i++ {
		UDHHeader[5] = uint8(i + 1) // current message part
		p := pdu.NewSubmitSM(sm.TLVFields)
		f := p.Fields()
		f.Set(pdufield.SourceAddr, sm.Src)
		f.Set(pdufield.DestinationAddr, sm.Dst)
		if i != countParts-1 {
			f.Set(pdufield.ShortMessage, pdutext.Raw(append(UDHHeader, rawMsg[i*maxLen:(i+1)*maxLen]...)))
		} else {
			f.Set(pdufield.ShortMessage, pdutext.Raw(append(UDHHeader, rawMsg[i*maxLen:]...)))
		}
		f.Set(pdufield.RegisteredDelivery, uint8(sm.Register))
		if sm.Validity != time.Duration(0) {
			f.Set(pdufield.ValidityPeriod, convertValidity(sm.Validity))
		}
		f.Set(pdufield.ServiceType, sm.ServiceType)
		f.Set(pdufield.SourceAddrTON, sm.SourceAddrTON)
		f.Set(pdufield.SourceAddrNPI, sm.SourceAddrNPI)
		f.Set(pdufield.DestAddrTON, sm.DestAddrTON)
		f.Set(pdufield.DestAddrNPI, sm.DestAddrNPI)
		f.Set(pdufield.ESMClass, 0x40)
		f.Set(pdufield.ProtocolID, sm.ProtocolID)
		f.Set(pdufield.PriorityFlag, sm.PriorityFlag)
		f.Set(pdufield.ScheduleDeliveryTime, sm.ScheduleDeliveryTime)
		f.Set(pdufield.ReplaceIfPresentFlag, sm.ReplaceIfPresentFlag)
		f.Set(pdufield.SMDefaultMsgID, sm.SMDefaultMsgID)
		f.Set(pdufield.DataCoding, uint8(sm.Text.Type()))
		//set the optional parameters in the submit pdu from sm
		optParams := p.TLVFields()
		for tag, value := range sm.TLVFields {
			err := optParams.Set(tag, value)
			if err != nil {
				return nil, err
			}
		}

		resp, err := t.do(p)
		if err != nil {
			return nil, err
		}
		sm.resp.Lock()
		sm.resp.p = resp.PDU
		sm.resp.Unlock()
		// checking for errors in the responses will be left to the client
		responses = append(responses, *sm)
	}
	return responses, nil
}

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant