project_files/frontlib/ipc/ipcconn.c
changeset 7182 076aba32abd3
parent 7179 f84805e6df03
child 7224 5143861c83bd
equal deleted inserted replaced
7179:f84805e6df03 7182:076aba32abd3
   153 	} else {
   153 	} else {
   154 		return -1;
   154 		return -1;
   155 	}
   155 	}
   156 }
   156 }
   157 
   157 
       
   158 static void logSentMsg(const uint8_t *data, size_t len) {
       
   159 	if(flib_log_getLevel() > FLIB_LOGLEVEL_DEBUG) {
       
   160 		size_t msgStart = 0;
       
   161 		while(msgStart < len) {
       
   162 			uint8_t msglen = data[msgStart];
       
   163 			if(msgStart+msglen < len) {
       
   164 				flib_log_d("[IPC OUT][%03u]%*.*s",(unsigned)msglen, (unsigned)msglen, (unsigned)msglen, data+msgStart+1);
       
   165 			} else {
       
   166 				uint8_t msglen2 = len-msgStart-1;
       
   167 				flib_log_d("[IPC OUT][%03u/%03u]%*.*s",(unsigned)msglen2, (unsigned)msglen, (unsigned)msglen2, (unsigned)msglen2, data+msgStart+1);
       
   168 			}
       
   169 			msgStart += (uint8_t)data[msgStart]+1;
       
   170 		}
       
   171 	}
       
   172 }
       
   173 
   158 int flib_ipcconn_send_raw(flib_ipcconn ipc, const void *data, size_t len) {
   174 int flib_ipcconn_send_raw(flib_ipcconn ipc, const void *data, size_t len) {
   159 	if(!ipc || (!data && len>0)) {
   175 	if(!ipc || (!data && len>0)) {
   160 		flib_log_e("Call to flib_ipcconn_send_raw with ipc==null or data==null");
   176 		flib_log_e("Call to flib_ipcconn_send_raw with ipc==null or data==null");
   161 		return -1;
   177 		return -1;
   162 	}
   178 	}
   164 		flib_log_w("flib_ipcconn_send_raw: Not connected.");
   180 		flib_log_w("flib_ipcconn_send_raw: Not connected.");
   165 		return -1;
   181 		return -1;
   166 	}
   182 	}
   167 
   183 
   168 	if(flib_socket_send(ipc->sock, data, len) == len) {
   184 	if(flib_socket_send(ipc->sock, data, len) == len) {
       
   185 		logSentMsg(data, len);
   169 		if(ipc->demoBuffer) {
   186 		if(ipc->demoBuffer) {
   170 			if(flib_demo_record_to_engine(ipc->demoBuffer, data, len) < 0) {
   187 			if(flib_demo_record_to_engine(ipc->demoBuffer, data, len) < 0) {
   171 				flib_log_w("Stopping demo recording due to an error.");
   188 				flib_log_w("Stopping demo recording due to an error.");
   172 				flib_vector_destroy(&ipc->demoBuffer);
   189 				flib_vector_destroy(&ipc->demoBuffer);
   173 			}
   190 			}
   187 	}
   204 	}
   188 
   205 
   189 	uint8_t sendbuf[256];
   206 	uint8_t sendbuf[256];
   190 	sendbuf[0] = len;
   207 	sendbuf[0] = len;
   191 	memcpy(sendbuf+1, data, len);
   208 	memcpy(sendbuf+1, data, len);
   192 
       
   193 	return flib_ipcconn_send_raw(ipc, sendbuf, len+1);
   209 	return flib_ipcconn_send_raw(ipc, sendbuf, len+1);
   194 }
   210 }
   195 
   211 
   196 int flib_ipcconn_send_messagestr(flib_ipcconn ipc, char *data) {
   212 int flib_ipcconn_send_messagestr(flib_ipcconn ipc, char *data) {
   197 	return flib_ipcconn_send_message(ipc, data, strlen(data));
   213 	return flib_ipcconn_send_message(ipc, data, strlen(data));