struct-frame 0.0.13__tar.gz → 0.0.15__tar.gz

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.

Potentially problematic release.


This version of struct-frame might be problematic. Click here for more details.

Files changed (41) hide show
  1. {struct_frame-0.0.13 → struct_frame-0.0.15}/PKG-INFO +2 -2
  2. {struct_frame-0.0.13 → struct_frame-0.0.15}/README.md +1 -1
  3. {struct_frame-0.0.13 → struct_frame-0.0.15}/c/biostream.sf.h +1 -1
  4. {struct_frame-0.0.13 → struct_frame-0.0.15}/pyproject.toml +3 -3
  5. struct_frame-0.0.15/src/main.py +3 -0
  6. struct_frame-0.0.15/src/struct_frame/__init__.py +8 -0
  7. struct_frame-0.0.15/src/struct_frame/__main__.py +8 -0
  8. {struct_frame-0.0.13/src/struct-frame → struct_frame-0.0.15/src/struct_frame}/c_gen.py +1 -1
  9. struct_frame-0.0.13/src/struct-frame/__main__.py → struct_frame-0.0.15/src/struct_frame/generate.py +17 -14
  10. {struct_frame-0.0.13/src/struct-frame → struct_frame-0.0.15/src/struct_frame}/ts_gen.py +1 -1
  11. struct_frame-0.0.15/tbiostream.sf.ts +92 -0
  12. struct_frame-0.0.15/tester/biostream.sf.h +68 -0
  13. {struct_frame-0.0.13/ts → struct_frame-0.0.15/tester}/biostream.sf.ts +1 -1
  14. struct_frame-0.0.15/tester/struct_frame.h +103 -0
  15. struct_frame-0.0.15/tester/struct_frame.ts +65 -0
  16. struct_frame-0.0.15/tester/struct_frame_gen.h +2 -0
  17. struct_frame-0.0.15/tester/struct_frame_gen.ts +7 -0
  18. struct_frame-0.0.15/tester/struct_frame_parser.h +101 -0
  19. struct_frame-0.0.15/tester/struct_frame_parser.ts +98 -0
  20. struct_frame-0.0.15/tester/struct_frame_types.h +69 -0
  21. struct_frame-0.0.15/tester/struct_frame_types.ts +80 -0
  22. struct_frame-0.0.15/ts/biostream.sf.ts +92 -0
  23. struct_frame-0.0.13/src/struct-frame/__init__.py +0 -6
  24. {struct_frame-0.0.13 → struct_frame-0.0.15}/.gitignore +0 -0
  25. {struct_frame-0.0.13 → struct_frame-0.0.15}/LICENSE +0 -0
  26. {struct_frame-0.0.13 → struct_frame-0.0.15}/biostream.proto +0 -0
  27. {struct_frame-0.0.13 → struct_frame-0.0.15}/index.ts +0 -0
  28. {struct_frame-0.0.13 → struct_frame-0.0.15}/main.c +0 -0
  29. {struct_frame-0.0.13 → struct_frame-0.0.15}/myl_vehicle.proto +0 -0
  30. {struct_frame-0.0.13 → struct_frame-0.0.15}/package-lock.json +0 -0
  31. {struct_frame-0.0.13 → struct_frame-0.0.15}/package.json +0 -0
  32. {struct_frame-0.0.13/src/struct-frame → struct_frame-0.0.15/src/struct_frame}/base.py +0 -0
  33. {struct_frame-0.0.13/src/struct-frame → struct_frame-0.0.15/src/struct_frame}/boilerplate/c/struct_frame.h +0 -0
  34. {struct_frame-0.0.13/src/struct-frame → struct_frame-0.0.15/src/struct_frame}/boilerplate/c/struct_frame_gen.h +0 -0
  35. {struct_frame-0.0.13/src/struct-frame → struct_frame-0.0.15/src/struct_frame}/boilerplate/c/struct_frame_parser.h +0 -0
  36. {struct_frame-0.0.13/src/struct-frame → struct_frame-0.0.15/src/struct_frame}/boilerplate/c/struct_frame_types.h +0 -0
  37. {struct_frame-0.0.13/src/struct-frame → struct_frame-0.0.15/src/struct_frame}/boilerplate/ts/struct_frame.ts +0 -0
  38. {struct_frame-0.0.13/src/struct-frame → struct_frame-0.0.15/src/struct_frame}/boilerplate/ts/struct_frame_gen.ts +0 -0
  39. {struct_frame-0.0.13/src/struct-frame → struct_frame-0.0.15/src/struct_frame}/boilerplate/ts/struct_frame_parser.ts +0 -0
  40. {struct_frame-0.0.13/src/struct-frame → struct_frame-0.0.15/src/struct_frame}/boilerplate/ts/struct_frame_types.ts +0 -0
  41. {struct_frame-0.0.13 → struct_frame-0.0.15}/tsconfig.json +0 -0
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: struct-frame
3
- Version: 0.0.13
3
+ Version: 0.0.15
4
4
  Summary: A framework for serializing data with headers
5
5
  Project-URL: Homepage, https://github.com/mylonics/struct-frame
6
6
  Project-URL: Issues, https://github.com/mylonics/struct-frame/issues
@@ -33,4 +33,4 @@ py -m twine upload dist/*
33
33
  py -m pip install --upgrade twine
34
34
 
35
35
 
36
- run locally python .\src\struct-frame
36
+ run locally python .\src\main.py
@@ -18,4 +18,4 @@ py -m twine upload dist/*
18
18
  py -m pip install --upgrade twine
19
19
 
20
20
 
21
- run locally python .\src\struct-frame
21
+ run locally python .\src\main.py
@@ -1,5 +1,5 @@
1
1
  /* Automatically generated struct frame header */
