>
> *Well, you're certainly right that the callback is messing*
> * things up. If I assume the same callback, then the callback is*
> * certainly changing data. If you can set the right breakpoint, you can*
> * tag the situation *if* the breakpoint also knows that the process is*
> * reading from the CAN bus.*
>
> * Had you considered disabling that callback function until the read*
> * from the CANbus is finished? Would it be practical? That's where the*
> * semaphore might help a lot.*
>
> * what variables could be common between the two routines?*
>
> * Harvey*
>
Well this is where previous experience fails me. I've pretty much avoided
code related to threading in software. In the past. I do know of fork() and
roughly what it is capable of, and I know about threads, but not to
implement them in C on Linux. Or what can be done with them. Lets talk code
a minute.
*IPC - Server - Reads from canbus*
int main(){
struct can_frame frame;
int sock = InitializeCAN("vcan0");
statistics_t *stats = NULL;
const long shm_size = sysconf(_SC_PAGESIZE);
int shm_fd = shm_open("acme", O_CREAT | O_RDWR, FILE_PERMS);
if(shm_fd == -1)
HandleError(strerror(errno));
const int retval = ftruncate(shm_fd, shm_size);
if(retval == -1)
HandleError(strerror(errno));
shared_memory = InitializeShm(shm_size * sizeof(char), shm_fd);
close(shm_fd);
while(1){
frame = ReadFrame(sock);
if(frame.can_dlc == FRAME_DLC)
stats = ProcessFastpacket(frame);
if(stats != NULL){
WriteToShm(shared_memory, stats);
stats = NULL;
printf("%s", ReadFromShm(shared_memory));
}
}
}/* main() */
*IPC - Client / webserver*
int main(void) {
struct mg_server *server = mg_create_server(NULL, ev_handler);
mg_set_option(server, "listening_port", "8000");
mg_set_option(server, "document_root", "./web");
printf("Started on port %s\n", mg_get_option(server,
"listening_port"));
// POSIX IPC - shared memory
const long shm_size = sysconf(_SC_PAGESIZE);
int shm_fd = shm_open("file", O_CREAT | O_RDWR, FILE_PERMS);
if(shm_fd == -1)
HandleError(strerror(errno));
const int retval = ftruncate(shm_fd, shm_size);
if(retval == -1)
HandleError(strerror(errno));
shared_memory = InitializeShm(shm_size * sizeof(char), shm_fd);
close(shm_fd);
char id = 0x00;
for (;;) {
mg_poll_server(server, 10);
if(shared_memory->sdata.data[19] != id){
push_message(server, shared_memory->sdata.data);
id = shared_memory->sdata.data[19];
}
}
mg_destroy_server(&server);
return 0;
}
In the context of whats interesting where threading is concerned. The loops
in each executable here might be useful. If somehow each, or even just the
for loop in the IPC client could somehow use objects in memory from the IPC
server. That is let us suppose for a minute IPC was removed entirely, then
somehow I could turn off the callback in the IPC client. This is what I'm
having a problem imagining. How could this be done ? In the context of
libmongoose I'm not sure. In the context of threading or using fork() I'm
also not sure. But if I could somehow through using threading context to
disable the callback I think that would be ideal. That way I could simply
disable that whole thread for a fraction of a second, and then resume it
once a fastpacket is constructed.
Anyway, a little information that might be needed. socketCAN reads data in
8 byte lengths for each frame..fastpackets are several frames in length,
and with the only current one I'm tracking being 11 frames long. Or 88
total bytes, not discounting the initial char from each frame which is a
sequence number. If there is a way, and I'm sure there is, I am all for
changing from an IPC model to a threaded model. But I still have some
doubts. Such as will it be fast enough to track multiple fastpackets a
second ? Past that how complex will it be ?
I have given multiple approaches consideration, just having a hard time
imaging how to work this out using a threading model.
--
For more options, visit http://beagleboard.org/discuss
---
You received this message because you are subscribed to the Google Groups
"BeagleBoard" group.
To unsubscribe from this group and stop receiving emails from it, send an email
to [email protected].
For more options, visit https://groups.google.com/d/optout.