def input_thread_fn(): connection = pika.BlockingConnection(params) channel = connection.channel() channel.exchange_declare(exchange='board_output', exchange_type='fanout') global ser while (True): frame_gen = get_kiss_frame(ser) for frame in frame_gen: try: # First, get the KISS frame print("Full frame content is %s" % frame) crc = int.from_bytes(frame[-2:], "little", signed=False) frame = frame[:-2] _CRC_FUNC = crcmod.predefined.mkCrcFun('crc-ccitt-false') calc_crc = _CRC_FUNC(frame) pld = frame if (calc_crc != crc): raise CRCError ser_msg = qmesh_pb2.SerialMsg() try: ser_msg.ParseFromString(pld) except UnicodeDecodeError: print("Failed to decode") channel.basic_publish(exchange='board_output', routing_key='', body=ser_msg.SerializeToString()) except CRCError: print("CRC Error detected")
def dbg_process(ch, method, properties, body): ser_msg = qmesh_pb2.SerialMsg() ser_msg.ParseFromString(body) if(ser_msg.type == ser_msg.STATUS): qmesh_common.print_status_msg(ser_msg.status) if(ser_msg.status.status == ser_msg.status.MANAGEMENT): qmesh_common.channel.stop_consuming()
def log_process(ch, method, properties, body): ser_msg = qmesh_pb2.SerialMsg() ser_msg.ParseFromString(body) if (ser_msg.type == ser_msg.STATUS): qmesh_common.print_status_msg(ser_msg.status) if (ser_msg.status.status == ser_msg.status.MANAGEMENT): qmesh_common.channel.stop_consuming() elif (ser_msg.type == ser_msg.REPLY_LOG): if (ser_msg.log_msg.valid == False): print("Finished reading in log entries") sys.exit(0) else: log_msg_str = qmesh_common.print_log_msg(ser_msg.log_msg) out_file.write(log_msg_str) out_file.flush() ser_msg = qmesh_pb2.SerialMsg() ser_msg.type = qmesh_pb2.SerialMsg.READ_LOG qmesh_common.publish_msg(ser_msg)
def dbg_process(ch, method, properties, body): ser_msg = qmesh_pb2.SerialMsg() ser_msg.ParseFromString(body) if(ser_msg.type == ser_msg.DEBUG_MSG): qmesh_common.print_dbg_msg(ser_msg.dbg_msg) elif(ser_msg.type == ser_msg.DATA): qmesh_common.print_data_msg(ser_msg.data_msg) elif(ser_msg.type == ser_msg.STATUS): qmesh_common.print_status_msg(ser_msg.status)
def dbg_process(ch, method, properties, body): ser_msg = qmesh_pb2.SerialMsg() ser_msg.ParseFromString(body) if (ser_msg.type == ser_msg.CONFIG): print("Got a config message") qmesh_common.print_cfg_msg(ser_msg) qmesh_common.cfg_to_yaml_file(ser_msg, 'cfg_dump.yaml') qmesh_common.channel.stop_consuming() sys.exit(0)
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the # GNU General Public License for more details. # You should have received a copy of the GNU General Public License # along with this program. If not, see <http://www.gnu.org/licenses/>. import sys, os import pika import qmesh_pb2 import qmesh_common def dbg_process(ch, method, properties, body): ser_msg = qmesh_pb2.SerialMsg() ser_msg.ParseFromString(body) if(ser_msg.type == ser_msg.STATUS): qmesh_common.print_status_msg(ser_msg.status) if(ser_msg.status.status == ser_msg.status.MANAGEMENT): qmesh_common.channel.stop_consuming() qmesh_common.setup_outgoing_rabbitmq(dbg_process) qmesh_common.reboot_board() qmesh_common.channel.start_consuming() qmesh_common.stay_in_management() ser_msg = qmesh_pb2.SerialMsg() ser_msg.type = ser_msg.ERASE_LOGS qmesh_common.publish_msg(ser_msg) qmesh_common.channel.start_consuming()
def dbg_process(ch, method, properties, body): ser_msg = qmesh_pb2.SerialMsg() ser_msg.ParseFromString(body) if (ser_msg.Type == ser_msg.DATA): qmesh_common.print_data_msg(ser_msg.data_msg)
def stay_in_management(): ser_msg = qmesh_pb2.SerialMsg() ser_msg.type = ser_msg.STAY_IN_MGT publish_msg(ser_msg) channel.start_consuming()
def reboot_board(): ser_msg = qmesh_pb2.SerialMsg() ser_msg.type = ser_msg.REBOOT publish_msg(ser_msg)