Exemplo n.º 1
0
Arquivo: at.c Projeto: dunn/gammu
static GSM_Error AT_WriteMessage (GSM_StateMachine *s, unsigned const char *buffer,
				     int length, int type)
{
	int sent=0, write_data=0, i=0;

	GSM_DumpMessageLevel2(s, buffer, length, type);
	GSM_DumpMessageLevel3(s, buffer, length, type);

	if (s->Protocol.Data.AT.FastWrite) {
		while (sent != length) {
			write_data = s->Device.Functions->WriteDevice(s,buffer + sent, length - sent);

			if (write_data == 0 || write_data < 0) {
				return ERR_DEVICEWRITEERROR;
			}
			sent += write_data;
		}
	} else {
		for (i = 0; i < length; i++) {
			/* For some phones like Siemens M20 we need to wait a little
			 * after writing each char. Possible reason: these phones
			 * can't receive so fast chars or there is bug here in Gammu */
			write_data = s->Device.Functions->WriteDevice(s, buffer + i, 1);

			if (write_data != 1) {
				return ERR_DEVICEWRITEERROR;
			}
			usleep(1000);
		}
		usleep(400000);
	}
	return ERR_NONE;
}
Exemplo n.º 2
0
static GSM_Error GNAPBUS_WriteMessage (GSM_StateMachine *s, unsigned const char *MsgBuffer,
				    int MsgLength, unsigned char MsgType)
{
	unsigned char	*buffer=NULL;
	int		sent=0,length=0,i=0;
	unsigned char	checksum=0;

	GSM_DumpMessageLevel3(s, MsgBuffer, MsgLength, MsgType);

	buffer = (unsigned char *)malloc(MsgLength + 10);

	buffer[0] = GNAPBUS_FRAME_ID,
	buffer[1] = 0x00;
	buffer[2] = MsgLength / 256;
	buffer[3] = MsgLength % 256;
	buffer[4] = MsgType;
	buffer[5] = 0x00;
	memcpy(buffer + 6, MsgBuffer, MsgLength);
	length = MsgLength+6;

	if (MsgLength & 1) buffer[length++] = 0x00;
	/* Odd messages require additional 0x00 byte */
/* 	if (MsgLength % 2) buffer[length++] = 0x00; */

	checksum 	= 0;
	for (i = 0; i < length; i+=2) checksum ^= buffer[i];
	buffer[length++] 	= checksum;

	checksum 	= 0;
	for (i = 1; i < length; i+=2) checksum ^= buffer[i];
	buffer[length++] 	= checksum;

/* 	GSM_DumpMessageLevel2(s, buffer, length, MsgType); */
	GSM_DumpMessageLevel2(s, MsgBuffer, MsgLength, MsgType);

	/* Sending to phone */
	sent = s->Device.Functions->WriteDevice(s,buffer,length);
	free(buffer);
	buffer=NULL;

	if (sent!=length) {
		return ERR_DEVICEWRITEERROR;
	}
	return ERR_NONE;
}
Exemplo n.º 3
0
static GSM_Error FBUS2_WriteMessage (GSM_StateMachine 	*s,
				     unsigned const char *MsgBuffer,
				     int 		MsgLength,
				     unsigned char 	MsgType)
{
	int 			i=0, nom=0, togo=0, thislength=0; /* number of messages, ... */
	unsigned char 		buffer[FBUS2_MAX_TRANSMIT_LENGTH + 2]={0}, seqnum=0;
	GSM_Protocol_FBUS2Data	*d = &s->Protocol.Data.FBUS2;
	GSM_Error 		error;

	GSM_DumpMessageLevel3(s, MsgBuffer, MsgLength, MsgType);

	nom  = (MsgLength + FBUS2_MAX_TRANSMIT_LENGTH - 1) / FBUS2_MAX_TRANSMIT_LENGTH;
	togo = MsgLength;

	for (i = 0; i < nom; i++) {
		seqnum = d->MsgSequenceNumber;

		if (i==0) {
			seqnum = seqnum + 0x40;
		}
		d->MsgSequenceNumber = (d->MsgSequenceNumber + 1) & 0x07;

		thislength = togo;

		if (togo > FBUS2_MAX_TRANSMIT_LENGTH) {
			thislength = FBUS2_MAX_TRANSMIT_LENGTH;
		}
		memcpy(buffer, MsgBuffer + (MsgLength - togo), thislength);
		buffer[thislength] = nom - i;
		buffer[thislength + 1]	= seqnum;
		togo = togo - thislength;

		GSM_DumpMessageLevel2(s, buffer, thislength, MsgType);

		error = FBUS2_WriteFrame(s, buffer, thislength + 2, MsgType);

		if (error != ERR_NONE) {
			return error;
		}
	}
	return ERR_NONE;
}