Some fixes.
This commit is contained in:
		
							
								
								
									
										1
									
								
								.gitignore
									
									
									
									
										vendored
									
									
										Normal file
									
								
							
							
						
						
									
										1
									
								
								.gitignore
									
									
									
									
										vendored
									
									
										Normal file
									
								
							@@ -0,0 +1 @@
 | 
			
		||||
node_modules
 | 
			
		||||
							
								
								
									
										51
									
								
								index.js
									
									
									
									
									
								
							
							
						
						
									
										51
									
								
								index.js
									
									
									
									
									
								
							@@ -3,34 +3,49 @@ const args = process.argv.slice(2).join(' ');
 | 
			
		||||
 | 
			
		||||
const pongoOSDevice = usb.findByIds(0x05ac, 0x4141);
 | 
			
		||||
 | 
			
		||||
function log(message, type) {
 | 
			
		||||
  switch (type) {
 | 
			
		||||
    case 'success':
 | 
			
		||||
      console.log("[+] " + message)
 | 
			
		||||
      break;
 | 
			
		||||
    case 'error':
 | 
			
		||||
      console.error("[-] " + message)
 | 
			
		||||
      break;
 | 
			
		||||
  }
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
function checkRoot() {
 | 
			
		||||
  return process.getuid && process.getuid() === 0
 | 
			
		||||
}
 | 
			
		||||
};
 | 
			
		||||
 | 
			
		||||
if (!checkRoot()) {
 | 
			
		||||
    console.error("Please run as root!")
 | 
			
		||||
    process.exit()
 | 
			
		||||
}
 | 
			
		||||
  log("Please run ass root", "error");
 | 
			
		||||
  process.exit(1);
 | 
			
		||||
};
 | 
			
		||||
 | 
			
		||||
if (!pongoOSDevice) {
 | 
			
		||||
    console.error('pongoOS Device not found !');
 | 
			
		||||
    process.exit();
 | 
			
		||||
}
 | 
			
		||||
  log("No device with pongoOS Booted has been found.", "error");
 | 
			
		||||
  process.exit(1);
 | 
			
		||||
};
 | 
			
		||||
if (!args) {
 | 
			
		||||
    console.error('No command provided.');
 | 
			
		||||
    process.exit();
 | 
			
		||||
}
 | 
			
		||||
  log("No argumment has been provided.", "error");
 | 
			
		||||
  process.exit(1);
 | 
			
		||||
};
 | 
			
		||||
try {
 | 
			
		||||
  pongoOSDevice.open(true)
 | 
			
		||||
} catch(e) {
 | 
			
		||||
	console.error('An error as occured while i was opening the device.' + e)
 | 
			
		||||
	process.exit()
 | 
			
		||||
}
 | 
			
		||||
} catch (e) {
 | 
			
		||||
  log("An error as occured while i was opening the device.", "error");
 | 
			
		||||
  process.exit(1)
 | 
			
		||||
};
 | 
			
		||||
if (args.length > 510) {
 | 
			
		||||
  log("You reached the length of the argumment.", "error");
 | 
			
		||||
  process.exit(1)
 | 
			
		||||
};
 | 
			
		||||
pongoOSDevice.controlTransfer(0x21, 3, 0, 0, new Buffer.from(`${args} \n`), (error) => {
 | 
			
		||||
  if (error) {
 | 
			
		||||
        console.error("An error as occured while sending cmd error :" + error);
 | 
			
		||||
        process.exit();
 | 
			
		||||
    log(`An error as occured while sending cmd error: ${error}`, "error")
 | 
			
		||||
    process.exit(1);
 | 
			
		||||
  }
 | 
			
		||||
    console.log('Command sent: ' + args);
 | 
			
		||||
    process.exit();
 | 
			
		||||
  log(`Success, command "${args}" has been sent.`, "success")
 | 
			
		||||
  process.exit(0);
 | 
			
		||||
})
 | 
			
		||||
							
								
								
									
										6
									
								
								package-lock.json
									
									
									
										generated
									
									
									
								
							
							
						
						
									
										6
									
								
								package-lock.json
									
									
									
										generated
									
									
									
								
							@@ -1,9 +1,13 @@
 | 
			
		||||
{
 | 
			
		||||
  "name": "cum",
 | 
			
		||||
  "name": "pongoos-cmd-sender",
 | 
			
		||||
  "version": "1.0.0",
 | 
			
		||||
  "lockfileVersion": 2,
 | 
			
		||||
  "requires": true,
 | 
			
		||||
  "packages": {
 | 
			
		||||
    "": {
 | 
			
		||||
      "name": "pongoos-cmd-sender",
 | 
			
		||||
      "version": "1.0.0",
 | 
			
		||||
      "license": "unlicensed",
 | 
			
		||||
      "dependencies": {
 | 
			
		||||
        "usb": "^1.7.0"
 | 
			
		||||
      }
 | 
			
		||||
 
 | 
			
		||||
@@ -1,6 +1,6 @@
 | 
			
		||||
{
 | 
			
		||||
  "name": "pongoos-cmd-sender",
 | 
			
		||||
  "version": "1.0.0",
 | 
			
		||||
  "version": "1.1.0",
 | 
			
		||||
  "description": "Send command to a device connected and running pongOS.",
 | 
			
		||||
  "main": "index.js",
 | 
			
		||||
  "repository": {
 | 
			
		||||
 
 | 
			
		||||
		Reference in New Issue
	
	Block a user