Last active
January 9, 2019 08:15
-
-
Save verybadsoldier/049597bd2251a330574fef1a4a6da2dd to your computer and use it in GitHub Desktop.
HM-MOD-UART-RPI latency test
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include <iostream> | |
#include <errno.h> | |
#include <sys/types.h> | |
#include <sys/stat.h> | |
#include <fcntl.h> | |
#include <stdexcept> | |
#include <string.h> | |
#include <unistd.h> | |
#include <sys/time.h> | |
#include <sys/types.h> | |
#include <unistd.h> | |
#include <chrono> | |
using namespace std; | |
int main(int argc, char *argv[]) { | |
if (argc != 2) { | |
std::cout << "not enough parameters" << std::endl; | |
} | |
const unsigned char reqCredits[] = {0xfd, 0x00, 0x03, 0x00, 0x50, 0x08, 0xf8, 0x36}; | |
const std::string iface = argv[1]; | |
int fd = open(iface.c_str(), O_RDWR); | |
if (fd < 0) | |
throw std::runtime_error( | |
std::string("Could not open device: ") + iface); | |
srand (time(NULL)); | |
// close(fd); | |
// return 0; | |
unsigned long writeCount = 0; | |
std::cout << "Starting..." << std::endl; | |
char buffer[256]; | |
while (true) { | |
int sl = 1500 + (rand() % 2000); | |
sl *= 1000; | |
usleep(sl); | |
auto start = std::chrono::system_clock::now(); | |
int writeRc = write(fd, reqCredits, sizeof(reqCredits)); | |
int readCount = read(fd, buffer, 256); | |
auto end = std::chrono::system_clock::now(); | |
auto elapsed = std::chrono::duration_cast<std::chrono::milliseconds>(end - start); | |
std::cout << "Slept: " << sl / 1000000.0f << " s \t\tRRT: " << elapsed.count() << std::endl; | |
} | |
return 0; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment