static void* thread_proc(void* param) { int robot_n = (int) param; for (;;) { long long start = microseconds(); long long count = 0; while (microseconds() - start < 1000000) { long long iterations = 10000; for (int i = 0; i < iterations; ++i) { while (__atomic_load_n(¤t, __ATOMIC_SEQ_CST) != robot_n * 2) { #ifdef USE_PAUSE _mm_pause(); #endif } __atomic_store_n(¤t, robot_n * 2 + 1, __ATOMIC_SEQ_CST); //printf("%d\n", robot_n); __atomic_store_n(¤t, (robot_n + 1) % thread_count * 2, __ATOMIC_SEQ_CST); } count += iterations; } if (robot_n == 0) { long long dns = 1000ll * (microseconds() - start); long long ns_per_call = dns / count; printf("%lld ns per step\n", ns_per_call); } } }
static void init(void) { FILE *f; int s; long long tb0; long long us0; long long tb1; long long us1; f = fopen("/proc/cpuinfo","r"); if (!f) return 0; for (;;) { s = fscanf(f," clock : %lf MHz",&cpufrequency); if (s > 0) break; if (s == 0) s = fscanf(f,"%*[^\n]\n"); if (s < 0) { cpufrequency = 0; break; } } fclose(f); if (!cpufrequency) return; cpufrequency *= 1000000.0; tb0 = timebase(); us0 = microseconds(); do { tb1 = timebase(); us1 = microseconds(); } while (us1 - us0 < 10000); if (tb1 <= tb0) return; tb1 -= tb0; us1 -= us0; tbcycles = myround((cpufrequency * 0.000001 * (double) us1) / (double) tb1); }
static void* thread_proc(void* param) { bool left = (bool) param; for (;;) { long long start = microseconds(); long long count = 0; while (microseconds() - start < 1000000) { long long iterations = 1000; for (int i = 0; i < iterations; ++i) { if (syscall(SYS_futex, ¤t, FUTEX_WAIT, !left, NULL, NULL, 0) < 0) { if (errno != EWOULDBLOCK) { perror("SYS_futex"); abort(); } } current = !left; E(syscall(SYS_futex, ¤t, FUTEX_WAKE, 1, NULL, NULL, 0) < 0); //printf("%d\n", left); } count += iterations; } if (left) { long long dns = 1000LL * (microseconds() - start); long long ns_per_call = dns / count; printf("%lld ns per step\n", ns_per_call); } } return NULL; }
// Send Modbus packet int send_modbus_packet(uint8_t device_address, uint8_t sequence_number, Packet* packet_to_send) { int bytes_written = 0; uint16_t packet_crc16 = 0; uint8_t crc16_first_byte_index = 0; int packet_size = packet_to_send->header.length + MODBUS_PACKET_OVERHEAD; uint8_t modbus_packet[packet_size]; //printf(">>>>>>>>>>>>>>>>>>>>> SEN %llu\n", microseconds()); // Assemble Modbus packet header modbus_packet[0] = device_address; modbus_packet[1] = RS485_EXTENSION_MODBUS_FUNCTION_CODE; modbus_packet[2] = sequence_number; // Assemble Tinkerforge packet header memcpy(&modbus_packet[3], &packet_to_send->header, sizeof(PacketHeader)); // Assemble Tinkerforge packet payload (if any) memcpy(&modbus_packet[3+sizeof(PacketHeader)], &packet_to_send->payload, packet_to_send->header.length - TINKERFORGE_HEADER_LENGTH); // Calculating CRC16 packet_crc16 = crc16(modbus_packet, packet_to_send->header.length + MODBUS_PACKET_HEADER_LENGTH); // Assemble the calculated CRC16 to the Modbus packet crc16_first_byte_index = packet_to_send->header.length + MODBUS_PACKET_HEADER_LENGTH; modbus_packet[crc16_first_byte_index] = packet_crc16 >> 8; modbus_packet[++crc16_first_byte_index] = packet_crc16 & 0x00FF; // Enabling TX start = microseconds(); gpio_output_set(_tx_pin); // Sending packet bytes_written = write(_rs485_serial_fd, modbus_packet, sizeof(modbus_packet)); if (bytes_written <= 0) { // Disabling TX gpio_output_clear(_tx_pin); end = microseconds(); send_verify_flag = 0; log_error("RS485: Error sending packet through serial interface"); return -1; } // Save the packet as byte array memcpy(current_request_as_byte_array, modbus_packet, packet_size); // Start the send verify timer setup_timer(&send_verify_timer, TIME_UNIT_NSEC, SEND_VERIFY_TIMEOUT); timerfd_settime(_send_verify_event, 0, &send_verify_timer, NULL); // Set send verify flag send_verify_flag = 1; log_debug("RS485: Packet sent through serial interface"); return bytes_written; }
bool TransportInfo::initWithSocket(const AsyncSocket* sock) { #if defined(__linux__) || defined(__FreeBSD__) if (!TransportInfo::readTcpInfo(&tcpinfo, sock)) { tcpinfoErrno = errno; return false; } rtt = microseconds(tcpinfo.tcpi_rtt); /* The ratio of packet retransmission (rtx) is a good indicator of network * bandwidth condition. Unfortunately, the number of segmentOut is not * available in current tcpinfo. To workaround this limitation, totalBytes * and MSS are used to estimate it. */ #if __GLIBC__ >= 2 && __GLIBC_MINOR__ >= 17 if (tcpinfo.tcpi_total_retrans == 0) { rtx = 0; } else if (tcpinfo.tcpi_total_retrans > 0 && tcpinfo.tcpi_snd_mss > 0 && totalBytes > 0) { // numSegmentOut is the underestimation of the number of tcp packets sent double numSegmentOut = double(totalBytes) / tcpinfo.tcpi_snd_mss; // so rtx is the overestimation of actual packet retransmission rate rtx = tcpinfo.tcpi_total_retrans / numSegmentOut; } else { rtx = -1; } #else rtx = -1; #endif // __GLIBC__ >= 2 && __GLIBC_MINOR__ >= 17 validTcpinfo = true; #else tcpinfoErrno = EINVAL; rtt = microseconds(-1); rtx = -1; #endif return true; }
void process_clock::now( process_times & times_, system::error_code & ec ) { tms tm; clock_t c = ::times( &tm ); if ( c == clock_t(-1) ) // error { if (BOOST_CHRONO_IS_THROWS(ec)) { boost::throw_exception( system::system_error( errno, BOOST_CHRONO_SYSTEM_CATEGORY, "chrono::process_clock" )); } else { ec.assign( errno, BOOST_CHRONO_SYSTEM_CATEGORY ); times_.real = times_.system = times_.user = nanoseconds(-1); } } else { times_.real = microseconds(c); times_.system = microseconds(tm.tms_stime + tm.tms_cstime); times_.user = microseconds(tm.tms_utime + tm.tms_cutime); if ( chrono_detail::tick_factor() != -1 ) { if (!BOOST_CHRONO_IS_THROWS(ec)) { ec.clear(); } times_.real *= chrono_detail::tick_factor(); times_.user *= chrono_detail::tick_factor(); times_.system *= chrono_detail::tick_factor(); } else { if (BOOST_CHRONO_IS_THROWS(ec)) { boost::throw_exception( system::system_error( errno, BOOST_CHRONO_SYSTEM_CATEGORY, "chrono::process_clock" )); } else { ec.assign( errno, BOOST_CHRONO_SYSTEM_CATEGORY ); times_.real = times_.user = times_.system = nanoseconds(-1); } } } }
void handleStepScene(const NaClAMMessage& message) { if (scene.dynamicsWorld == NULL || scene.dynamicsWorld->getNumCollisionObjects() == 1) { // No scene, just send a reply Json::Value root = NaClAMMakeReplyObject("noscene", message.requestId); NaClAMSendMessage(root, NULL, 0); return; } { Json::Value rayTo = message.headerRoot["args"]["rayTo"]; float x = rayTo[0].asFloat(); float y = rayTo[1].asFloat(); float z = rayTo[2].asFloat(); Json::Value rayFrom = message.headerRoot["args"]["rayFrom"]; float cx = rayFrom[0].asFloat(); float cy = rayFrom[1].asFloat(); float cz = rayFrom[2].asFloat(); scene.movePickingConstraint(btVector3(cx, cy, cz), btVector3(x,y,z)); } uint64_t start = microseconds(); // Do work scene.Step(); uint64_t end = microseconds(); uint64_t delta = end-start; { // Build headers Json::Value root = NaClAMMakeReplyObject("sceneupdate", message.requestId); root["simtime"] = Json::Value(delta); // Build transform frame int numObjects = scene.dynamicsWorld->getNumCollisionObjects(); uint32_t TransformSize = (numObjects-1)*4*4*sizeof(float); PP_Var Transform = moduleInterfaces.varArrayBuffer->Create(TransformSize); float* m = (float*)moduleInterfaces.varArrayBuffer->Map(Transform); for (int i = 1; i < numObjects; i++) { btCollisionObject* obj = scene.dynamicsWorld->getCollisionObjectArray()[i]; btRigidBody* body = btRigidBody::upcast(obj); if (body && body->getMotionState()) { btTransform xform; body->getMotionState()->getWorldTransform(xform); xform.getOpenGLMatrix(&m[0]); } m += 16; } moduleInterfaces.varArrayBuffer->Unmap(Transform); // Send message NaClAMSendMessage(root, &Transform, 1); moduleInterfaces.var->Release(Transform); } }
void end(sliptag tag) { if(!enabled) return; LARGE_INTEGER end; QueryPerformanceCounter(&end); activetag top = tagstack.top(); assert( top.tag == tag ); tagstack.pop(); calltree *tree = treeposition.top(); LARGE_INTEGER idelta; idelta.QuadPart = end.QuadPart - top.start.QuadPart; double time = microseconds(idelta); if( !firstupdate ) { tree->info.addtime( idelta, time ); info[tag].addtime(idelta, time); } poptree(); }
static void handleReply(redisAsyncContext *context, void *_reply, void *privdata) { REDIS_NOTUSED(privdata); redisReply *reply = (redisReply*)_reply; client c = (client)context->data; long long latency = (microseconds() - c->start) / 1000; if (reply == NULL && context->err) { fprintf(stderr,"Error: %s\n", context->errstr); exit(1); } else { assert(reply != NULL); if (reply->type == REDIS_REPLY_ERROR) { fprintf(stderr,"Error: %s\n", reply->str); exit(1); } } if (latency > MAX_LATENCY) latency = MAX_LATENCY; config.latency[latency]++; if (config.check) checkDataIntegrity(c,reply); freeReplyObject(reply); if (config.done || config.ctrlc) { redisAsyncDisconnect(c->context); return; } if (config.keepalive) { issueRequest(c); } else { /* createMissingClients will be called in the disconnection callback */ redisAsyncDisconnect(c->context); } }
Time Time::now() { auto now = std::chrono::high_resolution_clock::now().time_since_epoch(); return microseconds( std::chrono::duration_cast<std::chrono::microseconds>(now).count()); }
Decoder::Decoder(function<void(Codeword)> codewordHandler) : lasttime(microseconds(0)), receiving(false), position(0), codewordHandler(codewordHandler) { }
/* Check for elapsed timeouts * t is the time an event was marked as occurred; * tout is the configured timeout */ int elapsed (struct timeval * t, struct timeval * tout) { struct timeval now; gettimeofday (& now, NULL); return delta_time_in_microseconds (& now, t) >= microseconds (tout); }
static double guesstbcycles(void) { long long tb0; long long us0; long long tb1; long long us1; tb0 = timebase(); us0 = microseconds(); do { tb1 = timebase(); us1 = microseconds(); } while (us1 - us0 < 10000 || tb1 - tb0 < 1000); if (tb1 <= tb0) return 0; tb1 -= tb0; us1 -= us0; return (cpufrequency * 0.000001 * (double) us1) / (double) tb1; }
void report() { std::map<sliptag, std::string> names; for( std::map<std::string, sliptag>::const_iterator it = tagnames.begin(); it != tagnames.end(); ++it) { const std::string& name = (*it).first; sliptag tag = (*it).second; names[tag] = name; double time = microseconds(info[tag].time); char str[1024]; sprintf_s(str, 1024, "%s (id: %d): took %fms for %d calls (%fms avg, %fms min, %fms max)\n", name.c_str(), tag, info[tag].totaltime / 1000.0, info[tag].totalcount, info[tag].totaltime / 1000.0 / info[tag].totalcount, info[tag].totalmintime / 1000.0, info[tag].totalmaxtime / 1000.0); OutputDebugStringA(str); } OutputDebugStringA("\ntree calls\n\n"); treereport( tree, names ); }
inline long long display(const char* name, std::vector<long long>& timings) { long long min, max, avg, med, dev; statistics(timings, min, max, avg, med, dev); // Get statistics from timings std::fstream file; file.open((std::string(name)+".csv").c_str(), std::fstream::out | std::fstream::app); if (file) { #if !defined(_MSC_VER) || _MSC_VER >= 1600 // This will convert timings into cycles per iteration std::transform( timings.begin(), timings.end(), std::ostream_iterator<long long>(file, ", "), [](long long t) { return cycles(t)/N; } ); #endif file << "End" << std::endl; } file.close(); std::cout << name << " Time: [" << std::setw(4) << microseconds(min) << " --" << std::setw(5) << microseconds(avg) << "/" << std::setw(4) << microseconds(med) << " --" << std::setw(5) << microseconds(max) << "] Dev = " << std::setw(4) << microseconds(dev) #if defined(XTL_TIMING_METHOD_1) || defined(XTL_TIMING_METHOD_2) << " Cycles/iteration: [" << std::setw(4) << cycles(min)/N << " --" << std::setw(5) << cycles(avg)/N << "/" << std::setw(4) << cycles(med)/N << " --" << std::setw(5) << cycles(max)/N << "]" #endif << std::endl; return med; }
bool TransportInfo::initWithSocket(const TAsyncSocket* sock) { #ifndef __APPLE__ if (!TransportInfo::readTcpInfo(&tcpinfo, sock)) { tcpinfoErrno = errno; return false; } rtt = microseconds(tcpinfo.tcpi_rtt); #endif validTcpinfo = true; return true; }
TSVolatility::TSVolatility( Prices& series, time_duration dtTau, time_duration dtTauPrime, double p, unsigned int n ) : m_seriesSource( series ), m_dtTau( dtTau ), m_dtTauByTwo( microseconds( dtTau.total_microseconds() / 2 ) ), // m_dtTauPrime( microseconds( dtTauPrime.total_microseconds() / 2 ) ), m_dtTauPrime( dtTauPrime ), m_p( p ), m_n( n ), m_tsDif( series, dtTauPrime ), m_tsNorm( m_tsDif, m_dtTauByTwo, n, p ) { }
fpga_event::poll_result fpga_event::poll(int timeout_msec) { struct epoll_event events[1]; if (epollfd_ == -1) { return poll_result::error; } if (cancel_) return poll_result::canceled; int num_events = 0; auto begin = high_resolution_clock::now(); bool timedout = false; int fd = -1; while(!cancel_ && !timedout && num_events == 0) { num_events = epoll_wait(epollfd_, events, 1, 0); if (timeout_msec > 0) { timedout = high_resolution_clock::now() - begin > milliseconds(timeout_msec) && num_events == 0; } if (!timedout) { std::this_thread::sleep_for(microseconds(100)); } } if (cancel_) return poll_result::canceled; if (timedout) { return poll_result::timeout; } if (num_events < 0) { return errno == EINTR ? poll_result::canceled : poll_result::error; } if(fpgaGetOSObjectFromEventHandle(handle_, &fd) != 0) { return poll_result::error; } if (num_events == 1 && events[0].data.fd == fd) { return poll_result::triggered; } return poll_result::unknown; }
namespace PT22x2 { static constexpr microseconds pulsewidth_short = microseconds(322); static constexpr microseconds pulsewidth_long = microseconds(967); static constexpr microseconds pulsewidth_sync = microseconds(9995); static constexpr microseconds pulsewidth_tolerance = microseconds(200); static constexpr unsigned int codeword_length = 12; enum class Pulse { Short, Long }; enum class CodeBit { Zero, One, Floating }; typedef array<Pulse, 4*codeword_length> CodewordPulses; typedef array<CodeBit, codeword_length> Codeword; class Decoder { private: microseconds lasttime; bool receiving; unsigned int position; CodewordPulses pulses; function<void(Codeword)> codewordHandler; Codeword codewordFromPulses(CodewordPulses pulses); public: Decoder(function<void(Codeword)> codewordHandler); void edgeOccured(microseconds time); }; class Encoder { private: GPIOPin pin; CodewordPulses pulsesFromCodeword(Codeword codeword); public: Encoder(GPIOPin pin); void send(Codeword codeword); }; }
Time ClockWin32::getCurrentTime() { HANDLE currentThread = GetCurrentThread(); DWORD_PTR previousMask = SetThreadAffinityMask(currentThread, 1); static LARGE_INTEGER freq; QueryPerformanceFrequency(&freq); LARGE_INTEGER time; QueryPerformanceCounter(&time); SetThreadAffinityMask(currentThread, previousMask); return microseconds(1000000 * time.QuadPart / freq.QuadPart); }
process_real_cpu_clock::time_point process_real_cpu_clock::now( system::error_code & ec) { tms tm; clock_t c = ::times( &tm ); if ( c == clock_t(-1) ) // error { if (BOOST_CHRONO_IS_THROWS(ec)) { boost::throw_exception( system::system_error( errno, BOOST_CHRONO_SYSTEM_CATEGORY, "chrono::process_real_cpu_clock" )); } else { ec.assign( errno, BOOST_CHRONO_SYSTEM_CATEGORY ); return time_point(); } } else { if ( chrono_detail::tick_factor() != -1 ) { if (!BOOST_CHRONO_IS_THROWS(ec)) { ec.clear(); } return time_point( microseconds(c)*chrono_detail::tick_factor()); } else { if (BOOST_CHRONO_IS_THROWS(ec)) { boost::throw_exception( system::system_error( errno, BOOST_CHRONO_SYSTEM_CATEGORY, "chrono::process_real_cpu_clock" )); } else { ec.assign( errno, BOOST_CHRONO_SYSTEM_CATEGORY ); return time_point(); } } } }
int main(int argc, char** argv) { pthread_mutex_t mutex = PTHREAD_MUTEX_INITIALIZER; pthread_cond_t cond = PTHREAD_COND_INITIALIZER; for (;;) { long long start = microseconds(); long long count = 0; while (microseconds() - start < 1000000) { for (int i = 0; i < 1000000; ++i) { if (pthread_mutex_lock(&mutex) < 0) perror("pthread_mutex_lock"); if (pthread_cond_signal(&cond) < 0) perror("pthread_cond_signal"); if (pthread_mutex_unlock(&mutex) < 0) perror("pthread_mutex_unlock"); } count += 1000000; } long long dns = 1000L * (microseconds() - start); long long ns_per_call = dns / count; printf("%lld ns per lock/signal/unlock\n", ns_per_call); } return 0; }
int main(void) { IPConnection ipcon; Master master; int i; int repeats = 10000; uint16_t voltage; uint64_t start, stop; #ifdef _WIN32 fixes_init(); #endif ipcon_create(&ipcon); master_create(&master, "6wwv71", &ipcon); if (ipcon_connect(&ipcon, "localhost", 4223) < 0) { printf("error 1\n"); return EXIT_FAILURE; } start = microseconds(); for (i = 0; i < repeats; ++i) { if (master_get_usb_voltage(&master, &voltage) < 0) { return EXIT_FAILURE; } //printf("%u\n", voltage); } stop = microseconds(); printf("%.10f msec\n", ((stop - start) / 1000.0) / repeats); ipcon_destroy(&ipcon); return EXIT_SUCCESS; }
static void init(void) { FILE *f; long long tb0; long long us0; long long tb1; long long us1; f = popen("/usr/sbin/lsattr -E -l proc0 -a frequency","r"); if (!f) return; if (fscanf(f,"frequency %lf",&cpufrequency) < 1) cpufrequency = 0; pclose(f); if (!cpufrequency) return; tb0 = timebase(); us0 = microseconds(); do { tb1 = timebase(); us1 = microseconds(); } while (us1 - us0 < 10000); if (tb1 <= tb0) return; tb1 -= tb0; us1 -= us0; tbcycles = myround((cpufrequency * 0.000001 * (double) us1) / (double) tb1); }
static void issueRequest(client c) { int op = config.optab[random() % 100]; long key, hashkey; unsigned long datalen; config.issued_requests++; if (config.issued_requests == config.num_requests) config.done = 1; c->start = microseconds(); if (config.longtail) { key = longtailprng(0,config.keyspace-1,config.longtail_order); hashkey = longtailprng(0,config.hashkeyspace-1,config.longtail_order); } else { key = random() % config.keyspace; hashkey = random() % config.hashkeyspace; } c->keyid = key; c->reqtype = op; if (op == REDIS_IDLE) { /* Idle */ } else if (op == REDIS_SET) { datalen = randomData(key); redisAsyncCommand(c->context,handleReply,NULL,"SET string:%ld %b",key,config.databuf,datalen); } else if (op == REDIS_GET) { redisAsyncCommand(c->context,handleReply,NULL,"GET string:%ld",key); } else if (op == REDIS_DEL) { redisAsyncCommand(c->context,handleReply,NULL,"DEL string:%ld list:%ld hash:%ld",key,key,key); } else if (op == REDIS_LPUSH) { datalen = randomData(key); redisAsyncCommand(c->context,handleReply,NULL,"LPUSH list:%ld %b",key,config.databuf,datalen); } else if (op == REDIS_LPOP) { redisAsyncCommand(c->context,handleReply,NULL,"LPOP list:%ld",key); } else if (op == REDIS_HSET) { datalen = randomData(key); redisAsyncCommand(c->context,handleReply,NULL,"HSET hash:%ld key:%ld %b",key,hashkey,config.databuf,datalen); } else if (op == REDIS_HGET) { redisAsyncCommand(c->context,handleReply,NULL,"HGET hash:%ld key:%ld",key,hashkey); } else if (op == REDIS_HGETALL) { redisAsyncCommand(c->context,handleReply,NULL,"HGETALL hash:%ld",key); } else if (op == REDIS_SWAPIN) { /* Only accepts a single argument, so for now only works with string keys. */ redisAsyncCommand(c->context,handleReply,NULL,"DEBUG SWAPIN string:%ld",key); } else { assert(NULL); } }
void network_client_expects_response(Client *client, Packet *request) { PendingRequest *pending_request; char packet_signature[PACKET_MAX_SIGNATURE_LENGTH]; if (client->pending_request_count >= CLIENT_MAX_PENDING_REQUESTS) { log_warn("Pending requests list for client ("CLIENT_SIGNATURE_FORMAT") is full, dropping %d pending request(s)", client_expand_signature(client), client->pending_request_count - CLIENT_MAX_PENDING_REQUESTS + 1); while (client->pending_request_count >= CLIENT_MAX_PENDING_REQUESTS) { pending_request = containerof(client->pending_request_sentinel.next, PendingRequest, client_node); pending_request_remove_and_free(pending_request); } } pending_request = calloc(1, sizeof(PendingRequest)); if (pending_request == NULL) { log_error("Could not allocate pending request: %s (%d)", get_errno_name(ENOMEM), ENOMEM); return; } node_reset(&pending_request->global_node); node_insert_before(&_pending_request_sentinel, &pending_request->global_node); node_reset(&pending_request->client_node); node_insert_before(&client->pending_request_sentinel, &pending_request->client_node); ++client->pending_request_count; pending_request->client = client; pending_request->zombie = NULL; memcpy(&pending_request->header, &request->header, sizeof(PacketHeader)); #ifdef BRICKD_WITH_PROFILING pending_request->arrival_time = microseconds(); #endif log_packet_debug("Added pending request (%s) for client ("CLIENT_SIGNATURE_FORMAT")", packet_get_request_signature(packet_signature, request), client_expand_signature(client)); }
void checkpoint() { double ms = microseconds(time); totaltime += ms; if(mintime < totalmintime) totalmintime = mintime; if(maxtime > totalmaxtime) totalmaxtime = maxtime; totalcount += count; time.QuadPart = 0; count = 0; mintime = 1000000000.0; maxtime = 0; }
// Send verify timeout event handler void send_verify_timeout_handler(void *opaque) { (void)opaque; // Disabling TX gpio_output_clear(_tx_pin); end = microseconds(); // Disabling timers disable_all_timers(); // Clearing send verify flag send_verify_flag = 0; sent_ack_of_data_packet = 0; // Start slave poll timer in case of master if(_modbus_serial_config_address == 0 ) { master_current_request_processed = 1; master_poll_slave_timeout_handler(NULL); } log_error("RS485: Error sending packet on serial interface"); }
bool SensorImpl::open(Sensor::Type sensor) { // Get the default sensor matching the type m_sensor = getDefaultSensor(sensor); // Sensor not available, stop here if (!m_sensor) return false; // Get the minimum delay allowed between events Time minimumDelay = microseconds(ASensor_getMinDelay(m_sensor)); // Set the event rate (not to consume too much battery) ASensorEventQueue_setEventRate(sensorEventQueue, m_sensor, minimumDelay.asMicroseconds()); // Save the index of the sensor m_index = static_cast<unsigned int>(sensor); return true; }
// Master retry event handler void master_retry_timeout_handler(void* opaque) { (void)opaque; // Turning off the timers disable_all_timers(); if(master_current_retry <= 0) { if(send_verify_flag) { // Disabling TX gpio_output_clear(_tx_pin); end = microseconds(); // Clearing send verify flag send_verify_flag = 0; } if(sent_current_request_from_queue) { queue_pop(&_rs485_extension.packet_to_modbus_queue, NULL); sent_current_request_from_queue = 0; } partial_receive_flag = 0; master_current_request_processed = 1; master_poll_slave_timeout_handler(NULL); return; } // Resend request partial_receive_flag = 0; master_current_request_processed = 0; send_modbus_packet(_rs485_extension.slaves[master_current_slave_to_process], current_sequence_number, ¤t_request); log_debug("RS485: Retrying to send current request"); // Decrease current retry master_current_retry --; // Start master retry timer setup_timer(&master_retry_timer, TIME_UNIT_NSEC, MASTER_RETRY_TIMEOUT); timerfd_settime(_master_retry_event, 0, &master_retry_timer, NULL); }