2
- /* Generated by 0.0.1 at Sat Feb 8 11:10:26 2025. */
2
+ /* Generated by 0.0.1 at Sat Feb 8 11:45:44 2025. */
3
3
 
4
4
  #pragma once
5
5
  #pragma pack(1)
@@ -4,7 +4,7 @@ build-backend = "hatchling.build"
4
4
 
5
5
  [project]
6
6
  name = "struct-frame"
7
- version = "0.0.13"
7
+ version = "0.0.15"
8
8
  authors = [
9
9
  { name="Rijesh Augustine", email="rijesh@mylonics.com" },
10
10
  ]
@@ -27,8 +27,8 @@ Issues = "https://github.com/mylonics/struct-frame/issues"
27
27
 
28
28
 
29
29
  [tool.hatch.build.targets.wheel]
30
- only-include = ["src/struct-frame"]
30
+ only-include = ["src/struct_frame"]
31
31
 
32
32
  [tool.hatch.build.targets.wheel.sources]
33
33
  "src" = ""
34
- "boilerplate" = "src/struct-frame/boilerplate"
34
+ "boilerplate" = "src/struct_frame/boilerplate"
@@ -0,0 +1,3 @@
1
+ import struct_frame
2
+
3
+ struct_frame.main()
@@ -0,0 +1,8 @@
1
+ from .base import version, NamingStyleC, CamelToSnakeCase, pascalCase
2
+
3
+ from .c_gen import FileCGen
4
+ from .ts_gen import FileTsGen
5
+
6
+ from .generate import main
7
+
8
+ __all__ = ["main", "FileCGen", "FileTsGen", "version", "NamingStyleC", "CamelToSnakeCase", "pascalCase"]
@@ -0,0 +1,8 @@
1
+ #!/usr/bin/env python3
2
+ # kate: replace-tabs on; indent-width 4;
3
+
4
+
5
+ from struct_frame import main
6
+
7
+ if __name__ == '__main__':
8
+ main()
@@ -1,7 +1,7 @@
1
1
  #!/usr/bin/env python3
2
2
  # kate: replace-tabs on; indent-width 4;
3
3
 
4
- from base import version, NamingStyleC, CamelToSnakeCase, pascalCase
4
+ from struct_frame import version, NamingStyleC, CamelToSnakeCase, pascalCase
5
5
  import time
6
6
 
7
7
  StyleC = NamingStyleC()
@@ -2,8 +2,8 @@
2
2
  # kate: replace-tabs on; indent-width 4;
3
3
 
4
4
 
5
- from c_gen import FileCGen
6
- from ts_gen import FileTsGen
5
+ from struct_frame import FileCGen
6
+ from struct_frame import FileTsGen
7
7
  from proto_schema_parser.parser import Parser
8
8
  from proto_schema_parser import ast
9
9
 
@@ -246,11 +246,13 @@ processed_file = []
246
246
  required_file = []
247
247
 
248
248
  parser = argparse.ArgumentParser(
249
- prog='ProgramName',
250
- description='What the program does',
251
- epilog='Text at the bottom of help')
249
+ prog='struct_frame',
250
+ description='Message serialization and header generation program')
252
251
 
253
- parser.add_argument('filename') # positional argument
252
+ parser.add_argument('filename')
253
+ parser.add_argument('--debug', action='store_true')
254
+ parser.add_argument('--c_path', nargs=1, type=str, default="c/")
255
+ parser.add_argument('--ts_path', nargs=1, type=str, default="ts/")
254
256
 
255
257
 
256
258
  def parseFile(filename):
@@ -321,11 +323,10 @@ def generateTsFileStrings(path):
321
323
  name = path + value.name + ".sf.ts"
322
324
  data = ''.join(FileTsGen.generate(value))
323
325
  out[name] = data
324
-
325
326
  return out
326
327
 
327
-
328
328
  import os
329
+ import shutil
329
330
 
330
331
  def main():
331
332
  args = parser.parse_args()
@@ -337,11 +338,8 @@ def main():
337
338
  print(
338
339
  f'Recursion Error. Messages most likely have a cyclical dependancy. Check Message: {recErrCurrentMessage} and Field: {recErrCurrentField}')
339
340
 
340
- cpath = "c/"
341
- files = generateCFileStrings(cpath)
342
-
343
- tspath ="ts/"
344
- files.update(generateTsFileStrings(tspath))
341
+ files = generateCFileStrings(args.c_path[0])
342
+ files.update(generateTsFileStrings(args.ts_path[0]))
345
343
 
346
344
  for filename, filedata in files.items():
347
345
  dirname = os.path.dirname(filename)
@@ -351,7 +349,12 @@ def main():
351
349
  with open(filename , 'w', encoding='utf-8') as f:
352
350
  f.write(filedata)
353
351
 
354
- #printPackages()
352
+ dir_path = os.path.dirname(os.path.realpath(__file__))
353
+ shutil.copytree(os.path.join(dir_path,"boilerplate/c"), args.c_path[0], dirs_exist_ok=True)
354
+ shutil.copytree(os.path.join(dir_path,"boilerplate/ts"), args.ts_path[0], dirs_exist_ok=True)
355
+
356
+ if args.debug:
357
+ printPackages()
355
358
 
356
359
 
357
360
  if __name__ == '__main__':
@@ -1,7 +1,7 @@
1
1
  #!/usr/bin/env python3
2
2
  # kate: replace-tabs on; indent-width 4;
3
3
 
4
- from base import version, NamingStyleC
4
+ from struct_frame import version, NamingStyleC
5
5
  import time
6
6
 
7
7
  StyleC = NamingStyleC()
