void vscp_handleHeartbeat(void) { if ( !vscp_getSegmentCRC() ) { if ( ( 5 == (vscp_imsg.flags & 0x0f ) ) && (vscp_getSegmentCRC() != vscp_imsg.data[ 0 ])) { // Stored CRC are different than received // We must be on a different segment vscp_setSegmentCRC(vscp_imsg.data[ 0 ]); // Introduce ourself in the proper way and start from the beginning vscp_nickname = VSCP_ADDRESS_FREE; vscp_writeNicknamePermanent(VSCP_ADDRESS_FREE); vscp_node_state = VSCP_STATE_INIT; } } else { // First heartbeat seen by this node vscp_setSegmentCRC(vscp_imsg.data[ 0 ]); } }
/////////////////////////////////////////////////////////////////////////////// // vscp_rcv_heartbeat // void vscp_handleHeartbeat( void ) { if ((5 == RxMsg.length)&& ( vscp_getSegmentCRC()!= RxMsg.data[0])) { // Stored CRC are different than received // We must be on a different segment vscp_setSegmentCRC( RxMsg.data[0]); // Introduce ourself in the proper way and start from the beginning vscp_nickname = VSCP_ADDRESS_FREE; vscp_setNickname( VSCP_ADDRESS_FREE); vscp_init(); // Clear Restart with VSCP_ADDRESS_FREE } }
/////////////////////////////////////////////////////////////////////////////// // vscp_check_pstorage // // Check control position integrity and restore EEPROM // if invalid. // int08_t vscp_check_pstorage( void ) { // controlbyte == 01xxxxxx means initialized // everything else is uninitialized if ( VSCP_CRC_FREE != vscp_getSegmentCRC()) { return TRUE; } // No nickname yet. vscp_setNickname( VSCP_ADDRESS_FREE); // No segment CRC yet. vscp_setSegmentCRC( VSCP_CRC_FREE); vscp_setControlByte( VSCP_CONTROL_STARTUP); // Initial startup, write allowed return FALSE; }
int8_t vscp_check_pstorage(void) { // controlbyte == 01xxxxxx means initialized // everything else is uninitialized if ((vscp_getSegmentCRC() & 0xc0) == 0x40) { return TRUE; } // No nickname yet. vscp_writeNicknamePermanent(0xff); // No segment CRC yet. vscp_setSegmentCRC(0x00); // Initial startup // write allowed vscp_setControlByte(0xA0); return FALSE; }
/*! * @brief verify functionality of the custom defined vscp functions * vscp_firmware.h @ line 457 */ void test_vscp_externals(){ uint8_t FlashValue8; /*! gets an 8-bit vscp data field from permanent storage */ uint8_t val; /*! assign a value to write to buffer -> permanent storage */ printf("Testing vscp_functions\r\n"); val = 0x11; vscp_writeNicknamePermanent(val); FlashValue8 = vscp_readNicknamePermanent(); printf("Read %d dec, %x hex\r\n", FlashValue8, FlashValue8); val = 0x22; vscp_setSegmentCRC(val); FlashValue8 = vscp_getSegmentCRC(); printf("Read %d dec, %x hex\r\n", FlashValue8, FlashValue8); val = 0x33; vscp_setControlByte(val); FlashValue8 = vscp_getControlByte(); printf("Read %d dec, %x hex\r\n", FlashValue8, FlashValue8); }