Пример #1
0
static GSM_Error MBUS2_SendAck(GSM_StateMachine 	*s,
                               unsigned char 		type,
                               unsigned char 		sequence)
{
    GSM_Device_Functions 	*Device		= s->Device.Functions;
    unsigned char 		buffer[6]= {0};
    int 			i=0,length=0,write_data=0;

    buffer[0] = MBUS2_FRAME_ID;
    buffer[1] = MBUS2_DEVICE_PHONE;	/* destination */
    buffer[2] = MBUS2_DEVICE_PC;		/* source */
    buffer[3] = MBUS2_ACK_BYTE;
    buffer[4] = sequence;
    buffer[5] = '\0';
    length=strlen(buffer);

    /* Calculating checksum */
    for (i = 0; i < length; i++) {
        buffer[5] ^= buffer[i];
    }
    smprintf_level(s, D_TEXT, "[Sending Ack of type %02x, seq: %x]\n",type,sequence);

    /* Sending to phone */
    write_data=Device->WriteDevice(s,buffer,length);

    if (write_data!=length) {
        return ERR_DEVICEWRITEERROR;
    }
    return ERR_NONE;
}
Пример #2
0
static GSM_Error MBUS2_Initialise(GSM_StateMachine *s)
{
    GSM_Device_Functions 	*Device	= s->Device.Functions;
    GSM_Protocol_MBUS2Data 	*d	= &s->Protocol.Data.MBUS2;
    GSM_Error 		error;

    d->Msg.Length		= 0;
    d->Msg.BufferUsed	= 0;
    d->Msg.Buffer		= NULL;

    d->MsgSequenceNumber	= 0;
    d->MsgRXState		= RX_Sync;

    error=Device->DeviceSetSpeed(s,9600);
    if (error!=ERR_NONE) return error;

    error=Device->DeviceSetParity(s,TRUE);
    if (error!=ERR_NONE) return error;

    error=Device->DeviceSetDtrRts(s,FALSE,TRUE); /*DTR low,RTS high*/
    if (error!=ERR_NONE) return error;
    usleep(200000);

    return ERR_NONE;
}
Пример #3
0
static GSM_Error FBUS2_Initialise(GSM_StateMachine *s)
{
	GSM_Protocol_FBUS2Data	*d		= &s->Protocol.Data.FBUS2;
	GSM_Device_Functions	*Device 	= s->Device.Functions;
	GSM_Error		error;
	unsigned char		buff[300]={0};

	d->Msg.Length		= 0;
	d->Msg.Buffer		= NULL;
	d->MultiMsg.BufferUsed	= 0;
	d->MultiMsg.Length	= 0;
	d->MultiMsg.Buffer	= NULL;

	d->MsgSequenceNumber	= 0;
	d->FramesToGo		= 0;
	d->MsgRXState		= RX_Sync;

	error = Device->DeviceSetParity(s, FALSE);
	if (error != ERR_NONE) return error;

	switch (s->ConnectionType) {
#if defined(GSM_ENABLE_BLUEFBUS2) || defined(GSM_ENABLE_FBUS2BLUE)
	case GCT_FBUS2BLUE:
	case GCT_BLUEFBUS2:
		error = FBUS2_ATSwitch(s);
		if (error != ERR_NONE) return error;
		break;
#endif
#if defined(GSM_ENABLE_FBUS2DLR3) || defined(GSM_ENABLE_DKU5FBUS2) || defined(GSM_ENABLE_FBUS2PL2303)
	case GCT_DKU5FBUS2:
	case GCT_FBUS2PL2303:
	case GCT_FBUS2DLR3:
		error = Device->DeviceSetDtrRts(s,FALSE,FALSE);
		if (error != ERR_NONE) return error;
		sleep(1);

		if (! s->NoPowerCable) {
			error = Device->DeviceSetDtrRts(s,TRUE,TRUE);
			if (error != ERR_NONE) return error;
			sleep(1);
		}

		error = Device->DeviceSetSpeed(s,19200);
		if (error != ERR_NONE) return error;

		error = FBUS2_ATSwitch(s);
		if (error != ERR_NONE) return error;

		error = Device->DeviceSetSpeed(s,115200);
		if (error != ERR_NONE) return error;

		error = FBUS2_InitSequence(s, 32, 0, TRUE);
		if (error != ERR_NONE) return error;

		break;
#endif
	case GCT_FBUS2:
		error = Device->DeviceSetSpeed(s,115200);
		if (error != ERR_NONE) return error;

		/* Set DTR as power supply if needed, RTS is always low */
		error = Device->DeviceSetDtrRts(s, !(s->NoPowerCable), FALSE);
		if (error != ERR_NONE) return error;

		error = FBUS2_InitSequence(s, 32, 0, TRUE);
		if (error != ERR_NONE) return error;

		break;
#ifdef GSM_ENABLE_FBUS2IRDA
	case GCT_FBUS2IRDA:
		error = Device->DeviceSetSpeed(s,9600);
		if (error != ERR_NONE) return error;

		error = FBUS2_InitSequence(s, 32, 0, TRUE);
		if (error != ERR_NONE) return error;

		error = Device->DeviceSetSpeed(s,115200);
		if (error != ERR_NONE) return error;

		break;
#endif
	default:
		break;
	}

	/* A bit more of synchronisation could be needed here */
	if (s->ConnectionType != GCT_FBUS2BLUE && s->ConnectionType != GCT_BLUEFBUS2) {
		error = FBUS2_InitSequence(s, 250, 100, FALSE);
		if (error != ERR_NONE) return error;
	}

	/* Read any possible junk on the line */
	while (s->Device.Functions->ReadDevice(s, buff, sizeof(buff)) > 0) {
		usleep(1000);
	}

	return ERR_NONE;
}