Exemplo n.º 1
0
// CMGL sends AT+CMGL with the given filtering flag to the device and then parses
// the list of received messages that match ther filter. See MessageFlags for the
// list of supported filters.
func (p *DefaultProfile) CMGL(flag Opt) (octets map[uint64][]byte, err error) {
	req := fmt.Sprintf(`AT+CMGL=%d`, flag.ID)
	reply, err := p.dev.Send(req)
	if err != nil {
		return
	}
	lines := strings.Split(reply, "\n")
	if len(lines) < 2 {
		return
	}
	octets = make(map[uint64][]byte)
	for i := 0; i < len(lines); i += 2 {
		header := strings.TrimPrefix(lines[i], `+CMGL: `)
		fields := strings.Split(header, ",")
		if len(fields) < 4 {
			return nil, ErrParseReport
		}
		n, err := strconv.ParseUint(fields[0], 10, 16)
		if err != nil {
			return nil, ErrParseReport
		}
		var oct []byte
		if oct, err = util.Bytes(lines[i+1]); err != nil {
			return nil, ErrParseReport
		}
		octets[n] = oct
	}
	return
}
Exemplo n.º 2
0
func TestSmsDeliverPduUCS2(t *testing.T) {
	n, octets, err := smsDeliverUCS2.PDU()
	assert.NoError(t, err)
	assert.Equal(t, len(pduDeliverUCS2)/2-8, n)
	data, err := util.Bytes(pduDeliverUCS2)
	assert.NoError(t, err)
	assert.Equal(t, data, octets)
}
Exemplo n.º 3
0
func TestSmsSubmitPduGsm7(t *testing.T) {
	n, octets, err := smsSubmitGsm7.PDU()
	assert.NoError(t, err)
	assert.Equal(t, len(pduSubmitGsm7)/2-8, n)
	data, err := util.Bytes(pduSubmitGsm7)
	assert.NoError(t, err)
	assert.Equal(t, data, octets)
}
Exemplo n.º 4
0
func TestSmsDeliverReadFromGsm7(t *testing.T) {
	var msg Message
	data, err := util.Bytes(pduDeliverGsm7)
	assert.NoError(t, err)
	n, err := msg.ReadFrom(data)
	assert.NoError(t, err)
	assert.Equal(t, n, len(data))
	assert.Equal(t, smsDeliverGsm7, msg)
}
Exemplo n.º 5
0
func TestSmsSubmitReadFromUCS2(t *testing.T) {
	var msg Message
	data, err := util.Bytes(pduSubmitUCS2)
	assert.NoError(t, err)
	n, err := msg.ReadFrom(data)
	assert.NoError(t, err)
	assert.Equal(t, n, len(data))
	assert.Equal(t, smsSubmitUCS2, msg)
}
Exemplo n.º 6
0
// CMGR sends AT+CMGR with the given index to the device and returns the message contents.
func (p *DefaultProfile) CMGR(index uint64) (octets []byte, err error) {
	req := fmt.Sprintf(`AT+CMGR=%d`, index)
	reply, err := p.dev.Send(req)
	if err != nil {
		return
	}
	lines := strings.Split(reply, "\n")
	if len(lines) < 2 {
		return nil, ErrParseReport
	}
	octets, err = util.Bytes(lines[1])
	return
}
Exemplo n.º 7
0
func (r *ussdReport) Parse(str string) (err error) {
	fields := strings.Split(str, ",")
	if len(fields) < 3 {
		return ErrParseReport
	}
	if r.N, err = strconv.ParseUint(fields[0], 10, 8); err != nil {
		return
	}
	if r.Octets, err = util.Bytes(strings.Trim(fields[1], `"`)); err != nil {
		return
	}
	var e uint64
	if e, err = strconv.ParseUint(fields[2], 10, 8); err != nil {
		return
	}
	r.Enc = Encoding(e)
	return
}