@@ -0,0 +1,92 @@
1
+ /* Automatically generated struct frame header */
2
+ /* Generated by 0.0.1 at Sat Feb 8 11:47:03 2025. */
3
+
4
+ const typed_struct = require('typed-struct')
5
+ const ExtractType = typeof typed_struct.ExtractType;
6
+ const type = typeof typed_struct.ExtractType;
7
+
8
+ import { struct_frame_buffer } from './struct_frame_types';
9
+ import { msg_encode, msg_reserve, msg_finish } from './struct_frame';
10
+
11
+ /* Enum definitions */
12
+ export enum biostreamadc_sampling_frequency {
13
+ FREQ_1000 = 0,
14
+ FREQ_2000 = 1,
15
+ FREQ_4000 = 2,
16
+ FREQ_8000 = 3,
17
+ FREQ_16000 = 4
18
+ }
19
+
20
+ //enum before comment
21
+ export enum biostreamtrans_impedance_gain {
22
+ R_10 = 0,
23
+ R_100 = 1,
24
+ R_1K = 2,
25
+ //Enum inside comment
26
+ R_10K = 3
27
+ }
28
+
29
+ /* Struct definitions */
30
+ export const biostream_raw_data_t = new typed_struct.Struct('biostream_raw_data_t')
31
+ .Float32LE('ref_v')
32
+ .Float32LE('drn_c')
33
+ .Float32LE('src_v')
34
+ .Float32LE('drn_v')
35
+ .Float32LE('gte_v')
36
+ .Float32LE('phs_v')
37
+ .Float32LE('gte_c')
38
+ .Float32LE('temp')
39
+ .Float32LE('time')
40
+ .compile();
41
+
42
+ export const biostream_raw_data_t_max_size = 36;
43
+ export const RawData_msgid = 1
44
+ export function RawData_encode(buffer: struct_frame_buffer, msg: any) {
45
+ msg_encode(buffer, msg, RawData_msgid)
46
+ }
47
+ export function RawData_reserve(buffer: struct_frame_buffer) {
48
+ const msg_buffer = msg_reserve(buffer, RawData_msgid, RawData_max_size);
49
+ if (msg_buffer){
50
+ return new RawData(msg_buffer)
51
+ }
52
+ return;
53
+ }
54
+ export function RawData_finish(buffer: struct_frame_buffer) {
55
+ msg_finish(buffer);
56
+ }
57
+
58
+
59
+ export const biostream_adc_command_t = new typed_struct.Struct('biostream_adc_command_t')
60
+ .Boolean8('enable')
61
+ .biostream_adc_sampling_frequency('samplig_freq')
62
+ .biostream_uint8('over_sampling_rate')
63
+ .biostream_trans_impedance_gain('drain_res')
64
+ .biostream_trans_impedance_gain('gate_res')
65
+ .compile();
66
+
67
+ export const biostream_adc_command_t_max_size = 5;
68
+ export const AdcCommand_msgid = 112
69
+ export function AdcCommand_encode(buffer: struct_frame_buffer, msg: any) {
70
+ msg_encode(buffer, msg, AdcCommand_msgid)
71
+ }
72
+ export function AdcCommand_reserve(buffer: struct_frame_buffer) {
73
+ const msg_buffer = msg_reserve(buffer, AdcCommand_msgid, AdcCommand_max_size);
74
+ if (msg_buffer){
75
+ return new AdcCommand(msg_buffer)
76
+ }
77
+ return;
78
+ }
79
+ export function AdcCommand_finish(buffer: struct_frame_buffer) {
80
+ msg_finish(buffer);
81
+ }
82
+
83
+
84
+
85
+ export function get_message_length(msg_id : number){
86
+ switch (msg_id)
87
+ {
88
+ case raw_data_t_msgid: return raw_data_t_max_size;
89
+ case adc_command_t_msgid: return adc_command_t_max_size;
90
+ default: break;
91
+ } return 0;
92
+ }
@@ -0,0 +1,68 @@
1
+ /* Automatically generated struct frame header */
2
+ /* Generated by 0.0.1 at Sat Feb 8 11:54:37 2025. */
3
+
4
+ #pragma once
5
+ #pragma pack(1)
6
+ #include "struct_frame.h"
7
+ /* Enum definitions */
8
+ typedef enum BiostreamAdcSamplingFrequency {
9
+ ADC_SAMPLING_FREQUENCY_FREQ_1000 = 0,
10
+ ADC_SAMPLING_FREQUENCY_FREQ_2000 = 1,
11
+ ADC_SAMPLING_FREQUENCY_FREQ_4000 = 2,
12
+ ADC_SAMPLING_FREQUENCY_FREQ_8000 = 3,
13
+ ADC_SAMPLING_FREQUENCY_FREQ_16000 = 4
14
+ } BiostreamAdcSamplingFrequency;
15
+ typedef uint8_t BiostreamAdcSamplingFrequency_t;
16
+
17
+ //enum before comment
18
+ typedef enum BiostreamTransImpedanceGain {
19
+ TRANS_IMPEDANCE_GAIN_R_10 = 0,
20
+ TRANS_IMPEDANCE_GAIN_R_100 = 1,
21
+ TRANS_IMPEDANCE_GAIN_R_1K = 2,
22
+ //Enum inside comment
23
+ TRANS_IMPEDANCE_GAIN_R_10K = 3
24
+ } BiostreamTransImpedanceGain;
25
+ typedef uint8_t BiostreamTransImpedanceGain_t;
26
+
27
+ /* Struct definitions */
28
+ typedef struct BiostreamRawdata {
29
+ float refV;
30
+ float drnC;
31
+ float srcV;
32
+ float drnV;
33
+ float gteV;
34
+ float phsV;
35
+ float gteC;
36
+ float temp;
37
+ float time;
38
+ } BiostreamRawdata;
39
+
40
+ #define BIOSTREAM_RAW_DATA_MAX_SIZE 36;
41
+ #define BIOSTREAM_RAW_DATA_MSG_ID 1
42
+ MESSAGE_HELPER(biostream_raw_data, BiostreamRawdata, 36, 1);
43
+
44
+
45
+
46
+ typedef struct BiostreamAdccommand {
47
+ bool enable;
48
+ BiostreamAdcSamplingFrequency_t sampligFreq;
49
+ uint8_t overSamplingRate;
50
+ BiostreamTransImpedanceGain_t drainRes;
51
+ BiostreamTransImpedanceGain_t gateRes;
52
+ } BiostreamAdccommand;
53
+
54
+ #define BIOSTREAM_ADC_COMMAND_MAX_SIZE 5;
55
+ #define BIOSTREAM_ADC_COMMAND_MSG_ID 112
56
+ MESSAGE_HELPER(biostream_adc_command, BiostreamAdccommand, 5, 112);
57
+
58
+
59
+
60
+
61
+ uint8_t get_message_length(uint8_t msg_id){
62
+ switch (msg_id)
63
+ {
64
+ case BIOSTREAM_RAW_DATA_MSG_ID: return BIOSTREAM_RAW_DATA_MAX_SIZE;
65
+ case BIOSTREAM_ADC_COMMAND_MSG_ID: return BIOSTREAM_ADC_COMMAND_MAX_SIZE;
66
+ default: break;
67
+ } return 0;
68
+ }
@@ -1,5 +1,5 @@
1
1
  /* Automatically generated struct frame header */
