예제 #1
0
int sendHeartBeat( void )
{
	unsigned i;
	CONTROLSTATE state;
	unsigned char* p_char;
	
	readControlState( &state );
	
	p_char = (unsigned char *)&state; 
	
	vscp_omsg.priority = VSCP_PRIORITY_MEDIUM;
	vscp_omsg.flags = VSCP_VALID_MSG + 3;
	vscp_omsg.vscp_class = VSCP_CLASS1_INFORMATION;
	vscp_omsg.vscp_type = VSCP_TYPE_INFORMATION_NODE_HEARTBEAT;
	
	for(i=0; i < sizeof(CONTROLSTATE); i++)
	{
		vscp_omsg.data[i] = p_char[i];	
	}
	
	// Send data
	if ( !vscp_sendEvent() ) {
		return FALSE;
	}

	return TRUE;
}
예제 #2
0
void process_can_message()
{
	BYTE state_incoming;
	BYTE substate_incoming;
	
	// Incoming CAN data
	unsigned long ican_id;
	//BYTE ican_data[ 8 ]; 
	BYTE ican_dlc; 
	BYTE ican_flags;
	uint8_t msgflags;
	
	if ( bCanErrMsgValid )
	{
		send_can_error_message( g_can_lokal_error );
	}

	if ( bCanMsgValid )
	{
		if (  vscp_sendEvent( &can_msg2send ) )
			bCanMsgValid = FALSE;
	}
		
	// Incoming CAN message
	if ( vscp18f_readMsg( &ican_id, can_msg2send.data, &ican_dlc, &ican_flags ) ) 
	{	
		can_msg2send.sizeData = ican_dlc;	
		msgflags = ican_flags;		
		if ( ican_flags & CAN_RX_XTD_FRAME ) {
			msgflags |= 0x80;	// This is an extended frame 
		}
			
		if ( ican_flags & CAN_RX_RTR_FRAME ) {
			msgflags |= 0x40; // This is a RTR frame
		}
		can_msg2send.head = 0; //msgflags;

		can_msg2send.vscp_class = ican_id & 0xffff;
		can_msg2send.vscp_type = ( ican_id >> 16 ) & 0xffff;

		if (  vscp_sendEvent( &can_msg2send ) )
			bCanMsgValid = FALSE;
	}
예제 #3
0
void vscp_sendHeartBeat(uint8_t zone, uint8_t subzone)
{
    vscp_omsg.flags = VSCP_VALID_MSG + 3; // three databyte
    vscp_omsg.priority = VSCP_PRIORITY_LOW;
    vscp_omsg.vscp_class = VSCP_CLASS1_INFORMATION;
    vscp_omsg.vscp_type = VSCP_TYPE_INFORMATION_NODE_HEARTBEAT;
    vscp_omsg.data[ 0 ] = 0;
    vscp_omsg.data[ 1 ] = zone;
    vscp_omsg.data[ 2 ] = subzone;

    // send the event
    vscp_sendEvent();
}
예제 #4
0
void vscp_goActiveState(void)
{
    vscp_omsg.flags = VSCP_VALID_MSG + 1; // one databyte
    vscp_omsg.priority = VSCP_PRIORITY_HIGH;
    vscp_omsg.vscp_class = VSCP_CLASS1_PROTOCOL;
    vscp_omsg.vscp_type = VSCP_TYPE_PROTOCOL_NEW_NODE_ONLINE;
    vscp_omsg.data[ 0 ] = vscp_nickname;

    // send the event
    vscp_sendEvent();

//    vscp_initledfunc = VSCP_LED_ON;
}
예제 #5
0
void vscp_getEmbeddedMdfInfo( void )
{
	// No embedded DM so we respond with info about that
	
	vscp_omsg.priority = VSCP_PRIORITY_NORMAL;
	vscp_omsg.flags = VSCP_VALID_MSG + 3;
	vscp_omsg.vscp_class = VSCP_CLASS1_PROTOCOL;
	vscp_omsg.vscp_type = VSCP_TYPE_PROTOCOL_RW_RESPONSE;

	vscp_omsg.data[ 0 ] = 0;
	vscp_omsg.data[ 1 ] = 0;
	vscp_omsg.data[ 2 ] = 0;	
	
	// send the message
	vscp_sendEvent();
}
예제 #6
0
void vscp_newNodeOnline(void)
{
    if ((1 == (vscp_imsg.flags & 0x0f)) &&
            (vscp_nickname == vscp_imsg.data[ 0 ])) {

        // This is a probe which use our nickname
        // we have to respond to tell the new node that
        // ths nickname is in use

        vscp_omsg.flags = VSCP_VALID_MSG;
        vscp_omsg.priority = VSCP_PRIORITY_HIGH;
        vscp_omsg.vscp_class = VSCP_CLASS1_PROTOCOL;
        vscp_omsg.vscp_type = VSCP_TYPE_PROTOCOL_PROBE_ACK;
        vscp_sendEvent();

    }
}
예제 #7
0
void vscp_handleSetNickname(void)
{
    if ( ( 2 == (vscp_imsg.flags & 0x0f ) ) &&
            (vscp_nickname == vscp_imsg.data[ 0 ])) {

        // Yes, we are addressed
        vscp_nickname = vscp_imsg.data[ 1 ];
        vscp_writeNicknamePermanent(vscp_nickname);

		//return nickname accepted
		vscp_omsg.flags = VSCP_VALID_MSG + 1; // one data byte
		vscp_omsg.priority = VSCP_PRIORITY_HIGH;
		vscp_omsg.vscp_class = VSCP_CLASS1_PROTOCOL;
		vscp_omsg.vscp_type = VSCP_TYPE_PROTOCOL_NICKNAME_ACCEPTED;
		vscp_omsg.data[ 0 ] = vscp_nickname;

		// send the event
		vscp_sendEvent();

    }
}
예제 #8
0
void vscp_handleProbeState(void)
{
    switch (vscp_node_substate) {

        case VSCP_SUBSTATE_NONE:

            if (VSCP_ADDRESS_FREE != vscp_probe_address) {

                vscp_omsg.flags = VSCP_VALID_MSG + 1; // one databyte
                vscp_omsg.priority = VSCP_PRIORITY_HIGH;
                vscp_omsg.vscp_class = VSCP_CLASS1_PROTOCOL;
                vscp_omsg.vscp_type = VSCP_TYPE_PROTOCOL_NEW_NODE_ONLINE;
                vscp_omsg.data[ 0 ] = vscp_probe_address;

                // send the probe
                vscp_sendEvent();

                vscp_node_substate = VSCP_SUBSTATE_INIT_PROBE_SENT;
                vscp_timer = 0;

            } else {

                // No free address -> error
                vscp_node_state = VSCP_STATE_ERROR;

                // Tell system we are giving up
                vscp_omsg.flags = VSCP_VALID_MSG + 1; // one databyte
                vscp_omsg.data[ 0 ] = 0xff; // we are unassigned
                vscp_omsg.priority = VSCP_PRIORITY_LOW;
                vscp_omsg.vscp_class = VSCP_CLASS1_PROTOCOL;
                vscp_omsg.vscp_type = VSCP_TYPE_PROTOCOL_PROBE_ACK;

                // send the error event
                vscp_sendEvent();

            }
            break;

        case VSCP_SUBSTATE_INIT_PROBE_SENT:

            if (vscp_imsg.flags & VSCP_VALID_MSG) { // incoming event?

                // Yes, incoming event
                if ((VSCP_CLASS1_PROTOCOL == vscp_imsg.vscp_class) &&
                        (VSCP_TYPE_PROTOCOL_PROBE_ACK == vscp_imsg.vscp_type)) {

                    // Yes it was an ack from the segment master or a node
                    if (0 == vscp_probe_address) {

                        // Master controller answered
                        // wait for address
                        vscp_node_state = VSCP_STATE_PREACTIVE;
                        vscp_timer = 0; // reset timer

                    } else {

                        // node answered, try next address
                        vscp_probe_address++;
                        vscp_node_substate = VSCP_SUBSTATE_NONE;
                        vscp_probe_cnt = 0;

                    }
                }
            } else {

                if (vscp_timer > VSCP_PROBE_TIMEOUT) { // Check for timeout

                    vscp_probe_cnt++; // Another timeout

                    if (vscp_probe_cnt >= VSCP_PROBE_TIMEOUT_COUNT) {

                        // Yes we have a timeout
                        if (0 == vscp_probe_address) { // master controller probe?

                            // No master controler on segment, try next node
                            vscp_probe_address++;
                            vscp_node_substate = VSCP_SUBSTATE_NONE;
                            vscp_timer = 0;
                            vscp_probe_cnt = 0;

                        } else {

                            // We have found a free address - use it
                            vscp_nickname = vscp_probe_address;
                            vscp_node_state = VSCP_STATE_ACTIVE;
                            vscp_node_substate = VSCP_SUBSTATE_NONE;
                            vscp_writeNicknamePermanent(vscp_nickname);
                            vscp_setSegmentCRC(0x40); // segment code (non server segment )

                            // Report success
                            vscp_probe_cnt = 0;
                            vscp_goActiveState();

                        }
                    } else {
                        vscp_node_substate = VSCP_SUBSTATE_NONE;
                    }
                } // Timeout

            }
            break;

        case VSCP_SUBSTATE_INIT_PROBE_ACK:
            break;

        default:
            vscp_node_substate = VSCP_SUBSTATE_NONE;
            break;
    }

    vscp_imsg.flags = 0;

}