imc_def 0.6.4

  • Readme
  • Changelog
  • Example
  • Installing
  • new54

imc_def #

A dart package for IMC messages manipulation.

Getting Started #

This package is both a generator and an IMC messages manipulation package.

The IMC definition is found here.

Using the package #

To use you need to import into your pubspec.yaml such as:

  • In case to use the package with the bundle generated IMC
dependencies:
   imc_def: ^x.x.x

Don't forget to flutter pub get.

  • In case you want to use the source to generate your own code add your settings to your project's pubspec.yaml file or create a file in your root project folder named imc_def.yaml with your settings.
imc_def:
  imc: <path_to_imc_file_definitions>
  # package: imc # optional, will create in src inside the folder(s)

After adding your settings, run the package with

flutter pub pub run imc_def:imc_generator

In your code just import:

import 'package:imc_def/imc_def.dart' as imc;

or if generating:

import 'package:<project_name>/src/<package/>imc_def.dart' as imc;

An example of use is the following:

...
var hbMsgB = imc.HeartbeatBuilder();
Timer.periodic(Duration(milliseconds: 300), (Timer t) {
    var msg = (hbMsgB..timestamp = DateTime.now()).build();
    var dataB = imc.messagesIdsSerializers[msg.msgId]?.serialize(msg);
    var bytes = dataB?.buffer?.asUint8List(dataB.offsetInBytes, dataB.lengthInBytes);
    if (bytes != null) {
    var bs = socket.send(
        bytes,
        InternetAddress("0.0.0.0"),
        6002);
    print("Bytes sent $bs | ${dataB.offsetInBytes}, ${dataB.lengthInBytes}");
    }
});
...

Changelog #

[0.6.4] - 2 Nov 2019

  • Updated dependencies: built_value: ^7.0.0.

[0.6.3+1] - 23 Oct 2019

  • Cleanups for publishing.

[0.6.3] - 23 Oct 2019

  • Cleanups.

[0.6.2] - 23 Oct 2019

  • Fix toPrettyString() problem in BitfieldType.

[0.6.1] - 14 Oct 2019

  • Added toPrettyString() to EnumType and BitfieldType.
  • Updated dependencies: built_value: ^6.7.1; crypto: ^2.1.3.

[0.6.0] - 09 Oct 2019

  • Adding reading generator parameters by the pubspec.yaml or imc_def.yaml files for generating the IMC code on production.

[0.5.1] - 05 Oct 2019

  • Now you can test EnumLike (EnumType and BitfieldType) with ==.
  • Added test for checking if BitfieldType has bits at '1'.

[0.5.0] - 14 Jul 2019

  • First working base with IMC v5.4.11 @Git#d60a40a8c55bef407bbf1f49cfc1ab78103a3cc3.

[0.0.1] - n/a

  • Initial release.

example/example.dart

// Copyright (c) 2019, Paulo Sousa Dias. Please see the AUTHORS file for details.
// All rights reserved. Use of this source code is governed by a BSD-style 
// license that can be found in the LICENSE file.

import 'dart:async';
import 'dart:io';
import 'dart:typed_data';

import 'package:imc_def/imc_def.dart' as imc;

