// Encode_Decode_Data_OnKey // Makes use of Encode and Decode data // Press 'I' to encode the data, value is set to 1 // Decodes the data and is displayed in the Information View window // Press 'K' to display data in the Information View window // Loops 5 times and increments the 4th data byte by 5 void OnError(uchar channel, uchar error_type) { } void OnFrame(DataFrame *frame, uchar channel) { } void OnKey(char character) { /*Ctrl I encodes the data, Value is set to 1. Decodes the data and is displayed in the Information View window.*/ if(character=='I') { unsigned char data[50]; char encodestring[100]; PARAM_INFO testData; double value; int loop = 0; int sByte; int sBit; int sLen; double sendVal = 1.0; memset (data,0,50); sByte = 0; sBit = 0; sLen = 16; value = 0; testData.m_startByte = sByte; testData.m_startBit = sBit; testData.m_paramLength = sLen; testData.m_resolution = 1; testData.m_offset = 0; testData.m_signedUnsignedFlag = 0; testData.m_applyScaling = 1; if(EncodeData (data, 10 ,testData, sendVal ) == 0) { sprintf (encodestring,"Value was %f", sendVal); WriteInfo (encodestring); sprintf (encodestring,"Data = %02X %02X %02X %02X %02X %02X %02X %02X",data[0],data[1],data[2],data[3],data[4],data[5],data[6],data[7] ); WriteInfo (encodestring); WriteInfo ("Now let's decode it!"); if (DecodeData (data, 10, testData, &value) == 0) { sprintf (encodestring, "Decode Val = %f", value); WriteInfo (encodestring); } } } /*Press Ctrl K at same time the PARAM_INFO will be defined and then the data will be displayed in the Information View window. Encode Data and Decode Data is used. Loops 5 times and increments the 4th data byte by 5 */ else if (character == 'K') { unsigned char data[50]; char encodestring[100]; PARAM_INFO testData; double value; int loop = 0; int sByte; int sBit; int sLen; double sendVal = 50.0; memset (data,0,50); sByte = 2; sBit = 1; sLen = 16; value = 0; testData.m_startByte = sByte; testData.m_startBit = sBit; testData.m_paramLength = sLen; testData.m_resolution = 5; testData.m_offset = 0; testData.m_signedUnsignedFlag = 0; testData.m_applyScaling = 1; if (EncodeData (data, 10, testData, sendVal) == 0) { sprintf (encodestring, "Value was %f", sendVal); WriteInfo (encodestring); sprintf (encodestring, "Data = %02X %02X %02X %02X %02X %02X %02X %02X", data[0],data[1],data[2],data[3],data[4],data[5],data[6],data[7] ); WriteInfo (encodestring); WriteInfo ("Now let's decode it!"); if (DecodeData (data, 10, testData, &value) == 0) { sprintf (encodestring, "Decode Val = %f", value); WriteInfo (encodestring); } } for (loop =1; loop<6; loop++) { memset (data, 0, 10); EncodeData (data, 10, testData, sendVal+(loop*5) ); sprintf (encodestring,"Data = %02X %02X %02X %02X %02X %02X %02X %02X", data[0],data[1],data[2],data[3],data[4],data[5],data[6],data[7] ); WriteInfo (encodestring); DecodeData (data, 10, testData, &value); sprintf (encodestring, "Data Increment + 5 = %f", value); WriteInfo (encodestring); } } else WriteInfo ("You have pressed the wrong keys"); } void OnStart(long time) { WriteInfo("Press Ctrl I or Ctrl K"); } void OnStop(long time) { } void OnTimer(uint timerid) { } void OnTrigger(long time) { } void OnSerial(const void * data, unsigned short datacount) { } void OnMsg(char * string) { }