54 if ((
size_t)pHandle >= s->
devices.size())
68 if ((
size_t)pHandle >= s->
devices.size())
88 if ((
size_t)pHandle > s->
devices.size())
106 switch (data->
hdr.
id)
113 static time_t nextGpsMessageTime;
114 time_t currentTime = time(
NULLPTR);
115 if (currentTime > nextGpsMessageTime)
117 nextGpsMessageTime = currentTime + 5;
224 map<int, vector<p_data_t>> packets;
231 cMutexLocker logMutexLocker(&inertialSense->
m_logMutex);
234 packets[i->first] = i->second;
247 for (
map<
int, vector<p_data_t>>::iterator i = packets.begin(); i != packets.end(); i++)
249 for (
size_t j = 0; j < i->second.size(); j++)
251 if (!inertialSense->
m_logger.
LogData(i->first, &i->second[j].hdr, i->second[j].buf))
266 printf(
"\n...Logger thread terminated...\n");
275 vec.push_back(*data);
282 if (port[0] ==
'0' && port[1] ==
'\0')
301 float maxDiskSpacePercent,
302 uint32_t maxFileSize,
303 const string& subFolder)
317 return EnableLogging(path, logType, maxDiskSpacePercent, maxFileSize, subFolder);
330 vector<string> pieces;
332 if (pieces.size() < 3)
337 if (pieces[1] ==
"SERIAL")
339 if (pieces.size() < 4)
343 else if ((opened = (
m_serialServer.
Open(pieces[2].c_str(), atoi(pieces[3].c_str())))))
351 string url = (pieces.size() > 3 ? pieces[3] :
"");
352 string userAgent =
"NTRIP Inertial Sense";
353 string username = (pieces.size() > 4 ? pieces[4] :
"");
354 string password = (pieces.size() > 5 ? pieces[5] :
"");
396 size_t colon = ipAndPort.find(
':', 0);
397 if (colon == string::npos)
402 string host = ipAndPort.substr(0, colon);
403 string portString = ipAndPort.substr(colon + 1);
404 int port = (int)strtol(portString.c_str(),
NULLPTR, 10);
431 cout << endl <<
"Failed to write bytes to tcp server!" << endl;
444 static int error = 0;
448 #if 0 // Read one byte (simple method) 457 #else // Read a set of bytes (fast method) 489 printf(
"PARSE ERROR: %d\n", error++);
556 vector<string> ports;
628 if (periodMultiple < 0)
659 return BootloadFile(comPort, fileName,
"", baudRate, uploadProgress, verifyProgress,
NULLPTR, updateBootloader);
664 vector<bootloader_result_t> results;
665 vector<string> portStrings;
666 vector<bootloader_state_t> state;
676 sort(portStrings.begin(), portStrings.end());
677 state.resize(portStrings.size());
681 ifstream tmpStream(fileName);
682 if (!tmpStream.good())
684 for (
size_t i = 0; i < state.size(); i++)
686 results.push_back({ state[i].serial.port,
"File does not exist" });
691 if (results.size() == 0)
694 for (
size_t i = 0; i < state.size(); i++)
699 state[i].param.uploadProgress = uploadProgress;
700 state[i].param.verifyProgress = verifyProgress;
701 state[i].param.statusText = infoProgress;
702 state[i].param.fileName = fileName.c_str();
703 state[i].param.bootName = bootloaderFileName.c_str();
704 state[i].param.port = &state[i].serial;
705 state[i].param.verifyFileName =
NULLPTR;
706 state[i].param.flags.bitFields.enableVerify = (verifyProgress !=
NULLPTR);
707 state[i].param.numberOfDevices = (int)state.size();
708 state[i].param.baudRate = baudRate;
709 strncpy(state[i].
param.bootloadEnableCmd,
"BLEN", 4);
710 if (updateBootloader)
721 for (
size_t i = 0; i < state.size(); i++)
727 for (
size_t i = 0; i < state.size(); i++)
729 results.push_back({ state[i].serial.port, state[i].param.error });
751 cout << endl <<
"Client connecting..." << endl;
756 cout << endl <<
"Client connected: " << (int)socket << endl;
761 cout << endl <<
"Client connection failed!" << endl;
766 cout << endl <<
"Client disconnected: " << (int)socket << endl;
779 vector<string> ports;
780 size_t maxCount = UINT32_MAX;
788 maxCount = atoi(port + 1);
789 maxCount = (maxCount == 0 ? UINT32_MAX : maxCount);
799 for (
size_t i = 0; i < ports.size(); i++)
824 #define NUM_ENSURED_PKTS 10 828 if (
comManagerInit((
int)
m_comManagerState.
devices.size(),
NUM_ENSURED_PKTS, 10, 10,
staticReadPacket,
staticSendPacket, 0,
staticProcessRxData, 0, 0, &
m_cmInit,
m_cmPorts) == -1)
835 time_t startTime = time(0);
852 bool removedSerials =
false;
860 removedSerials =
true;
875 removedSerials =
true;
881 comManagerInit((
int)
m_comManagerState.
devices.size(), 10, 10, 10,
staticReadPacket,
staticSendPacket, 0,
staticProcessRxData, 0, 0, &
m_cmInit,
m_cmPorts);
int comManagerDisableData(int pHandle, uint32_t dataId)
static void LoggerThread(void *info)
void RemoveDevice(size_t index)
bool OnPacketReceived(const uint8_t *data, uint32_t dataLength)
void StopBroadcasts(bool allPorts=true)
vector< string > GetPorts()
static vector< bootloader_result_t > BootloadFile(const string &comPort, const string &fileName, const string &bootloaderFileName, int baudRate=IS_BAUD_RATE_BOOTLOADER, pfnBootloadProgress uploadProgress=NULLPTR, pfnBootloadProgress verifyProgress=NULLPTR, pfnBootloadStatus infoProgress=NULLPTR, bool updateBootloader=false)
int comManagerSendRawData(int pHandle, uint32_t dataId, void *dataPtr, int dataSize, int dataOffset)
static void StepLogger(InertialSense *i, const p_data_t *data, int pHandle)
bool param(const std::string ¶m_name, T ¶m_val, const T &default_val)
is_comm_instance_t m_gpComm
NMI_API SOCKET socket(uint16 u16Domain, uint8 u8Type, uint8 u8Flags)
void threadJoinAndFree(void *handle)
char port[MAX_SERIAL_PORT_NAME_LENGTH+1]
int comManagerValidateBaudRate(unsigned int baudRate)
bool HasReceivedResponseFromDevice(size_t index)
std::function< void(InertialSense *i, p_data_t *data, int pHandle)> pfnHandleBinaryData
ensured_pkt_t * ensuredPackets
#define PID_STOP_BROADCASTS_ALL_PORTS
InertialSense(pfnHandleBinaryData callback=NULL)
uint64_t m_clientServerByteCount
void * threadCreateAndStart(void(*function)(void *info), void *info)
int serialPortReadTimeout(serial_port_t *serialPort, unsigned char *buffer, int readCount, int timeoutMilliseconds)
uint8_t m_gpCommBuffer[PKT_BUF_SIZE]
int serialPortOpen(serial_port_t *serialPort, const char *port, int baudRate, int blocking)
broadcast_msg_t * broadcastMsg
bool OpenServerConnection(const string &connectionString)
size_t splitString(const string &s, const string &delimiter, vector< string > &result)
size_t count(InputIterator first, InputIterator last, T const &item)
void serialPortSetPort(serial_port_t *serialPort, const char *port)
pfnHandleBinaryData binaryCallbackGlobal
static void GetComPorts(vector< string > &ports)
protocol_type_t is_comm_parse_byte(is_comm_instance_t *instance, uint8_t byte)
int Open(const string &ipAddress, int port)
int m_clientBufferBytesToSend
void CloseServerConnection()
static void staticProcessRxData(CMHANDLE cmHandle, int pHandle, p_data_t *data)
void OnClientConnecting(cISTcpServer *server) OVERRIDE
void comManagerStep(void)
bool CreateHost(const string &ipAndPort)
#define COM_MANAGER_BUF_SIZE_BCAST_MSG(max_num_bcast_msgs)
static int staticReadPacket(CMHANDLE cmHandle, int pHandle, unsigned char *buf, int len)
void EnableLogging(bool enabled)
bool LogData(unsigned int device, p_data_hdr_t *dataHdr, const uint8_t *dataBuf)
int Open(const string &host, int port, int timeoutMilliseconds=IS_SOCKET_DEFAULT_TIMEOUT_MS)
void SendData(eDataIDs dataId, uint8_t *data, uint32_t length, uint32_t offset)
#define PID_STOP_BROADCASTS_CURRENT_PORT
bool SetLoggerEnabled(bool enable, const string &path=cISLogger::g_emptyString, cISLogger::eLogType logType=cISLogger::eLogType::LOGTYPE_DAT, uint64_t rmcPreset=RMC_PRESET_PPD_BITS, float maxDiskSpacePercent=0.5f, uint32_t maxFileSize=1024 *1024 *5, const string &subFolder=cISLogger::g_emptyString)
void SendRawData(eDataIDs dataId, uint8_t *data, uint32_t length=0, uint32_t offset=0)
bool InitSaveTimestamp(const string &timeStamp, const string &directory=g_emptyString, const string &subDirectory=g_emptyString, int numDevices=1, eLogType logType=LOGTYPE_DAT, float maxDiskSpacePercent=0.5f, uint32_t maxFileSize=1024 *1024 *5, bool useSubFolderTimestamp=true)
int is_comm_free(is_comm_instance_t *instance)
int Write(const uint8_t *data, int dataLength)
void SetFlashConfig(const nvm_flash_cfg_t &flashConfig, int pHandle=0)
com_manager_port_t * m_cmPorts
int enableBootloader(serial_port_t *port, int baudRate, char *error, int errorLength, const char *bootloadEnableCmd)
bool EnableLogging(const string &path, cISLogger::eLogType logType, float maxDiskSpacePercent, uint32_t maxFileSize, const string &subFolder)
uint32_t broadcastMsgSize
static int staticSendPacket(CMHANDLE cmHandle, int pHandle, unsigned char *buf, int len)
int(* pfnBootloadProgress)(const void *obj, float percent)
int serialPortWrite(serial_port_t *serialPort, const unsigned char *buffer, int writeCount)
bool m_disableBroadcastsOnClose
void OnClientDisconnected(cISTcpServer *server, socket_t socket) OVERRIDE
int serialPortClose(serial_port_t *serialPort)
int gpsToNmeaGGA(const gps_pos_t *gps, char *buffer, int bufferLength)
USBInterfaceDescriptor data
bool BroadcastBinaryData(uint32_t dataId, int periodMultiple, pfnHandleBinaryData callback=NULL)
bool OpenSerialPorts(const char *port, int baudRate)
int bootloadFileEx(bootload_params_t *params)
static void bootloaderUpdateBootloaderThread(void *state)
static void bootloaderThread(void *state)
void comManagerAssignUserPointer(CMHANDLE cmInstance, void *userPointer)
void SetSysCmd(const system_command_t &sysCmd, int pHandle=0)
void is_comm_init(is_comm_instance_t *instance, uint8_t *buffer, int bufferSize)
char error[BOOTLOADER_ERROR_LENGTH]
pfnHandleBinaryData binaryCallback[DID_COUNT]
#define COM_MANAGER_BUF_SIZE_ENSURED_PKTS(max_num_ensured_pkts)
#define MAX_NUM_BCAST_MSGS
bool Open(const char *port, int baudRate=IS_COM_BAUDRATE_DEFAULT, bool disableBroadcastsOnClose=false)
cISStream * m_clientStream
int serialPortIsOpen(serial_port_t *serialPort)
InertialSense::com_manager_cpp_state_t m_comManagerState
int bootloadUpdateBootloaderEx(bootload_params_t *p)
GeneratorWrapper< T > map(Func &&function, GeneratorWrapper< U > &&generator)
InertialSense * inertialSenseInterface
vector< is_device_t > devices
void comManagerGetDataRmc(int pHandle, uint64_t rmcBits, uint32_t rmcOptions)
int comManagerSend(int pHandle, uint8_t pktInfo, bufPtr_t *bodyHdr, bufPtr_t *txData, uint8_t pFlags)
void * comManagerGetUserPointer(CMHANDLE cmInstance)
static const string g_emptyString
bool SetDeviceInfo(const dev_info_t *info, unsigned int device=0)
virtual int Read(void *buffer, int count)
int comManagerSendData(int pHandle, uint32_t dataId, void *dataPtr, int dataSize, int dataOffset)
void(* pfnBootloadStatus)(const void *obj, const char *infoString)
bool HasReceivedResponseFromAllDevices()
protocol_type_t is_comm_parse(is_comm_instance_t *instance)
char bootloadEnableCmd[16]
void comManagerGetData(int pHandle, uint32_t dataId, int offset, int size, int periodMultiple)
Request data This function requests the specified data w/ offset and length for partial reads...
uint8_t buf[MAX_DATASET_SIZE]
int comManagerInit(int numHandles, int maxEnsuredPackets, int stepPeriodMilliseconds, int retryCount, pfnComManagerRead readFnc, pfnComManagerSend sendFnc, pfnComManagerSendBufferAvailableBytes txFreeFnc, pfnComManagerPostRead pstRxFnc, pfnComManagerPostAck pstAckFnc, pfnComManagerDisableBroadcasts disableBcastFnc, com_manager_init_t *buffers, com_manager_port_t *cmPorts)
com_manager_init_t m_cmInit
bool Open(const std::string &portName, int baudRate=BAUDRATE_921600, int timeout=0, bool blocking=false)
#define BOOTLOADER_ERROR_LENGTH
virtual int Write(const void *buffer, int count)
map< int, vector< p_data_t > > m_logPackets
cISSerialPort m_serialServer
uint32_t ensuredPacketsSize
void HttpGet(const string &subUrl, const string &userAgent, const string &userName, const string &password)
void OnClientConnectFailed(cISTcpServer *server) OVERRIDE
void OnClientConnected(cISTcpServer *server, socket_t socket) OVERRIDE
CMHANDLE comManagerGetGlobal(void)
void BroadcastBinaryDataRmcPreset(uint64_t rmcPreset=RMC_PRESET_INS_BITS, uint32_t rmcOptions=0)
pfnStepLogFunction stepLogFunction