|
|
|
|
@ -1,5 +1,6 @@
@@ -1,5 +1,6 @@
|
|
|
|
|
const { ApolloServer, gql, PubSub } = require("apollo-server"); |
|
|
|
|
const Indi = require("@atoy40/indijs"); |
|
|
|
|
const fs = require("fs"); |
|
|
|
|
|
|
|
|
|
const IndiDriverInterface = Indi.IndiDriverInterface; |
|
|
|
|
|
|
|
|
|
@ -115,7 +116,7 @@ const typeDefs = gql`
@@ -115,7 +116,7 @@ const typeDefs = gql`
|
|
|
|
|
type LightValue { |
|
|
|
|
name: String! |
|
|
|
|
label: String |
|
|
|
|
value: String |
|
|
|
|
value: Int |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
type Device { |
|
|
|
|
@ -126,6 +127,12 @@ const typeDefs = gql`
@@ -126,6 +127,12 @@ const typeDefs = gql`
|
|
|
|
|
connected: Boolean |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
type Message { |
|
|
|
|
id: String |
|
|
|
|
device: Device! |
|
|
|
|
message: String! |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
input NumberValueInput { |
|
|
|
|
name: String! |
|
|
|
|
value: Float! |
|
|
|
|
@ -155,6 +162,13 @@ const typeDefs = gql`
@@ -155,6 +162,13 @@ const typeDefs = gql`
|
|
|
|
|
values: [SwitchValueInput!]! |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
input OneTextInput { |
|
|
|
|
device: String! |
|
|
|
|
property: String! |
|
|
|
|
name: String! |
|
|
|
|
value: String! |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
type Query { |
|
|
|
|
connected: Boolean |
|
|
|
|
devices: [Device] |
|
|
|
|
@ -167,6 +181,7 @@ const typeDefs = gql`
@@ -167,6 +181,7 @@ const typeDefs = gql`
|
|
|
|
|
newDevice: Device |
|
|
|
|
newProperty: Property |
|
|
|
|
newValue: Vector |
|
|
|
|
newMessage: Message |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
type Mutation { |
|
|
|
|
@ -176,6 +191,7 @@ const typeDefs = gql`
@@ -176,6 +191,7 @@ const typeDefs = gql`
|
|
|
|
|
sendOneNumber(input: OneNumberInput!): Boolean |
|
|
|
|
sendNumber(input: NumberInput!): Boolean |
|
|
|
|
sendSwitch(input: SwitchInput!): Boolean |
|
|
|
|
sendOneText(input: OneTextInput!): Boolean |
|
|
|
|
} |
|
|
|
|
`;
|
|
|
|
|
|
|
|
|
|
@ -194,7 +210,6 @@ indi
@@ -194,7 +210,6 @@ indi
|
|
|
|
|
pubsub.publish(["NEW_DEVICE"], { newDevice: device }); |
|
|
|
|
}) |
|
|
|
|
.on("newProperty", (property) => { |
|
|
|
|
console.log("new props "+property.getName()) |
|
|
|
|
if ( |
|
|
|
|
property.getType() === Indi.PropertyType.Number || |
|
|
|
|
property.getType() === Indi.PropertyType.Switch || |
|
|
|
|
@ -209,7 +224,6 @@ indi
@@ -209,7 +224,6 @@ indi
|
|
|
|
|
}) |
|
|
|
|
.on("newSwitch", (s) => { |
|
|
|
|
pubsub.publish(["NEW_VALUE"], { newValue: s }); |
|
|
|
|
console.log(s); |
|
|
|
|
}) |
|
|
|
|
.on("newText", (t) => { |
|
|
|
|
pubsub.publish(["NEW_VALUE"], { newValue: t }); |
|
|
|
|
@ -217,14 +231,26 @@ indi
@@ -217,14 +231,26 @@ indi
|
|
|
|
|
.on("newLight", (l) => { |
|
|
|
|
pubsub.publish(["NEW_VALUE"], { newValue: l }); |
|
|
|
|
}) |
|
|
|
|
.on("newBlob", (b) => { |
|
|
|
|
console.log("new blob"); |
|
|
|
|
.on("newBLOB", (b) => { |
|
|
|
|
console.log("new blob " + b.length); |
|
|
|
|
fs.writeFile("test.fits", b, (err) => { |
|
|
|
|
if (err) { |
|
|
|
|
console.log("unable to save buffer"); |
|
|
|
|
return; |
|
|
|
|
} |
|
|
|
|
console.log("test.fits saved"); |
|
|
|
|
}); |
|
|
|
|
//pubsub.publish(["NEW_BLOB"], { newValue: l });
|
|
|
|
|
}) |
|
|
|
|
.on("newMessage", (device, id) => { |
|
|
|
|
console.log(device.getDeviceName()); |
|
|
|
|
console.log(device.messageQueue(id)); |
|
|
|
|
//pubsub.publish(["NEW_VALUE"], { newValue: l });
|
|
|
|
|
pubsub.publish(["NEW_MESSAGE"], { |
|
|
|
|
newMessage: { |
|
|
|
|
id: device.getDeviceName() + "." + id, |
|
|
|
|
device, |
|
|
|
|
message: device.messageQueue(id), |
|
|
|
|
}, |
|
|
|
|
}); |
|
|
|
|
}); |
|
|
|
|
|
|
|
|
|
// Resolvers
|
|
|
|
|
@ -271,7 +297,6 @@ const resolvers = {
@@ -271,7 +297,6 @@ const resolvers = {
|
|
|
|
|
.catch(() => false); |
|
|
|
|
}, |
|
|
|
|
sendOneNumber(_, { input: { device, property, name, value } }) { |
|
|
|
|
console.log(value); |
|
|
|
|
return indi |
|
|
|
|
.sendNewNumber(device, property, name, value) |
|
|
|
|
.then(() => true) |
|
|
|
|
@ -288,10 +313,6 @@ const resolvers = {
@@ -288,10 +313,6 @@ const resolvers = {
|
|
|
|
|
const vector = props.getValue(); |
|
|
|
|
|
|
|
|
|
for (let i = 0; i < vector.values.length; i++) { |
|
|
|
|
/*console.log(vector.values[i].name); |
|
|
|
|
console.log(vector.values[i].value); |
|
|
|
|
console.log(values[i].name); |
|
|
|
|
console.log(values[i].value);*/ |
|
|
|
|
vector.values[i].value = values[i].value; |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
@ -300,6 +321,12 @@ const resolvers = {
@@ -300,6 +321,12 @@ const resolvers = {
|
|
|
|
|
.then(() => true) |
|
|
|
|
.catch(() => false); |
|
|
|
|
}, |
|
|
|
|
sendOneText(_, { input: { device, property, name, value } }) { |
|
|
|
|
return indi |
|
|
|
|
.sendNewText(device, property, name, value) |
|
|
|
|
.then(() => true) |
|
|
|
|
.catch(() => false); |
|
|
|
|
}, |
|
|
|
|
}, |
|
|
|
|
|
|
|
|
|
Subscription: { |
|
|
|
|
@ -318,6 +345,9 @@ const resolvers = {
@@ -318,6 +345,9 @@ const resolvers = {
|
|
|
|
|
newValue: { |
|
|
|
|
subscribe: () => pubsub.asyncIterator(["NEW_VALUE"]), |
|
|
|
|
}, |
|
|
|
|
newMessage: { |
|
|
|
|
subscribe: () => pubsub.asyncIterator(["NEW_MESSAGE"]), |
|
|
|
|
}, |
|
|
|
|
}, |
|
|
|
|
|
|
|
|
|
Device: { |
|
|
|
|
@ -358,7 +388,7 @@ const resolvers = {
@@ -358,7 +388,7 @@ const resolvers = {
|
|
|
|
|
}, |
|
|
|
|
permission(property) { |
|
|
|
|
return property.getPermission(); |
|
|
|
|
} |
|
|
|
|
}, |
|
|
|
|
}, |
|
|
|
|
|
|
|
|
|
Vector: { |
|
|
|
|
|