/* this is called when the header file is included */ void PlatformLibrarySetup_attitudeactual(Picoc *pc) { #ifndef NO_FP const char *definition = "typedef struct {" "float Roll;" "float Pitch;" "float Yaw;" "} AttitudeActualData;"; PicocParse(pc, "mylib", definition, strlen(definition), TRUE, TRUE, FALSE, FALSE); #endif if (AttitudeActualHandle() == NULL) ProgramFailNoParser(pc, "no attitudeactual"); }
/* this is called when the header file is included */ void PlatformLibrarySetup_pid(Picoc *pc) { const char *definition = "typedef struct {" "float p;" "float i;" "float d;" "float iLim;" "float iAccumulator;" "float lastErr;" "float lastDer;" "float dTau;" "} pid;"; PicocParse(pc, "mylib", definition, strlen(definition), TRUE, TRUE, FALSE, FALSE); }
void PicocCallMain(int argc, char **argv) { /* check if the program wants arguments */ struct Value *FuncValue = NULL; if (!VariableDefined(TableStrRegister("main"))) ProgramFail(NULL, "main() no esta definido"); VariableGet(NULL, TableStrRegister("main"), &FuncValue); if (FuncValue->Typ->Base != TypeFunction) ProgramFail(NULL, "main no es una funcion - no puedo llamarla"); if (FuncValue->Val->FuncDef.NumParams != 0) { /* define the arguments */ VariableDefinePlatformVar(NULL, "__argc", &IntType, (union AnyValue *)&argc, FALSE); VariableDefinePlatformVar(NULL, "__argv", CharPtrPtrType, (union AnyValue *)&argv, FALSE); } if (FuncValue->Val->FuncDef.ReturnType == &VoidType) { if (FuncValue->Val->FuncDef.NumParams == 0) PicocParse("startup", CALL_MAIN_NO_ARGS_RETURN_VOID, strlen(CALL_MAIN_NO_ARGS_RETURN_VOID), TRUE, TRUE, FALSE); else PicocParse("startup", CALL_MAIN_WITH_ARGS_RETURN_VOID, strlen(CALL_MAIN_WITH_ARGS_RETURN_VOID), TRUE, TRUE, FALSE); } else { VariableDefinePlatformVar(NULL, "__exit_value", &IntType, (union AnyValue *)&PicocExitValue, TRUE); if (FuncValue->Val->FuncDef.NumParams == 0) PicocParse("startup", CALL_MAIN_NO_ARGS_RETURN_INT, strlen(CALL_MAIN_NO_ARGS_RETURN_INT), TRUE, TRUE, FALSE); else PicocParse("startup", CALL_MAIN_WITH_ARGS_RETURN_INT, strlen(CALL_MAIN_WITH_ARGS_RETURN_INT), TRUE, TRUE, FALSE); } }
void PicocCallMain(Picoc *pc, int argc, char **argv) { /* check if the program wants arguments */ struct Value *FuncValue = NULL; if (!VariableDefined(pc, TableStrRegister(pc, "main"))) ProgramFailNoParser(pc, "main() is not defined"); VariableGet(pc, NULL, TableStrRegister(pc, "main"), &FuncValue); if (FuncValue->Typ->Base != TypeFunction) ProgramFailNoParser(pc, "main is not a function - can't call it"); if (FuncValue->Val->FuncDef.NumParams != 0) { /* define the arguments */ VariableDefinePlatformVar(pc, NULL, "__argc", &pc->IntType, (union AnyValue *)&argc, FALSE); VariableDefinePlatformVar(pc, NULL, "__argv", pc->CharPtrPtrType, (union AnyValue *)&argv, FALSE); } if (FuncValue->Val->FuncDef.ReturnType == &pc->VoidType) { if (FuncValue->Val->FuncDef.NumParams == 0) PicocParse(pc, "startup", CALL_MAIN_NO_ARGS_RETURN_VOID, strlen(CALL_MAIN_NO_ARGS_RETURN_VOID), TRUE, TRUE, FALSE, TRUE); else PicocParse(pc, "startup", CALL_MAIN_WITH_ARGS_RETURN_VOID, strlen(CALL_MAIN_WITH_ARGS_RETURN_VOID), TRUE, TRUE, FALSE, TRUE); } else { VariableDefinePlatformVar(pc, NULL, "__exit_value", &pc->IntType, (union AnyValue *)&pc->PicocExitValue, TRUE); if (FuncValue->Val->FuncDef.NumParams == 0) PicocParse(pc, "startup", CALL_MAIN_NO_ARGS_RETURN_INT, strlen(CALL_MAIN_NO_ARGS_RETURN_INT), TRUE, TRUE, FALSE, TRUE); else PicocParse(pc, "startup", CALL_MAIN_WITH_ARGS_RETURN_INT, strlen(CALL_MAIN_WITH_ARGS_RETURN_INT), TRUE, TRUE, FALSE, TRUE); } }
/* this is called when the header file is included */ void PlatformLibrarySetup_accels(Picoc *pc) { #ifndef NO_FP const char *definition = "typedef struct {" "float x;" "float y;" "float z;" "float temperature;" "} AccelsData;"; PicocParse(pc, "mylib", definition, strlen(definition), TRUE, TRUE, FALSE, FALSE); #endif if (AccelsHandle() == NULL) ProgramFailNoParser(pc, "no accels"); }
/* this is called when the header file is included */ void PlatformLibrarySetup_pathdesired(Picoc *pc) { const char *definition = "typedef struct {" "float Start[3];" "float End[3];" "float StartingVelocity;" "float EndingVelocity;" "float ModeParameters;" "unsigned char Mode;" "} PathDesiredData;"; PicocParse(pc, "mylib", definition, strlen(definition), TRUE, TRUE, FALSE, FALSE); if (PathDesiredHandle() == NULL) ProgramFailNoParser(pc, "no pathdesired"); }
/* this is called when the header file is included */ void PlatformLibrarySetup_flightbatterystate(Picoc *pc) { #ifndef NO_FP const char *definition = "typedef struct {" "float Voltage;" "float Current;" "float BoardSupplyVoltage;" "float PeakCurrent;" "float AvgCurrent;" "float ConsumedEnergy;" "float EstimatedFlightTime;" "} FlightBatteryStateData;"; PicocParse(pc, "mylib", definition, strlen(definition), TRUE, TRUE, FALSE, FALSE); #endif if (FlightBatteryStateHandle() == NULL) ProgramFailNoParser(pc, "no flightbatterystate"); }
/* include one of a number of predefined libraries, or perhaps an actual file */ void IncludeFile(Picoc *pc, char *FileName) { struct IncludeLibrary *LInclude; struct InteractiveState_Struct OldState; /* scan for the include file name to see if it's in our list of predefined includes */ for (LInclude = pc->IncludeLibList; LInclude != NULL; LInclude = LInclude->NextLib) { if (strcmp(LInclude->IncludeName, FileName) == 0) { /* found it - protect against multiple inclusion */ if (!VariableDefined(pc, FileName)) { VariableDefine(pc, NULL, FileName, NULL, &pc->VoidType, FALSE); /* run an extra startup function if there is one */ if (LInclude->SetupFunction != NULL) (*LInclude->SetupFunction)(pc); /* parse the setup C source code - may define types etc. */ if (LInclude->SetupCSource != NULL) PicocParse(pc, FileName, LInclude->SetupCSource, (int) strlen(LInclude->SetupCSource), TRUE, TRUE, FALSE, FALSE); /* set up the library functions */ if (LInclude->FuncList != NULL) LibraryAdd(pc, &pc->GlobalTable, FileName, LInclude->FuncList); } return; } } /* not a predefined file, read a real file */ OldState = pc->InteractiveState; memset(&pc->InteractiveState, 0, sizeof(pc->InteractiveState)); PicocPlatformScanFile(pc, FileName); pc->InteractiveState = OldState; }
/* read and scan a file for definitions */ void PicocPlatformScanFile(const char *FileName) { char *SourceStr = PlatformReadFile(FileName); PicocParse(FileName, SourceStr, strlen(SourceStr), TRUE, FALSE, TRUE); }
void Initjl777vars() { const char *definition = "\ #define TRADEBOT_PRICECHANGE 1\n\ #define TRADEBOT_NEWMINUTE 2\n\ \ #define BARI_FIRSTBID 0\n\ #define BARI_FIRSTASK 1\n\ #define BARI_LOWBID 2\n\ #define BARI_HIGHASK 3\n\ #define BARI_HIGHBID 4\n\ #define BARI_LOWASK 5\n\ #define BARI_LASTBID 6\n\ #define BARI_LASTASK 7\n\ \ #define BARI_ARBBID 8\n\ #define BARI_ARBASK 9\n\ #define BARI_MINBID 10\n\ #define BARI_MAXASK 11\n\ #define BARI_VIRTBID 10\n\ #define BARI_VIRTASK 11\n\ #define BARI_AVEBID 12\n\ #define BARI_AVEASK 13\n\ #define BARI_MEDIAN 14\n\ #define BARI_AVEPRICE 15\n\ \ #define Bid(i) ((double *)pBids)[i]\n\ #define Ask(i) ((double *)pAsks)[i]\n\ #define Bidvol(i) ((double *)pBidvols)[i]\n\ #define Askvol(i) ((double *)pAskvols)[i]\n\ #define Bidid(i) ((unsigned long *)pBidnxt)[i]\n\ #define Askid(i) ((unsigned long *)pAsknxt)[i]\n\ #define M1(i,bari) ((float *)pM1)[((i) << 4) + (bari)]\n\ #define M2(i,bari) ((float *)pM2)[((i) << 4) + (bari)]\n\ #define M3(i,bari) ((float *)pM3)[((i) << 4) + (bari)]\n\ #define M4(i,bari) ((float *)pM4)[((i) << 4) + (bari)]\n\ #define M5(i,bari) ((float *)pM5)[((i) << 4) + (bari)]\n\ #define M10(i,bari) ((float *)pM10)[((i) << 4) + (bari)]\n\ #define M15(i,bari) ((float *)pM15)[((i) << 4) + (bari)]\n\ #define M30(i,bari) ((float *)pM30)[((i) << 4) + (bari)]\n\ #define H1(i,bari) ((float *)pH1)[((i) << 4) + (bari)]\n\ \ int init_PTL(int *eventp,int *changedp,char *exchange,char *base,char *rel)\n\ {\n\ *eventp = Event; *changedp = Changed;\n\ if ( exchange != 0 && strcmp(exchange,Exchange) != 0 )\n\ return(0);\n\ if ( strcmp(base,_Base) == 0 && strcmp(rel,_Rel) == 0 )\n\ {\n\ pBids = _Bids; Numbids = _Numbids; pAsks = _Asks; Numasks = _Numasks; Base = _Base; Rel = _Rel;\n\ pBidvols = _Bidvols; pBidnxt = _Bidnxt; pAskvols = _Askvols; pAsknxt = _Asknxt;\n\ pM1 = _M1; pM2 = _M2; pM3 = _M3; pM4 = _M4; pM5 = _M5; pM10 = _M10; pM15 = _M15; pM30 = _M30; pH1 = _H1;\n\ return(1);\n\ }\n\ else if ( strcmp(base,_Rel) == 0 && strcmp(rel,_Base) == 0 )\n\ {\n\ pBids = _inv_Bids; Numbids = _Numasks; pAsks = _inv_Asks; Numasks = _Numbids; Base = _Rel; Rel = _Base;\n\ pBidvols = _inv_Bidvols; pBidnxt = _Asknxt; pAskvols = _inv_Askvols; pAsknxt = _Bidnxt;\n\ pM1 = _inv_M1; pM2 = _inv_M2; pM3 = _inv_M3; pM4 = _inv_M4; pM5 = _inv_M5; pM10 = _inv_M10; pM15 = _inv_M15; pM30 = _inv_M30; pH1 = _inv_H1;\n\ return(-1);\n\ }\n\ else return(0);\n\ }\ "; //printf("PicoParse(%s)\n",definition); PicocParse("jl777lib",definition,(int)strlen(definition),TRUE,TRUE,FALSE); VariableDefinePlatformVar(NULL,"Exchange",CharPtrType,(union AnyValue *)&Exchange,FALSE); VariableDefinePlatformVar(NULL,"Jdatetime",&IntType,(union AnyValue *)&Jdatetime,FALSE); VariableDefinePlatformVar(NULL,"Changed",&IntType,(union AnyValue *)&Changed,FALSE); VariableDefinePlatformVar(NULL,"Event",&IntType,(union AnyValue *)&Event,FALSE); VariableDefinePlatformVar(NULL,"Maxbars",&IntType,(union AnyValue *)&Maxbars,FALSE); VariableDefinePlatformVar(NULL,"Numbids",&IntType,(union AnyValue *)&Numbids,TRUE); VariableDefinePlatformVar(NULL,"Numasks",&IntType,(union AnyValue *)&Numasks,TRUE); VariableDefinePlatformVar(NULL,"_Numbids",&IntType,(union AnyValue *)&_Numbids,FALSE); VariableDefinePlatformVar(NULL,"_Numasks",&IntType,(union AnyValue *)&_Numasks,FALSE); VariableDefinePlatformVar(NULL,"Base",CharPtrType,(union AnyValue *)&Base,TRUE); VariableDefinePlatformVar(NULL,"Rel",CharPtrType,(union AnyValue *)&Rel,TRUE); VariableDefinePlatformVar(NULL,"_Base",CharPtrType,(union AnyValue *)&_Base,FALSE); VariableDefinePlatformVar(NULL,"_Rel",CharPtrType,(union AnyValue *)&_Rel,FALSE); VariableDefinePlatformVar(NULL,"pBidnxt",VoidPtrType,(union AnyValue *)&pBidnxt,TRUE); VariableDefinePlatformVar(NULL,"pAsknxt",VoidPtrType,(union AnyValue *)&pAsknxt,TRUE); VariableDefinePlatformVar(NULL,"_Bidnxt",VoidPtrType,(union AnyValue *)&_Bidnxt,FALSE); VariableDefinePlatformVar(NULL,"_Asknxt",VoidPtrType,(union AnyValue *)&_Asknxt,FALSE); VariableDefinePlatformVar(NULL,"pBidvols",VoidPtrType,(union AnyValue *)&pBidvols,TRUE); VariableDefinePlatformVar(NULL,"pAskvols",VoidPtrType,(union AnyValue *)&pAskvols,TRUE); VariableDefinePlatformVar(NULL,"_Bidvols",VoidPtrType,(union AnyValue *)&_Bidvols,FALSE); VariableDefinePlatformVar(NULL,"_Askvols",VoidPtrType,(union AnyValue *)&_Askvols,FALSE); VariableDefinePlatformVar(NULL,"_inv_Bidvols",VoidPtrType,(union AnyValue *)&_inv_Bidvols,FALSE); VariableDefinePlatformVar(NULL,"_inv_Askvols",VoidPtrType,(union AnyValue *)&_inv_Askvols,FALSE); VariableDefinePlatformVar(NULL,"pM1",VoidPtrType,(union AnyValue *)&pM1,TRUE); VariableDefinePlatformVar(NULL,"pM2",VoidPtrType,(union AnyValue *)&pM2,TRUE); VariableDefinePlatformVar(NULL,"pM3",VoidPtrType,(union AnyValue *)&pM3,TRUE); VariableDefinePlatformVar(NULL,"pM4",VoidPtrType,(union AnyValue *)&pM4,TRUE); VariableDefinePlatformVar(NULL,"pM5",VoidPtrType,(union AnyValue *)&pM5,TRUE); VariableDefinePlatformVar(NULL,"pM10",VoidPtrType,(union AnyValue *)&pM10,TRUE); VariableDefinePlatformVar(NULL,"pM15",VoidPtrType,(union AnyValue *)&pM15,TRUE); VariableDefinePlatformVar(NULL,"pM30",VoidPtrType,(union AnyValue *)&pM30,TRUE); VariableDefinePlatformVar(NULL,"pH1",VoidPtrType,(union AnyValue *)&pH1,TRUE); VariableDefinePlatformVar(NULL,"pBids",VoidPtrType,(union AnyValue *)&pBids,TRUE); VariableDefinePlatformVar(NULL,"pAsks",VoidPtrType,(union AnyValue *)&pAsks,TRUE); VariableDefinePlatformVar(NULL,"_M1",VoidPtrType,(union AnyValue *)&_M1,FALSE); VariableDefinePlatformVar(NULL,"_M2",VoidPtrType,(union AnyValue *)&_M2,FALSE); VariableDefinePlatformVar(NULL,"_M3",VoidPtrType,(union AnyValue *)&_M3,FALSE); VariableDefinePlatformVar(NULL,"_M4",VoidPtrType,(union AnyValue *)&_M4,FALSE); VariableDefinePlatformVar(NULL,"_M5",VoidPtrType,(union AnyValue *)&_M5,FALSE); VariableDefinePlatformVar(NULL,"_M10",VoidPtrType,(union AnyValue *)&_M10,FALSE); VariableDefinePlatformVar(NULL,"_M15",VoidPtrType,(union AnyValue *)&_M15,FALSE); VariableDefinePlatformVar(NULL,"_M30",VoidPtrType,(union AnyValue *)&_M30,FALSE); VariableDefinePlatformVar(NULL,"_H1",VoidPtrType,(union AnyValue *)&_H1,FALSE); VariableDefinePlatformVar(NULL,"_Bids",VoidPtrType,(union AnyValue *)&_Bids,FALSE); VariableDefinePlatformVar(NULL,"_Asks",VoidPtrType,(union AnyValue *)&_Asks,FALSE); VariableDefinePlatformVar(NULL,"_inv_M1",VoidPtrType,(union AnyValue *)&_inv_M1,FALSE); VariableDefinePlatformVar(NULL,"_inv_M2",VoidPtrType,(union AnyValue *)&_inv_M2,FALSE); VariableDefinePlatformVar(NULL,"_inv_M3",VoidPtrType,(union AnyValue *)&_inv_M3,FALSE); VariableDefinePlatformVar(NULL,"_inv_M4",VoidPtrType,(union AnyValue *)&_inv_M4,FALSE); VariableDefinePlatformVar(NULL,"_inv_M5",VoidPtrType,(union AnyValue *)&_inv_M5,FALSE); VariableDefinePlatformVar(NULL,"_inv_M10",VoidPtrType,(union AnyValue *)&_inv_M10,FALSE); VariableDefinePlatformVar(NULL,"_inv_M15",VoidPtrType,(union AnyValue *)&_inv_M15,FALSE); VariableDefinePlatformVar(NULL,"_inv_M30",VoidPtrType,(union AnyValue *)&_inv_M30,FALSE); VariableDefinePlatformVar(NULL,"_inv_H1",VoidPtrType,(union AnyValue *)&_inv_H1,FALSE); VariableDefinePlatformVar(NULL,"_inv_Bids",VoidPtrType,(union AnyValue *)&_inv_Bids,FALSE); VariableDefinePlatformVar(NULL,"_inv_Asks",VoidPtrType,(union AnyValue *)&_inv_Asks,FALSE); //printf("Parsed pBids.%p %f pAsks.%p %f | _Bids %p _Asks %p | _inv_Bids %p _inv_Asks %p\n",pBids,((double *)_Bids)[0],pAsks,((double *)_Asks)[0],_Bids,_Asks,_inv_Bids,_inv_Asks); }