1
0
Fork 0
mirror of https://github.com/sensebox/blockly-app synced 2025-12-03 14:47:55 +01:00

finishedcompiler

This commit is contained in:
Kirubamoh 2018-11-23 13:24:13 +01:00
parent f4d854c7d7
commit 3c1b9d1044
3 changed files with 26 additions and 18 deletions

View file

@ -3,6 +3,7 @@ import { IonicPageModule } from 'ionic-angular';
import { OtaWizardPage } from './ota-wizard'; import { OtaWizardPage } from './ota-wizard';
import { Network } from '@ionic-native/network'; import { Network } from '@ionic-native/network';
import { OtaWifiProvider } from '../../providers/ota-wifi/ota-wifi'; import { OtaWifiProvider } from '../../providers/ota-wifi/ota-wifi';
import { CompilerProvider } from '../../providers/compiler/compiler';
@NgModule({ @NgModule({
declarations: [ declarations: [
@ -14,6 +15,7 @@ import { OtaWifiProvider } from '../../providers/ota-wifi/ota-wifi';
providers: [ providers: [
Network, Network,
OtaWifiProvider, OtaWifiProvider,
CompilerProvider
] ]
}) })
export class OtaWizardPageModule {} export class OtaWizardPageModule {}

View file

@ -14,6 +14,7 @@ import { Network } from '@ionic-native/network'
import { Subscription } from 'rxjs/Subscription'; import { Subscription } from 'rxjs/Subscription';
import { OtaWifiProvider, WifiStrategy } from '../../providers/ota-wifi/ota-wifi'; import { OtaWifiProvider, WifiStrategy } from '../../providers/ota-wifi/ota-wifi';
import { CompilerProvider } from '../../providers/compiler/compiler';
@IonicPage() @IonicPage()
@Component({ @Component({
@ -43,6 +44,7 @@ export class OtaWizardPage implements OnInit, OnDestroy {
private otaWifi: OtaWifiProvider, private otaWifi: OtaWifiProvider,
private navCtrl : NavController, private navCtrl : NavController,
navParams : NavParams, navParams : NavParams,
private compilerprovider:CompilerProvider
) { ) {
this.sketch = navParams.get('sketch') this.sketch = navParams.get('sketch')
} }
@ -170,11 +172,16 @@ export class OtaWizardPage implements OnInit, OnDestroy {
// TODO: implement. use this.sketch // TODO: implement. use this.sketch
this.state.compilation = 'compiling' this.state.compilation = 'compiling'
setTimeout(() => { try {
this.compiledSketch = 'firmware binary here..' this.compiledSketch = await this.compilerprovider.callcompiler(this.sketch)
console.log((this.compiledSketch))
this.state.compilation = 'done' this.state.compilation = 'done'
this.slides.lockSwipeToNext(false) this.slides.lockSwipeToNext(false)
}, 5000) } catch (err) {
this.state.compilation = 'error'
this.errorMsg = err.message
}
} }
} }

View file

@ -1,6 +1,7 @@
import { HttpClient,HttpHeaders } from '@angular/common/http'; import { HttpClient,HttpHeaders } from '@angular/common/http';
import { Http, Headers, RequestOptions } from '@angular/http'; import { Http, Headers, RequestOptions } from '@angular/http';
import { Injectable } from '@angular/core'; import { Injectable } from '@angular/core';
import { BindingFlags } from '@angular/core/src/view';
/* /*
Generated class for the CompilerProvider provider. Generated class for the CompilerProvider provider.
@ -8,6 +9,8 @@ import { Injectable } from '@angular/core';
See https://angular.io/guide/dependency-injection for more info on providers See https://angular.io/guide/dependency-injection for more info on providers
and Angular DI. and Angular DI.
*/ */
const url = "https://compiler.sensebox.de"
@Injectable() @Injectable()
export class CompilerProvider { export class CompilerProvider {
@ -15,25 +18,21 @@ export class CompilerProvider {
console.log('Hello CompilerProvider Provider'); console.log('Hello CompilerProvider Provider');
} }
async callcompiler(Binary : string): Promise<any> { async callcompiler(sketch : string): Promise<any> {
let Headers = new HttpHeaders({'Content-Type': 'application/json'} ); let Headers = new HttpHeaders({'Content-Type': 'application/json'} );
/*let options = new RequestOptions({ headers: headers });*/ /*let options = new RequestOptions({ headers: headers });*/
let data ='{"board":"sensebox-mcu", "sketch":"void setup() {\nSerial.begin(9600);\nSerial.println(\"Hello World\");\n}\nvoid loop() {}"}' let data ={"board":"sensebox-mcu", "sketch":sketch}
return this.http.post(`${url}/compile`, data,{ headers:new HttpHeaders({'Content-Type': 'application/json'} ) })
return this.http.post('url', data,{ headers:new HttpHeaders({'Content-Type': 'application/json'} ) })
.toPromise() .toPromise()
.then((response) => .then((response:any) =>{
{ console.log('API Response : ', response.data.id);
console.log('API Response : ', response.json()); return this.http.get(`${url}/download?id=${response.data.id}&board=sensebox-mcu`,{
return response.json(); responseType: 'text',
}) })
.toPromise()
};
});
}; };
/* .catch((error) => }
{
console.error('API Error : ', error.status);
console.error('API Error : ', JSON.stringify(error));
reject(error.json()); */