/*! \fn bool vscp_getVscpDataFromString( vscpEvent *pEvent, const wxString& str ) \brief Set data in VSCP event from a string. */ extern "C" bool WINAPI EXPORT vscp_getVscpDataFromString( vscpEvent *pEvent, const wxString& str ) { return getVscpDataFromString( pEvent, str ); }
bool CVSCPVariable::setValueFromString( int type, const wxString& strValue ) { // Convert to uppercase wxString strUpper; switch ( type ) { case VSCP_DAEMON_VARIABLE_CODE_STRING: m_strValue = strValue; break; case VSCP_DAEMON_VARIABLE_CODE_BOOLEAN: { strUpper = strValue.Upper(); if ( wxNOT_FOUND != strUpper.Find( _("TRUE") ) ) { m_boolValue = true; } else { m_boolValue = false; } } break; case VSCP_DAEMON_VARIABLE_CODE_INTEGER: m_longValue = readStringValue( strValue ); break; case VSCP_DAEMON_VARIABLE_CODE_LONG: m_longValue = readStringValue( strValue ); break; case VSCP_DAEMON_VARIABLE_CODE_DOUBLE: strValue.ToDouble( &m_floatValue ); break; case VSCP_DAEMON_VARIABLE_CODE_VSCP_MEASUREMENT: { uint8_t data[ VSCP_MAX_DATA ]; uint16_t sizeData = 0; getVscpDataArrayFromString( data, &sizeData, strValue ); if ( sizeData > 8 ) sizeData = 8; if (sizeData) memcpy( m_normInteger, data, sizeData ); m_normIntSize = sizeData; } break; case VSCP_DAEMON_VARIABLE_CODE_VSCP_EVENT: getVscpEventFromString( &m_event, strValue ); break; case VSCP_DAEMON_VARIABLE_CODE_VSCP_EVENT_GUID: getGuidFromString( &m_event, strValue ); break; case VSCP_DAEMON_VARIABLE_CODE_VSCP_EVENT_DATA: getVscpDataFromString( &m_event, strValue ); break; case VSCP_DAEMON_VARIABLE_CODE_VSCP_EVENT_CLASS: m_event.vscp_class = readStringValue( strValue ); break; case VSCP_DAEMON_VARIABLE_CODE_VSCP_EVENT_TYPE: m_event.vscp_type = readStringValue( strValue ); break; case VSCP_DAEMON_VARIABLE_CODE_VSCP_EVENT_TIMESTAMP: m_event.timestamp = readStringValue( strValue ); break; case VSCP_DAEMON_VARIABLE_CODE_DATETIME: m_timestamp.ParseDateTime( strValue ); break; case VSCP_DAEMON_VARIABLE_CODE_UNASSIGNED: // Fall through - Not allowed here default: return false; } return true; }
void ctrlUpdate::eventThreadMessage( wxCommandEvent &event ) { int write_pointer,checksum16; unsigned long intflash_blocksize,max_intflash_blocknumber,extflash_blocksize,max_extflash_blocknumber; int block_number; int i = event.GetInt(); int id = i & 0xFFFF; int type = (i >> 16) & 0xFFFF; CDeviceNode* pNode = m_plistNode->GetNodeByNickName(id); wxString strData = event.GetString(); vscpEvent* pVscp = new vscpEvent; getVscpDataFromString( pVscp, strData ); if(pNode != NULL) { if(event.GetExtraLong()==0) { switch(type) { case VSCP_TYPE_PROTOCOL_ACK_BOOT_LOADER: // pVscp->pdata[ 0 ] = 2; MSB internal flash block size // pVscp->pdata[ 1 ] = 2; MSB spi flash block size // pVscp->pdata[ 2 ] = 0; LSB spi flash block size // pVscp->pdata[ 3 ] = 0; LSB internal flash block size // pVscp->pdata[ 4 ] = 1; MSB internal flash number of block avalaible // pVscp->pdata[ 5 ] = 4; MSB spi flash number of block avalaible // pVscp->pdata[ 6 ] = 0; LSB spi flash number of block avalaible // pVscp->pdata[ 7 ] = 0; LSB internal flash number of block avalaible intflash_blocksize = (pVscp->pdata[0] << 8) | pVscp->pdata[3]; extflash_blocksize = (pVscp->pdata[1] << 8) | pVscp->pdata[2]; max_intflash_blocknumber = (pVscp->pdata[4] << 8) | pVscp->pdata[7]; max_extflash_blocknumber = (pVscp->pdata[5] << 8) | pVscp->pdata[6]; if((intflash_blocksize == BLOCKDATA_SIZE) && (extflash_blocksize == BLOCKDATA_SIZE) && (max_intflash_blocknumber >= (m_IntFlashBinaryLength/BLOCKDATA_SIZE))&& (max_extflash_blocknumber >= (m_ExtFlashBinaryLength/BLOCKDATA_SIZE)) ) { crcInit(); m_nTotalChecksum = 0; m_nCurrentBlockNumber = 0; m_nCurrentFlashType = INT_FLASH; // internal flash // attenzione: questo messaggio (VSCP_TYPE_PROTOCOL_ACK_BOOT_LOADER) è l'ultimo arrivato dal // programma user, ora ha preso il controllo il bootloader; è probabile che sia necessario // un delay prima di trasmettere il messaggio di "start block transfer" wxMilliSleep( 2000 );//wxMilliSleep( 500 );//wxMilliSleep( 200 ); StartBlockTransferMsg( pNode->GetNickName(), m_nCurrentBlockNumber, m_nCurrentFlashType ); } else { UpdateError(pNode); } //::wxGetApp().logMsg ( _("event ack bootloader"), DAEMON_LOGMSG_CRITICAL ); break; case VSCP_TYPE_PROTOCOL_START_BLOCK_ACK: // pVscp->pdata[0] MSB block number // pVscp->pdata[1] INTERNAL_FLASH/SPI_FLASH // pVscp->pdata[2] // pVscp->pdata[3] LSB block number if(m_nCurrentFlashType == pVscp->pdata[1]) { switch(m_nCurrentFlashType) { case INT_FLASH: DataBlockTransferMsg(); m_nChecksum = crcFast( &m_pIntFlashBinaryContent[USER_PROGRAM_ADDRESS + m_nCurrentBlockNumber*BLOCKDATA_SIZE], BLOCKDATA_SIZE );//crcFast( &m_pIntFlashBinaryContent[30208], BLOCKDATA_SIZE );//crcFast( &m_pIntFlashBinaryContent[USER_PROGRAM_ADDRESS + m_nCurrentBlockNumber*BLOCKDATA_SIZE], BLOCKDATA_SIZE ); //m_nTotalChecksum += m_nChecksum; break; case EXT_FLASH: DataBlockTransferMsg(); m_nChecksum = crcFast( &m_pExtFlashBinaryContent[m_nCurrentBlockNumber*BLOCKDATA_SIZE], BLOCKDATA_SIZE ); break; } } else { UpdateError(pNode); } //::wxGetApp().logMsg ( _("event ack data block"), DAEMON_LOGMSG_CRITICAL ); break; case VSCP_TYPE_PROTOCOL_BLOCK_DATA_ACK: // pVscp->pdata[0] = (checksum16 >> 8) & 0xFF; MSB 16 bit CRC for block // pVscp->pdata[1] = checksum16 & 0xFF; LSB 16 bit CRC for block // pVscp->pdata[2] = (write_pointer >> 8) & 0xFF; MSB of block number // pVscp->pdata[3] = 0; // pVscp->pdata[4] = 0; // pVscp->pdata[5] = write_pointer & 0xFF; LSB of block number checksum16 = (pVscp->pdata[0] << 8) | pVscp->pdata[1]; write_pointer = (pVscp->pdata[2] << 8) | pVscp->pdata[5]; if((checksum16 == m_nChecksum) && (write_pointer == m_nCurrentBlockNumber)) BlockProgramMsg( m_nCurrentBlockNumber, m_nCurrentFlashType ); else { // in questo caso di errore si ritrasmette il blocco StartBlockTransferMsg( pNode->GetNickName(), m_nCurrentBlockNumber, m_nCurrentFlashType ); //UpdateError(pNode); } //::wxGetApp().logMsg ( _("event ack data block"), DAEMON_LOGMSG_CRITICAL ); break; case VSCP_TYPE_PROTOCOL_PROGRAM_BLOCK_DATA_ACK: // pVscp->pdata[0] MSB block number // pVscp->pdata[1] INTERNAL_FLASH/SPI_FLASH // pVscp->pdata[2] // pVscp->pdata[3] LSB block number block_number = (pVscp->pdata[0] << 8) | pVscp->pdata[3]; if((block_number == m_nCurrentBlockNumber) && (pVscp->pdata[1] == m_nCurrentFlashType)) { switch(m_nCurrentFlashType) { case INT_FLASH: m_nCurrentBlockNumber++; //::wxGetApp().logMsg ( _("event PROGRAM ACK"), DAEMON_LOGMSG_CRITICAL ); m_nTotalChecksum += m_nChecksum; if(m_nCurrentBlockNumber == (int)((m_IntFlashBinaryLength - USER_PROGRAM_ADDRESS)/BLOCKDATA_SIZE)) { m_nCurrentBlockNumber = 0; m_nCurrentFlashType = EXT_FLASH; //ActivateNewImageMsg(); // DEBUG!! } //else // DEBUG!! //{// DEBUG!! // avanzamento progress control della dialog pNode->FirmwareProgressStep(); wxGetApp().Yield(); StartBlockTransferMsg( pNode->GetNickName(), m_nCurrentBlockNumber, m_nCurrentFlashType ); //}// DEBUG!! break; case EXT_FLASH: m_nCurrentBlockNumber++; if(m_nCurrentBlockNumber == (int)(m_ExtFlashBinaryLength/BLOCKDATA_SIZE)) { ActivateNewImageMsg(); } else { // avanzamento progress control della dialog pNode->FirmwareProgressStep(); wxGetApp().Yield(); StartBlockTransferMsg( pNode->GetNickName(), m_nCurrentBlockNumber, m_nCurrentFlashType ); } break; } } else { UpdateError(pNode); } //::wxGetApp().logMsg ( _("event ack program block"), DAEMON_LOGMSG_CRITICAL ); break; case VSCP_TYPE_PROTOCOL_ACTIVATENEWIMAGE_ACK: // delay per attendere che il nodo remoto abbia finito la fase di // inizializzazione altrimenti quando l'utente chiude la dialog di update // c'e' il rischio che il gestore dell' heartbeat non rilevi il nuovo stato (stato user) // del nodo wxMilliSleep( 8000 ); m_tDoneUpgrade = wxDateTime::Now(); ::wxGetApp().logMsg ( wxT("Upgrade Finished... taking: ") + (m_tDoneUpgrade - m_tStartUpgrade).Format(), DAEMON_LOGMSG_CRITICAL ); // avvisa la dialog che è finito il processo di update pNode->EndFirmwareProgress(FIRMWAREUPDATEOK); break; case VSCP_TYPE_PROTOCOL_NACK_BOOT_LOADER: UpdateError(pNode); ::wxGetApp().logMsg ( _("event NACK bootloader"), DAEMON_LOGMSG_CRITICAL ); break; case VSCP_TYPE_PROTOCOL_START_BLOCK_NACK: UpdateError(pNode); ::wxGetApp().logMsg ( _("event NACK start block"), DAEMON_LOGMSG_CRITICAL ); break; case VSCP_TYPE_PROTOCOL_BLOCK_DATA_NACK: UpdateError(pNode); ::wxGetApp().logMsg ( _("event NACK data block"), DAEMON_LOGMSG_CRITICAL ); break; case VSCP_TYPE_PROTOCOL_PROGRAM_BLOCK_DATA_NACK: UpdateError(pNode); ::wxGetApp().logMsg ( _("event NACK program block"), DAEMON_LOGMSG_CRITICAL ); break; case VSCP_TYPE_PROTOCOL_ACTIVATENEWIMAGE_NACK: UpdateError(pNode); ::wxGetApp().logMsg ( _("event NACK activate new image"), DAEMON_LOGMSG_CRITICAL ); break; } } else { UpdateError(pNode); } } deleteVSCPevent( pVscp ); }