warn when data could not be sent to snes
This commit is contained in:
		
							parent
							
								
									145aec89c4
								
							
						
					
					
						commit
						ce7aaf5c8c
					
				| 
						 | 
					@ -638,13 +638,13 @@ async def snes_write(ctx : Context, write_list):
 | 
				
			||||||
        PutAddress_Request = {"Opcode": "PutAddress", "Operands": [], 'Space': 'SNES'}
 | 
					        PutAddress_Request = {"Opcode": "PutAddress", "Operands": [], 'Space': 'SNES'}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
        try:
 | 
					        try:
 | 
				
			||||||
            #will pack those requests as soon as qusb2snes actually supports that for real
 | 
					 | 
				
			||||||
            for address, data in write_list:
 | 
					            for address, data in write_list:
 | 
				
			||||||
                PutAddress_Request['Operands'] = [hex(address)[2:], hex(len(data))[2:]]
 | 
					                PutAddress_Request['Operands'] = [hex(address)[2:], hex(len(data))[2:]]
 | 
				
			||||||
                if ctx.snes_socket is not None:
 | 
					                if ctx.snes_socket is not None:
 | 
				
			||||||
                    await ctx.snes_socket.send(json.dumps(PutAddress_Request))
 | 
					                    await ctx.snes_socket.send(json.dumps(PutAddress_Request))
 | 
				
			||||||
                if ctx.snes_socket is not None:
 | 
					 | 
				
			||||||
                    await ctx.snes_socket.send(data)
 | 
					                    await ctx.snes_socket.send(data)
 | 
				
			||||||
 | 
					                else:
 | 
				
			||||||
 | 
					                    logging.warning(f"Could not send data to SNES: {data}")
 | 
				
			||||||
        except websockets.ConnectionClosed:
 | 
					        except websockets.ConnectionClosed:
 | 
				
			||||||
            logging.warning("Could not write data to SNES")
 | 
					            logging.warning("Could not write data to SNES")
 | 
				
			||||||
            return False
 | 
					            return False
 | 
				
			||||||
| 
						 | 
					@ -655,7 +655,8 @@ async def snes_write(ctx : Context, write_list):
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					
 | 
				
			||||||
def snes_buffered_write(ctx : Context, address, data):
 | 
					def snes_buffered_write(ctx : Context, address, data):
 | 
				
			||||||
    if len(ctx.snes_write_buffer) > 0 and (ctx.snes_write_buffer[-1][0] + len(ctx.snes_write_buffer[-1][1])) == address:
 | 
					    if ctx.snes_write_buffer and (ctx.snes_write_buffer[-1][0] + len(ctx.snes_write_buffer[-1][1])) == address:
 | 
				
			||||||
 | 
					        # append to existing write command, bundling them
 | 
				
			||||||
        ctx.snes_write_buffer[-1] = (ctx.snes_write_buffer[-1][0], ctx.snes_write_buffer[-1][1] + data)
 | 
					        ctx.snes_write_buffer[-1] = (ctx.snes_write_buffer[-1][0], ctx.snes_write_buffer[-1][1] + data)
 | 
				
			||||||
    else:
 | 
					    else:
 | 
				
			||||||
        ctx.snes_write_buffer.append((address, data))
 | 
					        ctx.snes_write_buffer.append((address, data))
 | 
				
			||||||
| 
						 | 
					@ -665,8 +666,9 @@ async def snes_flush_writes(ctx : Context):
 | 
				
			||||||
    if not ctx.snes_write_buffer:
 | 
					    if not ctx.snes_write_buffer:
 | 
				
			||||||
        return
 | 
					        return
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    await snes_write(ctx, ctx.snes_write_buffer)
 | 
					    # swap buffers
 | 
				
			||||||
    ctx.snes_write_buffer = []
 | 
					    ctx.snes_write_buffer, writes = [], ctx.snes_write_buffer
 | 
				
			||||||
 | 
					    await snes_write(ctx, writes)
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					
 | 
				
			||||||
async def send_msgs(websocket, msgs):
 | 
					async def send_msgs(websocket, msgs):
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
		Loading…
	
		Reference in New Issue