2
- /* Generated by 0.0.1 at Sat Feb 8 11:10:26 2025. */
2
+ /* Generated by 0.0.1 at Sat Feb 8 11:54:37 2025. */
3
3
 
4
4
  const typed_struct = require('typed-struct')
5
5
  const ExtractType = typeof typed_struct.ExtractType;
@@ -0,0 +1,103 @@
1
+ #pragma once
2
+ #include "stdbool.h"
3
+ #include "stdint.h"
4
+ #include "string.h"
5
+ #include "struct_frame_types.h"
6
+
7
+ static inline struct checksum_t fletcher_checksum_calculation(uint8_t *buffer, uint8_t data_length)
8
+ {
9
+ checksum_t checksum;
10
+
11
+ for (int i = 0; i < data_length; i++)
12
+ {
13
+ checksum.byte1 += buffer[i];
14
+ checksum.byte2 += checksum.byte1;
15
+ }
16
+ return checksum;
17
+ }
18
+
19
+ static inline void msg_encode(struct_buffer *buffer, void *msg_buffer, uint8_t msg_id, uint8_t size)
20
+ {
21
+ buffer->data[buffer->size++] = buffer->config.start_byte;
22
+ buffer->crc_start_loc = buffer->size;
23
+ buffer->data[buffer->size++] = msg_id;
24
+
25
+ if (buffer->config.has_len)
26
+ {
27
+ buffer->data[buffer->size++] = size;
28
+ }
29
+ memcpy(buffer->data + buffer->size, (uint8_t *)msg_buffer, size);
30
+ buffer->size += size;
31
+ if (buffer->config.has_crc)
32
+ {
33
+ checksum_t crc = fletcher_checksum_calculation(buffer->data + buffer->crc_start_loc,
34
+ buffer->crc_start_loc - buffer->size);
35
+ buffer->data[buffer->size++] = crc.byte1;
36
+ buffer->data[buffer->size++] = crc.byte2;
37
+ }
38
+ }
39
+
40
+ static inline void *msg_reserve(struct_buffer *buffer, uint8_t msg_id, uint8_t size)
41
+ {
42
+ if (buffer->in_progress)
43
+ {
44
+ return 0;
45
+ }
46
+ buffer->in_progress = true;
47
+ buffer->data[buffer->size++] = buffer->config.start_byte;
48
+
49
+ buffer->data[buffer->size++] = msg_id;
50
+ if (buffer->config.has_len)
51
+ {
52
+ buffer->data[buffer->size++] = size;
53
+ }
54
+
55
+ void *out = &buffer->data[buffer->size];
56
+ buffer->size += size;
57
+
58
+ return out;
59
+ }
60
+
61
+ static inline void msg_finish(struct_buffer *buffer)
62
+ {
63
+ if (buffer->config.has_crc)
64
+ {
65
+ checksum_t crc = fletcher_checksum_calculation(buffer->data + buffer->crc_start_loc,
66
+ buffer->crc_start_loc - buffer->size);
67
+ buffer->data[buffer->size++] = crc.byte1;
68
+ buffer->data[buffer->size++] = crc.byte2;
69
+ }
70
+ buffer->in_progress = false;
71
+ }
72
+
73
+ #define MESSAGE_HELPER(funcname, name, msg_size, msg_id) \
74
+ static inline void funcname##_encode(struct_buffer *buffer, name *name##_obj) \
75
+ { \
76
+ msg_encode(buffer, name##_obj, msg_id, msg_size); \
77
+ } \
78
+ static inline bool funcname##_reserve(struct_buffer *buffer, name **msg) \
79
+ { \
80
+ void *ptr = msg_reserve(buffer, msg_id, msg_size); \
81
+ if (ptr) \
82
+ { \
83
+ *msg = (name *)ptr; \
84
+ return true; \
85
+ } \
86
+ return false; \
87
+ } \
88
+ static inline void funcname##_finish(struct_buffer *buffer) { msg_finish(buffer); } \
89
+ static inline name funcname##_get(struct_buffer *buffer) \
90
+ { \
91
+ name msg = *(name *)(buffer->data); \
92
+ return msg; \
93
+ } \
94
+ static inline name funcname##_get_from_buffer_result(buffer_parser_result_t result) \
95
+ { \
96
+ name msg = *(name *)(result.msg_loc); \
97
+ return msg; \
98
+ } \
99
+ static inline name *funcname##_get_ref(struct_buffer *buffer) { return (name *)(buffer->data); } \
100
+ static inline name *funcname##_get_ref_from_buffer_result(buffer_parser_result_t result) \
101
+ { \
102
+ return (name *)(result.msg_loc); \
103
+ }
@@ -0,0 +1,65 @@
1
+ import { Struct } from 'typed-struct';
2
+ import * as sf_types from './struct_frame_types';
3
+
4
+ function fletcher_checksum_calculation(buffer: Uint8Array, data_length: number): sf_types.checksum_t {
5
+ const checksum: sf_types.checksum_t = { byte1: 0, byte2: 0 };
6
+
7
+ for (let i = 0; i < data_length; i++) {
8
+ checksum.byte1 += buffer[i];
9
+ checksum.byte2 += checksum.byte1;
10
+ }
11
+ return checksum;
12
+ }
13
+
14
+ export function msg_encode(buffer: sf_types.struct_frame_buffer, msg: any, msgid: number) {
15
+ buffer.data[buffer.size++] = buffer.config.start_byte;
16
+ buffer.crc_start_loc = buffer.size;
17
+ buffer.data[buffer.size++] = msgid;
18
+
19
+ if (buffer.config.has_len) {
20
+ buffer.data[buffer.size++] = msg.getSize();
21
+ }
22
+ const rawData = Struct.raw(msg);
23
+ for (let i = 0; i < rawData.length; i++) {
24
+ buffer.data[buffer.size++] = rawData[i]
25
+ }
26
+
27
+ if (buffer.config.has_crc) {
28
+ const crc = fletcher_checksum_calculation(buffer.data.slice(buffer.crc_start_loc), buffer.crc_start_loc + rawData.length);
29
+ buffer.data[buffer.size++] = crc.byte1;
30
+ buffer.data[buffer.size++] = crc.byte2;
31
+ }
32
+ }
33
+
34
+ export function msg_reserve(buffer: sf_types.struct_frame_buffer, msg_id: number, msg_size: number) {
35
+ throw new Error('Function Unimplemented');
36
+
37
+ if (buffer.in_progress) {
38
+ return;
39
+ }
40
+ buffer.in_progress = true;
41
+ buffer.data[buffer.size++] = buffer.config.start_byte;
42
+
43
+ buffer.data[buffer.size++] = msg_id;
44
+ if (buffer.config.has_len) {
45
+ buffer.data[buffer.size++] = msg_size;
46
+ }
47
+
48
+ const ret = Buffer.from(buffer.data, buffer.size, msg_size);
49
+ buffer.size += msg_size;
50
+ return ret;
51
+ }
52
+
53
+
54
+
55
+ export function msg_finish(buffer: sf_types.struct_frame_buffer) {
56
+ throw new Error('Function Unimplemented');
57
+
58
+ if (buffer.config.has_crc) {
59
+ const crc = fletcher_checksum_calculation(buffer.data.slice(buffer.crc_start_loc), buffer.crc_start_loc - buffer.size);
60
+ buffer.data[buffer.size++] = crc.byte1;
61
+ buffer.data[buffer.size++] = crc.byte2;
62
+ buffer.size += 2
63
+ }
64
+ buffer.in_progress = false;
65
+ }
@@ -0,0 +1,2 @@
1
+ #pragma once
2
+ #include "myl_vehicle.sf.h"
@@ -0,0 +1,7 @@
1
+
2
+ import * as bs from './biostream.sf';
3
+
4
+ export function get_message_length(msg_id: number) {
5
+ console.log(msg_id)
6
+ return bs.get_message_length(msg_id);
7
+ }
@@ -0,0 +1,101 @@
1
+ #pragma once
2
+ #include "stdint.h"
3
+ #include "struct_frame_gen.h"
4
+ #include "struct_frame_types.h"
5
+
6
+ // https://github.com/serge-sans-paille/frozen
7
+
8
+ static inline bool parse_default_format_validate(uint8_t *data, msg_id_len_t *msg_id_len) {
9
+ (void)data;
10
+ (void)msg_id_len;
11
+ return true;
12
+ }
13
+
14
+ static inline bool parse_default_format_char_for_len_id(msg_id_len_t *msg_id_len, const uint8_t c) {
15
+ msg_id_len->msg_id = c;
16
+ msg_id_len->len = get_message_length(c);
17
+ return true;
18
+ }
19
+
20
+ parser_functions_t default_parser_functions = {parse_default_format_char_for_len_id,
21
+ parse_default_format_validate};
22
+
23
+ static inline parser_functions_t *parse_char_for_start_byte(const struct_frame_config config,
24
+ const uint8_t c) {
25
+ if (config.start_byte == c) {
26
+ return &default_parser_functions;
27
+ }
28
+ return NULL;
29
+ }
30
+
31
+ static inline bool parse_char(struct_buffer *pb, uint8_t c) {
32
+ parser_functions_t *parse_func_ptr = NULL;
33
+ switch (pb->state) {
34
+ case LOOKING_FOR_START_BYTE:
35
+ parse_func_ptr = parse_char_for_start_byte(pb->config, c);
36
+ if (parse_func_ptr) {
37
+ pb->config.parser_funcs = parse_func_ptr;
38
+ pb->state = GETTING_LENGTH_MSG_AND_ID;
39
+ }
40
+ break;
41
+
42
+ case GETTING_LENGTH_MSG_AND_ID:
43
+ if (pb->config.parser_funcs->get_msg_id_len(&pb->msg_id_len, c)) {
44
+ pb->state = GETTING_PAYLOAD;
45
+ pb->size = 0;
46
+ }
47
+ break;
48
+
49
+ case GETTING_PAYLOAD:
50
+ pb->data[pb->size++] = c;
51
+ if (pb->size >= pb->msg_id_len.len) {
52
+ pb->state = LOOKING_FOR_START_BYTE;
53
+ return pb->config.parser_funcs->validate_packet(pb->data, &pb->msg_id_len);
54
+ }
55
+
56
+ break;
57
+
58
+ default:
59
+ break;
60
+ }
61
+
62
+ return false;
63
+ }
64
+
65
+ static inline bool parse_buffer(uint8_t *buffer, size_t size, buffer_parser_result_t *parser_result) {
66
+ enum ParserState state = LOOKING_FOR_START_BYTE;
67
+ parser_functions_t *parse_func_ptr;
68
+ for (size_t i = parser_result->r_loc; i < size; i++) {
69
+ switch (state) {
70
+ case LOOKING_FOR_START_BYTE:
71
+ parse_func_ptr = parse_char_for_start_byte(parser_result->config, buffer[i]);
72
+ if (parse_func_ptr) {
73
+ state = GETTING_LENGTH_MSG_AND_ID;
74
+ }
75
+ break;
76
+
77
+ case GETTING_LENGTH_MSG_AND_ID:
78
+ if (parse_func_ptr->get_msg_id_len(&parser_result->msg_id_len, buffer[i])) {
79
+ state = GETTING_PAYLOAD;
80
+ }
81
+ break;
82
+
83
+ case GETTING_PAYLOAD:
84
+ parser_result->msg_loc = buffer + i;
85
+ parser_result->r_loc = i + parser_result->msg_id_len.len;
86
+ parser_result->found = true;
87
+ if (parse_func_ptr->validate_packet(parser_result->msg_loc, &parser_result->msg_id_len)) {
88
+ parser_result->valid = true;
89
+ return true;
90
+ } else {
91
+ parser_result->valid = false;
92
+ return true;
93
+ }
94
+ break;
95
+
96
+ default:
97
+ break;
98
+ }
99
+ }
100
+ return false;
101
+ }
@@ -0,0 +1,98 @@
1
+ import { get_message_length } from './struct_frame_gen';
2
+ import * as sf_types from './struct_frame_types';
3
+
4
+ function parse_default_format_validate(buffer: Uint8Array, msg_id_len: sf_types.msg_id_len_t): boolean {
5
+ return true;
6
+ }
7
+
8
+ function parse_default_format_char_for_len_id(c: number, msg_id_len: sf_types.msg_id_len_t): boolean {
9
+ msg_id_len.msg_id = c;
10
+ msg_id_len.len = get_message_length(c);
11
+ return true;
12
+ }
13
+
14
+ const default_parser_functions: sf_types.parser_functions_t = { get_msg_id_len: parse_default_format_char_for_len_id, validate_packet: parse_default_format_validate };
15
+
16
+ function parse_char_for_start_byte(config: sf_types.struct_frame_config, c: number): sf_types.parser_functions_t | undefined {
17
+ if (config.start_byte == c) {
18
+ return default_parser_functions;
19
+ }
20
+ return;
21
+ }
22
+
23
+ export function parse_char(pb: sf_types.struct_frame_buffer, c: number): boolean {
24
+ let parse_func_ptr: sf_types.parser_functions_t | undefined = undefined;
25
+ switch (pb.state) {
26
+ case sf_types.ParserState.LOOKING_FOR_START_BYTE:
27
+ parse_func_ptr = parse_char_for_start_byte(pb.config, c);
28
+ if (parse_func_ptr) {
29
+ pb.config.parser_funcs = parse_func_ptr;
30
+ pb.state = sf_types.ParserState.GETTING_LENGTH_MSG_AND_ID;
31
+ }
32
+ break;
33
+
34
+ case sf_types.ParserState.GETTING_LENGTH_MSG_AND_ID:
35
+ if (pb.config.parser_funcs && pb.config.parser_funcs.get_msg_id_len(c, pb.msg_id_len)) {
36
+ pb.state = sf_types.ParserState.GETTING_PAYLOAD;
37
+ pb.size = 0;
38
+ }
39
+ break;
40
+
41
+ case sf_types.ParserState.GETTING_PAYLOAD:
42
+ pb.data[pb.size] = c;
43
+ pb.size++;
44
+ if (pb.size >= pb.msg_id_len.len) {
45
+ pb.msg_data = Buffer.from(pb.data, 0, pb.size)
46
+ pb.state = sf_types.ParserState.LOOKING_FOR_START_BYTE;
47
+ if (pb.config.parser_funcs) {
48
+ return pb.config.parser_funcs.validate_packet(pb.data, pb.msg_id_len);
49
+ }
50
+ return false;
51
+ }
52
+ break;
53
+
54
+ default:
55
+ break;
56
+ }
57
+
58
+ return false;
59
+ }
60
+
61
+ export function parse_buffer(buffer: Uint8Array, size: number, parser_result: sf_types.buffer_parser_result_t): boolean {
62
+ let state: sf_types.ParserState = sf_types.ParserState.LOOKING_FOR_START_BYTE;
63
+ let parse_func_ptr: sf_types.parser_functions_t | undefined;
64
+ for (let i = parser_result.r_loc; i < size; i++) {
65
+ switch (state) {
66
+ case sf_types.ParserState.LOOKING_FOR_START_BYTE:
67
+ parse_func_ptr = parse_char_for_start_byte(parser_result.config, buffer[i]);
68
+ if (parse_func_ptr) {
69
+ state = sf_types.ParserState.GETTING_LENGTH_MSG_AND_ID;
70
+ }
71
+ break;
72
+
73
+ case sf_types.ParserState.GETTING_LENGTH_MSG_AND_ID:
74
+ if (parse_func_ptr && parse_func_ptr.get_msg_id_len(buffer[i], parser_result.msg_id_len)) {
75
+ state = sf_types.ParserState.GETTING_PAYLOAD;
76
+ }
77
+ break;
78
+
79
+ case sf_types.ParserState.GETTING_PAYLOAD:
80
+ parser_result.msg_data = Buffer.from(buffer, i, (i + parser_result.msg_id_len.len));
81
+ parser_result.r_loc = i + parser_result.msg_id_len.len;
82
+ parser_result.found = true;
83
+ if (parse_func_ptr && parse_func_ptr.validate_packet(parser_result.msg_data, parser_result.msg_id_len)) {
84
+ parser_result.valid = true;
85
+ return true;
86
+ }
87
+ else {
88
+ parser_result.valid = false;
89
+ return true;
90
+ }
91
+ break;
92
+
93
+ default:
94
+ break;
95
+ }
96
+ }
97
+ return false;
98
+ }
@@ -0,0 +1,69 @@
1
+ #pragma once
2
+
3
+ #include "stdbool.h"
4
+ #include "stdint.h"
5
+
6
+ typedef struct _msg_id_len_t {
7
+ bool valid;
8
+ uint8_t len;
9
+ uint8_t msg_id;
10
+ } msg_id_len_t;
11
+
12
+ typedef struct _parser_functions_t {
13
+ bool (*get_msg_id_len)(msg_id_len_t *, uint8_t);
14
+ bool (*validate_packet)(uint8_t *, msg_id_len_t *);
15
+ } parser_functions_t;
16
+
17
+ typedef struct _struct_frame_config {
18
+ uint8_t has_crc;
19
+ uint8_t has_len;
20
+ uint8_t start_byte;
21
+ parser_functions_t *parser_funcs;
22
+ } struct_frame_config;
23
+
24
+ enum ParserState { LOOKING_FOR_START_BYTE = 0, GETTING_LENGTH_MSG_AND_ID = 1, GETTING_PAYLOAD = 2 };
25
+
26
+ typedef struct _struct_frame_buffer {
27
+ // Used for framing and parsing
28
+ struct_frame_config config;
29
+ uint8_t *data;
30
+ size_t max_size;
31
+ size_t size;
32
+ bool in_progress;
33
+
34
+ // Used for framing
35
+ size_t crc_start_loc;
36
+
37
+ // Used for parsing
38
+ enum ParserState state;
39
+ size_t payload_len;
40
+ msg_id_len_t msg_id_len;
41
+
42
+ } struct_buffer;
43
+
44
+ typedef struct _buffer_parser_result_t {
45
+ struct_frame_config config;
46
+ bool found;
47
+ bool valid;
48
+ uint8_t *msg_loc;
49
+ size_t r_loc;
50
+ bool finished;
51
+ msg_id_len_t msg_id_len;
52
+ } buffer_parser_result_t;
53
+
54
+ // https://github.com/serge-sans-paille/frozen
55
+ // https://www.npmjs.com/package/typed-struct
56
+
57
+ #define default_parser {0, 0, 0x90}
58
+
59
+ #define zero_initialized_parser_result {default_parser, false, false, 0, 0, false, {0, 0}};
60
+
61
+ #define CREATE_DEFAULT_STRUCT_BUFFER(name, size) \
62
+ uint8_t name##_buffer[size]; \
63
+ struct_buffer name = { \
64
+ default_parser, name##_buffer, size, 0, false, 0, LOOKING_FOR_START_BYTE, 0, {false, 0, 0}}
65
+
66
+ typedef struct checksum_t {
67
+ uint8_t byte1;
68
+ uint8_t byte2;
69
+ } checksum_t;
@@ -0,0 +1,80 @@
1
+
2
+ export class msg_id_len_t {
3
+ valid = false;
4
+ len = 0;
5
+ msg_id = 0;
6
+ }
7
+
8
+ export type GetMsgIdLenType = (c: number, msg_id_len: msg_id_len_t) => boolean;
9
+ export type ValidatePacketType = (buffer: Uint8Array, msg_id_len: msg_id_len_t) => boolean;
10
+
11
+ export interface parser_functions_t {
12
+ get_msg_id_len: GetMsgIdLenType;
13
+ validate_packet: ValidatePacketType;
14
+ }
15
+
16
+ export interface struct_frame_config {
17
+ has_crc: number;
18
+ has_len: number;
19
+ start_byte: number;
20
+ parser_funcs?: parser_functions_t;
21
+ }
22
+
23
+ export enum ParserState {
24
+ LOOKING_FOR_START_BYTE = 0,
25
+ GETTING_LENGTH_MSG_AND_ID = 1,
26
+ GETTING_PAYLOAD = 2
27
+ };
28
+
29
+ export const basic_frame_config: struct_frame_config = { has_crc: 0, has_len: 0, start_byte: 0x90 };
30
+
31
+ export class struct_frame_buffer {
32
+ // Used for framing and parsing
33
+ config: struct_frame_config = basic_frame_config;
34
+ data: Uint8Array;
35
+ size = 0;
36
+ in_progress = false;
37
+
38
+ // Used for framing
39
+ crc_start_loc = 0;
40
+
41
+ // Used for parsing
42
+ state: ParserState = ParserState.LOOKING_FOR_START_BYTE;
43
+ payload_len = 0;
44
+ msg_id_len: msg_id_len_t = new msg_id_len_t();
45
+ msg_data: Buffer = Buffer.allocUnsafe(0);
46
+
47
+ constructor(public max_size: number, buffer?: Uint8Array) {
48
+ if (buffer) {
49
+ this.data = buffer;
50
+ } else {
51
+ this.data = new Uint8Array(max_size);
52
+ }
53
+ }
54
+ }
55
+
56
+ export class buffer_parser_result_t {
57
+ config: struct_frame_config = basic_frame_config;
58
+ found = false;
59
+ valid = false;
60
+ msg_data: Buffer = Buffer.allocUnsafe(0);
61
+ r_loc = 0;
62
+ finished = false;
63
+ msg_id_len: msg_id_len_t = new msg_id_len_t();
64
+ }
65
+
66
+ // https://github.com/serge-sans-paille/frozen
67
+ // https://www.npmjs.com/package/typed-struct
68
+
69
+ //#define default_parser { 0, 0, 0x90 }
70
+ //
71
+ //#define zero_initialized_parser_result { default_parser, false, false, 0, 0, false, { 0, 0} };
72
+ //
73
+ //#define CREATE_DEFAULT_STRUCT_BUFFER(name, size) \
74
+ // uint8_t name##_buffer[size]; \
75
+ // struct_buffer name = { default_parser, name##_buffer, size, 0, 0, false, 0, 0, 0, 0, NULL }
76
+
77
+ export interface checksum_t {
78
+ byte1: number;
79
+ byte2: number;
80
+ }
@@ -0,0 +1,92 @@
1
+ /* Automatically generated struct frame header */
2
+ /* Generated by 0.0.1 at Sat Feb 8 11:45:44 2025. */
3
+
4
+ const typed_struct = require('typed-struct')
5
+ const ExtractType = typeof typed_struct.ExtractType;
6
+ const type = typeof typed_struct.ExtractType;
7
+
8
+ import { struct_frame_buffer } from './struct_frame_types';
9
+ import { msg_encode, msg_reserve, msg_finish } from './struct_frame';
10
+
11
+ /* Enum definitions */
12
+ export enum biostreamadc_sampling_frequency {
13
+ FREQ_1000 = 0,
14
+ FREQ_2000 = 1,
15
+ FREQ_4000 = 2,
16
+ FREQ_8000 = 3,
17
+ FREQ_16000 = 4
18
+ }
19
+
20
+ //enum before comment
21
+ export enum biostreamtrans_impedance_gain {
22
+ R_10 = 0,
23
+ R_100 = 1,
24
+ R_1K = 2,
25
+ //Enum inside comment
26
+ R_10K = 3
27
+ }
28
+
29
+ /* Struct definitions */
30
+ export const biostream_raw_data_t = new typed_struct.Struct('biostream_raw_data_t')
31
+ .Float32LE('ref_v')
32
+ .Float32LE('drn_c')
33
+ .Float32LE('src_v')
34
+ .Float32LE('drn_v')
35
+ .Float32LE('gte_v')
36
+ .Float32LE('phs_v')
37
+ .Float32LE('gte_c')
38
+ .Float32LE('temp')
39
+ .Float32LE('time')
40
+ .compile();
41
+
42
+ export const biostream_raw_data_t_max_size = 36;
43
+ export const RawData_msgid = 1
44
+ export function RawData_encode(buffer: struct_frame_buffer, msg: any) {
45
+ msg_encode(buffer, msg, RawData_msgid)
46
+ }
47
+ export function RawData_reserve(buffer: struct_frame_buffer) {
48
+ const msg_buffer = msg_reserve(buffer, RawData_msgid, RawData_max_size);
49
+ if (msg_buffer){
50
+ return new RawData(msg_buffer)
51
+ }
52
+ return;
53
+ }
54
+ export function RawData_finish(buffer: struct_frame_buffer) {
55
+ msg_finish(buffer);
56
+ }
57
+
58
+
59
+ export const biostream_adc_command_t = new typed_struct.Struct('biostream_adc_command_t')
60
+ .Boolean8('enable')
61
+ .biostream_adc_sampling_frequency('samplig_freq')
62
+ .biostream_uint8('over_sampling_rate')
63
+ .biostream_trans_impedance_gain('drain_res')
64
+ .biostream_trans_impedance_gain('gate_res')
65
+ .compile();
66
+
67
+ export const biostream_adc_command_t_max_size = 5;
68
+ export const AdcCommand_msgid = 112
69
+ export function AdcCommand_encode(buffer: struct_frame_buffer, msg: any) {
70
+ msg_encode(buffer, msg, AdcCommand_msgid)
71
+ }
72
+ export function AdcCommand_reserve(buffer: struct_frame_buffer) {
73
+ const msg_buffer = msg_reserve(buffer, AdcCommand_msgid, AdcCommand_max_size);
74
+ if (msg_buffer){
75
+ return new AdcCommand(msg_buffer)
76
+ }
77
+ return;
78
+ }
79
+ export function AdcCommand_finish(buffer: struct_frame_buffer) {
80
+ msg_finish(buffer);
81
+ }
82
+
83
+
84
+
85
+ export function get_message_length(msg_id : number){
86
+ switch (msg_id)
87
+ {
88
+ case raw_data_t_msgid: return raw_data_t_max_size;
89
+ case adc_command_t_msgid: return adc_command_t_max_size;
90
+ default: break;
91
+ } return 0;
92
+ }
@@ -1,6 +0,0 @@
1
- from base import version, NamingStyleC, CamelToSnakeCase, pascalCase
2
-
3
- from c_gen import FileCGen
4
- from ts_gen import FileTsGen
5
-
6
- __all__ = ["FileCGen", "FileTsGen", "version", "NamingStyleC", "CamelToSnakeCase", "pascalCase"]
File without changes
File without changes
File without changes
File without changes