|
Hi all,
Iam having a checksum algo implemented in my code.
The Pc receives a packet from microcontroller and then does this as a check:
for(i=0;i < max_length-1;i++)<br />
{<br />
checksum ^= recd_buf[i];<br />
}
then this checksum is compared with the last member fo the received packet which has the checksum sent from microcontroller.
if(checksum != recd_buf[max_length-1])<br />
{<br />
"bad packet"<br />
}
but i always get the values to be not equal. By printing out the received packet details, they are all correct.
there s no error on the microcontroller end.
There is error in the calcualtion of checksum at the Pc end (the code shown above).
Can anyone help? I know there are various checksum algos available. but i want to find out the bug/error in this.
thanks in advance.
-- modified at 0:39 Monday 14th August, 2006
|
|
|
|
|
look here
if(checksum != recd_buf[max_length-1])
{
"bad packet"
}
do you think in " recd_buf[max_length-1]) "
the "max_length-1 " is ok. why donot you compare with
"max_length " . Because in first "for loop " your iterator "i" starts from " 0 " but at this time you are just checking maximum length.
as long I think
if(checksum != recd_buf[max_length])
{
"bad packet"
}
Tanvon
the brain behind ...
|
|
|
|
|
I think his loop is correct, because you usually don't include the check sum value in the check sum algo, hence the < max_length - 1 in the loop control. If you did recd_buf[max_length], that would be out of bounds, since it's zero based.
Thinking about it more, maybe the checksum should be part of the algo, maybe try i < max_length, instead of max_length - 1, and see if that works.
I've seen some other algorithms as well, but try that first.
- S
50 cups of coffee and you know it's on!
|
|
|
|
|
Is checksum initialized properly?
What are your data types? When using the bitwise operators, all types should be unsigned. You may be getting bit by sign-extension or some other result of integral promotion.
--Mike--
Visual C++ MVP
LINKS~! Ericahist | PimpFish | CP SearchBar v3.0 | C++ Forum FAQ
|
|
|
|
|
Hi,
I initialise checksum to zero everytime before calculating it.
Also, the data types are of signed16 or short and few are of float values.
But the received buffer is declared as char type and all the values are stored as 8 bit values in recd_buf[0] to recd_buf[max_length-1].
from the microcontroller end, the checksum is calcualted in a similar way and the checksum value is stored in the last position ie., sent_buf[max_length-1].
and in the PC end, the checksum is calculated the same way,(as in my previous message),
and the calcualted checkum is compared with the value that was sent as the last member of the packet from microcontroller.
Does this info help you? Any ideas/ suggestions?
|
|
|
|
|
hey all,
Thanks all for ur help.
I could get my algo going.
1. I had the checksum declared as char-- but now changed it to unsigned char.
2. the next thing was:
I was comparing the checksum value with the last member of the received packet array (where the array was declared to be signed char)
I created a temporary unsigned char variable and copied the last member of the array (checksum from microcontroller) to it.
Then used this temporary variable for comparing with the checksum calculated in Pc.
It works perfect.
It was basically signed/unsigned datatype problem..
Thanks to all again for ur help.
|
|
|
|
|
Have you tried to have the message sent with length equal to max_length including the checksum?
if(the length of the message is not equal to max_length)
{
if(checksum generated to array[real_length-1])
wrong;
else // checksum generated to array[max_length-1]
{
wrong;
// before and after transmission, index from real_length to max_length-1 =
// unknown values
}
}
else
must be correct
|
|
|
|
|
Hello,
After switching to release mode, the ProcessShellCommand show me a messagebox that say "error to build a empty document" and the fonction return false. I do not understand because my application was running without any problem before and now I get this problem.
What can I try to solve my problem.
Thank you
AutreChien
|
|
|
|
|
Hi,
I tried pEdit->SetWindowText("/n"); but a junk character is displayed instead of going to new line .
Plz help.
thanx in advance
|
|
|
|
|
try "\r\n"
also make sure your edit control style is ES_MULTILINE
|
|
|
|
|
Yeah.
It worked.
Thanx once again.
|
|
|
|
|
See here[^] maybe it is some helpful to you
|
|
|
|
|
what functions does netshell.dll include?
what parameters do they have?
And, thanks.
|
|
|
|
|
DllCanUnloadNow
DllGetClassObject
DllRegisterServer
DllUnregisterServer
NcFreeNetconProperties
NcIsValidConnectionName
HrLaunchNetworkOptionalComponents
HrCreateDesktopIcon
HrLaunchConnection
HrRenameConnection
InvokeDunFile
DoInitialCleanup
NetSetupRequestWizardPages
NetSetupFinishInstall
NetSetupAddRasConnection
HrDetectLegacyNetCards
HrUninitLegacyNetCardDetection
HrOemUpgrade
HrGetAnswerFileParametersForNetCard
HrGetInstanceGuidOfPreNT5NetCardInstance
NetSetupSetProgressCallback
NetSetupInstallSoftware
Open netshell.dll with Dependency Software !
|
|
|
|
|
I just want to how to use them. And, the parameters.
|
|
|
|
|
this is example how to use func in dll :
<br />
# define LWA_COLORKEY 1<br />
# define LWA_ALPHA 2<br />
# define WS_EX_LAYERED 0x80000<br />
HWND hWnd=this->m_hWnd;<br />
typedef DWORD (WINAPI *PSLWA)(HWND, DWORD, BYTE, DWORD);<br />
PSLWA pSetLayeredWindowAttributes;<br />
HMODULE hDLL = LoadLibrary ("user32");<br />
pSetLayeredWindowAttributes = (PSLWA) GetProcAddress(hDLL,"SetLayeredWindowAttributes");<br />
For parameter of functions refer to MSDN
|
|
|
|
|
diat wrote: what functions does netshell.dll include?
what parameters do they have?
What do you need exactly?
|
|
|
|
|
afx_msg void OnSize(UINT nID, int intWidth, int intHeight);
This function to change the position of all items on a dialog. Can i call this function by another function to redraw the dialog? If not, does it have another method to re-posit all items?
Thx
Another Questions:
How to set Picture control from invisible to visible?
how to get the width and the heigth of a dialog?
-- modified at 0:13 Monday 14th August, 2006
|
|
|
|
|
(1)you want to use WM_SIZE for redraw a window
(2)See ShowWindow(SW_*)
(3)See GetWindowRect(...) and ScreenToClient
|
|
|
|
|
But how to call onSize function?
And also how to set the picture control to visible??
thx a lot
|
|
|
|
|
use SendMessage(...) this method send messages to window and see WM_SIZE nWidth=LOWORD and height=HIWORD
|
|
|
|
|
If you have handle to that window, use SendMessage()for sending message to that window. Which eventually calls OnSize on that window.
i.e.
SendMessage(hWnd,WM_SIZE,wParam,lParam);
|
|
|
|
|
In case the windows(Dialog Base)is minimize status.
What is the function to use to make the windows show in screen again.
Is it ShowWindow(SW_RESTORE)?
If so, my problem is after call this function the windows will can't minimize again.
What the code I have to write with this function ?
|
|
|
|
|
This is a part of my non-MFC program, but I think you can get the idea
if(hThisApp) {
if (IsIconic(hThisApp) )
ShowWindow(hThisApp,SW_RESTORE);
SetForegroundWindow(hThisApp);
}
|
|
|
|
|
I am displaying some of the version info in an 'about' box within my app. The problem is, after reading Chinese text from the version info it kinda screws up following calls to LoadString() . I have narrowed the problem down to a single call to VerQueryValue() . This function does as it should, it reads the string from the version info and returns it. But for some reason, When calling LoadString with a resource id of IDS_13 (8 Chinese characters Shown below), instead of returning the null terminated string, it fills the provided buffer with all the strings from IDS_14 and up. If LoadString is called with an id of higher than IDS_13 the app crashes.
LPSTR GetVersionInfo(LPCTSTR csEntry)
{
LPSTR csRet = NULL;
HRSRC hVersion = FindResource( hGlobLang,
MAKEINTRESOURCE(VS_VERSION_INFO), RT_VERSION );
if (hVersion != NULL)
{
HGLOBAL hGlobal = LoadResource( hGlobLang, hVersion );
if ( hGlobal != NULL)
{
LPVOID versionInfo = LockResource(hGlobal);
if (versionInfo != NULL)
{
DWORD vLen,langD;
BOOL retVal;
LPVOID retbuf=NULL;
char fileEntry[256];
sprintf(fileEntry,"\\VarFileInfo\\Translation");
retVal = VerQueryValue(versionInfo,fileEntry,&retbuf,(UINT *)&vLen);
if (retVal && vLen==4)
{
memcpy(&langD,retbuf,4);
sprintf(fileEntry, "\\StringFileInfo\\%02X%02X%02X%02X\\%s",
(langD & 0xff00)>>8,langD & 0xff,(langD & 0xff000000)>>24,
(langD & 0xff0000)>>16, csEntry);
}
else
sprintf(fileEntry, "\\StringFileInfo\\%04X04B0\\%s",GetUserDefaultLangID(), csEntry);
if (VerQueryValue(versionInfo,fileEntry,&retbuf,(UINT *)&vLen))
csRet = (char*)retbuf;
}
}
UnlockResource( hGlobal );
FreeResource( hGlobal );
}
return csRet;
}
BOOL CALLBACK AboutProc(HWND hwnd, UINT Message, WPARAM wParam, LPARAM lParam)
{
static char Version[20],Date[40];
if (Message == WM_INITDIALOG)
{
char *tmp = LStr(IDS_14);
tmp = GetVersionInfo("SpecialBuild");
tmp = LStr(IDS_14);
STRINGTABLE DISCARDABLE
BEGIN
IDS_01 "ÃÜÂë´íÎó"
IDS_02 "´íÎóÓû§Ãû"
IDS_03 "Unkown Pending command"
IDS_04 "´ò¿ª"
IDS_05 "Excel Îĵµ (*.xls)\0*.xls\0\0"
IDS_06 "ѧÉúÊý¾Ý (*.sd)\0*.sd\0ËùÓÐÎĵµ (*.*)\0*.*\0\0"
IDS_07 "ѧÉúÊý¾Ý (*.sd)\0*.sd\0Excel Îĵµ (*.xls)\0*.xls\0ËùÓÐÎĵµ (*.*)\0*.*\0\0"
IDS_08 "ѧÉúÊý¾Ý¿â (*.sd)\0*.sd\0"
IDS_09 "¾¯¸æ"
IDS_10 "ÄãÏë±£´æÒѾÐ޸ĵÄÉèÖÃÂð?"
IDS_11 "ID ´íÎó'input_comment'"
END
STRINGTABLE DISCARDABLE
BEGIN
IDS_12 "ûÓпÉÓõļͼ"
IDS_13 "ÎÞ·¨»ñµÃѧÉú¼Í¼"
IDS_14 "ÎÞ·¨ÏÂÔØ 'Rich Edit' ¿ØÖÆ!"
IDS_15 "ÕýÔÚ×¼±¸..."
|
|
|
|