get some command wrapper stuff working

This commit is contained in:
optixx
2009-09-07 08:19:38 +02:00
parent 9be841521f
commit 90d4a0d019
20 changed files with 735 additions and 942 deletions

View File

@@ -1,6 +1,10 @@
#import "AppController.h"
#import "CommandWrapper.h"
#define UCON64 "/usr/local/bin/ucon64"
#define ROMFILE "/Users/david/Devel/arch/avr/code/quickdev16/roms/mrdo.smc"
@implementation AppController
- (id) init {
[super init];
@@ -8,36 +12,73 @@
return self;
}
- (void)awakeFromNib{
- (void)awakeFromNib {
[textFieldLog setStringValue:@"Log field"];
[textFieldInfo setStringValue:@"Info field"];
NSLog(@"awakeFromNib");
}
- (IBAction)romInfo:(id)sender {
NSString *string = [textField stringValue];
if ( [string length] == 0) {
NSLog(@"No message");
return;
}
NSLog(@"Have started speaking: %@", string);
//[stopButton setEnabled:YES];
- (IBAction)romUpload:(id)sender {
NSLog(@"romUpload:");
NSTask *ls=[[NSTask alloc] init];
NSPipe *pipe=[[NSPipe alloc] init];
NSFileHandle *handle;
[ls setLaunchPath:@UCON64];
[ls setArguments:[NSArray arrayWithObjects:@"-smc",@"--port=usb",@"--xquickdev16",@ROMFILE,nil]];
[ls setStandardOutput:pipe];
handle=[pipe fileHandleForReading];
[ls launch];
[NSThread detachNewThreadSelector:@selector(copyData:)
toTarget:self withObject:handle];
[pipe release];
[ls release];
}
- (IBAction)romUpload:(id)sender {
NSLog(@"romUpload");
- (void)copyData:(NSFileHandle*)handle {
NSAutoreleasePool *pool=[[NSAutoreleasePool alloc] init];
NSData *data;
while([data=[handle availableData] length]) { // until EOF (check reference)
NSString *string=[[NSString alloc] initWithData:data
encoding:NSASCIIStringEncoding];
[textFieldLog setStringValue:string];
[string release];
}
[pool release];
}
- (IBAction)romInfo:(id)sender {
NSTask *ls=[[NSTask alloc] init];
NSPipe *pipe=[[NSPipe alloc] init];
NSFileHandle *handle;
NSString *string;
NSLog(@"romInfo");
CommandWrapper *cw=[[CommandWrapper alloc] init];
[cw doPipedCommand];
NSString* myString = [[NSString alloc] init];
myString = @"test";
[textField setStringValue:myString];
if ( [myString length] != 0) {
NSLog(@"message: %@", myString);
return;
}
[ls setLaunchPath:@"/usr/local/bin/ucon64"];
[ls setArguments:[NSArray arrayWithObjects:@ROMFILE,nil]];
[ls setStandardOutput:pipe];
handle=[pipe fileHandleForReading];
[ls launch];
string=[[NSString alloc] initWithData:[handle readDataToEndOfFile]
encoding:NSASCIIStringEncoding]; // convert NSData -> NSString
NSLog(@"romInfo: %@", string);
[textFieldInfo setStringValue:string];
[string retain];
[pipe release];
[ls release];
}
-(NSSize)windowWillResize:(NSWindow *)send toSize:(NSSize) framesize;