//InternetAddress.ANY_IP_V4
void main() async {
  RawDatagramSocket.bind(InternetAddress.anyIPv4, 4444)
      .then((RawDatagramSocket socket) {
    print('Datagram socket ready to receive');
    print('${socket.address.address}:${socket.port}');
    socket.listen((RawSocketEvent e) {
      Datagram d = socket.receive();
      if (d == null) return;

      try {
        var data = d.data;
        var uData = Uint8List.fromList(data);
        var bData = uData.buffer.asByteData();
        var msgId = imc.getMessageIdFromHeaderIfSyncNumberOk(bData, 0);
        var bytesSerStr = " [";
        uData.forEach((b) {
          bytesSerStr += "0x${b.toRadixString(16)}, ";
        });
        bytesSerStr += "]";
        print("Msg ID: $msgId\nsize=${uData.lengthInBytes} | $bytesSerStr");
        if (msgId == imc.ImcId.nullId) return;

        var serializer = imc
            .messagesSerializers[imc.idsToMessages[msgId] ?? imc.ImcId.nullId];
        print("Msg Serializer: $serializer");
        if (serializer == null) return;

        var msg = serializer.deserialize(uData);
        print('Datagram from ${d.address.address}:${d.port}: \n$msg');
      } catch (e) {
        print("Error: $e");
      }
    });

    var hbMsgB = imc.HeartbeatBuilder();
    Timer.periodic(Duration(milliseconds: 300), (Timer t) {
      var msg = (hbMsgB..timestamp = DateTime.now()).build();
      //stdout.write("Sending ${msg.abbrev}  \n");
      var dataB = imc.messagesIdsSerializers[msg.msgId]?.serialize(msg);
      var bytes = dataB?.buffer?.asUint8List(dataB.offsetInBytes, dataB.lengthInBytes);
      if (bytes != null) {
        var bs = socket.send(
            bytes,
            InternetAddress("0.0.0.0"),
            6002);
        print("Bytes sent $bs | ${dataB.offsetInBytes}, ${dataB.lengthInBytes}");
      }
    });
  });
}

Use this package as an executable

1. Install it

You can install the package from the command line:


$ pub global activate imc_def

2. Use it

The package has the following executables:


$ imc_generator

Use this package as a library

1. Depend on it

Add this to your package's pubspec.yaml file:


dependencies:
  imc_def: ^0.6.4

2. Install it

You can install packages from the command line:

with Flutter:


$ flutter pub get

Alternatively, your editor might support flutter pub get. Check the docs for your editor to learn more.

3. Import it

Now in your Dart code, you can use:


import 'package:imc_def/imc_def.dart';
  
Popularity:
Describes how popular the package is relative to other packages. [more]
8
Health:
Code health derived from static analysis. [more]
100
Maintenance:
Reflects how tidy and up-to-date the package is. [more]
100
Overall:
Weighted score of the above. [more]
54
Learn more about scoring.

We analyzed this package on Nov 11, 2019, and provided a score, details, and suggestions below. Analysis was completed with status completed using:

  • Dart: 2.6.0
  • pana: 0.12.21
  • Flutter: 1.9.1+hotfix.6

Platforms

Detected platforms: Flutter

References Flutter, and has no conflicting libraries.

Health suggestions

Format bin/imc_generator.dart.

Run flutter format to format bin/imc_generator.dart.

Format lib/src/imc_def_e.dart.

Run flutter format to format lib/src/imc_def_e.dart.

Format lib/src/imc_def_el.dart.

Run flutter format to format lib/src/imc_def_el.dart.

Fix additional 6 files with analysis or formatting issues.

Additional issues in the following files:

  • lib/src/imc_def_enums.dart (Run flutter format to format lib/src/imc_def_enums.dart.)
  • lib/src/imc_def_gen.dart (Run flutter format to format lib/src/imc_def_gen.dart.)
  • lib/src/imc_def_i.dart (Run flutter format to format lib/src/imc_def_i.dart.)
  • lib/src/imc_def_m.dart (Run flutter format to format lib/src/imc_def_m.dart.)
  • lib/src/imc_serializers_base.dart (Run flutter format to format lib/src/imc_serializers_base.dart.)
  • lib/src/imc_serializers_gen.dart (Run flutter format to format lib/src/imc_serializers_gen.dart.)

Dependencies

Package Constraint Resolved Available
Direct dependencies
Dart SDK >=2.0.0-dev.68.0 <3.0.0
built_value ^7.0.0 7.0.0
crypto ^2.1.3 2.1.3
flutter 0.0.0
xml ^3.5.0 3.5.0
yaml ^2.2.0 2.2.0
Transitive dependencies
built_collection 4.2.2
charcode 1.1.2
collection 1.14.11 1.14.12
convert 2.1.1
fixnum 0.10.11
matcher 0.12.6
meta 1.1.7 1.1.8
path 1.6.4
petitparser 2.4.0
quiver 2.1.2+1
sky_engine 0.0.99
source_span 1.5.5
stack_trace 1.9.3
string_scanner 1.0.5
term_glyph 1.1.0
typed_data 1.1.6
vector_math 2.0.8
Dev dependencies
flutter_test