本文整理汇总了C++中file::readUInt8方法的典型用法代码示例。如果您正苦于以下问题:C++ file::readUInt8方法的具体用法?C++ file::readUInt8怎么用?C++ file::readUInt8使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类file
的用法示例。
在下文中一共展示了file::readUInt8方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: OnReceiveMessage
//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);
}
}