//This function is called when a capture is stopped
//"block" holds an object representing the current script block on the flowchart
void OnStopCapture(ScriptBlock block)
{
    if (bFileOpen == true) {
        handle.close();
    }
 
    //block.ClearOutputText(); //Clear this scripts output window
    block.PrintOutputText("Binary file write stopped\n", false, false, false, false); //Print to the output window
}
Example #2
0
void file::pipe(file &read_end, file &write_end) {
  // Close the descriptors first to make sure that assignments don't throw
  // and there are no leaks.
  read_end.close();
  write_end.close();
  int fds[2] = {};
#ifdef _WIN32
  // Make the default pipe capacity same as on Linux 2.6.11+.
  enum { DEFAULT_CAPACITY = 65536 };
  int result = FMT_POSIX_CALL(pipe(fds, DEFAULT_CAPACITY, _O_BINARY));
#else
  // Don't retry as the pipe function doesn't return EINTR.
  // http://pubs.opengroup.org/onlinepubs/009696799/functions/pipe.html
  int result = FMT_POSIX_CALL(pipe(fds));
#endif
  if (result != 0)
    FMT_THROW(system_error(errno, "cannot create pipe"));
  // The following assignments don't throw because read_fd and write_fd
  // are closed.
  read_end = file(fds[0]);
  write_end = file(fds[1]);
}
//This function is called everytime a message is received on an input port
//"inPort" will hold the port the message was received by (1, 2, or 3)
//"block" holds an object representing the current script block on the flowchart
//"msg" holds an object representing the message received
//type "block." or "msg." to see a list of available parameters and functions
void OnReceiveMessage(uint8 inPort, ScriptBlock block, Message &msg)
{
    if (!bFileOpen) {
        return;
    }
 
    //Here we pretend that we get some sort of ACK or response from the embedded device that indicates that
    //it is ready to receive the next packet of data containing the firmware image.  Most reprogramming/flash
    //protocols has some sort of similar indicator meaing something to the effect of "read for data".
    //For testing, you can simply use a 29-bit transmitter that sends a packet with ID=1234 at a repeating
    //interval
    if (msg.GetID() == 1234) {
 
        //Prep our data payload packet that will be sent to the embedded device
        Message dataMsg;
        dataMsg.SetID(12345);       
        dataMsg.Set11Bit(0);          //I am assuming its 29-bit CAN messages       
 
        block.PrintOutputText("Sending CAN packet ID=" + dataMsg.GetID() + " with data:", false, false, true, false);
        //Read up to 8 bytes of data from the firmware image to fill the next packet of CAN data   
        int i = 0;
        for (i = 0; i < 8; ++i) {
            if (handle.isEOF()) {   //Check for end of file
                block.PrintOutputText("\nEnd of file reached", false, false, false, true);  //print a message indicating the data
                handle.close();        //Close file and release flag that indicates its open
                bFileOpen = false;
                break;
            }
            uint8 dataByte = handle.readUInt8();  //read a single byte of data from the file
            block.PrintOutputText(" " + dataByte, false, false, true, false);  //print a message indicating the data
            dataMsg.SetData(i, dataByte);  //and store the byte from the file directly into our CAN packet structure       
        }
        block.PrintOutputText("\n", false, false, true, false);
 
        dataMsg.SetDataLength(i);  //set the length to the number of bytes read from the file
 
        //And finally send the data packet
        block.SendMessage(1, dataMsg);               
    }
}