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 { Network } from '@ionic-native/network';
import { OtaWifiProvider } from '../../providers/ota-wifi/ota-wifi';
import { CompilerProvider } from '../../providers/compiler/compiler';
@NgModule({
declarations: [
@ -14,6 +15,7 @@ import { OtaWifiProvider } from '../../providers/ota-wifi/ota-wifi';
providers: [
Network,
OtaWifiProvider,
CompilerProvider
]
})
export class OtaWizardPageModule {}

View file

@ -14,6 +14,7 @@ import { Network } from '@ionic-native/network'
import { Subscription } from 'rxjs/Subscription';
import { OtaWifiProvider, WifiStrategy } from '../../providers/ota-wifi/ota-wifi';
import { CompilerProvider } from '../../providers/compiler/compiler';
@IonicPage()
@Component({
@ -43,6 +44,7 @@ export class OtaWizardPage implements OnInit, OnDestroy {
private otaWifi: OtaWifiProvider,
private navCtrl : NavController,
navParams : NavParams,
private compilerprovider:CompilerProvider
) {
this.sketch = navParams.get('sketch')
}
@ -170,11 +172,16 @@ export class OtaWizardPage implements OnInit, OnDestroy {
// TODO: implement. use this.sketch
this.state.compilation = 'compiling'
setTimeout(() => {
this.compiledSketch = 'firmware binary here..'
try {
this.compiledSketch = await this.compilerprovider.callcompiler(this.sketch)
console.log((this.compiledSketch))
this.state.compilation = 'done'
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 { Http, Headers, RequestOptions } from '@angular/http';
import { Injectable } from '@angular/core';
import { BindingFlags } from '@angular/core/src/view';
/*
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
and Angular DI.
*/
const url = "https://compiler.sensebox.de"
@Injectable()
export class CompilerProvider {
@ -15,25 +18,21 @@ export class CompilerProvider {
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 options = new RequestOptions({ headers: headers });*/
let data ='{"board":"sensebox-mcu", "sketch":"void setup() {\nSerial.begin(9600);\nSerial.println(\"Hello World\");\n}\nvoid loop() {}"}'
return this.http.post('url', data,{ headers:new HttpHeaders({'Content-Type': 'application/json'} ) })
let data ={"board":"sensebox-mcu", "sketch":sketch}
return this.http.post(`${url}/compile`, data,{ headers:new HttpHeaders({'Content-Type': 'application/json'} ) })
.toPromise()
.then((response) =>
{
console.log('API Response : ', response.json());
return response.json();
.then((response:any) =>{
console.log('API Response : ', response.data.id);
return this.http.get(`${url}/download?id=${response.data.id}&board=sensebox-mcu`,{
responseType: 'text',
})
.toPromise()
});
};
};
/* .catch((error) =>
{
console.error('API Error : ', error.status);
console.error('API Error : ', JSON.stringify(error));
reject(error.json()); */
}