runtime.h 2.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384
  1. #ifndef OBOO_RUNTIME_H
  2. #define OBOO_RUNTIME_H
  3. #include <stdio.h>
  4. #include "duktape/duktape.h"
  5. #define FILE_RD_FLAGS "rb"
  6. #define FILE_WR_FLAGS "w"
  7. #define MAX_CHAR_LEN 256
  8. #define MAX_DATA_SIZE 8192
  9. #define CB_PREFIX "_cb"
  10. #define JS_NULL "null"
  11. struct MemoryStruct {
  12. char *memory;
  13. size_t size;
  14. };
  15. struct ThreadInf {
  16. pthread_t thread;
  17. char command[MAX_CHAR_LEN];
  18. char run;
  19. int pId;
  20. int index;
  21. FILE *in;
  22. };
  23. duk_context *ctx;
  24. void printHelp ();
  25. void initRuntime();
  26. void destroyRuntime();
  27. int loadJS (char* filename, char* path);
  28. void getExeDir (char *path);
  29. void handleMessage(char* topic, char* payload);
  30. void invokeCallback(char* cbIndex);
  31. void runSetup();
  32. int runLoop();
  33. duk_ret_t native_print(duk_context*);
  34. duk_ret_t native_sleep(duk_context*);
  35. duk_ret_t native_mqConnect(duk_context *ctx);
  36. duk_ret_t native_subscribe(duk_context *ctx);
  37. duk_ret_t native_publish(duk_context *ctx);
  38. duk_ret_t native_initCard(duk_context *ctx);
  39. duk_ret_t native_updateCard(duk_context *ctx);
  40. duk_ret_t native_deleteCard(duk_context *ctx);
  41. duk_ret_t native_httpRequest(duk_context *ctx);
  42. duk_ret_t native_setButton(duk_context *ctx);
  43. duk_ret_t native_setNightLight(duk_context *ctx);
  44. duk_ret_t native_updateSystemTime(duk_context *ctx);
  45. duk_ret_t native_openSerialPort(duk_context *ctx);
  46. duk_ret_t native_serialWrite(duk_context *ctx);
  47. duk_ret_t native_serialWriteByteArray(duk_context *ctx);
  48. duk_ret_t native_serialRead(duk_context *ctx);
  49. duk_ret_t native_serialReadByteArray(duk_context *ctx);
  50. duk_ret_t native_writeFile(duk_context *ctx);
  51. duk_ret_t native_readFile(duk_context *ctx);
  52. duk_ret_t native_setGpio(duk_context *ctx);
  53. duk_ret_t native_playMp3(duk_context *ctx);
  54. duk_ret_t native_systemCall(duk_context *ctx);
  55. duk_ret_t native_systemPopen(duk_context *ctx);
  56. duk_ret_t native_launchProcess(duk_context *ctx);
  57. duk_ret_t native_killProcess(duk_context *ctx);
  58. duk_ret_t native_checkProcess(duk_context *ctx);
  59. #endif // OBOO_RUNTIME_H