summaryrefslogtreecommitdiffabout
path: root/gammu/emb/common/phone/pfunc.c
blob: fe890fc3cf1e0b0f2601e72fe8aeffa9ee735bad (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
/* (c) 2002-2003 by Marcin Wiacek */

#include <string.h>
#include <ctype.h>

#include "../gsmstate.h"
#include "../service/sms/gsmsms.h"
#include "../misc/coding/coding.h"

/* These SMS layouts are used exactly as written in Nokia DCT3 phones.
 * In AT module(s) we have to use some layouts to convert AT frame to format
 * understod by SMS module. To share source the same layouts are used */
GSM_SMSMessageLayout PHONE_SMSDeliver = {
	35 	/*	SMS Text	*/,	16  /*	Phone number	*/,
	0 	/*	SMSC Number 	*/,	14  /*	TPDCS		*/,
	28 	/*	SendingDateTime	*/,	255 /*	SMSCDateTime	*/,
	255	/*	TPStatus	*/,	15  /*	TPUDL		*/,
	255	/*	TPVP		*/,	12  /*	firstbyte	*/,
	255	/*	TPMR		*/,	13  /*  TPPID		*/};
GSM_SMSMessageLayout PHONE_SMSSubmit = {
	36 	/*	SMS Text	*/,	17  /*	Phone number	*/,
	0 	/*	SMSC Number 	*/,	15  /*	TPDCS		*/,
	255 	/*	SendingDateTime	*/,	255 /*	SMSCDateTime	*/,
	255	/*	TPStatus	*/,	16  /*	TPUDL		*/,
	29	/*	TPVP		*/,	12  /*	firstbyte	*/,
	13	/*	TPMR		*/,	14  /*  TPPID		*/};
GSM_SMSMessageLayout PHONE_SMSStatusReport = {
	255 	/*	SMS Text	*/,	15  /*	Phone number	*/,
	0 	/*	SMSC Number 	*/,	255 /*	TPDCS		*/,
	27 	/*	SendingDateTime	*/,	34  /*	SMSCDateTime	*/,
	14	/*	TPStatus	*/,	255 /*	TPUDL		*/,
	255	/*	TPVP		*/,	12  /*	firstbyte	*/,
	13	/*	TPMR		*/,	255 /*  TPPID??		*/};

GSM_Error PHONE_GetSMSFolders(GSM_StateMachine *s, GSM_SMSFolders *folders)
{
	folders->Number=2;
	EncodeUnicode(folders->Folder[0].Name,GetMsg(s->msg,"Inbox"),strlen(GetMsg(s->msg,"Inbox")));
	EncodeUnicode(folders->Folder[1].Name,GetMsg(s->msg,"Outbox"),strlen(GetMsg(s->msg,"Outbox")));
	folders->Folder[0].InboxFolder = true;
	folders->Folder[1].InboxFolder = false;
	folders->Folder[0].Memory      = MEM_SM;
	folders->Folder[1].Memory      = MEM_SM;
	return ERR_NONE;
}

void GSM_CreateFirmwareNumber(GSM_StateMachine *s)
{
	StringToDouble(s->Phone.Data.Version, &s->Phone.Data.VerNum);
	dbgprintf("Number version is \"%f\"\n", s->Phone.Data.VerNum);
}

GSM_Error PHONE_EncodeSMSFrame(GSM_StateMachine *s, GSM_SMSMessage *SMS, unsigned char *buffer, GSM_SMSMessageLayout Layout, int *length, bool clear)
{
	GSM_Error error;

	if (SMS->SMSC.Location!=0) {
		error = s->Phone.Functions->GetSMSC(s, &SMS->SMSC);
		if (error != ERR_NONE) return error;
		SMS->SMSC.Location = 0;
	}
	if (SMS->PDU == SMS_Deliver) {
		if (SMS->SMSC.Number[0] == 0x00 && SMS->SMSC.Number[1] == 0x00) {
			smprintf(s,"No SMSC in SMS Deliver\n");
			return ERR_EMPTYSMSC;
		}
	}
	return GSM_EncodeSMSFrame(SMS, buffer, Layout, length, clear);
}

GSM_Error PHONE_Terminate(GSM_StateMachine *s)
{
	GSM_Error error;

	if (s->Phone.Data.EnableIncomingCB==true) {
		error=s->Phone.Functions->SetIncomingCB(s,false);
		if (error!=ERR_NONE) return error;
	}
	if (s->Phone.Data.EnableIncomingSMS==true) {
		error=s->Phone.Functions->SetIncomingSMS(s,false);
		if (error!=ERR_NONE) return error;
	}
	return ERR_NONE;
}

GSM_Error PHONE_RTTLPlayOneNote(GSM_StateMachine *s, GSM_RingNote note, bool first)
{
	int 		duration, Hz;
	GSM_Error 	error;

	Hz=GSM_RingNoteGetFrequency(note);
  	
	error=s->Phone.Functions->PlayTone(s,Hz,5,first);
	if (error!=ERR_NONE) return error;

	duration = GSM_RingNoteGetFullDuration(note);

	/* Is it correct ? Experimental values here */
	switch (note.Style) {
		case StaccatoStyle:
			my_sleep (7500);
			error=s->Phone.Functions->PlayTone(s,0,0,false);	
			if (error != ERR_NONE) return error;
			my_sleep ((1400000/note.Tempo*duration)-(7500));
			break;
		case ContinuousStyle:
			my_sleep  (1400000/note.Tempo*duration);
			break;
		case NaturalStyle:
			my_sleep  (1400000/note.Tempo*duration-50);
			error=s->Phone.Functions->PlayTone(s,0,0,false);	
			if (error != ERR_NONE) return error;
			my_sleep (50);
			break;	
	}
	return ERR_NONE;
}

GSM_Error PHONE_Beep(GSM_StateMachine *s)
{
	GSM_Error error;

	error=s->Phone.Functions->PlayTone(s, 4000, 5,true);
	if (error!=ERR_NONE) return error;

	my_sleep(500);

	return s->Phone.Functions->PlayTone(s,255*255,0,false);
}

GSM_Error NoneReply(GSM_Protocol_Message msg, GSM_StateMachine *s)
{
	smprintf(s,"None answer\n");
	return ERR_NONE;
}

/* How should editor hadle tabs in this file? Add editor commands here.
 * vim: noexpandtab sw=8 ts=8 sts=8:
 */