W800_Smart_Watch/src/gadget_bridge_parser/main.c

375 lines
11 KiB
C

/**
* @file main.c
* @author Anatole SCHRAMM-HENRY
* @brief Source file containing the test programm used to verify the parser
*
* @version 0.1
* @date 2023-04-10
*
* @copyright MIT
*
*/
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include "gadget_bridge.h"
/**
[3][16]setTime(1680860758);E.setTimeZone(2.0);(s=>{s&&(s.timezone=2.0)&&require('Storage').write('setting.json',s);})(require('Storage').readJSON('setting.json',1))
[10][16]GB({t:"calendar",id:63751,type:0,timestamp:1680991200,durationInSeconds:86400,title:"Easter Sunday",description:"Observance\nTo hide observances, go to Google Calendar Settings > Holidays in France",location:"",calName:"anatole.schramm-henry@master-stic.fr/Holidays in France",color:-15292571,allDay:true})
[10][16]GB({t:"calendar",id:63749,type:0,timestamp:1681077600,durationInSeconds:86400,title:"Easter Monday",description:"Public holiday",location:"",calName:"anatole.schramm-henry@master-stic.fr/Holidays in France",color:-15292571,allDay:true})
[10][16]GB({t:"weather",temp:0,hum:0,code:3200,wind:0.0,wdir:0,loc:""})[10]
[16]GB({t:"notify",id:1682154002,src:"Gadgetbridge",subject:"This is a test payload",body:"This is a test payload ",sender :"This is a test payload ",tel:"This is a test payload "})[10]
[16]GB({t:"notify",id:1680859061,body:"test hehe test",sender:"+33652623698",tel:"+33652623698"})
[10][16]GB({t:"notify",id:1680859062,src:"Messages",title:"06 52 62 36 98",body:"test hehe test"})[10]
[16]GB({t:"notify",id:1680859063,src:"E-mail",title:"Th3maz1ng Wot Channel",body:"Test subject"})[10]
[16]GB({t:"call",cmd:"incoming",name:"+33950208629",number:"+33950208629"})
[10][16]GB({t:"call",cmd:"end",name:"+33950208629",number:"+33950208629"})[10]
[16]GB({t:"weather",temp:284,hum:89,code:803,txt:"nuages mod⸮r⸮s",wind:11.0,wdir:347,loc:"ST. ETIENNE"})[10]
[16]GB({t:"weather",temp:284,hum:89,code:803,txt:"nuages mod⸮r⸮s",wind:11.0,wdir:347,loc:"ST. ETIENNE"})[10]
GB({t:"find",n:true})[10]
[16]GB({t:"find",n:false})[10]
GB({t:"act",hrm:false,stp:true,int:10})[10]
[16]GB({t:"act",hrm:true,stp:true,int:10})[10]
[16]GB({t:"act",hrm:true,stp:false,int:10})[10]
[16]GB({t:"act",hrm:false,stp:false,int:10})[10]
**/
void parser_event(const gadget_bridge_event_data_t *gadget_bridge_event_data)
{
printf("----------->Event of type : %s\n", gadget_bridge_event_type_2_str(gadget_bridge_event_data->event_type));
switch(gadget_bridge_event_data->event_type)
{
case GADGET_BRIDGE_EVENT_TYPE_SET_TIME:
printf("%d:%d:%d %d/%d/%d\n%d\n",
gadget_bridge_event_data->time.local_time.tm_hour,
gadget_bridge_event_data->time.local_time.tm_min,
gadget_bridge_event_data->time.local_time.tm_sec,
gadget_bridge_event_data->time.local_time.tm_mday,
gadget_bridge_event_data->time.local_time.tm_mon,
gadget_bridge_event_data->time.local_time.tm_year + 1900,
gadget_bridge_event_data->time.time_zone);
break;
case GADGET_BRIDGE_EVENT_TYPE_NOTIFY:
printf("%u\n%s\n%s\n%s\n",
gadget_bridge_event_data->notification.handle,
gadget_bridge_notification_type_2_str(gadget_bridge_event_data->notification.notification_type),
gadget_bridge_event_data->notification.title,
gadget_bridge_event_data->notification.body);
break;
break;
case GADGET_BRIDGE_EVENT_TYPE_CALL:
printf("%u\n%s\n%s\n",
gadget_bridge_event_data->call.call_action,
gadget_bridge_event_data->call.contact,
gadget_bridge_event_data->call.phone_number);
break;
case GADGET_BRIDGE_EVENT_TYPE_WEATHER:
printf("%.2f\n%u\n%s\n%.2f\n%u\n%s\n",
gadget_bridge_event_data->weather.temperature_celsius,
gadget_bridge_event_data->weather.humidity,
gadget_bridge_event_data->weather.weather_desc,
gadget_bridge_event_data->weather.wind_speed_kmh,
gadget_bridge_event_data->weather.wind_dir,
gadget_bridge_event_data->weather.location);
break;
case GADGET_BRIDGE_EVENT_TYPE_FIND:
printf("%d\n",gadget_bridge_event_data->find.find);
break;
case GADGET_BRIDGE_EVENT_TYPE_ACT:
printf("%d\n%d\n%u\n",
gadget_bridge_event_data->act.heart_rate_monitor,
gadget_bridge_event_data->act.steps,
gadget_bridge_event_data->act.heart_rate_interval);
break;
case GADGET_BRIDGE_EVENT_TYPE_MUSIC_STATE:
printf("%s\n%u\n%u\n%u\n",
gadget_bridge_music_state_2_str(gadget_bridge_event_data->music_state.music_state),
gadget_bridge_event_data->music_state.position_in_seconds,
gadget_bridge_event_data->music_state.shuffle,
gadget_bridge_event_data->music_state.repeat);
break;
case GADGET_BRIDGE_EVENT_TYPE_MUSIC_INFO:
printf("%s\n%s\n%u\n",
gadget_bridge_event_data->music_info.artist,
gadget_bridge_event_data->music_info.track,
gadget_bridge_event_data->music_info.duration_in_seconds);
break;
default:
printf("Unhandled\n");
}
}
const char *sample[] =
{
"[3]",
"[16]setTime(1680979884)",
";E.setTimeZone(2.0);",
"(s=>{s&&(s.timezone=",
"2.0)&&require('Stora",
"ge').write('setting.",
"json',s);})(require(",
"'Storage').readJSON(",
"'setting.json',1))[10]",
"[16]GB({t:\"calendar\",id",
":63992,type:0,timest",
"amp:1680991200,durat",
"ionInSeconds:86400,t",
"itle:\"Easter Sunday\"",
",description:\"Observ",
"ance\nTo hide observ",
"ances, go to Google ",
"Calendar Settings > ",
"Holidays in France\",",
"location:\"\",calName:",
"\"anatole.schramm-hen",
"ry@master-stic.fr/Ho",
"lidays in France\",co",
"lor:-15292571,allDay",
":true})[10]",
"[16]GB({t:\"calendar\",id",
":63990,type:0,timest",
"amp:1681077600,durat",
"ionInSeconds:86400,t",
"itle:\"Easter Monday\"",
",description:\"Public",
" holiday\",location:\"",
"\",calName:\"anatole.s",
"chramm-henry@master-",
"stic.fr/Holidays in ",
"France\",color:-15292",
"571,allDay:true})[10]",
"[16]GB({t:\"act\",hrm:fal",
"se,stp:true,int:10})",
"[10]",
"[16]GB({t:\"act\",hrm:tru",
"e,stp:true,int:10})[10]",
"[16]GB({t:\"act\",hrm:tru",
"e,stp:false,int:10})",
"[10]",
"[16]GB({t:\"act\",hrm:fal",
"se,stp:false,int:10}",
")[10]",
"[16]GB({t:\"find\",n:true",
"})[10]",
"[16]GB({t:\"find\",n:fals",
"e})[10]",
"[16]GB({t:\"find\",n:fals",
"e})[10]",
"[16]GB({t:\"weather\",tem",
"p:277,hum:96,code:80",
"4,txt:\"tr⸮s nuageux\"",
",wind:4.0,wdir:130,l",
"oc:\"ST. ETIENNE\"})[10]",
"[16]GB({t:\"notify\",id:1",
"680945578,body:\"test",
" 1 2 1 2\",sender:\"+3",
"3652623698\",tel:\"+33",
"652623698\"})[10]",
"[16]GB({t:\"notify\",id:1",
"680945579,src:\"Messa",
"ges\",title:\"06 52 62",
" 36 98\",body:\"test 1",
" 2 1 2\"})[10]",
"[16]GB({t:\"notify\",id:1",
"6809533,src:\"Messa",
"ges\",title:\"06 52 62",
" 36 98\",body:\"test 2",
"Lorem ipsum dolor sit ",
"Lorem ipsum dolor sit ",
"Lorem ipsum dolor sit ",
"Lorem ipsum dolor sit ",
"Lorem ipsum dolor sit ",
"Lorem ipsum dolor sit ",
"Lorem ipsum dolor sit ",
"Lorem ipsum dolor sit ",
"Lorem ipsum dolor sit ",
"Lorem ipsum dolor sit ",
"Lorem ipsum dolor sit ",
" lol xptdr\"})[10]",
"[16]GB({t:\"call\",cm",
"d:\"incoming\",nam",
"e:\"+3395020862",
"9\",number:\"+33950208",
"629\"})",
"[16]GB({t:\"call\",cm",
"d:\"end\",nam",
"e:\"+3395020862",
"9\",number:\"+33950208",
"629\"})",
"[16]GB({t:\"notify\",id",
":1680859063,src:\"E-mail",
"\",title:\"Th3maz1ng Wo",
"qsfsqfqsfagueule",
"et ce txcbxcbcxbxccxbcxcbcbeule",
"et ce txvvxcvcxvbnbv,jkmlgueule",
"et ce titre estcvbcnvcnghjhjhgjghueule",
"et ce titre ewcwxcxwcxwc magueule",
"t Channel\",body:\"Test",
"Lorem ipsum dolor sit ",
"Lorem ipsum dolor sit ",
"Lorem ipsum dolor sit ",
"Lorem ipsum dolor sit ",
"Lorem ipsum dolor sit ",
"Lorem ipsum dolor sit ",
"Lorem ipsum dolor sit ",
"Lorem ipsum dolor sit ",
"Lorem ipsum dolor sit ",
"Lorem ipsum dolor sit ",
"Lorem ipsum dolor sit ",
" subject\"})[10]",
"[16]GB({t:\"notify\",id",
":1680859063,src:\"E-mail",
"\",title:\"Th3maz1ng Wo",
"t Channel\",body:\"Test",
" subject\"})[10]",
"[16]GB({t:\"musicinfo\",a",
"rtist:\"The Good Life",
" Radio x Sensual Mus",
"ique\",track:\"The Goo",
"d Life Radio⸮?⸮24/7 ",
"Live Radio | Best Re",
"lax House, Chillout,",
" Study, Running, Gym",
", Happy Music\",dur:0",
",c:-1,n:-1})[10]",
"[16]GB({t:\"musicstate\",",
"state:\"pause\",positi",
"on:3587,shuffle:1,re",
"peat:1})[10]",
"[16]GB({t:\"musicinfo\",a",
"rtist:\"The Good Life",
" Radio x Sensual Mus",
"ique\",track:\"The Goo",
"d Life Radio⸮?⸮24/7 ",
"Live Radio | Best Re",
"lax House, Chillout,",
" Study, Running, Gym",
", Happy Music\",dur:0",
",c:-1,n:-1})[10]",
"[16]GB({t:\"musicstate\",",
"state:\"play\",positio",
"n:3582,shuffle:1,rep",
"eat:1})[10]",
"[16]GB({t:\"musicinfo\",a",
"rtist:\"Bliss Corpora",
"tion\",track:\"Eiffel ",
"65 - Blue (Da Ba Dee",
") [Gabry Ponte Ice P",
"op Mix] (Original Vi",
"deo with subtitles)\"",
",dur:219,c:-1,n:-1})",
"[16]GB({t:\"musicinfo\",a",
"rtist:\"Inna\",album:\"",
",track:\"Sun Is Up\",",
"dur:185,c:-1,n:0})",
"[16]GB({t:\"musicinfo\",a",
"rtist:\"The Fat ",
"Rat\",track:\"The cal",
"ling by laur",
"a brem) [Gabry Ponte Ice P",
"op Mix] (Original Vi",
"deo with subtitles)\"",
",dur:219,c:-1,n:-1})",
"[16]GB({t:\"notify\",i",
"d:1680859061,body:\"tes",
"t hehe test\",sender:\"",
"+33652623698\",tel:\"+3",
"3652623698\"})",
"[16]GB({t:\"notify\",id:",
"1682154002,src:\"Gadgetb",
"ridge\",subject:\"This i",
"s a test payload\",body:\"",
"This is a test payload \",",
"sender :\"This is a test",
"payload \",tel:\"This is",
" a test payload \"})[10]",
"[16]GB({t:\"notify\",id:",
"1682154002,src:\"Gadgetb",
"ridge\",subject:\"This i",
"s a test payload with a ",
"pretty long text because",
" it has to be also teste",
"d, we never know if some",
"thing was badly design",
"e\",body:\"",
"This is a test payload w",
"ith a very long content ",
"to make sure this case i",
"s handled in the parser ",
"and we do not crash the ",
"thing because we forgot ",
"to handle such a case, d",
"on't you think ? I need ",
"some more text apparentl",
"y as what I Wrote still ",
"isn't enough\",",
"sender :\"This is a test",
"payload \",tel:\"This is",
" a test payload \"})[10]",
"[16]GB({t:\"notify\",id:1",
"684049367,src:\"Whats",
"App\",title:\"Backyard",
" ⸮: ~?PIERRE EMMANUE",
"L DUCHET\",body:\"F⸮li",
"citations ⸮ Adrien q",
"ui vient de finir no",
"n pas son Ultra comm",
"e annonc⸮ (annul⸮) m",
"ais un 92 km 2000d+ ",
"en terminant premier",
" ex aequo en 7h59!!\\",
"nUn concurrent s⸮rie",
"ux pour la backyard ",
"!\nEncore bravo :cla",
"p::+1:\"})[10]",
};
int main()
{
gadget_bridge_parser_code_e code;
printf("Testing the gadget bridge parser :\n");
gadget_bridge_parser_register_event_callback(&(parser_event));
uint8_t sample_count = sizeof sample / sizeof *sample;
printf("Number of samples : %u\n", sample_count);
for(uint8_t i = 0; i < sample_count; i++)
{
gadget_bridge_parser_feed(sample[i], strlen(sample[i]));
//gadget_bridge_parser_debug();
while((code = gadget_bridge_parser_run()) == GADGET_BRIDGE_PARSER_CODE_PARSING);
printf("Parser code : %s\n", gadget_bridge_parser_code_2_str(code));
//gadget_bridge_parser_debug();
}
return 0;
}