-
Notifications
You must be signed in to change notification settings - Fork 56
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Array of Struct #52
Comments
What you're getting as a result? Can you put the code and sample file together in some repo I could take a look at? |
@RReverser Thank for the quick reply! I appreciate it. The code is as above but as requested I put it in the a repo along with the binary file and its C header. I get no results and no errors. |
First mistake - I see that C version defines var TIME_T = {
hour: 'int16',
min: 'int8',
type: 'int8'
};
var DATE_T = {
day: 'int8',
month: 'int8',
year: 'int16'
}; Second - if I understand correctly, in C, you're reading structures by simply mapping them onto the memory region. The problem that happens is that in C, structures are automatically aligned (not LOG_T: {
time: 'TIME_T', // time of log
date: 'DATE_T', // date of log
temp: 'float', // chamber temperature
tempSp: 'float', // temperature set point
tmpRamp: 'float', // temperature ramp
hum: 'float', // chamber humidity
humSp: 'float', // humidity set point
light: 'uint8', // chamber light
fan: 'uint8', // chamber fan
_align1: ['skip', 2], // simulating C alignment
tmpMax: 'float', // maximum temperature allowed
tmpMin: 'float', // minimum temperature allowed
humMax: 'float', // maximum humidity allowed
humMin: 'float', // minimum humidity allowed
roomTemp: 'uint8', // room temperature
_align2: ['skip', 1], // simulating C alignment
alarmStatus: 'uint16' // alarm status (refer to alarm mask defines)
} Finally, looks like you're assuming little-endian byte order (most common on x86 CPUs). If so, you need to add With these fixes, everything should work fine. I played a bit with your code and you can find version with those modifications here: https://gist.github.com/RReverser/bf31bfd30a09362c95a78894a73d359b Good luck! :) |
Thanks for taking your time and this complete answer. I did not know about the concepts you mentioned above. Your code works as expected. May I ask what is the program in the screenshot, that indicated the alignments as warnings? How did you find them? |
Sure. I wrote above:
So you can just pass this as an argument to |
Hi,
I am new to jBinary and have not used it before. Sorry if this issue is more like a question than a real issue or bug, but I really could not figure it out from the wiki documents.
I have an array of a struct in a file, the below code does not work. Am I using jBinary incorrectly? Maybe someone can correct me or point me to an example?.
For reading it as an array, the below code does not do the job:
or maybe I should define another type, which does not work too:
Thanks
The text was updated successfully, but these errors were encountered: