0

New Info:

I thought I would paste this in full as I can not seem to find any samples on the web of a c# solution for StarLink so hopefully anyone else looking for something may find this helpful and may contribute.

My New Proto File - (partial) - I took the advise of Yuri below. Thanks for the direction here. I was able to I have been using this tool and it has brought a lot of insight but I am still stuck on the c# side of the solution. I am an old VB.Net developer though I have done a bunch in c# I am by no means savvy in it and am probably missing something so simple. Again, any insight would be awesome. I can not post the full proto here as stack has char limit on posts. this is the first bit with messages etc. I can post more if it helps but trying to keep it to the important part.

    syntax = "proto3";

    option csharp_namespace = "SpaceX.API.Device";

    package SpaceX.API.Device;


    service Device {
        //rpc Handle (.SpaceX.API.Device.Request) returns (.SpaceX.API.Device.Response) {}
        //rpc Stream (stream .SpaceX.API.Device.ToDevice) returns (stream .SpaceX.API.Device.FromDevice) {}
        rpc Handle (Request) returns (Response);
        rpc Stream (Request) returns (Response);
    }

    message ToDevice {
        string message = 1;
    }


    message Request {
      uint64 id = 1;
      string target_id = 13;
      uint64 epoch_id = 14;
      oneof request {
        SignedData signed_request = 15;
        RebootRequest reboot = 1001;
        SpeedTestRequest speed_test = 1003;
        GetStatusRequest get_status = 1004;
        AuthenticateRequest authenticate = 1005;
        GetNextIdRequest get_next_id = 1006;
        GetHistoryRequest get_history = 1007;
        GetDeviceInfoRequest get_device_info = 1008;
        GetPingRequest get_ping = 1009;
        SetTrustedKeysRequest set_trusted_keys = 1010;
        FactoryResetRequest factory_reset = 1011;
        GetLogRequest get_log = 1012;
        SetSkuRequest set_sku = 1013;
        UpdateRequest update = 1014;
        GetNetworkInterfacesRequest get_network_interfaces = 1015;
        PingHostRequest ping_host = 1016;
        GetLocationRequest get_location = 1017;
        EnableFlowRequest enable_flow = 1018;
        GetHeapDumpRequest get_heap_dump = 1019;
        RestartControlRequest restart_control = 1020;
        FuseRequest fuse = 1021;
        GetPersistentStatsRequest get_persistent_stats = 1022;
        GetConnectionsRequest get_connections = 1023;
        FlushTelemRequest flush_telem = 1026;
        StartSpeedtestRequest start_speedtest = 1027;
        GetSpeedtestStatusRequest get_speedtest_status = 1028;
        ReportClientSpeedtestRequest report_client_speedtest = 1029;
        InitiateRemoteSshRequest initiate_remote_ssh = 1030;
        SelfTestRequest self_test = 1031;
        SetTestModeRequest set_test_mode = 1032;
        DishStowRequest dish_stow = 2002;
        DishGetContextRequest dish_get_context = 2003;
        DishSetEmcRequest dish_set_emc = 2007;
        DishGetObstructionMapRequest dish_get_obstruction_map = 2008;
        DishGetEmcRequest dish_get_emc = 2009;
        DishSetConfigRequest dish_set_config = 2010;
        DishGetConfigRequest dish_get_config = 2011;
        StartDishSelfTestRequest start_dish_self_test = 2012;
        WifiSetConfigRequest wifi_set_config = 3001;
        WifiGetClientsRequest wifi_get_clients = 3002;
        WifiSetupRequest wifi_setup = 3003;
        WifiGetPingMetricsRequest wifi_get_ping_metrics = 3007;
        WifiGetDiagnosticsRequest wifi_get_diagnostics = 3008;
        WifiGetConfigRequest wifi_get_config = 3009;
        WifiSetMeshDeviceTrustRequest wifi_set_mesh_device_trust = 3012;
        WifiSetMeshConfigRequest wifi_set_mesh_config = 3013;
        WifiGetClientHistoryRequest wifi_get_client_history = 3015;
        TransceiverIFLoopbackTestRequest transceiver_if_loopback_test = 4001;
        TransceiverGetStatusRequest transceiver_get_status = 4003;
        TransceiverGetTelemetryRequest transceiver_get_telemetry = 4004;
      }
      reserved 1025, 3011, 3014;
    }


    message SignedData {
      bytes data = 1;
      bytes signature = 2;
    }

My New .cs I have tried many things from Microsoft's examples to thing I can gather from other samples. I simply can not get it to work and am lost. Again, any insight would be amazing and hopefully helpful to others looking for a solution in c#. You will see my commented code of this I have been playing with. Basically I am attempting to achieve three things and have made some movement in one of them.

Goals:

1 - Use Server Reflection to discover services. I think I got this one resolved with dot-net grpc.

2 - Simply want to check available methods under a service and potentially either check or generate a new .proto file in case things change. StaLink does not publish its proto schema so I assume it could change anytime without warning.

3 - Just run any one of the available methods. I have tried the GetDeviceInfoRequest but can not seem to construct the request message properly. I have not been able to get this accomplishe in the gRPCurl tool either. I can do it on the basic service shown by Microsoft of course but these methods seem to be more complex and I simply get all kinds of errors.

Again, any insight or assistance would be amazing. Thanks to any and all in advance.

New .cs File

using System;
using System.Diagnostics;
using System.Threading.Tasks;
using Grpc.Core;
using Grpc.Net.Client;
using Grpc.Reflection.V1Alpha;
using ServerReflectionClient = Grpc.Reflection.V1Alpha.ServerReflection.ServerReflectionClient;
using SpaceX.API.Device;


public class Program
{
       

    static async Task Main(string[] args)
    {
        //SETUP CHANNEL AND CLIENT
        using var channel = GrpcChannel.ForAddress("http://192.168.100.1:9200");
        var client = new ServerReflectionClient(channel);


        var StarLinkClient = new Device.DeviceClient(channel);

        //using var call = StarLinkClient.StreamAsync(new ToDevice { Request = GetDeviceInfoRequest });

        //await foreach (var response in call.ResponseStream.ReadAllAsync())




        //var request = Device.GetDeviceInfoRequest;


        //var reply = await StarLinkClient.HandleAsync(
        //                  new Request {'"getDeviceInfo" : {} '});

        //Console.WriteLine(reply.Message);


        //=============================================SERVER REFLECTION=============================================================
        Console.WriteLine("Calling reflection service:");
        var response = await SingleRequestAsync(client, new ServerReflectionRequest
        {
            ListServices = "" // Get all services

        });

        Console.WriteLine("Services:");
        foreach (var item in response.ListServicesResponse.Service)
        {
            Console.WriteLine("- " + item.Name);
            Console.WriteLine();
            var StarLink = item.Name;

            //Console.WriteLine(StarLink.getStatus());
        }


        //=============================================SERVER REFLECTION=============================================================




        Console.WriteLine("Press any key to exit...");
        Console.ReadKey();
    }


    void setupchannel()
    {

    }


    private static Task SingleRequestAsync(ServerReflectionClient client, Metadata metadata)
    {
        throw new NotImplementedException();
    }

    private static async Task<ServerReflectionResponse> SingleRequestAsync(ServerReflectionClient client, ServerReflectionRequest request)
    {
        using var call = client.ServerReflectionInfo();
        await call.RequestStream.WriteAsync(request);
        Debug.Assert(await call.ResponseStream.MoveNext());


        var response = call.ResponseStream.Current;
        await call.RequestStream.CompleteAsync();


        return response;
    }
}

Again, thanks in advance to anyone willing to assist here. Hopefully this helps others as well.

nathan
  • 47
  • 4
  • According to https://github.com/sparky8512/starlink-grpc-tools/wiki/gRPC-Protocol-Modules you can use grpcurl to extract proto definitions: `grpcurl -plaintext -protoset-out dish.protoset 192.168.100.1:9200 describe SpaceX.API.Device.Device` – Yuri Golobokov Jul 13 '22 at 01:18
  • I am now able to potentially send a request via: grpcurl -d '{"getDeviceInfo":{}}' -plaintext 192.168.100.1:9200 SpaceX.API.Device.Device.Handle 'code' but am getting another error now: error getting request data: invalid character '\'' looking for beginning of value just getting more confused. – nathan Jul 17 '22 at 15:59
  • Getting Further _ can now make a call in gRPCurl as I found a post that stated gRPCurl documentation does not show it requires escape chars. So In gRPCrul 'grpcurl -d "{\"getDeviceInfo\":{}}" -plaintext 192.168.100.1:9200 SpaceX.API.Device.Device.Handle' SUCCESS!!! But in c# I can not transpose, please help... c# 'var reply = await StarLinkClient.HandleAsync( new Request { '"getDeviceInfo":{ }' });' just constant context errors. Any Advice would be great. Thanks. – nathan Jul 17 '22 at 17:34
  • From which package did you get SpaceX.API.Device? – Yaroslav May 25 '23 at 11:53

0 Answers0