Important changes to repositories hosted on mbed.com
Mbed hosted mercurial repositories are deprecated and are due to be permanently deleted in July 2026.
To keep a copy of this software download the repository Zip archive or clone locally using Mercurial.
It is also possible to export all your personal repositories from the account settings page.
Dependencies: DataStore JobScheduler NetworkServices W5500Interface nanopb protocol
Diff: source/jobSchedulesUpload.cpp
- Revision:
- 16:bef1673b199e
- Parent:
- 15:f83485cc5a2c
- Child:
- 17:b79ce8109995
diff -r f83485cc5a2c -r bef1673b199e source/jobSchedulesUpload.cpp --- a/source/jobSchedulesUpload.cpp Thu Aug 03 19:04:06 2017 +0000 +++ b/source/jobSchedulesUpload.cpp Thu Aug 03 20:57:50 2017 +0000 @@ -78,7 +78,7 @@ tr_error("job error: failed to fill schedule"); return; } - tr_debug("schedule data size: %d", pbJobs.items[idx].ScheduleData.size); + //tr_debug("schedule data size: %d", pbJobs.items[idx].ScheduleData.size); // pbJobs.items[idx].Data = pbJobs.items_count = idx; @@ -88,35 +88,21 @@ } } + // encode to nothing to detect buffer size pb_ostream_t sizeStream = {0}; pb_encode(&sizeStream, protocol_JobList_fields, &pbJobs); - tr_debug("JobsList payload size: %d", sizeStream.bytes_written); + // allocate output buffer and encode into it uint8_t* outBuf = new uint8_t[sizeStream.bytes_written]; - pb_ostream_t outStream = pb_ostream_from_buffer(outBuf, sizeof(outBuf)); + pb_ostream_t outStream = pb_ostream_from_buffer(outBuf, sizeStream.bytes_written); pb_encode(&outStream, protocol_JobList_fields, &pbJobs); + + tr_array(outBuf, outStream.bytes_written); + + // send CoAP message + time_t now = time(NULL); + _lce.SendV1("/uw/joblist", outBuf, outStream.bytes_written, false, now); delete outBuf; - -// protocol_Job job; - // time_t now = time(NULL); - //tr_debug("ADC created time is: %s\n", ctime(&now)); -// struct AdcMsg msg; - // convert seconds to nanoseconds -// msg.Created = now * 1e9; -// tr_debug("Current time: %x sec, %llx nanosecs", now, msg.Created); -// // swapt for byte order -// msg.Created = swap_uint64(msg.Created); // swap_uint64(msg.Created); -// msg.Mask = 0x80; // 0x80 bits: 1000 0000 -// for (int i = 0; i < 8; i++) { -// msg.Chs[i].Raw = 0; -// msg.Chs[i].V = 0; -// } -// msg.Chs[0].Raw = swap_uint32(_next++); -// msg.Chs[0].V = msg.Chs[0].Raw; - // /test can be used to send to test endpoint that responds with - // a short hardcoded string - // /uw/adc - to send adc version 1 - // _lce.SendV1("/uw/adc", (uint8_t*)&msg, sizeof(msg), false, now); }