Skip to content

Commit

Permalink
Merge pull request #42 from EdgePi-Cloud/read_rtd
Browse files Browse the repository at this point in the history
implement read_rtd_temperature method on client
  • Loading branch information
iaj2 authored Aug 31, 2023
2 parents 9b69e42 + 9ee0b0f commit 9cb6fb6
Show file tree
Hide file tree
Showing 2 changed files with 55 additions and 2 deletions.
24 changes: 24 additions & 0 deletions src/services/AdcService/AdcService.ts
Original file line number Diff line number Diff line change
Expand Up @@ -248,6 +248,30 @@ class AdcService {
const stateMsg: VoltageReadMsg = response.content as VoltageReadMsg
return stateMsg.voltageRead
}

async readRtdTemperature (): Promise<number> {
const requestType = this.serviceProtoRoot.lookupType('EdgePiRPC_ADC.EmptyMsg')
const responseType = this.serviceProtoRoot.lookupType('EdgePiRPC_ADC.TempReading')

// Create request
const serviceReq: serviceRequest = {
serviceName: this.serviceName,
methodName: 'read_rtd_temperature',
requestMsg: { /** Empty Msg */}
}

// Call method through rpc
console.info('Calling ADC read_rtd_temperature through Rpc Channel..')
const response: serverResponse =
await this.rpcChannel.callMethod(serviceReq, requestType, responseType)

if (response.error !== undefined) {
throw Error(response.error)
}

const successMsg: TempReading = response.content as TempReading
return successMsg.temp
}
}

export { AdcService }
33 changes: 31 additions & 2 deletions tests/integration/AdcService.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,11 @@ jest.unmock('zeromq')
describe('AdcService', ()=> {
let adc: AdcService

beforeAll(() =>{
adc = new AdcService('tcp://localhost:5555');
beforeAll(async() =>{
adc = new AdcService('tcp://192.168.1.216:5555');
// set rtds off
await adc.setRtd(false, ADCNum.ADC_1)
await adc.setRtd(false, ADCNum.ADC_2)

})

Expand Down Expand Up @@ -86,6 +89,8 @@ describe('AdcService', ()=> {
[ADCNum.ADC_2, DiffMode.DIFF_4, 'DiffMode.DIFF_4'],
[ADCNum.ADC_2, DiffMode.DIFF_OFF, 'DiffMode.DIFF_OFF'],
])('should run continuous differentials', async (adcNum, diff, diff_str) => {


// config continuous mode
await adc.setConfig({conversionMode:ConvMode.CONTINUOUS})

Expand All @@ -108,4 +113,28 @@ describe('AdcService', ()=> {
const stopConvRep = await adc.stopConversions(adcNum)
expect(stopConvRep).toEqual('Successfully stopped conversions.')
})

test.each([
[ADCNum.ADC_1],
[ADCNum.ADC_2,],

])('should get rtd readings', async (adcNum) => {
// config continuous mode
await adc.setConfig({conversionMode:ConvMode.CONTINUOUS})

// set rtds on
await adc.setRtd(true, adcNum)

// Start conversions
await adc.startConversions(adcNum)

// Read temp
const temp = await adc.readRtdTemperature()
expect(typeof temp === 'number').toBe(true)

// Stop conversions
await adc.stopConversions(adcNum)
})


})

0 comments on commit 9cb6fb6

Please sign in to comment.